Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

presenter mailer

  • Loading branch information...
commit 0e5918b67de261004e0364ed176751525f41d374 1 parent a29912b
@paulanthonywilson paulanthonywilson authored
View
15 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
View
37 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.
Something went wrong with that request. Please try again.