mongo-ruby-driver/test/safe_test.rb
Kyle Banker 68af3dbe8f Allow the setting of safe mode globally on the Connection,
DB, and Collection levels. The safe mode setting will
automatically be inherited down the hierarchy Connection ->
DB -> Collection -> (insert, update, remove). This default
can be overridden at any time. Connection#safe, DB#safe, and
Collection#safe will yield the current default value.
2010-11-03 17:36:08 -04:00

43 lines
1.0 KiB
Ruby

require './test/test_helper'
include Mongo
class SafeTest < Test::Unit::TestCase
context "Safe tests: " 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
end