[#1421] Move departements to DepartementChamp

This commit is contained in:
Frederic Merizen 2018-06-15 14:36:48 +02:00 committed by Pierre de La Morinerie
parent 5b59bce0b6
commit 0239f936d7
6 changed files with 7 additions and 8 deletions

View file

@ -19,10 +19,6 @@ class Champ < ApplicationRecord
mandatory? && value.blank?
end
def self.departements
JSON.parse(Carto::GeoAPI::Driver.departements).map { |liste| "#{liste['code']} - #{liste['nom']}" }.push('99 - Étranger')
end
def self.pays
JSON.parse(Carto::GeoAPI::Driver.pays).pluck("nom")
end

View file

@ -1,2 +1,5 @@
class Champs::DepartementChamp < Champs::TextChamp
def self.departements
JSON.parse(Carto::GeoAPI::Driver.departements).map { |liste| "#{liste['code']} - #{liste['nom']}" }.push('99 - Étranger')
end
end

View file

@ -1,3 +1,3 @@
= form.select :value,
Champ.departements,
Champs::DepartementChamp.departements,
required: champ.mandatory?

View file

@ -1,2 +1,2 @@
= select_tag("champs['#{champ.id}']",
options_for_select(Champ.departements, selected: champ.object.value))
options_for_select(Champs::DepartementChamp.departements, selected: champ.object.value))

View file

@ -13,7 +13,7 @@ feature 'The user' do
# attached file works
scenario 'fill a dossier', js: true do
allow(Champs::RegionChamp).to receive(:regions).and_return(['region1', 'region2']).at_least(:once)
allow(Champ).to receive(:departements).and_return(['dep1', 'dep2']).at_least(:once)
allow(Champs::DepartementChamp).to receive(:departements).and_return(['dep1', 'dep2']).at_least(:once)
log_in(user.email, password, procedure)

View file

@ -27,7 +27,7 @@ shared_examples 'champ_spec' do
end
describe '.departement', vcr: { cassette_name: 'call_geo_api_departements' } do
subject { Champ.departements }
subject { Champs::DepartementChamp.departements }
it { expect(subject).to include '99 - Étranger' }
end