2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-10-04 17:31:58 +02:00
|
|
|
describe DossierPreloader do
|
|
|
|
let(:types_de_champ) do
|
|
|
|
[
|
|
|
|
{ type: :text },
|
2023-11-30 14:10:33 +01:00
|
|
|
{ type: :repetition, mandatory: true, children: [{ type: :text }] },
|
|
|
|
{ type: :repetition, mandatory: false, children: [{ type: :text }] }
|
2022-10-04 17:31:58 +02:00
|
|
|
]
|
|
|
|
end
|
|
|
|
let(:procedure) { create(:procedure, types_de_champ_public: types_de_champ) }
|
|
|
|
let(:dossier) { create(:dossier, procedure: procedure) }
|
2024-09-27 15:37:11 +02:00
|
|
|
let(:repetition) { subject.project_champs_public.second }
|
|
|
|
let(:repetition_optional) { subject.project_champs_public.third }
|
|
|
|
let(:first_child) { subject.project_champs_public.second.champs.first }
|
2022-10-04 17:31:58 +02:00
|
|
|
|
|
|
|
describe 'all' do
|
2022-10-13 15:54:38 +02:00
|
|
|
subject { DossierPreloader.load_one(dossier, pj_template: true) }
|
2022-10-04 17:31:58 +02:00
|
|
|
|
|
|
|
before { subject }
|
|
|
|
|
|
|
|
it do
|
|
|
|
count = 0
|
|
|
|
|
|
|
|
callback = lambda { |*_args| count += 1 }
|
|
|
|
ActiveSupport::Notifications.subscribed(callback, "sql.active_record") do
|
|
|
|
expect(subject.id).to eq(dossier.id)
|
2024-09-27 15:37:11 +02:00
|
|
|
expect(subject.project_champs_public.size).to eq(types_de_champ.size)
|
2022-10-04 17:31:58 +02:00
|
|
|
expect(subject.changed?).to be false
|
|
|
|
|
|
|
|
expect(first_child.type).to eq('Champs::TextChamp')
|
|
|
|
expect(repetition.id).not_to eq(first_child.id)
|
2022-11-29 11:30:06 +01:00
|
|
|
expect(subject.champs.first.dossier).to eq(subject)
|
2024-03-28 12:42:29 +01:00
|
|
|
expect(subject.champs.find(&:public?).dossier).to eq(subject)
|
2024-09-27 15:37:11 +02:00
|
|
|
expect(subject.project_champs_public.first.dossier).to eq(subject)
|
2022-11-29 11:30:06 +01:00
|
|
|
|
2024-09-27 15:37:11 +02:00
|
|
|
expect(subject.project_champs_public.first.type_de_champ.piece_justificative_template.attached?).to eq(false)
|
2022-11-29 11:30:06 +01:00
|
|
|
|
|
|
|
expect(subject.champs.first.conditional?).to eq(false)
|
2024-03-28 12:42:29 +01:00
|
|
|
expect(subject.champs.find(&:public?).conditional?).to eq(false)
|
2024-09-27 15:37:11 +02:00
|
|
|
expect(subject.project_champs_public.first.conditional?).to eq(false)
|
2022-11-29 11:30:06 +01:00
|
|
|
|
2022-10-04 17:31:58 +02:00
|
|
|
expect(first_child.parent).to eq(repetition)
|
2023-11-30 14:10:33 +01:00
|
|
|
expect(repetition.champs.first).to eq(first_child)
|
|
|
|
expect(repetition_optional.champs).to be_empty
|
2022-10-04 17:31:58 +02:00
|
|
|
end
|
|
|
|
|
2022-10-04 17:32:45 +02:00
|
|
|
expect(count).to eq(0)
|
2022-10-04 17:31:58 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|