[Fix#980] Engagement checkbox should be checked sometimes

This commit is contained in:
Mathieu Magnin 2017-11-22 17:35:15 +01:00 committed by gregoirenovel
parent 2edcc12126
commit 8edfdff0fc
2 changed files with 21 additions and 1 deletions

View file

@ -1,2 +1,2 @@
%input{ type: 'hidden', name: "champs['#{champ.id}']", id: "champs_#{champ.id}", value: '' } %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

@ -0,0 +1,20 @@
require 'spec_helper'
describe 'users/description/champs/engagement.html.haml', type: :view do
let(:type_champ) { create(:type_de_champ_public, type_champ: :engagement) }
subject { render 'users/description/champs/engagement.html.haml', champ: champ }
context "when the value is on" do
let!(:champ) { create(:champ, type_de_champ: type_champ, value: "on").decorate }
it { is_expected.to have_selector("input[type='checkbox'][checked]") }
end
context "when the value is nil" do
let!(:champ) { create(:champ, type_de_champ: type_champ, value: nil).decorate }
it { is_expected.to have_selector("input[type='checkbox']") }
it { is_expected.not_to have_selector("input[type='checkbox'][checked]") }
end
end