diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 69f9619cf..1667bb00e 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -215,11 +215,17 @@ class Procedure < ActiveRecord::Base ] end - types_de_champ.reject { |tdc| tdc.type_champ == 'header_section' }.each do |type_de_champ| + types_de_champ + .reject { |tdc| ['header_section', 'explication'].include?(tdc.type_champ ) } + .each do |type_de_champ| + fields << field_hash(type_de_champ.libelle, 'type_de_champ', type_de_champ.id.to_s) end - types_de_champ_private.reject { |tdc| tdc.type_champ == 'header_section' }.each do |type_de_champ| + types_de_champ_private + .reject { |tdc| ['header_section', 'explication'].include?(tdc.type_champ ) } + .each do |type_de_champ| + fields << field_hash(type_de_champ.libelle, 'type_de_champ_private', type_de_champ.id.to_s) end diff --git a/app/views/new_gestionnaire/dossiers/_champs.html.haml b/app/views/new_gestionnaire/dossiers/_champs.html.haml index b7c125c92..b9f84cd96 100644 --- a/app/views/new_gestionnaire/dossiers/_champs.html.haml +++ b/app/views/new_gestionnaire/dossiers/_champs.html.haml @@ -5,7 +5,7 @@ - if c.type_champ == "header_section" %th.header-section{ colspan: 2 } = c.libelle - - else + - elsif c.type_champ != "explication" %th = "#{c.libelle} :" %td diff --git a/spec/factories/champ.rb b/spec/factories/champ.rb index 07cf128e9..4cd78dedc 100644 --- a/spec/factories/champ.rb +++ b/spec/factories/champ.rb @@ -9,5 +9,9 @@ FactoryGirl.define do trait :header_section do type_de_champ { FactoryGirl.create(:type_de_champ_public, :header_section) } end + + trait :explication do + type_de_champ { FactoryGirl.create(:type_de_champ_public, :explication) } + end end end diff --git a/spec/factories/type_de_champ_public.rb b/spec/factories/type_de_champ_public.rb index 76511640a..0add6b480 100644 --- a/spec/factories/type_de_champ_public.rb +++ b/spec/factories/type_de_champ_public.rb @@ -14,6 +14,10 @@ FactoryGirl.define do type_champ 'header_section' end + trait :explication do + type_champ 'explication' + end + trait :type_dossier_link do libelle 'Référence autre dossier' type_champ 'dossier_link' diff --git a/spec/models/procedure_spec.rb b/spec/models/procedure_spec.rb index 5373249dc..ef552b86f 100644 --- a/spec/models/procedure_spec.rb +++ b/spec/models/procedure_spec.rb @@ -423,11 +423,11 @@ describe Procedure do end describe "#fields" do - subject { create(:procedure, :with_type_de_champ, :with_type_de_champ_private, :types_de_champ_count => 2, :types_de_champ_private_count => 2) } - let(:tdc_1) { subject.types_de_champ.first } - let(:tdc_2) { subject.types_de_champ.last } - let(:tdc_private_1) { subject.types_de_champ_private.first } - let(:tdc_private_2) { subject.types_de_champ_private.last } + subject { create(:procedure, :with_type_de_champ, :with_type_de_champ_private, :types_de_champ_count => 4, :types_de_champ_private_count => 4) } + let(:tdc_1) { subject.types_de_champ[0] } + let(:tdc_2) { subject.types_de_champ[1] } + let(:tdc_private_1) { subject.types_de_champ_private[0] } + let(:tdc_private_2) { subject.types_de_champ_private[1] } let(:expected) { [ { "label" => 'Créé le', "table" => 'self', "column" => 'created_at' }, @@ -452,6 +452,13 @@ describe Procedure do ] } + before do + subject.types_de_champ[2].update_attribute(:type_champ, 'header_section') + subject.types_de_champ[3].update_attribute(:type_champ, 'explication') + subject.types_de_champ_private[2].update_attribute(:type_champ, 'header_section') + subject.types_de_champ_private[3].update_attribute(:type_champ, 'explication') + end + it { expect(subject.fields).to eq(expected) } end diff --git a/spec/views/new_gestionnaire/dossiers/_champs.html.haml_spec.rb b/spec/views/new_gestionnaire/dossiers/_champs.html.haml_spec.rb index 3a7ea2c2e..b5fbc8762 100644 --- a/spec/views/new_gestionnaire/dossiers/_champs.html.haml_spec.rb +++ b/spec/views/new_gestionnaire/dossiers/_champs.html.haml_spec.rb @@ -4,12 +4,16 @@ describe 'new_gestionnaire/dossiers/champs.html.haml', type: :view do context "there is some champs" do let(:champ1) { create(:champ, :checkbox, value: "true") } let(:champ2) { create(:champ, :header_section, value: "Section") } - let(:champs) { [champ1, champ2] } + let(:champ3) { create(:champ, :explication, value: "mazette") } + let(:champs) { [champ1, champ2, champ3] } it { expect(rendered).to include(champ1.libelle) } it { expect(rendered).to include(champ1.value) } it { expect(rendered).to have_css(".header-section") } it { expect(rendered).to include(champ2.libelle) } + + it { expect(rendered).not_to include(champ3.libelle) } + it { expect(rendered).not_to include(champ3.value) } end end