spec/support/crud/read.rb in mongo-2.5.3 vs spec/support/crud/read.rb in mongo-2.6.0

- old
+ new

@@ -1,6 +1,6 @@ -# Copyright (C) 2014-2017 MongoDB, Inc. +# Copyright (C) 2014-2018 MongoDB, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # @@ -68,11 +68,11 @@ # # @return [ Result, Array<Hash> ] The result of executing the operation. # # @since 2.0.0 def execute(collection) - send(name.to_sym, collection) + send(camel_to_snake(name), collection) end # Whether the operation is expected to have restuls. # # @example Whether the operation is expected to have results. @@ -94,10 +94,26 @@ opts end collection.count(filter, options) end + def count_documents(collection) + options = ARGUMENT_MAP.reduce({}) do |opts, (key, value)| + opts.merge!(key => arguments[value]) if arguments[value] + opts + end + collection.count_documents(filter, options) + end + + def estimated_document_count(collection) + options = ARGUMENT_MAP.reduce({}) do |opts, (key, value)| + opts.merge!(key => arguments[value]) if arguments[value] + opts + end + collection.estimated_document_count(options) + end + def aggregate(collection) collection.aggregate(pipeline, options).to_a end def distinct(collection) @@ -109,10 +125,15 @@ (read_preference ? collection.with(read: read_preference) : collection).find(filter, opts).to_a end def options ARGUMENT_MAP.reduce({}) do |opts, (key, value)| - arguments[value] ? opts.merge!(key => arguments[value]) : opts + value = if arguments[value].is_a?(Hash) && arguments[value]['$numberLong'] + arguments[value]['$numberLong'].to_i + else + arguments[value] + end + value ? opts.merge!(key => value) : opts end end def collation arguments['collation']