Merge pull request #291 from sgmap/dossiers-follow

[Fix #285] Use has_many and rename Gestionnaire#dossiers_follow
This commit is contained in:
gregoirenovel 2017-05-15 15:52:17 +02:00 committed by GitHub
commit bce8fd42bc
5 changed files with 7 additions and 23 deletions

View file

@ -18,7 +18,7 @@ class DossiersListFacades
end
def total_dossier_follow
@current_devise_profil.dossiers_follow.count
@current_devise_profil.followed_dossiers.count
end
def total_new_dossier

View file

@ -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 :followed_dossiers, 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])
@ -75,10 +72,10 @@ class Gestionnaire < ActiveRecord::Base
end
def notifications_for procedure
procedure_ids = dossiers_follow.pluck(:procedure_id)
procedure_ids = followed_dossiers.pluck(:procedure_id)
if procedure_ids.include?(procedure.id)
return dossiers_follow.where(procedure_id: procedure.id)
return followed_dossiers.where(procedure_id: procedure.id)
.inject(0) do |acc, dossier|
acc += dossier.notifications.where(already_read: false).count
end
@ -87,7 +84,7 @@ class Gestionnaire < ActiveRecord::Base
end
def dossiers_with_notifications_count_for_procedure(procedure)
followed_dossiers_id = dossiers_follow.where(procedure: procedure).pluck(:id)
followed_dossiers_id = followed_dossiers.where(procedure: procedure).pluck(:id)
Notification.unread.where(dossier_id: followed_dossiers_id).select(:dossier_id).distinct(:dossier_id).count
end

View file

@ -25,7 +25,7 @@ class DossiersListGestionnaireService
end
def suivi
@suivi ||= @current_devise_profil.dossiers_follow.merge(dossiers_to_display)
@suivi ||= @current_devise_profil.followed_dossiers.merge(dossiers_to_display)
end
def nouveaux

View file

@ -1,6 +1,6 @@
#first-block
.dossiers-en-cours
.count= current_gestionnaire.dossiers_follow.count
.count= current_gestionnaire.followed_dossiers.count
.text SUIVIS
.nouveaux-dossiers
.count= current_gestionnaire.dossiers.nouveaux.count

View file

@ -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 }