mongo_mapper 0.12.0 → 0.13.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.rdoc +35 -13
- data/bin/mmconsole +1 -1
- data/lib/mongo_mapper.rb +4 -0
- data/lib/mongo_mapper/connection.rb +17 -6
- data/lib/mongo_mapper/document.rb +1 -0
- data/lib/mongo_mapper/exceptions.rb +4 -1
- data/lib/mongo_mapper/extensions/binary.rb +1 -1
- data/lib/mongo_mapper/extensions/boolean.rb +20 -23
- data/lib/mongo_mapper/extensions/date.rb +3 -3
- data/lib/mongo_mapper/extensions/integer.rb +5 -1
- data/lib/mongo_mapper/extensions/kernel.rb +2 -0
- data/lib/mongo_mapper/extensions/ordered_hash.rb +23 -0
- data/lib/mongo_mapper/extensions/string.rb +2 -2
- data/lib/mongo_mapper/extensions/time.rb +7 -5
- data/lib/mongo_mapper/middleware/identity_map.rb +3 -4
- data/lib/mongo_mapper/plugins.rb +1 -1
- data/lib/mongo_mapper/plugins/associations.rb +11 -5
- data/lib/mongo_mapper/plugins/associations/base.rb +5 -3
- data/lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb +0 -0
- data/lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb +8 -8
- data/lib/mongo_mapper/plugins/associations/collection.rb +2 -0
- data/lib/mongo_mapper/plugins/associations/many_documents_proxy.rb +32 -7
- data/lib/mongo_mapper/plugins/associations/many_embedded_proxy.rb +2 -2
- data/lib/mongo_mapper/plugins/associations/one_proxy.rb +12 -12
- data/lib/mongo_mapper/plugins/associations/proxy.rb +5 -1
- data/lib/mongo_mapper/plugins/associations/single_association.rb +6 -6
- data/lib/mongo_mapper/plugins/clone.rb +4 -2
- data/lib/mongo_mapper/plugins/dirty.rb +22 -21
- data/lib/mongo_mapper/plugins/document.rb +4 -4
- data/lib/mongo_mapper/plugins/dumpable.rb +22 -0
- data/lib/mongo_mapper/plugins/embedded_callbacks.rb +58 -9
- data/lib/mongo_mapper/plugins/identity_map.rb +42 -32
- data/lib/mongo_mapper/plugins/keys.rb +133 -54
- data/lib/mongo_mapper/plugins/keys/key.rb +68 -22
- data/lib/mongo_mapper/plugins/modifiers.rb +26 -19
- data/lib/mongo_mapper/plugins/persistence.rb +15 -5
- data/lib/mongo_mapper/plugins/querying.rb +15 -40
- data/lib/mongo_mapper/plugins/querying/{decorator.rb → decorated_plucky_query.rb} +24 -4
- data/lib/mongo_mapper/plugins/rails.rb +22 -2
- data/lib/mongo_mapper/plugins/safe.rb +8 -5
- data/lib/mongo_mapper/plugins/sci.rb +26 -4
- data/lib/mongo_mapper/plugins/scopes.rb +5 -4
- data/lib/mongo_mapper/plugins/timestamps.rb +11 -4
- data/lib/mongo_mapper/plugins/validations.rb +1 -1
- data/lib/mongo_mapper/utils.rb +12 -0
- data/lib/mongo_mapper/version.rb +1 -1
- data/lib/rails/generators/mongo_mapper/config/config_generator.rb +20 -7
- data/lib/rails/generators/mongo_mapper/config/templates/mongo.yml +6 -0
- data/lib/rails/generators/mongo_mapper/model/model_generator.rb +18 -1
- data/lib/rails/generators/mongo_mapper/model/templates/model.rb +9 -5
- data/{test/functional/test_accessible.rb → spec/functional/accessible_spec.rb} +29 -29
- data/{test/functional/associations/test_belongs_to_polymorphic_proxy.rb → spec/functional/associations/belongs_to_polymorphic_proxy_spec.rb} +10 -10
- data/{test/functional/associations/test_belongs_to_proxy.rb → spec/functional/associations/belongs_to_proxy_spec.rb} +82 -64
- data/{test/functional/associations/test_in_array_proxy.rb → spec/functional/associations/in_array_proxy_spec.rb} +68 -68
- data/{test/functional/associations/test_many_documents_as_proxy.rb → spec/functional/associations/many_documents_as_proxy_spec.rb} +37 -38
- data/{test/functional/associations/test_many_documents_proxy.rb → spec/functional/associations/many_documents_proxy_spec.rb} +233 -146
- data/{test/functional/associations/test_many_embedded_polymorphic_proxy.rb → spec/functional/associations/many_embedded_polymorphic_proxy_spec.rb} +19 -20
- data/{test/functional/associations/test_many_embedded_proxy.rb → spec/functional/associations/many_embedded_proxy_spec.rb} +23 -24
- data/{test/functional/associations/test_many_polymorphic_proxy.rb → spec/functional/associations/many_polymorphic_proxy_spec.rb} +45 -46
- data/{test/functional/associations/test_one_as_proxy.rb → spec/functional/associations/one_as_proxy_spec.rb} +75 -77
- data/{test/functional/associations/test_one_embedded_polymorphic_proxy.rb → spec/functional/associations/one_embedded_polymorphic_proxy_spec.rb} +31 -32
- data/{test/functional/associations/test_one_embedded_proxy.rb → spec/functional/associations/one_embedded_proxy_spec.rb} +10 -10
- data/{test/functional/associations/test_one_proxy.rb → spec/functional/associations/one_proxy_spec.rb} +125 -102
- data/spec/functional/associations_spec.rb +48 -0
- data/{test/functional/test_binary.rb → spec/functional/binary_spec.rb} +6 -6
- data/spec/functional/caching_spec.rb +75 -0
- data/{test/functional/test_callbacks.rb → spec/functional/callbacks_spec.rb} +84 -26
- data/{test/functional/test_dirty.rb → spec/functional/dirty_spec.rb} +57 -42
- data/{test/functional/test_document.rb → spec/functional/document_spec.rb} +52 -52
- data/spec/functional/dumpable_spec.rb +24 -0
- data/{test/functional/test_dynamic_querying.rb → spec/functional/dynamic_querying_spec.rb} +14 -14
- data/{test/functional/test_embedded_document.rb → spec/functional/embedded_document_spec.rb} +51 -42
- data/{test/functional/test_equality.rb → spec/functional/equality_spec.rb} +4 -4
- data/spec/functional/extensions_spec.rb +16 -0
- data/{test/functional/test_identity_map.rb → spec/functional/identity_map_spec.rb} +73 -61
- data/spec/functional/indexes_spec.rb +48 -0
- data/spec/functional/keys_spec.rb +224 -0
- data/{test/functional/test_logger.rb → spec/functional/logger_spec.rb} +6 -6
- data/spec/functional/modifiers_spec.rb +550 -0
- data/spec/functional/pagination_spec.rb +89 -0
- data/spec/functional/protected_spec.rb +199 -0
- data/spec/functional/querying_spec.rb +1003 -0
- data/spec/functional/rails_spec.rb +55 -0
- data/spec/functional/safe_spec.rb +163 -0
- data/{test/functional/test_sci.rb → spec/functional/sci_spec.rb} +123 -34
- data/{test/functional/test_scopes.rb → spec/functional/scopes_spec.rb} +59 -26
- data/spec/functional/timestamps_spec.rb +97 -0
- data/{test/functional/test_touch.rb → spec/functional/touch_spec.rb} +13 -13
- data/spec/functional/userstamps_spec.rb +46 -0
- data/{test/functional/test_validations.rb → spec/functional/validations_spec.rb} +64 -64
- data/spec/spec_helper.rb +81 -0
- data/spec/support/matchers.rb +24 -0
- data/{test → spec/support}/models.rb +1 -6
- data/spec/unit/associations/base_spec.rb +146 -0
- data/spec/unit/associations/belongs_to_association_spec.rb +30 -0
- data/spec/unit/associations/many_association_spec.rb +64 -0
- data/spec/unit/associations/one_association_spec.rb +48 -0
- data/{test/unit/associations/test_proxy.rb → spec/unit/associations/proxy_spec.rb} +21 -21
- data/{test/unit/test_clone.rb → spec/unit/clone_spec.rb} +21 -11
- data/spec/unit/config_generator_spec.rb +24 -0
- data/{test/unit/test_document.rb → spec/unit/document_spec.rb} +42 -42
- data/{test/unit/test_dynamic_finder.rb → spec/unit/dynamic_finder_spec.rb} +28 -28
- data/{test/unit/test_embedded_document.rb → spec/unit/embedded_document_spec.rb} +102 -108
- data/{test/unit/test_equality.rb → spec/unit/equality_spec.rb} +7 -7
- data/{test/unit/test_exceptions.rb → spec/unit/exceptions_spec.rb} +3 -3
- data/{test/unit/test_extensions.rb → spec/unit/extensions_spec.rb} +85 -71
- data/spec/unit/identity_map_middleware_spec.rb +134 -0
- data/{test/unit/test_inspect.rb → spec/unit/inspect_spec.rb} +8 -8
- data/{test/unit/test_key.rb → spec/unit/key_spec.rb} +82 -52
- data/spec/unit/keys_spec.rb +155 -0
- data/spec/unit/model_generator_spec.rb +47 -0
- data/spec/unit/mongo_mapper_spec.rb +184 -0
- data/spec/unit/pagination_spec.rb +11 -0
- data/{test/unit/test_plugins.rb → spec/unit/plugins_spec.rb} +14 -14
- data/spec/unit/rails_compatibility_spec.rb +40 -0
- data/{test/unit/test_rails_reflect_on_association.rb → spec/unit/rails_reflect_on_association_spec.rb} +9 -9
- data/{test/unit/test_rails.rb → spec/unit/rails_spec.rb} +31 -31
- data/spec/unit/serialization_spec.rb +169 -0
- data/spec/unit/serializers/json_serializer_spec.rb +218 -0
- data/spec/unit/serializers/xml_serializer_spec.rb +198 -0
- data/{test/unit/test_time_zones.rb → spec/unit/time_zones_spec.rb} +8 -8
- data/{test/unit/test_translation.rb → spec/unit/translation_spec.rb} +6 -6
- data/{test/unit/test_validations.rb → spec/unit/validations_spec.rb} +72 -59
- metadata +199 -179
- data/test/_NOTE_ON_TESTING +0 -1
- data/test/functional/test_associations.rb +0 -46
- data/test/functional/test_caching.rb +0 -77
- data/test/functional/test_indexes.rb +0 -50
- data/test/functional/test_modifiers.rb +0 -537
- data/test/functional/test_pagination.rb +0 -91
- data/test/functional/test_protected.rb +0 -201
- data/test/functional/test_querying.rb +0 -935
- data/test/functional/test_safe.rb +0 -76
- data/test/functional/test_timestamps.rb +0 -62
- data/test/functional/test_userstamps.rb +0 -44
- data/test/support/railtie.rb +0 -4
- data/test/support/railtie/autoloaded.rb +0 -2
- data/test/support/railtie/not_autoloaded.rb +0 -3
- data/test/support/railtie/parent.rb +0 -3
- data/test/test_active_model_lint.rb +0 -18
- data/test/test_helper.rb +0 -93
- data/test/unit/associations/test_base.rb +0 -146
- data/test/unit/associations/test_belongs_to_association.rb +0 -29
- data/test/unit/associations/test_many_association.rb +0 -63
- data/test/unit/associations/test_one_association.rb +0 -47
- data/test/unit/serializers/test_json_serializer.rb +0 -216
- data/test/unit/serializers/test_xml_serializer.rb +0 -196
- data/test/unit/test_identity_map_middleware.rb +0 -132
- data/test/unit/test_keys.rb +0 -65
- data/test/unit/test_mongo_mapper.rb +0 -157
- data/test/unit/test_pagination.rb +0 -11
- data/test/unit/test_rails_compatibility.rb +0 -38
- data/test/unit/test_serialization.rb +0 -166
@@ -1,8 +1,8 @@
|
|
1
|
-
require '
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
|
-
|
3
|
+
describe "Equality" do
|
4
4
|
context "Case equality" do
|
5
|
-
|
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
|
22
|
+
it "should work with regular instance" do
|
23
23
|
@klass.should === @klass.new
|
24
24
|
end
|
25
25
|
|
26
|
-
should
|
26
|
+
it "should work with instances of subclasses" do
|
27
27
|
@klass.should === @subklass.new
|
28
28
|
end
|
29
29
|
|
30
|
-
should
|
30
|
+
it "should work with a faker class" do
|
31
31
|
@klass.should === @faker.new(@klass.new)
|
32
32
|
end
|
33
33
|
|
34
|
-
should
|
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 '
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
|
-
|
3
|
+
describe "Extensions" do
|
4
4
|
context "DocumentNotValid" do
|
5
|
-
should
|
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 '
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
|
-
|
3
|
+
describe "Support" do
|
4
4
|
context "Array.to_mongo" do
|
5
|
-
should
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
44
|
+
it "should be true for true" do
|
45
45
|
Boolean.to_mongo(true).should be_true
|
46
46
|
end
|
47
47
|
|
48
|
-
should
|
48
|
+
it "should be false for false" do
|
49
49
|
Boolean.to_mongo(false).should be_false
|
50
50
|
end
|
51
51
|
|
52
|
-
should
|
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
|
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
|
70
|
+
it "should be true for true" do
|
71
71
|
Boolean.from_mongo(true).should be_true
|
72
72
|
end
|
73
73
|
|
74
|
-
should
|
74
|
+
it "should be false for false" do
|
75
75
|
Boolean.from_mongo(false).should be_false
|
76
76
|
end
|
77
77
|
|
78
|
-
should
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
137
|
+
it "should leave nil values nil" do
|
138
138
|
Float.to_mongo(nil).should == nil
|
139
139
|
end
|
140
140
|
|
141
|
-
should
|
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
|
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
|
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
|
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
|
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
|
-
|
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
|
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
|
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
|
208
|
+
it "should call class to_mongo with self" do
|
195
209
|
object = Object.new
|
196
|
-
object.class.
|
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
|
216
|
+
it "should return nil for nil" do
|
203
217
|
ObjectId.to_mongo(nil).should be_nil
|
204
218
|
end
|
205
219
|
|
206
|
-
should
|
220
|
+
it "should return nil if blank string" do
|
207
221
|
ObjectId.to_mongo('').should be_nil
|
208
222
|
end
|
209
223
|
|
210
|
-
should
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
284
|
+
it "should return nil if nil" do
|
271
285
|
String.from_mongo(nil).should be_nil
|
272
286
|
end
|
273
287
|
|
274
|
-
should
|
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
|
-
|
294
|
+
before do
|
281
295
|
Time.zone = nil
|
282
296
|
end
|
283
297
|
|
284
|
-
should
|
285
|
-
Time.to_mongo('2000-01-01 01:01:01.123456').to_f.should
|
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
|
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
|
306
|
+
it "should be nil if blank string" do
|
293
307
|
Time.to_mongo('').should be_nil
|
294
308
|
end
|
295
309
|
|
296
|
-
should
|
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
|
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
|
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
|
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.
|
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
|
315
|
-
Time.to_mongo(Time.now.end_of_month).
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|