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,13 +2036,15 @@ class IssuesControllerTest < ActionController::TestCase
@request.session[:user_id] = 2 @request.session[:user_id] = 2
ActionMailer::Base.deliveries.clear ActionMailer::Base.deliveries.clear
assert_difference 'Watcher.count', 2 do with_settings :notified_events => %w(issue_added) do
post :create, :project_id => 1, assert_difference 'Watcher.count', 2 do
:issue => {:tracker_id => 1, post :create, :project_id => 1,
:subject => 'This is a new issue with watchers', :issue => {:tracker_id => 1,
:description => 'This is the description', :subject => 'This is a new issue with watchers',
:priority_id => 5, :description => 'This is the description',
:watcher_user_ids => ['2', '3']} :priority_id => 5,
: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
@@ -2148,18 +2150,20 @@ 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
assert_difference 'Issue.count' do with_settings :notified_events => %w(issue_added) do
post :create, :project_id => 1, assert_difference 'Issue.count' do
:issue => {:tracker_id => 3, post :create, :project_id => 1,
:subject => 'This is the test_new issue', :issue => {:tracker_id => 3,
:description => 'This is the description', :subject => 'This is the test_new issue',
:priority_id => 5, :description => 'This is the description',
:estimated_hours => '', :priority_id => 5,
:custom_field_values => {'2' => 'Value for field 2'}} :estimated_hours => '',
:custom_field_values => {'2' => 'Value for field 2'}}
end
assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
assert_equal 1, ActionMailer::Base.deliveries.size
end end
assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
assert_equal 1, ActionMailer::Base.deliveries.size
end end
def test_post_create_should_preserve_fields_values_on_validation_failure def test_post_create_should_preserve_fields_values_on_validation_failure
@@ -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,44 +2845,35 @@ 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
assert_difference('Journal.count') do with_settings :notified_events => %w(issue_updated) do
assert_difference('JournalDetail.count', 3) do assert_difference('Journal.count') do
put :update, :id => 1, :issue => {:project_id => '2', assert_difference('JournalDetail.count', 3) do
:tracker_id => '1', # no change put :update, :id => 1, :issue => {:project_id => '2',
:priority_id => '6', :tracker_id => '1', # no change
:category_id => '3' :priority_id => '6',
} :category_id => '3'
}
end
end end
end end
assert_redirected_to :action => 'show', :id => '1' assert_redirected_to :action => 'show', :id => '1'
@@ -2898,12 +2893,14 @@ class IssuesControllerTest < ActionController::TestCase
@request.session[:user_id] = 2 @request.session[:user_id] = 2
ActionMailer::Base.deliveries.clear ActionMailer::Base.deliveries.clear
assert_difference('Journal.count') do with_settings :notified_events => %w(issue_updated) do
assert_difference('JournalDetail.count', 2) do assert_difference('Journal.count') do
put :update, :id => 1, :issue => {:project_id => '1', assert_difference('JournalDetail.count', 2) do
:tracker_id => '2', put :update, :id => 1, :issue => {:project_id => '1',
:priority_id => '6' :tracker_id => '2',
} :priority_id => '6'
}
end
end end
end end
assert_redirected_to :action => 'show', :id => '1' assert_redirected_to :action => 'show', :id => '1'
@@ -2924,13 +2921,15 @@ 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
assert_difference('Journal.count') do with_settings :notified_events => %w(issue_updated) do
assert_difference('JournalDetail.count', 3) do assert_difference('Journal.count') do
put :update, :id => 1, :issue => {:subject => 'Custom field change', assert_difference('JournalDetail.count', 3) do
:priority_id => '6', put :update, :id => 1, :issue => {:subject => 'Custom field change',
:category_id => '1', # no change :priority_id => '6',
:custom_field_values => { '2' => 'New custom value' } :category_id => '1', # no change
} :custom_field_values => { '2' => 'New custom value' }
}
end
end end
end end
assert_redirected_to :action => 'show', :id => '1' assert_redirected_to :action => 'show', :id => '1'
@@ -2967,11 +2966,14 @@ 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
assert_difference('TimeEntry.count', 0) do
put :update, with_settings :notified_events => %w(issue_updated) do
:id => 1, assert_difference('TimeEntry.count', 0) do
:issue => { :status_id => 2, :assigned_to_id => 3, :notes => 'Assigned to dlopper' }, put :update,
:time_entry => { :hours => '', :comments => '', :activity_id => TimeEntryActivity.first } :id => 1,
:issue => { :status_id => 2, :assigned_to_id => 3, :notes => 'Assigned to dlopper' },
: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
@@ -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'
# anonymous user
put :update, with_settings :notified_events => %w(issue_updated) do
:id => 1, # anonymous user
:issue => { :notes => notes } put :update,
:id => 1,
: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,11 +3085,13 @@ 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
# anonymous user with_settings :notified_events => %w(issue_updated) do
assert_difference 'Attachment.count' do # anonymous user
put :update, :id => 1, assert_difference 'Attachment.count' do
:issue => {:notes => ''}, put :update, :id => 1,
:attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}} :issue => {:notes => ''},
: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'
@@ -3211,11 +3218,13 @@ 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'
put :update, :id => 1, :issue => {:subject => new_subject, with_settings :notified_events => %w(issue_updated) do
:priority_id => '6', put :update, :id => 1, :issue => {:subject => new_subject,
:category_id => '1' # no change :priority_id => '6',
} :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
@@ -3521,19 +3530,20 @@ 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
post(:bulk_update, with_settings :notified_events => %w(issue_updated) do
{ post(:bulk_update,
:ids => [1, 2], {
:notes => 'Bulk editing', :ids => [1, 2],
:issue => { :notes => 'Bulk editing',
:priority_id => 7, :issue => {
:assigned_to_id => '', :priority_id => 7,
:custom_field_values => {'2' => ''} :assigned_to_id => '',
} :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

View File

@@ -1825,11 +1825,13 @@ 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'
issue = Issue.find(2) with_settings :notified_events => %w(issue_updated) do
issue.init_journal User.find(1) issue = Issue.find(2)
issue.assigned_to = nil issue.init_journal User.find(1)
issue.save! issue.assigned_to = nil
assert_include user.mail, ActionMailer::Base.deliveries.last.bcc issue.save!
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