light_mongo 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +5 -1
- data/VERSION +1 -1
- data/integration/support/integration_helper.rb +1 -1
- data/lib/document/persistence.rb +3 -1
- data/lib/document/serialization/serializer.rb +1 -1
- data/spec/document/persistence_spec.rb +32 -10
- data/spec/document/serialization/serializer_spec.rb +1 -1
- metadata +3 -3
data/README.md
CHANGED
@@ -13,6 +13,10 @@ LightMongo is best installed via `gem install light_mongo` and required as norma
|
|
13
13
|
It is dependent on the gem `mongo`, which is the MongoDB Ruby driver.
|
14
14
|
For performance reasons I would recommend also installing `mongo_ext`, the C extensions for the driver.
|
15
15
|
|
16
|
+
Rails
|
17
|
+
-----
|
18
|
+
Please see [LightMongo-Rails][lm_rails] for an ActionPack-compatible bridge.
|
19
|
+
|
16
20
|
The problem
|
17
21
|
-----------
|
18
22
|
Developers occasionally encounter a domain which defies simple modelling in an ActiveRecord relational style, and look to some of the nosql databases for a solution. They find Mongo, a document database, and feel it might provide the flexibility they need. After a bit of research they pick out a persistence library which seems popular and well maintained. It even emulates most of ActiveRecord's behaviour, style and relational philosophy. Great!
|
@@ -131,7 +135,7 @@ Future development
|
|
131
135
|
1. Migrations (e.g. when you rename classes or modify their collection style).
|
132
136
|
2. Some kind of validations, perhaps.
|
133
137
|
|
134
|
-
|
138
|
+
[lm_rails]:http://github.com/elliotcm/light_mongo-rails
|
135
139
|
|
136
140
|
|
137
141
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
data/lib/document/persistence.rb
CHANGED
@@ -89,7 +89,9 @@ module LightMongo
|
|
89
89
|
end
|
90
90
|
|
91
91
|
def find(query=nil)
|
92
|
-
|
92
|
+
return new(collection.find_one(query)) if query.is_a?(Mongo::ObjectID)
|
93
|
+
return new(collection.find_one(Mongo::ObjectID.from_string(query))) if query.is_a? String
|
94
|
+
|
93
95
|
collection.find(query).map{|bson_hash| new(bson_hash)}
|
94
96
|
end
|
95
97
|
|
@@ -27,7 +27,7 @@ module LightMongo
|
|
27
27
|
end
|
28
28
|
|
29
29
|
if object_to_deserialize.has_key?('_embed') and object_to_deserialize['_embed'] == true
|
30
|
-
return Object.const_get(class_name).find(object_to_deserialize['_id'])
|
30
|
+
return Object.const_get(class_name).find(object_to_deserialize['_id'])
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
@@ -160,19 +160,41 @@ describe LightMongo::Document::Persistence do
|
|
160
160
|
end
|
161
161
|
|
162
162
|
describe ".find(query=nil)" do
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
163
|
+
context "when passed a string" do
|
164
|
+
before(:each) do
|
165
|
+
@query = "4bae6ac37bc7693598000001"
|
166
|
+
Mongo::ObjectID.stub!(:from_string).with(@query).and_return(oid = mock(:oid))
|
167
|
+
@test_class_collection.stub!(:find_one).with(oid).and_return(results = mock(:results))
|
168
|
+
TestClass.stub!(:new).with(results).and_return(@TestObject = mock(:TestObject))
|
169
|
+
end
|
170
|
+
|
171
|
+
it "does a single-record lookup using the string as an ID" do
|
172
|
+
TestClass.find(@query).should == @TestObject
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
context "when passed an OID" do
|
177
|
+
before(:each) do
|
178
|
+
@query = Mongo::ObjectID.from_string("4bae6ac37bc7693598000001")
|
179
|
+
@test_class_collection.stub!(:find_one).with(@query).and_return(results = mock(:results))
|
180
|
+
TestClass.stub!(:new).with(results).and_return(@TestObject = mock(:TestObject))
|
181
|
+
end
|
182
|
+
|
183
|
+
it "does a single-record lookup using the ID" do
|
184
|
+
TestClass.find(@query).should == @TestObject
|
185
|
+
end
|
168
186
|
end
|
169
187
|
|
170
|
-
|
171
|
-
|
172
|
-
|
188
|
+
context "when passed anything else" do
|
189
|
+
before(:each) do
|
190
|
+
@query = mock(:query)
|
191
|
+
@test_class_collection.stub!(:find).with(@query).and_return([results = mock(:results)])
|
192
|
+
TestClass.stub!(:new).with(results).and_return(@TestObject = mock(:TestObject))
|
193
|
+
end
|
173
194
|
|
174
|
-
|
175
|
-
|
195
|
+
it "does a multi-record lookup on the query" do
|
196
|
+
TestClass.find(@query).should == [@TestObject]
|
197
|
+
end
|
176
198
|
end
|
177
199
|
end
|
178
200
|
|
@@ -97,7 +97,7 @@ describe Serializer do
|
|
97
97
|
end
|
98
98
|
|
99
99
|
it "recovers the linked document" do
|
100
|
-
TestClass.stub!(:find).with(@id).and_return(
|
100
|
+
TestClass.stub!(:find).with(@id).and_return(test_instance = mock(:test_instance))
|
101
101
|
|
102
102
|
Serializer.deserialize(@object).should == test_instance
|
103
103
|
end
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
7
|
+
- 4
|
8
8
|
- 0
|
9
|
-
version: 0.
|
9
|
+
version: 0.4.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Elliot Crosby-McCullough
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-03-
|
17
|
+
date: 2010-03-28 00:00:00 +00:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|