determine default zones according to tchap hs
This commit is contained in:
parent
d0ca05259a
commit
3705dc2553
3 changed files with 20 additions and 0 deletions
|
@ -33,4 +33,9 @@ class Zone < ApplicationRecord
|
|||
OpenStruct.new(id: zone.id, label: zone.label_at(date))
|
||||
end
|
||||
end
|
||||
|
||||
def self.default_for(tchap_hs)
|
||||
sanitized_sql = ActiveRecord::Base.sanitize_sql "'#{tchap_hs}' = ANY (tchap_hs)"
|
||||
Zone.where(sanitized_sql)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
FactoryBot.define do
|
||||
factory :zone do
|
||||
sequence(:acronym) { |n| "MA#{n}" }
|
||||
tchap_hs { ['agent.educpop.tchap.gouv.fr'] }
|
||||
transient do
|
||||
labels { [{ designated_on: '1981-05-08', name: "Ministère de l'Education Populaire" }] }
|
||||
end
|
||||
|
|
|
@ -118,4 +118,18 @@ describe Zone do
|
|||
expect(Zone.available_at(start_previous_government + 1.day).map(&:label)).to eq ["Ministère de la Culture", "Ministère des Outre-mer"]
|
||||
end
|
||||
end
|
||||
|
||||
context 'with zones' do
|
||||
before do
|
||||
create(:zone, acronym: 'MEN', tchap_hs: ['agent.education.tchap.gouv.fr'])
|
||||
create(:zone, acronym: 'ESR', tchap_hs: ['agent.education.tchap.gouv.fr'])
|
||||
end
|
||||
|
||||
describe "#self.default_for" do
|
||||
it 'returns zone related to tchap hs' do
|
||||
expect(Zone.default_for('agent.education.tchap.gouv.fr').map(&:acronym)).to eq ['MEN', 'ESR']
|
||||
expect(Zone.default_for('agent.tchap.gouv.fr').map(&:acronym)).to eq []
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue