Rename changed_issue_email to reassigned_issue_email & make resque friendly

#changed_issue_email was really sending emails about issue reassignments.
Updated method name to reflect that.

Update method to take ids and then perform #finds itself during mailer
queue worker kick-off.
This commit is contained in:
Robb Kidd 2012-05-14 23:27:52 -04:00
parent 345f176a74
commit dd921053c8
4 changed files with 14 additions and 15 deletions

View file

@ -66,12 +66,11 @@ class Notify < ActionMailer::Base
@project = @merge_request.project @project = @merge_request.project
mail(:to => @user['email'], :subject => "gitlab | merge request changed | #{@merge_request.title} ") mail(:to => @user['email'], :subject => "gitlab | merge request changed | #{@merge_request.title} ")
end end
def changed_issue_email(user, issue) def reassigned_issue_email(recipient_id, issue_id, previous_assignee_id)
@issue = Issue.find(issue['id']) recipient = User.find(recipient_id)
@user = user @issue = Issue.find(issue_id)
@assignee_was ||= User.find(@issue.assignee_id_was) @previous_assignee ||= User.find(previous_assignee_id)
@project = @issue.project mail(:to => recipient.email, :subject => "gitlab | changed issue | #{@issue.title} ")
mail(:to => @user['email'], :subject => "gitlab | changed issue | #{@issue.title} ")
end end
end end

View file

@ -78,8 +78,8 @@ class MailerObserver < ActiveRecord::Observer
recipients_ids = issue.assignee_id_was, issue.assignee_id recipients_ids = issue.assignee_id_was, issue.assignee_id
recipients_ids.delete current_user.id recipients_ids.delete current_user.id
User.find(recipients_ids).each do |user| recipients_ids.each do |recipient_id|
Notify.changed_issue_email(user, issue).deliver Notify.reassigned_issue_email(recipient_id, issue.id, issue.assignee_id_was).deliver
end end
end end

View file

@ -5,12 +5,12 @@
%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; "}
Reassigned Issue Reassigned Issue
= link_to truncate(@issue.title, :length => 16), project_issue_url(@project, @issue) = link_to truncate(@issue.title, :length => 16), project_issue_url(@issue.project, @issue)
%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; "}
Assignee changed from #{@assignee_was.name} to #{@issue.assignee.name} Assignee changed from #{@previous_assignee.name} to #{@issue.assignee_name}
%td %td

View file

@ -47,7 +47,7 @@ describe Notify do
context 'for a project' do context 'for a project' do
describe 'items that are assignable, the email' do describe 'items that are assignable, the email' do
let(:assignee) { Factory.create(:user, :email => 'assignee@example.com') } let(:assignee) { Factory.create(:user, :email => 'assignee@example.com') }
let(:old_assignee) { Factory.create(:user, :name => 'Old Assignee Guy') } let(:previous_assignee) { Factory.create(:user, :name => 'Previous Assignee') }
shared_examples 'an assignee email' do shared_examples 'an assignee email' do
it 'is sent to the assignee' do it 'is sent to the assignee' do
@ -73,9 +73,9 @@ describe Notify do
end end
describe 'that have been reassigned' do describe 'that have been reassigned' do
before(:each) { issue.stub(:assignee_id_was).and_return(old_assignee.id) } before(:each) { issue.stub(:assignee_id_was).and_return(previous_assignee.id) }
subject { Notify.changed_issue_email(recipient, issue) } subject { Notify.reassigned_issue_email(recipient.id, issue.id, previous_assignee.id) }
it_behaves_like 'a multiple recipients email' it_behaves_like 'a multiple recipients email'
@ -84,7 +84,7 @@ describe Notify do
end end
it 'contains the name of the previous assignee' do it 'contains the name of the previous assignee' do
should have_body_text /#{old_assignee.name}/ should have_body_text /#{previous_assignee.name}/
end end
it 'contains the name of the new assignee' do it 'contains the name of the new assignee' do