From a611cace5f5c29b58f81b209a5ff7a52017bfb59 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Tue, 3 Oct 2017 15:08:51 +0200 Subject: [PATCH] Do not allow to filter by explication fields --- app/models/procedure.rb | 10 ++++++++-- spec/models/procedure_spec.rb | 17 ++++++++++++----- 2 files changed, 20 insertions(+), 7 deletions(-) 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/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