casting input from sort method as ordered hash, tweaking tests a bit
This commit is contained in:
parent
bdafae6eeb
commit
d1e45fdb1a
|
@ -81,7 +81,7 @@ module Mongo
|
||||||
# {:name => -1, :age => 1} (name descending, age asending)
|
# {:name => -1, :age => 1} (name descending, age asending)
|
||||||
def sort(order_hash = {})
|
def sort(order_hash = {})
|
||||||
raise InvalidOperation, "can't call Cursor#sort on a used cursor" if @query_run
|
raise InvalidOperation, "can't call Cursor#sort on a used cursor" if @query_run
|
||||||
@query.order_by = order_hash
|
@query.order_by = OrderedHash[order_hash]
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -67,11 +67,11 @@ class CursorTest < Test::Unit::TestCase
|
||||||
assert_equal 0, @@coll.find().sort({:a => 1}).next_object["a"]
|
assert_equal 0, @@coll.find().sort({:a => 1}).next_object["a"]
|
||||||
assert_equal 4, @@coll.find().sort({:a => -1}).next_object["a"]
|
assert_equal 4, @@coll.find().sort({:a => -1}).next_object["a"]
|
||||||
|
|
||||||
assert_equal 1, @@coll.find().sort({:a => 1, :b => 1}).next_object["b"]
|
assert_equal 1, @@coll.find().sort({:a => -1, :b => 1}).next_object["b"]
|
||||||
assert_equal 5, @@coll.find().sort({:a => 1, :b => -1}).next_object["b"]
|
assert_equal 5, @@coll.find().sort({:a => 1, :b => -1}).next_object["b"]
|
||||||
|
|
||||||
assert_equal 4, @@coll.find().sort({:a => 1}).sort({:a => -1}).next_object["a"]
|
assert_equal 4, @@coll.find().sort({:a => 1}).sort({:a => -1}).next_object["a"]
|
||||||
assert_equal 4, @@coll.find().sort({:a => 1}).sort({:a => -1}).next_object["a"]
|
assert_equal 0, @@coll.find().sort({:a => -1}).sort({:a => 1}).next_object["a"]
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue