add possible values
This commit is contained in:
parent
40b7ea3af2
commit
76c9d1ada5
4 changed files with 29 additions and 3 deletions
|
@ -1,4 +1,10 @@
|
|||
class TypesDeChamp::PrefillCommuneTypeDeChamp < TypesDeChamp::PrefillTypeDeChamp
|
||||
def possible_values
|
||||
departements.map do |departement|
|
||||
"#{departement[:code]} (#{departement[:name]}) : https://geo.api.gouv.fr/communes?codeDepartement=#{departement[:code]}"
|
||||
end
|
||||
end
|
||||
|
||||
def transform_value_to_assignable_attributes(value)
|
||||
return if value.blank? || !value.is_a?(Array)
|
||||
return if (departement_code = value.first).blank?
|
||||
|
@ -30,4 +36,8 @@ class TypesDeChamp::PrefillCommuneTypeDeChamp < TypesDeChamp::PrefillTypeDeChamp
|
|||
value: "#{commune_name} (#{postal_code})"
|
||||
)
|
||||
end
|
||||
|
||||
def departements
|
||||
@departements ||= APIGeoService.departements.sort_by { _1[:code] }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -129,14 +129,14 @@ en:
|
|||
yes_no_html: '"true" for Yes, "false" pour No'
|
||||
checkbox_html: '"true" to check, "false" to uncheck'
|
||||
pays_html: An <a href="https://en.wikipedia.org/wiki/ISO_3166-2" target="_blank" rel="noopener noreferrer">ISO 3166-2 country code</a>
|
||||
regions_html: An <a href="https://fr.wikipedia.org/wiki/R%C3%A9gion_fran%C3%A7aise" target="_blank" rel="noopener noreferrer">INSEE region code</a>
|
||||
departements_html: A <a href="https://fr.wikipedia.org/wiki/Num%C3%A9rotation_des_d%C3%A9partements_fran%C3%A7ais" target="_blank">department number</a>
|
||||
communes_html: An array of the department code and the <a href="https://geo.api.gouv.fr/communes" target="_blank" rel="noopener noreferrer">INSEE commune code</a>.
|
||||
drop_down_list_html: A choice among those selected when the procedure was created
|
||||
date_html: ISO8601 date
|
||||
datetime_html: ISO8601 datetime
|
||||
drop_down_list_other_html: Any value
|
||||
repetition_html: A array of hashes with possible values for each field of the repetition.
|
||||
regions_html: An <a href="https://fr.wikipedia.org/wiki/R%C3%A9gion_fran%C3%A7aise" target="_blank" rel="noopener noreferrer">INSEE region code</a>
|
||||
regions_html: An <a href="https://fr.wikipedia.org/wiki/R%C3%A9gion_fran%C3%A7aise" target="_blank" rel="noopener noreferrer">INSEE region code</a>
|
||||
epci_html: An array of the department code and the <a href="https://geo.api.gouv.fr/epcis" target="_blank" rel="noopener noreferrer">EPCI one</a>.
|
||||
examples:
|
||||
title: Example
|
||||
|
|
|
@ -120,13 +120,14 @@ fr:
|
|||
yes_no_html: '"true" pour Oui, "false" pour Non'
|
||||
checkbox_html: '"true" pour coché, "false" pour décoché'
|
||||
pays_html: Un <a href="https://en.wikipedia.org/wiki/ISO_3166-2" target="_blank" rel="noopener noreferrer">code pays ISO 3166-2</a>
|
||||
regions_html: Un <a href="https://fr.wikipedia.org/wiki/R%C3%A9gion_fran%C3%A7aise" target="_blank" rel="noopener noreferrer">code INSEE de région</a>
|
||||
departements_html: Un <a href="https://fr.wikipedia.org/wiki/Num%C3%A9rotation_des_d%C3%A9partements_fran%C3%A7ais" target="_blank">numéro de département</a>
|
||||
communes_html: Un tableau contenant le code de département et <a href="https://geo.api.gouv.fr/communes" target="_blank" rel="noopener noreferrer">le code INSEE de la commune</a>.
|
||||
drop_down_list_html: Un choix parmi ceux sélectionnés à la création de la procédure
|
||||
datetime_html: Datetime au format ISO8601
|
||||
date_html: Date au format ISO8601
|
||||
drop_down_list_other_html: Toute valeur
|
||||
repetition_html: Un tableau de dictionnaires avec les valeurs possibles pour chaque champ de la répétition.
|
||||
regions_html: Un <a href="https://fr.wikipedia.org/wiki/R%C3%A9gion_fran%C3%A7aise" target="_blank" rel="noopener noreferrer">code INSEE de région</a>
|
||||
epci_html: Un tableau contenant le code de département et <a href="https://geo.api.gouv.fr/epcis" target="_blank" rel="noopener noreferrer">celui de l'EPCI</a>.
|
||||
examples:
|
||||
title: Exemple
|
||||
|
|
|
@ -15,6 +15,15 @@ RSpec.describe TypesDeChamp::PrefillCommuneTypeDeChamp do
|
|||
it { is_expected.to be_kind_of(TypesDeChamp::PrefillTypeDeChamp) }
|
||||
end
|
||||
|
||||
describe '#possible_values', vcr: { cassette_name: 'api_geo_departements' } do
|
||||
let(:expected_values) do
|
||||
departements.map { |departement| "#{departement[:code]} (#{departement[:name]}) : https://geo.api.gouv.fr/communes?codeDepartement=#{departement[:code]}" }
|
||||
end
|
||||
subject(:possible_values) { described_class.new(type_de_champ).possible_values }
|
||||
|
||||
it { expect(possible_values).to match(expected_values) }
|
||||
end
|
||||
|
||||
describe '#transform_value_to_assignable_attributes' do
|
||||
subject(:transform_value_to_assignable_attributes) do
|
||||
described_class.build(type_de_champ).transform_value_to_assignable_attributes(value)
|
||||
|
@ -99,4 +108,10 @@ RSpec.describe TypesDeChamp::PrefillCommuneTypeDeChamp do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def departements
|
||||
APIGeoService.departements.sort_by { _1[:code] }
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue