Commit bb22360d1a7548facff3b72b2f9a0e66c6a55bb7
1 parent
5fe75649
Exists in
master
and in
4 other branches
Make Notify#note_merge_request_email resque friendly
Update method to take ids and then perform #finds itself during mailer queue worker kick-off.
Showing
4 changed files
with
14 additions
and
11 deletions
Show diff stats
app/mailers/notify.rb
| ... | ... | @@ -35,13 +35,12 @@ class Notify < ActionMailer::Base |
| 35 | 35 | @commit = @note.target |
| 36 | 36 | mail(:to => @user['email'], :subject => "gitlab | note for commit | #{@note.project.name} ") |
| 37 | 37 | end |
| 38 | - | |
| 39 | - def note_merge_request_email(user, note) | |
| 40 | - @user = user | |
| 41 | - @note = Note.find(note['id']) | |
| 42 | - @project = @note.project | |
| 38 | + | |
| 39 | + def note_merge_request_email(recipient_id, note_id) | |
| 40 | + recipient = User.find(recipient_id) | |
| 41 | + @note = Note.find(note_id) | |
| 43 | 42 | @merge_request = @note.noteable |
| 44 | - mail(:to => @user['email'], :subject => "gitlab | note for merge request | #{@note.project.name} ") | |
| 43 | + mail(:to => recipient.email, :subject => "gitlab | note for merge request | #{@note.project.name} ") | |
| 45 | 44 | end |
| 46 | 45 | |
| 47 | 46 | def note_issue_email(user, note) | ... | ... |
app/models/mailer_observer.rb
| ... | ... | @@ -36,7 +36,7 @@ class MailerObserver < ActiveRecord::Observer |
| 36 | 36 | when "Issue" then |
| 37 | 37 | Notify.note_issue_email(u, note).deliver |
| 38 | 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 | 40 | when "Snippet" |
| 41 | 41 | true |
| 42 | 42 | else | ... | ... |
app/views/notify/note_merge_request_email.html.haml
| ... | ... | @@ -5,13 +5,13 @@ |
| 5 | 5 | %td{:align => "left", :style => "padding: 20px 0 0;"} |
| 6 | 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 | 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 | 9 | %td{:style => "font-size: 1px; line-height: 1px;", :width => "21"} |
| 10 | 10 | %tr |
| 11 | 11 | %td{:style => "font-size: 1px; line-height: 1px;", :width => "21"} |
| 12 | 12 | %td{:style => "padding: 15px 0 15px;", :valign => "top"} |
| 13 | 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 | 15 | left next message: |
| 16 | 16 | %br |
| 17 | 17 | %table{:border => "0", :cellpadding => "0", :cellspacing => "0", :width => "558"} | ... | ... |
spec/mailers/notify_spec.rb
| ... | ... | @@ -153,6 +153,10 @@ describe Notify do |
| 153 | 153 | let(:note_author) { Factory.create(:user, :name => 'author_name') } |
| 154 | 154 | let(:note) { Factory.create(:note, :project => project, :author => note_author) } |
| 155 | 155 | |
| 156 | + before :each do | |
| 157 | + Note.stub(:find).with(note.id).and_return(note) | |
| 158 | + end | |
| 159 | + | |
| 156 | 160 | shared_examples 'a note email' do |
| 157 | 161 | it 'is sent to the given recipient' do |
| 158 | 162 | should deliver_to recipient.email |
| ... | ... | @@ -191,7 +195,7 @@ describe Notify do |
| 191 | 195 | end |
| 192 | 196 | before(:each) { note.stub(:target).and_return(commit) } |
| 193 | 197 | |
| 194 | - subject { Notify.note_commit_email(recipient, note) } | |
| 198 | + subject { Notify.note_commit_email(recipient.id, note.id) } | |
| 195 | 199 | |
| 196 | 200 | it_behaves_like 'a note email' |
| 197 | 201 | |
| ... | ... | @@ -209,7 +213,7 @@ describe Notify do |
| 209 | 213 | let(:note_on_merge_request_url) { project_merge_request_url(project, merge_request, :anchor => "note_#{note.id}") } |
| 210 | 214 | before(:each) { note.stub(:noteable).and_return(merge_request) } |
| 211 | 215 | |
| 212 | - subject { Notify.note_merge_request_email(recipient, note) } | |
| 216 | + subject { Notify.note_merge_request_email(recipient.id, note.id) } | |
| 213 | 217 | |
| 214 | 218 | it_behaves_like 'a note email' |
| 215 | 219 | ... | ... |