pwnash-mongo_mapper 0.7.5 → 0.7.6

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 (108) hide show
  1. data/lib/mongo_mapper.rb +6 -8
  2. data/lib/mongo_mapper/document.rb +6 -281
  3. data/lib/mongo_mapper/embedded_document.rb +5 -45
  4. data/lib/mongo_mapper/extensions.rb +190 -0
  5. data/lib/mongo_mapper/plugins.rb +27 -18
  6. data/lib/mongo_mapper/plugins/associations.rb +7 -6
  7. data/lib/mongo_mapper/plugins/associations/base.rb +1 -0
  8. data/lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb +1 -0
  9. data/lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb +1 -0
  10. data/lib/mongo_mapper/plugins/associations/collection.rb +1 -0
  11. data/lib/mongo_mapper/plugins/associations/embedded_collection.rb +1 -0
  12. data/lib/mongo_mapper/plugins/associations/in_array_proxy.rb +2 -1
  13. data/lib/mongo_mapper/plugins/associations/many_documents_as_proxy.rb +1 -0
  14. data/lib/mongo_mapper/plugins/associations/many_documents_proxy.rb +4 -4
  15. data/lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb +1 -0
  16. data/lib/mongo_mapper/plugins/associations/many_embedded_proxy.rb +1 -0
  17. data/lib/mongo_mapper/plugins/associations/many_polymorphic_proxy.rb +1 -0
  18. data/lib/mongo_mapper/plugins/associations/one_embedded_proxy.rb +1 -0
  19. data/lib/mongo_mapper/plugins/associations/one_proxy.rb +1 -0
  20. data/lib/mongo_mapper/plugins/associations/proxy.rb +1 -0
  21. data/lib/mongo_mapper/plugins/callbacks.rb +4 -3
  22. data/lib/mongo_mapper/plugins/clone.rb +1 -0
  23. data/lib/mongo_mapper/plugins/descendants.rb +1 -0
  24. data/lib/mongo_mapper/plugins/dirty.rb +1 -0
  25. data/lib/mongo_mapper/plugins/document.rb +40 -0
  26. data/lib/mongo_mapper/plugins/dynamic_querying.rb +42 -0
  27. data/lib/mongo_mapper/{support/find.rb → plugins/dynamic_querying/dynamic_finder.rb} +2 -36
  28. data/lib/mongo_mapper/plugins/embedded_document.rb +48 -0
  29. data/lib/mongo_mapper/plugins/equality.rb +1 -0
  30. data/lib/mongo_mapper/plugins/identity_map.rb +8 -11
  31. data/lib/mongo_mapper/plugins/indexes.rb +11 -0
  32. data/lib/mongo_mapper/plugins/inspect.rb +1 -0
  33. data/lib/mongo_mapper/plugins/keys.rb +7 -9
  34. data/lib/mongo_mapper/plugins/keys/key.rb +12 -2
  35. data/lib/mongo_mapper/plugins/logger.rb +1 -0
  36. data/lib/mongo_mapper/plugins/modifiers.rb +3 -2
  37. data/lib/mongo_mapper/plugins/pagination.rb +1 -0
  38. data/lib/mongo_mapper/plugins/pagination/proxy.rb +1 -0
  39. data/lib/mongo_mapper/plugins/persistence.rb +1 -0
  40. data/lib/mongo_mapper/plugins/protected.rb +1 -0
  41. data/lib/mongo_mapper/plugins/query_logger.rb +5 -10
  42. data/lib/mongo_mapper/plugins/querying.rb +236 -0
  43. data/lib/mongo_mapper/plugins/rails.rb +1 -0
  44. data/lib/mongo_mapper/plugins/sci.rb +31 -0
  45. data/lib/mongo_mapper/plugins/serialization.rb +1 -0
  46. data/lib/mongo_mapper/plugins/timestamps.rb +1 -0
  47. data/lib/mongo_mapper/plugins/userstamps.rb +1 -0
  48. data/lib/mongo_mapper/plugins/validations.rb +5 -1
  49. data/lib/mongo_mapper/query.rb +53 -120
  50. data/lib/mongo_mapper/support.rb +2 -213
  51. data/lib/mongo_mapper/support/descendant_appends.rb +3 -6
  52. data/lib/mongo_mapper/version.rb +2 -1
  53. metadata +156 -190
  54. data/.gitignore +0 -10
  55. data/Rakefile +0 -37
  56. data/mongo_mapper.gemspec +0 -216
  57. data/performance/read_write.rb +0 -52
  58. data/specs.watchr +0 -51
  59. data/test/NOTE_ON_TESTING +0 -1
  60. data/test/active_model_lint_test.rb +0 -13
  61. data/test/functional/associations/test_belongs_to_polymorphic_proxy.rb +0 -63
  62. data/test/functional/associations/test_belongs_to_proxy.rb +0 -101
  63. data/test/functional/associations/test_in_array_proxy.rb +0 -325
  64. data/test/functional/associations/test_many_documents_as_proxy.rb +0 -229
  65. data/test/functional/associations/test_many_documents_proxy.rb +0 -536
  66. data/test/functional/associations/test_many_embedded_polymorphic_proxy.rb +0 -176
  67. data/test/functional/associations/test_many_embedded_proxy.rb +0 -256
  68. data/test/functional/associations/test_many_polymorphic_proxy.rb +0 -302
  69. data/test/functional/associations/test_one_embedded_proxy.rb +0 -68
  70. data/test/functional/associations/test_one_proxy.rb +0 -196
  71. data/test/functional/test_associations.rb +0 -44
  72. data/test/functional/test_binary.rb +0 -27
  73. data/test/functional/test_callbacks.rb +0 -151
  74. data/test/functional/test_dirty.rb +0 -163
  75. data/test/functional/test_document.rb +0 -1219
  76. data/test/functional/test_embedded_document.rb +0 -210
  77. data/test/functional/test_identity_map.rb +0 -507
  78. data/test/functional/test_indexing.rb +0 -44
  79. data/test/functional/test_logger.rb +0 -20
  80. data/test/functional/test_modifiers.rb +0 -416
  81. data/test/functional/test_pagination.rb +0 -93
  82. data/test/functional/test_protected.rb +0 -163
  83. data/test/functional/test_string_id_compatibility.rb +0 -67
  84. data/test/functional/test_timestamps.rb +0 -64
  85. data/test/functional/test_userstamps.rb +0 -28
  86. data/test/functional/test_validations.rb +0 -342
  87. data/test/models.rb +0 -227
  88. data/test/support/custom_matchers.rb +0 -37
  89. data/test/support/timing.rb +0 -16
  90. data/test/test_helper.rb +0 -64
  91. data/test/unit/associations/test_base.rb +0 -212
  92. data/test/unit/associations/test_proxy.rb +0 -105
  93. data/test/unit/serializers/test_json_serializer.rb +0 -202
  94. data/test/unit/test_descendant_appends.rb +0 -71
  95. data/test/unit/test_document.rb +0 -225
  96. data/test/unit/test_dynamic_finder.rb +0 -123
  97. data/test/unit/test_embedded_document.rb +0 -657
  98. data/test/unit/test_keys.rb +0 -216
  99. data/test/unit/test_mongo_mapper.rb +0 -118
  100. data/test/unit/test_pagination.rb +0 -160
  101. data/test/unit/test_plugins.rb +0 -50
  102. data/test/unit/test_query.rb +0 -374
  103. data/test/unit/test_rails.rb +0 -181
  104. data/test/unit/test_rails_compatibility.rb +0 -52
  105. data/test/unit/test_serialization.rb +0 -51
  106. data/test/unit/test_support.rb +0 -390
  107. data/test/unit/test_time_zones.rb +0 -39
  108. data/test/unit/test_validations.rb +0 -544
@@ -1,52 +0,0 @@
1
- require 'test_helper'
2
-
3
- class TestRailsCompatibility < Test::Unit::TestCase
4
- class BigStuff
5
- include MongoMapper::Document
6
- end
7
-
8
- class Item
9
- include MongoMapper::EmbeddedDocument
10
- key :for_all, String
11
- end
12
-
13
- class FirstItem < Item
14
- key :first_only, String
15
- many :second_items
16
- end
17
-
18
- class SecondItem < Item
19
- key :second_only, String
20
- end
21
-
22
- context "EmbeddedDocument" do
23
- should "alias many to has_many" do
24
- FirstItem.should respond_to(:has_many)
25
- end
26
-
27
- should "alias one to has_one" do
28
- FirstItem.should respond_to(:has_one)
29
- end
30
-
31
- should "have column names" do
32
- Item.column_names.sort.should == ['_id', '_type', 'for_all']
33
- FirstItem.column_names.sort.should == ['_id', '_type', 'first_only', 'for_all']
34
- SecondItem.column_names.sort.should == ['_id', '_type', 'for_all', 'second_only']
35
- end
36
-
37
- should "alias new to new_record?" do
38
- instance = Item.new
39
- instance.new_record?.should == instance.new?
40
- end
41
-
42
- should "implement human_name" do
43
- Item.human_name.should == 'Item'
44
- end
45
- end
46
-
47
- context "Document" do
48
- should "implement human_name" do
49
- BigStuff.human_name.should == 'Big Stuff'
50
- end
51
- end
52
- end
@@ -1,51 +0,0 @@
1
- require 'test_helper'
2
-
3
- class SerializationTest < Test::Unit::TestCase
4
- def setup
5
- @document = EDoc do
6
- key :name, String
7
- key :age, Integer
8
- key :awesome, Boolean
9
- key :preferences, Hash
10
- key :created_at, Time
11
- end
12
-
13
- @instance = @document.new(
14
- :name => 'John Doe',
15
- :age => 25,
16
- :awesome => true,
17
- :preferences => {:language => 'Ruby'},
18
- :created_at => Time.now.change(:usec => 0)
19
- )
20
- end
21
-
22
- [:json].each do |format|
23
- context format do
24
- should "be reversable" do
25
- serialized = @instance.send("to_#{format}")
26
- unserialized = @document.send("from_#{format}", serialized)
27
-
28
- assert_equal @instance, unserialized
29
- end
30
-
31
- should "allow attribute only filtering" do
32
- serialized = @instance.send("to_#{format}", :only => [ :age, :name ])
33
- unserialized = @document.send("from_#{format}", serialized)
34
-
35
- assert_equal @instance.name, unserialized.name
36
- assert_equal @instance.age, unserialized.age
37
- assert ! unserialized.awesome
38
- assert_nil unserialized.created_at
39
- end
40
-
41
- should "allow attribute except filtering" do
42
- serialized = @instance.send("to_#{format}", :except => [ :age, :name ])
43
- unserialized = @document.send("from_#{format}", serialized)
44
-
45
- assert_nil unserialized.name
46
- assert_nil unserialized.age
47
- assert_equal @instance.awesome, unserialized.awesome
48
- end
49
- end
50
- end
51
- end
@@ -1,390 +0,0 @@
1
- require 'test_helper'
2
-
3
- class SupportTest < Test::Unit::TestCase
4
- context "Array#to_mongo" do
5
- should "convert value to_a" do
6
- Array.to_mongo([1, 2, 3, 4]).should == [1, 2, 3, 4]
7
- Array.to_mongo('1').should == ['1']
8
- Array.to_mongo({'1' => '2', '3' => '4'}).should == [['1', '2'], ['3', '4']]
9
- end
10
- end
11
-
12
- context "Array#from_mongo" do
13
- should "be array if array" do
14
- Array.from_mongo([1, 2]).should == [1, 2]
15
- end
16
-
17
- should "be empty array if nil" do
18
- Array.from_mongo(nil).should == []
19
- end
20
- end
21
-
22
- context "Binary#to_mongo" do
23
- should "convert to byte buffer if not byte buffer" do
24
- Binary.to_mongo('asdfsadasdfs').is_a?(BSON::ByteBuffer).should be_true
25
- end
26
-
27
- should "be byte buffer if byte buffer" do
28
- Binary.to_mongo(BSON::ByteBuffer.new('asdfsadasdfs')).is_a?(BSON::ByteBuffer).should be_true
29
- end
30
-
31
- should "be nil if nil" do
32
- Binary.to_mongo(nil).should be_nil
33
- end
34
- end
35
-
36
- context "Binary#from_mongo" do
37
- should "return value" do
38
- buffer = BSON::ByteBuffer.new('asdfasdfasdf')
39
- Binary.from_mongo(buffer).to_s.should == buffer.to_s
40
- end
41
- end
42
-
43
- context "Boolean#to_mongo" do
44
- should "be true for true" do
45
- Boolean.to_mongo(true).should be_true
46
- end
47
-
48
- should "be false for false" do
49
- Boolean.to_mongo(false).should be_false
50
- end
51
-
52
- should "handle odd assortment of other values" do
53
- Boolean.to_mongo('true').should be_true
54
- Boolean.to_mongo('t').should be_true
55
- Boolean.to_mongo('1').should be_true
56
- Boolean.to_mongo(1).should be_true
57
-
58
- Boolean.to_mongo('false').should be_false
59
- Boolean.to_mongo('f').should be_false
60
- Boolean.to_mongo('0').should be_false
61
- Boolean.to_mongo(0).should be_false
62
- end
63
-
64
- should "be nil for nil" do
65
- Boolean.to_mongo(nil).should be_nil
66
- end
67
- end
68
-
69
- context "Boolean#from_mongo" do
70
- should "be true for true" do
71
- Boolean.from_mongo(true).should be_true
72
- end
73
-
74
- should "be false for false" do
75
- Boolean.from_mongo(false).should be_false
76
- end
77
-
78
- should "be nil for nil" do
79
- Boolean.to_mongo(nil).should be_nil
80
- end
81
- end
82
-
83
- context "Date#to_mongo" do
84
- should "be time if string" do
85
- date = Date.to_mongo('2009-10-01')
86
- date.should == Time.utc(2009, 10, 1)
87
- date.should == date
88
- date.month.should == 10
89
- date.day.should == 1
90
- date.year.should == 2009
91
- end
92
-
93
- should "be time if date" do
94
- Date.to_mongo(Date.new(2009, 10, 1)).should == Time.utc(2009, 10, 1)
95
- end
96
-
97
- should "be date if time" do
98
- Date.to_mongo(Time.parse("2009-10-1T12:30:00")).should == Time.utc(2009, 10, 1)
99
- end
100
-
101
- should "be nil if bogus string" do
102
- Date.to_mongo('jdsafop874').should be_nil
103
- end
104
-
105
- should "be nil if empty string" do
106
- Date.to_mongo('').should be_nil
107
- end
108
- end
109
-
110
- context "Date#from_mongo" do
111
- should "be date if date" do
112
- date = Date.new(2009, 10, 1)
113
- from_date = Date.from_mongo(date)
114
- from_date.should == date
115
- from_date.month.should == 10
116
- from_date.day.should == 1
117
- from_date.year.should == 2009
118
- end
119
-
120
- should "be date if time" do
121
- time = Time.now
122
- Date.from_mongo(time).should == time.to_date
123
- end
124
-
125
- should "be nil if nil" do
126
- Date.from_mongo(nil).should be_nil
127
- end
128
- end
129
-
130
- context "Float#to_mongo" do
131
- should "convert value to_f" do
132
- [21, 21.0, '21'].each do |value|
133
- Float.to_mongo(value).should == 21.0
134
- end
135
- end
136
-
137
- should "leave nil values nil" do
138
- Float.to_mongo(nil).should == nil
139
- end
140
- end
141
-
142
- context "Hash#from_mongo" do
143
- should "convert hash to hash with indifferent access" do
144
- hash = Hash.from_mongo(:foo => 'bar')
145
- hash[:foo].should == 'bar'
146
- hash['foo'].should == 'bar'
147
- end
148
-
149
- should "be hash if nil" do
150
- hash = Hash.from_mongo(nil)
151
- hash.should == {}
152
- hash.is_a?(HashWithIndifferentAccess).should be_true
153
- end
154
- end
155
-
156
- context "Hash#to_mongo instance method" do
157
- should "have instance method that returns self" do
158
- hash = HashWithIndifferentAccess.new('foo' => 'bar')
159
- hash.to_mongo.should == {'foo' => 'bar'}
160
- end
161
- end
162
-
163
- context "Integer#to_mongo" do
164
- should "convert value to integer" do
165
- [21, 21.0, '21'].each do |value|
166
- Integer.to_mongo(value).should == 21
167
- end
168
- end
169
-
170
- should "work fine with big integers" do
171
- [9223372036854775807, '9223372036854775807'].each do |value|
172
- Integer.to_mongo(value).should == 9223372036854775807
173
- end
174
- end
175
- end
176
-
177
- context "ObjectId#to_mongo" do
178
- should "return nil for nil" do
179
- ObjectId.to_mongo(nil).should be_nil
180
- end
181
-
182
- should "return nil if blank string" do
183
- ObjectId.to_mongo('').should be_nil
184
- end
185
-
186
- should "return value if object id" do
187
- id = BSON::ObjectID.new
188
- ObjectId.to_mongo(id).should be(id)
189
- end
190
-
191
- should "return object id if string" do
192
- id = BSON::ObjectID.new
193
- ObjectId.to_mongo(id.to_s).should be(id)
194
- end
195
- end
196
-
197
- context "ObjectId#from_mongo" do
198
- should "return value" do
199
- id = BSON::ObjectID.new
200
- ObjectId.from_mongo(id).should == id
201
- end
202
- end
203
-
204
- context "NilClass#to_mongo" do
205
- should "return nil" do
206
- nil.to_mongo(nil).should be_nil
207
- end
208
- end
209
-
210
- context "NilClass#from_mongo" do
211
- should "return nil" do
212
- nil.from_mongo(nil).should be_nil
213
- end
214
- end
215
-
216
- context "Object#to_mongo" do
217
- should "return value" do
218
- Object.to_mongo(21).should == 21
219
- Object.to_mongo('21').should == '21'
220
- Object.to_mongo(9223372036854775807).should == 9223372036854775807
221
- end
222
- end
223
-
224
- context "Object#from_mongo" do
225
- should "return value" do
226
- Object.from_mongo(21).should == 21
227
- Object.from_mongo('21').should == '21'
228
- Object.from_mongo(9223372036854775807).should == 9223372036854775807
229
- end
230
- end
231
-
232
- context "Set#to_mongo" do
233
- should "convert value to_a" do
234
- Set.to_mongo(Set.new([1,2,3])).should == [1,2,3]
235
- end
236
-
237
- should "convert to empty array if nil" do
238
- Set.to_mongo(nil).should == []
239
- end
240
- end
241
-
242
- context "Set#from_mongo" do
243
- should "be a set if array" do
244
- Set.from_mongo([1,2,3]).should == Set.new([1,2,3])
245
- end
246
-
247
- should "be empty set if nil" do
248
- Set.from_mongo(nil).should == Set.new([])
249
- end
250
- end
251
-
252
- context "String#to_mongo" do
253
- should "convert value to_s" do
254
- [21, '21'].each do |value|
255
- String.to_mongo(value).should == '21'
256
- end
257
- end
258
-
259
- should "be nil if nil" do
260
- String.to_mongo(nil).should be_nil
261
- end
262
- end
263
-
264
- context "String#from_mongo" do
265
- should "be string if value present" do
266
- String.from_mongo('Scotch! Scotch! Scotch!').should == 'Scotch! Scotch! Scotch!'
267
- end
268
-
269
- should "return nil if nil" do
270
- String.from_mongo(nil).should be_nil
271
- end
272
-
273
- should "return empty string if blank" do
274
- String.from_mongo('').should == ''
275
- end
276
- end
277
-
278
- context "Symbol" do
279
- %w(gt lt gte lte ne in nin mod all size where exists asc desc).each do |operator|
280
- should "have $#{operator} operator" do
281
- :foo.respond_to?(operator)
282
- end
283
- end
284
- end
285
-
286
- context "Time#to_mongo without Time.zone" do
287
- setup do
288
- Time.zone = nil
289
- end
290
-
291
- should "be time to milliseconds if string" do
292
- Time.to_mongo('2000-01-01 01:01:01.123456').to_f.should == Time.local(2000, 1, 1, 1, 1, 1, 0).utc.to_f
293
- end
294
-
295
- should "be time in utc if time" do
296
- Time.to_mongo(Time.local(2009, 8, 15, 0, 0, 0)).zone.should == 'UTC'
297
- end
298
-
299
- should "be nil if blank string" do
300
- Time.to_mongo('').should be_nil
301
- end
302
-
303
- should "not be nil if nil" do
304
- Time.to_mongo(nil).should be_nil
305
- end
306
- end
307
-
308
- context "Time#to_mongo with Time.zone" do
309
- should "be time to milliseconds if time" do
310
- Time.zone = 'Hawaii'
311
- Time.to_mongo(Time.zone.local(2009, 8, 15, 14, 0, 0, 123456)).to_f.should == Time.utc(2009, 8, 16, 0, 0, 0, 0).to_f
312
- Time.zone = nil
313
- end
314
-
315
- should "be time to milliseconds if string" do
316
- Time.zone = 'Hawaii'
317
- Time.to_mongo('2009-08-15 14:00:00.123456').to_f.should == Time.utc(2009, 8, 16, 0, 0, 0, 0).to_f
318
- Time.zone = nil
319
- end
320
-
321
- should "not round up times at the end of the month" do
322
- Time.to_mongo(Time.now.end_of_month).to_i.should == Time.now.end_of_month.utc.to_i
323
- end
324
-
325
- should "be nil if blank string" do
326
- Time.zone = 'Hawaii'
327
- Time.to_mongo('').should be_nil
328
- Time.zone = nil
329
- end
330
-
331
- should "be nil if nil" do
332
- Time.zone = 'Hawaii'
333
- Time.to_mongo(nil).should be_nil
334
- Time.zone = nil
335
- end
336
- end
337
-
338
- context "Time#from_mongo without Time.zone" do
339
- should "be time" do
340
- time = Time.now
341
- Time.from_mongo(time).should == time
342
- end
343
-
344
- should "be nil if nil" do
345
- Time.from_mongo(nil).should be_nil
346
- end
347
- end
348
-
349
- context "Time#from_mongo with Time.zone" do
350
- should "be time in Time.zone" do
351
- Time.zone = 'Hawaii'
352
-
353
- time = Time.from_mongo(Time.utc(2009, 10, 1))
354
- time.should == Time.zone.local(2009, 9, 30, 14)
355
- time.is_a?(ActiveSupport::TimeWithZone).should be_true
356
-
357
- Time.zone = nil
358
- end
359
-
360
- should "be nil if nil" do
361
- Time.zone = 'Hawaii'
362
- Time.from_mongo(nil).should be_nil
363
- Time.zone = nil
364
- end
365
- end
366
-
367
- context "BSON::ObjectID" do
368
- context "#as_json" do
369
- should "convert object id to string" do
370
- id = BSON::ObjectID.new
371
- id.as_json.should == id.to_s
372
- end
373
- end
374
- context "#to_json" do
375
- should "convert object id to string" do
376
- id = BSON::ObjectID.new
377
- id.to_json.should == %Q("#{id}")
378
- end
379
-
380
- should "support ruby driver syntax also" do
381
- id = BSON::ObjectID.new
382
- id.original_to_json.should == %Q({"$oid": "#{id}"})
383
- end
384
- end
385
- end
386
-
387
- context "BSON::ObjectID.to_json" do
388
-
389
- end
390
- end