Checkbox should be checked when value is 'on'

This commit is contained in:
Mathieu Magnin 2017-03-30 15:24:40 +02:00
parent 066b43fa8a
commit 95b83a57c1
3 changed files with 32 additions and 2 deletions

View file

@ -1,2 +1 @@
%input{type: 'hidden', name:"champs['#{champ.id}']", id: "champs_#{champ.id}", value: ''}
%input{type: 'checkbox', style:'margin-left: 15px;', name:"champs['#{champ.id}']", id: "champs_#{champ.id}", checked: ('checked' if champ.value == 'on')}
%input{type: 'checkbox', style:'margin-left: 15px;', name:"champs['#{champ.id}']", id: "champs_#{champ.id}", checked: ('checked' if champ.object.value == 'on')}

View file

@ -5,5 +5,9 @@ FactoryGirl.define do
type_champ 'text'
order_place 1
mandatory false
trait :checkbox do
type_champ 'checkbox'
end
end
end

View file

@ -0,0 +1,27 @@
describe 'users/description/champs/render_list_champs.html.haml', type: :view do
let(:type_champ) { create(:type_de_champ_public, :checkbox) }
context "with a checkbox champ with value equals nil" do
let!(:champ_checkbox_checked) { create(:champ, type_de_champ: type_champ, value: nil) }
before do
render 'users/description/champs/render_list_champs.html.haml', champs: Champ.all, order_place: 0
end
it 'should not render a checked checkbox' do
expect(rendered).not_to have_css('input[type=checkbox][checked]')
end
end
context "with a checkbox champ with value equals 'on'" do
let!(:champ_checkbox_checked) { create(:champ, type_de_champ: type_champ, value: 'on') }
before do
render 'users/description/champs/render_list_champs.html.haml', champs: Champ.all, order_place: 0
end
it 'should render a checked checkbox' do
expect(rendered).to have_css('input[type=checkbox][checked]')
end
end
end