Skip to content

Commit

Permalink
added test for #85
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Henzen committed May 7, 2013
1 parent 4b59888 commit 39e2268
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions test/has_ancestry_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -775,4 +775,18 @@ def test_arrangement_nesting
assert_equal 1, model.arrange.count
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 39e2268

Please sign in to comment.