diff --git a/app/helpers/zone_helper.rb b/app/helpers/zone_helper.rb index 8d529a2a7..7f04ad465 100644 --- a/app/helpers/zone_helper.rb +++ b/app/helpers/zone_helper.rb @@ -1,9 +1,12 @@ module ZoneHelper - def grouped_options_for_zone + def grouped_options_for_zone(date) collectivite = Zone.find_by(acronym: "COLLECTIVITE") { - "--" => [[I18n.t('i_dont_know', scope: 'utils'), nil], [collectivite.label, collectivite.id]], - I18n.t('ministeres', scope: 'zones') => (Zone.order(:label) - [collectivite]).map { |m| [m.label, m.id] } + "--" => [ + [I18n.t('i_dont_know', scope: 'utils'), nil], + [collectivite.label, collectivite.id] + ], + I18n.t('ministeres', scope: 'zones') => (Zone.available_at(date) - [collectivite]).map { |m| [m.label_at(date), m.id] } } end end diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 89bd58036..747b9c810 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -812,6 +812,10 @@ class Procedure < ApplicationRecord api_particulier_sources['mesri'].present? end + def published_or_created_at + published_at || created_at + end + private def move_new_children_to_new_parent_coordinate(new_draft) diff --git a/app/views/administrateurs/procedures/_informations.html.haml b/app/views/administrateurs/procedures/_informations.html.haml index 37ebe8e4f..695584dba 100644 --- a/app/views/administrateurs/procedures/_informations.html.haml +++ b/app/views/administrateurs/procedures/_informations.html.haml @@ -17,7 +17,7 @@ = f.label :zone do = t('zone', scope: 'activerecord.attributes.procedure') %span.mandatory * - = f.select :zone_id, grouped_options_for_zone + = f.select :zone_id, grouped_options_for_zone(@procedure.published_or_created_at) %h3.header-subsection Logo de la démarche = render Attachment::EditComponent.new(form: f, attached_file: @procedure.logo, direct_upload: true, user_can_destroy: true) diff --git a/spec/views/administrateurs/procedures/edit.html.haml_spec.rb b/spec/views/administrateurs/procedures/edit.html.haml_spec.rb index c43c6244c..3be2ce535 100644 --- a/spec/views/administrateurs/procedures/edit.html.haml_spec.rb +++ b/spec/views/administrateurs/procedures/edit.html.haml_spec.rb @@ -1,15 +1,58 @@ describe 'administrateurs/procedures/edit.html.haml' do let(:logo) { fixture_file_upload('spec/fixtures/files/logo_test_procedure.png', 'image/png') } let(:procedure) { create(:procedure, logo: logo, lien_site_web: 'http://some.website') } + let(:populate_zones_task) { Rake::Task['zones:populate_zones'] } before do - assign(:procedure, procedure) - render + Flipper.enable(:zonage) + populate_zones_task.invoke + end + + after do + populate_zones_task.reenable end context 'when procedure logo is present' do it 'display on the page' do + assign(:procedure, procedure) + render + expect(rendered).to have_selector('.procedure-logos') end end + + context 'when procedure has never been published' do + before { Timecop.freeze(now) } + after { Timecop.return } + + let(:procedure) { create(:procedure, zone: Zone.find_by(acronym: 'MTEI')) } + let(:now) { Time.zone.parse('18/05/2022') } + + it 'displays zones with label available at the creation date' do + assign(:procedure, procedure) + render + + expect(rendered).to have_content("Ministère du Travail") + expect(rendered).not_to have_content("Ministère du Travail, du Plein emploi et de l'Insertion") + end + end + + context 'when procedure has been published' do + before { Timecop.freeze(now) } + after { Timecop.return } + + let(:procedure) { create(:procedure, zone: Zone.find_by(acronym: 'MTEI')) } + let(:now) { Time.zone.parse('18/05/2022') } + + it 'displays zones with label available at the creation date' do + Timecop.freeze(Time.zone.parse('22/05/2022')) do + procedure.publish! + end + + assign(:procedure, procedure) + render + + expect(rendered).to have_content("Ministère du Travail, du Plein emploi et de l'Insertion") + end + end end