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,44 +0,0 @@
1
- require 'test_helper'
2
-
3
- class IndexingTest < Test::Unit::TestCase
4
- context "Indexing" do
5
- setup do
6
- @document = Doc do
7
- set_collection_name 'users'
8
-
9
- key :first_name, String
10
- key :last_name, String
11
- key :age, Integer
12
- key :date, Date
13
- end
14
- drop_indexes(@document)
15
- end
16
-
17
- should "allow creating index for a key" do
18
- @document.ensure_index :first_name
19
- @document.should have_index('first_name_1')
20
- end
21
-
22
- should "allow creating unique index for a key" do
23
- @document.ensure_index :first_name, :unique => true
24
- @document.should have_index('first_name_1')
25
- end
26
-
27
- should "allow creating index on multiple keys" do
28
- @document.ensure_index [[:first_name, 1], [:last_name, -1]]
29
-
30
- # order is different for different versions of ruby so instead of
31
- # just checking have_index('first_name_1_last_name_-1') I'm checking
32
- # the values of the indexes to make sure the index creation was successful
33
- @document.collection.index_information.detect do |index|
34
- keys = index[0]
35
- keys.include?('first_name_1') && keys.include?('last_name_-1')
36
- end.should_not be_nil
37
- end
38
-
39
- should "work with :index shortcut when defining key" do
40
- @document.key :father, String, :index => true
41
- @document.should have_index('father_1')
42
- end
43
- end
44
- end
@@ -1,20 +0,0 @@
1
- require 'test_helper'
2
-
3
- class LoggerTest < Test::Unit::TestCase
4
- context "with connection that has logger" do
5
- setup do
6
- @output = StringIO.new
7
- @logger = Logger.new(@output)
8
- MongoMapper.connection = Mongo::Connection.new('127.0.0.1', 27017, :logger => @logger)
9
- end
10
-
11
- should "be able to get access to that logger" do
12
- MongoMapper.logger.should == @logger
13
- end
14
-
15
- should "be able to log messages" do
16
- MongoMapper.logger.debug 'testing'
17
- @output.string.include?('testing').should be_true
18
- end
19
- end
20
- end
@@ -1,416 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ModifierTest < Test::Unit::TestCase
4
- def setup
5
- @page_class = Doc do
6
- key :title, String
7
- key :day_count, Integer, :default => 0
8
- key :week_count, Integer, :default => 0
9
- key :month_count, Integer, :default => 0
10
- key :tags, Array
11
- end
12
- end
13
-
14
- def assert_page_counts(page, day_count, week_count, month_count)
15
- page.reload
16
- page.day_count.should == day_count
17
- page.week_count.should == week_count
18
- page.month_count.should == month_count
19
- end
20
-
21
- def assert_keys_removed(page, *keys)
22
- keys.each do |key|
23
- doc = @page_class.collection.find_one({:_id => page.id})
24
- doc.keys.should_not include(key)
25
- end
26
- end
27
-
28
- context "ClassMethods" do
29
- context "unset" do
30
- setup do
31
- @page = @page_class.create(:title => 'Home', :tags => %w(foo bar))
32
- @page2 = @page_class.create(:title => 'Home')
33
- end
34
-
35
- should "work with criteria and keys" do
36
- @page_class.unset({:title => 'Home'}, :title, :tags)
37
- assert_keys_removed @page, :title, :tags
38
- assert_keys_removed @page2, :title, :tags
39
- end
40
-
41
- should "work with ids and keys" do
42
- @page_class.unset(@page.id, @page2.id, :title, :tags)
43
- assert_keys_removed @page, :title, :tags
44
- assert_keys_removed @page2, :title, :tags
45
- end
46
- end
47
-
48
- context "increment" do
49
- setup do
50
- @page = @page_class.create(:title => 'Home')
51
- @page2 = @page_class.create(:title => 'Home')
52
- end
53
-
54
- should "work with criteria and modifier hashes" do
55
- @page_class.increment({:title => 'Home'}, :day_count => 1, :week_count => 2, :month_count => 3)
56
-
57
- assert_page_counts @page, 1, 2, 3
58
- assert_page_counts @page2, 1, 2, 3
59
- end
60
-
61
- should "work with ids and modifier hash" do
62
- @page_class.increment(@page.id, @page2.id, :day_count => 1, :week_count => 2, :month_count => 3)
63
-
64
- assert_page_counts @page, 1, 2, 3
65
- assert_page_counts @page2, 1, 2, 3
66
- end
67
- end
68
-
69
- context "decrement" do
70
- setup do
71
- @page = @page_class.create(:title => 'Home', :day_count => 1, :week_count => 2, :month_count => 3)
72
- @page2 = @page_class.create(:title => 'Home', :day_count => 1, :week_count => 2, :month_count => 3)
73
- end
74
-
75
- should "work with criteria and modifier hashes" do
76
- @page_class.decrement({:title => 'Home'}, :day_count => 1, :week_count => 2, :month_count => 3)
77
-
78
- assert_page_counts @page, 0, 0, 0
79
- assert_page_counts @page2, 0, 0, 0
80
- end
81
-
82
- should "work with ids and modifier hash" do
83
- @page_class.decrement(@page.id, @page2.id, :day_count => 1, :week_count => 2, :month_count => 3)
84
-
85
- assert_page_counts @page, 0, 0, 0
86
- assert_page_counts @page2, 0, 0, 0
87
- end
88
-
89
- should "decrement with positive or negative numbers" do
90
- @page_class.decrement(@page.id, @page2.id, :day_count => -1, :week_count => 2, :month_count => -3)
91
-
92
- assert_page_counts @page, 0, 0, 0
93
- assert_page_counts @page2, 0, 0, 0
94
- end
95
- end
96
-
97
- context "set" do
98
- setup do
99
- @page = @page_class.create(:title => 'Home')
100
- @page2 = @page_class.create(:title => 'Home')
101
- end
102
-
103
- should "work with criteria and modifier hashes" do
104
- @page_class.set({:title => 'Home'}, :title => 'Home Revised')
105
-
106
- @page.reload
107
- @page.title.should == 'Home Revised'
108
-
109
- @page2.reload
110
- @page2.title.should == 'Home Revised'
111
- end
112
-
113
- should "work with ids and modifier hash" do
114
- @page_class.set(@page.id, @page2.id, :title => 'Home Revised')
115
-
116
- @page.reload
117
- @page.title.should == 'Home Revised'
118
-
119
- @page2.reload
120
- @page2.title.should == 'Home Revised'
121
- end
122
-
123
- should "typecast values before querying" do
124
- @page_class.key :tags, Set
125
-
126
- assert_nothing_raised do
127
- @page_class.set(@page.id, :tags => ['foo', 'bar'].to_set)
128
- @page.reload
129
- @page.tags.should == Set.new(['foo', 'bar'])
130
- end
131
- end
132
-
133
- should "not typecast keys that are not defined in document" do
134
- assert_raises(BSON::InvalidDocument) do
135
- @page_class.set(@page.id, :colors => ['red', 'green'].to_set)
136
- end
137
- end
138
-
139
- should "set keys that are not defined in document" do
140
- @page_class.set(@page.id, :colors => %w[red green])
141
- @page.reload
142
- @page[:colors].should == %w[red green]
143
- end
144
- end
145
-
146
- context "push" do
147
- setup do
148
- @page = @page_class.create(:title => 'Home')
149
- @page2 = @page_class.create(:title => 'Home')
150
- end
151
-
152
- should "work with criteria and modifier hashes" do
153
- @page_class.push({:title => 'Home'}, :tags => 'foo')
154
-
155
- @page.reload
156
- @page.tags.should == %w(foo)
157
-
158
- @page2.reload
159
- @page.tags.should == %w(foo)
160
- end
161
-
162
- should "work with ids and modifier hash" do
163
- @page_class.push(@page.id, @page2.id, :tags => 'foo')
164
-
165
- @page.reload
166
- @page.tags.should == %w(foo)
167
-
168
- @page2.reload
169
- @page.tags.should == %w(foo)
170
- end
171
- end
172
-
173
- context "push_all" do
174
- setup do
175
- @page = @page_class.create(:title => 'Home')
176
- @page2 = @page_class.create(:title => 'Home')
177
- @tags = %w(foo bar)
178
- end
179
-
180
- should "work with criteria and modifier hashes" do
181
- @page_class.push_all({:title => 'Home'}, :tags => @tags)
182
-
183
- @page.reload
184
- @page.tags.should == @tags
185
-
186
- @page2.reload
187
- @page.tags.should == @tags
188
- end
189
-
190
- should "work with ids and modifier hash" do
191
- @page_class.push_all(@page.id, @page2.id, :tags => @tags)
192
-
193
- @page.reload
194
- @page.tags.should == @tags
195
-
196
- @page2.reload
197
- @page.tags.should == @tags
198
- end
199
- end
200
-
201
- context "pull" do
202
- setup do
203
- @page = @page_class.create(:title => 'Home', :tags => %w(foo bar))
204
- @page2 = @page_class.create(:title => 'Home', :tags => %w(foo bar))
205
- end
206
-
207
- should "work with criteria and modifier hashes" do
208
- @page_class.pull({:title => 'Home'}, :tags => 'foo')
209
-
210
- @page.reload
211
- @page.tags.should == %w(bar)
212
-
213
- @page2.reload
214
- @page.tags.should == %w(bar)
215
- end
216
-
217
- should "be able to pull with ids and modifier hash" do
218
- @page_class.pull(@page.id, @page2.id, :tags => 'foo')
219
-
220
- @page.reload
221
- @page.tags.should == %w(bar)
222
-
223
- @page2.reload
224
- @page.tags.should == %w(bar)
225
- end
226
- end
227
-
228
- context "pull_all" do
229
- setup do
230
- @page = @page_class.create(:title => 'Home', :tags => %w(foo bar baz))
231
- @page2 = @page_class.create(:title => 'Home', :tags => %w(foo bar baz))
232
- end
233
-
234
- should "work with criteria and modifier hashes" do
235
- @page_class.pull_all({:title => 'Home'}, :tags => %w(foo bar))
236
-
237
- @page.reload
238
- @page.tags.should == %w(baz)
239
-
240
- @page2.reload
241
- @page.tags.should == %w(baz)
242
- end
243
-
244
- should "work with ids and modifier hash" do
245
- @page_class.pull_all(@page.id, @page2.id, :tags => %w(foo bar))
246
-
247
- @page.reload
248
- @page.tags.should == %w(baz)
249
-
250
- @page2.reload
251
- @page.tags.should == %w(baz)
252
- end
253
- end
254
-
255
- context "add_to_set" do
256
- setup do
257
- @page = @page_class.create(:title => 'Home', :tags => 'foo')
258
- @page2 = @page_class.create(:title => 'Home')
259
- end
260
-
261
- should "be able to add to set with criteria and modifier hash" do
262
- @page_class.add_to_set({:title => 'Home'}, :tags => 'foo')
263
-
264
- @page.reload
265
- @page.tags.should == %w(foo)
266
-
267
- @page2.reload
268
- @page.tags.should == %w(foo)
269
- end
270
-
271
- should "be able to add to set with ids and modifier hash" do
272
- @page_class.add_to_set(@page.id, @page2.id, :tags => 'foo')
273
-
274
- @page.reload
275
- @page.tags.should == %w(foo)
276
-
277
- @page2.reload
278
- @page.tags.should == %w(foo)
279
- end
280
- end
281
-
282
- context "push_uniq" do
283
- setup do
284
- @page = @page_class.create(:title => 'Home', :tags => 'foo')
285
- @page2 = @page_class.create(:title => 'Home')
286
- end
287
-
288
- should "be able to push uniq with criteria and modifier hash" do
289
- @page_class.push_uniq({:title => 'Home'}, :tags => 'foo')
290
-
291
- @page.reload
292
- @page.tags.should == %w(foo)
293
-
294
- @page2.reload
295
- @page.tags.should == %w(foo)
296
- end
297
-
298
- should "be able to push uniq with ids and modifier hash" do
299
- @page_class.push_uniq(@page.id, @page2.id, :tags => 'foo')
300
-
301
- @page.reload
302
- @page.tags.should == %w(foo)
303
-
304
- @page2.reload
305
- @page.tags.should == %w(foo)
306
- end
307
- end
308
-
309
- context "pop" do
310
- setup do
311
- @page = @page_class.create(:title => 'Home', :tags => %w(foo bar))
312
- end
313
-
314
- should "be able to remove the last element the array" do
315
- @page_class.pop(@page.id, :tags => 1)
316
- @page.reload
317
- @page.tags.should == %w(foo)
318
- end
319
-
320
- should "be able to remove the first element of the array" do
321
- @page_class.pop(@page.id, :tags => -1)
322
- @page.reload
323
- @page.tags.should == %w(bar)
324
- end
325
- end
326
- end
327
-
328
- context "InstanceMethods" do
329
- should "be able to unset with keys" do
330
- page = @page_class.create(:title => 'Foo', :tags => %w(foo))
331
- page.unset(:title, :tags)
332
- assert_keys_removed page, :title, :tags
333
- end
334
-
335
- should "be able to increment with modifier hashes" do
336
- page = @page_class.create
337
- page.increment(:day_count => 1, :week_count => 2, :month_count => 3)
338
-
339
- assert_page_counts page, 1, 2, 3
340
- end
341
-
342
- should "be able to decrement with modifier hashes" do
343
- page = @page_class.create(:day_count => 1, :week_count => 2, :month_count => 3)
344
- page.decrement(:day_count => 1, :week_count => 2, :month_count => 3)
345
-
346
- assert_page_counts page, 0, 0, 0
347
- end
348
-
349
- should "always decrement when decrement is called whether number is positive or negative" do
350
- page = @page_class.create(:day_count => 1, :week_count => 2, :month_count => 3)
351
- page.decrement(:day_count => -1, :week_count => 2, :month_count => -3)
352
-
353
- assert_page_counts page, 0, 0, 0
354
- end
355
-
356
- should "be able to set with modifier hashes" do
357
- page = @page_class.create(:title => 'Home')
358
- page.set(:title => 'Home Revised')
359
-
360
- page.reload
361
- page.title.should == 'Home Revised'
362
- end
363
-
364
- should "be able to push with modifier hashes" do
365
- page = @page_class.create
366
- page.push(:tags => 'foo')
367
-
368
- page.reload
369
- page.tags.should == %w(foo)
370
- end
371
-
372
- should "be able to pull with criteria and modifier hashes" do
373
- page = @page_class.create(:tags => %w(foo bar))
374
- page.pull(:tags => 'foo')
375
-
376
- page.reload
377
- page.tags.should == %w(bar)
378
- end
379
-
380
- should "be able to add_to_set with criteria and modifier hash" do
381
- page = @page_class.create(:tags => 'foo')
382
- page2 = @page_class.create
383
-
384
- page.add_to_set(:tags => 'foo')
385
- page.add_to_set(:tags => 'foo')
386
-
387
- page.reload
388
- page.tags.should == %w(foo)
389
-
390
- page2.reload
391
- page.tags.should == %w(foo)
392
- end
393
-
394
- should "be able to push uniq with criteria and modifier hash" do
395
- page = @page_class.create(:tags => 'foo')
396
- page2 = @page_class.create
397
-
398
- page.push_uniq(:tags => 'foo')
399
- page.push_uniq(:tags => 'foo')
400
-
401
- page.reload
402
- page.tags.should == %w(foo)
403
-
404
- page2.reload
405
- page.tags.should == %w(foo)
406
- end
407
-
408
- should "be able to pop with modifier hashes" do
409
- page = @page_class.create(:tags => %w(foo bar))
410
- page.pop(:tags => 1)
411
-
412
- page.reload
413
- page.tags.should == %w(foo)
414
- end
415
- end
416
- end