adapter-mongo 0.5.4 → 0.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/.travis.yml +9 -0
- data/Gemfile +14 -8
- data/Guardfile +10 -0
- data/README.md +33 -0
- data/lib/adapter/mongo/version.rb +1 -1
- data/lib/adapter/mongo_atomic.rb +9 -0
- data/lib/adapter-mongo.rb +2 -1
- data/spec/helper.rb +39 -14
- data/spec/mongo_atomic_spec.rb +27 -0
- data/spec/mongo_spec.rb +4 -39
- metadata +10 -6
- data/Gemfile.lock +0 -43
- data/README.rdoc +0 -31
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/Gemfile
CHANGED
@@ -1,12 +1,18 @@
|
|
1
1
|
source "http://rubygems.org"
|
2
2
|
gemspec
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
gem '
|
11
|
-
|
4
|
+
gem 'rake', '~> 0.9.0'
|
5
|
+
|
6
|
+
gem 'mongo', '~> 1.6'
|
7
|
+
gem 'bson_ext', '~> 1.6', :require => false
|
8
|
+
|
9
|
+
group(:test) do
|
10
|
+
gem 'rspec', '~> 2.8'
|
11
|
+
end
|
12
|
+
|
13
|
+
group(:guard) do
|
14
|
+
gem 'guard', '~> 1.0.0'
|
15
|
+
gem 'guard-rspec', '~> 0.6.0'
|
16
|
+
gem 'guard-bundler', '~> 0.1.0'
|
17
|
+
gem 'growl', '~> 1.0.0'
|
12
18
|
end
|
data/Guardfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# adapter-mongo
|
2
|
+
|
3
|
+
Mongo adapter for adapter gem.
|
4
|
+
|
5
|
+
```ruby
|
6
|
+
require 'adapter/mongo'
|
7
|
+
|
8
|
+
client = Mongo::Connection.new.db('adapter')['testing']
|
9
|
+
adapter = Adapter[:mongo].new(client)
|
10
|
+
adapter.clear
|
11
|
+
|
12
|
+
adapter.write('foo', 'bar')
|
13
|
+
puts 'Should be bar: ' + adapter.read('foo').inspect
|
14
|
+
|
15
|
+
adapter.delete('foo')
|
16
|
+
puts 'Should be nil: ' + adapter.read('foo').inspect
|
17
|
+
|
18
|
+
adapter.write('foo', 'bar')
|
19
|
+
adapter.clear
|
20
|
+
puts 'Should be nil: ' + adapter.read('foo').inspect
|
21
|
+
|
22
|
+
puts 'Should be bar: ' + adapter.fetch('foo', 'bar')
|
23
|
+
```
|
24
|
+
|
25
|
+
See examples/ or specs/ for more usage.
|
26
|
+
|
27
|
+
## Contributing
|
28
|
+
|
29
|
+
* Fork the project.
|
30
|
+
* Make your feature addition or bug fix.
|
31
|
+
* Add tests for it. This is important so we don't break it in a future version unintentionally.
|
32
|
+
* Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine, but bump version in a commit by itself so we can ignore when we pull)
|
33
|
+
* Send us a pull request. Bonus points for topic branches.
|
data/lib/adapter-mongo.rb
CHANGED
@@ -1 +1,2 @@
|
|
1
|
-
require 'adapter/mongo'
|
1
|
+
require 'adapter/mongo'
|
2
|
+
require 'adapter/mongo_atomic'
|
data/spec/helper.rb
CHANGED
@@ -3,19 +3,10 @@ $:.unshift(File.expand_path('../../lib', __FILE__))
|
|
3
3
|
require 'rubygems'
|
4
4
|
require 'bundler'
|
5
5
|
|
6
|
-
Bundler.require(:default, :
|
7
|
-
|
8
|
-
require 'pathname'
|
9
|
-
require 'logger'
|
10
|
-
|
11
|
-
root_path = Pathname(__FILE__).dirname.join('..').expand_path
|
12
|
-
lib_path = root_path.join('lib')
|
13
|
-
log_path = root_path.join('log')
|
14
|
-
log_path.mkpath
|
6
|
+
Bundler.require(:default, :test)
|
15
7
|
|
16
8
|
require 'adapter/spec/an_adapter'
|
17
9
|
require 'adapter/spec/types'
|
18
|
-
|
19
10
|
require 'adapter-mongo'
|
20
11
|
|
21
12
|
shared_examples_for "a mongo adapter" do
|
@@ -28,11 +19,45 @@ shared_examples_for "a mongo adapter" do
|
|
28
19
|
adapter[key].should == {'_id' => 'key', 'foo' => :bar}
|
29
20
|
end
|
30
21
|
end
|
31
|
-
end
|
32
22
|
|
33
|
-
|
34
|
-
|
23
|
+
it "allows using object id's as keys in correct type" do
|
24
|
+
id = BSON::ObjectId.new
|
25
|
+
adapter.write(id, 'ham')
|
26
|
+
client.find_one('_id' => id).should_not be_nil
|
27
|
+
adapter.read(id).should == 'ham'
|
28
|
+
end
|
29
|
+
|
30
|
+
it "stores hashes right in document" do
|
31
|
+
adapter.write('foo', 'steak' => 'bacon')
|
32
|
+
client.find_one('_id' => 'foo').should == {'_id' => 'foo', 'steak' => 'bacon'}
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "with safe option" do
|
36
|
+
before do
|
37
|
+
client.ensure_index([['email', 1]], :unique => true)
|
38
|
+
@adapter = Adapter[adapter_name].new(client, :safe => true)
|
39
|
+
end
|
40
|
+
|
41
|
+
after do
|
42
|
+
client.drop_index('email_1')
|
43
|
+
end
|
44
|
+
|
45
|
+
it "does not raise operation failure on write if operation succeeds" do
|
46
|
+
adapter.write(BSON::ObjectId.new, {'email' => 'john@orderedlist.com'})
|
47
|
+
lambda {
|
48
|
+
adapter.write(BSON::ObjectId.new, {'email' => 'steve@orderedlist.com'})
|
49
|
+
}.should_not raise_error(Mongo::OperationFailure)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "raises operation failure on write if operation fails" do
|
53
|
+
adapter.write(BSON::ObjectId.new, {'email' => 'john@orderedlist.com'})
|
54
|
+
lambda {
|
55
|
+
adapter.write(BSON::ObjectId.new, {'email' => 'john@orderedlist.com'})
|
56
|
+
}.should raise_error(Mongo::OperationFailure)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
35
60
|
|
36
|
-
|
61
|
+
RSpec.configure do |c|
|
37
62
|
|
38
63
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe "Mongo atomic adapter" do
|
4
|
+
before do
|
5
|
+
@client = Mongo::Connection.new.db('test')['test']
|
6
|
+
@adapter = Adapter[adapter_name].new(@client)
|
7
|
+
@adapter.clear
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:adapter_name) { :mongo_atomic }
|
11
|
+
|
12
|
+
let(:adapter) { @adapter }
|
13
|
+
let(:client) { @client }
|
14
|
+
|
15
|
+
it_should_behave_like 'a mongo adapter'
|
16
|
+
|
17
|
+
it "allows updating only part of a document" do
|
18
|
+
oid = BSON::ObjectId.new
|
19
|
+
adapter.write(oid, {'a' => 'c', 'b' => 'd'})
|
20
|
+
adapter.write(oid, {'a' => 'z'})
|
21
|
+
adapter.read(oid).should eq({
|
22
|
+
'_id' => oid,
|
23
|
+
'a' => 'z',
|
24
|
+
'b' => 'd',
|
25
|
+
})
|
26
|
+
end
|
27
|
+
end
|
data/spec/mongo_spec.rb
CHANGED
@@ -3,49 +3,14 @@ require 'helper'
|
|
3
3
|
describe "Mongo adapter" do
|
4
4
|
before do
|
5
5
|
@client = Mongo::Connection.new.db('test')['test']
|
6
|
-
@adapter = Adapter[
|
6
|
+
@adapter = Adapter[adapter_name].new(@client)
|
7
7
|
@adapter.clear
|
8
8
|
end
|
9
9
|
|
10
|
+
let(:adapter_name) { :mongo }
|
11
|
+
|
10
12
|
let(:adapter) { @adapter }
|
11
13
|
let(:client) { @client }
|
12
14
|
|
13
15
|
it_should_behave_like 'a mongo adapter'
|
14
|
-
|
15
|
-
it "allows using object id's as keys in correct type" do
|
16
|
-
id = BSON::ObjectId.new
|
17
|
-
adapter.write(id, 'ham')
|
18
|
-
client.find_one('_id' => id).should_not be_nil
|
19
|
-
adapter.read(id).should == 'ham'
|
20
|
-
end
|
21
|
-
|
22
|
-
it "stores hashes right in document" do
|
23
|
-
adapter.write('foo', 'steak' => 'bacon')
|
24
|
-
client.find_one('_id' => 'foo').should == {'_id' => 'foo', 'steak' => 'bacon'}
|
25
|
-
end
|
26
|
-
|
27
|
-
describe "with safe option" do
|
28
|
-
before do
|
29
|
-
client.ensure_index([['email', 1]], :unique => true)
|
30
|
-
@adapter = Adapter[:mongo].new(@client, :safe => true)
|
31
|
-
end
|
32
|
-
|
33
|
-
after do
|
34
|
-
client.drop_index('email_1')
|
35
|
-
end
|
36
|
-
|
37
|
-
it "does not raise operation failure on write if operation succeeds" do
|
38
|
-
adapter.write(BSON::ObjectId.new, {'email' => 'john@orderedlist.com'})
|
39
|
-
lambda {
|
40
|
-
adapter.write(BSON::ObjectId.new, {'email' => 'steve@orderedlist.com'})
|
41
|
-
}.should_not raise_error(Mongo::OperationFailure)
|
42
|
-
end
|
43
|
-
|
44
|
-
it "raises operation failure on write if operation fails" do
|
45
|
-
adapter.write(BSON::ObjectId.new, {'email' => 'john@orderedlist.com'})
|
46
|
-
lambda {
|
47
|
-
adapter.write(BSON::ObjectId.new, {'email' => 'john@orderedlist.com'})
|
48
|
-
}.should raise_error(Mongo::OperationFailure)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
16
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: adapter-mongo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 1
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 5
|
9
|
-
-
|
10
|
-
version: 0.5.
|
9
|
+
- 5
|
10
|
+
version: 0.5.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- John Nunemaker
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-
|
18
|
+
date: 2012-05-19 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
type: :runtime
|
@@ -58,17 +58,20 @@ extra_rdoc_files: []
|
|
58
58
|
|
59
59
|
files:
|
60
60
|
- .gitignore
|
61
|
+
- .travis.yml
|
61
62
|
- Gemfile
|
62
|
-
-
|
63
|
+
- Guardfile
|
63
64
|
- LICENSE
|
64
|
-
- README.
|
65
|
+
- README.md
|
65
66
|
- Rakefile
|
66
67
|
- adapter-mongo.gemspec
|
67
68
|
- examples/mongo.rb
|
68
69
|
- lib/adapter-mongo.rb
|
69
70
|
- lib/adapter/mongo.rb
|
70
71
|
- lib/adapter/mongo/version.rb
|
72
|
+
- lib/adapter/mongo_atomic.rb
|
71
73
|
- spec/helper.rb
|
74
|
+
- spec/mongo_atomic_spec.rb
|
72
75
|
- spec/mongo_spec.rb
|
73
76
|
homepage: ""
|
74
77
|
licenses: []
|
@@ -105,4 +108,5 @@ specification_version: 3
|
|
105
108
|
summary: Adapter for mongo
|
106
109
|
test_files:
|
107
110
|
- spec/helper.rb
|
111
|
+
- spec/mongo_atomic_spec.rb
|
108
112
|
- spec/mongo_spec.rb
|
data/Gemfile.lock
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
adapter-mongo (0.5.4)
|
5
|
-
adapter (~> 0.5)
|
6
|
-
mongo (~> 1.5)
|
7
|
-
|
8
|
-
GEM
|
9
|
-
remote: http://rubygems.org/
|
10
|
-
specs:
|
11
|
-
activesupport (3.0.3)
|
12
|
-
adapter (0.5.2)
|
13
|
-
bson (1.5.2)
|
14
|
-
bson_ext (1.5.2)
|
15
|
-
bson (= 1.5.2)
|
16
|
-
diff-lcs (1.1.2)
|
17
|
-
i18n (0.5.0)
|
18
|
-
log_buddy (0.5.0)
|
19
|
-
mongo (1.5.2)
|
20
|
-
bson (= 1.5.2)
|
21
|
-
rake (0.9.2.2)
|
22
|
-
rspec (2.4.0)
|
23
|
-
rspec-core (~> 2.4.0)
|
24
|
-
rspec-expectations (~> 2.4.0)
|
25
|
-
rspec-mocks (~> 2.4.0)
|
26
|
-
rspec-core (2.4.0)
|
27
|
-
rspec-expectations (2.4.0)
|
28
|
-
diff-lcs (~> 1.1.2)
|
29
|
-
rspec-mocks (2.4.0)
|
30
|
-
timecop (0.3.5)
|
31
|
-
|
32
|
-
PLATFORMS
|
33
|
-
ruby
|
34
|
-
|
35
|
-
DEPENDENCIES
|
36
|
-
activesupport (~> 3)
|
37
|
-
adapter-mongo!
|
38
|
-
bson_ext
|
39
|
-
i18n (= 0.5.0)
|
40
|
-
log_buddy (~> 0.5.0)
|
41
|
-
rake
|
42
|
-
rspec (~> 2.3)
|
43
|
-
timecop (~> 0.3.5)
|
data/README.rdoc
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
= adapter-mongo
|
2
|
-
|
3
|
-
Mongo adapter for adapter gem.
|
4
|
-
|
5
|
-
require 'adapter/mongo'
|
6
|
-
|
7
|
-
client = Mongo::Connection.new.db('adapter')['testing']
|
8
|
-
adapter = Adapter[:mongo].new(client)
|
9
|
-
adapter.clear
|
10
|
-
|
11
|
-
adapter.write('foo', 'bar')
|
12
|
-
puts 'Should be bar: ' + adapter.read('foo').inspect
|
13
|
-
|
14
|
-
adapter.delete('foo')
|
15
|
-
puts 'Should be nil: ' + adapter.read('foo').inspect
|
16
|
-
|
17
|
-
adapter.write('foo', 'bar')
|
18
|
-
adapter.clear
|
19
|
-
puts 'Should be nil: ' + adapter.read('foo').inspect
|
20
|
-
|
21
|
-
puts 'Should be bar: ' + adapter.fetch('foo', 'bar')
|
22
|
-
|
23
|
-
See examples/ or specs/ for more usage.
|
24
|
-
|
25
|
-
== Note on Patches/Pull Requests
|
26
|
-
|
27
|
-
* Fork the project.
|
28
|
-
* Make your feature addition or bug fix.
|
29
|
-
* Add tests for it. This is important so we don't break it in a future version unintentionally.
|
30
|
-
* Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine, but bump version in a commit by itself so we can ignore when we pull)
|
31
|
-
* Send us a pull request. Bonus points for topic branches.
|