Set notified events as expected.

git-svn-id: http://svn.redmine.org/redmine/trunk@13683 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang
2014-11-30 20:44:29 +00:00
parent 62cf53384d
commit 430c8fd904
2 changed files with 102 additions and 90 deletions

View File

@@ -2036,6 +2036,7 @@ class IssuesControllerTest < ActionController::TestCase
@request.session[:user_id] = 2 @request.session[:user_id] = 2
ActionMailer::Base.deliveries.clear ActionMailer::Base.deliveries.clear
with_settings :notified_events => %w(issue_added) do
assert_difference 'Watcher.count', 2 do assert_difference 'Watcher.count', 2 do
post :create, :project_id => 1, post :create, :project_id => 1,
:issue => {:tracker_id => 1, :issue => {:tracker_id => 1,
@@ -2044,6 +2045,7 @@ class IssuesControllerTest < ActionController::TestCase
:priority_id => 5, :priority_id => 5,
:watcher_user_ids => ['2', '3']} :watcher_user_ids => ['2', '3']}
end end
end
issue = Issue.find_by_subject('This is a new issue with watchers') issue = Issue.find_by_subject('This is a new issue with watchers')
assert_not_nil issue assert_not_nil issue
assert_redirected_to :controller => 'issues', :action => 'show', :id => issue assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
@@ -2148,6 +2150,7 @@ class IssuesControllerTest < ActionController::TestCase
def test_post_create_should_send_a_notification def test_post_create_should_send_a_notification
ActionMailer::Base.deliveries.clear ActionMailer::Base.deliveries.clear
@request.session[:user_id] = 2 @request.session[:user_id] = 2
with_settings :notified_events => %w(issue_added) do
assert_difference 'Issue.count' do assert_difference 'Issue.count' do
post :create, :project_id => 1, post :create, :project_id => 1,
:issue => {:tracker_id => 3, :issue => {:tracker_id => 3,
@@ -2161,6 +2164,7 @@ class IssuesControllerTest < ActionController::TestCase
assert_equal 1, ActionMailer::Base.deliveries.size assert_equal 1, ActionMailer::Base.deliveries.size
end end
end
def test_post_create_should_preserve_fields_values_on_validation_failure def test_post_create_should_preserve_fields_values_on_validation_failure
@request.session[:user_id] = 2 @request.session[:user_id] = 2
@@ -2237,7 +2241,7 @@ class IssuesControllerTest < ActionController::TestCase
set_tmp_attachments_directory set_tmp_attachments_directory
@request.session[:user_id] = 2 @request.session[:user_id] = 2
with_settings :host_name => 'mydomain.foo', :protocol => 'http' do with_settings :host_name => 'mydomain.foo', :protocol => 'http', :notified_events => %w(issue_added) do
assert_difference 'Issue.count' do assert_difference 'Issue.count' do
post :create, :project_id => 1, post :create, :project_id => 1,
:issue => { :tracker_id => '1', :subject => 'With attachment' }, :issue => { :tracker_id => '1', :subject => 'With attachment' },
@@ -2841,37 +2845,27 @@ class IssuesControllerTest < ActionController::TestCase
def test_put_update_without_custom_fields_param def test_put_update_without_custom_fields_param
@request.session[:user_id] = 2 @request.session[:user_id] = 2
ActionMailer::Base.deliveries.clear
issue = Issue.find(1) issue = Issue.find(1)
assert_equal '125', issue.custom_value_for(2).value assert_equal '125', issue.custom_value_for(2).value
old_subject = issue.subject
new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
assert_difference('Journal.count') do assert_difference('Journal.count') do
assert_difference('JournalDetail.count', 2) do assert_difference('JournalDetail.count') do
put :update, :id => 1, :issue => {:subject => new_subject, put :update, :id => 1, :issue => {:subject => 'New subject'}
:priority_id => '6',
:category_id => '1' # no change
}
end end
end end
assert_redirected_to :action => 'show', :id => '1' assert_redirected_to :action => 'show', :id => '1'
issue.reload issue.reload
assert_equal new_subject, issue.subject assert_equal 'New subject', issue.subject
# Make sure custom fields were not cleared # Make sure custom fields were not cleared
assert_equal '125', issue.custom_value_for(2).value assert_equal '125', issue.custom_value_for(2).value
mail = ActionMailer::Base.deliveries.last
assert_not_nil mail
assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
assert_mail_body_match "Subject changed from #{old_subject} to #{new_subject}", mail
end end
def test_put_update_with_project_change def test_put_update_with_project_change
@request.session[:user_id] = 2 @request.session[:user_id] = 2
ActionMailer::Base.deliveries.clear ActionMailer::Base.deliveries.clear
with_settings :notified_events => %w(issue_updated) do
assert_difference('Journal.count') do assert_difference('Journal.count') do
assert_difference('JournalDetail.count', 3) do assert_difference('JournalDetail.count', 3) do
put :update, :id => 1, :issue => {:project_id => '2', put :update, :id => 1, :issue => {:project_id => '2',
@@ -2881,6 +2875,7 @@ class IssuesControllerTest < ActionController::TestCase
} }
end end
end end
end
assert_redirected_to :action => 'show', :id => '1' assert_redirected_to :action => 'show', :id => '1'
issue = Issue.find(1) issue = Issue.find(1)
assert_equal 2, issue.project_id assert_equal 2, issue.project_id
@@ -2898,6 +2893,7 @@ class IssuesControllerTest < ActionController::TestCase
@request.session[:user_id] = 2 @request.session[:user_id] = 2
ActionMailer::Base.deliveries.clear ActionMailer::Base.deliveries.clear
with_settings :notified_events => %w(issue_updated) do
assert_difference('Journal.count') do assert_difference('Journal.count') do
assert_difference('JournalDetail.count', 2) do assert_difference('JournalDetail.count', 2) do
put :update, :id => 1, :issue => {:project_id => '1', put :update, :id => 1, :issue => {:project_id => '1',
@@ -2906,6 +2902,7 @@ class IssuesControllerTest < ActionController::TestCase
} }
end end
end end
end
assert_redirected_to :action => 'show', :id => '1' assert_redirected_to :action => 'show', :id => '1'
issue = Issue.find(1) issue = Issue.find(1)
assert_equal 1, issue.project_id assert_equal 1, issue.project_id
@@ -2924,6 +2921,7 @@ class IssuesControllerTest < ActionController::TestCase
issue = Issue.find(1) issue = Issue.find(1)
assert_equal '125', issue.custom_value_for(2).value assert_equal '125', issue.custom_value_for(2).value
with_settings :notified_events => %w(issue_updated) do
assert_difference('Journal.count') do assert_difference('Journal.count') do
assert_difference('JournalDetail.count', 3) do assert_difference('JournalDetail.count', 3) do
put :update, :id => 1, :issue => {:subject => 'Custom field change', put :update, :id => 1, :issue => {:subject => 'Custom field change',
@@ -2933,6 +2931,7 @@ class IssuesControllerTest < ActionController::TestCase
} }
end end
end end
end
assert_redirected_to :action => 'show', :id => '1' assert_redirected_to :action => 'show', :id => '1'
issue.reload issue.reload
assert_equal 'New custom value', issue.custom_value_for(2).value assert_equal 'New custom value', issue.custom_value_for(2).value
@@ -2967,12 +2966,15 @@ class IssuesControllerTest < ActionController::TestCase
issue = Issue.find(1) issue = Issue.find(1)
assert_equal 1, issue.status_id assert_equal 1, issue.status_id
@request.session[:user_id] = 2 @request.session[:user_id] = 2
with_settings :notified_events => %w(issue_updated) do
assert_difference('TimeEntry.count', 0) do assert_difference('TimeEntry.count', 0) do
put :update, put :update,
:id => 1, :id => 1,
:issue => { :status_id => 2, :assigned_to_id => 3, :notes => 'Assigned to dlopper' }, :issue => { :status_id => 2, :assigned_to_id => 3, :notes => 'Assigned to dlopper' },
:time_entry => { :hours => '', :comments => '', :activity_id => TimeEntryActivity.first } :time_entry => { :hours => '', :comments => '', :activity_id => TimeEntryActivity.first }
end end
end
assert_redirected_to :action => 'show', :id => '1' assert_redirected_to :action => 'show', :id => '1'
issue.reload issue.reload
assert_equal 2, issue.status_id assert_equal 2, issue.status_id
@@ -2988,10 +2990,13 @@ class IssuesControllerTest < ActionController::TestCase
def test_put_update_with_note_only def test_put_update_with_note_only
notes = 'Note added by IssuesControllerTest#test_update_with_note_only' notes = 'Note added by IssuesControllerTest#test_update_with_note_only'
with_settings :notified_events => %w(issue_updated) do
# anonymous user # anonymous user
put :update, put :update,
:id => 1, :id => 1,
:issue => { :notes => notes } :issue => { :notes => notes }
end
assert_redirected_to :action => 'show', :id => '1' assert_redirected_to :action => 'show', :id => '1'
j = Journal.order('id DESC').first j = Journal.order('id DESC').first
assert_equal notes, j.notes assert_equal notes, j.notes
@@ -3080,12 +3085,14 @@ class IssuesControllerTest < ActionController::TestCase
# journal to get fetched in the next find. # journal to get fetched in the next find.
Journal.delete_all Journal.delete_all
with_settings :notified_events => %w(issue_updated) do
# anonymous user # anonymous user
assert_difference 'Attachment.count' do assert_difference 'Attachment.count' do
put :update, :id => 1, put :update, :id => 1,
:issue => {:notes => ''}, :issue => {:notes => ''},
:attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}} :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
end end
end
assert_redirected_to :action => 'show', :id => '1' assert_redirected_to :action => 'show', :id => '1'
j = Issue.find(1).journals.reorder('id DESC').first j = Issue.find(1).journals.reorder('id DESC').first
@@ -3211,12 +3218,14 @@ class IssuesControllerTest < ActionController::TestCase
old_subject = issue.subject old_subject = issue.subject
new_subject = 'Subject modified by IssuesControllerTest#test_post_edit' new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
with_settings :notified_events => %w(issue_updated) do
put :update, :id => 1, :issue => {:subject => new_subject, put :update, :id => 1, :issue => {:subject => new_subject,
:priority_id => '6', :priority_id => '6',
:category_id => '1' # no change :category_id => '1' # no change
} }
assert_equal 1, ActionMailer::Base.deliveries.size assert_equal 1, ActionMailer::Base.deliveries.size
end end
end
def test_put_update_with_invalid_spent_time_hours_only def test_put_update_with_invalid_spent_time_hours_only
@request.session[:user_id] = 2 @request.session[:user_id] = 2
@@ -3521,6 +3530,7 @@ class IssuesControllerTest < ActionController::TestCase
def test_bullk_update_should_send_a_notification def test_bullk_update_should_send_a_notification
@request.session[:user_id] = 2 @request.session[:user_id] = 2
ActionMailer::Base.deliveries.clear ActionMailer::Base.deliveries.clear
with_settings :notified_events => %w(issue_updated) do
post(:bulk_update, post(:bulk_update,
{ {
:ids => [1, 2], :ids => [1, 2],
@@ -3531,10 +3541,10 @@ class IssuesControllerTest < ActionController::TestCase
:custom_field_values => {'2' => ''} :custom_field_values => {'2' => ''}
} }
}) })
assert_response 302 assert_response 302
assert_equal 2, ActionMailer::Base.deliveries.size assert_equal 2, ActionMailer::Base.deliveries.size
end end
end
def test_bulk_update_project def test_bulk_update_project
@request.session[:user_id] = 2 @request.session[:user_id] = 2

View File

@@ -1825,12 +1825,14 @@ class IssueTest < ActiveSupport::TestCase
user.members.update_all ["mail_notification = ?", false] user.members.update_all ["mail_notification = ?", false]
user.update_attribute :mail_notification, 'only_assigned' user.update_attribute :mail_notification, 'only_assigned'
with_settings :notified_events => %w(issue_updated) do
issue = Issue.find(2) issue = Issue.find(2)
issue.init_journal User.find(1) issue.init_journal User.find(1)
issue.assigned_to = nil issue.assigned_to = nil
issue.save! issue.save!
assert_include user.mail, ActionMailer::Base.deliveries.last.bcc assert_include user.mail, ActionMailer::Base.deliveries.last.bcc
end end
end
def test_stale_issue_should_not_send_email_notification def test_stale_issue_should_not_send_email_notification
ActionMailer::Base.deliveries.clear ActionMailer::Base.deliveries.clear