mongo_mapper 0.12.0 → 0.13.0.beta1

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 (154) hide show
  1. checksums.yaml +7 -0
  2. data/README.rdoc +35 -13
  3. data/bin/mmconsole +1 -1
  4. data/lib/mongo_mapper.rb +4 -0
  5. data/lib/mongo_mapper/connection.rb +17 -6
  6. data/lib/mongo_mapper/document.rb +1 -0
  7. data/lib/mongo_mapper/exceptions.rb +4 -1
  8. data/lib/mongo_mapper/extensions/binary.rb +1 -1
  9. data/lib/mongo_mapper/extensions/boolean.rb +20 -23
  10. data/lib/mongo_mapper/extensions/date.rb +3 -3
  11. data/lib/mongo_mapper/extensions/integer.rb +5 -1
  12. data/lib/mongo_mapper/extensions/kernel.rb +2 -0
  13. data/lib/mongo_mapper/extensions/ordered_hash.rb +23 -0
  14. data/lib/mongo_mapper/extensions/string.rb +2 -2
  15. data/lib/mongo_mapper/extensions/time.rb +7 -5
  16. data/lib/mongo_mapper/middleware/identity_map.rb +3 -4
  17. data/lib/mongo_mapper/plugins.rb +1 -1
  18. data/lib/mongo_mapper/plugins/associations.rb +11 -5
  19. data/lib/mongo_mapper/plugins/associations/base.rb +5 -3
  20. data/lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb +0 -0
  21. data/lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb +8 -8
  22. data/lib/mongo_mapper/plugins/associations/collection.rb +2 -0
  23. data/lib/mongo_mapper/plugins/associations/many_documents_proxy.rb +32 -7
  24. data/lib/mongo_mapper/plugins/associations/many_embedded_proxy.rb +2 -2
  25. data/lib/mongo_mapper/plugins/associations/one_proxy.rb +12 -12
  26. data/lib/mongo_mapper/plugins/associations/proxy.rb +5 -1
  27. data/lib/mongo_mapper/plugins/associations/single_association.rb +6 -6
  28. data/lib/mongo_mapper/plugins/clone.rb +4 -2
  29. data/lib/mongo_mapper/plugins/dirty.rb +22 -21
  30. data/lib/mongo_mapper/plugins/document.rb +4 -4
  31. data/lib/mongo_mapper/plugins/dumpable.rb +22 -0
  32. data/lib/mongo_mapper/plugins/embedded_callbacks.rb +58 -9
  33. data/lib/mongo_mapper/plugins/identity_map.rb +42 -32
  34. data/lib/mongo_mapper/plugins/keys.rb +133 -54
  35. data/lib/mongo_mapper/plugins/keys/key.rb +68 -22
  36. data/lib/mongo_mapper/plugins/modifiers.rb +26 -19
  37. data/lib/mongo_mapper/plugins/persistence.rb +15 -5
  38. data/lib/mongo_mapper/plugins/querying.rb +15 -40
  39. data/lib/mongo_mapper/plugins/querying/{decorator.rb → decorated_plucky_query.rb} +24 -4
  40. data/lib/mongo_mapper/plugins/rails.rb +22 -2
  41. data/lib/mongo_mapper/plugins/safe.rb +8 -5
  42. data/lib/mongo_mapper/plugins/sci.rb +26 -4
  43. data/lib/mongo_mapper/plugins/scopes.rb +5 -4
  44. data/lib/mongo_mapper/plugins/timestamps.rb +11 -4
  45. data/lib/mongo_mapper/plugins/validations.rb +1 -1
  46. data/lib/mongo_mapper/utils.rb +12 -0
  47. data/lib/mongo_mapper/version.rb +1 -1
  48. data/lib/rails/generators/mongo_mapper/config/config_generator.rb +20 -7
  49. data/lib/rails/generators/mongo_mapper/config/templates/mongo.yml +6 -0
  50. data/lib/rails/generators/mongo_mapper/model/model_generator.rb +18 -1
  51. data/lib/rails/generators/mongo_mapper/model/templates/model.rb +9 -5
  52. data/{test/functional/test_accessible.rb → spec/functional/accessible_spec.rb} +29 -29
  53. data/{test/functional/associations/test_belongs_to_polymorphic_proxy.rb → spec/functional/associations/belongs_to_polymorphic_proxy_spec.rb} +10 -10
  54. data/{test/functional/associations/test_belongs_to_proxy.rb → spec/functional/associations/belongs_to_proxy_spec.rb} +82 -64
  55. data/{test/functional/associations/test_in_array_proxy.rb → spec/functional/associations/in_array_proxy_spec.rb} +68 -68
  56. data/{test/functional/associations/test_many_documents_as_proxy.rb → spec/functional/associations/many_documents_as_proxy_spec.rb} +37 -38
  57. data/{test/functional/associations/test_many_documents_proxy.rb → spec/functional/associations/many_documents_proxy_spec.rb} +233 -146
  58. data/{test/functional/associations/test_many_embedded_polymorphic_proxy.rb → spec/functional/associations/many_embedded_polymorphic_proxy_spec.rb} +19 -20
  59. data/{test/functional/associations/test_many_embedded_proxy.rb → spec/functional/associations/many_embedded_proxy_spec.rb} +23 -24
  60. data/{test/functional/associations/test_many_polymorphic_proxy.rb → spec/functional/associations/many_polymorphic_proxy_spec.rb} +45 -46
  61. data/{test/functional/associations/test_one_as_proxy.rb → spec/functional/associations/one_as_proxy_spec.rb} +75 -77
  62. data/{test/functional/associations/test_one_embedded_polymorphic_proxy.rb → spec/functional/associations/one_embedded_polymorphic_proxy_spec.rb} +31 -32
  63. data/{test/functional/associations/test_one_embedded_proxy.rb → spec/functional/associations/one_embedded_proxy_spec.rb} +10 -10
  64. data/{test/functional/associations/test_one_proxy.rb → spec/functional/associations/one_proxy_spec.rb} +125 -102
  65. data/spec/functional/associations_spec.rb +48 -0
  66. data/{test/functional/test_binary.rb → spec/functional/binary_spec.rb} +6 -6
  67. data/spec/functional/caching_spec.rb +75 -0
  68. data/{test/functional/test_callbacks.rb → spec/functional/callbacks_spec.rb} +84 -26
  69. data/{test/functional/test_dirty.rb → spec/functional/dirty_spec.rb} +57 -42
  70. data/{test/functional/test_document.rb → spec/functional/document_spec.rb} +52 -52
  71. data/spec/functional/dumpable_spec.rb +24 -0
  72. data/{test/functional/test_dynamic_querying.rb → spec/functional/dynamic_querying_spec.rb} +14 -14
  73. data/{test/functional/test_embedded_document.rb → spec/functional/embedded_document_spec.rb} +51 -42
  74. data/{test/functional/test_equality.rb → spec/functional/equality_spec.rb} +4 -4
  75. data/spec/functional/extensions_spec.rb +16 -0
  76. data/{test/functional/test_identity_map.rb → spec/functional/identity_map_spec.rb} +73 -61
  77. data/spec/functional/indexes_spec.rb +48 -0
  78. data/spec/functional/keys_spec.rb +224 -0
  79. data/{test/functional/test_logger.rb → spec/functional/logger_spec.rb} +6 -6
  80. data/spec/functional/modifiers_spec.rb +550 -0
  81. data/spec/functional/pagination_spec.rb +89 -0
  82. data/spec/functional/protected_spec.rb +199 -0
  83. data/spec/functional/querying_spec.rb +1003 -0
  84. data/spec/functional/rails_spec.rb +55 -0
  85. data/spec/functional/safe_spec.rb +163 -0
  86. data/{test/functional/test_sci.rb → spec/functional/sci_spec.rb} +123 -34
  87. data/{test/functional/test_scopes.rb → spec/functional/scopes_spec.rb} +59 -26
  88. data/spec/functional/timestamps_spec.rb +97 -0
  89. data/{test/functional/test_touch.rb → spec/functional/touch_spec.rb} +13 -13
  90. data/spec/functional/userstamps_spec.rb +46 -0
  91. data/{test/functional/test_validations.rb → spec/functional/validations_spec.rb} +64 -64
  92. data/spec/spec_helper.rb +81 -0
  93. data/spec/support/matchers.rb +24 -0
  94. data/{test → spec/support}/models.rb +1 -6
  95. data/spec/unit/associations/base_spec.rb +146 -0
  96. data/spec/unit/associations/belongs_to_association_spec.rb +30 -0
  97. data/spec/unit/associations/many_association_spec.rb +64 -0
  98. data/spec/unit/associations/one_association_spec.rb +48 -0
  99. data/{test/unit/associations/test_proxy.rb → spec/unit/associations/proxy_spec.rb} +21 -21
  100. data/{test/unit/test_clone.rb → spec/unit/clone_spec.rb} +21 -11
  101. data/spec/unit/config_generator_spec.rb +24 -0
  102. data/{test/unit/test_document.rb → spec/unit/document_spec.rb} +42 -42
  103. data/{test/unit/test_dynamic_finder.rb → spec/unit/dynamic_finder_spec.rb} +28 -28
  104. data/{test/unit/test_embedded_document.rb → spec/unit/embedded_document_spec.rb} +102 -108
  105. data/{test/unit/test_equality.rb → spec/unit/equality_spec.rb} +7 -7
  106. data/{test/unit/test_exceptions.rb → spec/unit/exceptions_spec.rb} +3 -3
  107. data/{test/unit/test_extensions.rb → spec/unit/extensions_spec.rb} +85 -71
  108. data/spec/unit/identity_map_middleware_spec.rb +134 -0
  109. data/{test/unit/test_inspect.rb → spec/unit/inspect_spec.rb} +8 -8
  110. data/{test/unit/test_key.rb → spec/unit/key_spec.rb} +82 -52
  111. data/spec/unit/keys_spec.rb +155 -0
  112. data/spec/unit/model_generator_spec.rb +47 -0
  113. data/spec/unit/mongo_mapper_spec.rb +184 -0
  114. data/spec/unit/pagination_spec.rb +11 -0
  115. data/{test/unit/test_plugins.rb → spec/unit/plugins_spec.rb} +14 -14
  116. data/spec/unit/rails_compatibility_spec.rb +40 -0
  117. data/{test/unit/test_rails_reflect_on_association.rb → spec/unit/rails_reflect_on_association_spec.rb} +9 -9
  118. data/{test/unit/test_rails.rb → spec/unit/rails_spec.rb} +31 -31
  119. data/spec/unit/serialization_spec.rb +169 -0
  120. data/spec/unit/serializers/json_serializer_spec.rb +218 -0
  121. data/spec/unit/serializers/xml_serializer_spec.rb +198 -0
  122. data/{test/unit/test_time_zones.rb → spec/unit/time_zones_spec.rb} +8 -8
  123. data/{test/unit/test_translation.rb → spec/unit/translation_spec.rb} +6 -6
  124. data/{test/unit/test_validations.rb → spec/unit/validations_spec.rb} +72 -59
  125. metadata +199 -179
  126. data/test/_NOTE_ON_TESTING +0 -1
  127. data/test/functional/test_associations.rb +0 -46
  128. data/test/functional/test_caching.rb +0 -77
  129. data/test/functional/test_indexes.rb +0 -50
  130. data/test/functional/test_modifiers.rb +0 -537
  131. data/test/functional/test_pagination.rb +0 -91
  132. data/test/functional/test_protected.rb +0 -201
  133. data/test/functional/test_querying.rb +0 -935
  134. data/test/functional/test_safe.rb +0 -76
  135. data/test/functional/test_timestamps.rb +0 -62
  136. data/test/functional/test_userstamps.rb +0 -44
  137. data/test/support/railtie.rb +0 -4
  138. data/test/support/railtie/autoloaded.rb +0 -2
  139. data/test/support/railtie/not_autoloaded.rb +0 -3
  140. data/test/support/railtie/parent.rb +0 -3
  141. data/test/test_active_model_lint.rb +0 -18
  142. data/test/test_helper.rb +0 -93
  143. data/test/unit/associations/test_base.rb +0 -146
  144. data/test/unit/associations/test_belongs_to_association.rb +0 -29
  145. data/test/unit/associations/test_many_association.rb +0 -63
  146. data/test/unit/associations/test_one_association.rb +0 -47
  147. data/test/unit/serializers/test_json_serializer.rb +0 -216
  148. data/test/unit/serializers/test_xml_serializer.rb +0 -196
  149. data/test/unit/test_identity_map_middleware.rb +0 -132
  150. data/test/unit/test_keys.rb +0 -65
  151. data/test/unit/test_mongo_mapper.rb +0 -157
  152. data/test/unit/test_pagination.rb +0 -11
  153. data/test/unit/test_rails_compatibility.rb +0 -38
  154. data/test/unit/test_serialization.rb +0 -166
@@ -1,8 +1,8 @@
1
- require 'test_helper'
1
+ require 'spec_helper'
2
2
 
3
- class EqualityTest < Test::Unit::TestCase
3
+ describe "Equality" do
4
4
  context "Case equality" do
5
- setup do
5
+ before do
6
6
  @klass = Class.new do
7
7
  include MongoMapper::Plugins::Equality
8
8
  end
@@ -19,19 +19,19 @@ class EqualityTest < Test::Unit::TestCase
19
19
  end
20
20
  end
21
21
 
22
- should "work with regular instance" do
22
+ it "should work with regular instance" do
23
23
  @klass.should === @klass.new
24
24
  end
25
25
 
26
- should "work with instances of subclasses" do
26
+ it "should work with instances of subclasses" do
27
27
  @klass.should === @subklass.new
28
28
  end
29
29
 
30
- should "work with a faker class" do
30
+ it "should work with a faker class" do
31
31
  @klass.should === @faker.new(@klass.new)
32
32
  end
33
33
 
34
- should "not work with other instances" do
34
+ it "should not work with other instances" do
35
35
  @klass.should_not === 1
36
36
  end
37
37
  end
@@ -1,8 +1,8 @@
1
- require 'test_helper'
1
+ require 'spec_helper'
2
2
 
3
- class ExtensionsTest < Test::Unit::TestCase
3
+ describe "Extensions" do
4
4
  context "DocumentNotValid" do
5
- should "have document reader method" do
5
+ it "should have document reader method" do
6
6
  doc_class = Doc()
7
7
  instance = doc_class.new
8
8
  exception = MongoMapper::DocumentNotValid.new(instance)
@@ -1,8 +1,8 @@
1
- require 'test_helper'
1
+ require 'spec_helper'
2
2
 
3
- class SupportTest < Test::Unit::TestCase
3
+ describe "Support" do
4
4
  context "Array.to_mongo" do
5
- should "convert value to_a" do
5
+ it "should convert value to_a" do
6
6
  Array.to_mongo([1, 2, 3, 4]).should == [1, 2, 3, 4]
7
7
  Array.to_mongo('1').should == ['1']
8
8
  Array.to_mongo({'1' => '2', '3' => '4'}).should include(['1', '2'], ['3', '4'])
@@ -10,46 +10,46 @@ class SupportTest < Test::Unit::TestCase
10
10
  end
11
11
 
12
12
  context "Array.from_mongo" do
13
- should "be array if array" do
13
+ it "should be array if array" do
14
14
  Array.from_mongo([1, 2]).should == [1, 2]
15
15
  end
16
16
 
17
- should "be empty array if nil" do
17
+ it "should be empty array if nil" do
18
18
  Array.from_mongo(nil).should == []
19
19
  end
20
20
  end
21
21
 
22
22
  context "Binary.to_mongo" do
23
- should "convert to binary if not binary" do
23
+ it "should convert to binary if not binary" do
24
24
  Binary.to_mongo('asdfsadasdfs').is_a?(BSON::Binary).should be_true
25
25
  end
26
26
 
27
- should "be binary if binary" do
27
+ it "should be binary if binary" do
28
28
  Binary.to_mongo(BSON::Binary.new('asdfsadasdfs')).is_a?(BSON::Binary).should be_true
29
29
  end
30
30
 
31
- should "be nil if nil" do
31
+ it "should be nil if nil" do
32
32
  Binary.to_mongo(nil).should be_nil
33
33
  end
34
34
  end
35
35
 
36
36
  context "Binary.from_mongo" do
37
- should "return value" do
37
+ it "should return value" do
38
38
  binary = BSON::Binary.new('asdfasdfasdf')
39
39
  Binary.from_mongo(binary).to_s.should == binary.to_s
40
40
  end
41
41
  end
42
42
 
43
43
  context "Boolean.to_mongo" do
44
- should "be true for true" do
44
+ it "should be true for true" do
45
45
  Boolean.to_mongo(true).should be_true
46
46
  end
47
47
 
48
- should "be false for false" do
48
+ it "should be false for false" do
49
49
  Boolean.to_mongo(false).should be_false
50
50
  end
51
51
 
52
- should "handle odd assortment of other values" do
52
+ it "should handle odd assortment of other values" do
53
53
  Boolean.to_mongo('true').should be_true
54
54
  Boolean.to_mongo('t').should be_true
55
55
  Boolean.to_mongo('1').should be_true
@@ -61,27 +61,27 @@ class SupportTest < Test::Unit::TestCase
61
61
  Boolean.to_mongo(0).should be_false
62
62
  end
63
63
 
64
- should "be nil for nil" do
64
+ it "should be nil for nil" do
65
65
  Boolean.to_mongo(nil).should be_nil
66
66
  end
67
67
  end
68
68
 
69
69
  context "Boolean.from_mongo" do
70
- should "be true for true" do
70
+ it "should be true for true" do
71
71
  Boolean.from_mongo(true).should be_true
72
72
  end
73
73
 
74
- should "be false for false" do
74
+ it "should be false for false" do
75
75
  Boolean.from_mongo(false).should be_false
76
76
  end
77
77
 
78
- should "be nil for nil" do
78
+ it "should be nil for nil" do
79
79
  Boolean.from_mongo(nil).should be_nil
80
80
  end
81
81
  end
82
82
 
83
83
  context "Date.to_mongo" do
84
- should "be time if string" do
84
+ it "should be time if string" do
85
85
  date = Date.to_mongo('2009-10-01')
86
86
  date.should == Time.utc(2009, 10, 1)
87
87
  date.should == date
@@ -90,25 +90,25 @@ class SupportTest < Test::Unit::TestCase
90
90
  date.year.should == 2009
91
91
  end
92
92
 
93
- should "be time if date" do
93
+ it "should be time if date" do
94
94
  Date.to_mongo(Date.new(2009, 10, 1)).should == Time.utc(2009, 10, 1)
95
95
  end
96
96
 
97
- should "be date if time" do
97
+ it "should be date if time" do
98
98
  Date.to_mongo(Time.parse("2009-10-1T12:30:00")).should == Time.utc(2009, 10, 1)
99
99
  end
100
100
 
101
- should "be nil if bogus string" do
101
+ it "should be nil if bogus string" do
102
102
  Date.to_mongo('jdsafop874').should be_nil
103
103
  end
104
104
 
105
- should "be nil if empty string" do
105
+ it "should be nil if empty string" do
106
106
  Date.to_mongo('').should be_nil
107
107
  end
108
108
  end
109
109
 
110
110
  context "Date.from_mongo" do
111
- should "be date if date" do
111
+ it "should be date if date" do
112
112
  date = Date.new(2009, 10, 1)
113
113
  from_date = Date.from_mongo(date)
114
114
  from_date.should == date
@@ -117,40 +117,40 @@ class SupportTest < Test::Unit::TestCase
117
117
  from_date.year.should == 2009
118
118
  end
119
119
 
120
- should "be date if time" do
120
+ it "should be date if time" do
121
121
  time = Time.now
122
122
  Date.from_mongo(time).should == time.to_date
123
123
  end
124
124
 
125
- should "be nil if nil" do
125
+ it "should be nil if nil" do
126
126
  Date.from_mongo(nil).should be_nil
127
127
  end
128
128
  end
129
129
 
130
130
  context "Float.to_mongo" do
131
- should "convert value to_f" do
131
+ it "should convert value to_f" do
132
132
  [21, 21.0, '21'].each do |value|
133
133
  Float.to_mongo(value).should == 21.0
134
134
  end
135
135
  end
136
136
 
137
- should "leave nil values nil" do
137
+ it "should leave nil values nil" do
138
138
  Float.to_mongo(nil).should == nil
139
139
  end
140
140
 
141
- should "leave blank values nil" do
141
+ it "should leave blank values nil" do
142
142
  Float.to_mongo('').should == nil
143
143
  end
144
144
  end
145
145
 
146
146
  context "Hash.from_mongo" do
147
- should "convert hash to hash with indifferent access" do
147
+ it "should convert hash to hash with indifferent access" do
148
148
  hash = Hash.from_mongo(:foo => 'bar')
149
149
  hash[:foo].should == 'bar'
150
150
  hash['foo'].should == 'bar'
151
151
  end
152
152
 
153
- should "be hash if nil" do
153
+ it "should be hash if nil" do
154
154
  hash = Hash.from_mongo(nil)
155
155
  hash.should == {}
156
156
  hash.is_a?(HashWithIndifferentAccess).should be_true
@@ -158,20 +158,34 @@ class SupportTest < Test::Unit::TestCase
158
158
  end
159
159
 
160
160
  context "Hash.to_mongo instance method" do
161
- should "have instance method that returns self" do
161
+ it "should have instance method that returns self" do
162
162
  hash = HashWithIndifferentAccess.new('foo' => 'bar')
163
163
  hash.to_mongo.should == {'foo' => 'bar'}
164
164
  end
165
165
  end
166
166
 
167
167
  context "Integer.to_mongo" do
168
- should "convert value to integer" do
168
+ it "should convert value to integer" do
169
169
  [21, 21.0, '21'].each do |value|
170
170
  Integer.to_mongo(value).should == 21
171
171
  end
172
172
  end
173
173
 
174
- should "work fine with big integers" do
174
+ it "should convert value from mongo to integer" do
175
+ [21, 21.0, '21'].each do |value|
176
+ Integer.from_mongo(value).should == 21
177
+ end
178
+ end
179
+
180
+ it "should convert nil to nil" do
181
+ Integer.to_mongo(nil).should be_nil
182
+ end
183
+
184
+ it "should convert nil to nil" do
185
+ Integer.from_mongo(nil).should be_nil
186
+ end
187
+
188
+ it "should work fine with big integers" do
175
189
  [9223372036854775807, '9223372036854775807'].each do |value|
176
190
  Integer.to_mongo(value).should == 9223372036854775807
177
191
  end
@@ -179,40 +193,40 @@ class SupportTest < Test::Unit::TestCase
179
193
  end
180
194
 
181
195
  context "NilClass#from_mongo" do
182
- should "return nil" do
196
+ it "should return nil" do
183
197
  nil.from_mongo(nil).should be_nil
184
198
  end
185
199
  end
186
200
 
187
201
  context "NilClass#to_mongo" do
188
- should "return nil" do
202
+ it "should return nil" do
189
203
  nil.to_mongo(nil).should be_nil
190
204
  end
191
205
  end
192
206
 
193
207
  context "ObjectId#to_mongo" do
194
- should "call class to_mongo with self" do
208
+ it "should call class to_mongo with self" do
195
209
  object = Object.new
196
- object.class.expects(:to_mongo).with(object)
210
+ object.class.should_receive(:to_mongo).with(object)
197
211
  object.to_mongo
198
212
  end
199
213
  end
200
214
 
201
215
  context "ObjectId.to_mongo" do
202
- should "return nil for nil" do
216
+ it "should return nil for nil" do
203
217
  ObjectId.to_mongo(nil).should be_nil
204
218
  end
205
219
 
206
- should "return nil if blank string" do
220
+ it "should return nil if blank string" do
207
221
  ObjectId.to_mongo('').should be_nil
208
222
  end
209
223
 
210
- should "return value if object id" do
224
+ it "should return value if object id" do
211
225
  id = BSON::ObjectId.new
212
226
  ObjectId.to_mongo(id).should be(id)
213
227
  end
214
228
 
215
- should "return value" do
229
+ it "should return value" do
216
230
  Object.to_mongo(21).should == 21
217
231
  Object.to_mongo('21').should == '21'
218
232
  Object.to_mongo(9223372036854775807).should == 9223372036854775807
@@ -220,7 +234,7 @@ class SupportTest < Test::Unit::TestCase
220
234
  end
221
235
 
222
236
  context "ObjectId.from_mongo" do
223
- should "return value" do
237
+ it "should return value" do
224
238
  Object.from_mongo(21).should == 21
225
239
  Object.from_mongo('21').should == '21'
226
240
  Object.from_mongo(9223372036854775807).should == 9223372036854775807
@@ -231,97 +245,97 @@ class SupportTest < Test::Unit::TestCase
231
245
  end
232
246
 
233
247
  context "Set.to_mongo" do
234
- should "convert value to_a" do
248
+ it "should convert value to_a" do
235
249
  Set.to_mongo(Set.new([1,2,3])).should == [1,2,3]
236
250
  end
237
251
 
238
- should "convert to empty array if nil" do
252
+ it "should convert to empty array if nil" do
239
253
  Set.to_mongo(nil).should == []
240
254
  end
241
255
  end
242
256
 
243
257
  context "Set.from_mongo" do
244
- should "be a set if array" do
258
+ it "should be a set if array" do
245
259
  Set.from_mongo([1,2,3]).should == Set.new([1,2,3])
246
260
  end
247
261
 
248
- should "be empty set if nil" do
262
+ it "should be empty set if nil" do
249
263
  Set.from_mongo(nil).should == Set.new([])
250
264
  end
251
265
  end
252
266
 
253
267
  context "String.to_mongo" do
254
- should "convert value to_s" do
268
+ it "should convert value to_s" do
255
269
  [21, '21'].each do |value|
256
270
  String.to_mongo(value).should == '21'
257
271
  end
258
272
  end
259
273
 
260
- should "be nil if nil" do
274
+ it "should be nil if nil" do
261
275
  String.to_mongo(nil).should be_nil
262
276
  end
263
277
  end
264
278
 
265
279
  context "String.from_mongo" do
266
- should "be string if value present" do
280
+ it "should be string if value present" do
267
281
  String.from_mongo('Scotch! Scotch! Scotch!').should == 'Scotch! Scotch! Scotch!'
268
282
  end
269
283
 
270
- should "return nil if nil" do
284
+ it "should return nil if nil" do
271
285
  String.from_mongo(nil).should be_nil
272
286
  end
273
287
 
274
- should "return empty string if blank" do
288
+ it "should return empty string if blank" do
275
289
  String.from_mongo('').should == ''
276
290
  end
277
291
  end
278
292
 
279
293
  context "Time.to_mongo without Time.zone" do
280
- setup do
294
+ before do
281
295
  Time.zone = nil
282
296
  end
283
297
 
284
- should "be time to milliseconds if string" do
285
- Time.to_mongo('2000-01-01 01:01:01.123456').to_f.should be_close(Time.local(2000, 1, 1, 1, 1, 1, 123456).utc.to_f, 0.0000001)
298
+ it "should be time to milliseconds if string" do
299
+ Time.to_mongo('2000-01-01 01:01:01.123456').to_f.should be_within(0.0000001).of(Time.local(2000, 1, 1, 1, 1, 1, 123000).utc.to_f)
286
300
  end
287
301
 
288
- should "be time in utc if time" do
302
+ it "should be time in utc if time" do
289
303
  Time.to_mongo(Time.local(2009, 8, 15, 0, 0, 0)).zone.should == 'UTC'
290
304
  end
291
305
 
292
- should "be nil if blank string" do
306
+ it "should be nil if blank string" do
293
307
  Time.to_mongo('').should be_nil
294
308
  end
295
309
 
296
- should "not be nil if nil" do
310
+ it "should not be nil if nil" do
297
311
  Time.to_mongo(nil).should be_nil
298
312
  end
299
313
  end
300
314
 
301
315
  context "Time.to_mongo with Time.zone" do
302
- should "be time to milliseconds if time" do
316
+ it "should be time to milliseconds if time" do
303
317
  Time.zone = 'Hawaii'
304
- Time.to_mongo(Time.zone.local(2009, 8, 15, 14, 0, 0, 123456)).to_f.should be_close(Time.utc(2009, 8, 16, 0, 0, 0, 123456).to_f, 0.0000001)
318
+ Time.to_mongo(Time.zone.local(2009, 8, 15, 14, 0, 0, 123456)).to_f.should be_within(0.0000001).of(Time.utc(2009, 8, 16, 0, 0, 0, 123000).to_f)
305
319
  Time.zone = nil
306
320
  end
307
321
 
308
- should "be time to milliseconds if string" do
322
+ it "should be time to milliseconds if string" do
309
323
  Time.zone = 'Hawaii'
310
- Time.to_mongo('2009-08-15 14:00:00.123456').to_f.should be_close(Time.utc(2009, 8, 16, 0, 0, 0, 123456).to_f, 0.0000001)
324
+ Time.to_mongo('2009-08-15 14:00:00.123000').to_f.should be_within(0.0000001).of(Time.utc(2009, 8, 16, 0, 0, 0, 123000).to_f)
311
325
  Time.zone = nil
312
326
  end
313
327
 
314
- should "not round up times at the end of the month" do
315
- Time.to_mongo(Time.now.end_of_month).to_f.should be_close(Time.now.end_of_month.utc.to_f, 0.0000001)
328
+ it "should not round up times at the end of the month" do
329
+ Time.to_mongo(Time.now.end_of_month).to_i.should == Time.now.end_of_month.utc.to_i
316
330
  end
317
331
 
318
- should "be nil if blank string" do
332
+ it "should be nil if blank string" do
319
333
  Time.zone = 'Hawaii'
320
334
  Time.to_mongo('').should be_nil
321
335
  Time.zone = nil
322
336
  end
323
337
 
324
- should "be nil if nil" do
338
+ it "should be nil if nil" do
325
339
  Time.zone = 'Hawaii'
326
340
  Time.to_mongo(nil).should be_nil
327
341
  Time.zone = nil
@@ -329,18 +343,18 @@ class SupportTest < Test::Unit::TestCase
329
343
  end
330
344
 
331
345
  context "Time.from_mongo without Time.zone" do
332
- should "be time" do
346
+ it "should be time" do
333
347
  time = Time.now
334
348
  Time.from_mongo(time).should == time
335
349
  end
336
350
 
337
- should "be nil if nil" do
351
+ it "should be nil if nil" do
338
352
  Time.from_mongo(nil).should be_nil
339
353
  end
340
354
  end
341
355
 
342
356
  context "Time.from_mongo with Time.zone" do
343
- should "be time in Time.zone" do
357
+ it "should be time in Time.zone" do
344
358
  Time.zone = 'Hawaii'
345
359
 
346
360
  time = Time.from_mongo(Time.utc(2009, 10, 1))
@@ -350,7 +364,7 @@ class SupportTest < Test::Unit::TestCase
350
364
  Time.zone = nil
351
365
  end
352
366
 
353
- should "be nil if nil" do
367
+ it "should be nil if nil" do
354
368
  Time.zone = 'Hawaii'
355
369
  Time.from_mongo(nil).should be_nil
356
370
  Time.zone = nil
@@ -359,19 +373,19 @@ class SupportTest < Test::Unit::TestCase
359
373
 
360
374
  context "BSON::ObjectId" do
361
375
  context "#as_json" do
362
- should "convert object id to string" do
376
+ it "should convert object id to string" do
363
377
  id = BSON::ObjectId.new
364
378
  id.as_json.should == id.to_s
365
379
  end
366
380
  end
367
381
 
368
382
  context "#to_json" do
369
- should "convert object id to string" do
383
+ it "should convert object id to string" do
370
384
  id = BSON::ObjectId.new
371
385
  id.to_json.should == %Q("#{id}")
372
386
  end
373
387
 
374
- should "support ruby driver syntax also" do
388
+ it "should support ruby driver syntax also" do
375
389
  id = BSON::ObjectId.new
376
390
  id.original_to_json.should == %Q({"$oid": "#{id}"})
377
391
  end