mongo_mapper-unstable 2009.11.8 → 2009.11.18

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. data/Rakefile +3 -3
  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/belongs_to_polymorphic_proxy.rb +1 -1
  6. data/lib/mongo_mapper/associations/belongs_to_proxy.rb +1 -1
  7. data/lib/mongo_mapper/associations/many_documents_as_proxy.rb +2 -2
  8. data/lib/mongo_mapper/associations/many_documents_proxy.rb +2 -2
  9. data/lib/mongo_mapper/associations/many_embedded_proxy.rb +2 -1
  10. data/lib/mongo_mapper/document.rb +3 -12
  11. data/lib/mongo_mapper/embedded_document.rb +37 -19
  12. data/lib/mongo_mapper/finder_options.rb +17 -11
  13. data/lib/mongo_mapper/rails_compatibility/document.rb +4 -0
  14. data/lib/mongo_mapper/rails_compatibility/embedded_document.rb +4 -0
  15. data/lib/mongo_mapper/serializers/json_serializer.rb +2 -2
  16. data/lib/mongo_mapper/support.rb +16 -44
  17. data/lib/mongo_mapper/types.rb +64 -0
  18. data/lib/mongo_mapper/validations.rb +1 -1
  19. data/mongo_mapper.gemspec +15 -12
  20. data/test/functional/associations/test_belongs_to_polymorphic_proxy.rb +10 -10
  21. data/test/functional/associations/test_belongs_to_proxy.rb +2 -1
  22. data/test/functional/associations/test_many_documents_as_proxy.rb +13 -12
  23. data/test/functional/associations/test_many_embedded_polymorphic_proxy.rb +34 -34
  24. data/test/functional/associations/test_many_embedded_proxy.rb +22 -22
  25. data/test/functional/associations/test_many_polymorphic_proxy.rb +10 -10
  26. data/test/functional/associations/test_many_proxy.rb +14 -15
  27. data/test/functional/test_associations.rb +4 -4
  28. data/test/functional/test_binary.rb +1 -1
  29. data/test/functional/test_dirty.rb +6 -6
  30. data/test/functional/test_document.rb +64 -65
  31. data/test/functional/test_embedded_document.rb +34 -14
  32. data/test/functional/test_string_id_compatibility.rb +72 -0
  33. data/test/functional/test_validations.rb +1 -1
  34. data/test/models.rb +24 -24
  35. data/test/unit/test_document.rb +7 -4
  36. data/test/unit/test_embedded_document.rb +47 -5
  37. data/test/unit/test_finder_options.rb +22 -3
  38. data/test/unit/test_mongo_mapper.rb +65 -0
  39. data/test/unit/test_rails_compatibility.rb +14 -0
  40. data/test/unit/test_support.rb +45 -0
  41. metadata +8 -5
  42. data/test/unit/test_mongomapper.rb +0 -28
@@ -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-unstable
3
3
  version: !ruby/object:Gem::Version
4
- version: 2009.11.8
4
+ version: 2009.11.18
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-11-08 00:00:00 -05:00
12
+ date: 2009-11-18 00:00:00 -05:00
13
13
  default_executable: mmconsole
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -30,7 +30,7 @@ dependencies:
30
30
  requirements:
31
31
  - - "="
32
32
  - !ruby/object:Gem::Version
33
- version: "0.16"
33
+ version: 0.17.1
34
34
  version:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: jnunemaker-validatable
@@ -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
@@ -200,18 +202,19 @@ test_files:
200
202
  - test/unit/test_dynamic_finder.rb
201
203
  - test/unit/serializers/test_json_serializer.rb
202
204
  - test/unit/test_support.rb
203
- - test/unit/test_mongomapper.rb
204
205
  - test/unit/test_finder_options.rb
205
206
  - test/unit/test_time_zones.rb
206
207
  - test/unit/test_observing.rb
207
208
  - test/unit/test_rails_compatibility.rb
208
209
  - test/unit/test_validations.rb
210
+ - test/unit/test_mongo_mapper.rb
209
211
  - test/unit/test_document.rb
210
212
  - test/unit/test_pagination.rb
211
213
  - test/test_helper.rb
212
214
  - test/support/custom_matchers.rb
213
215
  - test/support/timing.rb
214
216
  - test/functional/test_embedded_document.rb
217
+ - test/functional/test_string_id_compatibility.rb
215
218
  - test/functional/test_associations.rb
216
219
  - test/functional/associations/test_belongs_to_proxy.rb
217
220
  - test/functional/associations/test_many_proxy.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 = '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
- end