Skip to content

Commit

Permalink
presenter mailer
Browse files Browse the repository at this point in the history
  • Loading branch information
paulanthonywilson committed Apr 14, 2012
1 parent a29912b commit 0e5918b
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
15 changes: 15 additions & 0 deletions app/mailers/presenter_mailer.rb
@@ -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
37 changes: 37 additions & 0 deletions test/functional/presenter_mailer_test.rb
@@ -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

0 comments on commit 0e5918b

Please sign in to comment.