Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Add parent query methods #97

wants to merge 1 commit into
Jump to file or symbol
Failed to load files and symbols.
+7 −0
@@ -122,6 +122,10 @@ def parent
if parent_id.blank? then nil else unscoped_find(parent_id) end
+ def parent?
+ parent_id.present?
+ end
# Root
def root_id
if ancestor_ids.empty? then id else ancestor_ids.first end
@@ -107,6 +107,7 @@ def test_tree_navigation
# Parent assertions
assert_equal nil, lvl0_node.parent_id
assert_equal nil, lvl0_node.parent
+ assert !lvl0_node.parent?
# Root assertions
assert_equal lvl0_node.id, lvl0_node.root_id
assert_equal lvl0_node, lvl0_node.root
@@ -139,6 +140,7 @@ def test_tree_navigation
# Parent assertions
assert_equal lvl0_node.id, lvl1_node.parent_id
assert_equal lvl0_node, lvl1_node.parent
+ assert lvl1_node.parent?
# Root assertions
assert_equal lvl0_node.id, lvl1_node.root_id
assert_equal lvl0_node, lvl1_node.root
@@ -171,6 +173,7 @@ def test_tree_navigation
# Parent assertions
assert_equal lvl1_node.id, lvl2_node.parent_id
assert_equal lvl1_node, lvl2_node.parent
+ assert lvl2_node.parent?
# Root assertions
assert_equal lvl0_node.id, lvl2_node.root_id
assert_equal lvl0_node, lvl2_node.root