2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2021-06-16 10:48:15 +02:00
|
|
|
describe ProcedurePresentation do
|
|
|
|
describe "#types_de_champ_for_procedure_presentation" do
|
2021-10-22 12:18:43 +02:00
|
|
|
subject { procedure.types_de_champ_for_procedure_presentation.not_repetition.pluck(:libelle) }
|
2021-06-16 10:48:15 +02:00
|
|
|
|
|
|
|
context 'for a draft procedure' do
|
2024-01-23 09:52:20 +01:00
|
|
|
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :number, libelle: 'libelle 1' }]) }
|
2021-06-16 10:48:15 +02:00
|
|
|
|
2022-05-02 10:48:05 +02:00
|
|
|
context 'when there are one tdc on a draft revision' do
|
2021-06-16 10:48:15 +02:00
|
|
|
it { is_expected.to match(['libelle 1']) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for a published procedure' do
|
2024-01-23 09:52:20 +01:00
|
|
|
let(:procedure) { create(:procedure, :published, types_de_champ_public: []) }
|
|
|
|
let!(:tdc) { procedure.draft_revision.add_type_de_champ({ type_champ: :number, libelle: 'libelle 1' }) }
|
2021-06-16 10:48:15 +02:00
|
|
|
|
|
|
|
before do
|
|
|
|
procedure.publish_revision!
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to match(['libelle 1']) }
|
|
|
|
|
|
|
|
context 'when there is another published revision with an added tdc' do
|
2024-01-23 09:52:20 +01:00
|
|
|
let(:added_tdc) { { type_champ: :number, libelle: 'libelle 2', after_stable_id: tdc.stable_id } }
|
2021-06-16 10:48:15 +02:00
|
|
|
|
|
|
|
before do
|
|
|
|
procedure.draft_revision.add_type_de_champ(added_tdc)
|
|
|
|
procedure.publish_revision!
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to match(['libelle 1', 'libelle 2']) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'add one tdc above the first one' do
|
2022-05-02 10:48:05 +02:00
|
|
|
let(:tdc0) { { type_champ: :number, libelle: 'libelle 0' } }
|
2021-06-16 10:48:15 +02:00
|
|
|
|
|
|
|
before do
|
2022-05-02 10:48:05 +02:00
|
|
|
created_tdc0 = procedure.draft_revision.add_type_de_champ(tdc0)
|
2022-05-11 20:22:52 +02:00
|
|
|
procedure.draft_revision.reload.move_type_de_champ(created_tdc0.stable_id, 0)
|
2021-06-16 10:48:15 +02:00
|
|
|
procedure.publish_revision!
|
|
|
|
end
|
|
|
|
|
2022-05-02 10:48:05 +02:00
|
|
|
it { is_expected.to match(['libelle 0', 'libelle 1']) }
|
2021-06-16 10:48:15 +02:00
|
|
|
|
2021-11-12 08:27:02 +01:00
|
|
|
context 'and finally, when this tdc is removed' do
|
2022-05-02 10:48:05 +02:00
|
|
|
let!(:previous_tdc0) { procedure.published_revision.types_de_champ_public.find_by(libelle: 'libelle 0') }
|
2021-06-16 10:48:15 +02:00
|
|
|
|
|
|
|
before do
|
2022-05-02 10:48:05 +02:00
|
|
|
procedure.draft_revision.remove_type_de_champ(previous_tdc0.stable_id)
|
2021-06-16 10:48:15 +02:00
|
|
|
|
|
|
|
procedure.publish_revision!
|
|
|
|
end
|
|
|
|
|
2022-05-02 10:48:05 +02:00
|
|
|
it { is_expected.to match(['libelle 1', 'libelle 0']) }
|
2021-06-16 10:48:15 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there is another published revision with a renamed tdc' do
|
2022-04-28 14:25:49 +02:00
|
|
|
let!(:previous_tdc) { procedure.published_revision.types_de_champ_public.first }
|
2021-06-16 10:48:15 +02:00
|
|
|
let!(:changed_tdc) { { type_champ: :number, libelle: 'changed libelle 1' } }
|
|
|
|
|
|
|
|
before do
|
2022-05-25 09:40:02 +02:00
|
|
|
type_de_champ = procedure.draft_revision.find_and_ensure_exclusive_use(previous_tdc.id)
|
2021-06-16 10:48:15 +02:00
|
|
|
type_de_champ.update(changed_tdc)
|
|
|
|
|
|
|
|
procedure.publish_revision!
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to match(['changed libelle 1']) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|