Skip to content

Commit 5f8e617

Browse files
committed
Merge pull request #754 from estolfo/RUBY-1093-neg-limit
RUBY-1093 Negative limits become their absolute value in find commands
2 parents 828bd93 + 4d2c24f commit 5f8e617

File tree

3 files changed

+4
-8
lines changed

3 files changed

+4
-8
lines changed

lib/mongo/collection/view/builder/find_command.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def find_command
100100

101101
def convert_negative_limit(command)
102102
if command[:limit] && command[:limit] < 0
103-
command.delete('limit')
103+
command['limit'] = command['limit'].abs
104104
command[:singleBatch] = true
105105
end
106106
command

spec/mongo/collection/view/builder/find_command_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@
159159
expect(selector['singleBatch']).to be true
160160
end
161161

162-
it 'removes the limit from the command' do
163-
expect(selector['limit']).to be_nil
162+
it 'converts the limit to a positive value' do
163+
expect(selector['limit']).to be(options[:limit].abs)
164164
end
165165
end
166166

spec/mongo/cursor_spec.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,10 @@
136136
Mongo::Collection::View.new(authorized_collection, {}, :limit => -2)
137137
end
138138

139-
it 'returns the positive number of documents', unless: find_command_enabled? do
139+
it 'returns the positive number of documents' do
140140
expect(cursor.to_a.count).to eq(2)
141141
end
142142

143-
it 'returns all documents', if: find_command_enabled? do
144-
expect(cursor.to_a.count).to eq(10)
145-
end
146-
147143
it 'iterates the documents' do
148144
cursor.each do |doc|
149145
expect(doc).to have_key('field')

0 commit comments

Comments
 (0)