Skip to content

Commit f782d0e

Browse files
committed
adding mailer.
1 parent 6e7f9c9 commit f782d0e

5 files changed

Lines changed: 50 additions & 0 deletions

File tree

app/mailers/notification.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Notification < ActionMailer::Base
2+
default from: "steve@hackety.com"
3+
default_url_options[:host] = "example.com"
4+
5+
def new_answer(question)
6+
@question = question
7+
@url = question_url(question, :host => "hackety.com")
8+
mail(:to => question.user.email, :subject => "New Answer on Hackety.com!")
9+
end
10+
end
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Hey there! You asked a question on Hackety.com: ""
2+
3+
Someone has replied with an answer! Check it out here: #{@url}

spec/mailers/notification_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
require "spec_helper"
2+
3+
describe Notification do
4+
describe "new_answer" do
5+
let(:question) { Fabricate(:question) }
6+
let(:mail) { Notification.new_answer(question) }
7+
8+
it "has a link to the question" do
9+
mail.body.encoded.should match(question_url(question, :host => "hackety.com"))
10+
end
11+
12+
it "is from Steve" do
13+
mail.from.should eq(["steve@hackety.com"])
14+
end
15+
16+
it "is to the question's author" do
17+
mail.to.should eq([question.user.email])
18+
end
19+
20+
it "has the proper subject" do
21+
mail.subject.should eq("New Answer on Hackety.com!")
22+
end
23+
end
24+
end

spec/spec_helper.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,7 @@
2323
config.before(:each) do
2424
DatabaseCleaner[:mongo_mapper].clean
2525
end
26+
27+
config.include(MailerMacros)
28+
config.before(:each) { reset_email }
2629
end

spec/support/mailer_macros.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module MailerMacros
2+
def last_email
3+
ActionMailer::Base.deliveries.last
4+
end
5+
6+
def reset_email
7+
ActionMailer::Base.deliveries = []
8+
end
9+
end
10+

0 commit comments

Comments
 (0)