demarches-normaliennes/spec/services/update_zone_to_procedures_service_spec.rb
Christophe Robillard f9609b0b0b fix zone specs
by reenabling task before the next spec is run
2021-12-23 09:58:31 +01:00

57 lines
1.5 KiB
Ruby

describe UpdateZoneToProceduresService do
before(:each) do
Rake::Task['zones:populate_zones'].invoke
end
after(:each) do
Rake::Task['zones:populate_zones'].reenable
end
describe '#call' do
let(:procedure1) { create(:procedure, zone: nil) }
let(:procedure2) { create(:procedure, zone: nil) }
subject { described_class.call(lines) }
context 'nominal case' do
let(:lines) do
[
{ "id" => procedure1.id, "POL_PUB_MINISTERE RATTACHEMENT" => "PM" },
{ "id" => procedure2.id, "POL_PUB_MINISTERE RATTACHEMENT" => "MI" }
]
end
it 'updates zone to procedures' do
errors = subject
expect(errors).to eq []
expect(procedure1.reload.zone.acronym).to eq("PM")
expect(procedure2.reload.zone.acronym).to eq("MI")
end
end
context 'with unknown procedure' do
let(:lines) do
[
{ "id" => procedure1.id + procedure2.id, "POL_PUB_MINISTERE RATTACHEMENT" => "PM" }
]
end
it 'returns errors' do
errors = subject
expect(errors).to eq ["Procedure #{procedure1.id + procedure2.id} introuvable"]
end
end
context 'with unknown zone' do
let(:lines) do
[
{ "id" => procedure1.id, "POL_PUB_MINISTERE RATTACHEMENT" => "YOUPI" }
]
end
it 'returns errors' do
errors = subject
expect(errors).to eq ["Zone YOUPI introuvable"]
end
end
end
end