commit
0f0c9772f3
2 changed files with 14 additions and 72 deletions
|
@ -117,11 +117,11 @@ class Dossier < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def ordered_champs
|
def ordered_champs
|
||||||
champs.joins(', types_de_champ').where("champs.type_de_champ_id = types_de_champ.id AND types_de_champ.procedure_id = #{procedure.id}").order('order_place')
|
champs.includes(:type_de_champ).order('types_de_champ.order_place')
|
||||||
end
|
end
|
||||||
|
|
||||||
def ordered_champs_private
|
def ordered_champs_private
|
||||||
champs_private.joins(', types_de_champ').where("champs.type_de_champ_id = types_de_champ.id AND types_de_champ.procedure_id = #{procedure.id}").order('order_place')
|
champs_private.includes(:type_de_champ).order('types_de_champ.order_place')
|
||||||
end
|
end
|
||||||
|
|
||||||
def ordered_pieces_justificatives
|
def ordered_pieces_justificatives
|
||||||
|
|
|
@ -598,87 +598,29 @@ describe Dossier do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#ordered_champs' do
|
describe '#ordered_champs' do
|
||||||
let!(:procedure_1) { create :procedure }
|
let(:procedure) { create(:procedure) }
|
||||||
let!(:procedure_2) { create :procedure }
|
let(:dossier) { Dossier.create(user: create(:user), procedure: procedure) }
|
||||||
|
|
||||||
let(:dossier_1) { Dossier.new(id: 0, procedure: procedure_1) }
|
|
||||||
let(:dossier_2) { Dossier.new(id: 0, procedure: procedure_2) }
|
|
||||||
|
|
||||||
before do
|
before do
|
||||||
create :type_de_champ_public, libelle: 'type_1_1', order_place: 1, procedure: dossier_1.procedure
|
create(:type_de_champ_public, libelle: 'l1', order_place: 1, procedure: procedure)
|
||||||
create :type_de_champ_public, libelle: 'type_1_2', order_place: 2, procedure: dossier_1.procedure
|
create(:type_de_champ_public, libelle: 'l3', order_place: 3, procedure: procedure)
|
||||||
|
create(:type_de_champ_public, libelle: 'l2', order_place: 2, procedure: procedure)
|
||||||
create :type_de_champ_public, libelle: 'type_2_1', order_place: 1, procedure: dossier_2.procedure
|
|
||||||
create :type_de_champ_public, libelle: 'type_2_2', order_place: 2, procedure: dossier_2.procedure
|
|
||||||
create :type_de_champ_public, libelle: 'type_2_3', order_place: 3, procedure: dossier_2.procedure
|
|
||||||
|
|
||||||
dossier_1.build_default_champs
|
|
||||||
dossier_2.build_default_champs
|
|
||||||
end
|
end
|
||||||
|
|
||||||
subject { dossier.ordered_champs }
|
it { expect(dossier.ordered_champs.pluck(:libelle)).to match(%w(l1 l2 l3)) }
|
||||||
|
|
||||||
it { expect(ChampPublic.where(dossier_id: 0).size).to eq 5 }
|
|
||||||
|
|
||||||
describe 'for dossier 1' do
|
|
||||||
let(:dossier) { dossier_1 }
|
|
||||||
|
|
||||||
it { expect(subject.size).to eq 2 }
|
|
||||||
it { expect(subject.first.type_de_champ.libelle).to eq 'type_1_1' }
|
|
||||||
it { expect(subject.last.type_de_champ.libelle).to eq 'type_1_2' }
|
|
||||||
end
|
|
||||||
|
|
||||||
describe 'for dossier 2' do
|
|
||||||
let(:dossier) { dossier_2 }
|
|
||||||
|
|
||||||
it { expect(subject.size).to eq 3 }
|
|
||||||
|
|
||||||
it { expect(subject.first.type_de_champ.libelle).to eq 'type_2_1' }
|
|
||||||
it { expect(subject.second.type_de_champ.libelle).to eq 'type_2_2' }
|
|
||||||
it { expect(subject.last.type_de_champ.libelle).to eq 'type_2_3' }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#ordered_champs_private' do
|
describe '#ordered_champs_private' do
|
||||||
let!(:procedure_1) { create :procedure }
|
let(:procedure) { create :procedure }
|
||||||
let!(:procedure_2) { create :procedure }
|
let(:dossier) { Dossier.create(user: create(:user), procedure: procedure) }
|
||||||
|
|
||||||
let(:dossier_1) { Dossier.new(id: 0, procedure: procedure_1) }
|
|
||||||
let(:dossier_2) { Dossier.new(id: 0, procedure: procedure_2) }
|
|
||||||
|
|
||||||
before do
|
before do
|
||||||
create :type_de_champ_private, libelle: 'type_1_1', order_place: 1, procedure: dossier_1.procedure
|
create :type_de_champ_private, libelle: 'l1', order_place: 1, procedure: procedure
|
||||||
create :type_de_champ_private, libelle: 'type_1_2', order_place: 2, procedure: dossier_1.procedure
|
create :type_de_champ_private, libelle: 'l3', order_place: 3, procedure: procedure
|
||||||
|
create :type_de_champ_private, libelle: 'l2', order_place: 2, procedure: procedure
|
||||||
create :type_de_champ_private, libelle: 'type_2_1', order_place: 1, procedure: dossier_2.procedure
|
|
||||||
create :type_de_champ_private, libelle: 'type_2_2', order_place: 2, procedure: dossier_2.procedure
|
|
||||||
create :type_de_champ_private, libelle: 'type_2_3', order_place: 3, procedure: dossier_2.procedure
|
|
||||||
|
|
||||||
dossier_1.build_default_champs
|
|
||||||
dossier_2.build_default_champs
|
|
||||||
end
|
end
|
||||||
|
|
||||||
subject { dossier.ordered_champs_private }
|
it { expect(dossier.ordered_champs_private.pluck(:libelle)).to match(%w(l1 l2 l3)) }
|
||||||
|
|
||||||
it { expect(ChampPrivate.where(dossier_id: 0).size).to eq 5 }
|
|
||||||
|
|
||||||
describe 'for dossier 1' do
|
|
||||||
let(:dossier) { dossier_1 }
|
|
||||||
|
|
||||||
it { expect(subject.size).to eq 2 }
|
|
||||||
it { expect(subject.first.type_de_champ.libelle).to eq 'type_1_1' }
|
|
||||||
it { expect(subject.last.type_de_champ.libelle).to eq 'type_1_2' }
|
|
||||||
end
|
|
||||||
|
|
||||||
describe 'for dossier 2' do
|
|
||||||
let(:dossier) { dossier_2 }
|
|
||||||
|
|
||||||
it { expect(subject.size).to eq 3 }
|
|
||||||
|
|
||||||
it { expect(subject.first.type_de_champ.libelle).to eq 'type_2_1' }
|
|
||||||
it { expect(subject.second.type_de_champ.libelle).to eq 'type_2_2' }
|
|
||||||
it { expect(subject.last.type_de_champ.libelle).to eq 'type_2_3' }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#total_follow' do
|
describe '#total_follow' do
|
||||||
|
|
Loading…
Reference in a new issue