Permalink
Browse files

Add specs for Notify ActionMailer emails.

Covers new user, new issue and wall note emails.

Depends on email_spec (https://github.com/bmabey/email-spec/) for
friendly matchers.
  • Loading branch information...
1 parent be79c9d commit c7489578e61bf81af085cbd541dbcf68742061b2 @robbkidd robbkidd committed May 14, 2012
Showing with 88 additions and 0 deletions.
  1. +1 −0 Gemfile
  2. +4 −0 Gemfile.lock
  3. +82 −0 spec/mailers/notify_spec.rb
  4. +1 −0 spec/spec_helper.rb
View
@@ -66,4 +66,5 @@ group :test do
gem "turn", :require => false
gem "simplecov", :require => false
gem "shoulda", "3.0.1"
+ gem 'email_spec'
end
View
@@ -114,6 +114,9 @@ GEM
warden (~> 1.1)
diff-lcs (1.1.3)
drapper (0.8.4)
+ email_spec (1.2.1)
+ mail (~> 2.2)
+ rspec (~> 2.0)
erubis (2.7.0)
escape_utils (0.2.4)
eventmachine (0.12.10)
@@ -330,6 +333,7 @@ DEPENDENCIES
database_cleaner
devise (~> 1.5)
drapper
+ email_spec
faker
foreman
git
@@ -0,0 +1,82 @@
+require 'spec_helper'
+
+describe Notify do
+ include EmailSpec::Helpers
+ include EmailSpec::Matchers
+
+ before :all do
+ default_url_options[:host] = 'example.com'
+ end
+
+ let(:example_email) { 'user@example.com' }
+
+ describe 'new user email' do
+ let(:example_password) { 'thisismypassword' }
+ let(:example_site_url) { root_url }
+ let(:new_user) { Factory.new(:user, :email => example_email, :password => example_password) }
+
+ subject { Notify.new_user_email(new_user, new_user.password) }
+
+ it 'is sent to the new user' do
+ should deliver_to new_user.email
+ end
+
+ it 'has the correct subject' do
+ should have_subject /Account was created for you/
+ end
+
+ it 'contains the new user\'s login name' do
+ should have_body_text /#{new_user.email}/
+ end
+
+ it 'contains the new user\'s password' do
+ should have_body_text /#{new_user.password}/
+ end
+
+ it 'includes a link to the site' do
+ should have_body_text /#{example_site_url}/
+ end
+ end
+
+ describe 'new issue email' do
+ let(:project) { Factory.create(:project) }
+ let(:assignee) { Factory.create(:user, :email => example_email) }
+ let(:issue) { Factory.create(:issue, :assignee => assignee, :project => project ) }
+
+ subject { Notify.new_issue_email(issue) }
+
+ it 'is sent to the assignee' do
+ should deliver_to assignee.email
+ end
+
+ it 'has the correct subject' do
+ should have_subject /New Issue was created/
+ end
+
+ it 'contains a link to the new issue' do
+ should have_body_text /#{project_issue_url project, issue}/
+ end
+ end
+
+ describe 'note wall email' do
+ let(:project) { Factory.create(:project) }
+ let(:recipient) { Factory.create(:user, :email => example_email) }
+ let(:author) { Factory.create(:user) }
+ let(:note) { Factory.create(:note, :project => project, :author => author) }
+ let(:note_url) { wall_project_url(project, :anchor => "note_#{note.id}") }
+
+ subject { Notify.note_wall_email(recipient, note) }
+
+ it 'is sent to the given recipient' do
+ should deliver_to recipient.email
+ end
+
+ it 'has the correct subject' do
+ should have_subject /#{project.name}/
+ end
+
+ it 'contains a link to the wall note' do
+ should have_body_text /#{note_url}/
+ end
+ end
+end
View
@@ -11,6 +11,7 @@
require 'webmock/rspec'
require 'factories'
require 'monkeypatch'
+require 'email_spec'
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.

0 comments on commit c748957

Please sign in to comment.