2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-02-02 10:07:16 +01:00
|
|
|
describe DossierRebaseConcern do
|
2022-05-20 10:19:09 +02:00
|
|
|
describe '#can_rebase?' do
|
2024-06-25 17:17:51 +02:00
|
|
|
let(:procedure) { create(:procedure, types_de_champ_public: [{ mandatory: true }, { type: :yes_no, mandatory: false }], types_de_champ_private: [{}]) }
|
2022-05-20 10:19:09 +02:00
|
|
|
let(:attestation_template) { procedure.draft_revision.attestation_template.find_or_revise! }
|
2022-11-16 12:46:33 +01:00
|
|
|
let(:type_de_champ) { procedure.active_revision.types_de_champ_public.find { |tdc| !tdc.mandatory? } }
|
2022-12-14 09:17:09 +01:00
|
|
|
let(:private_type_de_champ) { procedure.active_revision.types_de_champ_private.first }
|
2022-11-16 12:46:33 +01:00
|
|
|
let(:mandatory_type_de_champ) { procedure.active_revision.types_de_champ_public.find(&:mandatory?) }
|
2022-05-20 10:19:09 +02:00
|
|
|
|
2023-02-01 17:33:23 +01:00
|
|
|
context 'on unpublished procedure' do
|
|
|
|
context 'en_construction' do
|
|
|
|
let(:dossier) { create(:dossier, :en_construction, procedure: procedure) }
|
|
|
|
|
|
|
|
it 'should be false' do
|
|
|
|
expect(dossier.pending_changes).to be_empty
|
|
|
|
expect(dossier.can_rebase?).to be_falsey
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-05-20 10:19:09 +02:00
|
|
|
context 'en_construction' do
|
|
|
|
let(:dossier) { create(:dossier, :en_construction, procedure: procedure) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
procedure.publish!
|
|
|
|
procedure.reload
|
|
|
|
dossier
|
|
|
|
end
|
|
|
|
|
2024-06-25 17:17:51 +02:00
|
|
|
context 'with added non mandatory type de champ' do
|
2022-05-20 10:19:09 +02:00
|
|
|
before do
|
|
|
|
procedure.draft_revision.add_type_de_champ({
|
|
|
|
type_champ: TypeDeChamp.type_champs.fetch(:text),
|
2024-06-25 17:17:51 +02:00
|
|
|
libelle: "Un champ text",
|
|
|
|
mandatory: false
|
2022-05-20 10:19:09 +02:00
|
|
|
})
|
|
|
|
procedure.publish_revision!
|
|
|
|
dossier.reload
|
|
|
|
end
|
|
|
|
|
2022-12-14 09:17:09 +01:00
|
|
|
it 'should be true' do
|
|
|
|
expect(dossier.pending_changes).not_to be_empty
|
|
|
|
expect(dossier.can_rebase?).to be_truthy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with added mandatory type de champ' do
|
|
|
|
before do
|
|
|
|
procedure.draft_revision.add_type_de_champ({
|
|
|
|
type_champ: TypeDeChamp.type_champs.fetch(:text),
|
|
|
|
libelle: "Un champ text",
|
|
|
|
mandatory: true
|
|
|
|
})
|
|
|
|
procedure.publish_revision!
|
|
|
|
dossier.reload
|
|
|
|
end
|
|
|
|
|
2022-05-20 10:19:09 +02:00
|
|
|
it 'should be false' do
|
|
|
|
expect(dossier.pending_changes).not_to be_empty
|
|
|
|
expect(dossier.can_rebase?).to be_falsey
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with type de champ made optional' do
|
|
|
|
before do
|
2022-05-25 09:40:02 +02:00
|
|
|
procedure.draft_revision.find_and_ensure_exclusive_use(mandatory_type_de_champ.stable_id).update(mandatory: false)
|
2022-05-20 10:19:09 +02:00
|
|
|
procedure.publish_revision!
|
|
|
|
dossier.reload
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be true' do
|
|
|
|
expect(dossier.pending_changes).not_to be_empty
|
|
|
|
expect(dossier.can_rebase?).to be_truthy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with type de champ made mandatory' do
|
|
|
|
before do
|
2022-05-25 09:40:02 +02:00
|
|
|
procedure.draft_revision.find_and_ensure_exclusive_use(type_de_champ.stable_id).update(mandatory: true)
|
2022-05-20 10:19:09 +02:00
|
|
|
procedure.publish_revision!
|
|
|
|
dossier.reload
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be false' do
|
|
|
|
expect(dossier.pending_changes).not_to be_empty
|
|
|
|
expect(dossier.can_rebase?).to be_falsey
|
|
|
|
end
|
2022-12-22 13:08:04 +01:00
|
|
|
|
|
|
|
context 'with a value' do
|
|
|
|
before do
|
2024-07-01 15:31:32 +02:00
|
|
|
dossier.champs.find_by(stable_id: type_de_champ.stable_id).update(value: 'a value')
|
2022-12-22 13:08:04 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be true' do
|
|
|
|
expect(dossier.pending_changes).not_to be_empty
|
|
|
|
expect(dossier.can_rebase?).to be_truthy
|
|
|
|
end
|
|
|
|
end
|
2022-05-20 10:19:09 +02:00
|
|
|
end
|
|
|
|
|
2022-12-14 09:17:09 +01:00
|
|
|
context 'with type de champ change type' do
|
|
|
|
context 'type de champ public' do
|
|
|
|
before do
|
|
|
|
procedure.draft_revision.find_and_ensure_exclusive_use(type_de_champ.stable_id).update(type_champ: :checkbox)
|
|
|
|
procedure.publish_revision!
|
|
|
|
dossier.reload
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be false' do
|
|
|
|
expect(dossier.pending_changes).not_to be_empty
|
|
|
|
expect(dossier.can_rebase?).to be_falsey
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'type de champ private' do
|
|
|
|
before do
|
|
|
|
procedure.draft_revision.find_and_ensure_exclusive_use(private_type_de_champ.stable_id).update(type_champ: :checkbox)
|
|
|
|
procedure.publish_revision!
|
|
|
|
dossier.reload
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be true' do
|
|
|
|
expect(dossier.pending_changes).not_to be_empty
|
|
|
|
expect(dossier.can_rebase?).to be_truthy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-10-13 14:27:03 +02:00
|
|
|
context 'with type de champ regexp and regexp change' do
|
2024-06-25 17:17:51 +02:00
|
|
|
let(:procedure) { create(:procedure, types_de_champ_public: [{ mandatory: true }, { type: :expression_reguliere, mandatory: false }], types_de_champ_private: [{}]) }
|
2023-10-13 14:27:03 +02:00
|
|
|
|
|
|
|
before do
|
|
|
|
procedure.draft_revision.find_and_ensure_exclusive_use(type_de_champ.stable_id).update(expression_reguliere: /\d+/)
|
|
|
|
procedure.publish_revision!
|
|
|
|
dossier.reload
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be false' do
|
|
|
|
expect(dossier.pending_changes).not_to be_empty
|
|
|
|
expect(dossier.can_rebase?).to be_falsey
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-05-20 10:19:09 +02:00
|
|
|
context 'with removed type de champ' do
|
|
|
|
before do
|
|
|
|
procedure.draft_revision.remove_type_de_champ(type_de_champ.stable_id)
|
|
|
|
procedure.publish_revision!
|
|
|
|
dossier.reload
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be true' do
|
|
|
|
expect(dossier.pending_changes).not_to be_empty
|
|
|
|
expect(dossier.can_rebase?).to be_truthy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'en_instruction' do
|
|
|
|
let(:dossier) { create(:dossier, :en_instruction, procedure: procedure) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
procedure.publish!
|
|
|
|
procedure.reload
|
|
|
|
dossier
|
|
|
|
end
|
|
|
|
|
2024-06-25 17:17:51 +02:00
|
|
|
context 'with added non mandatory type de champ' do
|
2022-05-20 10:19:09 +02:00
|
|
|
before do
|
|
|
|
procedure.draft_revision.add_type_de_champ({
|
|
|
|
type_champ: TypeDeChamp.type_champs.fetch(:text),
|
2024-06-25 17:17:51 +02:00
|
|
|
libelle: "Un champ text",
|
|
|
|
mandatory: false
|
2022-05-20 10:19:09 +02:00
|
|
|
})
|
|
|
|
procedure.publish_revision!
|
|
|
|
dossier.reload
|
|
|
|
end
|
|
|
|
|
2022-12-14 09:17:09 +01:00
|
|
|
it 'should be true' do
|
2022-05-20 10:19:09 +02:00
|
|
|
expect(dossier.pending_changes).not_to be_empty
|
2022-12-14 09:17:09 +01:00
|
|
|
expect(dossier.can_rebase?).to be_truthy
|
2022-05-20 10:19:09 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-12-14 09:17:09 +01:00
|
|
|
context 'with added mandatory type de champ' do
|
2022-05-20 10:19:09 +02:00
|
|
|
before do
|
2022-12-14 09:17:09 +01:00
|
|
|
procedure.draft_revision.add_type_de_champ({
|
|
|
|
type_champ: TypeDeChamp.type_champs.fetch(:text),
|
|
|
|
libelle: "Un champ text",
|
|
|
|
mandatory: true
|
|
|
|
})
|
2022-05-20 10:19:09 +02:00
|
|
|
procedure.publish_revision!
|
|
|
|
dossier.reload
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be false' do
|
|
|
|
expect(dossier.pending_changes).not_to be_empty
|
|
|
|
expect(dossier.can_rebase?).to be_falsey
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with type de champ made optional' do
|
|
|
|
before do
|
2022-05-25 09:40:02 +02:00
|
|
|
procedure.draft_revision.find_and_ensure_exclusive_use(mandatory_type_de_champ.stable_id).update(mandatory: false)
|
2022-05-20 10:19:09 +02:00
|
|
|
procedure.publish_revision!
|
|
|
|
dossier.reload
|
|
|
|
end
|
|
|
|
|
2022-12-14 09:17:09 +01:00
|
|
|
it 'should be true' do
|
|
|
|
expect(dossier.pending_changes).not_to be_empty
|
|
|
|
expect(dossier.can_rebase?).to be_truthy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with type de champ made mandatory' do
|
|
|
|
before do
|
|
|
|
procedure.draft_revision.find_and_ensure_exclusive_use(type_de_champ.stable_id).update(mandatory: true)
|
|
|
|
procedure.publish_revision!
|
|
|
|
dossier.reload
|
|
|
|
end
|
|
|
|
|
2022-05-20 10:19:09 +02:00
|
|
|
it 'should be false' do
|
|
|
|
expect(dossier.pending_changes).not_to be_empty
|
|
|
|
expect(dossier.can_rebase?).to be_falsey
|
|
|
|
end
|
|
|
|
end
|
2022-12-14 09:17:09 +01:00
|
|
|
|
|
|
|
context 'with type de champ change type' do
|
|
|
|
context 'type de champ public' do
|
|
|
|
before do
|
|
|
|
procedure.draft_revision.find_and_ensure_exclusive_use(type_de_champ.stable_id).update(type_champ: :checkbox)
|
|
|
|
procedure.publish_revision!
|
|
|
|
dossier.reload
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be false' do
|
|
|
|
expect(dossier.pending_changes).not_to be_empty
|
|
|
|
expect(dossier.can_rebase?).to be_falsey
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'type de champ private' do
|
|
|
|
before do
|
|
|
|
procedure.draft_revision.find_and_ensure_exclusive_use(private_type_de_champ.stable_id).update(type_champ: :checkbox)
|
|
|
|
procedure.publish_revision!
|
|
|
|
dossier.reload
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be true' do
|
|
|
|
expect(dossier.pending_changes).not_to be_empty
|
|
|
|
expect(dossier.can_rebase?).to be_truthy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with removed type de champ' do
|
|
|
|
before do
|
|
|
|
procedure.draft_revision.remove_type_de_champ(type_de_champ.stable_id)
|
|
|
|
procedure.publish_revision!
|
|
|
|
dossier.reload
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be true' do
|
|
|
|
expect(dossier.pending_changes).not_to be_empty
|
|
|
|
expect(dossier.can_rebase?).to be_truthy
|
|
|
|
end
|
|
|
|
end
|
2022-05-20 10:19:09 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#rebase" do
|
2023-05-22 13:50:58 +02:00
|
|
|
let(:procedure) { create(:procedure, types_de_champ_public:, types_de_champ_private:) }
|
|
|
|
let(:types_de_champ_public) do
|
|
|
|
[
|
2023-02-07 10:37:03 +01:00
|
|
|
{ type: :text, mandatory: true, stable_id: 1 },
|
2023-01-31 12:32:11 +01:00
|
|
|
{
|
2023-02-02 09:59:03 +01:00
|
|
|
type: :repetition, stable_id: 101, mandatory: true, children: [
|
2023-01-31 12:32:11 +01:00
|
|
|
{ type: :text, stable_id: 102 }
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{ type: :datetime, stable_id: 103 },
|
|
|
|
{ type: :yes_no, stable_id: 104 },
|
|
|
|
{ type: :integer_number, stable_id: 105 }
|
2023-05-22 13:50:58 +02:00
|
|
|
]
|
2023-01-31 12:32:11 +01:00
|
|
|
end
|
2023-05-22 13:50:58 +02:00
|
|
|
let(:types_de_champ_private) { [{ type: :text, stable_id: 11 }] }
|
2023-07-07 14:06:10 +02:00
|
|
|
let(:dossier) { create(:dossier, :with_entreprise, procedure: procedure) }
|
2023-01-31 12:32:11 +01:00
|
|
|
let(:types_de_champ) { procedure.active_revision.types_de_champ }
|
2022-05-20 10:19:09 +02:00
|
|
|
|
2023-02-07 10:37:03 +01:00
|
|
|
let(:text_type_de_champ) { types_de_champ.find { _1.stable_id == 1 } }
|
2023-01-31 12:32:11 +01:00
|
|
|
let(:repetition_type_de_champ) { types_de_champ.find { _1.stable_id == 101 } }
|
|
|
|
let(:repetition_text_type_de_champ) { types_de_champ.find { _1.stable_id == 102 } }
|
|
|
|
let(:datetime_type_de_champ) { types_de_champ.find { _1.stable_id == 103 } }
|
|
|
|
let(:yes_no_type_de_champ) { types_de_champ.find { _1.stable_id == 104 } }
|
2022-05-20 10:19:09 +02:00
|
|
|
|
2024-09-27 15:37:11 +02:00
|
|
|
let(:text_champ) { dossier.project_champs_public.find { _1.stable_id == 1 } }
|
|
|
|
let(:repetition_champ) { dossier.project_champs_public.find { _1.stable_id == 101 } }
|
|
|
|
let(:datetime_champ) { dossier.project_champs_public.find { _1.stable_id == 103 } }
|
2023-01-26 17:58:41 +01:00
|
|
|
|
2024-09-27 15:37:11 +02:00
|
|
|
let(:rebased_text_champ) { dossier.project_champs_public.find { _1.stable_id == 1 } }
|
|
|
|
let(:rebased_repetition_champ) { dossier.project_champs_public.find { _1.stable_id == 101 } }
|
|
|
|
let(:rebased_datetime_champ) { dossier.project_champs_public.find { _1.stable_id == 103 } }
|
|
|
|
let(:rebased_number_champ) { dossier.project_champs_public.find { _1.stable_id == 105 } }
|
2022-05-20 10:19:09 +02:00
|
|
|
|
2024-09-27 15:37:11 +02:00
|
|
|
let(:rebased_new_repetition_champ) { dossier.project_champs_public.find { _1.libelle == "une autre repetition" } }
|
2022-05-20 10:19:09 +02:00
|
|
|
|
2023-03-22 11:42:58 +01:00
|
|
|
let(:private_text_type_de_champ) { types_de_champ.find { _1.stable_id == 11 } }
|
2024-09-27 15:37:11 +02:00
|
|
|
let(:rebased_private_text_champ) { dossier.project_champs_private.find { _1.stable_id == 11 } }
|
2023-03-22 11:42:58 +01:00
|
|
|
|
2023-05-22 13:50:58 +02:00
|
|
|
context "when revision is published" do
|
|
|
|
before do
|
|
|
|
procedure.publish!
|
|
|
|
procedure.draft_revision.add_type_de_champ({
|
|
|
|
type_champ: TypeDeChamp.type_champs.fetch(:text),
|
|
|
|
libelle: "Un champ text"
|
|
|
|
})
|
2024-07-25 18:29:01 +02:00
|
|
|
procedure.draft_revision.add_type_de_champ({
|
|
|
|
type_champ: TypeDeChamp.type_champs.fetch(:piece_justificative),
|
|
|
|
libelle: "Un champ pj"
|
|
|
|
})
|
2023-05-22 13:50:58 +02:00
|
|
|
procedure.draft_revision.find_and_ensure_exclusive_use(text_type_de_champ.stable_id).update(mandatory: false, libelle: "nouveau libelle")
|
|
|
|
procedure.draft_revision.find_and_ensure_exclusive_use(datetime_type_de_champ.stable_id).update(type_champ: TypeDeChamp.type_champs.fetch(:date))
|
|
|
|
procedure.draft_revision.find_and_ensure_exclusive_use(repetition_text_type_de_champ.stable_id).update(libelle: "nouveau libelle dans une repetition")
|
|
|
|
procedure.draft_revision.add_type_de_champ({
|
|
|
|
type_champ: TypeDeChamp.type_champs.fetch(:checkbox),
|
|
|
|
libelle: "oui ou non",
|
|
|
|
parent_stable_id: repetition_type_de_champ.stable_id
|
|
|
|
})
|
|
|
|
procedure.draft_revision.remove_type_de_champ(yes_no_type_de_champ.stable_id)
|
|
|
|
new_repetition_type_de_champ = procedure.draft_revision.add_type_de_champ({
|
|
|
|
type_champ: TypeDeChamp.type_champs.fetch(:repetition),
|
|
|
|
libelle: "une autre repetition",
|
|
|
|
mandatory: true
|
|
|
|
})
|
|
|
|
procedure.draft_revision.add_type_de_champ({
|
|
|
|
type_champ: TypeDeChamp.type_champs.fetch(:text),
|
|
|
|
libelle: "un champ text dans une autre repetition",
|
|
|
|
parent_stable_id: new_repetition_type_de_champ.stable_id
|
|
|
|
})
|
|
|
|
procedure.draft_revision.add_type_de_champ({
|
|
|
|
type_champ: TypeDeChamp.type_champs.fetch(:date),
|
|
|
|
libelle: "un champ date dans une autre repetition",
|
|
|
|
parent_stable_id: new_repetition_type_de_champ.stable_id
|
|
|
|
})
|
|
|
|
|
|
|
|
datetime_champ.update(value: Time.zone.now.to_s)
|
|
|
|
text_champ.update(value: 'bonjour')
|
2024-09-27 15:37:11 +02:00
|
|
|
text_champ.type_de_champ
|
2023-05-22 13:50:58 +02:00
|
|
|
# Add two rows then remove previous to last row in order to create a "hole" in the sequence
|
2024-08-27 10:29:10 +02:00
|
|
|
repetition_champ.add_row(updated_by: 'test')
|
|
|
|
repetition_champ.add_row(updated_by: 'test')
|
2024-09-27 15:44:57 +02:00
|
|
|
repetition_champ.dossier.champs.where(row_id: repetition_champ.row_ids[-2]).destroy_all
|
2024-09-27 15:37:11 +02:00
|
|
|
dossier.reload
|
2023-05-22 13:50:58 +02:00
|
|
|
end
|
2022-05-20 10:19:09 +02:00
|
|
|
|
2023-05-22 13:50:58 +02:00
|
|
|
it "updates the brouillon champs with the latest revision changes" do
|
|
|
|
expect(dossier.revision).to eq(procedure.published_revision)
|
2024-09-27 15:37:11 +02:00
|
|
|
expect(dossier.project_champs_public.size).to eq(5)
|
2024-03-28 12:42:29 +01:00
|
|
|
expect(dossier.champs.count(&:public?)).to eq(7)
|
2023-05-22 13:50:58 +02:00
|
|
|
expect(repetition_champ.rows.size).to eq(2)
|
|
|
|
expect(repetition_champ.rows[0].size).to eq(1)
|
|
|
|
expect(repetition_champ.rows[1].size).to eq(1)
|
2022-05-20 10:19:09 +02:00
|
|
|
|
2023-05-22 13:50:58 +02:00
|
|
|
procedure.publish_revision!
|
|
|
|
perform_enqueued_jobs
|
|
|
|
procedure.reload
|
|
|
|
dossier.reload
|
|
|
|
|
|
|
|
expect(procedure.revisions.size).to eq(3)
|
|
|
|
expect(dossier.revision).to eq(procedure.published_revision)
|
2024-09-27 15:37:11 +02:00
|
|
|
expect(dossier.project_champs_public.size).to eq(7)
|
2024-07-25 18:29:01 +02:00
|
|
|
expect(dossier.champs.count(&:public?)).to eq(13)
|
2023-05-22 13:50:58 +02:00
|
|
|
expect(rebased_text_champ.value).to eq(text_champ.value)
|
2024-07-01 15:31:32 +02:00
|
|
|
expect(rebased_text_champ.type_de_champ).not_to eq(text_champ.type_de_champ)
|
2023-05-22 13:50:58 +02:00
|
|
|
expect(rebased_datetime_champ.type_champ).to eq(TypeDeChamp.type_champs.fetch(:date))
|
|
|
|
expect(rebased_datetime_champ.value).to be_nil
|
|
|
|
expect(rebased_repetition_champ.rows.size).to eq(2)
|
|
|
|
expect(rebased_repetition_champ.rows[0].size).to eq(2)
|
|
|
|
expect(rebased_repetition_champ.rows[1].size).to eq(2)
|
|
|
|
expect(rebased_text_champ.rebased_at).not_to be_nil
|
|
|
|
expect(rebased_datetime_champ.rebased_at).not_to be_nil
|
|
|
|
expect(rebased_number_champ.rebased_at).to be_nil
|
|
|
|
expect(rebased_new_repetition_champ).not_to be_nil
|
|
|
|
expect(rebased_new_repetition_champ.rebased_at).not_to be_nil
|
|
|
|
expect(rebased_new_repetition_champ.rows.size).to eq(1)
|
|
|
|
expect(rebased_new_repetition_champ.rows[0].size).to eq(2)
|
|
|
|
|
|
|
|
dossier.passer_en_construction!
|
|
|
|
procedure.draft_revision.find_and_ensure_exclusive_use(private_text_type_de_champ.stable_id).update(type_champ: TypeDeChamp.type_champs.fetch(:textarea))
|
|
|
|
procedure.publish_revision!
|
|
|
|
perform_enqueued_jobs
|
|
|
|
procedure.reload
|
|
|
|
dossier.reload
|
2022-05-20 10:19:09 +02:00
|
|
|
|
2023-05-22 13:50:58 +02:00
|
|
|
expect(rebased_private_text_champ.type_champ).to eq(TypeDeChamp.type_champs.fetch(:textarea))
|
|
|
|
expect(rebased_private_text_champ.type).to eq("Champs::TextareaChamp")
|
|
|
|
end
|
|
|
|
end
|
2023-03-22 11:42:58 +01:00
|
|
|
|
2023-05-22 13:50:58 +02:00
|
|
|
context 'force rebase en construction' do
|
|
|
|
subject { dossier.rebase!(force: true) }
|
|
|
|
|
|
|
|
context 'procedure not published' do
|
|
|
|
let(:procedure) { create(:procedure, :draft, types_de_champ_public:, types_de_champ_private:) }
|
|
|
|
let(:dossier) { create(:dossier, :en_construction, procedure:) }
|
|
|
|
|
|
|
|
it 'is noop' do
|
2024-09-27 15:37:11 +02:00
|
|
|
expect { subject }.not_to change { dossier.reload.project_champs_public[0].rebased_at }
|
2023-05-22 13:50:58 +02:00
|
|
|
expect { subject }.not_to change { dossier.updated_at }
|
|
|
|
end
|
|
|
|
end
|
2022-05-20 10:19:09 +02:00
|
|
|
end
|
|
|
|
end
|
2022-05-20 11:55:20 +02:00
|
|
|
|
|
|
|
context 'small grained' do
|
|
|
|
subject do
|
|
|
|
procedure.publish_revision!
|
|
|
|
perform_enqueued_jobs
|
|
|
|
|
|
|
|
dossier.reload
|
|
|
|
end
|
|
|
|
|
2022-05-23 11:23:14 +02:00
|
|
|
context 'with a procedure with a dropdown tdc' do
|
|
|
|
let!(:procedure) do
|
|
|
|
create(:procedure).tap do |p|
|
2024-09-20 10:56:12 +02:00
|
|
|
p.draft_revision.add_type_de_champ(type_champ: :drop_down_list, libelle: 'l1', drop_down_options: ["option", "v1"])
|
2022-05-23 11:23:14 +02:00
|
|
|
p.publish!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
let!(:dossier) { create(:dossier, procedure: procedure) }
|
|
|
|
|
2023-01-06 12:57:15 +01:00
|
|
|
context 'when a dropdown option is added' do
|
2022-05-23 11:23:14 +02:00
|
|
|
before do
|
2024-09-27 15:37:11 +02:00
|
|
|
dossier.project_champs_public.first.update(value: 'v1')
|
2022-05-23 11:23:14 +02:00
|
|
|
|
|
|
|
stable_id = procedure.draft_revision.types_de_champ.find_by(libelle: 'l1')
|
2022-05-25 09:40:02 +02:00
|
|
|
tdc_to_update = procedure.draft_revision.find_and_ensure_exclusive_use(stable_id)
|
2024-09-20 10:56:12 +02:00
|
|
|
tdc_to_update.update(drop_down_options: ["option", "updated", "v1"])
|
2023-01-06 12:57:15 +01:00
|
|
|
end
|
|
|
|
|
2024-11-06 22:30:31 +01:00
|
|
|
it { expect { subject }.not_to change { dossier.project_champs_public.first.to_s } }
|
2023-01-06 12:57:15 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a dropdown option is removed' do
|
|
|
|
before do
|
2024-09-27 15:37:11 +02:00
|
|
|
dossier.project_champs_public.first.update(value: 'v1')
|
2023-01-06 12:57:15 +01:00
|
|
|
|
|
|
|
stable_id = procedure.draft_revision.types_de_champ.find_by(libelle: 'l1')
|
|
|
|
tdc_to_update = procedure.draft_revision.find_and_ensure_exclusive_use(stable_id)
|
2024-09-20 10:56:12 +02:00
|
|
|
tdc_to_update.update(drop_down_options: ["option", "updated"])
|
2022-05-23 11:23:14 +02:00
|
|
|
end
|
|
|
|
|
2024-11-06 22:30:31 +01:00
|
|
|
it { expect { subject }.to change { dossier.project_champs_public.first.to_s }.from('v1').to('') }
|
2022-05-23 11:23:14 +02:00
|
|
|
end
|
2023-01-06 12:57:15 +01:00
|
|
|
|
|
|
|
context 'when a dropdown unused option is removed' do
|
|
|
|
before do
|
2024-09-27 15:37:11 +02:00
|
|
|
dossier.project_champs_public.first.update(value: 'v1')
|
2023-01-06 12:57:15 +01:00
|
|
|
|
|
|
|
stable_id = procedure.draft_revision.types_de_champ.find_by(libelle: 'l1')
|
|
|
|
tdc_to_update = procedure.draft_revision.find_and_ensure_exclusive_use(stable_id)
|
2024-09-20 10:56:12 +02:00
|
|
|
tdc_to_update.update(drop_down_options: ["v1", "updated"])
|
2023-01-06 12:57:15 +01:00
|
|
|
end
|
|
|
|
|
2024-11-06 22:30:31 +01:00
|
|
|
it { expect { subject }.not_to change { dossier.project_champs_public.first.to_s } }
|
2023-01-06 12:57:15 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a procedure with a multiple dropdown tdc' do
|
|
|
|
let!(:procedure) do
|
|
|
|
create(:procedure).tap do |p|
|
2024-09-20 10:56:12 +02:00
|
|
|
p.draft_revision.add_type_de_champ(type_champ: :multiple_drop_down_list, libelle: 'l1', drop_down_options: ["option", "v1"])
|
2023-01-06 12:57:15 +01:00
|
|
|
p.publish!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
let!(:dossier) { create(:dossier, procedure: procedure) }
|
|
|
|
|
|
|
|
context 'when a dropdown option is added' do
|
|
|
|
before do
|
2024-09-27 15:37:11 +02:00
|
|
|
dossier.project_champs_public.first.update(value: '["v1"]')
|
2023-01-06 12:57:15 +01:00
|
|
|
|
|
|
|
stable_id = procedure.draft_revision.types_de_champ.find_by(libelle: 'l1')
|
|
|
|
tdc_to_update = procedure.draft_revision.find_and_ensure_exclusive_use(stable_id)
|
2024-09-20 10:56:12 +02:00
|
|
|
tdc_to_update.update(drop_down_options: ["option", "updated", "v1"])
|
2023-01-06 12:57:15 +01:00
|
|
|
end
|
|
|
|
|
2024-11-06 22:30:31 +01:00
|
|
|
it { expect { subject }.not_to change { dossier.project_champs_public.first.to_s } }
|
2023-01-06 12:57:15 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a dropdown option is removed' do
|
|
|
|
before do
|
2024-09-27 15:37:11 +02:00
|
|
|
dossier.project_champs_public.first.update(value: '["v1", "option"]')
|
2023-01-06 12:57:15 +01:00
|
|
|
|
|
|
|
stable_id = procedure.draft_revision.types_de_champ.find_by(libelle: 'l1')
|
|
|
|
tdc_to_update = procedure.draft_revision.find_and_ensure_exclusive_use(stable_id)
|
2024-09-20 10:56:12 +02:00
|
|
|
tdc_to_update.update(drop_down_options: ["option", "updated"])
|
2023-01-06 12:57:15 +01:00
|
|
|
end
|
|
|
|
|
2024-11-06 22:30:31 +01:00
|
|
|
it { expect { subject }.to change { dossier.project_champs_public.first.to_s }.from('v1, option').to('option') }
|
2023-01-06 12:57:15 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a dropdown unused option is removed' do
|
|
|
|
before do
|
2024-09-27 15:37:11 +02:00
|
|
|
dossier.project_champs_public.first.update(value: '["v1"]')
|
2023-01-06 12:57:15 +01:00
|
|
|
|
|
|
|
stable_id = procedure.draft_revision.types_de_champ.find_by(libelle: 'l1')
|
|
|
|
tdc_to_update = procedure.draft_revision.find_and_ensure_exclusive_use(stable_id)
|
2024-09-20 10:56:12 +02:00
|
|
|
tdc_to_update.update(drop_down_options: ["v1", "updated"])
|
2023-01-06 12:57:15 +01:00
|
|
|
end
|
|
|
|
|
2024-11-06 22:30:31 +01:00
|
|
|
it { expect { subject }.not_to change { dossier.project_champs_public.first.to_s } }
|
2023-01-06 12:57:15 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a procedure with a linked dropdown tdc' do
|
|
|
|
let!(:procedure) do
|
|
|
|
create(:procedure).tap do |p|
|
2024-09-20 10:56:12 +02:00
|
|
|
p.draft_revision.add_type_de_champ(type_champ: :linked_drop_down_list, libelle: 'l1', drop_down_options: ["--titre1--", "option", "v1", "--titre2--", "option2", "v2"])
|
2023-01-06 12:57:15 +01:00
|
|
|
p.publish!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
let!(:dossier) { create(:dossier, procedure: procedure) }
|
|
|
|
|
|
|
|
context 'when a dropdown option is added' do
|
|
|
|
before do
|
2024-11-06 22:30:31 +01:00
|
|
|
dossier.project_champs_public.first.update(value: '["titre1",""]')
|
2023-01-06 12:57:15 +01:00
|
|
|
|
|
|
|
stable_id = procedure.draft_revision.types_de_champ.find_by(libelle: 'l1')
|
|
|
|
tdc_to_update = procedure.draft_revision.find_and_ensure_exclusive_use(stable_id)
|
2024-09-20 10:56:12 +02:00
|
|
|
tdc_to_update.update(drop_down_options: ["--titre1--", "option", "v1", "updated", "--titre2--", "option2", "v2"])
|
2023-01-06 12:57:15 +01:00
|
|
|
end
|
|
|
|
|
2024-11-06 22:30:31 +01:00
|
|
|
it { expect { subject }.not_to change { dossier.project_champs_public.first.to_s } }
|
2023-01-06 12:57:15 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a dropdown option is removed' do
|
|
|
|
before do
|
2024-11-06 22:30:31 +01:00
|
|
|
dossier.project_champs_public.first.update(value: '["titre2","option2"]')
|
2023-01-06 12:57:15 +01:00
|
|
|
|
|
|
|
stable_id = procedure.draft_revision.types_de_champ.find_by(libelle: 'l1')
|
|
|
|
tdc_to_update = procedure.draft_revision.find_and_ensure_exclusive_use(stable_id)
|
2024-11-06 22:30:31 +01:00
|
|
|
tdc_to_update.update(drop_down_options: ["--titre1--", "option", "updated", "--titre2--", "v2"])
|
2023-01-06 12:57:15 +01:00
|
|
|
end
|
|
|
|
|
2024-11-06 22:30:31 +01:00
|
|
|
it { expect { subject }.to change { dossier.project_champs_public.first.to_s }.from('titre2 / option2').to('titre2') }
|
2023-01-06 12:57:15 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a dropdown unused option is removed' do
|
|
|
|
before do
|
2024-11-06 22:30:31 +01:00
|
|
|
dossier.project_champs_public.first.update(value: '["titre2",""]')
|
2023-01-06 12:57:15 +01:00
|
|
|
|
|
|
|
stable_id = procedure.draft_revision.types_de_champ.find_by(libelle: 'l1')
|
|
|
|
tdc_to_update = procedure.draft_revision.find_and_ensure_exclusive_use(stable_id)
|
2024-09-20 10:56:12 +02:00
|
|
|
tdc_to_update.update(drop_down_options: ["--titre1--", "v1", "updated", "--titre2--", "option2", "v2"])
|
2023-01-06 12:57:15 +01:00
|
|
|
end
|
|
|
|
|
2024-11-06 22:30:31 +01:00
|
|
|
it { expect { subject }.not_to change { dossier.project_champs_public.first.to_s } }
|
2023-01-06 12:57:15 +01:00
|
|
|
end
|
2022-05-23 11:23:14 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a procedure with a carte tdc' do
|
|
|
|
let!(:procedure) do
|
|
|
|
create(:procedure).tap do |p|
|
|
|
|
champ = p.draft_revision.add_type_de_champ(type_champ: :carte, libelle: 'l1', cadastres: true)
|
|
|
|
p.publish!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
let!(:dossier) { create(:dossier, procedure: procedure) }
|
|
|
|
|
|
|
|
context 'and the cadastre are removed' do
|
|
|
|
before do
|
2024-09-27 15:37:11 +02:00
|
|
|
dossier.project_champs_public.first.update(value: 'v1', geo_areas: [build(:geo_area, :cadastre)])
|
2022-05-23 11:23:14 +02:00
|
|
|
|
|
|
|
stable_id = procedure.draft_revision.types_de_champ.find_by(libelle: 'l1')
|
2022-05-25 09:40:02 +02:00
|
|
|
tdc_to_update = procedure.draft_revision.find_and_ensure_exclusive_use(stable_id)
|
2022-05-23 11:23:14 +02:00
|
|
|
tdc_to_update.update(cadastres: false)
|
|
|
|
end
|
|
|
|
|
2024-09-27 15:37:11 +02:00
|
|
|
it { expect { subject }.to change { dossier.project_champs_public.first.cadastres.count }.from(1).to(0) }
|
2022-05-23 11:23:14 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-05-20 11:55:20 +02:00
|
|
|
context 'with a procedure with 2 tdc' do
|
|
|
|
let!(:procedure) do
|
2024-01-23 09:52:20 +01:00
|
|
|
create(:procedure, :published, types_de_champ_public: [{ type: :text, libelle: 'l1' }, { type: :text, libelle: 'l2' }])
|
2022-05-20 11:55:20 +02:00
|
|
|
end
|
|
|
|
let!(:dossier) { create(:dossier, procedure: procedure) }
|
|
|
|
|
2024-02-16 12:02:24 +01:00
|
|
|
def champ_libelles = dossier.revision.types_de_champ_public.map(&:libelle)
|
2022-05-20 11:55:20 +02:00
|
|
|
|
|
|
|
context 'when a tdc is added in the middle' do
|
|
|
|
before do
|
|
|
|
added_tdc = procedure.draft_revision.add_type_de_champ(type_champ: :text, libelle: 'l3')
|
|
|
|
procedure.draft_revision.move_type_de_champ(added_tdc.stable_id, 1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect { subject }.to change { champ_libelles }.from(['l1', 'l2']).to(['l1', 'l3', 'l2']) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the first tdc is removed' do
|
|
|
|
before do
|
2022-05-23 11:23:14 +02:00
|
|
|
stable_id = procedure.draft_revision.types_de_champ.find_by(libelle: 'l1')
|
2022-05-25 09:40:02 +02:00
|
|
|
tdc_to_remove = procedure.draft_revision.find_and_ensure_exclusive_use(stable_id)
|
2022-05-20 11:55:20 +02:00
|
|
|
procedure.draft_revision.remove_type_de_champ(tdc_to_remove.stable_id)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect { subject }.to change { champ_libelles }.from(['l1', 'l2']).to(['l2']) }
|
|
|
|
end
|
|
|
|
|
2022-05-23 11:23:14 +02:00
|
|
|
context 'when the second tdc is moved at the first place' do
|
|
|
|
before do
|
|
|
|
stable_id = procedure.draft_revision.types_de_champ.find_by(libelle: 'l2')
|
|
|
|
procedure.draft_revision.move_type_de_champ(stable_id, 0)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect { subject }.to change { champ_libelles }.from(['l1', 'l2']).to(['l2', 'l1']) }
|
|
|
|
end
|
|
|
|
|
2022-05-20 11:55:20 +02:00
|
|
|
context 'when the first tdc libelle is updated' do
|
|
|
|
before do
|
2022-05-23 11:23:14 +02:00
|
|
|
stable_id = procedure.draft_revision.types_de_champ.find_by(libelle: 'l1')
|
2022-05-25 09:40:02 +02:00
|
|
|
tdc_to_update = procedure.draft_revision.find_and_ensure_exclusive_use(stable_id)
|
2022-05-20 11:55:20 +02:00
|
|
|
tdc_to_update.update(libelle: 'l1 updated')
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect { subject }.to change { champ_libelles }.from(['l1', 'l2']).to(['l1 updated', 'l2']) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the first tdc type is updated' do
|
2024-09-27 15:37:11 +02:00
|
|
|
def first_champ = dossier.project_champs_public.first
|
2022-05-23 11:23:14 +02:00
|
|
|
|
2022-05-20 11:55:20 +02:00
|
|
|
before do
|
2024-07-01 15:31:32 +02:00
|
|
|
first_champ.update(value: 'v1', external_id: '123', geo_areas: [build(:geo_area)])
|
2022-05-23 11:23:14 +02:00
|
|
|
first_champ.update(data: { a: 1 })
|
|
|
|
|
|
|
|
first_champ.piece_justificative_file.attach(
|
|
|
|
io: StringIO.new("toto"),
|
|
|
|
filename: "toto.txt",
|
|
|
|
content_type: "text/plain",
|
|
|
|
# we don't want to run virus scanner on this file
|
|
|
|
metadata: { virus_scan_result: ActiveStorage::VirusScanner::SAFE }
|
|
|
|
)
|
|
|
|
|
2022-05-24 15:14:14 +02:00
|
|
|
first_champ.update_column('updated_at', Time.zone.parse('01/01/1901'))
|
|
|
|
|
2022-05-23 11:23:14 +02:00
|
|
|
stable_id = procedure.draft_revision.types_de_champ.find_by(libelle: 'l1')
|
2022-05-25 09:40:02 +02:00
|
|
|
tdc_to_update = procedure.draft_revision.find_and_ensure_exclusive_use(stable_id)
|
2022-05-20 11:55:20 +02:00
|
|
|
tdc_to_update.update(type_champ: :integer_number)
|
|
|
|
end
|
|
|
|
|
2024-02-16 12:02:24 +01:00
|
|
|
it { expect { subject }.to change { dossier.revision.types_de_champ_public.map(&:type_champ) }.from(['text', 'text']).to(['integer_number', 'text']) }
|
2022-05-23 11:23:14 +02:00
|
|
|
it { expect { subject }.to change { first_champ.class }.from(Champs::TextChamp).to(Champs::IntegerNumberChamp) }
|
2024-11-06 22:30:31 +01:00
|
|
|
it { expect { subject }.to change { first_champ.to_s }.from('v1').to('') }
|
2022-05-23 11:23:14 +02:00
|
|
|
it { expect { subject }.to change { first_champ.external_id }.from('123').to(nil) }
|
|
|
|
it { expect { subject }.to change { first_champ.data }.from({ 'a' => 1 }).to(nil) }
|
|
|
|
it { expect { subject }.to change { first_champ.geo_areas.count }.from(1).to(0) }
|
|
|
|
it { expect { subject }.to change { first_champ.piece_justificative_file.attached? }.from(true).to(false) }
|
2022-12-14 09:17:09 +01:00
|
|
|
it { expect { subject }.not_to change { first_champ.updated_at }.from(Time.zone.parse('01/01/1901')) }
|
2022-05-20 11:55:20 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a procedure with a repetition' do
|
|
|
|
let!(:procedure) do
|
2024-01-23 09:52:20 +01:00
|
|
|
create(:procedure, :published, types_de_champ_public: [
|
|
|
|
{
|
|
|
|
type: :repetition,
|
|
|
|
libelle: 'p1',
|
|
|
|
mandatory: true,
|
|
|
|
children: [
|
|
|
|
{ type: :text, libelle: 'c1' },
|
|
|
|
{ type: :text, libelle: 'c2' }
|
|
|
|
]
|
|
|
|
}
|
|
|
|
])
|
2022-05-20 11:55:20 +02:00
|
|
|
end
|
|
|
|
let!(:dossier) { create(:dossier, procedure: procedure) }
|
2024-01-23 09:52:20 +01:00
|
|
|
let(:repetition) { procedure.draft_revision.types_de_champ.find(&:repetition?) }
|
2022-05-20 11:55:20 +02:00
|
|
|
|
2024-02-16 12:02:24 +01:00
|
|
|
def child_libelles = dossier.revision.revision_types_de_champ_public.first.revision_types_de_champ.map(&:libelle)
|
|
|
|
def child_types_champ = dossier.revision.revision_types_de_champ_public.first.revision_types_de_champ.map(&:type_champ)
|
2022-05-20 11:55:20 +02:00
|
|
|
|
|
|
|
context 'when a child tdc is added in the middle' do
|
|
|
|
before do
|
2024-01-23 09:52:20 +01:00
|
|
|
last_child = procedure.draft_revision.children_of(repetition).last
|
|
|
|
added_tdc = procedure.draft_revision.add_type_de_champ(type_champ: :text, libelle: 'c3', parent_stable_id: repetition.stable_id, after_stable_id: last_child)
|
2022-05-20 11:55:20 +02:00
|
|
|
procedure.draft_revision.move_type_de_champ(added_tdc.stable_id, 1)
|
2024-01-23 09:52:20 +01:00
|
|
|
# procedure.publish_revision!
|
2022-05-20 11:55:20 +02:00
|
|
|
end
|
|
|
|
|
2024-01-23 09:52:20 +01:00
|
|
|
it 'does somehting' do
|
|
|
|
expect { subject }.to change { child_libelles }.from(['c1', 'c2']).to(['c1', 'c3', 'c2'])
|
|
|
|
end
|
2022-05-20 11:55:20 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the first child tdc is removed' do
|
|
|
|
before do
|
|
|
|
tdc_to_remove = procedure.draft_revision.types_de_champ.find_by(libelle: 'c1')
|
|
|
|
procedure.draft_revision.remove_type_de_champ(tdc_to_remove.stable_id)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect { subject }.to change { child_libelles }.from(['c1', 'c2']).to(['c2']) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the first child libelle tdc is updated' do
|
|
|
|
before do
|
|
|
|
stable_id = procedure.draft_revision.types_de_champ.find_by(libelle: 'c1')
|
2022-05-25 09:40:02 +02:00
|
|
|
tdc_to_update = procedure.draft_revision.find_and_ensure_exclusive_use(stable_id)
|
2022-05-20 11:55:20 +02:00
|
|
|
tdc_to_update.update(libelle: 'c1 updated')
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect { subject }.to change { child_libelles }.from(['c1', 'c2']).to(['c1 updated', 'c2']) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the first child tdc type is updated' do
|
|
|
|
before do
|
|
|
|
stable_id = procedure.draft_revision.types_de_champ.find_by(libelle: 'c1')
|
2022-05-25 09:40:02 +02:00
|
|
|
tdc_to_update = procedure.draft_revision.find_and_ensure_exclusive_use(stable_id)
|
2022-05-20 11:55:20 +02:00
|
|
|
tdc_to_update.update(type_champ: :integer_number)
|
|
|
|
end
|
|
|
|
|
2024-02-16 12:02:24 +01:00
|
|
|
it { expect { subject }.to change { child_types_champ }.from(['text', 'text']).to(['integer_number', 'text']) }
|
2022-05-20 11:55:20 +02:00
|
|
|
end
|
2022-05-23 11:23:14 +02:00
|
|
|
|
|
|
|
context 'when the parents type is changed' do
|
|
|
|
before do
|
|
|
|
stable_id = procedure.draft_revision.types_de_champ.find_by(libelle: 'p1')
|
2022-05-25 09:40:02 +02:00
|
|
|
parent = procedure.draft_revision.find_and_ensure_exclusive_use(stable_id)
|
2022-05-23 11:23:14 +02:00
|
|
|
parent.update(type_champ: :integer_number)
|
|
|
|
end
|
|
|
|
|
2024-09-27 15:44:57 +02:00
|
|
|
it { expect { subject }.to change { dossier.champs.filter(&:child?).count }.from(2).to(0) }
|
2022-05-23 11:23:14 +02:00
|
|
|
it { expect { subject }.to change { Champ.count }.from(3).to(1) }
|
2024-11-06 22:30:31 +01:00
|
|
|
it { expect { subject }.to change { dossier.project_champs_public.find(&:repetition?)&.libelle }.from('p1').to(nil) }
|
2022-05-23 11:23:14 +02:00
|
|
|
end
|
2022-05-20 11:55:20 +02:00
|
|
|
end
|
|
|
|
end
|
2022-05-20 10:19:09 +02:00
|
|
|
end
|