diff --git a/app/models/types_de_champ/prefill_drop_down_list_type_de_champ.rb b/app/models/types_de_champ/prefill_drop_down_list_type_de_champ.rb index b5505151f..648f2d17e 100644 --- a/app/models/types_de_champ/prefill_drop_down_list_type_de_champ.rb +++ b/app/models/types_de_champ/prefill_drop_down_list_type_de_champ.rb @@ -1,10 +1,4 @@ class TypesDeChamp::PrefillDropDownListTypeDeChamp < TypesDeChamp::PrefillTypeDeChamp - def example_value - possible_values_list.first - end - - private - def possible_values_list if drop_down_other? drop_down_list_enabled_non_empty_options.insert( @@ -15,4 +9,8 @@ class TypesDeChamp::PrefillDropDownListTypeDeChamp < TypesDeChamp::PrefillTypeDe drop_down_list_enabled_non_empty_options end end + + def example_value + possible_values_list.first + end end diff --git a/app/models/types_de_champ/prefill_pays_type_de_champ.rb b/app/models/types_de_champ/prefill_pays_type_de_champ.rb index cf0fa0278..a5e6aad21 100644 --- a/app/models/types_de_champ/prefill_pays_type_de_champ.rb +++ b/app/models/types_de_champ/prefill_pays_type_de_champ.rb @@ -1,14 +1,14 @@ class TypesDeChamp::PrefillPaysTypeDeChamp < TypesDeChamp::PrefillTypeDeChamp + def possible_values_list + countries.map { |country| "#{country[:code]} (#{country[:name]})" } + end + def example_value countries.pick(:code) end private - def possible_values_list - countries.map { |country| "#{country[:code]} (#{country[:name]})" } - end - def countries @countries ||= APIGeoService.countries.sort_by { |country| country[:code] } end diff --git a/app/models/types_de_champ/prefill_region_type_de_champ.rb b/app/models/types_de_champ/prefill_region_type_de_champ.rb index 6362fccac..7d52601b4 100644 --- a/app/models/types_de_champ/prefill_region_type_de_champ.rb +++ b/app/models/types_de_champ/prefill_region_type_de_champ.rb @@ -1,10 +1,10 @@ class TypesDeChamp::PrefillRegionTypeDeChamp < TypesDeChamp::PrefillTypeDeChamp - private - def possible_values_list regions.map { |region| "#{region[:code]} (#{region[:name]})" } end + private + def regions @regions ||= APIGeoService.regions.sort_by { |region| region[:code] } end diff --git a/app/models/types_de_champ/prefill_type_de_champ.rb b/app/models/types_de_champ/prefill_type_de_champ.rb index 8b6c0bbba..3ab56de61 100644 --- a/app/models/types_de_champ/prefill_type_de_champ.rb +++ b/app/models/types_de_champ/prefill_type_de_champ.rb @@ -27,6 +27,12 @@ class TypesDeChamp::PrefillTypeDeChamp < SimpleDelegator [possible_values_list_display, link_to_all_possible_values].compact.join('
').html_safe # rubocop:disable Rails/OutputSafety end + def possible_values_list + return [] unless prefillable? + + [I18n.t("views.prefill_descriptions.edit.possible_values.#{type_champ}_html")] + end + def example_value return nil unless prefillable? @@ -43,12 +49,6 @@ class TypesDeChamp::PrefillTypeDeChamp < SimpleDelegator private - def possible_values_list - return [] unless prefillable? - - [I18n.t("views.prefill_descriptions.edit.possible_values.#{type_champ}_html")] - end - def link_to_all_possible_values return unless too_many_possible_values? && prefillable? diff --git a/spec/controllers/prefill_type_de_champs_controller_spec.rb b/spec/controllers/prefill_type_de_champs_controller_spec.rb index a4b61f19c..5e13be629 100644 --- a/spec/controllers/prefill_type_de_champs_controller_spec.rb +++ b/spec/controllers/prefill_type_de_champs_controller_spec.rb @@ -8,6 +8,8 @@ RSpec.describe PrefillTypeDeChampsController, type: :controller do context 'when the procedure is found' do context 'when the procedure is publiee' do context 'when the procedure is opendata' do + render_views + let(:procedure) { create(:procedure, :published, opendata: true) } it { expect(show_request).to render_template(:show) }