##// END OF EJS Templates
Fixed circular dependencies possibly introduced when using reverse relations, for instance "blocked by" relations (#8616)....
Jean-Baptiste Barth -
r6004:f982c5b90d52
parent child
Show More
@@ -1,113 +1,118
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 class IssueRelation < ActiveRecord::Base
18 class IssueRelation < ActiveRecord::Base
19 belongs_to :issue_from, :class_name => 'Issue', :foreign_key => 'issue_from_id'
19 belongs_to :issue_from, :class_name => 'Issue', :foreign_key => 'issue_from_id'
20 belongs_to :issue_to, :class_name => 'Issue', :foreign_key => 'issue_to_id'
20 belongs_to :issue_to, :class_name => 'Issue', :foreign_key => 'issue_to_id'
21
21
22 TYPE_RELATES = "relates"
22 TYPE_RELATES = "relates"
23 TYPE_DUPLICATES = "duplicates"
23 TYPE_DUPLICATES = "duplicates"
24 TYPE_DUPLICATED = "duplicated"
24 TYPE_DUPLICATED = "duplicated"
25 TYPE_BLOCKS = "blocks"
25 TYPE_BLOCKS = "blocks"
26 TYPE_BLOCKED = "blocked"
26 TYPE_BLOCKED = "blocked"
27 TYPE_PRECEDES = "precedes"
27 TYPE_PRECEDES = "precedes"
28 TYPE_FOLLOWS = "follows"
28 TYPE_FOLLOWS = "follows"
29
29
30 TYPES = { TYPE_RELATES => { :name => :label_relates_to, :sym_name => :label_relates_to, :order => 1, :sym => TYPE_RELATES },
30 TYPES = { TYPE_RELATES => { :name => :label_relates_to, :sym_name => :label_relates_to, :order => 1, :sym => TYPE_RELATES },
31 TYPE_DUPLICATES => { :name => :label_duplicates, :sym_name => :label_duplicated_by, :order => 2, :sym => TYPE_DUPLICATED },
31 TYPE_DUPLICATES => { :name => :label_duplicates, :sym_name => :label_duplicated_by, :order => 2, :sym => TYPE_DUPLICATED },
32 TYPE_DUPLICATED => { :name => :label_duplicated_by, :sym_name => :label_duplicates, :order => 3, :sym => TYPE_DUPLICATES, :reverse => TYPE_DUPLICATES },
32 TYPE_DUPLICATED => { :name => :label_duplicated_by, :sym_name => :label_duplicates, :order => 3, :sym => TYPE_DUPLICATES, :reverse => TYPE_DUPLICATES },
33 TYPE_BLOCKS => { :name => :label_blocks, :sym_name => :label_blocked_by, :order => 4, :sym => TYPE_BLOCKED },
33 TYPE_BLOCKS => { :name => :label_blocks, :sym_name => :label_blocked_by, :order => 4, :sym => TYPE_BLOCKED },
34 TYPE_BLOCKED => { :name => :label_blocked_by, :sym_name => :label_blocks, :order => 5, :sym => TYPE_BLOCKS, :reverse => TYPE_BLOCKS },
34 TYPE_BLOCKED => { :name => :label_blocked_by, :sym_name => :label_blocks, :order => 5, :sym => TYPE_BLOCKS, :reverse => TYPE_BLOCKS },
35 TYPE_PRECEDES => { :name => :label_precedes, :sym_name => :label_follows, :order => 6, :sym => TYPE_FOLLOWS },
35 TYPE_PRECEDES => { :name => :label_precedes, :sym_name => :label_follows, :order => 6, :sym => TYPE_FOLLOWS },
36 TYPE_FOLLOWS => { :name => :label_follows, :sym_name => :label_precedes, :order => 7, :sym => TYPE_PRECEDES, :reverse => TYPE_PRECEDES }
36 TYPE_FOLLOWS => { :name => :label_follows, :sym_name => :label_precedes, :order => 7, :sym => TYPE_PRECEDES, :reverse => TYPE_PRECEDES }
37 }.freeze
37 }.freeze
38
38
39 validates_presence_of :issue_from, :issue_to, :relation_type
39 validates_presence_of :issue_from, :issue_to, :relation_type
40 validates_inclusion_of :relation_type, :in => TYPES.keys
40 validates_inclusion_of :relation_type, :in => TYPES.keys
41 validates_numericality_of :delay, :allow_nil => true
41 validates_numericality_of :delay, :allow_nil => true
42 validates_uniqueness_of :issue_to_id, :scope => :issue_from_id
42 validates_uniqueness_of :issue_to_id, :scope => :issue_from_id
43
43
44 attr_protected :issue_from_id, :issue_to_id
44 attr_protected :issue_from_id, :issue_to_id
45
45
46 def validate
46 def validate
47 if issue_from && issue_to
47 if issue_from && issue_to
48 errors.add :issue_to_id, :invalid if issue_from_id == issue_to_id
48 errors.add :issue_to_id, :invalid if issue_from_id == issue_to_id
49 errors.add :issue_to_id, :not_same_project unless issue_from.project_id == issue_to.project_id || Setting.cross_project_issue_relations?
49 errors.add :issue_to_id, :not_same_project unless issue_from.project_id == issue_to.project_id || Setting.cross_project_issue_relations?
50 errors.add_to_base :circular_dependency if issue_to.all_dependent_issues.include? issue_from
50 #detect circular dependencies depending wether the relation should be reversed
51 if TYPES.has_key?(relation_type) && TYPES[relation_type][:reverse]
52 errors.add_to_base :circular_dependency if issue_from.all_dependent_issues.include? issue_to
53 else
54 errors.add_to_base :circular_dependency if issue_to.all_dependent_issues.include? issue_from
55 end
51 errors.add_to_base :cant_link_an_issue_with_a_descendant if issue_from.is_descendant_of?(issue_to) || issue_from.is_ancestor_of?(issue_to)
56 errors.add_to_base :cant_link_an_issue_with_a_descendant if issue_from.is_descendant_of?(issue_to) || issue_from.is_ancestor_of?(issue_to)
52 end
57 end
53 end
58 end
54
59
55 def other_issue(issue)
60 def other_issue(issue)
56 (self.issue_from_id == issue.id) ? issue_to : issue_from
61 (self.issue_from_id == issue.id) ? issue_to : issue_from
57 end
62 end
58
63
59 # Returns the relation type for +issue+
64 # Returns the relation type for +issue+
60 def relation_type_for(issue)
65 def relation_type_for(issue)
61 if TYPES[relation_type]
66 if TYPES[relation_type]
62 if self.issue_from_id == issue.id
67 if self.issue_from_id == issue.id
63 relation_type
68 relation_type
64 else
69 else
65 TYPES[relation_type][:sym]
70 TYPES[relation_type][:sym]
66 end
71 end
67 end
72 end
68 end
73 end
69
74
70 def label_for(issue)
75 def label_for(issue)
71 TYPES[relation_type] ? TYPES[relation_type][(self.issue_from_id == issue.id) ? :name : :sym_name] : :unknow
76 TYPES[relation_type] ? TYPES[relation_type][(self.issue_from_id == issue.id) ? :name : :sym_name] : :unknow
72 end
77 end
73
78
74 def before_save
79 def before_save
75 reverse_if_needed
80 reverse_if_needed
76
81
77 if TYPE_PRECEDES == relation_type
82 if TYPE_PRECEDES == relation_type
78 self.delay ||= 0
83 self.delay ||= 0
79 else
84 else
80 self.delay = nil
85 self.delay = nil
81 end
86 end
82 set_issue_to_dates
87 set_issue_to_dates
83 end
88 end
84
89
85 def set_issue_to_dates
90 def set_issue_to_dates
86 soonest_start = self.successor_soonest_start
91 soonest_start = self.successor_soonest_start
87 if soonest_start && issue_to
92 if soonest_start && issue_to
88 issue_to.reschedule_after(soonest_start)
93 issue_to.reschedule_after(soonest_start)
89 end
94 end
90 end
95 end
91
96
92 def successor_soonest_start
97 def successor_soonest_start
93 if (TYPE_PRECEDES == self.relation_type) && delay && issue_from && (issue_from.start_date || issue_from.due_date)
98 if (TYPE_PRECEDES == self.relation_type) && delay && issue_from && (issue_from.start_date || issue_from.due_date)
94 (issue_from.due_date || issue_from.start_date) + 1 + delay
99 (issue_from.due_date || issue_from.start_date) + 1 + delay
95 end
100 end
96 end
101 end
97
102
98 def <=>(relation)
103 def <=>(relation)
99 TYPES[self.relation_type][:order] <=> TYPES[relation.relation_type][:order]
104 TYPES[self.relation_type][:order] <=> TYPES[relation.relation_type][:order]
100 end
105 end
101
106
102 private
107 private
103
108
104 # Reverses the relation if needed so that it gets stored in the proper way
109 # Reverses the relation if needed so that it gets stored in the proper way
105 def reverse_if_needed
110 def reverse_if_needed
106 if TYPES.has_key?(relation_type) && TYPES[relation_type][:reverse]
111 if TYPES.has_key?(relation_type) && TYPES[relation_type][:reverse]
107 issue_tmp = issue_to
112 issue_tmp = issue_to
108 self.issue_to = issue_from
113 self.issue_to = issue_from
109 self.issue_from = issue_tmp
114 self.issue_from = issue_tmp
110 self.relation_type = TYPES[relation_type][:reverse]
115 self.relation_type = TYPES[relation_type][:reverse]
111 end
116 end
112 end
117 end
113 end
118 end
@@ -1,100 +1,102
1 require File.expand_path('../../test_helper', __FILE__)
1 require File.expand_path('../../test_helper', __FILE__)
2 require 'issue_relations_controller'
2 require 'issue_relations_controller'
3
3
4 # Re-raise errors caught by the controller.
4 # Re-raise errors caught by the controller.
5 class IssueRelationsController; def rescue_action(e) raise e end; end
5 class IssueRelationsController; def rescue_action(e) raise e end; end
6
6
7
7
8 class IssueRelationsControllerTest < ActionController::TestCase
8 class IssueRelationsControllerTest < ActionController::TestCase
9 fixtures :projects,
9 fixtures :projects,
10 :users,
10 :users,
11 :roles,
11 :roles,
12 :members,
12 :members,
13 :member_roles,
13 :member_roles,
14 :issues,
14 :issues,
15 :issue_statuses,
15 :issue_statuses,
16 :issue_relations,
16 :issue_relations,
17 :enabled_modules,
17 :enabled_modules,
18 :enumerations,
18 :enumerations,
19 :trackers
19 :trackers
20
20
21 def setup
21 def setup
22 @controller = IssueRelationsController.new
22 @controller = IssueRelationsController.new
23 @request = ActionController::TestRequest.new
23 @request = ActionController::TestRequest.new
24 @response = ActionController::TestResponse.new
24 @response = ActionController::TestResponse.new
25 User.current = nil
25 User.current = nil
26 end
26 end
27
27
28 def test_new
28 def test_new
29 assert_difference 'IssueRelation.count' do
29 assert_difference 'IssueRelation.count' do
30 @request.session[:user_id] = 3
30 @request.session[:user_id] = 3
31 post :new, :issue_id => 1,
31 post :new, :issue_id => 1,
32 :relation => {:issue_to_id => '2', :relation_type => 'relates', :delay => ''}
32 :relation => {:issue_to_id => '2', :relation_type => 'relates', :delay => ''}
33 end
33 end
34 end
34 end
35
35
36 def test_new_xhr
36 def test_new_xhr
37 assert_difference 'IssueRelation.count' do
37 assert_difference 'IssueRelation.count' do
38 @request.session[:user_id] = 3
38 @request.session[:user_id] = 3
39 xhr :post, :new,
39 xhr :post, :new,
40 :issue_id => 3,
40 :issue_id => 3,
41 :relation => {:issue_to_id => '1', :relation_type => 'relates', :delay => ''}
41 :relation => {:issue_to_id => '1', :relation_type => 'relates', :delay => ''}
42 assert_select_rjs 'relations' do
42 assert_select_rjs 'relations' do
43 assert_select 'table', 1
43 assert_select 'table', 1
44 assert_select 'tr', 2 # relations
44 assert_select 'tr', 2 # relations
45 end
45 end
46 end
46 end
47 end
47 end
48
48
49 def test_new_should_accept_id_with_hash
49 def test_new_should_accept_id_with_hash
50 assert_difference 'IssueRelation.count' do
50 assert_difference 'IssueRelation.count' do
51 @request.session[:user_id] = 3
51 @request.session[:user_id] = 3
52 post :new, :issue_id => 1,
52 post :new, :issue_id => 1,
53 :relation => {:issue_to_id => '#2', :relation_type => 'relates', :delay => ''}
53 :relation => {:issue_to_id => '#2', :relation_type => 'relates', :delay => ''}
54 end
54 end
55 end
55 end
56
56
57 def test_new_should_not_break_with_non_numerical_id
57 def test_new_should_not_break_with_non_numerical_id
58 assert_no_difference 'IssueRelation.count' do
58 assert_no_difference 'IssueRelation.count' do
59 assert_nothing_raised do
59 assert_nothing_raised do
60 @request.session[:user_id] = 3
60 @request.session[:user_id] = 3
61 post :new, :issue_id => 1,
61 post :new, :issue_id => 1,
62 :relation => {:issue_to_id => 'foo', :relation_type => 'relates', :delay => ''}
62 :relation => {:issue_to_id => 'foo', :relation_type => 'relates', :delay => ''}
63 end
63 end
64 end
64 end
65 end
65 end
66
66
67 def test_should_create_relations_with_visible_issues_only
67 def test_should_create_relations_with_visible_issues_only
68 Setting.cross_project_issue_relations = '1'
68 Setting.cross_project_issue_relations = '1'
69 assert_nil Issue.visible(User.find(3)).find_by_id(4)
69 assert_nil Issue.visible(User.find(3)).find_by_id(4)
70
70
71 assert_no_difference 'IssueRelation.count' do
71 assert_no_difference 'IssueRelation.count' do
72 @request.session[:user_id] = 3
72 @request.session[:user_id] = 3
73 post :new, :issue_id => 1,
73 post :new, :issue_id => 1,
74 :relation => {:issue_to_id => '4', :relation_type => 'relates', :delay => ''}
74 :relation => {:issue_to_id => '4', :relation_type => 'relates', :delay => ''}
75 end
75 end
76 end
76 end
77
78 should "prevent relation creation when there's a circular dependency"
77
79
78 def test_destroy
80 def test_destroy
79 assert_difference 'IssueRelation.count', -1 do
81 assert_difference 'IssueRelation.count', -1 do
80 @request.session[:user_id] = 3
82 @request.session[:user_id] = 3
81 post :destroy, :id => '2', :issue_id => '3'
83 post :destroy, :id => '2', :issue_id => '3'
82 end
84 end
83 end
85 end
84
86
85 def test_destroy_xhr
87 def test_destroy_xhr
86 IssueRelation.create!(:relation_type => IssueRelation::TYPE_RELATES) do |r|
88 IssueRelation.create!(:relation_type => IssueRelation::TYPE_RELATES) do |r|
87 r.issue_from_id = 3
89 r.issue_from_id = 3
88 r.issue_to_id = 1
90 r.issue_to_id = 1
89 end
91 end
90
92
91 assert_difference 'IssueRelation.count', -1 do
93 assert_difference 'IssueRelation.count', -1 do
92 @request.session[:user_id] = 3
94 @request.session[:user_id] = 3
93 xhr :post, :destroy, :id => '2', :issue_id => '3'
95 xhr :post, :destroy, :id => '2', :issue_id => '3'
94 assert_select_rjs 'relations' do
96 assert_select_rjs 'relations' do
95 assert_select 'table', 1
97 assert_select 'table', 1
96 assert_select 'tr', 1 # relation left
98 assert_select 'tr', 1 # relation left
97 end
99 end
98 end
100 end
99 end
101 end
100 end
102 end
@@ -1,85 +1,97
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2009 Jean-Philippe Lang
2 # Copyright (C) 2006-2009 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require File.expand_path('../../test_helper', __FILE__)
18 require File.expand_path('../../test_helper', __FILE__)
19
19
20 class IssueRelationTest < ActiveSupport::TestCase
20 class IssueRelationTest < ActiveSupport::TestCase
21 fixtures :issue_relations, :issues
21 fixtures :issue_relations, :issues
22
22
23 def test_create
23 def test_create
24 from = Issue.find(1)
24 from = Issue.find(1)
25 to = Issue.find(2)
25 to = Issue.find(2)
26
26
27 relation = IssueRelation.new :issue_from => from, :issue_to => to, :relation_type => IssueRelation::TYPE_PRECEDES
27 relation = IssueRelation.new :issue_from => from, :issue_to => to, :relation_type => IssueRelation::TYPE_PRECEDES
28 assert relation.save
28 assert relation.save
29 relation.reload
29 relation.reload
30 assert_equal IssueRelation::TYPE_PRECEDES, relation.relation_type
30 assert_equal IssueRelation::TYPE_PRECEDES, relation.relation_type
31 assert_equal from, relation.issue_from
31 assert_equal from, relation.issue_from
32 assert_equal to, relation.issue_to
32 assert_equal to, relation.issue_to
33 end
33 end
34
34
35 def test_follows_relation_should_be_reversed
35 def test_follows_relation_should_be_reversed
36 from = Issue.find(1)
36 from = Issue.find(1)
37 to = Issue.find(2)
37 to = Issue.find(2)
38
38
39 relation = IssueRelation.new :issue_from => from, :issue_to => to, :relation_type => IssueRelation::TYPE_FOLLOWS
39 relation = IssueRelation.new :issue_from => from, :issue_to => to, :relation_type => IssueRelation::TYPE_FOLLOWS
40 assert relation.save
40 assert relation.save
41 relation.reload
41 relation.reload
42 assert_equal IssueRelation::TYPE_PRECEDES, relation.relation_type
42 assert_equal IssueRelation::TYPE_PRECEDES, relation.relation_type
43 assert_equal to, relation.issue_from
43 assert_equal to, relation.issue_from
44 assert_equal from, relation.issue_to
44 assert_equal from, relation.issue_to
45 end
45 end
46
46
47 # TODO : document why it shouldn't be reversed if validation fails : having
48 # relations reversed before the validation would allow simpler code for the
49 # validation
47 def test_follows_relation_should_not_be_reversed_if_validation_fails
50 def test_follows_relation_should_not_be_reversed_if_validation_fails
48 from = Issue.find(1)
51 from = Issue.find(1)
49 to = Issue.find(2)
52 to = Issue.find(2)
50
53
51 relation = IssueRelation.new :issue_from => from, :issue_to => to, :relation_type => IssueRelation::TYPE_FOLLOWS, :delay => 'xx'
54 relation = IssueRelation.new :issue_from => from, :issue_to => to, :relation_type => IssueRelation::TYPE_FOLLOWS, :delay => 'xx'
52 assert !relation.save
55 assert !relation.save
53 assert_equal IssueRelation::TYPE_FOLLOWS, relation.relation_type
56 assert_equal IssueRelation::TYPE_FOLLOWS, relation.relation_type
54 assert_equal from, relation.issue_from
57 assert_equal from, relation.issue_from
55 assert_equal to, relation.issue_to
58 assert_equal to, relation.issue_to
56 end
59 end
57
60
58 def test_relation_type_for
61 def test_relation_type_for
59 from = Issue.find(1)
62 from = Issue.find(1)
60 to = Issue.find(2)
63 to = Issue.find(2)
61
64
62 relation = IssueRelation.new :issue_from => from, :issue_to => to, :relation_type => IssueRelation::TYPE_PRECEDES
65 relation = IssueRelation.new :issue_from => from, :issue_to => to, :relation_type => IssueRelation::TYPE_PRECEDES
63 assert_equal IssueRelation::TYPE_PRECEDES, relation.relation_type_for(from)
66 assert_equal IssueRelation::TYPE_PRECEDES, relation.relation_type_for(from)
64 assert_equal IssueRelation::TYPE_FOLLOWS, relation.relation_type_for(to)
67 assert_equal IssueRelation::TYPE_FOLLOWS, relation.relation_type_for(to)
65 end
68 end
66
69
67 def test_set_issue_to_dates_without_issue_to
70 def test_set_issue_to_dates_without_issue_to
68 r = IssueRelation.new(:issue_from => Issue.new(:start_date => Date.today), :relation_type => IssueRelation::TYPE_PRECEDES, :delay => 1)
71 r = IssueRelation.new(:issue_from => Issue.new(:start_date => Date.today), :relation_type => IssueRelation::TYPE_PRECEDES, :delay => 1)
69 assert_nil r.set_issue_to_dates
72 assert_nil r.set_issue_to_dates
70 end
73 end
71
74
72 def test_set_issue_to_dates_without_issues
75 def test_set_issue_to_dates_without_issues
73 r = IssueRelation.new(:relation_type => IssueRelation::TYPE_PRECEDES, :delay => 1)
76 r = IssueRelation.new(:relation_type => IssueRelation::TYPE_PRECEDES, :delay => 1)
74 assert_nil r.set_issue_to_dates
77 assert_nil r.set_issue_to_dates
75 end
78 end
76
79
77 def test_validates_circular_dependency
80 def test_validates_circular_dependency
78 IssueRelation.delete_all
81 IssueRelation.delete_all
79 assert IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => IssueRelation::TYPE_PRECEDES)
82 assert IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => IssueRelation::TYPE_PRECEDES)
80 assert IssueRelation.create!(:issue_from => Issue.find(2), :issue_to => Issue.find(3), :relation_type => IssueRelation::TYPE_PRECEDES)
83 assert IssueRelation.create!(:issue_from => Issue.find(2), :issue_to => Issue.find(3), :relation_type => IssueRelation::TYPE_PRECEDES)
81 r = IssueRelation.new(:issue_from => Issue.find(3), :issue_to => Issue.find(1), :relation_type => IssueRelation::TYPE_PRECEDES)
84 r = IssueRelation.new(:issue_from => Issue.find(3), :issue_to => Issue.find(1), :relation_type => IssueRelation::TYPE_PRECEDES)
82 assert !r.save
85 assert !r.save
83 assert_not_nil r.errors.on(:base)
86 assert_not_nil r.errors.on(:base)
84 end
87 end
88
89 def test_validates_circular_dependency_on_reverse_relations
90 IssueRelation.delete_all
91 assert IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(3), :relation_type => IssueRelation::TYPE_BLOCKS)
92 assert IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => IssueRelation::TYPE_BLOCKED)
93 r = IssueRelation.new(:issue_from => Issue.find(2), :issue_to => Issue.find(1), :relation_type => IssueRelation::TYPE_BLOCKED)
94 assert !r.save
95 assert_not_nil r.errors.on(:base)
96 end
85 end
97 end
General Comments 0
You need to be logged in to leave comments. Login now