mongo_mapper 0.7.5 → 0.7.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. data/lib/mongo_mapper.rb +3 -5
  2. data/lib/mongo_mapper/document.rb +23 -53
  3. data/lib/mongo_mapper/plugins/associations.rb +1 -1
  4. data/lib/mongo_mapper/plugins/associations/base.rb +4 -4
  5. data/lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb +1 -1
  6. data/lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb +1 -1
  7. data/lib/mongo_mapper/plugins/associations/many_documents_proxy.rb +1 -1
  8. data/lib/mongo_mapper/plugins/associations/one_proxy.rb +1 -1
  9. data/lib/mongo_mapper/plugins/equality.rb +3 -3
  10. data/lib/mongo_mapper/plugins/identity_map.rb +8 -7
  11. data/lib/mongo_mapper/plugins/keys.rb +49 -73
  12. data/lib/mongo_mapper/plugins/keys/key.rb +44 -0
  13. data/lib/mongo_mapper/plugins/modifiers.rb +9 -5
  14. data/lib/mongo_mapper/plugins/pagination/proxy.rb +3 -3
  15. data/lib/mongo_mapper/plugins/serialization.rb +3 -3
  16. data/lib/mongo_mapper/plugins/timestamps.rb +1 -1
  17. data/lib/mongo_mapper/plugins/validations.rb +2 -2
  18. data/lib/mongo_mapper/query.rb +9 -129
  19. data/lib/mongo_mapper/support.rb +17 -39
  20. data/lib/mongo_mapper/version.rb +1 -1
  21. metadata +54 -140
  22. data/.gitignore +0 -10
  23. data/Rakefile +0 -37
  24. data/mongo_mapper.gemspec +0 -214
  25. data/performance/read_write.rb +0 -52
  26. data/specs.watchr +0 -51
  27. data/test/NOTE_ON_TESTING +0 -1
  28. data/test/active_model_lint_test.rb +0 -13
  29. data/test/functional/associations/test_belongs_to_polymorphic_proxy.rb +0 -63
  30. data/test/functional/associations/test_belongs_to_proxy.rb +0 -101
  31. data/test/functional/associations/test_in_array_proxy.rb +0 -325
  32. data/test/functional/associations/test_many_documents_as_proxy.rb +0 -229
  33. data/test/functional/associations/test_many_documents_proxy.rb +0 -536
  34. data/test/functional/associations/test_many_embedded_polymorphic_proxy.rb +0 -176
  35. data/test/functional/associations/test_many_embedded_proxy.rb +0 -256
  36. data/test/functional/associations/test_many_polymorphic_proxy.rb +0 -302
  37. data/test/functional/associations/test_one_embedded_proxy.rb +0 -68
  38. data/test/functional/associations/test_one_proxy.rb +0 -196
  39. data/test/functional/test_associations.rb +0 -44
  40. data/test/functional/test_binary.rb +0 -27
  41. data/test/functional/test_callbacks.rb +0 -151
  42. data/test/functional/test_dirty.rb +0 -163
  43. data/test/functional/test_document.rb +0 -1219
  44. data/test/functional/test_embedded_document.rb +0 -210
  45. data/test/functional/test_identity_map.rb +0 -507
  46. data/test/functional/test_indexing.rb +0 -44
  47. data/test/functional/test_logger.rb +0 -20
  48. data/test/functional/test_modifiers.rb +0 -394
  49. data/test/functional/test_pagination.rb +0 -93
  50. data/test/functional/test_protected.rb +0 -163
  51. data/test/functional/test_string_id_compatibility.rb +0 -67
  52. data/test/functional/test_timestamps.rb +0 -64
  53. data/test/functional/test_userstamps.rb +0 -28
  54. data/test/functional/test_validations.rb +0 -342
  55. data/test/models.rb +0 -227
  56. data/test/support/custom_matchers.rb +0 -37
  57. data/test/support/timing.rb +0 -16
  58. data/test/test_helper.rb +0 -64
  59. data/test/unit/associations/test_base.rb +0 -212
  60. data/test/unit/associations/test_proxy.rb +0 -105
  61. data/test/unit/serializers/test_json_serializer.rb +0 -202
  62. data/test/unit/test_descendant_appends.rb +0 -71
  63. data/test/unit/test_document.rb +0 -225
  64. data/test/unit/test_dynamic_finder.rb +0 -123
  65. data/test/unit/test_embedded_document.rb +0 -657
  66. data/test/unit/test_keys.rb +0 -185
  67. data/test/unit/test_mongo_mapper.rb +0 -118
  68. data/test/unit/test_pagination.rb +0 -160
  69. data/test/unit/test_plugins.rb +0 -50
  70. data/test/unit/test_query.rb +0 -374
  71. data/test/unit/test_rails.rb +0 -181
  72. data/test/unit/test_rails_compatibility.rb +0 -52
  73. data/test/unit/test_serialization.rb +0 -51
  74. data/test/unit/test_support.rb +0 -382
  75. data/test/unit/test_time_zones.rb +0 -39
  76. 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,394 +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
- end
123
-
124
- context "push" do
125
- setup do
126
- @page = @page_class.create(:title => 'Home')
127
- @page2 = @page_class.create(:title => 'Home')
128
- end
129
-
130
- should "work with criteria and modifier hashes" do
131
- @page_class.push({:title => 'Home'}, :tags => 'foo')
132
-
133
- @page.reload
134
- @page.tags.should == %w(foo)
135
-
136
- @page2.reload
137
- @page.tags.should == %w(foo)
138
- end
139
-
140
- should "work with ids and modifier hash" do
141
- @page_class.push(@page.id, @page2.id, :tags => 'foo')
142
-
143
- @page.reload
144
- @page.tags.should == %w(foo)
145
-
146
- @page2.reload
147
- @page.tags.should == %w(foo)
148
- end
149
- end
150
-
151
- context "push_all" do
152
- setup do
153
- @page = @page_class.create(:title => 'Home')
154
- @page2 = @page_class.create(:title => 'Home')
155
- @tags = %w(foo bar)
156
- end
157
-
158
- should "work with criteria and modifier hashes" do
159
- @page_class.push_all({:title => 'Home'}, :tags => @tags)
160
-
161
- @page.reload
162
- @page.tags.should == @tags
163
-
164
- @page2.reload
165
- @page.tags.should == @tags
166
- end
167
-
168
- should "work with ids and modifier hash" do
169
- @page_class.push_all(@page.id, @page2.id, :tags => @tags)
170
-
171
- @page.reload
172
- @page.tags.should == @tags
173
-
174
- @page2.reload
175
- @page.tags.should == @tags
176
- end
177
- end
178
-
179
- context "pull" do
180
- setup do
181
- @page = @page_class.create(:title => 'Home', :tags => %w(foo bar))
182
- @page2 = @page_class.create(:title => 'Home', :tags => %w(foo bar))
183
- end
184
-
185
- should "work with criteria and modifier hashes" do
186
- @page_class.pull({:title => 'Home'}, :tags => 'foo')
187
-
188
- @page.reload
189
- @page.tags.should == %w(bar)
190
-
191
- @page2.reload
192
- @page.tags.should == %w(bar)
193
- end
194
-
195
- should "be able to pull with ids and modifier hash" do
196
- @page_class.pull(@page.id, @page2.id, :tags => 'foo')
197
-
198
- @page.reload
199
- @page.tags.should == %w(bar)
200
-
201
- @page2.reload
202
- @page.tags.should == %w(bar)
203
- end
204
- end
205
-
206
- context "pull_all" do
207
- setup do
208
- @page = @page_class.create(:title => 'Home', :tags => %w(foo bar baz))
209
- @page2 = @page_class.create(:title => 'Home', :tags => %w(foo bar baz))
210
- end
211
-
212
- should "work with criteria and modifier hashes" do
213
- @page_class.pull_all({:title => 'Home'}, :tags => %w(foo bar))
214
-
215
- @page.reload
216
- @page.tags.should == %w(baz)
217
-
218
- @page2.reload
219
- @page.tags.should == %w(baz)
220
- end
221
-
222
- should "work with ids and modifier hash" do
223
- @page_class.pull_all(@page.id, @page2.id, :tags => %w(foo bar))
224
-
225
- @page.reload
226
- @page.tags.should == %w(baz)
227
-
228
- @page2.reload
229
- @page.tags.should == %w(baz)
230
- end
231
- end
232
-
233
- context "add_to_set" do
234
- setup do
235
- @page = @page_class.create(:title => 'Home', :tags => 'foo')
236
- @page2 = @page_class.create(:title => 'Home')
237
- end
238
-
239
- should "be able to add to set with criteria and modifier hash" do
240
- @page_class.add_to_set({:title => 'Home'}, :tags => 'foo')
241
-
242
- @page.reload
243
- @page.tags.should == %w(foo)
244
-
245
- @page2.reload
246
- @page.tags.should == %w(foo)
247
- end
248
-
249
- should "be able to add to set with ids and modifier hash" do
250
- @page_class.add_to_set(@page.id, @page2.id, :tags => 'foo')
251
-
252
- @page.reload
253
- @page.tags.should == %w(foo)
254
-
255
- @page2.reload
256
- @page.tags.should == %w(foo)
257
- end
258
- end
259
-
260
- context "push_uniq" do
261
- setup do
262
- @page = @page_class.create(:title => 'Home', :tags => 'foo')
263
- @page2 = @page_class.create(:title => 'Home')
264
- end
265
-
266
- should "be able to push uniq with criteria and modifier hash" do
267
- @page_class.push_uniq({:title => 'Home'}, :tags => 'foo')
268
-
269
- @page.reload
270
- @page.tags.should == %w(foo)
271
-
272
- @page2.reload
273
- @page.tags.should == %w(foo)
274
- end
275
-
276
- should "be able to push uniq with ids and modifier hash" do
277
- @page_class.push_uniq(@page.id, @page2.id, :tags => 'foo')
278
-
279
- @page.reload
280
- @page.tags.should == %w(foo)
281
-
282
- @page2.reload
283
- @page.tags.should == %w(foo)
284
- end
285
- end
286
-
287
- context "pop" do
288
- setup do
289
- @page = @page_class.create(:title => 'Home', :tags => %w(foo bar))
290
- end
291
-
292
- should "be able to remove the last element the array" do
293
- @page_class.pop(@page.id, :tags => 1)
294
- @page.reload
295
- @page.tags.should == %w(foo)
296
- end
297
-
298
- should "be able to remove the first element of the array" do
299
- @page_class.pop(@page.id, :tags => -1)
300
- @page.reload
301
- @page.tags.should == %w(bar)
302
- end
303
- end
304
- end
305
-
306
- context "InstanceMethods" do
307
- should "be able to unset with keys" do
308
- page = @page_class.create(:title => 'Foo', :tags => %w(foo))
309
- page.unset(:title, :tags)
310
- assert_keys_removed page, :title, :tags
311
- end
312
-
313
- should "be able to increment with modifier hashes" do
314
- page = @page_class.create
315
- page.increment(:day_count => 1, :week_count => 2, :month_count => 3)
316
-
317
- assert_page_counts page, 1, 2, 3
318
- end
319
-
320
- should "be able to decrement with modifier hashes" do
321
- page = @page_class.create(:day_count => 1, :week_count => 2, :month_count => 3)
322
- page.decrement(:day_count => 1, :week_count => 2, :month_count => 3)
323
-
324
- assert_page_counts page, 0, 0, 0
325
- end
326
-
327
- should "always decrement when decrement is called whether number is positive or negative" do
328
- page = @page_class.create(:day_count => 1, :week_count => 2, :month_count => 3)
329
- page.decrement(:day_count => -1, :week_count => 2, :month_count => -3)
330
-
331
- assert_page_counts page, 0, 0, 0
332
- end
333
-
334
- should "be able to set with modifier hashes" do
335
- page = @page_class.create(:title => 'Home')
336
- page.set(:title => 'Home Revised')
337
-
338
- page.reload
339
- page.title.should == 'Home Revised'
340
- end
341
-
342
- should "be able to push with modifier hashes" do
343
- page = @page_class.create
344
- page.push(:tags => 'foo')
345
-
346
- page.reload
347
- page.tags.should == %w(foo)
348
- end
349
-
350
- should "be able to pull with criteria and modifier hashes" do
351
- page = @page_class.create(:tags => %w(foo bar))
352
- page.pull(:tags => 'foo')
353
-
354
- page.reload
355
- page.tags.should == %w(bar)
356
- end
357
-
358
- should "be able to add_to_set with criteria and modifier hash" do
359
- page = @page_class.create(:tags => 'foo')
360
- page2 = @page_class.create
361
-
362
- page.add_to_set(:tags => 'foo')
363
- page.add_to_set(:tags => 'foo')
364
-
365
- page.reload
366
- page.tags.should == %w(foo)
367
-
368
- page2.reload
369
- page.tags.should == %w(foo)
370
- end
371
-
372
- should "be able to push uniq with criteria and modifier hash" do
373
- page = @page_class.create(:tags => 'foo')
374
- page2 = @page_class.create
375
-
376
- page.push_uniq(:tags => 'foo')
377
- page.push_uniq(:tags => 'foo')
378
-
379
- page.reload
380
- page.tags.should == %w(foo)
381
-
382
- page2.reload
383
- page.tags.should == %w(foo)
384
- end
385
-
386
- should "be able to pop with modifier hashes" do
387
- page = @page_class.create(:tags => %w(foo bar))
388
- page.pop(:tags => 1)
389
-
390
- page.reload
391
- page.tags.should == %w(foo)
392
- end
393
- end
394
- end