From 5b59bce0b616937c0de9e3666f99983abee1e63a Mon Sep 17 00:00:00 2001 From: Frederic Merizen Date: Fri, 15 Jun 2018 14:35:49 +0200 Subject: [PATCH] [#1421] Move regions to RegionChamp --- app/models/champ.rb | 4 ---- app/models/champs/region_champ.rb | 3 +++ app/views/shared/dossiers/editable_champs/_regions.html.haml | 2 +- app/views/users/description/champs/_regions.html.haml | 2 +- spec/features/new_user/dossier_spec.rb | 2 +- 5 files changed, 6 insertions(+), 7 deletions(-) diff --git a/app/models/champ.rb b/app/models/champ.rb index 89efe8f10..e22cb1625 100644 --- a/app/models/champ.rb +++ b/app/models/champ.rb @@ -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 diff --git a/app/models/champs/region_champ.rb b/app/models/champs/region_champ.rb index ba9045087..8c5320c29 100644 --- a/app/models/champs/region_champ.rb +++ b/app/models/champs/region_champ.rb @@ -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 diff --git a/app/views/shared/dossiers/editable_champs/_regions.html.haml b/app/views/shared/dossiers/editable_champs/_regions.html.haml index b947a8d31..460a4b1af 100644 --- a/app/views/shared/dossiers/editable_champs/_regions.html.haml +++ b/app/views/shared/dossiers/editable_champs/_regions.html.haml @@ -1,3 +1,3 @@ = form.select :value, - Champ.regions, + Champs::RegionChamp.regions, required: champ.mandatory? diff --git a/app/views/users/description/champs/_regions.html.haml b/app/views/users/description/champs/_regions.html.haml index 613b6af27..24c6f4bc5 100644 --- a/app/views/users/description/champs/_regions.html.haml +++ b/app/views/users/description/champs/_regions.html.haml @@ -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)) diff --git a/spec/features/new_user/dossier_spec.rb b/spec/features/new_user/dossier_spec.rb index 763b9555e..caa7f259a 100644 --- a/spec/features/new_user/dossier_spec.rb +++ b/spec/features/new_user/dossier_spec.rb @@ -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)