From a45622585279603ff5b336c78019812a7bef3d37 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Wed, 19 Dec 2007 22:09:31 +0000 Subject: [PATCH] Add email notification to IssuesController#edit. git-svn-id: http://redmine.rubyforge.org/svn/trunk@1018 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/issues_controller.rb | 3 ++- test/functional/issues_controller_test.rb | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 78bcf76a7..f202e9bba 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -96,7 +96,7 @@ class IssuesController < ApplicationController @custom_values = @project.custom_fields_for_issues(@issue.tracker).collect { |x| @issue.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x, :customized => @issue) } else begin - @issue.init_journal(User.current) + journal = @issue.init_journal(User.current) # Retrieve custom fields and values if params["custom_fields"] @custom_values = @project.custom_fields_for_issues(@issue.tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue, :value => params["custom_fields"][x.id.to_s]) } @@ -105,6 +105,7 @@ class IssuesController < ApplicationController @issue.attributes = params[:issue] if @issue.save flash[:notice] = l(:notice_successful_update) + Mailer.deliver_issue_edit(journal) if Setting.notified_events.include?('issue_updated') redirect_to(params[:back_to] || {:action => 'show', :id => @issue}) end rescue ActiveRecord::StaleObjectError diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb index ebcf78f24..06d2f1029 100644 --- a/test/functional/issues_controller_test.rb +++ b/test/functional/issues_controller_test.rb @@ -112,9 +112,21 @@ class IssuesControllerTest < Test::Unit::TestCase def test_post_edit @request.session[:user_id] = 2 - post :edit, :id => 1, :issue => {:subject => 'Modified subject'} + ActionMailer::Base.deliveries.clear + + issue = Issue.find(1) + old_subject = issue.subject + new_subject = 'Subject modified by IssuesControllerTest#test_post_edit' + + post :edit, :id => 1, :issue => {:subject => new_subject} assert_redirected_to 'issues/show/1' - assert_equal 'Modified subject', Issue.find(1).subject + issue.reload + assert_equal new_subject, issue.subject + + mail = ActionMailer::Base.deliveries.last + assert_kind_of TMail::Mail, mail + assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]") + assert mail.body.include?("Subject changed from #{old_subject} to #{new_subject}") end def test_post_change_status -- 2.39.5