Commit c3e9c260

mo khan <mo@mokhan.ca>
2014-09-18 17:13:46
create the password reset mailer.
1 parent 4f5283e
app/mailers/password_reset_mailer.rb
@@ -1,4 +1,8 @@
-class PasswordResetMailer
+class PasswordResetMailer < ActionMailer::Base
+  default from: "noreply@cakeside.com"
+
   def send_password_reset_instructions_to(user)
+    @user = user
+    mail(to: @user.email, subject: "CakeSide - Password Reset Request")
   end
 end
app/views/password_reset_mailer/send_password_reset_instructions_to.text.erb
@@ -0,0 +1,9 @@
+Hi <%= @user.name %>,
+
+To reset your password please copy the following link into your browsers address bar:
+
+<%= edit_password_url(@user.reset_password_token, protocol: 'https') %>
+
+If you did not request a password reset, then please ignore this email.
+
+Have a wonderful day!
spec/mailers/previews/password_reset_mailer_preview.rb
@@ -0,0 +1,5 @@
+class PasswordResetMailerPreview < ActionMailer::Preview
+  def send_password_reset_instructions_to
+    PasswordResetMailer.send_password_reset_instructions_to(User.new(name: 'johnny blaze', reset_password_token: SecureRandom.hex(32)))
+  end
+end
spec/mailers/password_reset_mailer_spec.rb
@@ -0,0 +1,24 @@
+require "rails_helper"
+
+describe PasswordResetMailer do
+  describe '#send_password_reset_instructions_to' do
+    let(:user) { build(:user) }
+    let(:mail) { PasswordResetMailer.send_password_reset_instructions_to(user) }
+
+    it "adds a subject" do
+      expect(mail.subject).to eql("CakeSide - Password Reset Request")
+    end
+
+    it "sends to the users email" do
+      expect(mail.to).to include(user.email)
+    end
+
+    it "should send from the correct address" do
+      expect(mail.from).to include('noreply@cakeside.com')
+    end
+
+    it "includes their name" do
+      expect(mail.body.encoded).to match(user.name)
+    end
+  end
+end