Permalink
Browse files

Added test for sort_by_ancestry with block.

  • Loading branch information...
1 parent 7250efd commit 18514ea742c7747b244753a1578409b230f8a794 @iliya-gr iliya-gr committed Dec 20, 2011
Showing with 15 additions and 0 deletions.
  1. +15 −0 test/has_ancestry_test.rb
@@ -704,4 +704,19 @@ def test_sort_by_ancestry
assert_equal [n1, n2, n4, n3, n5].map(&:id), arranged.map(&:id)
end
end
+
+ def test_sort_by_ancestry_with_block
+ AncestryTestDatabase.with_model :extra_columns => {:rank => :integer} do |model|
+ n1 = model.create!(:rank => 0)
+ n2 = model.create!(:rank => 1)
+ n3 = model.create!(:rank => 0, :parent => n1)
+ n4 = model.create!(:rank => 0, :parent => n2)
+ n5 = model.create!(:rank => 1, :parent => n1)
+ n6 = model.create!(:rank => 1, :parent => n2)
+
+ arranged = model.sort_by_ancestry(model.all.sort_by(&:rank).reverse) {|a, b| a.rank <=> b.rank}
+ assert_equal [n1, n3, n5, n2, n4, n6].map(&:id), arranged.map(&:id)
+ end
+ end
+
end

0 comments on commit 18514ea

Please sign in to comment.