mongo_mapper-rails3 0.7.0.1 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. data/README.rdoc +8 -37
  2. metadata +16 -284
  3. data/.gitignore +0 -10
  4. data/Gemfile +0 -15
  5. data/LICENSE +0 -20
  6. data/Rakefile +0 -58
  7. data/VERSION +0 -1
  8. data/bin/mmconsole +0 -60
  9. data/lib/mongo_mapper.rb +0 -131
  10. data/lib/mongo_mapper/document.rb +0 -439
  11. data/lib/mongo_mapper/embedded_document.rb +0 -68
  12. data/lib/mongo_mapper/plugins.rb +0 -30
  13. data/lib/mongo_mapper/plugins/associations.rb +0 -106
  14. data/lib/mongo_mapper/plugins/associations/base.rb +0 -123
  15. data/lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb +0 -30
  16. data/lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb +0 -25
  17. data/lib/mongo_mapper/plugins/associations/collection.rb +0 -21
  18. data/lib/mongo_mapper/plugins/associations/embedded_collection.rb +0 -50
  19. data/lib/mongo_mapper/plugins/associations/in_array_proxy.rb +0 -141
  20. data/lib/mongo_mapper/plugins/associations/many_documents_as_proxy.rb +0 -28
  21. data/lib/mongo_mapper/plugins/associations/many_documents_proxy.rb +0 -120
  22. data/lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb +0 -31
  23. data/lib/mongo_mapper/plugins/associations/many_embedded_proxy.rb +0 -23
  24. data/lib/mongo_mapper/plugins/associations/many_polymorphic_proxy.rb +0 -13
  25. data/lib/mongo_mapper/plugins/associations/one_proxy.rb +0 -68
  26. data/lib/mongo_mapper/plugins/associations/proxy.rb +0 -119
  27. data/lib/mongo_mapper/plugins/callbacks.rb +0 -87
  28. data/lib/mongo_mapper/plugins/clone.rb +0 -14
  29. data/lib/mongo_mapper/plugins/descendants.rb +0 -17
  30. data/lib/mongo_mapper/plugins/dirty.rb +0 -120
  31. data/lib/mongo_mapper/plugins/equality.rb +0 -24
  32. data/lib/mongo_mapper/plugins/identity_map.rb +0 -124
  33. data/lib/mongo_mapper/plugins/inspect.rb +0 -15
  34. data/lib/mongo_mapper/plugins/keys.rb +0 -310
  35. data/lib/mongo_mapper/plugins/logger.rb +0 -19
  36. data/lib/mongo_mapper/plugins/pagination.rb +0 -26
  37. data/lib/mongo_mapper/plugins/pagination/proxy.rb +0 -72
  38. data/lib/mongo_mapper/plugins/protected.rb +0 -46
  39. data/lib/mongo_mapper/plugins/rails.rb +0 -46
  40. data/lib/mongo_mapper/plugins/serialization.rb +0 -50
  41. data/lib/mongo_mapper/plugins/validations.rb +0 -88
  42. data/lib/mongo_mapper/query.rb +0 -130
  43. data/lib/mongo_mapper/support.rb +0 -217
  44. data/lib/mongo_mapper/support/descendant_appends.rb +0 -46
  45. data/lib/mongo_mapper/support/find.rb +0 -77
  46. data/mongo_mapper-rails3.gemspec +0 -208
  47. data/performance/read_write.rb +0 -52
  48. data/specs.watchr +0 -51
  49. data/test/NOTE_ON_TESTING +0 -1
  50. data/test/functional/associations/test_belongs_to_polymorphic_proxy.rb +0 -63
  51. data/test/functional/associations/test_belongs_to_proxy.rb +0 -101
  52. data/test/functional/associations/test_in_array_proxy.rb +0 -321
  53. data/test/functional/associations/test_many_documents_as_proxy.rb +0 -229
  54. data/test/functional/associations/test_many_documents_proxy.rb +0 -453
  55. data/test/functional/associations/test_many_embedded_polymorphic_proxy.rb +0 -176
  56. data/test/functional/associations/test_many_embedded_proxy.rb +0 -256
  57. data/test/functional/associations/test_many_polymorphic_proxy.rb +0 -302
  58. data/test/functional/associations/test_one_proxy.rb +0 -161
  59. data/test/functional/test_associations.rb +0 -44
  60. data/test/functional/test_binary.rb +0 -27
  61. data/test/functional/test_callbacks.rb +0 -81
  62. data/test/functional/test_dirty.rb +0 -163
  63. data/test/functional/test_document.rb +0 -1244
  64. data/test/functional/test_embedded_document.rb +0 -125
  65. data/test/functional/test_identity_map.rb +0 -508
  66. data/test/functional/test_logger.rb +0 -20
  67. data/test/functional/test_modifiers.rb +0 -252
  68. data/test/functional/test_pagination.rb +0 -93
  69. data/test/functional/test_protected.rb +0 -161
  70. data/test/functional/test_string_id_compatibility.rb +0 -67
  71. data/test/functional/test_validations.rb +0 -329
  72. data/test/models.rb +0 -232
  73. data/test/support/custom_matchers.rb +0 -55
  74. data/test/support/timing.rb +0 -16
  75. data/test/test_helper.rb +0 -59
  76. data/test/unit/associations/test_base.rb +0 -207
  77. data/test/unit/associations/test_proxy.rb +0 -105
  78. data/test/unit/serializers/test_json_serializer.rb +0 -189
  79. data/test/unit/test_descendant_appends.rb +0 -71
  80. data/test/unit/test_document.rb +0 -231
  81. data/test/unit/test_dynamic_finder.rb +0 -123
  82. data/test/unit/test_embedded_document.rb +0 -663
  83. data/test/unit/test_keys.rb +0 -169
  84. data/test/unit/test_lint.rb +0 -8
  85. data/test/unit/test_mongo_mapper.rb +0 -125
  86. data/test/unit/test_pagination.rb +0 -160
  87. data/test/unit/test_plugins.rb +0 -51
  88. data/test/unit/test_query.rb +0 -334
  89. data/test/unit/test_rails.rb +0 -123
  90. data/test/unit/test_rails_compatibility.rb +0 -57
  91. data/test/unit/test_serialization.rb +0 -51
  92. data/test/unit/test_support.rb +0 -362
  93. data/test/unit/test_time_zones.rb +0 -39
  94. data/test/unit/test_validations.rb +0 -557
@@ -1,39 +0,0 @@
1
- require 'test_helper'
2
-
3
- class TimeZonesTest < Test::Unit::TestCase
4
- context "An instance of an embedded document" do
5
- setup do
6
- @document = EDoc do
7
- key :name, String
8
- key :created_at, Time
9
- end
10
- end
11
-
12
- should "work without Time.zone" do
13
- Time.zone = nil
14
-
15
- doc = @document.new(:created_at => "2009-08-15 14:00:00")
16
- doc.created_at.should == Time.local(2009, 8, 15, 14, 0, 0).utc
17
- end
18
-
19
- should "work with Time.zone set to the (default) UTC" do
20
- Time.zone = 'UTC'
21
-
22
- doc = @document.new(:created_at => "2009-08-15 14:00:00")
23
- doc.created_at.is_a?(ActiveSupport::TimeWithZone).should be_true
24
- doc.created_at.should == Time.utc(2009, 8, 15, 14)
25
-
26
- Time.zone = nil
27
- end
28
-
29
- should "work with timezones that are not UTC" do
30
- Time.zone = 'Hawaii'
31
-
32
- doc = @document.new(:created_at => "2009-08-15 14:00:00")
33
- doc.created_at.is_a?(ActiveSupport::TimeWithZone).should be_true
34
- doc.created_at.should == Time.utc(2009, 8, 16)
35
-
36
- Time.zone = nil
37
- end
38
- end
39
- end
@@ -1,557 +0,0 @@
1
- require 'test_helper'
2
-
3
- module MongoMapper::EmbeddedDocument
4
- include MongoMapper::Document::InstanceMethods
5
- end
6
-
7
- class ValidationsTest < Test::Unit::TestCase
8
- context "Validations" do
9
- context "on a Document" do
10
- setup do
11
- @document = Doc()
12
- end
13
-
14
- context "Validating acceptance of" do
15
- should "work with validates_acceptance_of macro" do
16
- @document.key :terms, String
17
- @document.validates_acceptance_of :terms
18
- doc = @document.new(:terms => '')
19
- doc.should have_error_on(:terms)
20
- doc.terms = '1'
21
- doc.should_not have_error_on(:terms)
22
- end
23
- end
24
-
25
- context "validating confirmation of" do
26
- should "work with validates_confirmation_of macro" do
27
- @document.key :password, String
28
- @document.validates_confirmation_of :password
29
- doc = @document.new
30
- doc.password = 'foobar'
31
- doc.password_confirmation = 'gfg'
32
- doc.should have_error_on(:password)
33
- doc.password_confirmation = 'foobar'
34
- doc.should_not have_error_on(:password)
35
- end
36
- end
37
-
38
- context "validating format of" do
39
- should "work with validates_format_of macro" do
40
- @document.key :name, String
41
- @document.validates_format_of :name, :with => /.+/
42
- doc = @document.new
43
- doc.should have_error_on(:name)
44
- doc.name = 'John'
45
- doc.should_not have_error_on(:name)
46
- end
47
-
48
- should "work with :format shorcut key" do
49
- @document.key :name, String, :format => /.+/
50
- doc = @document.new
51
- doc.should have_error_on(:name)
52
- doc.name = 'John'
53
- doc.should_not have_error_on(:name)
54
- end
55
- end
56
-
57
- context "validating length of" do
58
- should "work with validates_length_of macro" do
59
- @document.key :name, String
60
- @document.validates_length_of :name, :minimum => 5
61
- doc = @document.new
62
- doc.should have_error_on(:name)
63
- end
64
-
65
- context "with :length => integer shortcut" do
66
- should "set maximum of integer provided" do
67
- @document.key :name, String, :length => 5
68
- doc = @document.new
69
- doc.name = '123456'
70
- doc.should have_error_on(:name)
71
- doc.name = '12345'
72
- doc.should_not have_error_on(:name)
73
- end
74
- end
75
-
76
- context "with :length => range shortcut" do
77
- setup do
78
- @document.key :name, String, :length => 5..7
79
- end
80
-
81
- should "set minimum of range min" do
82
- doc = @document.new
83
- doc.should have_error_on(:name)
84
- doc.name = '123456'
85
- doc.should_not have_error_on(:name)
86
- end
87
-
88
- should "set maximum of range max" do
89
- doc = @document.new
90
- doc.should have_error_on(:name)
91
- doc.name = '12345678'
92
- doc.should have_error_on(:name)
93
- doc.name = '123456'
94
- doc.should_not have_error_on(:name)
95
- end
96
- end
97
-
98
- context "with :length => hash shortcut" do
99
- should "pass options through" do
100
- @document.key :name, String, :length => {:minimum => 2}
101
- doc = @document.new
102
- doc.should have_error_on(:name)
103
- doc.name = '12'
104
- doc.should_not have_error_on(:name)
105
- end
106
- end
107
- end # validates_length_of
108
-
109
- context "Validating numericality of" do
110
- should "work with validates_numericality_of macro" do
111
- @document.key :age, Integer
112
- @document.validates_numericality_of :age
113
- doc = @document.new
114
- doc.age = 'String'
115
- doc.should have_error_on(:age)
116
- doc.age = 23
117
- doc.should_not have_error_on(:age)
118
- end
119
-
120
- # doesn't work cause MM casts 'String' to 0.0
121
- # context "with :numeric shortcut" do
122
- # should "work with integer or float" do
123
- # puts 'before'
124
- # @document.key :weight, Float, :numeric => true
125
- # @document.validates_numericality_of :weight
126
- # puts 'after'
127
- # doc = @document.new
128
- # doc.weight = 'String'
129
- # puts doc.valid?
130
- # puts doc.save
131
- # puts doc.weight
132
- # doc.should have_error_on(:weight)
133
- # doc.weight = 23.0
134
- # doc.should_not have_error_on(:weight)
135
- # doc.weight = 23
136
- # doc.should_not have_error_on(:weight)
137
- # end
138
- # end
139
-
140
- # context "with :numeric shortcut on Integer key" do
141
- # should "only work with integers" do
142
- # @document.key :age, Integer, :numeric => true
143
- # doc = @document.new
144
- # doc.age = 'String'
145
- # doc.should have_error_on(:age)
146
- # doc.age = 23.1
147
- # doc.should have_error_on(:age)
148
- # doc.age = 23
149
- # doc.should_not have_error_on(:age)
150
- # end
151
- # end
152
- end # numericality of
153
-
154
- context "validating presence of" do
155
- should "work with validates_presence_of macro" do
156
- @document.key :name, String
157
- @document.validates_presence_of :name
158
- doc = @document.new
159
- doc.should have_error_on(:name)
160
- end
161
-
162
- should "work with :required shortcut on key definition" do
163
- @document.key :name, String, :required => true
164
- doc = @document.new
165
- doc.should have_error_on(:name)
166
- end
167
- end
168
-
169
- context "validating exclusion of" do
170
- should "throw error if enumerator not provided" do
171
- @document.key :action, String
172
- lambda {
173
- @document.validates_exclusion_of :action
174
- }.should raise_error(ArgumentError)
175
- end
176
-
177
- should "work with validates_exclusion_of macro" do
178
- @document.key :action, String
179
- @document.validates_exclusion_of :action, :within => %w(kick run)
180
-
181
- doc = @document.new
182
- doc.should_not have_error_on(:action)
183
-
184
- doc.action = 'fart'
185
- doc.should_not have_error_on(:action)
186
-
187
- doc.action = 'kick'
188
- doc.should have_error_on(:action, 'is reserved')
189
- end
190
-
191
- should "work with :not_in shortcut on key definition" do
192
- @document.key :action, String, :not_in => %w(kick run)
193
-
194
- doc = @document.new
195
- doc.should_not have_error_on(:action)
196
-
197
- doc.action = 'fart'
198
- doc.should_not have_error_on(:action)
199
-
200
- doc.action = 'kick'
201
- doc.should have_error_on(:action, 'is reserved')
202
- end
203
-
204
- should "not have error if allow nil is true and value is nil" do
205
- @document.key :action, String
206
- @document.validates_exclusion_of :action, :within => %w(kick run), :allow_nil => true
207
-
208
- doc = @document.new
209
- doc.should_not have_error_on(:action)
210
- end
211
-
212
- should "not have error if allow blank is true and value is blank" do
213
- @document.key :action, String
214
- @document.validates_exclusion_of :action, :within => %w(kick run), :allow_nil => true
215
-
216
- doc = @document.new(:action => '')
217
- doc.should_not have_error_on(:action)
218
- end
219
- end
220
-
221
- context "validating inclusion of" do
222
- should "throw error if enumerator not provided" do
223
- @document.key :action, String
224
- lambda {
225
- @document.validates_inclusion_of :action
226
- }.should raise_error(ArgumentError)
227
- end
228
-
229
- should "work with validates_inclusion_of macro" do
230
- @document.key :action, String
231
- @document.validates_inclusion_of :action, :within => %w(kick run)
232
-
233
- doc = @document.new
234
- doc.should have_error_on(:action, 'is not included in the list')
235
-
236
- doc.action = 'fart'
237
- doc.should have_error_on(:action, 'is not included in the list')
238
-
239
- doc.action = 'kick'
240
- doc.should_not have_error_on(:action)
241
- end
242
-
243
- should "work with :in shortcut on key definition" do
244
- @document.key :action, String, :in => %w(kick run)
245
-
246
- doc = @document.new
247
- doc.should have_error_on(:action, 'is not included in the list')
248
-
249
- doc.action = 'fart'
250
- doc.should have_error_on(:action, 'is not included in the list')
251
-
252
- doc.action = 'kick'
253
- doc.should_not have_error_on(:action)
254
- end
255
-
256
- should "not have error if allow nil is true and value is nil" do
257
- @document.key :action, String
258
- @document.validates_inclusion_of :action, :within => %w(kick run), :allow_nil => true
259
-
260
- doc = @document.new
261
- doc.should_not have_error_on(:action)
262
- end
263
-
264
- should "not have error if allow blank is true and value is blank" do
265
- @document.key :action, String
266
- @document.validates_inclusion_of :action, :within => %w(kick run), :allow_blank => true
267
-
268
- doc = @document.new(:action => '')
269
- doc.should_not have_error_on(:action)
270
- end
271
- end
272
-
273
- end # End on a Document
274
-
275
- context "On an EmbeddedDocument" do
276
- setup do
277
- @embedded_doc = EDoc()
278
- end
279
-
280
- context "Validating acceptance of" do
281
- should "work with validates_acceptance_of macro" do
282
- @embedded_doc.key :terms, String
283
- @embedded_doc.validates_acceptance_of :terms
284
- doc = @embedded_doc.new(:terms => '')
285
- doc.should have_error_on(:terms)
286
- doc.terms = '1'
287
- doc.should_not have_error_on(:terms)
288
- end
289
- end
290
-
291
- context "validating confirmation of" do
292
- should "work with validates_confirmation_of macro" do
293
- @embedded_doc.key :password, String
294
- @embedded_doc.validates_confirmation_of :password
295
- doc = @embedded_doc.new
296
- doc.password = 'foobar'
297
- doc.password_confirmation = 'fgfg'
298
- doc.should have_error_on(:password)
299
- doc.password_confirmation = 'foobar'
300
- doc.should_not have_error_on(:password)
301
- end
302
- end
303
-
304
- context "validating format of" do
305
- should "work with validates_format_of macro" do
306
- @embedded_doc.key :name, String
307
- @embedded_doc.validates_format_of :name, :with => /.+/
308
- doc = @embedded_doc.new
309
- doc.should have_error_on(:name)
310
- doc.name = 'John'
311
- doc.should_not have_error_on(:name)
312
- end
313
-
314
- should "work with :format shorcut key" do
315
- @embedded_doc.key :name, String, :format => /.+/
316
- doc = @embedded_doc.new
317
- doc.should have_error_on(:name)
318
- doc.name = 'John'
319
- doc.should_not have_error_on(:name)
320
- end
321
- end
322
-
323
- context "validating length of" do
324
- should "work with validates_length_of macro" do
325
- @embedded_doc.key :name, String
326
- @embedded_doc.validates_length_of :name, :minimum => 5
327
- doc = @embedded_doc.new
328
- doc.should have_error_on(:name)
329
- end
330
-
331
- context "with :length => integer shortcut" do
332
- should "set maximum of integer provided" do
333
- @embedded_doc.key :name, String, :length => 5
334
- doc = @embedded_doc.new
335
- doc.name = '123456'
336
- doc.should have_error_on(:name)
337
- doc.name = '12345'
338
- doc.should_not have_error_on(:name)
339
- end
340
- end
341
-
342
- context "with :length => range shortcut" do
343
- setup do
344
- @embedded_doc.key :name, String, :length => 5..7
345
- end
346
-
347
- should "set minimum of range min" do
348
- doc = @embedded_doc.new
349
- doc.should have_error_on(:name)
350
- doc.name = '123456'
351
- doc.should_not have_error_on(:name)
352
- end
353
-
354
- should "set maximum of range max" do
355
- doc = @embedded_doc.new
356
- doc.should have_error_on(:name)
357
- doc.name = '12345678'
358
- doc.should have_error_on(:name)
359
- doc.name = '123456'
360
- doc.should_not have_error_on(:name)
361
- end
362
- end
363
-
364
- context "with :length => hash shortcut" do
365
- should "pass options through" do
366
- @embedded_doc.key :name, String, :length => {:minimum => 2}
367
- doc = @embedded_doc.new
368
- doc.should have_error_on(:name)
369
- doc.name = '12'
370
- doc.should_not have_error_on(:name)
371
- end
372
- end
373
- end # validates_length_of
374
-
375
- context "Validating numericality of" do
376
- should "work with validates_numericality_of macro" do
377
- @embedded_doc.key :age, Integer
378
- @embedded_doc.validates_numericality_of :age
379
- doc = @embedded_doc.new
380
- doc.age = 'String'
381
- doc.should have_error_on(:age)
382
- doc.age = 23
383
- doc.should_not have_error_on(:age)
384
- end
385
-
386
- # context "with :numeric shortcut" do
387
- # should "work with integer or float" do
388
- # @embedded_doc.key :weight, Float, :numeric => true
389
- # doc = @embedded_doc.new
390
- # doc.weight = 'String'
391
- # doc.should have_error_on(:weight)
392
- # doc.weight = 23.0
393
- # doc.should_not have_error_on(:weight)
394
- # doc.weight = 23
395
- # doc.should_not have_error_on(:weight)
396
- # end
397
- # end
398
-
399
- # context "with :numeric shortcut on Integer key" do
400
- # should "only work with integers" do
401
- # @embedded_doc.key :age, Integer, :numeric => true
402
- # doc = @embedded_doc.new
403
- # doc.age = 'String'
404
- # doc.should have_error_on(:age)
405
- # doc.age = 23.1
406
- # doc.should have_error_on(:age)
407
- # doc.age = 23
408
- # doc.should_not have_error_on(:age)
409
- # end
410
- # end
411
- end # numericality of
412
-
413
- context "validating presence of" do
414
- should "work with validates_presence_of macro" do
415
- @embedded_doc.key :name, String
416
- @embedded_doc.validates_presence_of :name
417
- doc = @embedded_doc.new
418
- doc.should have_error_on(:name)
419
- end
420
-
421
- should "work with :required shortcut on key definition" do
422
- @embedded_doc.key :name, String, :required => true
423
- doc = @embedded_doc.new
424
- doc.should have_error_on(:name)
425
- end
426
- end
427
-
428
- context "validating exclusion of" do
429
- should "throw error if enumerator not provided" do
430
- @embedded_doc.key :action, String
431
- lambda {
432
- @embedded_doc.validates_exclusion_of :action
433
- }.should raise_error(ArgumentError)
434
- end
435
-
436
- should "work with validates_exclusion_of macro" do
437
- @embedded_doc.key :action, String
438
- @embedded_doc.validates_exclusion_of :action, :within => %w(kick run)
439
-
440
- doc = @embedded_doc.new
441
- doc.should_not have_error_on(:action)
442
-
443
- doc.action = 'fart'
444
- doc.should_not have_error_on(:action)
445
-
446
- doc.action = 'kick'
447
- doc.should have_error_on(:action, 'is reserved')
448
- end
449
-
450
- should "work with :not_in shortcut on key definition" do
451
- @embedded_doc.key :action, String, :not_in => %w(kick run)
452
-
453
- doc = @embedded_doc.new
454
- doc.should_not have_error_on(:action)
455
-
456
- doc.action = 'fart'
457
- doc.should_not have_error_on(:action)
458
-
459
- doc.action = 'kick'
460
- doc.should have_error_on(:action, 'is reserved')
461
- end
462
-
463
- should "not have error if allow nil is true and value is nil" do
464
- @embedded_doc.key :action, String
465
- @embedded_doc.validates_exclusion_of :action, :within => %w(kick run), :allow_nil => true
466
-
467
- doc = @embedded_doc.new
468
- doc.should_not have_error_on(:action)
469
- end
470
-
471
- should "not have error if allow blank is true and value is blank" do
472
- @embedded_doc.key :action, String
473
- @embedded_doc.validates_exclusion_of :action, :within => %w(kick run), :allow_nil => true
474
-
475
- doc = @embedded_doc.new(:action => '')
476
- doc.should_not have_error_on(:action)
477
- end
478
- end
479
-
480
- context "validating inclusion of" do
481
- should "throw error if enumerator not provided" do
482
- @embedded_doc.key :action, String
483
- lambda {
484
- @embedded_doc.validates_inclusion_of :action
485
- }.should raise_error(ArgumentError)
486
- end
487
-
488
- should "work with validates_inclusion_of macro" do
489
- @embedded_doc.key :action, String
490
- @embedded_doc.validates_inclusion_of :action, :within => %w(kick run)
491
-
492
- doc = @embedded_doc.new
493
- doc.should have_error_on(:action, 'is not included in the list')
494
-
495
- doc.action = 'fart'
496
- doc.should have_error_on(:action, 'is not included in the list')
497
-
498
- doc.action = 'kick'
499
- doc.should_not have_error_on(:action)
500
- end
501
-
502
- should "work with :in shortcut on key definition" do
503
- @embedded_doc.key :action, String, :in => %w(kick run)
504
-
505
- doc = @embedded_doc.new
506
- doc.should have_error_on(:action, 'is not included in the list')
507
-
508
- doc.action = 'fart'
509
- doc.should have_error_on(:action, 'is not included in the list')
510
-
511
- doc.action = 'kick'
512
- doc.should_not have_error_on(:action)
513
- end
514
-
515
- should "not have error if allow nil is true and value is nil" do
516
- @embedded_doc.key :action, String
517
- @embedded_doc.validates_inclusion_of :action, :within => %w(kick run), :allow_nil => true
518
-
519
- doc = @embedded_doc.new
520
- doc.should_not have_error_on(:action)
521
- end
522
-
523
- should "not have error if allow blank is true and value is blank" do
524
- @embedded_doc.key :action, String
525
- @embedded_doc.validates_inclusion_of :action, :within => %w(kick run), :allow_blank => true
526
-
527
- doc = @embedded_doc.new(:action => '')
528
- doc.should_not have_error_on(:action)
529
- end
530
- end
531
-
532
- end # End on an EmbeddedDocument
533
-
534
- end # Validations
535
-
536
- context "Adding validation errors" do
537
- setup do
538
- @document = Doc do
539
- key :action, String
540
- def action_present
541
- errors.add(:action, 'is invalid') if action.blank?
542
- end
543
- end
544
- end
545
-
546
- should "work with validate callback" do
547
- @document.validate :action_present
548
-
549
- doc = @document.new
550
- doc.action = nil
551
- doc.should have_error_on(:action)
552
-
553
- doc.action = 'kick'
554
- doc.should_not have_error_on(:action)
555
- end
556
- end
557
- end