-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🛠️ Zones | Add LAST_ZONE and Remove N+1 for zones queries
- Loading branch information
1 parent
d61078d
commit 19fb7de
Showing
5 changed files
with
82 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 34 additions & 29 deletions
63
spec/views/administrateurs/procedures/zones.html.haml_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,57 @@ | ||
# frozen_string_literal: true | ||
|
||
describe 'administrateurs/procedures/zones' do | ||
let(:administrateur) { administrateurs(:default_admin) } | ||
let(:procedure) { create(:procedure) } | ||
let(:populate_zones_task) { Rake::Task['after_party:populate_zones_with_tchap_hs'] } | ||
require 'rails_helper' | ||
|
||
RSpec.describe 'administrateurs/procedures/zones', type: :view do | ||
let(:administrateur) { create(:administrateur) } | ||
let(:procedure) { create(:procedure, published_at: Time.zone.parse('2022-07-20')) } # Définir une date de publication de la procédure plus tardive | ||
let!(:zone1) { create(:zone, acronym: 'MTEI', labels: [{ designated_on: '2022-05-18', name: "Ministère du Travail" }]) } | ||
let!(:zone2) { create(:zone, acronym: 'MEP', labels: [{ designated_on: '2022-05-18', name: "Ministère des vacances" }]) } | ||
|
||
before do | ||
Rails.application.config.ds_zonage_enabled = true | ||
populate_zones_task.invoke | ||
allow(view).to receive(:current_administrateur).and_return(administrateur) | ||
assign(:procedure, procedure) | ||
assign(:zones, Zone.available_at(procedure.published_or_created_at, administrateur.default_zones)) | ||
end | ||
|
||
after do | ||
populate_zones_task.reenable | ||
it 'affiche le titre de la page' do | ||
render | ||
expect(rendered).to include('Zones') | ||
end | ||
|
||
context 'when procedure has never been published' do | ||
before { Timecop.freeze(now) } | ||
after { Timecop.return } | ||
it 'affiche les zones par défaut de l’administrateur' do | ||
allow(administrateur).to receive(:default_zones).and_return([zone1]) | ||
assign(:zones, Zone.available_at(procedure.published_or_created_at, administrateur.default_zones)) | ||
render | ||
|
||
let(:procedure) { create(:procedure, zones: [Zone.find_by(acronym: 'MTEI')]) } | ||
let(:now) { Time.zone.parse('18/05/2022') } | ||
expect(rendered).to match(/Ministère du Travail/) | ||
end | ||
|
||
it 'displays zones with label available at the creation date' do | ||
assign(:procedure, procedure) | ||
render | ||
it 'affiche toutes les zones disponibles' do | ||
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 | ||
expect(rendered).to match(/Ministère du Travail/) | ||
expect(rendered).to match(/Ministère des vacances/) | ||
end | ||
|
||
context 'when procedure has been published' do | ||
before { Timecop.freeze(now) } | ||
after { Timecop.return } | ||
it 'affiche les actions en bas de page' do | ||
render | ||
|
||
let(:procedure) { create(:procedure, zones: [Zone.find_by(acronym: 'MTEI')]) } | ||
let(:now) { Time.zone.parse('18/05/2022') } | ||
expect(rendered).to include('Annuler') | ||
expect(rendered).to include('Enregistrer') | ||
end | ||
|
||
it 'displays zones with label available at the creation date' do | ||
Timecop.freeze(Time.zone.parse('22/05/2022')) do | ||
procedure.publish! | ||
end | ||
context 'quand le zonage est désactivé' do | ||
before do | ||
Rails.application.config.ds_zonage_enabled = false | ||
end | ||
|
||
assign(:procedure, procedure) | ||
it 'n’affiche pas les zones' do | ||
render | ||
|
||
expect(rendered).to have_content("Ministère du Travail, du Plein emploi et de l'Insertion") | ||
expect(rendered).not_to match(/Ministère du Travail/) | ||
expect(rendered).not_to match(/Ministère des vacances/) | ||
end | ||
end | ||
end |