spec/helper.rb in adapter-mongo-0.5.4 vs spec/helper.rb in adapter-mongo-0.5.5

- old
+ new

@@ -1,23 +1,14 @@ $:.unshift(File.expand_path('../../lib', __FILE__)) require 'rubygems' require 'bundler' -Bundler.require(:default, :development) +Bundler.require(:default, :test) -require 'pathname' -require 'logger' - -root_path = Pathname(__FILE__).dirname.join('..').expand_path -lib_path = root_path.join('lib') -log_path = root_path.join('log') -log_path.mkpath - require 'adapter/spec/an_adapter' require 'adapter/spec/types' - require 'adapter-mongo' shared_examples_for "a mongo adapter" do it_should_behave_like 'an adapter' @@ -26,13 +17,47 @@ adapter[key] = {:foo => :bar} # mongo knows hashes and can serialize symbol values adapter[key].should == {'_id' => 'key', 'foo' => :bar} end end -end -logger = Logger.new(log_path.join('test.log')) -LogBuddy.init(:logger => logger) + it "allows using object id's as keys in correct type" do + id = BSON::ObjectId.new + adapter.write(id, 'ham') + client.find_one('_id' => id).should_not be_nil + adapter.read(id).should == 'ham' + end -Rspec.configure do |c| + it "stores hashes right in document" do + adapter.write('foo', 'steak' => 'bacon') + client.find_one('_id' => 'foo').should == {'_id' => 'foo', 'steak' => 'bacon'} + end + + describe "with safe option" do + before do + client.ensure_index([['email', 1]], :unique => true) + @adapter = Adapter[adapter_name].new(client, :safe => true) + end + + after do + client.drop_index('email_1') + end + + it "does not raise operation failure on write if operation succeeds" do + adapter.write(BSON::ObjectId.new, {'email' => 'john@orderedlist.com'}) + lambda { + adapter.write(BSON::ObjectId.new, {'email' => 'steve@orderedlist.com'}) + }.should_not raise_error(Mongo::OperationFailure) + end + + it "raises operation failure on write if operation fails" do + adapter.write(BSON::ObjectId.new, {'email' => 'john@orderedlist.com'}) + lambda { + adapter.write(BSON::ObjectId.new, {'email' => 'john@orderedlist.com'}) + }.should raise_error(Mongo::OperationFailure) + end + end +end + +RSpec.configure do |c| end