Dossier: retrieve all dossiers for a procedure

This commit is contained in:
simon lehericey 2019-09-18 13:07:30 +02:00
parent 21577a0f0b
commit 9b16bd2037
2 changed files with 19 additions and 0 deletions

View file

@ -161,6 +161,8 @@ class Dossier < ApplicationRecord
user: []) user: [])
} }
scope :for_procedure, -> (procedure) { includes(:user, :groupe_instructeur).where(groupe_instructeurs: { procedure: procedure }) }
accepts_nested_attributes_for :individual accepts_nested_attributes_for :individual
delegate :siret, :siren, to: :etablissement, allow_nil: true delegate :siret, :siren, to: :etablissement, allow_nil: true

View file

@ -1009,4 +1009,21 @@ describe Dossier do
expect(dossier.individual.prenom).to eq user_info.given_name expect(dossier.individual.prenom).to eq user_info.given_name
} }
end end
describe '#for_procedure' do
let!(:procedure_1) { create(:procedure) }
let!(:procedure_2) { create(:procedure) }
let!(:dossier_1_1) { create(:dossier, procedure: procedure_1) }
let!(:dossier_1_2) { create(:dossier, procedure: procedure_1) }
let!(:dossier_2_1) { create(:dossier, procedure: procedure_2) }
before do
gi_1_2 = procedure_1.groupe_instructeurs.create(label: 2)
gi_1_2.dossiers << dossier_1_2
end
it { expect(Dossier.for_procedure(procedure_1)).to contain_exactly(dossier_1_1, dossier_1_2) }
it { expect(Dossier.for_procedure(procedure_2)).to contain_exactly(dossier_2_1) }
end
end end