Skip to content

Commit 3b775f5

Browse files
committed
Merge pull request #688 from mongodb/RUBY-1022
RUBY-1022/RUBY-1016: Don't fail queries with 'ok', 'err', or 'errmsg' fields in first doc.
2 parents 039c8ec + 3b51099 commit 3b775f5

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

lib/mongo/operation/read/query/result.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Result < Operation::Result
3131
#
3232
# @since 2.0.0
3333
def successful?
34-
!query_failure? && parser.message.empty?
34+
!query_failure?
3535
end
3636
end
3737
end

spec/mongo/collection_spec.rb

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,50 @@
470470
end
471471
end
472472

473+
context 'when the user is not authorized' do
474+
475+
let(:view) do
476+
unauthorized_collection.find
477+
end
478+
479+
it 'iterates over the documents' do
480+
expect {
481+
view.each{ |document| document }
482+
}.to raise_error(Mongo::Error::OperationFailure)
483+
end
484+
end
485+
486+
context 'when documents contain potential error message fields' do
487+
488+
[ Mongo::Error::ERRMSG, Mongo::Error::ERROR, Mongo::Operation::Result::OK ].each do |field|
489+
490+
context "when the document contains a '#{field}' field" do
491+
492+
let(:value) do
493+
'testing'
494+
end
495+
496+
let(:view) do
497+
authorized_collection.find
498+
end
499+
500+
before do
501+
authorized_collection.insert_one({ field => value })
502+
end
503+
504+
after do
505+
authorized_collection.delete_many
506+
end
507+
508+
it 'iterates over the documents' do
509+
view.each do |document|
510+
expect(document[field]).to eq(value)
511+
end
512+
end
513+
end
514+
end
515+
end
516+
473517
context 'when provided options' do
474518

475519
let(:view) do

0 commit comments

Comments
 (0)