mongo_mapper 0.6.2 → 0.6.3

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.2
1
+ 0.6.3
@@ -16,7 +16,7 @@ module MongoMapper
16
16
  # TODO: test that both string and oid version work
17
17
  def find(id)
18
18
  load_target
19
- @target.detect { |item| item.id == id || item._id == id }
19
+ @target.detect { |item| item.id.to_s == id || item.id == id }
20
20
  end
21
21
 
22
22
  def <<(*docs)
@@ -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).to_s
295
+ read_attribute(:_id)
296
296
  end
297
297
 
298
298
  def id=(value)
@@ -183,4 +183,11 @@ class Time
183
183
  value
184
184
  end
185
185
  end
186
+ end
187
+
188
+ # TODO: Remove when patch accepted into driver
189
+ class Mongo::ObjectID
190
+ def to_json(options = nil)
191
+ to_s
192
+ end
186
193
  end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mongo_mapper}
8
- s.version = "0.6.2"
8
+ s.version = "0.6.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["John Nunemaker"]
@@ -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 = Person.new(:name => "Meg", :pets => [sparky])
142
- meg.pets.find(sparky._id).should == sparky
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
- project.statuses.open.should == [status1, status2]
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.should_not be_nil
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.should_not be(nil)
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.should_not be(nil)
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 that sets _id" do
327
- doc = @document.new
328
- doc.id.should == doc._id.to_s
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.to_s
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)
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongo_mapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Nunemaker