Commit 1b85cbc6d638e8ddbde1ebcb71cb9fc195fb3012

Authored by Dmitriy Zaporozhets
2 parents be79c9de 991d23e2

Merge pull request #824 from robbkidd/test_the_mailers

Spec Notify mailers
@@ -66,4 +66,5 @@ group :test do @@ -66,4 +66,5 @@ group :test do
66 gem "turn", :require => false 66 gem "turn", :require => false
67 gem "simplecov", :require => false 67 gem "simplecov", :require => false
68 gem "shoulda", "3.0.1" 68 gem "shoulda", "3.0.1"
  69 + gem 'email_spec'
69 end 70 end
@@ -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
app/mailers/notify.rb
@@ -7,71 +7,60 @@ class Notify < ActionMailer::Base @@ -7,71 +7,60 @@ class Notify < ActionMailer::Base
7 7
8 default from: EMAIL_OPTS["from"] 8 default from: EMAIL_OPTS["from"]
9 9
10 - def new_user_email(user, password)  
11 - @user = user 10 + def new_user_email(user_id, password)
  11 + @user = User.find(user_id)
12 @password = password 12 @password = password
13 - mail(:to => @user['email'], :subject => "gitlab | Account was created for you") 13 + mail(:to => @user.email, :subject => "gitlab | Account was created for you")
14 end 14 end
15 15
16 - def new_issue_email(issue)  
17 - @issue = Issue.find(issue['id'])  
18 - @user = @issue.assignee  
19 - @project = @issue.project  
20 -  
21 - mail(:to => @user.email, :subject => "gitlab | New Issue was created") 16 + def new_issue_email(issue_id)
  17 + @issue = Issue.find(issue_id)
  18 + mail(:to => @issue.assignee_email, :subject => "gitlab | New Issue was created")
22 end 19 end
23 20
24 - def note_wall_email(user, note)  
25 - @user = user  
26 - @note = Note.find(note['id'])  
27 - @project = @note.project  
28 - mail(:to => @user['email'], :subject => "gitlab | #{@note.project.name} ") 21 + def note_wall_email(recipient_id, note_id)
  22 + recipient = User.find(recipient_id)
  23 + @note = Note.find(note_id)
  24 + mail(:to => recipient.email, :subject => "gitlab | #{@note.project_name} ")
29 end 25 end
30 26
31 - def note_commit_email(user, note)  
32 - @user = user  
33 - @note = Note.find(note['id'])  
34 - @project = @note.project 27 + def note_commit_email(recipient_id, note_id)
  28 + recipient = User.find(recipient_id)
  29 + @note = Note.find(note_id)
35 @commit = @note.target 30 @commit = @note.target
36 - mail(:to => @user['email'], :subject => "gitlab | note for commit | #{@note.project.name} ") 31 + mail(:to => recipient.email, :subject => "gitlab | note for commit | #{@note.project_name} ")
37 end 32 end
38 -  
39 - def note_merge_request_email(user, note)  
40 - @user = user  
41 - @note = Note.find(note['id'])  
42 - @project = @note.project 33 +
  34 + def note_merge_request_email(recipient_id, note_id)
  35 + recipient = User.find(recipient_id)
  36 + @note = Note.find(note_id)
43 @merge_request = @note.noteable 37 @merge_request = @note.noteable
44 - mail(:to => @user['email'], :subject => "gitlab | note for merge request | #{@note.project.name} ") 38 + mail(:to => recipient.email, :subject => "gitlab | note for merge request | #{@note.project_name} ")
45 end 39 end
46 40
47 - def note_issue_email(user, note)  
48 - @user = user  
49 - @note = Note.find(note['id'])  
50 - @project = @note.project 41 + def note_issue_email(recipient_id, note_id)
  42 + recipient = User.find(recipient_id)
  43 + @note = Note.find(note_id)
51 @issue = @note.noteable 44 @issue = @note.noteable
52 - mail(:to => @user['email'], :subject => "gitlab | note for issue #{@issue.id} | #{@note.project.name} ") 45 + mail(:to => recipient.email, :subject => "gitlab | note for issue #{@issue.id} | #{@note.project_name} ")
53 end 46 end
54 -  
55 - def new_merge_request_email(merge_request)  
56 - @merge_request = MergeRequest.find(merge_request['id'])  
57 - @user = @merge_request.assignee  
58 - @project = @merge_request.project  
59 - mail(:to => @user.email, :subject => "gitlab | new merge request | #{@merge_request.title} ") 47 +
  48 + def new_merge_request_email(merge_request_id)
  49 + @merge_request = MergeRequest.find(merge_request_id)
  50 + mail(:to => @merge_request.assignee_email, :subject => "gitlab | new merge request | #{@merge_request.title} ")
60 end 51 end
61 -  
62 - def changed_merge_request_email(user, merge_request)  
63 - @user = user  
64 - @merge_request = MergeRequest.find(merge_request.id)  
65 - @assignee_was ||= User.find(@merge_request.assignee_id_was)  
66 - @project = @merge_request.project  
67 - mail(:to => @user['email'], :subject => "gitlab | merge request changed | #{@merge_request.title} ") 52 +
  53 + def reassigned_merge_request_email(recipient_id, merge_request_id, previous_assignee_id)
  54 + recipient = User.find(recipient_id)
  55 + @merge_request = MergeRequest.find(merge_request_id)
  56 + @previous_assignee ||= User.find(previous_assignee_id)
  57 + mail(:to => recipient.email, :subject => "gitlab | merge request changed | #{@merge_request.title} ")
68 end 58 end
69 -  
70 - def changed_issue_email(user, issue)  
71 - @issue = Issue.find(issue['id'])  
72 - @user = user  
73 - @assignee_was ||= User.find(@issue.assignee_id_was)  
74 - @project = @issue.project  
75 - mail(:to => @user['email'], :subject => "gitlab | changed issue | #{@issue.title} ") 59 +
  60 + def reassigned_issue_email(recipient_id, issue_id, previous_assignee_id)
  61 + recipient = User.find(recipient_id)
  62 + @issue = Issue.find(issue_id)
  63 + @previous_assignee ||= User.find(previous_assignee_id)
  64 + mail(:to => recipient.email, :subject => "gitlab | changed issue | #{@issue.title} ")
76 end 65 end
77 end 66 end
app/models/mailer_observer.rb
@@ -18,12 +18,12 @@ class MailerObserver < ActiveRecord::Observer @@ -18,12 +18,12 @@ class MailerObserver < ActiveRecord::Observer
18 18
19 def new_issue(issue) 19 def new_issue(issue)
20 if issue.assignee != current_user 20 if issue.assignee != current_user
21 - Notify.new_issue_email(issue).deliver 21 + Notify.new_issue_email(issue.id).deliver
22 end 22 end
23 end 23 end
24 24
25 def new_user(user) 25 def new_user(user)
26 - Notify.new_user_email(user, user.password).deliver 26 + Notify.new_user_email(user.id, user.password).deliver
27 end 27 end
28 28
29 def new_note(note) 29 def new_note(note)
@@ -32,26 +32,26 @@ class MailerObserver < ActiveRecord::Observer @@ -32,26 +32,26 @@ class MailerObserver < ActiveRecord::Observer
32 note.project.users.reject { |u| u.id == current_user.id } .each do |u| 32 note.project.users.reject { |u| u.id == current_user.id } .each do |u|
33 case note.noteable_type 33 case note.noteable_type
34 when "Commit" then 34 when "Commit" then
35 - Notify.note_commit_email(u, note).deliver 35 + Notify.note_commit_email(u.id, note.id).deliver
36 when "Issue" then 36 when "Issue" then
37 - Notify.note_issue_email(u, note).deliver 37 + Notify.note_issue_email(u.id, note.id).deliver
38 when "MergeRequest" then 38 when "MergeRequest" then
39 - Notify.note_merge_request_email(u, note).deliver 39 + Notify.note_merge_request_email(u.id, note.id).deliver
40 when "Snippet" 40 when "Snippet"
41 true 41 true
42 else 42 else
43 - Notify.note_wall_email(u, note).deliver 43 + Notify.note_wall_email(u.id, note.id).deliver
44 end 44 end
45 end 45 end
46 # Notify only author of resource 46 # Notify only author of resource
47 elsif note.notify_author 47 elsif note.notify_author
48 - Notify.note_commit_email(note.commit_author, note).deliver 48 + Notify.note_commit_email(note.commit_author.id, note.id).deliver
49 end 49 end
50 end 50 end
51 51
52 def new_merge_request(merge_request) 52 def new_merge_request(merge_request)
53 if merge_request.assignee != current_user 53 if merge_request.assignee != current_user
54 - Notify.new_merge_request_email(merge_request).deliver 54 + Notify.new_merge_request_email(merge_request.id).deliver
55 end 55 end
56 end 56 end
57 57
@@ -61,7 +61,7 @@ class MailerObserver < ActiveRecord::Observer @@ -61,7 +61,7 @@ class MailerObserver < ActiveRecord::Observer
61 recipients_ids.delete current_user.id 61 recipients_ids.delete current_user.id
62 62
63 User.find(recipients_ids).each do |user| 63 User.find(recipients_ids).each do |user|
64 - Notify.changed_merge_request_email(user, merge_request).deliver 64 + Notify.reassigned_merge_request_email(user.id, merge_request.id, merge_request.assignee_id_was).deliver
65 end 65 end
66 end 66 end
67 67
@@ -78,8 +78,8 @@ class MailerObserver < ActiveRecord::Observer @@ -78,8 +78,8 @@ class MailerObserver < ActiveRecord::Observer
78 recipients_ids = issue.assignee_id_was, issue.assignee_id 78 recipients_ids = issue.assignee_id_was, issue.assignee_id
79 recipients_ids.delete current_user.id 79 recipients_ids.delete current_user.id
80 80
81 - User.find(recipients_ids).each do |user|  
82 - Notify.changed_issue_email(user, issue).deliver 81 + recipients_ids.each do |recipient_id|
  82 + Notify.reassigned_issue_email(recipient_id, issue.id, issue.assignee_id_was).deliver
83 end 83 end
84 end 84 end
85 85
app/models/note.rb
@@ -8,6 +8,10 @@ class Note < ActiveRecord::Base @@ -8,6 +8,10 @@ class Note < ActiveRecord::Base
8 :class_name => "User" 8 :class_name => "User"
9 9
10 delegate :name, 10 delegate :name,
  11 + :to => :project,
  12 + :prefix => true
  13 +
  14 + delegate :name,
11 :email, 15 :email,
12 :to => :author, 16 :to => :author,
13 :prefix => true 17 :prefix => true
app/views/notify/changed_issue_email.html.haml
@@ -1,16 +0,0 @@ @@ -1,16 +0,0 @@
1 -%td.content{:align => "left", :style => "font-family: Helvetica, Arial, sans-serif; padding: 20px 0 0;", :valign => "top", :width => "600"}  
2 - %table{:border => "0", :cellpadding => "0", :cellspacing => "0", :style => "color: #717171; font: normal 11px Helvetica, Arial, sans-serif; margin: 0; padding: 0;", :width => "600"}  
3 - %tr  
4 - %td{:style => "font-size: 1px; line-height: 1px;", :width => "21"}  
5 - %td{:align => "left", :style => "padding: 20px 0 0;"}  
6 - %h2{:style => "color:#646464; font-weight: bold; margin: 0; padding: 0; line-height: 26px; font-size: 18px; font-family: Helvetica, Arial, sans-serif; "}  
7 - Reassigned Issue  
8 - = link_to truncate(@issue.title, :length => 16), project_issue_url(@project, @issue)  
9 - %td{:style => "font-size: 1px; line-height: 1px;", :width => "21"}  
10 - %tr  
11 - %td{:style => "font-size: 1px; line-height: 1px;", :width => "21"}  
12 - %td{:style => "padding: 15px 0 15px;", :valign => "top"}  
13 - %p{:style => "color:#767676; font-weight: normal; margin: 0; padding: 0; line-height: 20px; font-size: 12px;font-family: Helvetica, Arial, sans-serif; "}  
14 - Assignee changed from #{@assignee_was.name} to #{@issue.assignee.name}  
15 - %td  
16 -  
app/views/notify/changed_merge_request_email.html.haml
@@ -1,16 +0,0 @@ @@ -1,16 +0,0 @@
1 -%td.content{:align => "left", :style => "font-family: Helvetica, Arial, sans-serif; padding: 20px 0 0;", :valign => "top", :width => "600"}  
2 - %table{:border => "0", :cellpadding => "0", :cellspacing => "0", :style => "color: #717171; font: normal 11px Helvetica, Arial, sans-serif; margin: 0; padding: 0;", :width => "600"}  
3 - %tr  
4 - %td{:style => "font-size: 1px; line-height: 1px;", :width => "21"}  
5 - %td{:align => "left", :style => "padding: 20px 0 0;"}  
6 - %h2{:style => "color:#646464; font-weight: bold; margin: 0; padding: 0; line-height: 26px; font-size: 18px; font-family: Helvetica, Arial, sans-serif; "}  
7 - Reassigned Merge Request  
8 - = link_to truncate(@merge_request.title, :length => 16), project_merge_request_url(@project, @merge_request)  
9 - %td{:style => "font-size: 1px; line-height: 1px;", :width => "21"}  
10 - %tr  
11 - %td{:style => "font-size: 1px; line-height: 1px;", :width => "21"}  
12 - %td{:style => "padding: 15px 0 15px;", :valign => "top"}  
13 - %p{:style => "color:#767676; font-weight: normal; margin: 0; padding: 0; line-height: 20px; font-size: 12px;font-family: Helvetica, Arial, sans-serif; "}  
14 - Assignee changed from #{@assignee_was.name} to #{@merge_request.assignee.name}  
15 - %td  
16 -  
app/views/notify/new_issue_email.html.haml
@@ -10,7 +10,7 @@ @@ -10,7 +10,7 @@
10 %td{:style => "font-size: 1px; line-height: 1px;", :width => "21"} 10 %td{:style => "font-size: 1px; line-height: 1px;", :width => "21"}
11 %td{:align => "left", :style => "padding: 20px 0 0;"} 11 %td{:align => "left", :style => "padding: 20px 0 0;"}
12 %h2{:style => "color:#646464 !important; font-weight: bold; margin: 0; padding: 0; line-height: 26px; font-size: 18px; font-family: Helvetica, Arial, sans-serif; "} 12 %h2{:style => "color:#646464 !important; font-weight: bold; margin: 0; padding: 0; line-height: 26px; font-size: 18px; font-family: Helvetica, Arial, sans-serif; "}
13 - = link_to project_issue_url(@project, @issue), :title => @issue.title do 13 + = link_to project_issue_url(@issue.project, @issue), :title => @issue.title do
14 = "Issue ##{@issue.id.to_s}" 14 = "Issue ##{@issue.id.to_s}"
15 = truncate(@issue.title, :length => 45) 15 = truncate(@issue.title, :length => 45)
16 %br 16 %br
app/views/notify/new_merge_request_email.html.haml
@@ -5,16 +5,14 @@ @@ -5,16 +5,14 @@
5 %td{:align => "left", :style => "padding: 20px 0 0;"} 5 %td{:align => "left", :style => "padding: 20px 0 0;"}
6 %h2{:style => "color:#646464; font-weight: bold; margin: 0; padding: 0; line-height: 26px; font-size: 18px; font-family: Helvetica, Arial, sans-serif; "} 6 %h2{:style => "color:#646464; font-weight: bold; margin: 0; padding: 0; line-height: 26px; font-size: 18px; font-family: Helvetica, Arial, sans-serif; "}
7 New Merge Request 7 New Merge Request
8 - = link_to truncate(@merge_request.title, :length => 16), project_merge_request_url(@project, @merge_request) 8 + = link_to truncate(@merge_request.title, :length => 16), project_merge_request_url(@merge_request.project, @merge_request)
9 %td{:style => "font-size: 1px; line-height: 1px;", :width => "21"} 9 %td{:style => "font-size: 1px; line-height: 1px;", :width => "21"}
10 %tr 10 %tr
11 %td{:style => "font-size: 1px; line-height: 1px;", :width => "21"} 11 %td{:style => "font-size: 1px; line-height: 1px;", :width => "21"}
12 %td{:style => "padding: 15px 0 15px;", :valign => "top"} 12 %td{:style => "padding: 15px 0 15px;", :valign => "top"}
13 %p{:style => "color:#767676; font-weight: normal; margin: 0; padding: 0; line-height: 20px; font-size: 12px;font-family: Helvetica, Arial, sans-serif; "} 13 %p{:style => "color:#767676; font-weight: normal; margin: 0; padding: 0; line-height: 20px; font-size: 12px;font-family: Helvetica, Arial, sans-serif; "}
14 Branches: #{@merge_request.source_branch} → #{@merge_request.target_branch} 14 Branches: #{@merge_request.source_branch} → #{@merge_request.target_branch}
15 -  
16 %p{:style => "color:#767676; font-weight: normal; margin: 0; padding: 0; line-height: 20px; font-size: 12px;font-family: Helvetica, Arial, sans-serif; "} 15 %p{:style => "color:#767676; font-weight: normal; margin: 0; padding: 0; line-height: 20px; font-size: 12px;font-family: Helvetica, Arial, sans-serif; "}
17 - Asignee: #{@merge_request.author.name} → #{@merge_request.assignee.name}  
18 - 16 + Asignee: #{@merge_request.author_name} → #{@merge_request.assignee_name}
19 %td 17 %td
20 18
app/views/notify/note_commit_email.html.haml
@@ -5,13 +5,13 @@ @@ -5,13 +5,13 @@
5 %td{:align => "left", :style => "padding: 20px 0 0;"} 5 %td{:align => "left", :style => "padding: 20px 0 0;"}
6 %h2{:style => "color:#646464; font-weight: bold; margin: 0; padding: 0; line-height: 26px; font-size: 18px; font-family: Helvetica, Arial, sans-serif; "} 6 %h2{:style => "color:#646464; font-weight: bold; margin: 0; padding: 0; line-height: 26px; font-size: 18px; font-family: Helvetica, Arial, sans-serif; "}
7 New comment for commit 7 New comment for commit
8 - = link_to truncate(@commit.id.to_s, :length => 16), project_commit_url(@project, :id => @commit.id, :anchor => "note_#{@note.id}") 8 + = link_to truncate(@commit.id.to_s, :length => 16), project_commit_url(@commit.project, :id => @commit.id, :anchor => "note_#{@note.id}")
9 %td{:style => "font-size: 1px; line-height: 1px;", :width => "21"} 9 %td{:style => "font-size: 1px; line-height: 1px;", :width => "21"}
10 %tr 10 %tr
11 %td{:style => "font-size: 1px; line-height: 1px;", :width => "21"} 11 %td{:style => "font-size: 1px; line-height: 1px;", :width => "21"}
12 %td{:style => "padding: 15px 0 15px;", :valign => "top"} 12 %td{:style => "padding: 15px 0 15px;", :valign => "top"}
13 %p{:style => "color:#767676; font-weight: normal; margin: 0; padding: 0; line-height: 20px; font-size: 12px;font-family: Helvetica, Arial, sans-serif; "} 13 %p{:style => "color:#767676; font-weight: normal; margin: 0; padding: 0; line-height: 20px; font-size: 12px;font-family: Helvetica, Arial, sans-serif; "}
14 - %a{:href => "#", :style => "color: #0eb6ce; text-decoration: none;"} #{@note.author.name} 14 + %a{:href => "#", :style => "color: #0eb6ce; text-decoration: none;"} #{@note.author_name}
15 left next message: 15 left next message:
16 %br 16 %br
17 %table{:border => "0", :cellpadding => "0", :cellspacing => "0", :width => "558"} 17 %table{:border => "0", :cellpadding => "0", :cellspacing => "0", :width => "558"}
app/views/notify/note_issue_email.html.haml
@@ -5,7 +5,7 @@ @@ -5,7 +5,7 @@
5 %td{:align => "left", :style => "padding: 20px 0 0;"} 5 %td{:align => "left", :style => "padding: 20px 0 0;"}
6 %h2{:style => "color:#646464 !important; font-weight: bold; margin: 0; padding: 0; line-height: 26px; font-size: 18px; font-family: Helvetica, Arial, sans-serif; "} 6 %h2{:style => "color:#646464 !important; font-weight: bold; margin: 0; padding: 0; line-height: 26px; font-size: 18px; font-family: Helvetica, Arial, sans-serif; "}
7 New comment - 7 New comment -
8 - = link_to project_issue_url(@project, @issue, :anchor => "note_#{@note.id}") do 8 + = link_to project_issue_url(@issue.project, @issue, :anchor => "note_#{@note.id}") do
9 = "Issue ##{@issue.id.to_s}" 9 = "Issue ##{@issue.id.to_s}"
10 = truncate(@issue.title, :length => 35) 10 = truncate(@issue.title, :length => 35)
11 %td{:style => "font-size: 1px; line-height: 1px;", :width => "21"} 11 %td{:style => "font-size: 1px; line-height: 1px;", :width => "21"}
@@ -13,7 +13,7 @@ @@ -13,7 +13,7 @@
13 %td{:style => "font-size: 1px; line-height: 1px;", :width => "21"} 13 %td{:style => "font-size: 1px; line-height: 1px;", :width => "21"}
14 %td{:style => "padding: 15px 0 15px;", :valign => "top"} 14 %td{:style => "padding: 15px 0 15px;", :valign => "top"}
15 %p{:style => "color:#767676; font-weight: normal; margin: 0; padding: 0; line-height: 20px; font-size: 12px;font-family: Helvetica, Arial, sans-serif; "} 15 %p{:style => "color:#767676; font-weight: normal; margin: 0; padding: 0; line-height: 20px; font-size: 12px;font-family: Helvetica, Arial, sans-serif; "}
16 - %a{:href => "#", :style => "color: #0eb6ce; text-decoration: none;"} #{@note.author.name} 16 + %a{:href => "#", :style => "color: #0eb6ce; text-decoration: none;"} #{@note.author_name}
17 left next message: 17 left next message:
18 %br 18 %br
19 %table{:border => "0", :cellpadding => "0", :cellspacing => "0", :width => "558"} 19 %table{:border => "0", :cellpadding => "0", :cellspacing => "0", :width => "558"}
app/views/notify/note_merge_request_email.html.haml
@@ -5,13 +5,13 @@ @@ -5,13 +5,13 @@
5 %td{:align => "left", :style => "padding: 20px 0 0;"} 5 %td{:align => "left", :style => "padding: 20px 0 0;"}
6 %h2{:style => "color:#646464; font-weight: bold; margin: 0; padding: 0; line-height: 26px; font-size: 18px; font-family: Helvetica, Arial, sans-serif; "} 6 %h2{:style => "color:#646464; font-weight: bold; margin: 0; padding: 0; line-height: 26px; font-size: 18px; font-family: Helvetica, Arial, sans-serif; "}
7 New comment for Merge Request 7 New comment for Merge Request
8 - = link_to truncate(@merge_request.title, :length => 16), project_merge_request_url(@project, @merge_request, :anchor => "note_#{@note.id}") 8 + = link_to truncate(@merge_request.title, :length => 16), project_merge_request_url(@merge_request.project, @merge_request, :anchor => "note_#{@note.id}")
9 %td{:style => "font-size: 1px; line-height: 1px;", :width => "21"} 9 %td{:style => "font-size: 1px; line-height: 1px;", :width => "21"}
10 %tr 10 %tr
11 %td{:style => "font-size: 1px; line-height: 1px;", :width => "21"} 11 %td{:style => "font-size: 1px; line-height: 1px;", :width => "21"}
12 %td{:style => "padding: 15px 0 15px;", :valign => "top"} 12 %td{:style => "padding: 15px 0 15px;", :valign => "top"}
13 %p{:style => "color:#767676; font-weight: normal; margin: 0; padding: 0; line-height: 20px; font-size: 12px;font-family: Helvetica, Arial, sans-serif; "} 13 %p{:style => "color:#767676; font-weight: normal; margin: 0; padding: 0; line-height: 20px; font-size: 12px;font-family: Helvetica, Arial, sans-serif; "}
14 - %a{:href => "#", :style => "color: #0eb6ce; text-decoration: none;"} #{@note.author.name} 14 + %a{:href => "#", :style => "color: #0eb6ce; text-decoration: none;"} #{@note.author_name}
15 left next message: 15 left next message:
16 %br 16 %br
17 %table{:border => "0", :cellpadding => "0", :cellspacing => "0", :width => "558"} 17 %table{:border => "0", :cellpadding => "0", :cellspacing => "0", :width => "558"}
app/views/notify/note_wall_email.html.haml
@@ -5,13 +5,13 @@ @@ -5,13 +5,13 @@
5 %td{:align => "left", :style => "padding: 20px 0 0;"} 5 %td{:align => "left", :style => "padding: 20px 0 0;"}
6 %h2{:style => "color:#646464; font-weight: bold; margin: 0; padding: 0; line-height: 26px; font-size: 18px; font-family: Helvetica, Arial, sans-serif; "} 6 %h2{:style => "color:#646464; font-weight: bold; margin: 0; padding: 0; line-height: 26px; font-size: 18px; font-family: Helvetica, Arial, sans-serif; "}
7 New message on 7 New message on
8 - = link_to "Project Wall", wall_project_url(@project, :anchor => "note_#{@note.id}") 8 + = link_to "Project Wall", wall_project_url(@note.project, :anchor => "note_#{@note.id}")
9 %td{:style => "font-size: 1px; line-height: 1px;", :width => "21"} 9 %td{:style => "font-size: 1px; line-height: 1px;", :width => "21"}
10 %tr 10 %tr
11 %td{:style => "font-size: 1px; line-height: 1px;", :width => "21"} 11 %td{:style => "font-size: 1px; line-height: 1px;", :width => "21"}
12 %td{:style => "padding: 15px 0 15px;", :valign => "top"} 12 %td{:style => "padding: 15px 0 15px;", :valign => "top"}
13 %p{:style => "color:#767676; font-weight: normal; margin: 0; padding: 0; line-height: 20px; font-size: 12px;font-family: Helvetica, Arial, sans-serif; "} 13 %p{:style => "color:#767676; font-weight: normal; margin: 0; padding: 0; line-height: 20px; font-size: 12px;font-family: Helvetica, Arial, sans-serif; "}
14 - %a{:href => "#", :style => "color: #0eb6ce; text-decoration: none;"} #{@note.author.name} 14 + %a{:href => "#", :style => "color: #0eb6ce; text-decoration: none;"} #{@note.author_name}
15 left next message: 15 left next message:
16 %br 16 %br
17 %table{:border => "0", :cellpadding => "0", :cellspacing => "0", :width => "558"} 17 %table{:border => "0", :cellpadding => "0", :cellspacing => "0", :width => "558"}
app/views/notify/reassigned_issue_email.html.haml 0 → 100644
@@ -0,0 +1,16 @@ @@ -0,0 +1,16 @@
  1 +%td.content{:align => "left", :style => "font-family: Helvetica, Arial, sans-serif; padding: 20px 0 0;", :valign => "top", :width => "600"}
  2 + %table{:border => "0", :cellpadding => "0", :cellspacing => "0", :style => "color: #717171; font: normal 11px Helvetica, Arial, sans-serif; margin: 0; padding: 0;", :width => "600"}
  3 + %tr
  4 + %td{:style => "font-size: 1px; line-height: 1px;", :width => "21"}
  5 + %td{:align => "left", :style => "padding: 20px 0 0;"}
  6 + %h2{:style => "color:#646464; font-weight: bold; margin: 0; padding: 0; line-height: 26px; font-size: 18px; font-family: Helvetica, Arial, sans-serif; "}
  7 + Reassigned Issue
  8 + = link_to truncate(@issue.title, :length => 16), project_issue_url(@issue.project, @issue)
  9 + %td{:style => "font-size: 1px; line-height: 1px;", :width => "21"}
  10 + %tr
  11 + %td{:style => "font-size: 1px; line-height: 1px;", :width => "21"}
  12 + %td{:style => "padding: 15px 0 15px;", :valign => "top"}
  13 + %p{:style => "color:#767676; font-weight: normal; margin: 0; padding: 0; line-height: 20px; font-size: 12px;font-family: Helvetica, Arial, sans-serif; "}
  14 + Assignee changed from #{@previous_assignee.name} to #{@issue.assignee_name}
  15 + %td
  16 +
app/views/notify/reassigned_merge_request_email.html.haml 0 → 100644
@@ -0,0 +1,16 @@ @@ -0,0 +1,16 @@
  1 +%td.content{:align => "left", :style => "font-family: Helvetica, Arial, sans-serif; padding: 20px 0 0;", :valign => "top", :width => "600"}
  2 + %table{:border => "0", :cellpadding => "0", :cellspacing => "0", :style => "color: #717171; font: normal 11px Helvetica, Arial, sans-serif; margin: 0; padding: 0;", :width => "600"}
  3 + %tr
  4 + %td{:style => "font-size: 1px; line-height: 1px;", :width => "21"}
  5 + %td{:align => "left", :style => "padding: 20px 0 0;"}
  6 + %h2{:style => "color:#646464; font-weight: bold; margin: 0; padding: 0; line-height: 26px; font-size: 18px; font-family: Helvetica, Arial, sans-serif; "}
  7 + Reassigned Merge Request
  8 + = link_to truncate(@merge_request.title, :length => 16), project_merge_request_url(@merge_request.project, @merge_request)
  9 + %td{:style => "font-size: 1px; line-height: 1px;", :width => "21"}
  10 + %tr
  11 + %td{:style => "font-size: 1px; line-height: 1px;", :width => "21"}
  12 + %td{:style => "padding: 15px 0 15px;", :valign => "top"}
  13 + %p{:style => "color:#767676; font-weight: normal; margin: 0; padding: 0; line-height: 20px; font-size: 12px;font-family: Helvetica, Arial, sans-serif; "}
  14 + Assignee changed from #{@previous_assignee.name} to #{@merge_request.assignee_name}
  15 + %td
  16 +
spec/mailers/notify_spec.rb 0 → 100644
@@ -0,0 +1,249 @@ @@ -0,0 +1,249 @@
  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(:recipient) { Factory.create(:user, :email => 'recipient@example.com') }
  12 + let(:project) { Factory.create(:project) }
  13 +
  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
  21 + let(:example_site_url) { root_url }
  22 + let(:new_user) { Factory.create(:user, :email => 'newguy@example.com') }
  23 +
  24 + subject { Notify.new_user_email(new_user.id, new_user.password) }
  25 +
  26 + it 'is sent to the new user' do
  27 + should deliver_to new_user.email
  28 + end
  29 +
  30 + it 'has the correct subject' do
  31 + should have_subject /Account was created for you/
  32 + end
  33 +
  34 + it 'contains the new user\'s login name' do
  35 + should have_body_text /#{new_user.email}/
  36 + end
  37 +
  38 + it 'contains the new user\'s password' do
  39 + should have_body_text /#{new_user.password}/
  40 + end
  41 +
  42 + it 'includes a link to the site' do
  43 + should have_body_text /#{example_site_url}/
  44 + end
  45 + end
  46 +
  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(:previous_assignee) { Factory.create(:user, :name => 'Previous Assignee') }
  51 +
  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
  57 +
  58 + context 'for issues' do
  59 + let(:issue) { Factory.create(:issue, :assignee => assignee, :project => project ) }
  60 +
  61 + describe 'that are new' do
  62 + subject { Notify.new_issue_email(issue.id) }
  63 +
  64 + it_behaves_like 'an assignee email'
  65 +
  66 + it 'has the correct subject' do
  67 + should have_subject /New Issue was created/
  68 + end
  69 +
  70 + it 'contains a link to the new issue' do
  71 + should have_body_text /#{project_issue_url project, issue}/
  72 + end
  73 + end
  74 +
  75 + describe 'that have been reassigned' do
  76 + before(:each) { issue.stub(:assignee_id_was).and_return(previous_assignee.id) }
  77 +
  78 + subject { Notify.reassigned_issue_email(recipient.id, issue.id, previous_assignee.id) }
  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 /#{previous_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.id) }
  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(previous_assignee.id) }
  127 +
  128 + subject { Notify.reassigned_merge_request_email(recipient.id, merge_request.id, previous_assignee.id) }
  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 /#{previous_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
  150 + end
  151 +
  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 + before :each do
  157 + Note.stub(:find).with(note.id).and_return(note)
  158 + end
  159 +
  160 + shared_examples 'a note email' do
  161 + it 'is sent to the given recipient' do
  162 + should deliver_to recipient.email
  163 + end
  164 +
  165 + it 'contains the name of the note\'s author' do
  166 + should have_body_text /#{note_author.name}/
  167 + end
  168 +
  169 + it 'contains the message from the note' do
  170 + should have_body_text /#{note.note}/
  171 + end
  172 + end
  173 +
  174 + describe 'on a project wall' do
  175 + let(:note_on_the_wall_url) { wall_project_url(project, :anchor => "note_#{note.id}") }
  176 +
  177 + subject { Notify.note_wall_email(recipient.id, note.id) }
  178 +
  179 + it_behaves_like 'a note email'
  180 +
  181 + it 'has the correct subject' do
  182 + should have_subject /#{project.name}/
  183 + end
  184 +
  185 + it 'contains a link to the wall note' do
  186 + should have_body_text /#{note_on_the_wall_url}/
  187 + end
  188 + end
  189 +
  190 + describe 'on a commit' do
  191 + let(:commit) do
  192 + mock(:commit).tap do |commit|
  193 + commit.stub(:id).and_return('fauxsha1')
  194 + commit.stub(:project).and_return(project)
  195 + end
  196 + end
  197 + before(:each) { note.stub(:target).and_return(commit) }
  198 +
  199 + subject { Notify.note_commit_email(recipient.id, note.id) }
  200 +
  201 + it_behaves_like 'a note email'
  202 +
  203 + it 'has the correct subject' do
  204 + should have_subject /note for commit/
  205 + end
  206 +
  207 + it 'contains a link to the commit' do
  208 + should have_body_text /fauxsha1/
  209 + end
  210 + end
  211 +
  212 + describe 'on a merge request' do
  213 + let(:merge_request) { Factory.create(:merge_request, :project => project) }
  214 + let(:note_on_merge_request_url) { project_merge_request_url(project, merge_request, :anchor => "note_#{note.id}") }
  215 + before(:each) { note.stub(:noteable).and_return(merge_request) }
  216 +
  217 + subject { Notify.note_merge_request_email(recipient.id, note.id) }
  218 +
  219 + it_behaves_like 'a note email'
  220 +
  221 + it 'has the correct subject' do
  222 + should have_subject /note for merge request/
  223 + end
  224 +
  225 + it 'contains a link to the merge request note' do
  226 + should have_body_text /#{note_on_merge_request_url}/
  227 + end
  228 + end
  229 +
  230 + describe 'on an issue' do
  231 + let(:issue) { Factory.create(:issue, :project => project) }
  232 + let(:note_on_issue_url) { project_issue_url(project, issue, :anchor => "note_#{note.id}") }
  233 + before(:each) { note.stub(:noteable).and_return(issue) }
  234 +
  235 + subject { Notify.note_issue_email(recipient.id, note.id) }
  236 +
  237 + it_behaves_like 'a note email'
  238 +
  239 + it 'has the correct subject' do
  240 + should have_subject /note for issue #{issue.id}/
  241 + end
  242 +
  243 + it 'contains a link to the issue note' do
  244 + should have_body_text /#{note_on_issue_url}/
  245 + end
  246 + end
  247 + end
  248 + end
  249 +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.