spec/support/crud.rb in mongo-2.4.1 vs spec/support/crud.rb in mongo-2.4.2
- old
+ new
@@ -81,18 +81,11 @@
# @return [ true, false ] Whether the test can be run on the given
# server version.
#
# @since 2.4.0
def server_version_satisfied?(client)
- case @min_server_version
- when '2.6'
- client.cluster.servers.first.features.write_command_enabled?
- when '3.4'
- client.cluster.servers.first.features.collation_enabled?
- else
- true
- end
+ lower_bound_satisfied?(client) && upper_bound_satisfied?(client)
end
# Get a list of CRUDTests for each test definition.
#
# @example Get the list of CRUDTests.
@@ -104,10 +97,36 @@
def tests
@crud_tests.collect do |test|
Mongo::CRUD::CRUDTest.new(@data, test)
end
end
+
+ private
+
+ def upper_bound_satisfied?(client)
+ if @max_server_version
+ if @max_server_version < '2.6'
+ !client.cluster.next_primary.features.write_command_enabled?
+ end
+ else
+ true
+ end
+ end
+
+ def lower_bound_satisfied?(client)
+ if @min_server_version
+ if @min_server_version >= '3.4'
+ client.cluster.next_primary.features.collation_enabled?
+ elsif @min_server_version >= '2.6'
+ client.cluster.next_primary.features.write_command_enabled?
+ else
+ true
+ end
+ else
+ true
+ end
+ end
end
# Represents a single CRUD test.
#
# @since 2.0.0
@@ -225,14 +244,23 @@
def compare_result(expected, actual)
case expected
when nil
actual.nil?
when Hash
- actual.each do |k, v|
- expected[k] == v
+ actual.all? do |k, v|
+ expected[k] == v || handle_upserted_id(k, expected[k], v)
end
when Integer
expected == actual
+ end
+ end
+
+ def handle_upserted_id(field, expected_id, actual_id)
+ return true if expected_id.nil?
+ if field == 'upsertedId'
+ if expected_id.is_a?(Integer)
+ actual_id.is_a?(BSON::ObjectId) || actual_id.nil?
+ end
end
end
def actual_collection_data
if @outcome['collection']