Commit 06b45acb8f2491234811a06f01b94af634d58b61

Authored by Robb Kidd
1 parent c7489578

Add specs for all of the emails.

Showing 1 changed file with 194 additions and 33 deletions   Show diff stats
spec/mailers/notify_spec.rb
... ... @@ -8,12 +8,18 @@ describe Notify do
8 8 default_url_options[:host] = 'example.com'
9 9 end
10 10  
11   - let(:example_email) { 'user@example.com' }
  11 + let(:recipient) { Factory.create(:user, :email => 'recipient@example.com') }
  12 + let(:project) { Factory.create(:project) }
12 13  
13   - describe 'new user email' do
14   - let(:example_password) { 'thisismypassword' }
  14 + shared_examples 'a multiple recipients email' do
  15 + it 'is sent to the given recipient' do
  16 + should deliver_to recipient.email
  17 + end
  18 + end
  19 +
  20 + describe 'for new users, the email' do
15 21 let(:example_site_url) { root_url }
16   - let(:new_user) { Factory.new(:user, :email => example_email, :password => example_password) }
  22 + let(:new_user) { Factory.new(:user, :email => 'newguy@example.com', :password => 'new_password') }
17 23  
18 24 subject { Notify.new_user_email(new_user, new_user.password) }
19 25  
... ... @@ -38,45 +44,200 @@ describe Notify do
38 44 end
39 45 end
40 46  
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 ) }
  47 + context 'for a project' do
  48 + describe 'items that are assignable, the email' do
  49 + let(:assignee) { Factory.create(:user, :email => 'assignee@example.com') }
  50 + let(:old_assignee) { Factory.create(:user, :name => 'Old Assignee Guy') }
45 51  
46   - subject { Notify.new_issue_email(issue) }
  52 + shared_examples 'an assignee email' do
  53 + it 'is sent to the assignee' do
  54 + should deliver_to assignee.email
  55 + end
  56 + end
47 57  
48   - it 'is sent to the assignee' do
49   - should deliver_to assignee.email
50   - end
  58 + context 'for issues' do
  59 + let(:issue) { Factory.create(:issue, :assignee => assignee, :project => project ) }
51 60  
52   - it 'has the correct subject' do
53   - should have_subject /New Issue was created/
54   - end
  61 + describe 'that are new' do
  62 + subject { Notify.new_issue_email(issue) }
55 63  
56   - it 'contains a link to the new issue' do
57   - should have_body_text /#{project_issue_url project, issue}/
58   - end
59   - end
  64 + it_behaves_like 'an assignee email'
60 65  
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}") }
  66 + it 'has the correct subject' do
  67 + should have_subject /New Issue was created/
  68 + end
67 69  
68   - subject { Notify.note_wall_email(recipient, note) }
  70 + it 'contains a link to the new issue' do
  71 + should have_body_text /#{project_issue_url project, issue}/
  72 + end
  73 + end
69 74  
70   - it 'is sent to the given recipient' do
71   - should deliver_to recipient.email
72   - end
  75 + describe 'that have been reassigned' do
  76 + before(:each) { issue.stub(:assignee_id_was).and_return(old_assignee.id) }
73 77  
74   - it 'has the correct subject' do
75   - should have_subject /#{project.name}/
  78 + subject { Notify.changed_issue_email(recipient, issue) }
  79 +
  80 + it_behaves_like 'a multiple recipients email'
  81 +
  82 + it 'has the correct subject' do
  83 + should have_subject /changed issue/
  84 + end
  85 +
  86 + it 'contains the name of the previous assignee' do
  87 + should have_body_text /#{old_assignee.name}/
  88 + end
  89 +
  90 + it 'contains the name of the new assignee' do
  91 + should have_body_text /#{assignee.name}/
  92 + end
  93 +
  94 + it 'contains a link to the issue' do
  95 + should have_body_text /#{project_issue_url project, issue}/
  96 + end
  97 + end
  98 + end
  99 +
  100 + context 'for merge requests' do
  101 + let(:merge_request) { Factory.create(:merge_request, :assignee => assignee, :project => project) }
  102 +
  103 + describe 'that are new' do
  104 + subject { Notify.new_merge_request_email(merge_request) }
  105 +
  106 + it_behaves_like 'an assignee email'
  107 +
  108 + it 'has the correct subject' do
  109 + should have_subject /new merge request/
  110 + end
  111 +
  112 + it 'contains a link to the new merge request' do
  113 + should have_body_text /#{project_merge_request_url(project, merge_request)}/
  114 + end
  115 +
  116 + it 'contains the source branch for the merge request' do
  117 + should have_body_text /#{merge_request.source_branch}/
  118 + end
  119 +
  120 + it 'contains the target branch for the merge request' do
  121 + should have_body_text /#{merge_request.target_branch}/
  122 + end
  123 + end
  124 +
  125 + describe 'that are reassigned' do
  126 + before(:each) { merge_request.stub(:assignee_id_was).and_return(old_assignee.id) }
  127 +
  128 + subject { Notify.changed_merge_request_email(recipient, merge_request) }
  129 +
  130 + it_behaves_like 'a multiple recipients email'
  131 +
  132 + it 'has the correct subject' do
  133 + should have_subject /merge request changed/
  134 + end
  135 +
  136 + it 'contains the name of the previous assignee' do
  137 + should have_body_text /#{old_assignee.name}/
  138 + end
  139 +
  140 + it 'contains the name of the new assignee' do
  141 + should have_body_text /#{assignee.name}/
  142 + end
  143 +
  144 + it 'contains a link to the merge request' do
  145 + should have_body_text /#{project_merge_request_url project, merge_request}/
  146 + end
  147 +
  148 + end
  149 + end
76 150 end
77 151  
78   - it 'contains a link to the wall note' do
79   - should have_body_text /#{note_url}/
  152 + context 'items that are noteable, the email for a note' do
  153 + let(:note_author) { Factory.create(:user, :name => 'author_name') }
  154 + let(:note) { Factory.create(:note, :project => project, :author => note_author) }
  155 +
  156 + shared_examples 'a note email' do
  157 + it 'is sent to the given recipient' do
  158 + should deliver_to recipient.email
  159 + end
  160 +
  161 + it 'contains the name of the note\'s author' do
  162 + should have_body_text /#{note_author.name}/
  163 + end
  164 +
  165 + it 'contains the message from the note' do
  166 + should have_body_text /#{note.note}/
  167 + end
  168 + end
  169 +
  170 + describe 'on a project wall' do
  171 + let(:note_on_the_wall_url) { wall_project_url(project, :anchor => "note_#{note.id}") }
  172 +
  173 + subject { Notify.note_wall_email(recipient, note) }
  174 +
  175 + it_behaves_like 'a note email'
  176 +
  177 + it 'has the correct subject' do
  178 + should have_subject /#{project.name}/
  179 + end
  180 +
  181 + it 'contains a link to the wall note' do
  182 + should have_body_text /#{note_on_the_wall_url}/
  183 + end
  184 + end
  185 +
  186 + describe 'on a commit' do
  187 + let(:commit) do
  188 + mock(:commit).tap do |commit|
  189 + commit.stub(:id).and_return('faux_sha_1')
  190 + end
  191 + end
  192 + before(:each) { note.stub(:target).and_return(commit) }
  193 +
  194 + subject { Notify.note_commit_email(recipient, note) }
  195 +
  196 + it_behaves_like 'a note email'
  197 +
  198 + it 'has the correct subject' do
  199 + should have_subject /note for commit/
  200 + end
  201 +
  202 + it 'contains a link to the commit' do
  203 + should have_body_text /faux_sha_1/
  204 + end
  205 + end
  206 +
  207 + describe 'on a merge request' do
  208 + let(:merge_request) { Factory.create(:merge_request, :project => project) }
  209 + let(:note_on_merge_request_url) { project_merge_request_url(project, merge_request, :anchor => "note_#{note.id}") }
  210 + before(:each) { note.stub(:noteable).and_return(merge_request) }
  211 +
  212 + subject { Notify.note_merge_request_email(recipient, note) }
  213 +
  214 + it_behaves_like 'a note email'
  215 +
  216 + it 'has the correct subject' do
  217 + should have_subject /note for merge request/
  218 + end
  219 +
  220 + it 'contains a link to the merge request note' do
  221 + should have_body_text /#{note_on_merge_request_url}/
  222 + end
  223 + end
  224 +
  225 + describe 'on an issue' do
  226 + let(:issue) { Factory.create(:issue, :project => project) }
  227 + let(:note_on_issue_url) { project_issue_url(project, issue, :anchor => "note_#{note.id}") }
  228 + before(:each) { note.stub(:noteable).and_return(issue) }
  229 + subject { Notify.note_issue_email(recipient, note) }
  230 +
  231 + it_behaves_like 'a note email'
  232 +
  233 + it 'has the correct subject' do
  234 + should have_subject /note for issue #{issue.id}/
  235 + end
  236 +
  237 + it 'contains a link to the issue note' do
  238 + should have_body_text /#{note_on_issue_url}/
  239 + end
  240 + end
80 241 end
81 242 end
82 243 end
... ...