@@ -1105,6 +1105,10 class Issue < ActiveRecord::Base | |||
|
1105 | 1105 | s = arg.to_s.strip.presence |
|
1106 | 1106 | if s && (m = s.match(%r{\A#?(\d+)\z})) && (@parent_issue = Issue.find_by_id(m[1])) |
|
1107 | 1107 | @parent_issue.id |
|
1108 | @invalid_parent_issue_id = nil | |
|
1109 | elsif s.blank? | |
|
1110 | @parent_issue = nil | |
|
1111 | @invalid_parent_issue_id = nil | |
|
1108 | 1112 | else |
|
1109 | 1113 | @parent_issue = nil |
|
1110 | 1114 | @invalid_parent_issue_id = arg |
@@ -1280,6 +1284,13 class Issue < ActiveRecord::Base | |||
|
1280 | 1284 | move_to_child_of(@parent_issue) |
|
1281 | 1285 | end |
|
1282 | 1286 | elsif parent_issue_id != parent_id |
|
1287 | update_nested_set_attributes_on_parent_change | |
|
1288 | end | |
|
1289 | remove_instance_variable(:@parent_issue) if instance_variable_defined?(:@parent_issue) | |
|
1290 | end | |
|
1291 | ||
|
1292 | # Updates the nested set for when an existing issue is moved | |
|
1293 | def update_nested_set_attributes_on_parent_change | |
|
1283 | 1294 |
|
|
1284 | 1295 |
|
|
1285 | 1296 |
|
@@ -1311,8 +1322,6 class Issue < ActiveRecord::Base | |||
|
1311 | 1322 |
|
|
1312 | 1323 |
|
|
1313 | 1324 |
|
|
1314 | remove_instance_variable(:@parent_issue) if instance_variable_defined?(:@parent_issue) | |
|
1315 | end | |
|
1316 | 1325 | |
|
1317 | 1326 | def update_parent_attributes |
|
1318 | 1327 | recalculate_attributes_for(parent_id) if parent_id |
@@ -166,6 +166,41 class IssueNestedSetTest < ActiveSupport::TestCase | |||
|
166 | 166 | assert_not_equal [], child.errors[:parent_issue_id] |
|
167 | 167 | end |
|
168 | 168 | |
|
169 | def test_updating_a_root_issue_should_not_trigger_update_nested_set_attributes_on_parent_change | |
|
170 | issue = Issue.find(Issue.generate!.id) | |
|
171 | issue.parent_issue_id = "" | |
|
172 | issue.expects(:update_nested_set_attributes_on_parent_change).never | |
|
173 | issue.save! | |
|
174 | end | |
|
175 | ||
|
176 | def test_updating_a_child_issue_should_not_trigger_update_nested_set_attributes_on_parent_change | |
|
177 | issue = Issue.find(Issue.generate!(:parent_issue_id => 1).id) | |
|
178 | issue.parent_issue_id = "1" | |
|
179 | issue.expects(:update_nested_set_attributes_on_parent_change).never | |
|
180 | issue.save! | |
|
181 | end | |
|
182 | ||
|
183 | def test_moving_a_root_issue_should_trigger_update_nested_set_attributes_on_parent_change | |
|
184 | issue = Issue.find(Issue.generate!.id) | |
|
185 | issue.parent_issue_id = "1" | |
|
186 | issue.expects(:update_nested_set_attributes_on_parent_change).once | |
|
187 | issue.save! | |
|
188 | end | |
|
189 | ||
|
190 | def test_moving_a_child_issue_to_another_parent_should_trigger_update_nested_set_attributes_on_parent_change | |
|
191 | issue = Issue.find(Issue.generate!(:parent_issue_id => 1).id) | |
|
192 | issue.parent_issue_id = "2" | |
|
193 | issue.expects(:update_nested_set_attributes_on_parent_change).once | |
|
194 | issue.save! | |
|
195 | end | |
|
196 | ||
|
197 | def test_moving_a_child_issue_to_root_should_trigger_update_nested_set_attributes_on_parent_change | |
|
198 | issue = Issue.find(Issue.generate!(:parent_issue_id => 1).id) | |
|
199 | issue.parent_issue_id = "" | |
|
200 | issue.expects(:update_nested_set_attributes_on_parent_change).once | |
|
201 | issue.save! | |
|
202 | end | |
|
203 | ||
|
169 | 204 | def test_destroy_should_destroy_children |
|
170 | 205 | issue1 = Issue.generate! |
|
171 | 206 | issue2 = Issue.generate! |
General Comments 0
You need to be logged in to leave comments.
Login now