toystore-mongo 0.6.0 → 0.7.0

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/Gemfile CHANGED
@@ -1,8 +1,10 @@
1
1
  source "http://rubygems.org"
2
2
  gemspec
3
3
 
4
+ require 'plucky/version'
5
+
4
6
  group(:development) do
5
- gem 'bson_ext'
7
+ gem 'bson_ext', Plucky::MongoVersion, :require => false
6
8
  gem 'SystemTimer'
7
9
  gem 'rake', '~> 0.8.7'
8
10
  gem 'rspec', '~> 2.3'
@@ -0,0 +1,9 @@
1
+ class BSON::ObjectId
2
+ def self.to_store(value, *)
3
+ Plucky.to_object_id(value)
4
+ end
5
+
6
+ def self.from_store(value, *args)
7
+ Plucky.to_object_id(value)
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ module Toy
2
+ module Identity
3
+ class ObjectIdKeyFactory < AbstractKeyFactory
4
+ def key_type
5
+ BSON::ObjectId
6
+ end
7
+
8
+ def next_key(object)
9
+ BSON::ObjectId.new
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,5 +1,5 @@
1
1
  module Toy
2
2
  module Mongo
3
- VERSION = '0.6.0'
3
+ VERSION = '0.7.0'
4
4
  end
5
5
  end
data/lib/toy/mongo.rb CHANGED
@@ -1,10 +1,10 @@
1
1
  require 'plucky'
2
2
  require 'toy'
3
+ require 'toy/extensions/bson_object_id'
3
4
  require 'toy/identity/object_id_key_factory'
4
5
  require 'toy/mongo/querying'
5
6
  require 'adapter/mongo'
6
7
 
7
-
8
8
  module Toy
9
9
  module Mongo
10
10
  extend ActiveSupport::Concern
@@ -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
@@ -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', '~> 0.4.0')
16
- s.add_dependency('toystore', '~> 0.7.0')
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: 7
4
+ hash: 3
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 6
8
+ - 7
9
9
  - 0
10
- version: 0.6.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-05-08 00:00:00 Z
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: 15
28
+ hash: 13
29
29
  segments:
30
30
  - 0
31
31
  - 4
32
- - 0
33
- version: 0.4.0
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: 3
44
+ hash: 63
45
45
  segments:
46
46
  - 0
47
- - 7
47
+ - 8
48
48
  - 0
49
- version: 0.7.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: