Sha256: 6f1a01e5290a58e0cddd79a1701db3e0253064f9c983c5ea5be10d4ec8da9792
Contents?: true
Size: 1.68 KB
Versions: 4
Compression:
Stored size: 1.68 KB
Contents
require File.expand_path("../test_helper", __FILE__) include Mongo class SafeTest < Test::Unit::TestCase context "Safe mode propogation: " do setup do @con = standard_connection(:safe => {:w => 1}) @db = @con[MONGO_TEST_DB] @col = @db['test-safe'] @col.create_index([[:a, 1]], :unique => true) @col.remove end should "propogate safe option on insert" do @col.insert({:a => 1}) assert_raise_error(OperationFailure, "duplicate key") do @col.insert({:a => 1}) end end should "allow safe override on insert" do @col.insert({:a => 1}) @col.insert({:a => 1}, :safe => false) end should "propogate safe option on update" do @col.insert({:a => 1}) @col.insert({:a => 2}) assert_raise_error(OperationFailure, "duplicate key") do @col.update({:a => 2}, {:a => 1}) end end should "allow safe override on update" do @col.insert({:a => 1}) @col.insert({:a => 2}) @col.update({:a => 2}, {:a => 1}, :safe => false) end end context "Safe error objects" do setup do @con = standard_connection @db = @con[MONGO_TEST_DB] @col = @db['test'] @col.remove @col.insert({:a => 1}) @col.insert({:a => 1}) @col.insert({:a => 1}) end should "return object on update" do response = @col.update({:a => 1}, {"$set" => {:a => 2}}, :multi => true, :safe => true) assert response['updatedExisting'] assert_equal 3, response['n'] end should "return object on remove" do response = @col.remove({}, :safe => true) assert_equal 3, response['n'] end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
mongo-1.7.1 | test/safe_test.rb |
mongo-1.7.0 | test/safe_test.rb |
mongo-1.7.0.rc0 | test/safe_test.rb |
mongo-1.6.4 | test/safe_test.rb |