Merge branch 'develop' into staging

This commit is contained in:
Xavier J 2016-10-04 19:58:20 +02:00
commit 4bf7ef6cb1
4 changed files with 41 additions and 7 deletions

View file

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

View file

@ -0,0 +1,11 @@
class FixTypeDeChampHeaderSectionWithMandatoryTrue < ActiveRecord::Migration
class TypeDeChamp < ActiveRecord::Base
end
def change
TypeDeChamp.all.each do |type_de_champ|
type_de_champ.update_column(:mandatory, false) if type_de_champ.type_champ == 'header_section'
end
end
end

View file

@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20160927154248) do ActiveRecord::Schema.define(version: 20161004175442) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"

View file

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