Mercurial > hg > soundsoftware-site
comparison test/unit/issue_relation_test.rb @ 1464:261b3d9a4903 redmine-2.4
Update to Redmine 2.4 branch rev 12663
author | Chris Cannam |
---|---|
date | Tue, 14 Jan 2014 14:37:42 +0000 |
parents | 433d4f72a19b |
children | e248c7af89ec |
comparison
equal
deleted
inserted
replaced
1296:038ba2d95de8 | 1464:261b3d9a4903 |
---|---|
1 # Redmine - project management software | 1 # Redmine - project management software |
2 # Copyright (C) 2006-2012 Jean-Philippe Lang | 2 # Copyright (C) 2006-2013 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. |
26 :issues, | 26 :issues, |
27 :issue_statuses, | 27 :issue_statuses, |
28 :issue_relations, | 28 :issue_relations, |
29 :enabled_modules, | 29 :enabled_modules, |
30 :enumerations, | 30 :enumerations, |
31 :trackers | 31 :trackers, |
32 :projects_trackers | |
33 | |
34 include Redmine::I18n | |
32 | 35 |
33 def test_create | 36 def test_create |
34 from = Issue.find(1) | 37 from = Issue.find(1) |
35 to = Issue.find(2) | 38 to = Issue.find(2) |
36 | 39 |
110 r = IssueRelation.new( | 113 r = IssueRelation.new( |
111 :issue_from => Issue.find(3), :issue_to => Issue.find(1), | 114 :issue_from => Issue.find(3), :issue_to => Issue.find(1), |
112 :relation_type => IssueRelation::TYPE_PRECEDES | 115 :relation_type => IssueRelation::TYPE_PRECEDES |
113 ) | 116 ) |
114 assert !r.save | 117 assert !r.save |
115 assert_not_nil r.errors[:base] | 118 assert_not_equal [], r.errors[:base] |
119 end | |
120 | |
121 def test_validates_circular_dependency_of_subtask | |
122 set_language_if_valid 'en' | |
123 issue1 = Issue.generate! | |
124 issue2 = Issue.generate! | |
125 IssueRelation.create!( | |
126 :issue_from => issue1, :issue_to => issue2, | |
127 :relation_type => IssueRelation::TYPE_PRECEDES | |
128 ) | |
129 child = Issue.generate!(:parent_issue_id => issue2.id) | |
130 issue1.reload | |
131 child.reload | |
132 | |
133 r = IssueRelation.new( | |
134 :issue_from => child, :issue_to => issue1, | |
135 :relation_type => IssueRelation::TYPE_PRECEDES | |
136 ) | |
137 assert !r.save | |
138 assert_include 'This relation would create a circular dependency', r.errors.full_messages | |
139 end | |
140 | |
141 def test_subtasks_should_allow_precedes_relation | |
142 parent = Issue.generate! | |
143 child1 = Issue.generate!(:parent_issue_id => parent.id) | |
144 child2 = Issue.generate!(:parent_issue_id => parent.id) | |
145 | |
146 r = IssueRelation.new( | |
147 :issue_from => child1, :issue_to => child2, | |
148 :relation_type => IssueRelation::TYPE_PRECEDES | |
149 ) | |
150 assert r.valid? | |
151 assert r.save | |
116 end | 152 end |
117 | 153 |
118 def test_validates_circular_dependency_on_reverse_relations | 154 def test_validates_circular_dependency_on_reverse_relations |
119 IssueRelation.delete_all | 155 IssueRelation.delete_all |
120 assert IssueRelation.create!( | 156 assert IssueRelation.create!( |
128 r = IssueRelation.new( | 164 r = IssueRelation.new( |
129 :issue_from => Issue.find(2), :issue_to => Issue.find(1), | 165 :issue_from => Issue.find(2), :issue_to => Issue.find(1), |
130 :relation_type => IssueRelation::TYPE_BLOCKED | 166 :relation_type => IssueRelation::TYPE_BLOCKED |
131 ) | 167 ) |
132 assert !r.save | 168 assert !r.save |
133 assert_not_nil r.errors[:base] | 169 assert_not_equal [], r.errors[:base] |
170 end | |
171 | |
172 def test_create_should_make_journal_entry | |
173 from = Issue.find(1) | |
174 to = Issue.find(2) | |
175 from_journals = from.journals.size | |
176 to_journals = to.journals.size | |
177 relation = IssueRelation.new(:issue_from => from, :issue_to => to, | |
178 :relation_type => IssueRelation::TYPE_PRECEDES) | |
179 assert relation.save | |
180 from.reload | |
181 to.reload | |
182 relation.reload | |
183 assert_equal from.journals.size, (from_journals + 1) | |
184 assert_equal to.journals.size, (to_journals + 1) | |
185 assert_equal 'relation', from.journals.last.details.last.property | |
186 assert_equal 'label_precedes', from.journals.last.details.last.prop_key | |
187 assert_equal '2', from.journals.last.details.last.value | |
188 assert_nil from.journals.last.details.last.old_value | |
189 assert_equal 'relation', to.journals.last.details.last.property | |
190 assert_equal 'label_follows', to.journals.last.details.last.prop_key | |
191 assert_equal '1', to.journals.last.details.last.value | |
192 assert_nil to.journals.last.details.last.old_value | |
193 end | |
194 | |
195 def test_delete_should_make_journal_entry | |
196 relation = IssueRelation.find(1) | |
197 id = relation.id | |
198 from = relation.issue_from | |
199 to = relation.issue_to | |
200 from_journals = from.journals.size | |
201 to_journals = to.journals.size | |
202 assert relation.destroy | |
203 from.reload | |
204 to.reload | |
205 assert_equal from.journals.size, (from_journals + 1) | |
206 assert_equal to.journals.size, (to_journals + 1) | |
207 assert_equal 'relation', from.journals.last.details.last.property | |
208 assert_equal 'label_blocks', from.journals.last.details.last.prop_key | |
209 assert_equal '9', from.journals.last.details.last.old_value | |
210 assert_nil from.journals.last.details.last.value | |
211 assert_equal 'relation', to.journals.last.details.last.property | |
212 assert_equal 'label_blocked_by', to.journals.last.details.last.prop_key | |
213 assert_equal '10', to.journals.last.details.last.old_value | |
214 assert_nil to.journals.last.details.last.value | |
134 end | 215 end |
135 end | 216 end |