🐛 make possible_values_list method public

This commit is contained in:
sebastiencarceles 2023-02-14 11:41:35 +01:00
parent a77a0e2c7f
commit 0159a10969
5 changed files with 18 additions and 18 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -27,6 +27,12 @@ class TypesDeChamp::PrefillTypeDeChamp < SimpleDelegator
[possible_values_list_display, link_to_all_possible_values].compact.join('<br>').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?

View file

@ -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) }