diff --git a/app/views/users/description/champs/_date.html.haml b/app/views/users/description/champs/_date.html.haml index f04b581a6..74088b67c 100644 --- a/app/views/users/description/champs/_date.html.haml +++ b/app/views/users/description/champs/_date.html.haml @@ -1,5 +1,5 @@ %input.form-control{ name: "champs['#{champ.id}']", placeholder: "JJ/MM/AAAA", id: "champs_#{champ.id}", - value: champ.value, + value: champ.value ? champ.object.value : champ.value, type: "date" } diff --git a/app/views/users/description/champs/_yes_no.html.haml b/app/views/users/description/champs/_yes_no.html.haml index e914d1bb3..83d4622dc 100644 --- a/app/views/users/description/champs/_yes_no.html.haml +++ b/app/views/users/description/champs/_yes_no.html.haml @@ -1,8 +1,8 @@ %div %label.radio-inline - = radio_button_tag "champs['#{champ.id}']", "true", champ.value == 'true' + = radio_button_tag "champs['#{champ.id}']", "true", champ.object.value == 'true' Oui %label.radio-inline - = radio_button_tag "champs['#{champ.id}']", "false", champ.value == 'false' + = radio_button_tag "champs['#{champ.id}']", "false", champ.object.value == 'false' Non diff --git a/spec/views/users/description/champs/_date.html.haml_spec.rb b/spec/views/users/description/champs/_date.html.haml_spec.rb new file mode 100644 index 000000000..5e0e797e7 --- /dev/null +++ b/spec/views/users/description/champs/_date.html.haml_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +describe 'users/description/champs/date.html.haml', type: :view do + let(:type_champ) { create(:type_de_champ_public, type_champ: :date) } + + before do + render 'users/description/champs/date.html.haml', champ: champ + end + + let!(:champ) { create(:champ, type_de_champ: type_champ, value: "2017-09-19").decorate } + + it 'should render an input for the dossier link' do + expect(rendered).to have_css("input[value='2017-09-19']") + end +end diff --git a/spec/views/users/description/champs/_yes_no.html.haml_spec.rb b/spec/views/users/description/champs/_yes_no.html.haml_spec.rb new file mode 100644 index 000000000..9d2af680c --- /dev/null +++ b/spec/views/users/description/champs/_yes_no.html.haml_spec.rb @@ -0,0 +1,25 @@ +require 'spec_helper' + +describe 'users/description/champs/yes_no.html.haml', type: :view do + let(:type_champ) { create(:type_de_champ_public, type_champ: :yes_no) } + + before do + render 'users/description/champs/yes_no.html.haml', champ: champ + end + + context "when the value is Oui" do + let!(:champ) { create(:champ, type_de_champ: type_champ, value: "true").decorate } + + it 'should select the Oui radio button' do + expect(rendered).to have_selector("input[value='true'][checked]") + end + end + + context "when the value is Non" do + let!(:champ) { create(:champ, type_de_champ: type_champ, value: "false").decorate } + + it 'should select the Non radio button' do + expect(rendered).to have_selector("input[value='false'][checked]") + end + end +end