adapter-mongo 0.5 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- adapter-mongo (0.5)
4
+ adapter-mongo (0.5.1)
5
5
  adapter (~> 0.5.1)
6
6
  mongo (~> 1.2.0)
7
7
 
data/lib/adapter/mongo.rb CHANGED
@@ -12,11 +12,11 @@ module Adapter
12
12
  end
13
13
 
14
14
  def write(key, value)
15
- client.save({'_id' => key_for(key)}.merge(encode(value)))
15
+ client.save({'_id' => key_for(key)}.merge(encode(value)), {:safe => options[:safe]})
16
16
  end
17
17
 
18
18
  def delete(key)
19
- read(key).tap { client.remove('_id' => key_for(key)) }
19
+ read(key).tap { client.remove({'_id' => key_for(key)}, {:safe => options[:safe]}) }
20
20
  end
21
21
 
22
22
  def clear
@@ -1,5 +1,5 @@
1
1
  module Adapter
2
2
  module Mongo
3
- VERSION = "0.5"
3
+ VERSION = "0.5.1"
4
4
  end
5
5
  end
data/spec/mongo_spec.rb CHANGED
@@ -24,4 +24,29 @@ describe "Mongo adapter" do
24
24
  adapter.write('foo', 'steak' => 'bacon')
25
25
  client.find_one('_id' => 'foo').should == {'_id' => 'foo', 'steak' => 'bacon'}
26
26
  end
27
+
28
+ describe "with safe option" do
29
+ before do
30
+ client.ensure_index([['email', 1]], :unique => true)
31
+ @adapter = Adapter[:mongo].new(@client, :safe => true)
32
+ end
33
+
34
+ after do
35
+ client.drop_index('email_1')
36
+ end
37
+
38
+ it "does not raise operation failure on write if operation succeeds" do
39
+ adapter.write(BSON::ObjectId.new, {'email' => 'john@orderedlist.com'})
40
+ lambda {
41
+ adapter.write(BSON::ObjectId.new, {'email' => 'steve@orderedlist.com'})
42
+ }.should_not raise_error(Mongo::OperationFailure)
43
+ end
44
+
45
+ it "raises operation failure on write if operation fails" do
46
+ adapter.write(BSON::ObjectId.new, {'email' => 'john@orderedlist.com'})
47
+ lambda {
48
+ adapter.write(BSON::ObjectId.new, {'email' => 'john@orderedlist.com'})
49
+ }.should raise_error(Mongo::OperationFailure)
50
+ end
51
+ end
27
52
  end
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: adapter-mongo
3
3
  version: !ruby/object:Gem::Version
4
- hash: 1
5
4
  prerelease: false
6
5
  segments:
7
6
  - 0
8
7
  - 5
9
- version: "0.5"
8
+ - 1
9
+ version: 0.5.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - John Nunemaker
@@ -25,7 +25,6 @@ dependencies:
25
25
  requirements:
26
26
  - - ~>
27
27
  - !ruby/object:Gem::Version
28
- hash: 9
29
28
  segments:
30
29
  - 0
31
30
  - 5
@@ -41,7 +40,6 @@ dependencies:
41
40
  requirements:
42
41
  - - ~>
43
42
  - !ruby/object:Gem::Version
44
- hash: 31
45
43
  segments:
46
44
  - 1
47
45
  - 2
@@ -86,7 +84,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
86
84
  requirements:
87
85
  - - ">="
88
86
  - !ruby/object:Gem::Version
89
- hash: 3
90
87
  segments:
91
88
  - 0
92
89
  version: "0"
@@ -95,7 +92,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
92
  requirements:
96
93
  - - ">="
97
94
  - !ruby/object:Gem::Version
98
- hash: 3
99
95
  segments:
100
96
  - 0
101
97
  version: "0"