File tree Expand file tree Collapse file tree 2 files changed +18
-13
lines changed Expand file tree Collapse file tree 2 files changed +18
-13
lines changed Original file line number Diff line number Diff line change @@ -84,7 +84,7 @@ def count
84
84
# This method overrides any sort order specified in the Collection#find
85
85
# method, and only the last sort applied has an effect
86
86
def sort ( order )
87
- raise InvalidOperation , "can't call Cursor#sort on a used cursor" if @query_run
87
+ check_modifiable
88
88
@query . order_by = order
89
89
self
90
90
end
@@ -100,7 +100,7 @@ def limit(number_to_return)
100
100
raise ArgumentError , "limit requires an integer" unless number_to_return . is_a? Integer
101
101
102
102
@query . number_to_return = number_to_return
103
- return self
103
+ self
104
104
end
105
105
106
106
# Skips the first +number_to_skip+ results of this cursor.
@@ -114,7 +114,7 @@ def skip(number_to_skip)
114
114
raise ArgumentError , "skip requires an integer" unless number_to_skip . is_a? Integer
115
115
116
116
@query . number_to_skip = number_to_skip
117
- return self
117
+ self
118
118
end
119
119
120
120
# Iterate over each document in this cursor, yielding it to the given
Original file line number Diff line number Diff line change @@ -57,22 +57,27 @@ def test_count
57
57
58
58
assert_equal 0 , @@db [ 'acollectionthatdoesn' ] . count ( )
59
59
end
60
-
60
+
61
61
def test_sort
62
62
@@coll . clear
63
- 5 . times { |x | @@coll . insert ( { "a" => x , "b" => 5 - x } ) }
64
-
65
- assert_kind_of Cursor , @@coll . find ( ) . sort ( { :a => 1 } )
66
-
63
+ 5 . times { |x | @@coll . insert ( { "a" => x } ) }
64
+
65
+ assert_kind_of Cursor , @@coll . find ( ) . sort ( { :a => 1 } )
66
+
67
67
assert_equal 0 , @@coll . find ( ) . sort ( { :a => 1 } ) . next_object [ "a" ]
68
68
assert_equal 4 , @@coll . find ( ) . sort ( { :a => -1 } ) . next_object [ "a" ]
69
-
70
- assert_equal 1 , @@coll . find ( ) . sort ( { :a => - 1 , :b => 1 } ) . next_object [ "b" ]
71
- assert_equal 5 , @@coll . find ( ) . sort ( { :a => 1 , :b => - 1 } ) . next_object [ "b" ]
72
-
69
+ assert_equal 0 , @@coll . find ( ) . sort ( [ "a" ] ) . next_object [ "a" ]
70
+
71
+ assert_kind_of Cursor , @@coll . find ( ) . sort ( { :a => - 1 , :b => 1 } )
72
+
73
73
assert_equal 4 , @@coll . find ( ) . sort ( { :a => 1 } ) . sort ( { :a => -1 } ) . next_object [ "a" ]
74
74
assert_equal 0 , @@coll . find ( ) . sort ( { :a => -1 } ) . sort ( { :a => 1 } ) . next_object [ "a" ]
75
-
75
+
76
+ cursor = @@coll . find ( )
77
+ cursor . next_object ( )
78
+ assert_raise InvalidOperation do
79
+ cursor . sort ( [ "a" ] )
80
+ end
76
81
end
77
82
78
83
def test_limit
You can’t perform that action at this time.
0 commit comments