-
Notifications
You must be signed in to change notification settings - Fork 532
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
7 changed files
with
224 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.