Skip to content

Commit dacf2e0

Browse files
committed
Merge pull request #684 from estolfo/RUBY-1016-query-op
RUBY-1016 Don't check the 'ok' field in query operation validation
2 parents 31a9a36 + 859c4e4 commit dacf2e0

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

lib/mongo/operation/read/query.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
require 'mongo/operation/read/query/result'
16+
1517
module Mongo
1618
module Operation
1719
module Read
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Copyright (C) 2014-2015 MongoDB, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
module Mongo
16+
module Operation
17+
module Read
18+
class Query
19+
20+
# Defines custom behaviour of results for a query.
21+
#
22+
# @since 2.1.0
23+
class Result < Operation::Result
24+
25+
# Determine if the query was a success.
26+
#
27+
# @example Was the query successful?
28+
# result.successful?
29+
#
30+
# @return [ true, false ] If the query was successful.
31+
#
32+
# @since 2.0.0
33+
def successful?
34+
!query_failure? && parser.message.empty?
35+
end
36+
end
37+
end
38+
end
39+
end
40+
end

spec/mongo/operation/read/query_spec.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,25 @@
8282
op.execute(primary_context)
8383
end
8484
end
85+
86+
context "when the document contains an 'ok' field" do
87+
88+
before do
89+
authorized_collection.insert_one(ok: false)
90+
end
91+
92+
after do
93+
authorized_collection.delete_many
94+
end
95+
96+
let(:context) do
97+
authorized_client.cluster.next_primary.context
98+
end
99+
100+
it 'does not raise an exception' do
101+
expect(op.execute(context)).to be_a(Mongo::Operation::Read::Query::Result)
102+
end
103+
end
85104
end
86105
end
87106

0 commit comments

Comments
 (0)