Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: jnunemaker/adapter-mongo
base: 6eb1732a1b
...
head fork: jnunemaker/adapter-mongo
compare: 1c5b153fdc
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 4 files changed
  • 0 commit comments
  • 1 contributor
View
1  Guardfile
@@ -4,6 +4,7 @@ guard 'bundler' do
end
guard 'rspec', :version => 2 do
+ watch('spec/support/shared_mongo_adapter.rb') { 'spec' }
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/adapter/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
View
9 lib/adapter/mongo.rb
@@ -24,7 +24,12 @@ def clear
end
def key_for(key)
- key.is_a?(BSON::ObjectId) ? key : super
+ case key
+ when BSON::ObjectId, Hash
+ key
+ else
+ super
+ end
end
def encode(value)
@@ -38,4 +43,4 @@ def decode(value)
end
end
-Adapter.define(:mongo, Adapter::Mongo)
+Adapter.define(:mongo, Adapter::Mongo)
View
50 spec/helper.rb
@@ -1,4 +1,5 @@
$:.unshift(File.expand_path('../../lib', __FILE__))
+$:.unshift(File.expand_path('../', __FILE__))
require 'rubygems'
require 'bundler'
@@ -9,54 +10,7 @@
require 'adapter/spec/types'
require 'adapter-mongo'
-shared_examples_for "a mongo adapter" do
- it_should_behave_like 'an adapter'
-
- Adapter::Spec::Types.each do |type, (key, key2)|
- it "writes Object values to keys that are #{type}s like a Hash" do
- adapter[key] = {:foo => :bar}
- # mongo knows hashes and can serialize symbol values
- adapter[key].should == {'_id' => 'key', 'foo' => :bar}
- end
- end
-
- 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
-
- 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
+require 'support/shared_mongo_adapter'
RSpec.configure do |c|
View
62 spec/support/shared_mongo_adapter.rb
@@ -0,0 +1,62 @@
+shared_examples_for "a mongo adapter" do
+ it_should_behave_like 'an adapter'
+
+ Adapter::Spec::Types.each do |type, (key, key2)|
+ it "writes Object values to keys that are #{type}s like a Hash" do
+ adapter[key] = {:foo => :bar}
+ # mongo knows hashes and can serialize symbol values
+ adapter[key].should == {'_id' => 'key', 'foo' => :bar}
+ end
+ end
+
+ 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
+
+ it "allows using ordered hashes as keys" do
+ key = BSON::OrderedHash['d', 1, 'n', 1]
+ adapter.write(key, 'ham')
+ client.find_one('_id' => key).should_not be_nil
+ adapter.read(key).should == 'ham'
+ end
+
+ it "allows using hashes as keys" do
+ key = {:d => 1}
+ adapter.write(key, 'ham')
+ client.find_one('_id' => key).should_not be_nil
+ adapter.read(key).should == 'ham'
+ end
+
+ 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

No commit comments for this range

Something went wrong with that request. Please try again.