Commit bb22360d authored by Robb Kidd's avatar Robb Kidd

Make Notify#note_merge_request_email resque friendly

Update method to take ids and then perform #finds itself during mailer
queue worker kick-off.
parent 5fe75649
...@@ -36,12 +36,11 @@ class Notify < ActionMailer::Base ...@@ -36,12 +36,11 @@ class Notify < ActionMailer::Base
mail(:to => @user['email'], :subject => "gitlab | note for commit | #{@note.project.name} ") mail(:to => @user['email'], :subject => "gitlab | note for commit | #{@note.project.name} ")
end end
def note_merge_request_email(user, note) def note_merge_request_email(recipient_id, note_id)
@user = user recipient = User.find(recipient_id)
@note = Note.find(note['id']) @note = Note.find(note_id)
@project = @note.project
@merge_request = @note.noteable @merge_request = @note.noteable
mail(:to => @user['email'], :subject => "gitlab | note for merge request | #{@note.project.name} ") mail(:to => recipient.email, :subject => "gitlab | note for merge request | #{@note.project.name} ")
end end
def note_issue_email(user, note) def note_issue_email(user, note)
......
...@@ -36,7 +36,7 @@ class MailerObserver < ActiveRecord::Observer ...@@ -36,7 +36,7 @@ class MailerObserver < ActiveRecord::Observer
when "Issue" then when "Issue" then
Notify.note_issue_email(u, note).deliver Notify.note_issue_email(u, note).deliver
when "MergeRequest" then when "MergeRequest" then
Notify.note_merge_request_email(u, note).deliver Notify.note_merge_request_email(u.id, note.id).deliver
when "Snippet" when "Snippet"
true true
else else
......
...@@ -5,13 +5,13 @@ ...@@ -5,13 +5,13 @@
%td{:align => "left", :style => "padding: 20px 0 0;"} %td{:align => "left", :style => "padding: 20px 0 0;"}
%h2{:style => "color:#646464; font-weight: bold; margin: 0; padding: 0; line-height: 26px; font-size: 18px; font-family: Helvetica, Arial, sans-serif; "} %h2{:style => "color:#646464; font-weight: bold; margin: 0; padding: 0; line-height: 26px; font-size: 18px; font-family: Helvetica, Arial, sans-serif; "}
New comment for Merge Request New comment for Merge Request
= link_to truncate(@merge_request.title, :length => 16), project_merge_request_url(@project, @merge_request, :anchor => "note_#{@note.id}") = link_to truncate(@merge_request.title, :length => 16), project_merge_request_url(@merge_request.project, @merge_request, :anchor => "note_#{@note.id}")
%td{:style => "font-size: 1px; line-height: 1px;", :width => "21"} %td{:style => "font-size: 1px; line-height: 1px;", :width => "21"}
%tr %tr
%td{:style => "font-size: 1px; line-height: 1px;", :width => "21"} %td{:style => "font-size: 1px; line-height: 1px;", :width => "21"}
%td{:style => "padding: 15px 0 15px;", :valign => "top"} %td{:style => "padding: 15px 0 15px;", :valign => "top"}
%p{:style => "color:#767676; font-weight: normal; margin: 0; padding: 0; line-height: 20px; font-size: 12px;font-family: Helvetica, Arial, sans-serif; "} %p{:style => "color:#767676; font-weight: normal; margin: 0; padding: 0; line-height: 20px; font-size: 12px;font-family: Helvetica, Arial, sans-serif; "}
%a{:href => "#", :style => "color: #0eb6ce; text-decoration: none;"} #{@note.author.name} %a{:href => "#", :style => "color: #0eb6ce; text-decoration: none;"} #{@note.author_name}
left next message: left next message:
%br %br
%table{:border => "0", :cellpadding => "0", :cellspacing => "0", :width => "558"} %table{:border => "0", :cellpadding => "0", :cellspacing => "0", :width => "558"}
......
...@@ -153,6 +153,10 @@ describe Notify do ...@@ -153,6 +153,10 @@ describe Notify do
let(:note_author) { Factory.create(:user, :name => 'author_name') } let(:note_author) { Factory.create(:user, :name => 'author_name') }
let(:note) { Factory.create(:note, :project => project, :author => note_author) } let(:note) { Factory.create(:note, :project => project, :author => note_author) }
before :each do
Note.stub(:find).with(note.id).and_return(note)
end
shared_examples 'a note email' do shared_examples 'a note email' do
it 'is sent to the given recipient' do it 'is sent to the given recipient' do
should deliver_to recipient.email should deliver_to recipient.email
...@@ -191,7 +195,7 @@ describe Notify do ...@@ -191,7 +195,7 @@ describe Notify do
end end
before(:each) { note.stub(:target).and_return(commit) } before(:each) { note.stub(:target).and_return(commit) }
subject { Notify.note_commit_email(recipient, note) } subject { Notify.note_commit_email(recipient.id, note.id) }
it_behaves_like 'a note email' it_behaves_like 'a note email'
...@@ -209,7 +213,7 @@ describe Notify do ...@@ -209,7 +213,7 @@ describe Notify do
let(:note_on_merge_request_url) { project_merge_request_url(project, merge_request, :anchor => "note_#{note.id}") } let(:note_on_merge_request_url) { project_merge_request_url(project, merge_request, :anchor => "note_#{note.id}") }
before(:each) { note.stub(:noteable).and_return(merge_request) } before(:each) { note.stub(:noteable).and_return(merge_request) }
subject { Notify.note_merge_request_email(recipient, note) } subject { Notify.note_merge_request_email(recipient.id, note.id) }
it_behaves_like 'a note email' it_behaves_like 'a note email'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment