Mercurial > hg > soundsoftware-site
comparison .svn/pristine/ac/ac29d85a760bdd05295d465c5da481729f76a3a3.svn-base @ 1494:e248c7af89ec redmine-2.4
Update to Redmine SVN revision 12979 on 2.4-stable branch
author | Chris Cannam |
---|---|
date | Mon, 17 Mar 2014 08:54:02 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1464:261b3d9a4903 | 1494:e248c7af89ec |
---|---|
1 # Redmine - project management software | |
2 # Copyright (C) 2006-2014 Jean-Philippe Lang | |
3 # | |
4 # This program is free software; you can redistribute it and/or | |
5 # modify it under the terms of the GNU General Public License | |
6 # as published by the Free Software Foundation; either version 2 | |
7 # of the License, or (at your option) any later version. | |
8 # | |
9 # This program is distributed in the hope that it will be useful, | |
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 # GNU General Public License for more details. | |
13 # | |
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 | |
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 | |
18 require File.expand_path('../../test_helper', __FILE__) | |
19 | |
20 class IssueRelationTest < ActiveSupport::TestCase | |
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, | |
32 :projects_trackers | |
33 | |
34 include Redmine::I18n | |
35 | |
36 def test_create | |
37 from = Issue.find(1) | |
38 to = Issue.find(2) | |
39 | |
40 relation = IssueRelation.new :issue_from => from, :issue_to => to, | |
41 :relation_type => IssueRelation::TYPE_PRECEDES | |
42 assert relation.save | |
43 relation.reload | |
44 assert_equal IssueRelation::TYPE_PRECEDES, relation.relation_type | |
45 assert_equal from, relation.issue_from | |
46 assert_equal to, relation.issue_to | |
47 end | |
48 | |
49 def test_create_minimum | |
50 relation = IssueRelation.new :issue_from => Issue.find(1), :issue_to => Issue.find(2) | |
51 assert relation.save | |
52 assert_equal IssueRelation::TYPE_RELATES, relation.relation_type | |
53 end | |
54 | |
55 def test_follows_relation_should_be_reversed | |
56 from = Issue.find(1) | |
57 to = Issue.find(2) | |
58 | |
59 relation = IssueRelation.new :issue_from => from, :issue_to => to, | |
60 :relation_type => IssueRelation::TYPE_FOLLOWS | |
61 assert relation.save | |
62 relation.reload | |
63 assert_equal IssueRelation::TYPE_PRECEDES, relation.relation_type | |
64 assert_equal to, relation.issue_from | |
65 assert_equal from, relation.issue_to | |
66 end | |
67 | |
68 def test_follows_relation_should_not_be_reversed_if_validation_fails | |
69 from = Issue.find(1) | |
70 to = Issue.find(2) | |
71 | |
72 relation = IssueRelation.new :issue_from => from, :issue_to => to, | |
73 :relation_type => IssueRelation::TYPE_FOLLOWS, | |
74 :delay => 'xx' | |
75 assert !relation.save | |
76 assert_equal IssueRelation::TYPE_FOLLOWS, relation.relation_type | |
77 assert_equal from, relation.issue_from | |
78 assert_equal to, relation.issue_to | |
79 end | |
80 | |
81 def test_relation_type_for | |
82 from = Issue.find(1) | |
83 to = Issue.find(2) | |
84 | |
85 relation = IssueRelation.new :issue_from => from, :issue_to => to, | |
86 :relation_type => IssueRelation::TYPE_PRECEDES | |
87 assert_equal IssueRelation::TYPE_PRECEDES, relation.relation_type_for(from) | |
88 assert_equal IssueRelation::TYPE_FOLLOWS, relation.relation_type_for(to) | |
89 end | |
90 | |
91 def test_set_issue_to_dates_without_issue_to | |
92 r = IssueRelation.new(:issue_from => Issue.new(:start_date => Date.today), | |
93 :relation_type => IssueRelation::TYPE_PRECEDES, | |
94 :delay => 1) | |
95 assert_nil r.set_issue_to_dates | |
96 end | |
97 | |
98 def test_set_issue_to_dates_without_issues | |
99 r = IssueRelation.new(:relation_type => IssueRelation::TYPE_PRECEDES, :delay => 1) | |
100 assert_nil r.set_issue_to_dates | |
101 end | |
102 | |
103 def test_validates_circular_dependency | |
104 IssueRelation.delete_all | |
105 assert IssueRelation.create!( | |
106 :issue_from => Issue.find(1), :issue_to => Issue.find(2), | |
107 :relation_type => IssueRelation::TYPE_PRECEDES | |
108 ) | |
109 assert IssueRelation.create!( | |
110 :issue_from => Issue.find(2), :issue_to => Issue.find(3), | |
111 :relation_type => IssueRelation::TYPE_PRECEDES | |
112 ) | |
113 r = IssueRelation.new( | |
114 :issue_from => Issue.find(3), :issue_to => Issue.find(1), | |
115 :relation_type => IssueRelation::TYPE_PRECEDES | |
116 ) | |
117 assert !r.save | |
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 | |
152 end | |
153 | |
154 def test_validates_circular_dependency_on_reverse_relations | |
155 IssueRelation.delete_all | |
156 assert IssueRelation.create!( | |
157 :issue_from => Issue.find(1), :issue_to => Issue.find(3), | |
158 :relation_type => IssueRelation::TYPE_BLOCKS | |
159 ) | |
160 assert IssueRelation.create!( | |
161 :issue_from => Issue.find(1), :issue_to => Issue.find(2), | |
162 :relation_type => IssueRelation::TYPE_BLOCKED | |
163 ) | |
164 r = IssueRelation.new( | |
165 :issue_from => Issue.find(2), :issue_to => Issue.find(1), | |
166 :relation_type => IssueRelation::TYPE_BLOCKED | |
167 ) | |
168 assert !r.save | |
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 | |
215 end | |
216 end |