##// END OF EJS Templates
add missing fixture to test/unit/issue_relation_test.rb...
Toshi MARUYAMA -
r11839:c20b1d64a72f
parent child
Show More
@@ -1,215 +1,216
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2013 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 21 fixtures :projects,
22 22 :users,
23 23 :roles,
24 24 :members,
25 25 :member_roles,
26 26 :issues,
27 27 :issue_statuses,
28 28 :issue_relations,
29 29 :enabled_modules,
30 30 :enumerations,
31 :trackers
31 :trackers,
32 :projects_trackers
32 33
33 34 include Redmine::I18n
34 35
35 36 def test_create
36 37 from = Issue.find(1)
37 38 to = Issue.find(2)
38 39
39 40 relation = IssueRelation.new :issue_from => from, :issue_to => to,
40 41 :relation_type => IssueRelation::TYPE_PRECEDES
41 42 assert relation.save
42 43 relation.reload
43 44 assert_equal IssueRelation::TYPE_PRECEDES, relation.relation_type
44 45 assert_equal from, relation.issue_from
45 46 assert_equal to, relation.issue_to
46 47 end
47 48
48 49 def test_create_minimum
49 50 relation = IssueRelation.new :issue_from => Issue.find(1), :issue_to => Issue.find(2)
50 51 assert relation.save
51 52 assert_equal IssueRelation::TYPE_RELATES, relation.relation_type
52 53 end
53 54
54 55 def test_follows_relation_should_be_reversed
55 56 from = Issue.find(1)
56 57 to = Issue.find(2)
57 58
58 59 relation = IssueRelation.new :issue_from => from, :issue_to => to,
59 60 :relation_type => IssueRelation::TYPE_FOLLOWS
60 61 assert relation.save
61 62 relation.reload
62 63 assert_equal IssueRelation::TYPE_PRECEDES, relation.relation_type
63 64 assert_equal to, relation.issue_from
64 65 assert_equal from, relation.issue_to
65 66 end
66 67
67 68 def test_follows_relation_should_not_be_reversed_if_validation_fails
68 69 from = Issue.find(1)
69 70 to = Issue.find(2)
70 71
71 72 relation = IssueRelation.new :issue_from => from, :issue_to => to,
72 73 :relation_type => IssueRelation::TYPE_FOLLOWS,
73 74 :delay => 'xx'
74 75 assert !relation.save
75 76 assert_equal IssueRelation::TYPE_FOLLOWS, relation.relation_type
76 77 assert_equal from, relation.issue_from
77 78 assert_equal to, relation.issue_to
78 79 end
79 80
80 81 def test_relation_type_for
81 82 from = Issue.find(1)
82 83 to = Issue.find(2)
83 84
84 85 relation = IssueRelation.new :issue_from => from, :issue_to => to,
85 86 :relation_type => IssueRelation::TYPE_PRECEDES
86 87 assert_equal IssueRelation::TYPE_PRECEDES, relation.relation_type_for(from)
87 88 assert_equal IssueRelation::TYPE_FOLLOWS, relation.relation_type_for(to)
88 89 end
89 90
90 91 def test_set_issue_to_dates_without_issue_to
91 92 r = IssueRelation.new(:issue_from => Issue.new(:start_date => Date.today),
92 93 :relation_type => IssueRelation::TYPE_PRECEDES,
93 94 :delay => 1)
94 95 assert_nil r.set_issue_to_dates
95 96 end
96 97
97 98 def test_set_issue_to_dates_without_issues
98 99 r = IssueRelation.new(:relation_type => IssueRelation::TYPE_PRECEDES, :delay => 1)
99 100 assert_nil r.set_issue_to_dates
100 101 end
101 102
102 103 def test_validates_circular_dependency
103 104 IssueRelation.delete_all
104 105 assert IssueRelation.create!(
105 106 :issue_from => Issue.find(1), :issue_to => Issue.find(2),
106 107 :relation_type => IssueRelation::TYPE_PRECEDES
107 108 )
108 109 assert IssueRelation.create!(
109 110 :issue_from => Issue.find(2), :issue_to => Issue.find(3),
110 111 :relation_type => IssueRelation::TYPE_PRECEDES
111 112 )
112 113 r = IssueRelation.new(
113 114 :issue_from => Issue.find(3), :issue_to => Issue.find(1),
114 115 :relation_type => IssueRelation::TYPE_PRECEDES
115 116 )
116 117 assert !r.save
117 118 assert_not_nil r.errors[:base]
118 119 end
119 120
120 121 def test_validates_circular_dependency_of_subtask
121 122 set_language_if_valid 'en'
122 123 issue1 = Issue.generate!
123 124 issue2 = Issue.generate!
124 125 IssueRelation.create!(
125 126 :issue_from => issue1, :issue_to => issue2,
126 127 :relation_type => IssueRelation::TYPE_PRECEDES
127 128 )
128 129 child = Issue.generate!(:parent_issue_id => issue2.id)
129 130 issue1.reload
130 131 child.reload
131 132
132 133 r = IssueRelation.new(
133 134 :issue_from => child, :issue_to => issue1,
134 135 :relation_type => IssueRelation::TYPE_PRECEDES
135 136 )
136 137 assert !r.save
137 138 assert_include 'This relation would create a circular dependency', r.errors.full_messages
138 139 end
139 140
140 141 def test_subtasks_should_allow_precedes_relation
141 142 parent = Issue.generate!
142 143 child1 = Issue.generate!(:parent_issue_id => parent.id)
143 144 child2 = Issue.generate!(:parent_issue_id => parent.id)
144 145
145 146 r = IssueRelation.new(
146 147 :issue_from => child1, :issue_to => child2,
147 148 :relation_type => IssueRelation::TYPE_PRECEDES
148 149 )
149 150 assert r.valid?
150 151 assert r.save
151 152 end
152 153
153 154 def test_validates_circular_dependency_on_reverse_relations
154 155 IssueRelation.delete_all
155 156 assert IssueRelation.create!(
156 157 :issue_from => Issue.find(1), :issue_to => Issue.find(3),
157 158 :relation_type => IssueRelation::TYPE_BLOCKS
158 159 )
159 160 assert IssueRelation.create!(
160 161 :issue_from => Issue.find(1), :issue_to => Issue.find(2),
161 162 :relation_type => IssueRelation::TYPE_BLOCKED
162 163 )
163 164 r = IssueRelation.new(
164 165 :issue_from => Issue.find(2), :issue_to => Issue.find(1),
165 166 :relation_type => IssueRelation::TYPE_BLOCKED
166 167 )
167 168 assert !r.save
168 169 assert_not_nil r.errors[:base]
169 170 end
170 171
171 172 def test_create_should_make_journal_entry
172 173 from = Issue.find(1)
173 174 to = Issue.find(2)
174 175 from_journals = from.journals.size
175 176 to_journals = to.journals.size
176 177 relation = IssueRelation.new(:issue_from => from, :issue_to => to,
177 178 :relation_type => IssueRelation::TYPE_PRECEDES)
178 179 assert relation.save
179 180 from.reload
180 181 to.reload
181 182 relation.reload
182 183 assert_equal from.journals.size, (from_journals + 1)
183 184 assert_equal to.journals.size, (to_journals + 1)
184 185 assert_equal 'relation', from.journals.last.details.last.property
185 186 assert_equal 'label_precedes', from.journals.last.details.last.prop_key
186 187 assert_equal '2', from.journals.last.details.last.value
187 188 assert_nil from.journals.last.details.last.old_value
188 189 assert_equal 'relation', to.journals.last.details.last.property
189 190 assert_equal 'label_follows', to.journals.last.details.last.prop_key
190 191 assert_equal '1', to.journals.last.details.last.value
191 192 assert_nil to.journals.last.details.last.old_value
192 193 end
193 194
194 195 def test_delete_should_make_journal_entry
195 196 relation = IssueRelation.find(1)
196 197 id = relation.id
197 198 from = relation.issue_from
198 199 to = relation.issue_to
199 200 from_journals = from.journals.size
200 201 to_journals = to.journals.size
201 202 assert relation.destroy
202 203 from.reload
203 204 to.reload
204 205 assert_equal from.journals.size, (from_journals + 1)
205 206 assert_equal to.journals.size, (to_journals + 1)
206 207 assert_equal 'relation', from.journals.last.details.last.property
207 208 assert_equal 'label_blocks', from.journals.last.details.last.prop_key
208 209 assert_equal '9', from.journals.last.details.last.old_value
209 210 assert_nil from.journals.last.details.last.value
210 211 assert_equal 'relation', to.journals.last.details.last.property
211 212 assert_equal 'label_blocked_by', to.journals.last.details.last.prop_key
212 213 assert_equal '10', to.journals.last.details.last.old_value
213 214 assert_nil to.journals.last.details.last.value
214 215 end
215 216 end
General Comments 0
You need to be logged in to leave comments. Login now