Avis: move notify_gestionnaire to private method

This commit is contained in:
Simon Lehericey 2017-07-20 11:54:41 +02:00
parent afae7478f5
commit fe1b97b738
2 changed files with 18 additions and 4 deletions

View file

@ -14,10 +14,6 @@ class Avis < ApplicationRecord
gestionnaire.try(:email) || email
end
def notify_gestionnaire
AvisMailer.avis_invitation(self).deliver_now
end
def self.link_avis_to_gestionnaire(gestionnaire)
Avis.where(email: gestionnaire.email).update_all(email: nil, gestionnaire_id: gestionnaire.id)
end
@ -26,4 +22,10 @@ class Avis < ApplicationRecord
avis = Avis.find_by(id: avis_id)
avis.present? && avis.email == email
end
private
def notify_gestionnaire
AvisMailer.avis_invitation(self).deliver_now
end
end

View file

@ -86,4 +86,16 @@ RSpec.describe Avis, type: :model do
end
end
end
describe '#notify_gestionnaire' do
context 'when an avis is created' do
before do
avis_invitation_double = double('avis_invitation', deliver_now: true)
allow(AvisMailer).to receive(:avis_invitation).and_return(avis_invitation_double)
Avis.create(claimant: claimant, email: 'email@l.com')
end
it { expect(AvisMailer).to have_received(:avis_invitation) }
end
end
end