Fix bug type_de_champ header section can be mandatory

This commit is contained in:
Xavier J 2016-10-04 19:53:21 +02:00
parent 52249f92b5
commit 1ccf84dac2
2 changed files with 29 additions and 6 deletions

View file

@ -24,7 +24,8 @@ class TypeDeChamp < ActiveRecord::Base
validates :libelle, presence: true, allow_blank: false, allow_nil: false
validates :type_champ, presence: true, allow_blank: false, allow_nil: false
# validates :order_place, presence: true, allow_blank: false, allow_nil: false
before_validation :change_header_section_mandatory
def self.type_de_champs_list_fr
type_champs.map { |champ| [ I18n.t("activerecord.attributes.type_de_champ.type_champs.#{champ.last}"), champ.first ] }
@ -33,4 +34,8 @@ class TypeDeChamp < ActiveRecord::Base
def field_for_list?
!(type_champ == 'textarea' || type_champ == 'header_section')
end
def change_header_section_mandatory
self.mandatory = false if self.type_champ == 'header_section'
end
end

View file

@ -34,7 +34,7 @@ describe Admin::TypesDeChampController, type: :controller do
describe '#update' do
let(:libelle) { 'mon libelle' }
let(:type_champ) { 'text' }
let(:type_champ) { 'header_section' }
let(:description) { 'titi' }
let(:order_place) { '' }
let(:types_de_champ_id) { '' }
@ -78,9 +78,23 @@ describe Admin::TypesDeChampController, type: :controller do
subject { procedure.types_de_champ.first }
it { expect(subject.libelle).to eq('mon libelle') }
it { expect(subject.type_champ).to eq('text') }
it { expect(subject.type_champ).to eq('header_section') }
it { expect(subject.description).to eq('titi') }
it { expect(subject.mandatory).to be_truthy }
end
context 'when type_champ is header_section and mandatory is true' do
let(:type_champ) { 'header_section' }
let(:mandatory) { 'on' }
before do
request
procedure.reload
end
subject { procedure.types_de_champ.first }
it { expect(subject.type_champ).to eq type_champ }
it { expect(subject.mandatory).to be_falsey }
end
context 'when type_de_champ already exist' do
@ -88,20 +102,24 @@ describe Admin::TypesDeChampController, type: :controller do
let(:type_de_champ) { procedure.types_de_champ.first }
let(:types_de_champ_id) { type_de_champ.id }
let(:libelle) { 'toto' }
let(:type_champ) { 'text' }
let(:type_champ) { 'header_section' }
let(:description) { 'citrouille' }
let(:order_place) { '0' }
let(:mandatory) { 'on' }
before do
request
procedure.reload
end
subject { procedure.types_de_champ.first }
it { expect(subject.libelle).to eq('toto') }
it { expect(subject.type_champ).to eq('text') }
it { expect(subject.type_champ).to eq('header_section') }
it { expect(subject.description).to eq('citrouille') }
it { expect(subject.order_place).to eq(0) }
it { expect(subject.order_place).to be_truthy }
it { expect(subject.mandatory).to be_falsey }
end
end
context 'when procedure is not found' do