@ -315,10 +315,14 @@ class IssuesControllerTest < ActionController::TestCase
end
end
def test_show_atom
def test_show_atom
get :show , :id = > 1 , :format = > 'atom'
issue = Issue . find ( 2 )
issue . recreate_initial_journal!
get :show , :id = > 2 , :format = > 'atom'
assert_response :success
assert_response :success
assert_template 'journals/index'
assert_template 'journals/index'
assert_select 'content' , :text = > Regexp . new ( Regexp . quote ( 'http://test.host/work_packages/2' ) )
assert_match / http: \/ \/ test \ .host \/ work_packages \/ 2 / , response . body
end
end
def test_show_export_to_pdf
def test_show_export_to_pdf
@ -635,14 +639,14 @@ class IssuesControllerTest < ActionController::TestCase
context " # update " do
context " # update " do
should " ignore status change " do
should " ignore status change " do
assert_difference 'WorkPackageJournal.count' do
assert_difference 'Journal:: WorkPackageJournal.count' do
put :update , :id = > 1 , :notes = > 'just trying' , :issue = > { :status_id = > 3 }
put :update , :id = > 1 , :notes = > 'just trying' , :issue = > { :status_id = > 3 }
end
end
assert_equal 1 , Issue . find ( 1 ) . status_id
assert_equal 1 , Issue . find ( 1 ) . status_id
end
end
should " ignore attributes changes " do
should " ignore attributes changes " do
assert_difference 'WorkPackageJournal.count' do
assert_difference 'Journal:: WorkPackageJournal.count' do
put :update , :id = > 1 , :notes = > 'just trying' , :issue = > { :subject = > 'changed' , :assigned_to_id = > 2 }
put :update , :id = > 1 , :notes = > 'just trying' , :issue = > { :subject = > 'changed' , :assigned_to_id = > 2 }
end
end
issue = Issue . find ( 1 )
issue = Issue . find ( 1 )
@ -662,21 +666,21 @@ class IssuesControllerTest < ActionController::TestCase
context " # update " do
context " # update " do
should " accept authorized status " do
should " accept authorized status " do
assert_difference 'WorkPackageJournal.count' do
assert_difference 'Journal:: WorkPackageJournal.count' do
put :update , :id = > 1 , :notes = > 'just trying' , :issue = > { :status_id = > 3 }
put :update , :id = > 1 , :notes = > 'just trying' , :issue = > { :status_id = > 3 }
end
end
assert_equal 3 , Issue . find ( 1 ) . status_id
assert_equal 3 , Issue . find ( 1 ) . status_id
end
end
should " ignore unauthorized status " do
should " ignore unauthorized status " do
assert_difference 'WorkPackageJournal.count' do
assert_difference 'Journal:: WorkPackageJournal.count' do
put :update , :id = > 1 , :notes = > 'just trying' , :issue = > { :status_id = > 2 }
put :update , :id = > 1 , :notes = > 'just trying' , :issue = > { :status_id = > 2 }
end
end
assert_equal 1 , Issue . find ( 1 ) . status_id
assert_equal 1 , Issue . find ( 1 ) . status_id
end
end
should " accept authorized attributes changes " do
should " accept authorized attributes changes " do
assert_difference 'WorkPackageJournal.count' do
assert_difference 'Journal:: WorkPackageJournal.count' do
put :update , :id = > 1 , :notes = > 'just trying' , :issue = > { :assigned_to_id = > 2 }
put :update , :id = > 1 , :notes = > 'just trying' , :issue = > { :assigned_to_id = > 2 }
end
end
issue = Issue . find ( 1 )
issue = Issue . find ( 1 )
@ -684,7 +688,7 @@ class IssuesControllerTest < ActionController::TestCase
end
end
should " ignore unauthorized attributes changes " do
should " ignore unauthorized attributes changes " do
assert_difference 'WorkPackageJournal.count' do
assert_difference 'Journal:: WorkPackageJournal.count' do
put :update , :id = > 1 , :notes = > 'just trying' , :issue = > { :subject = > 'changed' }
put :update , :id = > 1 , :notes = > 'just trying' , :issue = > { :subject = > 'changed' }
end
end
issue = Issue . find ( 1 )
issue = Issue . find ( 1 )
@ -698,21 +702,21 @@ class IssuesControllerTest < ActionController::TestCase
end
end
should " accept authorized status " do
should " accept authorized status " do
assert_difference 'WorkPackageJournal.count' do
assert_difference 'Journal:: WorkPackageJournal.count' do
put :update , :id = > 1 , :notes = > 'just trying' , :issue = > { :status_id = > 3 }
put :update , :id = > 1 , :notes = > 'just trying' , :issue = > { :status_id = > 3 }
end
end
assert_equal 3 , Issue . find ( 1 ) . status_id
assert_equal 3 , Issue . find ( 1 ) . status_id
end
end
should " ignore unauthorized status " do
should " ignore unauthorized status " do
assert_difference 'WorkPackageJournal.count' do
assert_difference 'Journal:: WorkPackageJournal.count' do
put :update , :id = > 1 , :notes = > 'just trying' , :issue = > { :status_id = > 2 }
put :update , :id = > 1 , :notes = > 'just trying' , :issue = > { :status_id = > 2 }
end
end
assert_equal 1 , Issue . find ( 1 ) . status_id
assert_equal 1 , Issue . find ( 1 ) . status_id
end
end
should " accept authorized attributes changes " do
should " accept authorized attributes changes " do
assert_difference 'WorkPackageJournal.count' do
assert_difference 'Journal:: WorkPackageJournal.count' do
put :update , :id = > 1 , :notes = > 'just trying' , :issue = > { :subject = > 'changed' , :assigned_to_id = > 2 }
put :update , :id = > 1 , :notes = > 'just trying' , :issue = > { :subject = > 'changed' , :assigned_to_id = > 2 }
end
end
issue = Issue . find ( 1 )
issue = Issue . find ( 1 )
@ -793,19 +797,22 @@ class IssuesControllerTest < ActionController::TestCase
ActionMailer :: Base . deliveries . clear
ActionMailer :: Base . deliveries . clear
issue = Issue . find ( 1 )
issue = Issue . find ( 1 )
issue . recreate_initial_journal!
assert_equal '125' , issue . custom_value_for ( 2 ) . value
assert_equal '125' , issue . custom_value_for ( 2 ) . value
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'
assert_difference ( 'WorkPackageJournal.count' ) do
assert_difference ( 'Journal:: WorkPackageJournal.count' ) 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
}
}
end
end
assert issue . current_journal . changed_data . has_key? " subject "
issue . reload
assert issue . current_journal . changed_data . has_key? " priority_id "
assert issue . current_journal . changed_data . has_key? :subject
assert ! issue . current_journal . changed_data . has_key? ( " category_id " )
assert issue . current_journal . changed_data . has_key? :priority_id
assert ! issue . current_journal . changed_data . has_key? ( :category_id )
assert_redirected_to work_package_path ( 1 )
assert_redirected_to work_package_path ( 1 )
issue . reload
issue . reload
@ -823,20 +830,23 @@ class IssuesControllerTest < ActionController::TestCase
def test_put_update_with_custom_field_change
def test_put_update_with_custom_field_change
@request . session [ :user_id ] = 2
@request . session [ :user_id ] = 2
issue = Issue . find ( 1 )
issue = Issue . find ( 1 )
issue . recreate_initial_journal!
ActionMailer :: Base . deliveries . clear
ActionMailer :: Base . deliveries . clear
assert_equal '125' , issue . custom_value_for ( 2 ) . value
assert_equal '125' , issue . custom_value_for ( 2 ) . value
assert_difference ( 'WorkPackageJournal.count' ) do
assert_difference ( 'Journal:: WorkPackageJournal.count' ) do
put :update , :id = > 1 , :issue = > { :subject = > 'Custom field change' ,
put :update , :id = > 1 , :issue = > { :subject = > 'Custom field change' ,
:priority_id = > '6' ,
:priority_id = > '6' ,
:category_id = > '1' , # no change
:category_id = > '1' , # no change
:custom_field_values = > { '2' = > 'New custom value' }
:custom_field_values = > { '2' = > 'New custom value' }
}
}
end
end
assert issue . current_journal . changed_data . has_key? " subject "
issue . reload
assert issue . current_journal . changed_data . has_key? " priority_id "
assert issue . current_journal . changed_data . has_key? :subject
assert ! issue . current_journal . changed_data . has_key? ( " category_id " )
assert issue . current_journal . changed_data . has_key? :priority_id
assert issue . current_journal . changed_data . has_key? " custom_values2 "
assert ! issue . current_journal . changed_data . has_key? ( :category_id )
assert issue . current_journal . changed_data . has_key? :custom_fields_2
assert_redirected_to work_package_path ( 1 )
assert_redirected_to work_package_path ( 1 )
issue . reload
issue . reload
@ -849,6 +859,8 @@ class IssuesControllerTest < ActionController::TestCase
def test_put_update_with_status_and_assignee_change
def test_put_update_with_status_and_assignee_change
issue = Issue . find ( 1 )
issue = Issue . find ( 1 )
issue . recreate_initial_journal!
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
assert_difference ( 'TimeEntry.count' , 0 ) do
@ -861,7 +873,7 @@ class IssuesControllerTest < ActionController::TestCase
assert_redirected_to work_package_path ( 1 )
assert_redirected_to work_package_path ( 1 )
issue . reload
issue . reload
assert_equal 2 , issue . status_id
assert_equal 2 , issue . status_id
j = WorkPackage Journal. find ( :first , :order = > 'id DESC' )
j = Journal . find ( :first , :order = > 'id DESC' )
assert_equal 'Assigned to dlopper' , j . notes
assert_equal 'Assigned to dlopper' , j . notes
assert_equal 2 , j . details . size
assert_equal 2 , j . details . size
@ -872,13 +884,17 @@ class IssuesControllerTest < ActionController::TestCase
end
end
def test_put_update_with_note_only
def test_put_update_with_note_only
issue = Issue . find ( 1 )
issue . recreate_initial_journal!
notes = 'Note added by IssuesControllerTest#test_update_with_note_only'
notes = 'Note added by IssuesControllerTest#test_update_with_note_only'
# anonymous user
# anonymous user
put :update ,
put :update ,
:id = > 1 ,
:id = > 1 ,
:notes = > notes
:notes = > notes
assert_redirected_to work_package_path ( 1 )
assert_redirected_to work_package_path ( 1 )
j = WorkPackageJournal . find ( :first , :order = > 'id DESC' )
issue . reload
j = Journal . find ( :first , :order = > 'id DESC' )
assert_equal notes , j . notes
assert_equal notes , j . notes
assert_equal 0 , j . details . size
assert_equal 0 , j . details . size
assert_equal User . anonymous , j . user
assert_equal User . anonymous , j . user
@ -888,6 +904,9 @@ class IssuesControllerTest < ActionController::TestCase
end
end
def test_put_update_with_note_and_spent_time
def test_put_update_with_note_and_spent_time
issue = Issue . find ( 1 )
issue . recreate_initial_journal!
@request . session [ :user_id ] = 2
@request . session [ :user_id ] = 2
spent_hours_before = Issue . find ( 1 ) . spent_hours
spent_hours_before = Issue . find ( 1 ) . spent_hours
assert_difference ( 'TimeEntry.count' ) do
assert_difference ( 'TimeEntry.count' ) do
@ -898,9 +917,8 @@ class IssuesControllerTest < ActionController::TestCase
end
end
assert_redirected_to work_package_path ( 1 )
assert_redirected_to work_package_path ( 1 )
issue = Issue . find ( 1 )
issue . reload
j = Journal . find ( :first , :order = > 'id DESC' )
j = WorkPackageJournal . find ( :first , :order = > 'id DESC' )
assert_equal '2.5 hours added' , j . notes
assert_equal '2.5 hours added' , j . notes
assert_equal 0 , j . details . size
assert_equal 0 , j . details . size
@ -911,6 +929,9 @@ class IssuesControllerTest < ActionController::TestCase
end
end
def test_put_update_with_attachment_only
def test_put_update_with_attachment_only
issue = Issue . find ( 1 )
issue . recreate_initial_journal!
Setting . host_name = 'mydomain.foo'
Setting . host_name = 'mydomain.foo'
Setting . protocol = 'https'
Setting . protocol = 'https'
@ -938,7 +959,7 @@ class IssuesControllerTest < ActionController::TestCase
# Delete all fixtured journals, a race condition can occur causing the wrong
# Delete all fixtured journals, a race condition can occur causing the wrong
# journal to get fetched in the next find.
# journal to get fetched in the next find.
WorkPackage Journal. delete_all
Journal . delete_all
# Mock out the unsaved attachment
# Mock out the unsaved attachment
Attachment . any_instance . stubs ( :create ) . returns ( Attachment . new )
Attachment . any_instance . stubs ( :create ) . returns ( Attachment . new )
@ -955,9 +976,11 @@ class IssuesControllerTest < ActionController::TestCase
def test_put_update_with_no_change
def test_put_update_with_no_change
issue = Issue . find ( 1 )
issue = Issue . find ( 1 )
issue . recreate_initial_journal!
ActionMailer :: Base . deliveries . clear
ActionMailer :: Base . deliveries . clear
assert_no_difference ( 'WorkPackage Journal.count' ) do
assert_no_difference ( 'Journal.count' ) do
put :update ,
put :update ,
:id = > 1 ,
:id = > 1 ,
:notes = > ''
:notes = > ''
@ -973,6 +996,7 @@ class IssuesControllerTest < ActionController::TestCase
@request . session [ :user_id ] = 2
@request . session [ :user_id ] = 2
ActionMailer :: Base . deliveries . clear
ActionMailer :: Base . deliveries . clear
issue = Issue . find ( 1 )
issue = Issue . find ( 1 )
issue . recreate_initial_journal!
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'
@ -1003,7 +1027,7 @@ class IssuesControllerTest < ActionController::TestCase
@request . session [ :user_id ] = 2
@request . session [ :user_id ] = 2
notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
assert_no_difference ( 'WorkPackageJournal.count' ) do
assert_no_difference ( 'Journal:: WorkPackageJournal.count' ) do
put :update ,
put :update ,
:id = > 1 ,
:id = > 1 ,
:notes = > notes ,
:notes = > notes ,
@ -1021,7 +1045,7 @@ class IssuesControllerTest < ActionController::TestCase
@request . session [ :user_id ] = 2
@request . session [ :user_id ] = 2
notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
assert_no_difference ( 'WorkPackageJournal.count' ) do
assert_no_difference ( 'Journal:: WorkPackageJournal.count' ) do
put :update ,
put :update ,
:id = > 1 ,
:id = > 1 ,
:notes = > notes ,
:notes = > notes ,
@ -1118,6 +1142,9 @@ class IssuesControllerTest < ActionController::TestCase
end
end
def test_bulk_update
def test_bulk_update
issue = Issue . find ( 1 )
issue . recreate_initial_journal!
@request . session [ :user_id ] = 2
@request . session [ :user_id ] = 2
# update issues priority
# update issues priority
put :bulk_update , :ids = > [ 1 , 2 ] , :notes = > 'Bulk editing' ,
put :bulk_update , :ids = > [ 1 , 2 ] , :notes = > 'Bulk editing' ,
@ -1129,7 +1156,7 @@ class IssuesControllerTest < ActionController::TestCase
# check that the issues were updated
# check that the issues were updated
assert_equal [ 7 , 7 ] , Issue . find_all_by_id ( [ 1 , 2 ] ) . collect { | i | i . priority . id }
assert_equal [ 7 , 7 ] , Issue . find_all_by_id ( [ 1 , 2 ] ) . collect { | i | i . priority . id }
issue = Issue . find ( 1 )
issue . reload
journal = issue . journals . reorder ( 'created_at DESC' ) . first
journal = issue . journals . reorder ( 'created_at DESC' ) . first
assert_equal '125' , issue . custom_value_for ( 2 ) . value
assert_equal '125' , issue . custom_value_for ( 2 ) . value
assert_equal 'Bulk editing' , journal . notes
assert_equal 'Bulk editing' , journal . notes
@ -1156,6 +1183,9 @@ class IssuesControllerTest < ActionController::TestCase
end
end
def test_bulk_update_on_different_projects
def test_bulk_update_on_different_projects
issue = Issue . find ( 1 )
issue . recreate_initial_journal!
@request . session [ :user_id ] = 2
@request . session [ :user_id ] = 2
# update issues priority
# update issues priority
put :bulk_update , :ids = > [ 1 , 2 , 6 ] , :notes = > 'Bulk editing' ,
put :bulk_update , :ids = > [ 1 , 2 , 6 ] , :notes = > 'Bulk editing' ,
@ -1167,7 +1197,7 @@ class IssuesControllerTest < ActionController::TestCase
# check that the issues were updated
# check that the issues were updated
assert_equal [ 7 , 7 , 7 ] , Issue . find ( [ 1 , 2 , 6 ] ) . map ( & :priority_id )
assert_equal [ 7 , 7 , 7 ] , Issue . find ( [ 1 , 2 , 6 ] ) . map ( & :priority_id )
issue = Issue . find ( 1 )
issue . reload
journal = issue . journals . reorder ( 'created_at DESC' ) . first
journal = issue . journals . reorder ( 'created_at DESC' ) . first
assert_equal '125' , issue . custom_value_for ( 2 ) . value
assert_equal '125' , issue . custom_value_for ( 2 ) . value
assert_equal 'Bulk editing' , journal . notes
assert_equal 'Bulk editing' , journal . notes
@ -1185,10 +1215,13 @@ class IssuesControllerTest < ActionController::TestCase
:assigned_to_id = > '' ,
:assigned_to_id = > '' ,
:custom_field_values = > { '2' = > '' } }
:custom_field_values = > { '2' = > '' } }
assert_response 403
assert_response 403
assert_not_equal " Bulk should fail " , WorkPackageJournal . last . notes
assert Journal :: WorkPackageJournal . all . empty?
end
end
def test_bulk_update_should_send_a_notification
def test_bulk_update_should_send_a_notification
WorkPackage . find ( 1 ) . recreate_initial_journal!
WorkPackage . find ( 2 ) . recreate_initial_journal!
@request . session [ :user_id ] = 2
@request . session [ :user_id ] = 2
ActionMailer :: Base . deliveries . clear
ActionMailer :: Base . deliveries . clear
put ( :bulk_update ,
put ( :bulk_update ,
@ -1233,6 +1266,9 @@ class IssuesControllerTest < ActionController::TestCase
end
end
def test_bulk_update_custom_field
def test_bulk_update_custom_field
issue = Issue . find ( 1 )
issue . recreate_initial_journal!
@request . session [ :user_id ] = 2
@request . session [ :user_id ] = 2
# update issues priority
# update issues priority
put :bulk_update , :ids = > [ 1 , 2 ] , :notes = > 'Bulk editing custom field' ,
put :bulk_update , :ids = > [ 1 , 2 ] , :notes = > 'Bulk editing custom field' ,
@ -1242,12 +1278,12 @@ class IssuesControllerTest < ActionController::TestCase
assert_response 302
assert_response 302
issue = Issue . find ( 1 )
issue . reload
journal = issue . journals . last
journal = issue . journals . last
assert_equal '777' , issue . custom_value_for ( 2 ) . value
assert_equal '777' , issue . custom_value_for ( 2 ) . value
assert_equal 1 , journal . details . size
assert_equal 1 , journal . details . size
assert_equal '125' , journal . old_value_for ( 'custom_values2' )
assert_equal '125' , journal . old_value_for ( :custom_fields_2 )
assert_equal '777' , journal . new_value_for ( 'custom_values2' )
assert_equal '777' , journal . new_value_for ( :custom_fields_2 )
end
end
def test_bulk_update_unassign
def test_bulk_update_unassign
@ -1359,12 +1395,14 @@ class IssuesControllerTest < ActionController::TestCase
end
end
def test_quote_issue
def test_quote_issue
issue = WorkPackage . find ( 6 )
@request . session [ :user_id ] = 2
@request . session [ :user_id ] = 2
get :quoted , :id = > 6
get :quoted , :id = > 6
assert_response :success
assert_response :success
assert_template 'edit'
assert_template 'edit'
assert_not_nil assigns ( :issue )
assert_not_nil assigns ( :issue )
assert_equal Issue . find ( 6 ) , assigns ( :issue )
assert_equal issue , assigns ( :issue )
end
end
def test_quote_issue_without_permission
def test_quote_issue_without_permission
@ -1374,12 +1412,16 @@ class IssuesControllerTest < ActionController::TestCase
end
end
def test_quote_note
def test_quote_note
issue = Issue . find ( 6 )
journal = FactoryGirl . create :work_package_journal , journable_id : issue . id
@request . session [ :user_id ] = 2
@request . session [ :user_id ] = 2
get :quoted , :id = > 6 , :journal_id = > 4
get :quoted , :id = > 6 , :journal_id = > journal . id
assert_response :success
assert_response :success
assert_template 'edit'
assert_template 'edit'
assert_not_nil assigns ( :issue )
assert_not_nil assigns ( :issue )
assert_equal Issue . find ( 6 ) , assigns ( :issue )
assert_equal Issue . find ( 6 ) , assigns ( :issue )
assert_equal Journal . find ( 4 ) , assigns ( :journal )
assert_equal journal , assigns ( :journal )
end
end
end
end