##// END OF EJS Templates
Adds a test for issue circular dependency validation....
Jean-Philippe Lang -
r4601:d2b6a6bc2cd4
parent child
Show More
@@ -1,76 +1,85
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 def test_follows_relation_should_not_be_reversed_if_validation_fails
47 def test_follows_relation_should_not_be_reversed_if_validation_fails
48 from = Issue.find(1)
48 from = Issue.find(1)
49 to = Issue.find(2)
49 to = Issue.find(2)
50
50
51 relation = IssueRelation.new :issue_from => from, :issue_to => to, :relation_type => IssueRelation::TYPE_FOLLOWS, :delay => 'xx'
51 relation = IssueRelation.new :issue_from => from, :issue_to => to, :relation_type => IssueRelation::TYPE_FOLLOWS, :delay => 'xx'
52 assert !relation.save
52 assert !relation.save
53 assert_equal IssueRelation::TYPE_FOLLOWS, relation.relation_type
53 assert_equal IssueRelation::TYPE_FOLLOWS, relation.relation_type
54 assert_equal from, relation.issue_from
54 assert_equal from, relation.issue_from
55 assert_equal to, relation.issue_to
55 assert_equal to, relation.issue_to
56 end
56 end
57
57
58 def test_relation_type_for
58 def test_relation_type_for
59 from = Issue.find(1)
59 from = Issue.find(1)
60 to = Issue.find(2)
60 to = Issue.find(2)
61
61
62 relation = IssueRelation.new :issue_from => from, :issue_to => to, :relation_type => IssueRelation::TYPE_PRECEDES
62 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)
63 assert_equal IssueRelation::TYPE_PRECEDES, relation.relation_type_for(from)
64 assert_equal IssueRelation::TYPE_FOLLOWS, relation.relation_type_for(to)
64 assert_equal IssueRelation::TYPE_FOLLOWS, relation.relation_type_for(to)
65 end
65 end
66
66
67 def test_set_issue_to_dates_without_issue_to
67 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)
68 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
69 assert_nil r.set_issue_to_dates
70 end
70 end
71
71
72 def test_set_issue_to_dates_without_issues
72 def test_set_issue_to_dates_without_issues
73 r = IssueRelation.new(:relation_type => IssueRelation::TYPE_PRECEDES, :delay => 1)
73 r = IssueRelation.new(:relation_type => IssueRelation::TYPE_PRECEDES, :delay => 1)
74 assert_nil r.set_issue_to_dates
74 assert_nil r.set_issue_to_dates
75 end
75 end
76
77 def test_validates_circular_dependency
78 IssueRelation.delete_all
79 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)
81 r = IssueRelation.new(:issue_from => Issue.find(3), :issue_to => Issue.find(1), :relation_type => IssueRelation::TYPE_PRECEDES)
82 assert !r.save
83 assert_not_nil r.errors.on(:base)
84 end
76 end
85 end
General Comments 0
You need to be logged in to leave comments. Login now