Merge pull request #57 from sgmap/fix_checkbox_never_checked_when_rendered

Checkbox should be checked when value is 'on'
This commit is contained in:
Mathieu Magnin 2017-04-03 10:55:51 +02:00 committed by GitHub
commit 655070c913
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