]> source.dussan.org Git - redmine.git/commitdiff
Prevent SystemStackError on Issue#all_dependent_issues with mutiple circular dependen...
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 13 Mar 2011 13:00:55 +0000 (13:00 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 13 Mar 2011 13:00:55 +0000 (13:00 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@5104 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/issue.rb
test/unit/issue_test.rb

index 94b4fc0c84d269ba3f4eceb9a80acda259269ea0..de31aa636929591e168acc21dc094a7f455951c1 100644 (file)
@@ -455,11 +455,11 @@ class Issue < ActiveRecord::Base
     (relations_from + relations_to).sort
   end
   
-  def all_dependent_issues(except=nil)
-    except ||= self
+  def all_dependent_issues(except=[])
+    except << self
     dependencies = []
     relations_from.each do |relation|
-      if relation.issue_to && relation.issue_to != except
+      if relation.issue_to && !except.include?(relation.issue_to) 
         dependencies << relation.issue_to
         dependencies += relation.issue_to.all_dependent_issues(except)
       end
index 8dcee3847d0f1085a7b48aded7d1c2b79d2ad7a4..f4dcf6625448a19e96131954439d877df2e4660f 100644 (file)
@@ -686,6 +686,18 @@ class IssueTest < ActiveSupport::TestCase
     
     assert_equal [2, 3], Issue.find(1).all_dependent_issues.collect(&:id).sort
   end
+
+  def test_all_dependent_issues_with_persistent_multiple_circular_dependencies
+    IssueRelation.delete_all
+    assert IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => IssueRelation::TYPE_RELATES)
+    assert IssueRelation.create!(:issue_from => Issue.find(2), :issue_to => Issue.find(3), :relation_type => IssueRelation::TYPE_RELATES)
+    assert IssueRelation.create!(:issue_from => Issue.find(3), :issue_to => Issue.find(8), :relation_type => IssueRelation::TYPE_RELATES)
+    # Validation skipping
+    assert IssueRelation.new(:issue_from => Issue.find(8), :issue_to => Issue.find(2), :relation_type => IssueRelation::TYPE_RELATES).save(false)
+    assert IssueRelation.new(:issue_from => Issue.find(3), :issue_to => Issue.find(1), :relation_type => IssueRelation::TYPE_RELATES).save(false)
+    
+    assert_equal [2, 3, 8], Issue.find(1).all_dependent_issues.collect(&:id).sort
+  end
   
   context "#done_ratio" do
     setup do