[Fix #719] Unformat date and yes/no values in the form

This commit is contained in:
gregoirenovel 2017-09-14 16:41:58 +02:00
parent 121ff6417c
commit 5b955677c2
4 changed files with 43 additions and 3 deletions

View file

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

View file

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

View file

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

View file

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