From c7489578e61bf81af085cbd541dbcf68742061b2 Mon Sep 17 00:00:00 2001 From: Robb Kidd Date: Mon, 14 May 2012 14:05:32 -0400 Subject: [PATCH] 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. --- Gemfile | 1 + Gemfile.lock | 4 ++ spec/mailers/notify_spec.rb | 82 +++++++++++++++++++++++++++++++++++++ spec/spec_helper.rb | 1 + 4 files changed, 88 insertions(+) create mode 100644 spec/mailers/notify_spec.rb diff --git a/Gemfile b/Gemfile index 1cb5520a..af5b0241 100644 --- a/Gemfile +++ b/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 diff --git a/Gemfile.lock b/Gemfile.lock index 182cf669..6a18f7d1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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 diff --git a/spec/mailers/notify_spec.rb b/spec/mailers/notify_spec.rb new file mode 100644 index 00000000..97ac15dc --- /dev/null +++ b/spec/mailers/notify_spec.rb @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f24496ec..18b7854d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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.