From d1e45fdb1a43bf27464e9787b7a1af905d110987 Mon Sep 17 00:00:00 2001 From: mbernstein Date: Sat, 5 Sep 2009 12:51:44 -0400 Subject: [PATCH] casting input from sort method as ordered hash, tweaking tests a bit --- lib/mongo/cursor.rb | 2 +- test/test_cursor.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/mongo/cursor.rb b/lib/mongo/cursor.rb index c3d99a5..68c06fc 100644 --- a/lib/mongo/cursor.rb +++ b/lib/mongo/cursor.rb @@ -81,7 +81,7 @@ module Mongo # {:name => -1, :age => 1} (name descending, age asending) def sort(order_hash = {}) 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 end diff --git a/test/test_cursor.rb b/test/test_cursor.rb index 0744715..049e224 100644 --- a/test/test_cursor.rb +++ b/test/test_cursor.rb @@ -67,11 +67,11 @@ class CursorTest < Test::Unit::TestCase assert_equal 0, @@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 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