diff options
author | Marius Balteanu <marius.balteanu@zitec.com> | 2021-08-11 20:35:28 +0000 |
---|---|---|
committer | Marius Balteanu <marius.balteanu@zitec.com> | 2021-08-11 20:35:28 +0000 |
commit | 24a8f97decffc6a3bec3e581d3b93937d0e40531 (patch) | |
tree | 871d5786a38049967c49c8365f6b180595edf39e | |
parent | 10b9620176253a654c4dc00526e40c6ad0d15778 (diff) | |
download | redmine-24a8f97decffc6a3bec3e581d3b93937d0e40531.tar.gz redmine-24a8f97decffc6a3bec3e581d3b93937d0e40531.zip |
Merged r21150 to 4.2-stable (#35655).
git-svn-id: http://svn.redmine.org/redmine/branches/4.2-stable@21153 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r-- | app/controllers/issue_relations_controller.rb | 9 | ||||
-rw-r--r-- | test/functional/issue_relations_controller_test.rb | 25 |
2 files changed, 31 insertions, 3 deletions
diff --git a/app/controllers/issue_relations_controller.rb b/app/controllers/issue_relations_controller.rb index 52be512f1..8143f4f4a 100644 --- a/app/controllers/issue_relations_controller.rb +++ b/app/controllers/issue_relations_controller.rb @@ -56,10 +56,13 @@ class IssueRelationsController < ApplicationController @relation.safe_attributes = params_relation @relation.init_journals(User.current) - unless saved = @relation.save - saved = false - unsaved_relations << @relation + begin + saved = @relation.save + rescue ActiveRecord::RecordNotUnique + @relation.errors.add :base, :taken end + + unsaved_relations << @relation unless saved end respond_to do |format| diff --git a/test/functional/issue_relations_controller_test.rb b/test/functional/issue_relations_controller_test.rb index b5ea6cb93..099254979 100644 --- a/test/functional/issue_relations_controller_test.rb +++ b/test/functional/issue_relations_controller_test.rb @@ -216,6 +216,31 @@ class IssueRelationsControllerTest < Redmine::ControllerTest assert_include 'Related issue cannot be blank', response.body end + def test_create_duplicated_follows_relations_should_not_raise_exception + IssueRelation.create( + :issue_from => Issue.find(1), :issue_to => Issue.find(2), + :relation_type => IssueRelation::TYPE_PRECEDES + ) + + assert_no_difference 'IssueRelation.count' do + post( + :create, + :params => { + :issue_id => 2, + :relation => { + :issue_to_id => 1, + :relation_type => 'follows', + :delay => '' + } + }, + :xhr => true + ) + end + + assert_response :success + assert_include 'has already been taken', response.body + end + def test_bulk_create_with_multiple_issue_to_id_issues assert_difference 'IssueRelation.count', +3 do post :create, :params => { |