Permalink
Browse files

add specs for to_nested_a methods

  • Loading branch information...
1 parent 46adf10 commit 1c34ef2448cad325d37566f4b38c1449be1b99ac Paweł Kondzior committed Jan 10, 2009
Showing with 25 additions and 10 deletions.
  1. +1 −1 lib/sequel_nested_set.rb
  2. +24 −9 spec/nested_set_spec.rb
View
@@ -443,7 +443,7 @@ def to_text
# The block arguments are |item, level|. The remaining arguments for
# this method are for recursion and should not normally be given.
def to_nested_a(flat = false, mover = nil, descendants = nil, level = self.level, &block)
- descendants ||= self.descendants
+ descendants ||= self.descendants.all
array = [ block_given? ? yield(self, level) : self ]
while not descendants.empty?
View
@@ -17,7 +17,6 @@
describe "ClassMethods" do
it "should have nested_set_options" do
- debugger
Client.should respond_to(:nested_set_options)
end
@@ -62,6 +61,14 @@
it "should have to_text method that returns whole tree from all root nodes as text and should be able to pass block" do
Client.to_text { |node| node.name }.should == "* Top Level (nil, 1, 10)\n** Child 1 (1, 2, 3)\n** Child 2 (1, 4, 7)\n*** Child 2.1 (3, 5, 6)\n** Child 3 (1, 8, 9)\n* Top Level 2 (nil, 11, 12)"
end
+
+ it "should have to_nested_a method that returns nested array of all nodes from roots to leaves" do
+ Client.to_nested_a.should == [[@root, [@node1], [@node2, [@node2_1]], [@node3]], [@root2]]
+ end
+
+ it "should have to_nested_a method that can pass block with node and level" do
+ Client.to_nested_a { |node, level| level }.should == [[0, [1], [1, [2]], [1]], [0]]
+ end
end
describe "InstanceMethods" do
@@ -200,14 +207,6 @@
@node3.right_sibling.should be_nil
end
- it "should @root and @node be in same scope" do
- @root.same_scope?(@node).should be_true
- end
-
- it "should @root and @root_in_other_scope be in different scope" do
-
- end
-
it "should have node_x.is_or_is_descendant_of?(node_y) that will return proper boolean value" do
@node1.is_or_is_descendant_of?(@root).should be_true
@node2_1.is_or_is_descendant_of?(@root).should be_true
@@ -505,6 +504,14 @@
n4.move_to_child_of(n2)
Client.valid?.should be_true
end
+
+ it "should have to_nested_a method that returns nested array of all nodes from roots to leaves" do
+ @root.to_nested_a.should == [@root, [@node1], [@node2, [@node2_1]], [@node3]]
+ end
+
+ it "should have to_nested_a method that can pass block with node and level" do
+ @root.to_nested_a { |node, level| level }.should == [0, [1], [1, [2]], [1]]
+ end
end
end
@@ -534,6 +541,14 @@
end
+ it "should @root and @node be in same scope" do
+# @root.same_scope?(@node).should be_true
+ end
+
+ it "should @root and @root_in_other_scope be in different scope" do
+
+ end
+
# def test_multi_scoped_no_duplicates_for_columns?
# assert_nothing_raised do
# Note.no_duplicates_for_columns?

0 comments on commit 1c34ef2

Please sign in to comment.