From b2fe1b856c067303fffb53e1970a92b83d625ae5 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Tue, 16 Jan 2018 14:20:34 +0100 Subject: [PATCH] Use #sum instead of #inject when possible --- app/models/gestionnaire.rb | 4 ++-- spec/models/gestionnaire_spec.rb | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/models/gestionnaire.rb b/app/models/gestionnaire.rb index 02cd33e81..1b965373a 100644 --- a/app/models/gestionnaire.rb +++ b/app/models/gestionnaire.rb @@ -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 diff --git a/spec/models/gestionnaire_spec.rb b/spec/models/gestionnaire_spec.rb index e300ffe6c..7b92dd830 100644 --- a/spec/models/gestionnaire_spec.rb +++ b/spec/models/gestionnaire_spec.rb @@ -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