diff --git a/app/views/users/description/champs/_departements.html.haml b/app/views/users/description/champs/_departements.html.haml index 018a60526..5fd949ccd 100644 --- a/app/views/users/description/champs/_departements.html.haml +++ b/app/views/users/description/champs/_departements.html.haml @@ -1 +1,2 @@ -= render partial: 'users/description/champs/drop_down_template', locals: {values: Champ.departements, champ: champ} += select_tag("champs['#{champ.id}']", + options_for_select(Champ.departements, selected: champ.object.value)) diff --git a/app/views/users/description/champs/_drop_down_list.html.haml b/app/views/users/description/champs/_drop_down_list.html.haml index 1480aff23..eebb763f1 100644 --- a/app/views/users/description/champs/_drop_down_list.html.haml +++ b/app/views/users/description/champs/_drop_down_list.html.haml @@ -1,2 +1,6 @@ -- unless champ.drop_down_list.nil? - = render partial: 'users/description/champs/drop_down_template', locals: { drop_down_list: champ.drop_down_list, champ: champ } +- if champ.drop_down_list && champ.drop_down_list.options.any? + = select_tag("champs['#{champ.id}']", + options_for_select(champ.drop_down_list.options, selected: champ.drop_down_list.selected_options(champ), + disabled: champ.drop_down_list.disabled_options), + multiple: champ.drop_down_list.multiple, + class: champ.drop_down_list.multiple ? 'select2' : nil) diff --git a/app/views/users/description/champs/_drop_down_template.html.haml b/app/views/users/description/champs/_drop_down_template.html.haml deleted file mode 100644 index 5ec502745..000000000 --- a/app/views/users/description/champs/_drop_down_template.html.haml +++ /dev/null @@ -1,6 +0,0 @@ -- unless drop_down_list.options.blank? - = select_tag("champs['#{champ.id}']", - options_for_select(drop_down_list.options, selected: drop_down_list.selected_options(champ), - disabled: drop_down_list.disabled_options), - multiple: drop_down_list.multiple, - class: drop_down_list.multiple ? 'select2' : nil) diff --git a/app/views/users/description/champs/_pays.html.haml b/app/views/users/description/champs/_pays.html.haml index ac4a842bf..2f530b683 100644 --- a/app/views/users/description/champs/_pays.html.haml +++ b/app/views/users/description/champs/_pays.html.haml @@ -1 +1,2 @@ -= render partial: 'users/description/champs/drop_down_template', locals: {values: Champ.pays, champ: champ} += select_tag("champs['#{champ.id}']", + options_for_select(Champ.pays, selected: champ.object.value)) diff --git a/app/views/users/description/champs/_regions.html.haml b/app/views/users/description/champs/_regions.html.haml index 280e8e959..613b6af27 100644 --- a/app/views/users/description/champs/_regions.html.haml +++ b/app/views/users/description/champs/_regions.html.haml @@ -1,3 +1,2 @@ -= render partial: 'users/description/champs/drop_down_template', locals: {values: Champ.regions, champ: champ} - - += select_tag("champs['#{champ.id}']", + options_for_select(Champ.regions, selected: champ.object.value)) diff --git a/spec/views/users/description/champs/_departements.html.haml_spec.rb b/spec/views/users/description/champs/_departements.html.haml_spec.rb new file mode 100644 index 000000000..d0d6d4fa1 --- /dev/null +++ b/spec/views/users/description/champs/_departements.html.haml_spec.rb @@ -0,0 +1,13 @@ +require 'spec_helper' + +describe 'users/description/champs/departements.html.haml', vcr: {cassette_name: 'geoapi_departements'}, type: :view do + let(:champ) { create(:champ) } + + before do + render 'users/description/champs/departements.html.haml', champ: champ.decorate + end + + it 'should render departments drop down list' do + expect(rendered).to include("Ain") + end +end diff --git a/spec/views/users/description/champs/_pays.html.haml_spec.rb b/spec/views/users/description/champs/_pays.html.haml_spec.rb new file mode 100644 index 000000000..78374b392 --- /dev/null +++ b/spec/views/users/description/champs/_pays.html.haml_spec.rb @@ -0,0 +1,13 @@ +require 'spec_helper' + +describe 'users/description/champs/pays.html.haml', type: :view do + let(:champ) { create(:champ) } + + before do + render 'users/description/champs/pays.html.haml', champ: champ.decorate + end + + it 'should render pays drop down list' do + expect(rendered).to include("FRANCE") + end +end diff --git a/spec/views/users/description/champs/_regions.html.haml_spec.rb b/spec/views/users/description/champs/_regions.html.haml_spec.rb new file mode 100644 index 000000000..95e9fdef8 --- /dev/null +++ b/spec/views/users/description/champs/_regions.html.haml_spec.rb @@ -0,0 +1,13 @@ +require 'spec_helper' + +describe 'users/description/champs/regions.html.haml', vcr: {cassette_name: 'geoapi_regions'}, type: :view do + let(:champ) { create(:champ) } + + before do + render 'users/description/champs/regions.html.haml', champ: champ.decorate + end + + it 'should render regions drop down list' do + expect(rendered).to include("Normandie") + end +end