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