From e4826b468a3cf2a2be021d9d77f31f6ef42ee0a1 Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Tue, 28 Mar 2017 13:26:25 +0200 Subject: [PATCH] Fix departements / pays / regions drop down list --- .../description/champs/_departements.html.haml | 3 ++- .../description/champs/_drop_down_list.html.haml | 8 ++++++-- .../champs/_drop_down_template.html.haml | 6 ------ app/views/users/description/champs/_pays.html.haml | 3 ++- .../users/description/champs/_regions.html.haml | 5 ++--- .../champs/_departements.html.haml_spec.rb | 13 +++++++++++++ .../description/champs/_pays.html.haml_spec.rb | 13 +++++++++++++ .../description/champs/_regions.html.haml_spec.rb | 13 +++++++++++++ 8 files changed, 51 insertions(+), 13 deletions(-) delete mode 100644 app/views/users/description/champs/_drop_down_template.html.haml create mode 100644 spec/views/users/description/champs/_departements.html.haml_spec.rb create mode 100644 spec/views/users/description/champs/_pays.html.haml_spec.rb create mode 100644 spec/views/users/description/champs/_regions.html.haml_spec.rb 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