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.
This commit is contained in:
parent
be79c9def9
commit
c7489578e6
1
Gemfile
1
Gemfile
|
@ -66,4 +66,5 @@ group :test do
|
|||
gem "turn", :require => false
|
||||
gem "simplecov", :require => false
|
||||
gem "shoulda", "3.0.1"
|
||||
gem 'email_spec'
|
||||
end
|
||||
|
|
|
@ -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
|
||||
|
|
82
spec/mailers/notify_spec.rb
Normal file
82
spec/mailers/notify_spec.rb
Normal file
|
@ -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
|
|
@ -11,6 +11,7 @@ require 'capybara/dsl'
|
|||
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.
|
||||
|
|
Loading…
Reference in a new issue