Commit a6cdc20c
Changed files (2)
app
models
spec
models
app/models/password_reset.rb
@@ -3,7 +3,7 @@ class PasswordReset
user = User.find_by(email: email)
return if user.nil?
user.update(reset_password_token: SecureRandom.hex(32), reset_password_sent_at: DateTime.now)
- PasswordResetMailer.delay.send_password_reset_instructions_to(user)
+ PasswordResetMailer.send_password_reset_instructions_to(user).deliver_later
end
def self.reset(reset_token, new_password)
spec/models/password_reset_spec.rb
@@ -3,10 +3,12 @@ require "rails_helper"
describe PasswordReset do
describe ".send_reset_instructions_to" do
let(:user) { create(:user, reset_password_token: nil, reset_password_sent_at: nil) }
- let(:mailer) { double(send_password_reset_instructions_to: true) }
+ let(:mailer) { double(deliver_later: true) }
before :each do
- allow(PasswordResetMailer).to receive(:delay).and_return(mailer)
+ allow(PasswordResetMailer).to receive(:send_password_reset_instructions_to).
+ with(user).
+ and_return(mailer)
end
it "creates a new reset token for the user" do
@@ -18,12 +20,12 @@ describe PasswordReset do
it "sends an email to the user" do
PasswordReset.send_reset_instructions_to(user.email)
- expect(mailer).to have_received(:send_password_reset_instructions_to).with(user)
+ expect(mailer).to have_received(:deliver_later)
end
it "does nothing if the email is not known" do
PasswordReset.send_reset_instructions_to(Faker::Internet.email)
- expect(mailer).to_not have_received(:send_password_reset_instructions_to)
+ expect(mailer).to_not have_received(:deliver_later)
end
end