]> source.dussan.org Git - redmine.git/commitdiff
Fixed create duplicate follow relation fails with 500 internal error (#35655).
authorMarius Balteanu <marius.balteanu@zitec.com>
Tue, 10 Aug 2021 19:35:53 +0000 (19:35 +0000)
committerMarius Balteanu <marius.balteanu@zitec.com>
Tue, 10 Aug 2021 19:35:53 +0000 (19:35 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@21150 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/issue_relations_controller.rb
test/functional/issue_relations_controller_test.rb

index 52be512f16f5fd503eaf1e047ded056c06ac5450..8143f4f4aecff109f9838082e4d6032363ed74f5 100644 (file)
@@ -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|
index b5ea6cb93ecc9a6f8645ca43fc09b6491e4577b5..099254979641e89427e0489438c5b896e60c0ffd 100644 (file)
@@ -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 => {