toystore-mongo 0.8.2 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +1 -1
- data/lib/toy/extensions/bson_object_id.rb +7 -3
- data/lib/toy/mongo/querying.rb +4 -4
- data/lib/toy/mongo/version.rb +1 -1
- data/spec/support/constants.rb +3 -2
- data/spec/toy/identity/object_id_key_factory_spec.rb +1 -1
- data/spec/toy/mongo/querying_spec.rb +15 -16
- data/toystore-mongo.gemspec +1 -1
- metadata +7 -7
data/README.rdoc
CHANGED
@@ -1,9 +1,13 @@
|
|
1
|
-
|
2
|
-
def
|
1
|
+
module ObjectIdConversions
|
2
|
+
def to_store(value, *)
|
3
3
|
Plucky.to_object_id(value)
|
4
4
|
end
|
5
5
|
|
6
|
-
def
|
6
|
+
def from_store(value, *)
|
7
7
|
Plucky.to_object_id(value)
|
8
8
|
end
|
9
9
|
end
|
10
|
+
|
11
|
+
class BSON::ObjectId
|
12
|
+
extend ObjectIdConversions
|
13
|
+
end
|
data/lib/toy/mongo/querying.rb
CHANGED
@@ -51,7 +51,7 @@ module Toy
|
|
51
51
|
|
52
52
|
def query
|
53
53
|
# TODO: add object id keys to convert
|
54
|
-
Plucky::Query.new(
|
54
|
+
Plucky::Query.new(adapter.client, :transformer => transformer).object_ids(object_id_attributes)
|
55
55
|
end
|
56
56
|
|
57
57
|
PluckyMethods.each do |name|
|
@@ -85,7 +85,7 @@ module Toy
|
|
85
85
|
run_callbacks(:update) do
|
86
86
|
criteria = {'_id' => id}
|
87
87
|
update = {'$set' => persistable_changes}
|
88
|
-
|
88
|
+
adapter.client.update(criteria, update, {:safe => adapter.options[:safe]})
|
89
89
|
true
|
90
90
|
end
|
91
91
|
end
|
@@ -98,11 +98,11 @@ module Toy
|
|
98
98
|
options = {}
|
99
99
|
criteria = {'_id' => id}
|
100
100
|
criteria.update(opts[:criteria]) if opts[:criteria]
|
101
|
-
options[:safe] = opts.key?(:safe) ? opts[:safe] :
|
101
|
+
options[:safe] = opts.key?(:safe) ? opts[:safe] : adapter.options[:safe]
|
102
102
|
|
103
103
|
run_callbacks(:save) do
|
104
104
|
run_callbacks(:update) do
|
105
|
-
|
105
|
+
adapter.client.update(criteria, update, options)
|
106
106
|
end
|
107
107
|
end
|
108
108
|
end
|
data/lib/toy/mongo/version.rb
CHANGED
data/spec/support/constants.rb
CHANGED
@@ -29,7 +29,7 @@ describe Toy::Identity::ObjectIdKeyFactory do
|
|
29
29
|
it "correctly stores id in database" do
|
30
30
|
user = User.create(:name => 'John')
|
31
31
|
user.id.should be_instance_of(BSON::ObjectId)
|
32
|
-
key = user.
|
32
|
+
key = user.adapter.client.find_one(user.id)['_id']
|
33
33
|
key.should be_instance_of(BSON::ObjectId)
|
34
34
|
user.id.should == key
|
35
35
|
end
|
@@ -5,7 +5,6 @@ describe Toy::Mongo::Querying do
|
|
5
5
|
|
6
6
|
before(:each) do
|
7
7
|
User.send(:include, CallbacksHelper)
|
8
|
-
User.identity_map_off
|
9
8
|
User.attribute(:name, String)
|
10
9
|
User.attribute(:bio, String)
|
11
10
|
end
|
@@ -36,16 +35,16 @@ describe Toy::Mongo::Querying do
|
|
36
35
|
@user.name.should == 'Frank'
|
37
36
|
end
|
38
37
|
|
39
|
-
it "defaults to
|
40
|
-
@user.
|
38
|
+
it "defaults to adapter's :safe option" do
|
39
|
+
@user.adapter.client.should_receive(:update).with(kind_of(Hash), kind_of(Hash), :safe => nil)
|
41
40
|
@user.atomic_update('$set' => {'name' => 'Frank'})
|
42
41
|
|
43
|
-
User.
|
44
|
-
@user.
|
42
|
+
User.adapter(:mongo, STORE, :safe => false)
|
43
|
+
@user.adapter.client.should_receive(:update).with(kind_of(Hash), kind_of(Hash), :safe => false)
|
45
44
|
@user.atomic_update('$set' => {'name' => 'Frank'})
|
46
45
|
|
47
|
-
User.
|
48
|
-
@user.
|
46
|
+
User.adapter(:mongo, STORE, :safe => true)
|
47
|
+
@user.adapter.client.should_receive(:update).with(kind_of(Hash), kind_of(Hash), :safe => true)
|
49
48
|
@user.atomic_update('$set' => {'name' => 'Frank'})
|
50
49
|
end
|
51
50
|
|
@@ -56,13 +55,13 @@ describe Toy::Mongo::Querying do
|
|
56
55
|
end
|
57
56
|
|
58
57
|
context "with :safe option" do
|
59
|
-
it "overrides
|
60
|
-
User.
|
61
|
-
@user.
|
58
|
+
it "overrides adapter's :safe option" do
|
59
|
+
User.adapter(:mongo, STORE, :safe => false)
|
60
|
+
@user.adapter.client.should_receive(:update).with(kind_of(Hash), kind_of(Hash), :safe => true)
|
62
61
|
@user.atomic_update({'$set' => {'name' => 'Frank'}}, :safe => true)
|
63
62
|
|
64
|
-
User.
|
65
|
-
@user.
|
63
|
+
User.adapter(:mongo, STORE, :safe => true)
|
64
|
+
@user.adapter.client.should_receive(:update).with(kind_of(Hash), kind_of(Hash), :safe => false)
|
66
65
|
@user.atomic_update({'$set' => {'name' => 'Frank'}}, :safe => false)
|
67
66
|
end
|
68
67
|
end
|
@@ -137,15 +136,15 @@ describe Toy::Mongo::Querying do
|
|
137
136
|
it "only persists changes" do
|
138
137
|
query = {'_id' => @user.id}
|
139
138
|
update = {'$set' => {'name' => 'Frank'}}
|
140
|
-
@user.
|
139
|
+
@user.adapter.client.should_receive(:update).with(query, update, {:safe => nil})
|
141
140
|
@user.atomic_update_attributes(:name => 'Frank')
|
142
141
|
end
|
143
142
|
|
144
|
-
it "persists changes with safe option from
|
145
|
-
User.
|
143
|
+
it "persists changes with safe option from adapter" do
|
144
|
+
User.adapter(:mongo, STORE, :safe => true)
|
146
145
|
query = {'_id' => @user.id}
|
147
146
|
update = {'$set' => {'name' => 'Frank'}}
|
148
|
-
@user.
|
147
|
+
@user.adapter.client.should_receive(:update).with(query, update, {:safe => true})
|
149
148
|
@user.atomic_update_attributes(:name => 'Frank')
|
150
149
|
end
|
151
150
|
|
data/toystore-mongo.gemspec
CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
|
|
13
13
|
s.description = %q{Mongo integration for Toystore}
|
14
14
|
|
15
15
|
s.add_dependency('plucky', '~> 0.4.1')
|
16
|
-
s.add_dependency('toystore', '~> 0.
|
16
|
+
s.add_dependency('toystore', '~> 0.9.0')
|
17
17
|
s.add_dependency('adapter-mongo', '~> 0.5.3')
|
18
18
|
|
19
19
|
s.files = `git ls-files`.split("\n") - ['specs.watchr']
|
metadata
CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 9
|
9
|
+
- 0
|
10
|
+
version: 0.9.0
|
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-03-14 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: plucky
|
@@ -41,12 +41,12 @@ dependencies:
|
|
41
41
|
requirements:
|
42
42
|
- - ~>
|
43
43
|
- !ruby/object:Gem::Version
|
44
|
-
hash:
|
44
|
+
hash: 59
|
45
45
|
segments:
|
46
46
|
- 0
|
47
|
-
-
|
47
|
+
- 9
|
48
48
|
- 0
|
49
|
-
version: 0.
|
49
|
+
version: 0.9.0
|
50
50
|
type: :runtime
|
51
51
|
version_requirements: *id002
|
52
52
|
- !ruby/object:Gem::Dependency
|