mongo_mapper 0.6.2 → 0.6.3
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/VERSION +1 -1
- data/lib/mongo_mapper/associations/many_embedded_proxy.rb +1 -1
- data/lib/mongo_mapper/embedded_document.rb +2 -2
- data/lib/mongo_mapper/support.rb +7 -0
- data/mongo_mapper.gemspec +1 -1
- data/test/functional/associations/test_many_embedded_proxy.rb +4 -2
- data/test/functional/associations/test_many_proxy.rb +5 -1
- data/test/functional/test_document.rb +3 -7
- data/test/unit/test_embedded_document.rb +12 -12
- data/test/unit/test_support.rb +8 -0
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.6.
|
1
|
+
0.6.3
|
@@ -219,7 +219,7 @@ module MongoMapper
|
|
219
219
|
end
|
220
220
|
|
221
221
|
def to_param
|
222
|
-
id
|
222
|
+
id.to_s
|
223
223
|
end
|
224
224
|
|
225
225
|
def attributes=(attrs)
|
@@ -292,7 +292,7 @@ module MongoMapper
|
|
292
292
|
end
|
293
293
|
|
294
294
|
def id
|
295
|
-
read_attribute(:_id)
|
295
|
+
read_attribute(:_id)
|
296
296
|
end
|
297
297
|
|
298
298
|
def id=(value)
|
data/lib/mongo_mapper/support.rb
CHANGED
data/mongo_mapper.gemspec
CHANGED
@@ -138,8 +138,10 @@ class ManyEmbeddedProxyTest < Test::Unit::TestCase
|
|
138
138
|
|
139
139
|
should "allow finding by id" do
|
140
140
|
sparky = Pet.new(:name => "Sparky", :species => "Dog")
|
141
|
-
meg
|
142
|
-
|
141
|
+
meg = Person.new(:name => "Meg", :pets => [sparky])
|
142
|
+
|
143
|
+
meg.pets.find(sparky._id).should == sparky # oid
|
144
|
+
meg.pets.find(sparky.id.to_s).should == sparky # string
|
143
145
|
end
|
144
146
|
|
145
147
|
context "extending the association" do
|
@@ -365,7 +365,11 @@ class ManyProxyTest < Test::Unit::TestCase
|
|
365
365
|
status3 = Status.new(:name => "Closed")
|
366
366
|
project.statuses = [status1, status2, status3]
|
367
367
|
project.save
|
368
|
-
|
368
|
+
|
369
|
+
open_statuses = project.statuses.open
|
370
|
+
open_statuses.should include(status1)
|
371
|
+
open_statuses.should include(status2)
|
372
|
+
open_statuses.should_not include(status3)
|
369
373
|
end
|
370
374
|
|
371
375
|
should "work using many's :extend option" do
|
@@ -172,9 +172,7 @@ class DocumentTest < Test::Unit::TestCase
|
|
172
172
|
end
|
173
173
|
|
174
174
|
should "automatically set id" do
|
175
|
-
@doc_instance.id.
|
176
|
-
@doc_instance.id.size.should == 24
|
177
|
-
@doc_instance.id.should be_instance_of(String)
|
175
|
+
@doc_instance.id.should be_instance_of(Mongo::ObjectID)
|
178
176
|
@doc_instance._id.should be_instance_of(Mongo::ObjectID)
|
179
177
|
end
|
180
178
|
|
@@ -777,8 +775,7 @@ class DocumentTest < Test::Unit::TestCase
|
|
777
775
|
end
|
778
776
|
|
779
777
|
should "assign an id for the document" do
|
780
|
-
@doc.id.
|
781
|
-
@doc.id.size.should == 24
|
778
|
+
@doc.id.should be_instance_of(Mongo::ObjectID)
|
782
779
|
end
|
783
780
|
|
784
781
|
should "save attributes" do
|
@@ -858,8 +855,7 @@ class DocumentTest < Test::Unit::TestCase
|
|
858
855
|
end
|
859
856
|
|
860
857
|
should "assign an id for the document" do
|
861
|
-
@doc.id.
|
862
|
-
@doc.id.size.should == 24
|
858
|
+
@doc.id.should be_instance_of(Mongo::ObjectID)
|
863
859
|
end
|
864
860
|
|
865
861
|
should "save attributes" do
|
@@ -307,9 +307,9 @@ class EmbeddedDocumentTest < Test::Unit::TestCase
|
|
307
307
|
end
|
308
308
|
end
|
309
309
|
|
310
|
-
should "have to_param that is id" do
|
310
|
+
should "have to_param that is string representation of id" do
|
311
311
|
doc = @document.new
|
312
|
-
doc.to_param.should == doc.id
|
312
|
+
doc.to_param.should == doc.id.to_s
|
313
313
|
doc.to_param.should be_instance_of(String)
|
314
314
|
end
|
315
315
|
|
@@ -323,9 +323,10 @@ class EmbeddedDocumentTest < Test::Unit::TestCase
|
|
323
323
|
@document.keys.keys.should include('_id')
|
324
324
|
end
|
325
325
|
|
326
|
-
should "have id method
|
327
|
-
|
328
|
-
doc
|
326
|
+
should "have id method returns _id" do
|
327
|
+
id = Mongo::ObjectID.new
|
328
|
+
doc = @document.new(:_id => id)
|
329
|
+
doc.id.should == id
|
329
330
|
end
|
330
331
|
|
331
332
|
context "assigning id with _id ObjectId type" do
|
@@ -338,18 +339,13 @@ class EmbeddedDocumentTest < Test::Unit::TestCase
|
|
338
339
|
|
339
340
|
should "convert string object id to mongo object id" do
|
340
341
|
id = Mongo::ObjectID.new
|
341
|
-
doc = @document.new
|
342
|
-
doc.id = id.to_s
|
342
|
+
doc = @document.new(:id => id.to_s)
|
343
343
|
doc._id.should == id
|
344
|
-
doc.id.should == id
|
344
|
+
doc.id.should == id
|
345
345
|
doc.using_custom_id?.should be_false
|
346
346
|
end
|
347
347
|
end
|
348
348
|
|
349
|
-
should "have a nil _root_document" do
|
350
|
-
@document.new._root_document.should be_nil
|
351
|
-
end
|
352
|
-
|
353
349
|
context "setting custom id" do
|
354
350
|
should "set _id" do
|
355
351
|
@document.key :_id, String
|
@@ -366,6 +362,10 @@ class EmbeddedDocumentTest < Test::Unit::TestCase
|
|
366
362
|
end
|
367
363
|
end
|
368
364
|
|
365
|
+
should "have a nil _root_document" do
|
366
|
+
@document.new._root_document.should be_nil
|
367
|
+
end
|
368
|
+
|
369
369
|
context "being initialized" do
|
370
370
|
should "accept a hash that sets keys and values" do
|
371
371
|
doc = @document.new(:name => 'John', :age => 23)
|
data/test/unit/test_support.rb
CHANGED
@@ -331,4 +331,12 @@ class SupportTest < Test::Unit::TestCase
|
|
331
331
|
Time.zone = nil
|
332
332
|
end
|
333
333
|
end
|
334
|
+
|
335
|
+
context "Mongo::ObjectID.to_json" do
|
336
|
+
should "convert object id to string" do
|
337
|
+
id = Mongo::ObjectID.new
|
338
|
+
id.to_json.should == id.to_s
|
339
|
+
end
|
340
|
+
end
|
341
|
+
|
334
342
|
end
|