toystore-mongo 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -1
- data/lib/toy/extensions/bson_object_id.rb +9 -0
- data/lib/toy/identity/object_id_key_factory.rb +13 -0
- data/lib/toy/mongo/version.rb +1 -1
- data/lib/toy/mongo.rb +1 -1
- data/spec/toy/extensions/bson_object_id_spec.rb +41 -0
- data/spec/toy/identity/object_id_key_factory_spec.rb +37 -0
- data/toystore-mongo.gemspec +2 -2
- metadata +16 -10
data/Gemfile
CHANGED
data/lib/toy/mongo/version.rb
CHANGED
data/lib/toy/mongo.rb
CHANGED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe "BSON::ObjectId.to_store" do
|
4
|
+
it "returns nil if value nil" do
|
5
|
+
BSON::ObjectId.to_store(nil).should be_nil
|
6
|
+
end
|
7
|
+
|
8
|
+
it "returns value if already bson object id" do
|
9
|
+
id = BSON::ObjectId.new
|
10
|
+
BSON::ObjectId.to_store(id).should be(id)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "returns bson object id if string and valid bson object id" do
|
14
|
+
id = BSON::ObjectId.new
|
15
|
+
BSON::ObjectId.to_store(id.to_s).should == id
|
16
|
+
end
|
17
|
+
|
18
|
+
it "returns whatever is passed in if not object id or string version of object id" do
|
19
|
+
BSON::ObjectId.to_store('foo').should == 'foo'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "BSON::ObjectId.from_store" do
|
24
|
+
it "returns nil if value nil" do
|
25
|
+
BSON::ObjectId.from_store(nil).should be_nil
|
26
|
+
end
|
27
|
+
|
28
|
+
it "returns value if already bson object id" do
|
29
|
+
id = BSON::ObjectId.new
|
30
|
+
BSON::ObjectId.from_store(id).should be(id)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "returns bson object id if string and valid bson object id" do
|
34
|
+
id = BSON::ObjectId.new
|
35
|
+
BSON::ObjectId.from_store(id.to_s).should == id
|
36
|
+
end
|
37
|
+
|
38
|
+
it "returns whatever is passed in if not object id or string version of object id" do
|
39
|
+
BSON::ObjectId.from_store('foo').should == 'foo'
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe Toy::Identity::ObjectIdKeyFactory do
|
4
|
+
uses_constants('User')
|
5
|
+
|
6
|
+
it "should use BSON::ObjectId as key_type" do
|
7
|
+
Toy::Identity::ObjectIdKeyFactory.new.key_type.should be(BSON::ObjectId)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should use object id for next key" do
|
11
|
+
key = Toy::Identity::ObjectIdKeyFactory.new.next_key(nil)
|
12
|
+
key.should be_instance_of(BSON::ObjectId)
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "Declaring key to be object_id" do
|
16
|
+
before(:each) do
|
17
|
+
User.key(Toy::Identity::ObjectIdKeyFactory.new)
|
18
|
+
User.attribute(:name, String)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "returns BSON::ObjectId as .key_type" do
|
22
|
+
User.key_type.should be(BSON::ObjectId)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "sets id attribute to BSON::ObjectId type" do
|
26
|
+
User.attributes['id'].type.should be(BSON::ObjectId)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "correctly stores id in database" do
|
30
|
+
user = User.create(:name => 'John')
|
31
|
+
user.id.should be_instance_of(BSON::ObjectId)
|
32
|
+
key = user.store.client.find_one(user.id)['_id']
|
33
|
+
key.should be_instance_of(BSON::ObjectId)
|
34
|
+
user.id.should == key
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/toystore-mongo.gemspec
CHANGED
@@ -12,8 +12,8 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.summary = %q{Mongo integration for Toystore}
|
13
13
|
s.description = %q{Mongo integration for Toystore}
|
14
14
|
|
15
|
-
s.add_dependency('plucky',
|
16
|
-
s.add_dependency('toystore',
|
15
|
+
s.add_dependency('plucky', '~> 0.4.1')
|
16
|
+
s.add_dependency('toystore', '~> 0.8.0')
|
17
17
|
s.add_dependency('adapter-mongo', '~> 0.5.2')
|
18
18
|
|
19
19
|
s.files = `git ls-files`.split("\n") - ['specs.watchr']
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: toystore-mongo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 3
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 7
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.7.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: 2011-
|
18
|
+
date: 2011-06-07 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: plucky
|
@@ -25,12 +25,12 @@ dependencies:
|
|
25
25
|
requirements:
|
26
26
|
- - ~>
|
27
27
|
- !ruby/object:Gem::Version
|
28
|
-
hash:
|
28
|
+
hash: 13
|
29
29
|
segments:
|
30
30
|
- 0
|
31
31
|
- 4
|
32
|
-
-
|
33
|
-
version: 0.4.
|
32
|
+
- 1
|
33
|
+
version: 0.4.1
|
34
34
|
type: :runtime
|
35
35
|
version_requirements: *id001
|
36
36
|
- !ruby/object:Gem::Dependency
|
@@ -41,12 +41,12 @@ dependencies:
|
|
41
41
|
requirements:
|
42
42
|
- - ~>
|
43
43
|
- !ruby/object:Gem::Version
|
44
|
-
hash:
|
44
|
+
hash: 63
|
45
45
|
segments:
|
46
46
|
- 0
|
47
|
-
-
|
47
|
+
- 8
|
48
48
|
- 0
|
49
|
-
version: 0.
|
49
|
+
version: 0.8.0
|
50
50
|
type: :runtime
|
51
51
|
version_requirements: *id002
|
52
52
|
- !ruby/object:Gem::Dependency
|
@@ -80,6 +80,8 @@ files:
|
|
80
80
|
- LICENSE
|
81
81
|
- README.rdoc
|
82
82
|
- Rakefile
|
83
|
+
- lib/toy/extensions/bson_object_id.rb
|
84
|
+
- lib/toy/identity/object_id_key_factory.rb
|
83
85
|
- lib/toy/mongo.rb
|
84
86
|
- lib/toy/mongo/querying.rb
|
85
87
|
- lib/toy/mongo/version.rb
|
@@ -87,6 +89,8 @@ files:
|
|
87
89
|
- spec/helper.rb
|
88
90
|
- spec/spec.opts
|
89
91
|
- spec/support/constants.rb
|
92
|
+
- spec/toy/extensions/bson_object_id_spec.rb
|
93
|
+
- spec/toy/identity/object_id_key_factory_spec.rb
|
90
94
|
- spec/toy/mongo/querying_spec.rb
|
91
95
|
- spec/toy/mongo_spec.rb
|
92
96
|
- toystore-mongo.gemspec
|
@@ -127,6 +131,8 @@ test_files:
|
|
127
131
|
- spec/helper.rb
|
128
132
|
- spec/spec.opts
|
129
133
|
- spec/support/constants.rb
|
134
|
+
- spec/toy/extensions/bson_object_id_spec.rb
|
135
|
+
- spec/toy/identity/object_id_key_factory_spec.rb
|
130
136
|
- spec/toy/mongo/querying_spec.rb
|
131
137
|
- spec/toy/mongo_spec.rb
|
132
138
|
has_rdoc:
|