Use #sum instead of #inject when possible
This commit is contained in:
parent
24ddbc73ee
commit
b2fe1b856c
2 changed files with 5 additions and 5 deletions
|
@ -55,8 +55,8 @@ class Gestionnaire < ActiveRecord::Base
|
|||
procedure_ids = followed_dossiers.pluck(:procedure_id)
|
||||
|
||||
if procedure_ids.include?(procedure.id)
|
||||
return followed_dossiers.where(procedure_id: procedure.id).inject(0) do |acc, dossier|
|
||||
acc += dossier.notifications.where(already_read: false).count
|
||||
return followed_dossiers.where(procedure_id: procedure.id).sum do |dossier|
|
||||
dossier.notifications.where(already_read: false).count
|
||||
end
|
||||
end
|
||||
0
|
||||
|
|
|
@ -95,7 +95,7 @@ describe Gestionnaire, type: :model do
|
|||
it { is_expected.to eq 0 }
|
||||
it { expect(gestionnaire.follows.count).to eq 0 }
|
||||
it do
|
||||
expect_any_instance_of(Dossier::ActiveRecord_AssociationRelation).not_to receive(:inject)
|
||||
expect_any_instance_of(Dossier::ActiveRecord_AssociationRelation).not_to receive(:sum)
|
||||
subject
|
||||
end
|
||||
end
|
||||
|
@ -108,7 +108,7 @@ describe Gestionnaire, type: :model do
|
|||
it { is_expected.to eq 0 }
|
||||
it { expect(gestionnaire.follows.count).to eq 1 }
|
||||
it do
|
||||
expect_any_instance_of(Dossier::ActiveRecord_AssociationRelation).not_to receive(:inject)
|
||||
expect_any_instance_of(Dossier::ActiveRecord_AssociationRelation).not_to receive(:sum)
|
||||
subject
|
||||
end
|
||||
end
|
||||
|
@ -124,7 +124,7 @@ describe Gestionnaire, type: :model do
|
|||
it { is_expected.to eq 1 }
|
||||
it { expect(gestionnaire.follows.count).to eq 1 }
|
||||
it do
|
||||
expect_any_instance_of(Dossier::ActiveRecord_AssociationRelation).to receive(:inject)
|
||||
expect_any_instance_of(Dossier::ActiveRecord_AssociationRelation).to receive(:sum)
|
||||
subject
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue