Commit c7489578e61bf81af085cbd541dbcf68742061b2
1 parent
be79c9de
Exists in
master
and in
4 other branches
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.
Showing
4 changed files
with
88 additions
and
0 deletions
Show diff stats
Gemfile
Gemfile.lock
| @@ -114,6 +114,9 @@ GEM | @@ -114,6 +114,9 @@ GEM | ||
| 114 | warden (~> 1.1) | 114 | warden (~> 1.1) |
| 115 | diff-lcs (1.1.3) | 115 | diff-lcs (1.1.3) |
| 116 | drapper (0.8.4) | 116 | drapper (0.8.4) |
| 117 | + email_spec (1.2.1) | ||
| 118 | + mail (~> 2.2) | ||
| 119 | + rspec (~> 2.0) | ||
| 117 | erubis (2.7.0) | 120 | erubis (2.7.0) |
| 118 | escape_utils (0.2.4) | 121 | escape_utils (0.2.4) |
| 119 | eventmachine (0.12.10) | 122 | eventmachine (0.12.10) |
| @@ -330,6 +333,7 @@ DEPENDENCIES | @@ -330,6 +333,7 @@ DEPENDENCIES | ||
| 330 | database_cleaner | 333 | database_cleaner |
| 331 | devise (~> 1.5) | 334 | devise (~> 1.5) |
| 332 | drapper | 335 | drapper |
| 336 | + email_spec | ||
| 333 | faker | 337 | faker |
| 334 | foreman | 338 | foreman |
| 335 | git | 339 | git |
| @@ -0,0 +1,82 @@ | @@ -0,0 +1,82 @@ | ||
| 1 | +require 'spec_helper' | ||
| 2 | + | ||
| 3 | +describe Notify do | ||
| 4 | + include EmailSpec::Helpers | ||
| 5 | + include EmailSpec::Matchers | ||
| 6 | + | ||
| 7 | + before :all do | ||
| 8 | + default_url_options[:host] = 'example.com' | ||
| 9 | + end | ||
| 10 | + | ||
| 11 | + let(:example_email) { 'user@example.com' } | ||
| 12 | + | ||
| 13 | + describe 'new user email' do | ||
| 14 | + let(:example_password) { 'thisismypassword' } | ||
| 15 | + let(:example_site_url) { root_url } | ||
| 16 | + let(:new_user) { Factory.new(:user, :email => example_email, :password => example_password) } | ||
| 17 | + | ||
| 18 | + subject { Notify.new_user_email(new_user, new_user.password) } | ||
| 19 | + | ||
| 20 | + it 'is sent to the new user' do | ||
| 21 | + should deliver_to new_user.email | ||
| 22 | + end | ||
| 23 | + | ||
| 24 | + it 'has the correct subject' do | ||
| 25 | + should have_subject /Account was created for you/ | ||
| 26 | + end | ||
| 27 | + | ||
| 28 | + it 'contains the new user\'s login name' do | ||
| 29 | + should have_body_text /#{new_user.email}/ | ||
| 30 | + end | ||
| 31 | + | ||
| 32 | + it 'contains the new user\'s password' do | ||
| 33 | + should have_body_text /#{new_user.password}/ | ||
| 34 | + end | ||
| 35 | + | ||
| 36 | + it 'includes a link to the site' do | ||
| 37 | + should have_body_text /#{example_site_url}/ | ||
| 38 | + end | ||
| 39 | + end | ||
| 40 | + | ||
| 41 | + describe 'new issue email' do | ||
| 42 | + let(:project) { Factory.create(:project) } | ||
| 43 | + let(:assignee) { Factory.create(:user, :email => example_email) } | ||
| 44 | + let(:issue) { Factory.create(:issue, :assignee => assignee, :project => project ) } | ||
| 45 | + | ||
| 46 | + subject { Notify.new_issue_email(issue) } | ||
| 47 | + | ||
| 48 | + it 'is sent to the assignee' do | ||
| 49 | + should deliver_to assignee.email | ||
| 50 | + end | ||
| 51 | + | ||
| 52 | + it 'has the correct subject' do | ||
| 53 | + should have_subject /New Issue was created/ | ||
| 54 | + end | ||
| 55 | + | ||
| 56 | + it 'contains a link to the new issue' do | ||
| 57 | + should have_body_text /#{project_issue_url project, issue}/ | ||
| 58 | + end | ||
| 59 | + end | ||
| 60 | + | ||
| 61 | + describe 'note wall email' do | ||
| 62 | + let(:project) { Factory.create(:project) } | ||
| 63 | + let(:recipient) { Factory.create(:user, :email => example_email) } | ||
| 64 | + let(:author) { Factory.create(:user) } | ||
| 65 | + let(:note) { Factory.create(:note, :project => project, :author => author) } | ||
| 66 | + let(:note_url) { wall_project_url(project, :anchor => "note_#{note.id}") } | ||
| 67 | + | ||
| 68 | + subject { Notify.note_wall_email(recipient, note) } | ||
| 69 | + | ||
| 70 | + it 'is sent to the given recipient' do | ||
| 71 | + should deliver_to recipient.email | ||
| 72 | + end | ||
| 73 | + | ||
| 74 | + it 'has the correct subject' do | ||
| 75 | + should have_subject /#{project.name}/ | ||
| 76 | + end | ||
| 77 | + | ||
| 78 | + it 'contains a link to the wall note' do | ||
| 79 | + should have_body_text /#{note_url}/ | ||
| 80 | + end | ||
| 81 | + end | ||
| 82 | +end |
spec/spec_helper.rb
| @@ -11,6 +11,7 @@ require 'capybara/dsl' | @@ -11,6 +11,7 @@ require 'capybara/dsl' | ||
| 11 | require 'webmock/rspec' | 11 | require 'webmock/rspec' |
| 12 | require 'factories' | 12 | require 'factories' |
| 13 | require 'monkeypatch' | 13 | require 'monkeypatch' |
| 14 | +require 'email_spec' | ||
| 14 | 15 | ||
| 15 | # Requires supporting ruby files with custom matchers and macros, etc, | 16 | # Requires supporting ruby files with custom matchers and macros, etc, |
| 16 | # in spec/support/ and its subdirectories. | 17 | # in spec/support/ and its subdirectories. |