Skip to content

Commit

Permalink
Mise à jour des tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kara22 committed Oct 11, 2024
1 parent fc8a992 commit 484e762
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 25 deletions.
32 changes: 20 additions & 12 deletions spec/controllers/administrateurs/procedures_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
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 } }
Expand Down Expand Up @@ -64,7 +65,7 @@
monavis_embed: monavis_embed,
zone_ids: zone_ids,
lien_site_web: lien_site_web,
tags: tags
procedure_tag_names: ['Aao', 'Accompagnement']
}
}

Expand Down Expand Up @@ -278,21 +279,29 @@
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

Expand Down Expand Up @@ -495,8 +504,7 @@
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
Expand Down
19 changes: 6 additions & 13 deletions spec/system/administrateurs/procedure_update_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,16 @@
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') }

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'])
scenario 'the tags are persisted when not interacting with the tags combobox' do
procedure.procedure_tags << social_tag

visit edit_admin_procedure_path(procedure)
click_on 'Enregistrer'

expect(procedure.reload.tags).to eq(['social'])
click_on 'Enregistrer'
expect(procedure.procedure_tags.pluck(:name)).to match_array(['social'])
end
end

Expand Down

0 comments on commit 484e762

Please sign in to comment.