mongo_mapper 0.5.8 → 0.6.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.
Files changed (47) hide show
  1. data/Rakefile +4 -4
  2. data/VERSION +1 -1
  3. data/bin/mmconsole +10 -5
  4. data/lib/mongo_mapper.rb +28 -5
  5. data/lib/mongo_mapper/associations.rb +113 -12
  6. data/lib/mongo_mapper/associations/base.rb +24 -9
  7. data/lib/mongo_mapper/associations/belongs_to_polymorphic_proxy.rb +1 -1
  8. data/lib/mongo_mapper/associations/belongs_to_proxy.rb +1 -1
  9. data/lib/mongo_mapper/associations/many_documents_as_proxy.rb +2 -2
  10. data/lib/mongo_mapper/associations/many_documents_proxy.rb +7 -2
  11. data/lib/mongo_mapper/associations/many_embedded_proxy.rb +22 -36
  12. data/lib/mongo_mapper/associations/proxy.rb +11 -6
  13. data/lib/mongo_mapper/document.rb +37 -21
  14. data/lib/mongo_mapper/embedded_document.rb +32 -18
  15. data/lib/mongo_mapper/finder_options.rb +19 -12
  16. data/lib/mongo_mapper/rails_compatibility/document.rb +4 -0
  17. data/lib/mongo_mapper/rails_compatibility/embedded_document.rb +4 -0
  18. data/lib/mongo_mapper/support.rb +18 -46
  19. data/lib/mongo_mapper/types.rb +64 -0
  20. data/lib/mongo_mapper/validations.rb +13 -43
  21. data/mongo_mapper.gemspec +13 -10
  22. data/test/functional/associations/test_belongs_to_polymorphic_proxy.rb +10 -10
  23. data/test/functional/associations/test_belongs_to_proxy.rb +29 -30
  24. data/test/functional/associations/test_many_documents_as_proxy.rb +13 -12
  25. data/test/functional/associations/test_many_embedded_polymorphic_proxy.rb +34 -34
  26. data/test/functional/associations/test_many_embedded_proxy.rb +69 -74
  27. data/test/functional/associations/test_many_polymorphic_proxy.rb +10 -10
  28. data/test/functional/associations/test_many_proxy.rb +14 -15
  29. data/test/functional/test_associations.rb +4 -4
  30. data/test/functional/test_binary.rb +1 -1
  31. data/test/functional/test_dirty.rb +6 -6
  32. data/test/functional/test_document.rb +76 -69
  33. data/test/functional/test_embedded_document.rb +15 -14
  34. data/test/functional/test_pagination.rb +9 -1
  35. data/test/functional/test_string_id_compatibility.rb +72 -0
  36. data/test/functional/test_validations.rb +56 -7
  37. data/test/models.rb +7 -7
  38. data/test/test_helper.rb +2 -5
  39. data/test/unit/test_association_base.rb +6 -1
  40. data/test/unit/test_document.rb +22 -13
  41. data/test/unit/test_embedded_document.rb +47 -5
  42. data/test/unit/test_finder_options.rb +22 -3
  43. data/test/unit/test_mongo_mapper.rb +65 -0
  44. data/test/unit/test_rails_compatibility.rb +14 -0
  45. data/test/unit/test_support.rb +45 -0
  46. metadata +9 -6
  47. data/test/unit/test_mongomapper.rb +0 -28
@@ -57,9 +57,28 @@ class FinderOptionsTest < Test::Unit::TestCase
57
57
  end
58
58
 
59
59
  should "convert id to _id" do
60
- FinderOptions.new(Room, :id => '1').criteria.should == {
61
- :_id => '1'
62
- }
60
+ id = Mongo::ObjectID.new
61
+ FinderOptions.new(Room, :id => id).criteria.should == {:_id => id}
62
+ end
63
+
64
+ should "make sure that _id's are object ids" do
65
+ id = Mongo::ObjectID.new
66
+ FinderOptions.new(Room, :_id => id.to_s).criteria.should == {:_id => id}
67
+ end
68
+
69
+ should "work fine with _id's that are object ids" do
70
+ id = Mongo::ObjectID.new
71
+ FinderOptions.new(Room, :_id => id).criteria.should == {:_id => id}
72
+ end
73
+
74
+ should "make sure other object id typed keys get converted" do
75
+ id = Mongo::ObjectID.new
76
+ FinderOptions.new(Message, :room_id => id.to_s).criteria.should == {:room_id => id}
77
+ end
78
+
79
+ should "work fine with object ids for object id typed keys" do
80
+ id = Mongo::ObjectID.new
81
+ FinderOptions.new(Message, :room_id => id).criteria.should == {:room_id => id}
63
82
  end
64
83
 
65
84
  should "use $in for arrays" do
@@ -0,0 +1,65 @@
1
+ require 'test_helper'
2
+
3
+ class Address; end
4
+
5
+ class MongoMapperTest < Test::Unit::TestCase
6
+ should "be able to write and read connection" do
7
+ conn = Mongo::Connection.new
8
+ MongoMapper.connection = conn
9
+ MongoMapper.connection.should == conn
10
+ end
11
+
12
+ should "default connection to new mongo ruby driver" do
13
+ MongoMapper.connection = nil
14
+ MongoMapper.connection.should be_instance_of(Mongo::Connection)
15
+ end
16
+
17
+ should "be able to write and read default database" do
18
+ MongoMapper.database = 'test'
19
+ MongoMapper.database.should be_instance_of(Mongo::DB)
20
+ MongoMapper.database.name.should == 'test'
21
+ end
22
+
23
+ should "have document not found error" do
24
+ lambda {
25
+ MongoMapper::DocumentNotFound
26
+ }.should_not raise_error
27
+ end
28
+
29
+ context "use_time_zone?" do
30
+ should "be true if Time.zone set" do
31
+ Time.zone = 'Hawaii'
32
+ MongoMapper.use_time_zone?.should be_true
33
+ Time.zone = nil
34
+ end
35
+
36
+ should "be false if Time.zone not set" do
37
+ MongoMapper.use_time_zone?.should be_false
38
+ end
39
+ end
40
+
41
+ context "time_class" do
42
+ should "be Time.zone if using time zones" do
43
+ Time.zone = 'Hawaii'
44
+ MongoMapper.time_class.should == Time.zone
45
+ Time.zone = nil
46
+ end
47
+
48
+ should "be Time if not using time zones" do
49
+ MongoMapper.time_class.should == Time
50
+ end
51
+ end
52
+
53
+ context "normalize_object_id" do
54
+ should "turn string into object id" do
55
+ id = Mongo::ObjectID.new
56
+ MongoMapper.normalize_object_id(id.to_s).should == id
57
+ end
58
+
59
+ should "leave object id alone" do
60
+ id = Mongo::ObjectID.new
61
+ MongoMapper.normalize_object_id(id).should == id
62
+ end
63
+ end
64
+
65
+ end
@@ -1,6 +1,10 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class TestRailsCompatibility < Test::Unit::TestCase
4
+ class BigStuff
5
+ include MongoMapper::Document
6
+ end
7
+
4
8
  class Item
5
9
  include MongoMapper::EmbeddedDocument
6
10
  key :for_all, String
@@ -31,5 +35,15 @@ class TestRailsCompatibility < Test::Unit::TestCase
31
35
  instance = Item.new
32
36
  instance.new_record?.should == instance.new?
33
37
  end
38
+
39
+ should "implement human_name" do
40
+ Item.human_name.should == 'Item'
41
+ end
42
+ end
43
+
44
+ context "Document" do
45
+ should "implement human_name" do
46
+ BigStuff.human_name.should == 'Big Stuff'
47
+ end
34
48
  end
35
49
  end
@@ -1,6 +1,8 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class SupportTest < Test::Unit::TestCase
4
+ include MongoMapper::Types
5
+
4
6
  context "Array#to_mongo" do
5
7
  should "convert value to_a" do
6
8
  Array.to_mongo([1, 2, 3, 4]).should == [1, 2, 3, 4]
@@ -162,6 +164,29 @@ class SupportTest < Test::Unit::TestCase
162
164
  end
163
165
  end
164
166
 
167
+ context "ObjectId#to_mongo" do
168
+ should "return nil for nil" do
169
+ ObjectId.to_mongo(nil).should be_nil
170
+ end
171
+
172
+ should "return value if object id" do
173
+ id = Mongo::ObjectID.new
174
+ ObjectId.to_mongo(id).should be(id)
175
+ end
176
+
177
+ should "return object id if string" do
178
+ id = Mongo::ObjectID.new
179
+ ObjectId.to_mongo(id.to_s).should be(id)
180
+ end
181
+ end
182
+
183
+ context "ObjectId#from_mongo" do
184
+ should "return value" do
185
+ id = Mongo::ObjectID.new
186
+ ObjectId.from_mongo(id).should == id
187
+ end
188
+ end
189
+
165
190
  context "NilClass#to_mongo" do
166
191
  should "return nil" do
167
192
  nil.to_mongo(nil).should be_nil
@@ -190,6 +215,26 @@ class SupportTest < Test::Unit::TestCase
190
215
  end
191
216
  end
192
217
 
218
+ context "Set#to_mongo" do
219
+ should "convert value to_a" do
220
+ Set.to_mongo(Set.new([1,2,3])).should == [1,2,3]
221
+ end
222
+
223
+ should "convert to empty array if nil" do
224
+ Set.to_mongo(nil).should == []
225
+ end
226
+ end
227
+
228
+ context "Set#from_mongo" do
229
+ should "be a set if array" do
230
+ Set.from_mongo([1,2,3]).should == Set.new([1,2,3])
231
+ end
232
+
233
+ should "be empty set if nil" do
234
+ Set.from_mongo(nil).should == Set.new([])
235
+ end
236
+ end
237
+
193
238
  context "String#to_mongo" do
194
239
  should "convert value to_s" do
195
240
  [21, '21'].each do |value|
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.5.8
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Nunemaker
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-29 00:00:00 -04:00
12
+ date: 2009-11-14 00:00:00 -05:00
13
13
  default_executable: mmconsole
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -40,7 +40,7 @@ dependencies:
40
40
  requirements:
41
41
  - - "="
42
42
  - !ruby/object:Gem::Version
43
- version: 1.8.0
43
+ version: 1.8.1
44
44
  version:
45
45
  - !ruby/object:Gem::Dependency
46
46
  name: jnunemaker-matchy
@@ -80,7 +80,7 @@ dependencies:
80
80
  requirements:
81
81
  - - "="
82
82
  - !ruby/object:Gem::Version
83
- version: 0.9.4
83
+ version: 0.9.8
84
84
  version:
85
85
  description:
86
86
  email: nunemaker@gmail.com
@@ -124,6 +124,7 @@ files:
124
124
  - lib/mongo_mapper/serialization.rb
125
125
  - lib/mongo_mapper/serializers/json_serializer.rb
126
126
  - lib/mongo_mapper/support.rb
127
+ - lib/mongo_mapper/types.rb
127
128
  - lib/mongo_mapper/validations.rb
128
129
  - mongo_mapper.gemspec
129
130
  - specs.watchr
@@ -144,6 +145,7 @@ files:
144
145
  - test/functional/test_logger.rb
145
146
  - test/functional/test_pagination.rb
146
147
  - test/functional/test_rails_compatibility.rb
148
+ - test/functional/test_string_id_compatibility.rb
147
149
  - test/functional/test_validations.rb
148
150
  - test/models.rb
149
151
  - test/support/custom_matchers.rb
@@ -156,7 +158,7 @@ files:
156
158
  - test/unit/test_embedded_document.rb
157
159
  - test/unit/test_finder_options.rb
158
160
  - test/unit/test_key.rb
159
- - test/unit/test_mongomapper.rb
161
+ - test/unit/test_mongo_mapper.rb
160
162
  - test/unit/test_observing.rb
161
163
  - test/unit/test_pagination.rb
162
164
  - test/unit/test_rails_compatibility.rb
@@ -209,6 +211,7 @@ test_files:
209
211
  - test/functional/test_logger.rb
210
212
  - test/functional/test_pagination.rb
211
213
  - test/functional/test_rails_compatibility.rb
214
+ - test/functional/test_string_id_compatibility.rb
212
215
  - test/functional/test_validations.rb
213
216
  - test/models.rb
214
217
  - test/support/custom_matchers.rb
@@ -221,7 +224,7 @@ test_files:
221
224
  - test/unit/test_embedded_document.rb
222
225
  - test/unit/test_finder_options.rb
223
226
  - test/unit/test_key.rb
224
- - test/unit/test_mongomapper.rb
227
+ - test/unit/test_mongo_mapper.rb
225
228
  - test/unit/test_observing.rb
226
229
  - test/unit/test_pagination.rb
227
230
  - test/unit/test_rails_compatibility.rb
@@ -1,28 +0,0 @@
1
- require 'test_helper'
2
-
3
- class Address; end
4
-
5
- class MongoMapperTest < Test::Unit::TestCase
6
- should "be able to write and read connection" do
7
- conn = Mongo::Connection.new
8
- MongoMapper.connection = conn
9
- MongoMapper.connection.should == conn
10
- end
11
-
12
- should "default connection to new mongo ruby driver" do
13
- MongoMapper.connection = nil
14
- MongoMapper.connection.should be_instance_of(Mongo::Connection)
15
- end
16
-
17
- should "be able to write and read default database" do
18
- MongoMapper.database = DefaultDatabase
19
- MongoMapper.database.should be_instance_of(Mongo::DB)
20
- MongoMapper.database.name.should == DefaultDatabase
21
- end
22
-
23
- should "have document not found error" do
24
- lambda {
25
- MongoMapper::DocumentNotFound
26
- }.should_not raise_error
27
- end
28
- end