minor: tweaks and some more test cases
This commit is contained in:
parent
1b98a1961f
commit
f41b48a51b
|
@ -84,7 +84,7 @@ module Mongo
|
||||||
# This method overrides any sort order specified in the Collection#find
|
# This method overrides any sort order specified in the Collection#find
|
||||||
# method, and only the last sort applied has an effect
|
# method, and only the last sort applied has an effect
|
||||||
def sort(order)
|
def sort(order)
|
||||||
raise InvalidOperation, "can't call Cursor#sort on a used cursor" if @query_run
|
check_modifiable
|
||||||
@query.order_by = order
|
@query.order_by = order
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
@ -100,7 +100,7 @@ module Mongo
|
||||||
raise ArgumentError, "limit requires an integer" unless number_to_return.is_a? Integer
|
raise ArgumentError, "limit requires an integer" unless number_to_return.is_a? Integer
|
||||||
|
|
||||||
@query.number_to_return = number_to_return
|
@query.number_to_return = number_to_return
|
||||||
return self
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
# Skips the first +number_to_skip+ results of this cursor.
|
# Skips the first +number_to_skip+ results of this cursor.
|
||||||
|
@ -114,7 +114,7 @@ module Mongo
|
||||||
raise ArgumentError, "skip requires an integer" unless number_to_skip.is_a? Integer
|
raise ArgumentError, "skip requires an integer" unless number_to_skip.is_a? Integer
|
||||||
|
|
||||||
@query.number_to_skip = number_to_skip
|
@query.number_to_skip = number_to_skip
|
||||||
return self
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
# Iterate over each document in this cursor, yielding it to the given
|
# Iterate over each document in this cursor, yielding it to the given
|
||||||
|
|
|
@ -57,22 +57,27 @@ class CursorTest < Test::Unit::TestCase
|
||||||
|
|
||||||
assert_equal 0, @@db['acollectionthatdoesn'].count()
|
assert_equal 0, @@db['acollectionthatdoesn'].count()
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_sort
|
def test_sort
|
||||||
@@coll.clear
|
@@coll.clear
|
||||||
5.times{|x| @@coll.insert({"a" => x, "b" => 5-x}) }
|
5.times{|x| @@coll.insert({"a" => x}) }
|
||||||
|
|
||||||
assert_kind_of Cursor, @@coll.find().sort({:a=>1})
|
assert_kind_of Cursor, @@coll.find().sort({:a => 1})
|
||||||
|
|
||||||
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 0, @@coll.find().sort(["a"]).next_object["a"]
|
||||||
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_kind_of Cursor, @@coll.find().sort({:a => -1, :b => 1})
|
||||||
|
|
||||||
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"]
|
assert_equal 0, @@coll.find().sort({:a => -1}).sort({:a => 1}).next_object["a"]
|
||||||
|
|
||||||
|
cursor = @@coll.find()
|
||||||
|
cursor.next_object()
|
||||||
|
assert_raise InvalidOperation do
|
||||||
|
cursor.sort(["a"])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_limit
|
def test_limit
|
||||||
|
|
Loading…
Reference in New Issue