##// END OF EJS Templates
Merged r10572 from trunk...
Toshi MARUYAMA -
r10366:3b4126e14f26
parent child
Show More
@@ -1,107 +1,117
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.expand_path('../../test_helper', __FILE__)
19 19
20 20 class IssueRelationTest < ActiveSupport::TestCase
21 fixtures :issue_relations, :issues
21 fixtures :projects,
22 :users,
23 :roles,
24 :members,
25 :member_roles,
26 :issues,
27 :issue_statuses,
28 :issue_relations,
29 :enabled_modules,
30 :enumerations,
31 :trackers
22 32
23 33 def test_create
24 34 from = Issue.find(1)
25 35 to = Issue.find(2)
26 36
27 37 relation = IssueRelation.new :issue_from => from, :issue_to => to,
28 38 :relation_type => IssueRelation::TYPE_PRECEDES
29 39 assert relation.save
30 40 relation.reload
31 41 assert_equal IssueRelation::TYPE_PRECEDES, relation.relation_type
32 42 assert_equal from, relation.issue_from
33 43 assert_equal to, relation.issue_to
34 44 end
35 45
36 46 def test_create_minimum
37 47 relation = IssueRelation.new :issue_from => Issue.find(1), :issue_to => Issue.find(2)
38 48 assert relation.save
39 49 assert_equal IssueRelation::TYPE_RELATES, relation.relation_type
40 50 end
41 51
42 52 def test_follows_relation_should_be_reversed
43 53 from = Issue.find(1)
44 54 to = Issue.find(2)
45 55
46 56 relation = IssueRelation.new :issue_from => from, :issue_to => to,
47 57 :relation_type => IssueRelation::TYPE_FOLLOWS
48 58 assert relation.save
49 59 relation.reload
50 60 assert_equal IssueRelation::TYPE_PRECEDES, relation.relation_type
51 61 assert_equal to, relation.issue_from
52 62 assert_equal from, relation.issue_to
53 63 end
54 64
55 65 def test_follows_relation_should_not_be_reversed_if_validation_fails
56 66 from = Issue.find(1)
57 67 to = Issue.find(2)
58 68
59 69 relation = IssueRelation.new :issue_from => from, :issue_to => to,
60 70 :relation_type => IssueRelation::TYPE_FOLLOWS,
61 71 :delay => 'xx'
62 72 assert !relation.save
63 73 assert_equal IssueRelation::TYPE_FOLLOWS, relation.relation_type
64 74 assert_equal from, relation.issue_from
65 75 assert_equal to, relation.issue_to
66 76 end
67 77
68 78 def test_relation_type_for
69 79 from = Issue.find(1)
70 80 to = Issue.find(2)
71 81
72 82 relation = IssueRelation.new :issue_from => from, :issue_to => to,
73 83 :relation_type => IssueRelation::TYPE_PRECEDES
74 84 assert_equal IssueRelation::TYPE_PRECEDES, relation.relation_type_for(from)
75 85 assert_equal IssueRelation::TYPE_FOLLOWS, relation.relation_type_for(to)
76 86 end
77 87
78 88 def test_set_issue_to_dates_without_issue_to
79 89 r = IssueRelation.new(:issue_from => Issue.new(:start_date => Date.today),
80 90 :relation_type => IssueRelation::TYPE_PRECEDES,
81 91 :delay => 1)
82 92 assert_nil r.set_issue_to_dates
83 93 end
84 94
85 95 def test_set_issue_to_dates_without_issues
86 96 r = IssueRelation.new(:relation_type => IssueRelation::TYPE_PRECEDES, :delay => 1)
87 97 assert_nil r.set_issue_to_dates
88 98 end
89 99
90 100 def test_validates_circular_dependency
91 101 IssueRelation.delete_all
92 102 assert IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => IssueRelation::TYPE_PRECEDES)
93 103 assert IssueRelation.create!(:issue_from => Issue.find(2), :issue_to => Issue.find(3), :relation_type => IssueRelation::TYPE_PRECEDES)
94 104 r = IssueRelation.new(:issue_from => Issue.find(3), :issue_to => Issue.find(1), :relation_type => IssueRelation::TYPE_PRECEDES)
95 105 assert !r.save
96 106 assert_not_nil r.errors[:base]
97 107 end
98 108
99 109 def test_validates_circular_dependency_on_reverse_relations
100 110 IssueRelation.delete_all
101 111 assert IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(3), :relation_type => IssueRelation::TYPE_BLOCKS)
102 112 assert IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => IssueRelation::TYPE_BLOCKED)
103 113 r = IssueRelation.new(:issue_from => Issue.find(2), :issue_to => Issue.find(1), :relation_type => IssueRelation::TYPE_BLOCKED)
104 114 assert !r.save
105 115 assert_not_nil r.errors[:base]
106 116 end
107 117 end
General Comments 0
You need to be logged in to leave comments. Login now