spec/runners/unified/crud_operations.rb in mongo-2.16.4 vs spec/runners/unified/crud_operations.rb in mongo-2.17.0

- old
+ new

@@ -6,11 +6,13 @@ module CrudOperations def find(op) collection = entities.get(:collection, op.use!('object')) use_arguments(op) do |args| - opts = {} + opts = { + let: args.use('let'), + } if session = args.use('session') opts[:session] = entities.get(:session, session) end req = collection.find(args.use!('filter'), **opts) if batch_size = args.use('batchSize') @@ -27,11 +29,15 @@ end def count_documents(op) collection = entities.get(:collection, op.use!('object')) use_arguments(op) do |args| - collection.find(args.use!('filter')).count_documents + opts = {} + if session = args.use('session') + opts[:session] = entities.get(:session, session) + end + collection.find(args.use!('filter')).count_documents(**opts) end end def estimated_document_count(op) collection = entities.get(:collection, op.use!('object')) @@ -45,42 +51,63 @@ end def distinct(op) collection = entities.get(:collection, op.use!('object')) use_arguments(op) do |args| - req = collection.find(args.use!('filter')).distinct(args.use!('fieldName')) + opts = {} + if session = args.use('session') + opts[:session] = entities.get(:session, session) + end + req = collection.find(args.use!('filter'), **opts).distinct(args.use!('fieldName'), **opts) result = req.to_a end end def find_one_and_update(op) collection = entities.get(:collection, op.use!('object')) use_arguments(op) do |args| filter = args.use!('filter') update = args.use!('update') - opts = {} + opts = { + let: args.use('let'), + } if return_document = args.use('returnDocument') opts[:return_document] = return_document.downcase.to_sym end + if session = args.use('session') + opts[:session] = entities.get(:session, session) + end collection.find_one_and_update(filter, update, **opts) end end def find_one_and_replace(op) collection = entities.get(:collection, op.use!('object')) use_arguments(op) do |args| filter = args.use!('filter') update = args.use!('replacement') - collection.find_one_and_replace(filter, update) + opts = { + let: args.use('let'), + } + if session = args.use('session') + opts[:session] = entities.get(:session, session) + end + collection.find_one_and_replace(filter, update, **opts) end end def find_one_and_delete(op) collection = entities.get(:collection, op.use!('object')) use_arguments(op) do |args| filter = args.use!('filter') - collection.find_one_and_delete(filter) + opts = { + let: args.use('let'), + } + if session = args.use('session') + opts[:session] = entities.get(:session, session) + end + collection.find_one_and_delete(filter, **opts) end end def insert_one(op) collection = entities.get(:collection, op.use!('object')) @@ -94,29 +121,41 @@ end def insert_many(op) collection = entities.get(:collection, op.use!('object')) use_arguments(op) do |args| - options = {} + opts = {} unless (ordered = args.use('ordered')).nil? - options[:ordered] = ordered + opts[:ordered] = ordered end - collection.insert_many(args.use!('documents'), **options) + if session = args.use('session') + opts[:session] = entities.get(:session, session) + end + collection.insert_many(args.use!('documents'), **opts) end end def update_one(op) collection = entities.get(:collection, op.use!('object')) use_arguments(op) do |args| - collection.update_one(args.use!('filter'), args.use!('update')) + opts = { + let: args.use('let'), + } + if session = args.use('session') + opts[:session] = entities.get(:session, session) + end + collection.update_one(args.use!('filter'), args.use!('update'), **opts) end end def update_many(op) collection = entities.get(:collection, op.use!('object')) use_arguments(op) do |args| - collection.update_many(args.use!('filter'), args.use!('update')) + opts = { + let: args.use('let'), + } + collection.update_many(args.use!('filter'), args.use!('update'), **opts) end end def replace_one(op) collection = entities.get(:collection, op.use!('object')) @@ -130,18 +169,27 @@ end def delete_one(op) collection = entities.get(:collection, op.use!('object')) use_arguments(op) do |args| - collection.delete_one(args.use!('filter')) + opts = { + let: args.use('let'), + } + if session = args.use('session') + opts[:session] = entities.get(:session, session) + end + collection.delete_one(args.use!('filter'), **opts) end end def delete_many(op) collection = entities.get(:collection, op.use!('object')) use_arguments(op) do |args| - collection.delete_many(args.use!('filter')) + opts = { + let: args.use('let'), + } + collection.delete_many(args.use!('filter'), **opts) end end def bulk_write(op) collection = entities.get(:collection, op.use!('object')) @@ -155,10 +203,26 @@ end collection.bulk_write(requests, **opts) end end + def aggregate(op) + obj = entities.get_any(op.use!('object')) + args = op.use!('arguments') + pipeline = args.use!('pipeline') + opts = { + let: args.use('let'), + } + if session = args.use('session') + opts[:session] = entities.get(:session, session) + end + unless args.empty? + raise NotImplementedError, "Unhandled spec keys: #{args} in #{test_spec}" + end + obj.aggregate(pipeline, **opts).to_a + end + private def convert_bulk_write_spec(spec) unless spec.keys.length == 1 raise NotImplementedError, "Must have exactly one item" @@ -189,18 +253,8 @@ end unless spec.empty? raise NotImplementedError, "Unhandled keys: #{spec}" end {Utils.underscore(op) =>out} - end - - def aggregate(op) - obj = entities.get_any(op.use!('object')) - args = op.use!('arguments') - pipeline = args.use!('pipeline') - unless args.empty? - raise NotImplementedError, "Unhandled spec keys: #{test_spec}" - end - obj.aggregate(pipeline).to_a end end end