minor: :collect_on_error docs and tests.

This commit is contained in:
Kyle Banker 2012-01-19 12:34:08 -05:00
parent 5b1e09a6ce
commit a0da417c42
2 changed files with 12 additions and 5 deletions

View File

@ -323,8 +323,8 @@ module Mongo
# The _id of the inserted document or a list of _ids of all inserted documents.
# @return [[ObjectId, Array], [Hash, Array]]
# 1st, the _id of the inserted document or a list of _ids of all inserted documents.
# 2nd, a list of invalid documents as a BSON.
# Return this result format when :collect_on_error is true.
# 2nd, a list of invalid documents.
# Return this result format only when :collect_on_error is true.
#
# @option opts [Boolean, Hash] :safe (+false+)
# run the operation in safe mode, which run a getlasterror command on the
@ -343,7 +343,7 @@ module Mongo
# enabled, any error will raise an OperationFailure exception.
# MongoDB v2.0+.
# @option opts [Boolean] :collect_on_error (+false+) if true, then
# collects invalid documents as a BSON. This option changes result format.
# collects invalid documents as an array. Note that this option changes the result format.
#
# @core insert insert-instance_method
def insert(doc_or_docs, opts={})

View File

@ -152,7 +152,6 @@ class TestCollection < Test::Unit::TestCase
end
def test_bulk_insert
@@test.remove
docs = []
docs << {:foo => 1}
docs << {:foo => 2}
@ -161,7 +160,6 @@ class TestCollection < Test::Unit::TestCase
assert_equal 3, response.length
assert response.all? {|id| id.is_a?(BSON::ObjectId)}
assert_equal 3, @@test.count
@@test.remove
end
def test_bulk_insert_with_continue_on_error
@ -193,6 +191,15 @@ class TestCollection < Test::Unit::TestCase
end
end
def test_bson_valid_with_collect_on_error
docs = []
docs << {:foo => 1}
docs << {:bar => 1}
doc_ids, error_docs = @@test.insert(docs, :collect_on_error => true)
assert_equal 2, @@test.count
assert_equal error_docs, []
end
def test_bson_invalid_key_serialize_error_with_collect_on_error
docs = []
docs << {:foo => 1}