Skip to content

RUBY-1022/RUBY-1016: Don't fail queries with 'ok', 'err', or 'errmsg' fields in first doc. #688

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 4, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/mongo/operation/read/query/result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Result < Operation::Result
#
# @since 2.0.0
def successful?
!query_failure? && parser.message.empty?
!query_failure?
end
end
end
Expand Down
44 changes: 44 additions & 0 deletions spec/mongo/collection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,50 @@
end
end

context 'when the user is not authorized' do

let(:view) do
unauthorized_collection.find
end

it 'iterates over the documents' do
expect {
view.each{ |document| document }
}.to raise_error(Mongo::Error::OperationFailure)
end
end

context 'when documents contain potential error message fields' do

[ Mongo::Error::ERRMSG, Mongo::Error::ERROR, Mongo::Operation::Result::OK ].each do |field|

context "when the document contains a '#{field}' field" do

let(:value) do
'testing'
end

let(:view) do
authorized_collection.find
end

before do
authorized_collection.insert_one({ field => value })
end

after do
authorized_collection.delete_many
end

it 'iterates over the documents' do
view.each do |document|
expect(document[field]).to eq(value)
end
end
end
end
end

context 'when provided options' do

let(:view) do
Expand Down