Skip to content

Commit

Permalink
New self_and_ancestors_ids method to get self id with ancestor_ids
Browse files Browse the repository at this point in the history
  • Loading branch information
kirs committed Feb 5, 2014
1 parent 6c047d2 commit 51b63ca
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/closure_tree/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ def ancestor_ids
_ct.ids_from(ancestors)
end

def self_and_ancestors_ids
_ct.ids_from(ancestors) + [id]
end

# Returns an array, root first, of self_and_ancestors' values of the +to_s_column+, which defaults
# to the +name_column+.
# (so child.ancestry_path == +%w{grandparent parent child}+
Expand Down
2 changes: 2 additions & 0 deletions spec/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,10 @@ def assert_mid_and_leaf_remain
u = User.find_or_create_by_path(%w([email protected] [email protected] [email protected]))
u.descendant_ids.should == []
u.ancestor_ids.should == [u.parent.id, u.root.id]
u.self_and_ancestor_ids.should == [u.parent.id, u.root.id] + [u.id]
u.root.descendant_ids.should == [u.parent.id, u.id]
u.root.ancestor_ids.should == []
u.root.self_and_ancestor_ids.should == [u.root.id]
c1 = u.contracts.create!
c2 = u.parent.contracts.create!
u.root.indirect_contracts.to_a.should =~ [c1, c2]
Expand Down

0 comments on commit 51b63ca

Please sign in to comment.