summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGo MAEDA <maeda@farend.jp>2017-12-06 13:23:52 +0000
committerGo MAEDA <maeda@farend.jp>2017-12-06 13:23:52 +0000
commit2e8d269c057c1a78499d6b60f313a39f6ac0b570 (patch)
treebbab380ba948e790f55b87b34e86d010e27132df
parente9963f948338e6ce46478fbb129e9c21c199ef30 (diff)
downloadredmine-2e8d269c057c1a78499d6b60f313a39f6ac0b570.tar.gz
redmine-2e8d269c057c1a78499d6b60f313a39f6ac0b570.zip
Merged r17056 to 3.4-stable (#27663).
git-svn-id: http://svn.redmine.org/redmine/branches/3.4-stable@17057 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/models/issue_relation.rb10
-rw-r--r--test/functional/issue_relations_controller_test.rb4
-rw-r--r--test/unit/issue_relation_test.rb14
3 files changed, 25 insertions, 3 deletions
diff --git a/app/models/issue_relation.rb b/app/models/issue_relation.rb
index d8673596c..d38825ea6 100644
--- a/app/models/issue_relation.rb
+++ b/app/models/issue_relation.rb
@@ -204,13 +204,19 @@ class IssueRelation < ActiveRecord::Base
# Reverses the relation if needed so that it gets stored in the proper way
# Should not be reversed before validation so that it can be displayed back
- # as entered on new relation form
+ # as entered on new relation form.
+ #
+ # Orders relates relations by ID, so that uniqueness index in DB is triggered
+ # on concurrent access.
def reverse_if_needed
if TYPES.has_key?(relation_type) && TYPES[relation_type][:reverse]
issue_tmp = issue_to
self.issue_to = issue_from
self.issue_from = issue_tmp
self.relation_type = TYPES[relation_type][:reverse]
+
+ elsif relation_type == TYPE_RELATES && issue_from_id > issue_to_id
+ self.issue_to, self.issue_from = issue_from, issue_to
end
end
@@ -225,6 +231,8 @@ class IssueRelation < ActiveRecord::Base
issue_from.blocks? issue_to
when 'blocks'
issue_to.blocks? issue_from
+ when 'relates'
+ self.class.where(issue_from_id: issue_to, issue_to_id: issue_from).present?
else
false
end
diff --git a/test/functional/issue_relations_controller_test.rb b/test/functional/issue_relations_controller_test.rb
index 020ff32fd..1842786d5 100644
--- a/test/functional/issue_relations_controller_test.rb
+++ b/test/functional/issue_relations_controller_test.rb
@@ -82,8 +82,8 @@ class IssueRelationsControllerTest < Redmine::ControllerTest
assert_equal 'text/javascript', response.content_type
end
relation = IssueRelation.order('id DESC').first
- assert_equal 3, relation.issue_from_id
- assert_equal 1, relation.issue_to_id
+ assert_equal 1, relation.issue_from_id
+ assert_equal 3, relation.issue_to_id
assert_include 'Bug #1', response.body
end
diff --git a/test/unit/issue_relation_test.rb b/test/unit/issue_relation_test.rb
index e6d126dcb..585a8293e 100644
--- a/test/unit/issue_relation_test.rb
+++ b/test/unit/issue_relation_test.rb
@@ -65,6 +65,20 @@ class IssueRelationTest < ActiveSupport::TestCase
assert_equal from, relation.issue_to
end
+ def test_cannot_create_inverse_relates_relations
+ from = Issue.find(1)
+ to = Issue.find(2)
+
+ relation1 = IssueRelation.new :issue_from => from, :issue_to => to,
+ :relation_type => IssueRelation::TYPE_RELATES
+ assert relation1.save
+
+ relation2 = IssueRelation.new :issue_from => to, :issue_to => from,
+ :relation_type => IssueRelation::TYPE_RELATES
+ assert !relation2.save
+ assert_not_equal [], relation2.errors[:base]
+ end
+
def test_follows_relation_should_not_be_reversed_if_validation_fails
from = Issue.find(1)
to = Issue.find(2)