Skip to content

Commit b605aec

Browse files
author
Shirish Pampoorickal
committedFeb 16, 2016
Merge pull request #5 from mavenlink/fix_ancestry_depth_for_multi_level_stories
Update root_ancestor_id of descendants when parent is made a root
2 parents 26409fc + d3bdaa8 commit b605aec

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed
 

‎lib/arboreal/instance_methods.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def apply_ancestry_change_to_descendants
115115

116116
def descendant_attributes_to_update(old_path_string)
117117
if root_relation_enabled?
118-
["root_ancestor_id = ?, materialized_path = REPLACE(materialized_path, ?, ?)", root_ancestor_id, old_path_string, path_string]
118+
["root_ancestor_id = ?, materialized_path = REPLACE(materialized_path, ?, ?)", root_ancestor_id || id, old_path_string, path_string]
119119
else
120120
["materialized_path = REPLACE(materialized_path, ?, ?)", old_path_string, path_string]
121121
end

‎spec/hierarchy_spec.rb

+5
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@
240240

241241
describe "when a node becomes a root" do
242242
before do
243+
Node.create!(:name => "Southbank", :parent => @melbourne)
243244
@victoria.update_attribute(:parent_id, nil)
244245
end
245246

@@ -254,6 +255,10 @@
254255
it "persists changes to the ancestors" do
255256
@victoria.reload.ancestors.should be_empty
256257
end
258+
259+
it 'updates the root of its descendants' do
260+
@victoria.descendants.map(&:root_ancestor).uniq.should == [@victoria]
261+
end
257262
end
258263

259264
describe "node created using find_or_create_by" do

0 commit comments

Comments
 (0)