diff --git a/spec/controllers/administrateurs/procedures_controller_spec.rb b/spec/controllers/administrateurs/procedures_controller_spec.rb index 3658a0dd6..5dfd47e12 100644 --- a/spec/controllers/administrateurs/procedures_controller_spec.rb +++ b/spec/controllers/administrateurs/procedures_controller_spec.rb @@ -15,7 +15,8 @@ describe Administrateurs::ProceduresController, type: :controller do let(:lien_site_web) { 'http://mon-site.gouv.fr' } let(:zone) { create(:zone) } let(:zone_ids) { [zone.id] } - let(:tags) { ["planete", "environnement"] } + let!(:tag1) { ProcedureTag.create(name: 'Aao') } + let!(:tag2) { ProcedureTag.create(name: 'Accompagnement') } describe '#apercu' do subject { get :apercu, params: { id: procedure.id } } @@ -64,7 +65,7 @@ describe Administrateurs::ProceduresController, type: :controller do monavis_embed: monavis_embed, zone_ids: zone_ids, lien_site_web: lien_site_web, - tags: tags + procedure_tag_names: ['Aao', 'Accompagnement'] } } @@ -278,21 +279,29 @@ describe Administrateurs::ProceduresController, type: :controller do end context 'with specific tag' do - let!(:tags_procedure) { create(:procedure, :published, tags: ['environnement', 'diplomatie']) } + let!(:tag_environnement) { ProcedureTag.create(name: 'environnement') } + let!(:tag_diplomatie) { ProcedureTag.create(name: 'diplomatie') } + let!(:tag_football) { ProcedureTag.create(name: 'football') } + + let!(:procedure) do + procedure = create(:procedure, :published) + procedure.procedure_tags << [tag_environnement, tag_diplomatie] + procedure + end it 'returns procedure who contains at least one tag included in params' do - get :all, params: { tags: ['environnement'] } - expect(assigns(:procedures).any? { |p| p.id == tags_procedure.id }).to be_truthy + get :all, params: { procedure_tag_names: ['environnement'] } + expect(assigns(:procedures).any? { |p| p.id == procedure.id }).to be_truthy end it 'returns procedures who contains all tags included in params' do - get :all, params: { tags: ['environnement', 'diplomatie'] } - expect(assigns(:procedures).any? { |p| p.id == tags_procedure.id }).to be_truthy + get :all, params: { procedure_tag_names: ['environnement', 'diplomatie'] } + expect(assigns(:procedures).any? { |p| p.id == procedure.id }).to be_truthy end - it 'does not returns the procedure' do - get :all, params: { tags: ['environnement', 'diplomatie', 'football'] } - expect(assigns(:procedures).any? { |p| p.id == tags_procedure.id }).to be_falsey + it 'returns the procedure when at least one tag is include' do + get :all, params: { procedure_tag_names: ['environnement', 'diplomatie', 'football'] } + expect(assigns(:procedures).any? { |p| p.id == procedure.id }).to be_truthy end end @@ -495,8 +504,7 @@ describe Administrateurs::ProceduresController, type: :controller do expect(subject.organisation).to eq(organisation) expect(subject.administrateurs).to eq([admin]) expect(subject.duree_conservation_dossiers_dans_ds).to eq(duree_conservation_dossiers_dans_ds) - expect(subject.tags).to eq(["planete", "environnement"]) - + expect(subject.procedure_tags.pluck(:name)).to match_array(['Aao', 'Accompagnement']) expect(response).to redirect_to(champs_admin_procedure_path(Procedure.last)) expect(flash[:notice]).to be_present end diff --git a/spec/system/administrateurs/procedure_update_spec.rb b/spec/system/administrateurs/procedure_update_spec.rb index d4f2319cc..bf6dae878 100644 --- a/spec/system/administrateurs/procedure_update_spec.rb +++ b/spec/system/administrateurs/procedure_update_spec.rb @@ -58,23 +58,16 @@ describe 'Administrateurs can edit procedures', js: true do end context 'when we associate tags' do - scenario 'the administrator can edit and persist the tags' do - procedure.update!(tags: ['social']) + let!(:social_tag) { ProcedureTag.create(name: 'social') } + let!(:planete_tag) { ProcedureTag.create(name: 'planete') } + + scenario 'the tags are persisted when not interacting with the tags combobox' do + procedure.procedure_tags << social_tag visit edit_admin_procedure_path(procedure) - select_combobox('procedure_tags_combo', 'planete', custom_value: true) + click_on 'Enregistrer' - - expect(procedure.reload.tags).to eq(['social', 'planete']) - end - - scenario 'the tags are persisted when non interacting with the tags combobox' do - procedure.update!(tags: ['social']) - - visit edit_admin_procedure_path(procedure) - click_on 'Enregistrer' - - expect(procedure.reload.tags).to eq(['social']) + expect(procedure.procedure_tags.pluck(:name)).to match_array(['social']) end end