Better handling of issue update conflicts (#8691).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8774 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
@@ -52,7 +52,7 @@ class IssuesControllerTransactionTest < ActionController::TestCase
|
||||
User.current = nil
|
||||
end
|
||||
|
||||
def test_put_update_stale_issue
|
||||
def test_update_stale_issue_should_not_update_the_issue
|
||||
issue = Issue.find(2)
|
||||
@request.session[:user_id] = 2
|
||||
|
||||
@@ -65,7 +65,7 @@ class IssuesControllerTransactionTest < ActionController::TestCase
|
||||
:fixed_version_id => 4,
|
||||
:lock_version => (issue.lock_version - 1)
|
||||
},
|
||||
:notes => '',
|
||||
:notes => 'My notes',
|
||||
:attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}},
|
||||
:time_entry => { :hours => '2.5', :comments => '', :activity_id => TimeEntryActivity.first.id }
|
||||
end
|
||||
@@ -74,8 +74,125 @@ class IssuesControllerTransactionTest < ActionController::TestCase
|
||||
|
||||
assert_response :success
|
||||
assert_template 'edit'
|
||||
assert_tag :tag => 'div', :attributes => { :id => 'errorExplanation' },
|
||||
:content => /Data has been updated by another user/
|
||||
assert_tag 'div', :attributes => {:class => 'conflict'}
|
||||
assert_tag 'input', :attributes => {:name => 'conflict_resolution', :value => 'overwrite'}
|
||||
assert_tag 'input', :attributes => {:name => 'conflict_resolution', :value => 'add_notes'}
|
||||
assert_tag 'input', :attributes => {:name => 'conflict_resolution', :value => 'cancel'}
|
||||
end
|
||||
|
||||
def test_update_stale_issue_without_notes_should_not_show_add_notes_option
|
||||
issue = Issue.find(2)
|
||||
@request.session[:user_id] = 2
|
||||
|
||||
put :update, :id => issue.id,
|
||||
:issue => {
|
||||
:fixed_version_id => 4,
|
||||
:lock_version => (issue.lock_version - 1)
|
||||
},
|
||||
:notes => ''
|
||||
|
||||
assert_tag 'div', :attributes => {:class => 'conflict'}
|
||||
assert_tag 'input', :attributes => {:name => 'conflict_resolution', :value => 'overwrite'}
|
||||
assert_no_tag 'input', :attributes => {:name => 'conflict_resolution', :value => 'add_notes'}
|
||||
assert_tag 'input', :attributes => {:name => 'conflict_resolution', :value => 'cancel'}
|
||||
|
||||
end
|
||||
|
||||
def test_update_stale_issue_should_show_conflicting_journals
|
||||
@request.session[:user_id] = 2
|
||||
|
||||
put :update, :id => 1,
|
||||
:issue => {
|
||||
:fixed_version_id => 4,
|
||||
:lock_version => 2
|
||||
},
|
||||
:notes => '',
|
||||
:last_journal_id => 1
|
||||
|
||||
assert_not_nil assigns(:conflict_journals)
|
||||
assert_equal 1, assigns(:conflict_journals).size
|
||||
assert_equal 2, assigns(:conflict_journals).first.id
|
||||
assert_tag 'div', :attributes => {:class => 'conflict'},
|
||||
:descendant => {:content => /Some notes with Redmine links/}
|
||||
end
|
||||
|
||||
def test_update_stale_issue_without_previous_journal_should_show_all_journals
|
||||
@request.session[:user_id] = 2
|
||||
|
||||
put :update, :id => 1,
|
||||
:issue => {
|
||||
:fixed_version_id => 4,
|
||||
:lock_version => 2
|
||||
},
|
||||
:notes => '',
|
||||
:last_journal_id => ''
|
||||
|
||||
assert_not_nil assigns(:conflict_journals)
|
||||
assert_equal 2, assigns(:conflict_journals).size
|
||||
assert_tag 'div', :attributes => {:class => 'conflict'},
|
||||
:descendant => {:content => /Some notes with Redmine links/}
|
||||
assert_tag 'div', :attributes => {:class => 'conflict'},
|
||||
:descendant => {:content => /Journal notes/}
|
||||
end
|
||||
|
||||
def test_update_stale_issue_with_overwrite_conflict_resolution_should_update
|
||||
@request.session[:user_id] = 2
|
||||
|
||||
assert_difference 'Journal.count' do
|
||||
put :update, :id => 1,
|
||||
:issue => {
|
||||
:fixed_version_id => 4,
|
||||
:lock_version => 2
|
||||
},
|
||||
:notes => 'overwrite_conflict_resolution',
|
||||
:conflict_resolution => 'overwrite'
|
||||
end
|
||||
|
||||
assert_response 302
|
||||
issue = Issue.find(1)
|
||||
assert_equal 4, issue.fixed_version_id
|
||||
journal = Journal.first(:order => 'id DESC')
|
||||
assert_equal 'overwrite_conflict_resolution', journal.notes
|
||||
assert journal.details.any?
|
||||
end
|
||||
|
||||
def test_update_stale_issue_with_add_notes_conflict_resolution_should_update
|
||||
@request.session[:user_id] = 2
|
||||
|
||||
assert_difference 'Journal.count' do
|
||||
put :update, :id => 1,
|
||||
:issue => {
|
||||
:fixed_version_id => 4,
|
||||
:lock_version => 2
|
||||
},
|
||||
:notes => 'add_notes_conflict_resolution',
|
||||
:conflict_resolution => 'add_notes'
|
||||
end
|
||||
|
||||
assert_response 302
|
||||
issue = Issue.find(1)
|
||||
assert_nil issue.fixed_version_id
|
||||
journal = Journal.first(:order => 'id DESC')
|
||||
assert_equal 'add_notes_conflict_resolution', journal.notes
|
||||
assert journal.details.empty?
|
||||
end
|
||||
|
||||
def test_update_stale_issue_with_cancel_conflict_resolution_should_redirect_without_updating
|
||||
@request.session[:user_id] = 2
|
||||
|
||||
assert_no_difference 'Journal.count' do
|
||||
put :update, :id => 1,
|
||||
:issue => {
|
||||
:fixed_version_id => 4,
|
||||
:lock_version => 2
|
||||
},
|
||||
:notes => 'add_notes_conflict_resolution',
|
||||
:conflict_resolution => 'cancel'
|
||||
end
|
||||
|
||||
assert_redirected_to '/issues/1'
|
||||
issue = Issue.find(1)
|
||||
assert_nil issue.fixed_version_id
|
||||
end
|
||||
|
||||
def test_index_should_rescue_invalid_sql_query
|
||||
|
||||
Reference in New Issue
Block a user