From a0da417c4202ff737053c855956fb9b0c342e47e Mon Sep 17 00:00:00 2001 From: Kyle Banker Date: Thu, 19 Jan 2012 12:34:08 -0500 Subject: [PATCH] minor: :collect_on_error docs and tests. --- lib/mongo/collection.rb | 6 +++--- test/collection_test.rb | 11 +++++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/mongo/collection.rb b/lib/mongo/collection.rb index 1a9c632..bbc5b72 100644 --- a/lib/mongo/collection.rb +++ b/lib/mongo/collection.rb @@ -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={}) diff --git a/test/collection_test.rb b/test/collection_test.rb index 948131d..88acfaf 100644 --- a/test/collection_test.rb +++ b/test/collection_test.rb @@ -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}