Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a29912b
commit 0e5918b
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class PresenterMailer < ActionMailer::Base | ||
default from: "conference@scottishrubyconference.com" | ||
def email_about_proposal(proposal, subject, body) | ||
presenter = proposal.presenter | ||
mail(:to => presenter.email, | ||
:subject=>substitute(proposal, subject), | ||
:body=>substitute(proposal, body)) | ||
end | ||
|
||
private | ||
def substitute(proposal, text) | ||
text.gsub("NAME", proposal.presenter.familiar_name). | ||
gsub("PRESENTATION", proposal.title) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
require 'test_helper' | ||
|
||
class PresenterMailerTest < ActionMailer::TestCase | ||
|
||
def setup | ||
@presenter = Factory(:presenter, :email=>'bob@example.com', :familiar_name=>'Bobby') | ||
@proposal = Factory(:proposal, :presenter=>@presenter, :title=>"Fly Fishing") | ||
end | ||
|
||
test "sent to presenter" do | ||
email = PresenterMailer.email_about_proposal(@proposal, "", "") | ||
assert_equal ["bob@example.com"], email.to | ||
end | ||
|
||
test "contains body and subject" do | ||
email = PresenterMailer.email_about_proposal(@proposal, "About something", "Lorem is an ipsum.") | ||
|
||
assert_equal "About something", email.subject | ||
assert_match "Lorem is an ipsum", email.encoded | ||
|
||
end | ||
|
||
test "replaces NAME with the presenter's familiar name" do | ||
email = PresenterMailer.email_about_proposal(@proposal, "About NAME", "Lorem is a NAME.") | ||
|
||
assert_equal "About Bobby", email.subject | ||
assert_match "Lorem is a Bobby", email.encoded | ||
end | ||
|
||
test "replaces PRESENTATION with the presentaton title" do | ||
|
||
email = PresenterMailer.email_about_proposal(@proposal, "About PRESENTATION", "Lorem is PRESENTATION.") | ||
|
||
assert_equal "About Fly Fishing", email.subject | ||
assert_match "Lorem is Fly Fishing", email.encoded | ||
end | ||
end |