spec/support/crud/read.rb in mongo-2.3.1 vs spec/support/crud/read.rb in mongo-2.4.0.rc0
- old
+ new
@@ -26,23 +26,14 @@
#
# @since 2.0.0
ARGUMENT_MAP = { :sort => 'sort',
:skip => 'skip',
:batch_size => 'batchSize',
- :limit => 'limit'
+ :limit => 'limit',
+ :collation => 'collation'
}
- # Map of read preference mode names to their equivalent Ruby-formatted symbols.
- #
- # @since 2.4.0
- READ_PREFERENCE_MAP = { 'primary' => :primary,
- 'secondary' => :secondary,
- 'primaryPreferred' => :primary_preferred,
- 'secondaryPreferred' => :secondary_preferred,
- 'nearest' => :nearest
- }
-
# The operation name.
#
# @return [ String ] name The operation name.
#
# @since 2.0.0
@@ -98,10 +89,30 @@
# @since 2.0.0
def requires_2_6?(collection)
name == 'aggregate' && pipeline.find {|op| op.keys.include?('$out') }
end
+ # Whether this operation requires a certain server version to be run.
+ #
+ # @example Determine whether this operation requires a certain server feature.
+ # operation.feature_enabled?(collection)
+ #
+ # @param [ Collection ] collection The collection the operation
+ # should be executed on.
+ #
+ # @return [ true, false ] Whether this operation requires a certain server version.
+ #
+ # @since 2.4.0
+ def feature_enabled?(collection)
+ if collation
+ return $mongo_client.cluster.servers.first.features.collation_enabled?
+ elsif requires_2_6?(collection)
+ return $mongo_client.cluster.servers.first.features.write_command_enabled?
+ end
+ true
+ end
+
private
def count(collection)
options = ARGUMENT_MAP.reduce({}) do |opts, (key, value)|
opts.merge!(key => arguments[value]) if arguments[value]
@@ -117,20 +128,23 @@
def distinct(collection)
collection.distinct(field_name, filter, options)
end
def find(collection)
- opts = modifiers ? options.merge(modifiers: BSON::Document.new(modifiers)) : options
- (read_preference ? collection.with(read: read_preference) : collection).find(filter, opts).to_a
+ collection.find(filter, options.merge(modifiers: BSON::Document.new(modifiers) || {})).to_a
end
def options
ARGUMENT_MAP.reduce({}) do |opts, (key, value)|
arguments[value] ? opts.merge!(key => arguments[value]) : opts
end
end
+ def collation
+ arguments['collation']
+ end
+
def batch_size
arguments['batchSize']
end
def filter
@@ -149,15 +163,9 @@
arguments['fieldName']
end
def arguments
@spec['arguments']
- end
-
- def read_preference
- if @spec['read_preference'] && @spec['read_preference']['mode']
- { mode: READ_PREFERENCE_MAP[@spec['read_preference']['mode']] }
- end
end
end
end
end
end