[Fix #285] Use a has_many through for Gestionnaire#dossiers_follow
This commit is contained in:
parent
318a14dfe2
commit
f67aa63766
2 changed files with 1 additions and 17 deletions
|
@ -9,6 +9,7 @@ class Gestionnaire < ActiveRecord::Base
|
|||
has_many :assign_to, dependent: :destroy
|
||||
has_many :procedures, through: :assign_to
|
||||
has_many :dossiers, -> { where.not(state: :draft) }, through: :procedures
|
||||
has_many :dossiers_follow, through: :follows, source: :dossier
|
||||
has_many :follows
|
||||
has_many :preference_list_dossiers
|
||||
|
||||
|
@ -17,10 +18,6 @@ class Gestionnaire < ActiveRecord::Base
|
|||
|
||||
include CredentialsSyncableConcern
|
||||
|
||||
def dossiers_follow
|
||||
@dossiers_follow ||= dossiers.joins(:follows).where("follows.gestionnaire_id = #{id}")
|
||||
end
|
||||
|
||||
def procedure_filter
|
||||
return nil unless assign_to.pluck(:procedure_id).include?(self[:procedure_filter])
|
||||
|
||||
|
|
|
@ -116,19 +116,6 @@ describe Gestionnaire, type: :model do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#dossiers_follow' do
|
||||
let!(:dossier) { create :dossier, procedure: procedure, state: :initiated }
|
||||
|
||||
before do
|
||||
create :follow, dossier_id: dossier.id, gestionnaire_id: gestionnaire.id
|
||||
end
|
||||
|
||||
subject { gestionnaire.dossiers_follow }
|
||||
|
||||
it { expect(Follow.all.size).to eq 1 }
|
||||
it { expect(subject.first).to eq dossier }
|
||||
end
|
||||
|
||||
describe '#build_default_preferences_list_dossier' do
|
||||
subject { gestionnaire.preference_list_dossiers }
|
||||
|
||||
|
|
Loading…
Reference in a new issue