[#1421] Move regions to RegionChamp

This commit is contained in:
Frederic Merizen 2018-06-15 14:35:49 +02:00 committed by Pierre de La Morinerie
parent 95666238ea
commit 5b59bce0b6
5 changed files with 6 additions and 7 deletions

View file

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

View file

@ -1,2 +1,5 @@
class Champs::RegionChamp < Champs::TextChamp
def self.regions
JSON.parse(Carto::GeoAPI::Driver.regions).sort_by { |e| e['nom'] }.pluck("nom")
end
end

View file

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

View file

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

View file

@ -12,7 +12,7 @@ feature 'The user' do
# there are no extraneous input
# attached file works
scenario 'fill a dossier', js: true do
allow(Champ).to receive(:regions).and_return(['region1', 'region2']).at_least(:once)
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)
log_in(user.email, password, procedure)