mongo_mapper-unstable 2009.10.11
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +8 -0
- data/LICENSE +20 -0
- data/README.rdoc +50 -0
- data/Rakefile +87 -0
- data/VERSION +1 -0
- data/bin/mmconsole +55 -0
- data/lib/mongo_mapper/associations/base.rb +83 -0
- data/lib/mongo_mapper/associations/belongs_to_polymorphic_proxy.rb +34 -0
- data/lib/mongo_mapper/associations/belongs_to_proxy.rb +22 -0
- data/lib/mongo_mapper/associations/many_documents_as_proxy.rb +27 -0
- data/lib/mongo_mapper/associations/many_documents_proxy.rb +116 -0
- data/lib/mongo_mapper/associations/many_embedded_polymorphic_proxy.rb +33 -0
- data/lib/mongo_mapper/associations/many_embedded_proxy.rb +67 -0
- data/lib/mongo_mapper/associations/many_polymorphic_proxy.rb +11 -0
- data/lib/mongo_mapper/associations/many_proxy.rb +6 -0
- data/lib/mongo_mapper/associations/proxy.rb +74 -0
- data/lib/mongo_mapper/associations.rb +86 -0
- data/lib/mongo_mapper/callbacks.rb +106 -0
- data/lib/mongo_mapper/dirty.rb +137 -0
- data/lib/mongo_mapper/document.rb +340 -0
- data/lib/mongo_mapper/dynamic_finder.rb +35 -0
- data/lib/mongo_mapper/embedded_document.rb +355 -0
- data/lib/mongo_mapper/finder_options.rb +98 -0
- data/lib/mongo_mapper/key.rb +36 -0
- data/lib/mongo_mapper/observing.rb +50 -0
- data/lib/mongo_mapper/pagination.rb +51 -0
- data/lib/mongo_mapper/rails_compatibility/document.rb +15 -0
- data/lib/mongo_mapper/rails_compatibility/embedded_document.rb +27 -0
- data/lib/mongo_mapper/save_with_validation.rb +19 -0
- data/lib/mongo_mapper/serialization.rb +55 -0
- data/lib/mongo_mapper/serializers/json_serializer.rb +92 -0
- data/lib/mongo_mapper/support.rb +161 -0
- data/lib/mongo_mapper/validations.rb +69 -0
- data/lib/mongo_mapper.rb +111 -0
- data/mongo_mapper.gemspec +162 -0
- data/specs.watchr +32 -0
- data/test/NOTE_ON_TESTING +1 -0
- data/test/custom_matchers.rb +55 -0
- data/test/functional/associations/test_belongs_to_polymorphic_proxy.rb +55 -0
- data/test/functional/associations/test_belongs_to_proxy.rb +49 -0
- data/test/functional/associations/test_many_documents_as_proxy.rb +244 -0
- data/test/functional/associations/test_many_embedded_polymorphic_proxy.rb +132 -0
- data/test/functional/associations/test_many_embedded_proxy.rb +174 -0
- data/test/functional/associations/test_many_polymorphic_proxy.rb +297 -0
- data/test/functional/associations/test_many_proxy.rb +331 -0
- data/test/functional/test_associations.rb +44 -0
- data/test/functional/test_binary.rb +18 -0
- data/test/functional/test_callbacks.rb +85 -0
- data/test/functional/test_dirty.rb +138 -0
- data/test/functional/test_document.rb +1051 -0
- data/test/functional/test_embedded_document.rb +97 -0
- data/test/functional/test_logger.rb +20 -0
- data/test/functional/test_pagination.rb +87 -0
- data/test/functional/test_rails_compatibility.rb +30 -0
- data/test/functional/test_validations.rb +279 -0
- data/test/models.rb +195 -0
- data/test/test_helper.rb +30 -0
- data/test/unit/serializers/test_json_serializer.rb +189 -0
- data/test/unit/test_association_base.rb +144 -0
- data/test/unit/test_document.rb +184 -0
- data/test/unit/test_dynamic_finder.rb +125 -0
- data/test/unit/test_embedded_document.rb +656 -0
- data/test/unit/test_finder_options.rb +261 -0
- data/test/unit/test_key.rb +172 -0
- data/test/unit/test_mongomapper.rb +28 -0
- data/test/unit/test_observing.rb +101 -0
- data/test/unit/test_pagination.rb +109 -0
- data/test/unit/test_rails_compatibility.rb +39 -0
- data/test/unit/test_serializations.rb +52 -0
- data/test/unit/test_support.rb +291 -0
- data/test/unit/test_time_zones.rb +40 -0
- data/test/unit/test_validations.rb +503 -0
- metadata +210 -0
@@ -0,0 +1,503 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ValidationsTest < Test::Unit::TestCase
|
4
|
+
context "Validations" do
|
5
|
+
|
6
|
+
context "on a Document" do
|
7
|
+
|
8
|
+
setup do
|
9
|
+
@document = Class.new do
|
10
|
+
include MongoMapper::Document
|
11
|
+
set_collection_name 'test'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context "Validating acceptance of" do
|
16
|
+
should "work with validates_acceptance_of macro" do
|
17
|
+
@document.key :terms, String
|
18
|
+
@document.validates_acceptance_of :terms
|
19
|
+
doc = @document.new(:terms => '')
|
20
|
+
doc.should have_error_on(:terms)
|
21
|
+
doc.terms = '1'
|
22
|
+
doc.should_not have_error_on(:terms)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context "validating confirmation of" do
|
27
|
+
should "work with validates_confirmation_of macro" do
|
28
|
+
@document.key :password, String
|
29
|
+
@document.validates_confirmation_of :password
|
30
|
+
doc = @document.new
|
31
|
+
doc.password = 'foobar'
|
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
|
+
context "with :numeric shortcut" do
|
121
|
+
should "work with integer or float" do
|
122
|
+
@document.key :weight, Float, :numeric => true
|
123
|
+
doc = @document.new
|
124
|
+
doc.weight = 'String'
|
125
|
+
doc.should have_error_on(:weight)
|
126
|
+
doc.weight = 23.0
|
127
|
+
doc.should_not have_error_on(:weight)
|
128
|
+
doc.weight = 23
|
129
|
+
doc.should_not have_error_on(:weight)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
context "with :numeric shortcut on Integer key" do
|
134
|
+
should "only work with integers" do
|
135
|
+
@document.key :age, Integer, :numeric => true
|
136
|
+
doc = @document.new
|
137
|
+
doc.age = 'String'
|
138
|
+
doc.should have_error_on(:age)
|
139
|
+
doc.age = 23.1
|
140
|
+
doc.should have_error_on(:age)
|
141
|
+
doc.age = 23
|
142
|
+
doc.should_not have_error_on(:age)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end # numericality of
|
146
|
+
|
147
|
+
context "validating presence of" do
|
148
|
+
should "work with validates_presence_of macro" do
|
149
|
+
@document.key :name, String
|
150
|
+
@document.validates_presence_of :name
|
151
|
+
doc = @document.new
|
152
|
+
doc.should have_error_on(:name)
|
153
|
+
end
|
154
|
+
|
155
|
+
should "work with :required shortcut on key definition" do
|
156
|
+
@document.key :name, String, :required => true
|
157
|
+
doc = @document.new
|
158
|
+
doc.should have_error_on(:name)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
context "validating exclusion of" do
|
163
|
+
should "throw error if enumerator not provided" do
|
164
|
+
@document.key :action, String
|
165
|
+
lambda {
|
166
|
+
@document.validates_exclusion_of :action
|
167
|
+
}.should raise_error(ArgumentError)
|
168
|
+
end
|
169
|
+
|
170
|
+
should "work with validates_exclusion_of macro" do
|
171
|
+
@document.key :action, String
|
172
|
+
@document.validates_exclusion_of :action, :within => %w(kick run)
|
173
|
+
|
174
|
+
doc = @document.new
|
175
|
+
doc.should_not have_error_on(:action)
|
176
|
+
|
177
|
+
doc.action = 'fart'
|
178
|
+
doc.should_not have_error_on(:action)
|
179
|
+
|
180
|
+
doc.action = 'kick'
|
181
|
+
doc.should have_error_on(:action, 'is reserved')
|
182
|
+
end
|
183
|
+
|
184
|
+
should "not have error if allow nil is true and value is nil" do
|
185
|
+
@document.key :action, String
|
186
|
+
@document.validates_exclusion_of :action, :within => %w(kick run), :allow_nil => true
|
187
|
+
|
188
|
+
doc = @document.new
|
189
|
+
doc.should_not have_error_on(:action)
|
190
|
+
end
|
191
|
+
|
192
|
+
should "not have error if allow blank is true and value is blank" do
|
193
|
+
@document.key :action, String
|
194
|
+
@document.validates_exclusion_of :action, :within => %w(kick run), :allow_nil => true
|
195
|
+
|
196
|
+
doc = @document.new(:action => '')
|
197
|
+
doc.should_not have_error_on(:action)
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
context "validating inclusion of" do
|
202
|
+
should "throw error if enumerator not provided" do
|
203
|
+
@document.key :action, String
|
204
|
+
lambda {
|
205
|
+
@document.validates_inclusion_of :action
|
206
|
+
}.should raise_error(ArgumentError)
|
207
|
+
end
|
208
|
+
|
209
|
+
should "work with validates_inclusion_of macro" do
|
210
|
+
@document.key :action, String
|
211
|
+
@document.validates_inclusion_of :action, :within => %w(kick run)
|
212
|
+
|
213
|
+
doc = @document.new
|
214
|
+
doc.should have_error_on(:action, 'is not in the list')
|
215
|
+
|
216
|
+
doc.action = 'fart'
|
217
|
+
doc.should have_error_on(:action, 'is not in the list')
|
218
|
+
|
219
|
+
doc.action = 'kick'
|
220
|
+
doc.should_not have_error_on(:action)
|
221
|
+
end
|
222
|
+
|
223
|
+
should "not have error if allow nil is true and value is nil" do
|
224
|
+
@document.key :action, String
|
225
|
+
@document.validates_inclusion_of :action, :within => %w(kick run), :allow_nil => true
|
226
|
+
|
227
|
+
doc = @document.new
|
228
|
+
doc.should_not have_error_on(:action)
|
229
|
+
end
|
230
|
+
|
231
|
+
should "not have error if allow blank is true and value is blank" do
|
232
|
+
@document.key :action, String
|
233
|
+
@document.validates_inclusion_of :action, :within => %w(kick run), :allow_blank => true
|
234
|
+
|
235
|
+
doc = @document.new(:action => '')
|
236
|
+
doc.should_not have_error_on(:action)
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
end # End on a Document
|
241
|
+
|
242
|
+
context "On an EmbeddedDocument" do
|
243
|
+
|
244
|
+
setup do
|
245
|
+
@embedded_doc = Class.new do
|
246
|
+
include MongoMapper::EmbeddedDocument
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
context "Validating acceptance of" do
|
251
|
+
should "work with validates_acceptance_of macro" do
|
252
|
+
@embedded_doc.key :terms, String
|
253
|
+
@embedded_doc.validates_acceptance_of :terms
|
254
|
+
doc = @embedded_doc.new(:terms => '')
|
255
|
+
doc.should have_error_on(:terms)
|
256
|
+
doc.terms = '1'
|
257
|
+
doc.should_not have_error_on(:terms)
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
context "validating confirmation of" do
|
262
|
+
should "work with validates_confirmation_of macro" do
|
263
|
+
@embedded_doc.key :password, String
|
264
|
+
@embedded_doc.validates_confirmation_of :password
|
265
|
+
doc = @embedded_doc.new
|
266
|
+
doc.password = 'foobar'
|
267
|
+
doc.should have_error_on(:password)
|
268
|
+
doc.password_confirmation = 'foobar'
|
269
|
+
doc.should_not have_error_on(:password)
|
270
|
+
end
|
271
|
+
end
|
272
|
+
|
273
|
+
context "validating format of" do
|
274
|
+
should "work with validates_format_of macro" do
|
275
|
+
@embedded_doc.key :name, String
|
276
|
+
@embedded_doc.validates_format_of :name, :with => /.+/
|
277
|
+
doc = @embedded_doc.new
|
278
|
+
doc.should have_error_on(:name)
|
279
|
+
doc.name = 'John'
|
280
|
+
doc.should_not have_error_on(:name)
|
281
|
+
end
|
282
|
+
|
283
|
+
should "work with :format shorcut key" do
|
284
|
+
@embedded_doc.key :name, String, :format => /.+/
|
285
|
+
doc = @embedded_doc.new
|
286
|
+
doc.should have_error_on(:name)
|
287
|
+
doc.name = 'John'
|
288
|
+
doc.should_not have_error_on(:name)
|
289
|
+
end
|
290
|
+
end
|
291
|
+
|
292
|
+
context "validating length of" do
|
293
|
+
should "work with validates_length_of macro" do
|
294
|
+
@embedded_doc.key :name, String
|
295
|
+
@embedded_doc.validates_length_of :name, :minimum => 5
|
296
|
+
doc = @embedded_doc.new
|
297
|
+
doc.should have_error_on(:name)
|
298
|
+
end
|
299
|
+
|
300
|
+
context "with :length => integer shortcut" do
|
301
|
+
should "set maximum of integer provided" do
|
302
|
+
@embedded_doc.key :name, String, :length => 5
|
303
|
+
doc = @embedded_doc.new
|
304
|
+
doc.name = '123456'
|
305
|
+
doc.should have_error_on(:name)
|
306
|
+
doc.name = '12345'
|
307
|
+
doc.should_not have_error_on(:name)
|
308
|
+
end
|
309
|
+
end
|
310
|
+
|
311
|
+
context "with :length => range shortcut" do
|
312
|
+
setup do
|
313
|
+
@embedded_doc.key :name, String, :length => 5..7
|
314
|
+
end
|
315
|
+
|
316
|
+
should "set minimum of range min" do
|
317
|
+
doc = @embedded_doc.new
|
318
|
+
doc.should have_error_on(:name)
|
319
|
+
doc.name = '123456'
|
320
|
+
doc.should_not have_error_on(:name)
|
321
|
+
end
|
322
|
+
|
323
|
+
should "set maximum of range max" do
|
324
|
+
doc = @embedded_doc.new
|
325
|
+
doc.should have_error_on(:name)
|
326
|
+
doc.name = '12345678'
|
327
|
+
doc.should have_error_on(:name)
|
328
|
+
doc.name = '123456'
|
329
|
+
doc.should_not have_error_on(:name)
|
330
|
+
end
|
331
|
+
end
|
332
|
+
|
333
|
+
context "with :length => hash shortcut" do
|
334
|
+
should "pass options through" do
|
335
|
+
@embedded_doc.key :name, String, :length => {:minimum => 2}
|
336
|
+
doc = @embedded_doc.new
|
337
|
+
doc.should have_error_on(:name)
|
338
|
+
doc.name = '12'
|
339
|
+
doc.should_not have_error_on(:name)
|
340
|
+
end
|
341
|
+
end
|
342
|
+
end # validates_length_of
|
343
|
+
|
344
|
+
context "Validating numericality of" do
|
345
|
+
should "work with validates_numericality_of macro" do
|
346
|
+
@embedded_doc.key :age, Integer
|
347
|
+
@embedded_doc.validates_numericality_of :age
|
348
|
+
doc = @embedded_doc.new
|
349
|
+
doc.age = 'String'
|
350
|
+
doc.should have_error_on(:age)
|
351
|
+
doc.age = 23
|
352
|
+
doc.should_not have_error_on(:age)
|
353
|
+
end
|
354
|
+
|
355
|
+
context "with :numeric shortcut" do
|
356
|
+
should "work with integer or float" do
|
357
|
+
@embedded_doc.key :weight, Float, :numeric => true
|
358
|
+
doc = @embedded_doc.new
|
359
|
+
doc.weight = 'String'
|
360
|
+
doc.should have_error_on(:weight)
|
361
|
+
doc.weight = 23.0
|
362
|
+
doc.should_not have_error_on(:weight)
|
363
|
+
doc.weight = 23
|
364
|
+
doc.should_not have_error_on(:weight)
|
365
|
+
end
|
366
|
+
end
|
367
|
+
|
368
|
+
context "with :numeric shortcut on Integer key" do
|
369
|
+
should "only work with integers" do
|
370
|
+
@embedded_doc.key :age, Integer, :numeric => true
|
371
|
+
doc = @embedded_doc.new
|
372
|
+
doc.age = 'String'
|
373
|
+
doc.should have_error_on(:age)
|
374
|
+
doc.age = 23.1
|
375
|
+
doc.should have_error_on(:age)
|
376
|
+
doc.age = 23
|
377
|
+
doc.should_not have_error_on(:age)
|
378
|
+
end
|
379
|
+
end
|
380
|
+
end # numericality of
|
381
|
+
|
382
|
+
context "validating presence of" do
|
383
|
+
should "work with validates_presence_of macro" do
|
384
|
+
@embedded_doc.key :name, String
|
385
|
+
@embedded_doc.validates_presence_of :name
|
386
|
+
doc = @embedded_doc.new
|
387
|
+
doc.should have_error_on(:name)
|
388
|
+
end
|
389
|
+
|
390
|
+
should "work with :required shortcut on key definition" do
|
391
|
+
@embedded_doc.key :name, String, :required => true
|
392
|
+
doc = @embedded_doc.new
|
393
|
+
doc.should have_error_on(:name)
|
394
|
+
end
|
395
|
+
end
|
396
|
+
|
397
|
+
context "validating exclusion of" do
|
398
|
+
should "throw error if enumerator not provided" do
|
399
|
+
@embedded_doc.key :action, String
|
400
|
+
lambda {
|
401
|
+
@embedded_doc.validates_exclusion_of :action
|
402
|
+
}.should raise_error(ArgumentError)
|
403
|
+
end
|
404
|
+
|
405
|
+
should "work with validates_exclusion_of macro" do
|
406
|
+
@embedded_doc.key :action, String
|
407
|
+
@embedded_doc.validates_exclusion_of :action, :within => %w(kick run)
|
408
|
+
|
409
|
+
doc = @embedded_doc.new
|
410
|
+
doc.should_not have_error_on(:action)
|
411
|
+
|
412
|
+
doc.action = 'fart'
|
413
|
+
doc.should_not have_error_on(:action)
|
414
|
+
|
415
|
+
doc.action = 'kick'
|
416
|
+
doc.should have_error_on(:action, 'is reserved')
|
417
|
+
end
|
418
|
+
|
419
|
+
should "not have error if allow nil is true and value is nil" do
|
420
|
+
@embedded_doc.key :action, String
|
421
|
+
@embedded_doc.validates_exclusion_of :action, :within => %w(kick run), :allow_nil => true
|
422
|
+
|
423
|
+
doc = @embedded_doc.new
|
424
|
+
doc.should_not have_error_on(:action)
|
425
|
+
end
|
426
|
+
|
427
|
+
should "not have error if allow blank is true and value is blank" do
|
428
|
+
@embedded_doc.key :action, String
|
429
|
+
@embedded_doc.validates_exclusion_of :action, :within => %w(kick run), :allow_nil => true
|
430
|
+
|
431
|
+
doc = @embedded_doc.new(:action => '')
|
432
|
+
doc.should_not have_error_on(:action)
|
433
|
+
end
|
434
|
+
end
|
435
|
+
|
436
|
+
context "validating inclusion of" do
|
437
|
+
should "throw error if enumerator not provided" do
|
438
|
+
@embedded_doc.key :action, String
|
439
|
+
lambda {
|
440
|
+
@embedded_doc.validates_inclusion_of :action
|
441
|
+
}.should raise_error(ArgumentError)
|
442
|
+
end
|
443
|
+
|
444
|
+
should "work with validates_inclusion_of macro" do
|
445
|
+
@embedded_doc.key :action, String
|
446
|
+
@embedded_doc.validates_inclusion_of :action, :within => %w(kick run)
|
447
|
+
|
448
|
+
doc = @embedded_doc.new
|
449
|
+
doc.should have_error_on(:action, 'is not in the list')
|
450
|
+
|
451
|
+
doc.action = 'fart'
|
452
|
+
doc.should have_error_on(:action, 'is not in the list')
|
453
|
+
|
454
|
+
doc.action = 'kick'
|
455
|
+
doc.should_not have_error_on(:action)
|
456
|
+
end
|
457
|
+
|
458
|
+
should "not have error if allow nil is true and value is nil" do
|
459
|
+
@embedded_doc.key :action, String
|
460
|
+
@embedded_doc.validates_inclusion_of :action, :within => %w(kick run), :allow_nil => true
|
461
|
+
|
462
|
+
doc = @embedded_doc.new
|
463
|
+
doc.should_not have_error_on(:action)
|
464
|
+
end
|
465
|
+
|
466
|
+
should "not have error if allow blank is true and value is blank" do
|
467
|
+
@embedded_doc.key :action, String
|
468
|
+
@embedded_doc.validates_inclusion_of :action, :within => %w(kick run), :allow_blank => true
|
469
|
+
|
470
|
+
doc = @embedded_doc.new(:action => '')
|
471
|
+
doc.should_not have_error_on(:action)
|
472
|
+
end
|
473
|
+
end
|
474
|
+
|
475
|
+
end # End on an EmbeddedDocument
|
476
|
+
|
477
|
+
end # Validations
|
478
|
+
|
479
|
+
context "Adding validation errors" do
|
480
|
+
setup do
|
481
|
+
@document = Class.new do
|
482
|
+
include MongoMapper::Document
|
483
|
+
set_collection_name 'test'
|
484
|
+
|
485
|
+
key :action, String
|
486
|
+
def action_present
|
487
|
+
errors.add(:action, 'is invalid') if action.blank?
|
488
|
+
end
|
489
|
+
end
|
490
|
+
end
|
491
|
+
|
492
|
+
should "work with validate callback" do
|
493
|
+
@document.validate :action_present
|
494
|
+
|
495
|
+
doc = @document.new
|
496
|
+
doc.action = nil
|
497
|
+
doc.should have_error_on(:action)
|
498
|
+
|
499
|
+
doc.action = 'kick'
|
500
|
+
doc.should_not have_error_on(:action)
|
501
|
+
end
|
502
|
+
end
|
503
|
+
end
|
metadata
ADDED
@@ -0,0 +1,210 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mongo_mapper-unstable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2009.10.11
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- John Nunemaker
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-10-11 00:00:00 -05:00
|
13
|
+
default_executable: mmconsole
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: activesupport
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: mongo
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.15.1
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: jnunemaker-validatable
|
37
|
+
type: :runtime
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - "="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 1.7.4
|
44
|
+
version:
|
45
|
+
- !ruby/object:Gem::Dependency
|
46
|
+
name: mocha
|
47
|
+
type: :development
|
48
|
+
version_requirement:
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.9.4
|
54
|
+
version:
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: jnunemaker-matchy
|
57
|
+
type: :development
|
58
|
+
version_requirement:
|
59
|
+
version_requirements: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - "="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: 0.4.0
|
64
|
+
version:
|
65
|
+
description:
|
66
|
+
email: nunemaker@gmail.com
|
67
|
+
executables:
|
68
|
+
- mmconsole
|
69
|
+
extensions: []
|
70
|
+
|
71
|
+
extra_rdoc_files:
|
72
|
+
- LICENSE
|
73
|
+
- README.rdoc
|
74
|
+
files:
|
75
|
+
- .gitignore
|
76
|
+
- LICENSE
|
77
|
+
- README.rdoc
|
78
|
+
- Rakefile
|
79
|
+
- VERSION
|
80
|
+
- bin/mmconsole
|
81
|
+
- lib/mongo_mapper.rb
|
82
|
+
- lib/mongo_mapper/associations.rb
|
83
|
+
- lib/mongo_mapper/associations/base.rb
|
84
|
+
- lib/mongo_mapper/associations/belongs_to_polymorphic_proxy.rb
|
85
|
+
- lib/mongo_mapper/associations/belongs_to_proxy.rb
|
86
|
+
- lib/mongo_mapper/associations/many_documents_as_proxy.rb
|
87
|
+
- lib/mongo_mapper/associations/many_documents_proxy.rb
|
88
|
+
- lib/mongo_mapper/associations/many_embedded_polymorphic_proxy.rb
|
89
|
+
- lib/mongo_mapper/associations/many_embedded_proxy.rb
|
90
|
+
- lib/mongo_mapper/associations/many_polymorphic_proxy.rb
|
91
|
+
- lib/mongo_mapper/associations/many_proxy.rb
|
92
|
+
- lib/mongo_mapper/associations/proxy.rb
|
93
|
+
- lib/mongo_mapper/callbacks.rb
|
94
|
+
- lib/mongo_mapper/dirty.rb
|
95
|
+
- lib/mongo_mapper/document.rb
|
96
|
+
- lib/mongo_mapper/dynamic_finder.rb
|
97
|
+
- lib/mongo_mapper/embedded_document.rb
|
98
|
+
- lib/mongo_mapper/finder_options.rb
|
99
|
+
- lib/mongo_mapper/key.rb
|
100
|
+
- lib/mongo_mapper/observing.rb
|
101
|
+
- lib/mongo_mapper/pagination.rb
|
102
|
+
- lib/mongo_mapper/rails_compatibility/document.rb
|
103
|
+
- lib/mongo_mapper/rails_compatibility/embedded_document.rb
|
104
|
+
- lib/mongo_mapper/save_with_validation.rb
|
105
|
+
- lib/mongo_mapper/serialization.rb
|
106
|
+
- lib/mongo_mapper/serializers/json_serializer.rb
|
107
|
+
- lib/mongo_mapper/support.rb
|
108
|
+
- lib/mongo_mapper/validations.rb
|
109
|
+
- mongo_mapper.gemspec
|
110
|
+
- specs.watchr
|
111
|
+
- test/NOTE_ON_TESTING
|
112
|
+
- test/custom_matchers.rb
|
113
|
+
- test/functional/associations/test_belongs_to_polymorphic_proxy.rb
|
114
|
+
- test/functional/associations/test_belongs_to_proxy.rb
|
115
|
+
- test/functional/associations/test_many_documents_as_proxy.rb
|
116
|
+
- test/functional/associations/test_many_embedded_polymorphic_proxy.rb
|
117
|
+
- test/functional/associations/test_many_embedded_proxy.rb
|
118
|
+
- test/functional/associations/test_many_polymorphic_proxy.rb
|
119
|
+
- test/functional/associations/test_many_proxy.rb
|
120
|
+
- test/functional/test_associations.rb
|
121
|
+
- test/functional/test_binary.rb
|
122
|
+
- test/functional/test_callbacks.rb
|
123
|
+
- test/functional/test_dirty.rb
|
124
|
+
- test/functional/test_document.rb
|
125
|
+
- test/functional/test_embedded_document.rb
|
126
|
+
- test/functional/test_logger.rb
|
127
|
+
- test/functional/test_pagination.rb
|
128
|
+
- test/functional/test_rails_compatibility.rb
|
129
|
+
- test/functional/test_validations.rb
|
130
|
+
- test/models.rb
|
131
|
+
- test/test_helper.rb
|
132
|
+
- test/unit/serializers/test_json_serializer.rb
|
133
|
+
- test/unit/test_association_base.rb
|
134
|
+
- test/unit/test_document.rb
|
135
|
+
- test/unit/test_dynamic_finder.rb
|
136
|
+
- test/unit/test_embedded_document.rb
|
137
|
+
- test/unit/test_finder_options.rb
|
138
|
+
- test/unit/test_key.rb
|
139
|
+
- test/unit/test_mongomapper.rb
|
140
|
+
- test/unit/test_observing.rb
|
141
|
+
- test/unit/test_pagination.rb
|
142
|
+
- test/unit/test_rails_compatibility.rb
|
143
|
+
- test/unit/test_serializations.rb
|
144
|
+
- test/unit/test_support.rb
|
145
|
+
- test/unit/test_time_zones.rb
|
146
|
+
- test/unit/test_validations.rb
|
147
|
+
has_rdoc: true
|
148
|
+
homepage: http://github.com/jnunemaker/mongomapper
|
149
|
+
licenses: []
|
150
|
+
|
151
|
+
post_install_message:
|
152
|
+
rdoc_options:
|
153
|
+
- --charset=UTF-8
|
154
|
+
require_paths:
|
155
|
+
- lib
|
156
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
157
|
+
requirements:
|
158
|
+
- - ">="
|
159
|
+
- !ruby/object:Gem::Version
|
160
|
+
version: "0"
|
161
|
+
version:
|
162
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: "0"
|
167
|
+
version:
|
168
|
+
requirements: []
|
169
|
+
|
170
|
+
rubyforge_project: mongomapper
|
171
|
+
rubygems_version: 1.3.5
|
172
|
+
signing_key:
|
173
|
+
specification_version: 3
|
174
|
+
summary: Awesome gem for modeling your domain and storing it in mongo
|
175
|
+
test_files:
|
176
|
+
- test/unit/test_embedded_document.rb
|
177
|
+
- test/unit/test_association_base.rb
|
178
|
+
- test/unit/test_serializations.rb
|
179
|
+
- test/unit/test_key.rb
|
180
|
+
- test/unit/test_dynamic_finder.rb
|
181
|
+
- test/unit/serializers/test_json_serializer.rb
|
182
|
+
- test/unit/test_support.rb
|
183
|
+
- test/unit/test_mongomapper.rb
|
184
|
+
- test/unit/test_finder_options.rb
|
185
|
+
- test/unit/test_time_zones.rb
|
186
|
+
- test/unit/test_observing.rb
|
187
|
+
- test/unit/test_rails_compatibility.rb
|
188
|
+
- test/unit/test_validations.rb
|
189
|
+
- test/unit/test_document.rb
|
190
|
+
- test/unit/test_pagination.rb
|
191
|
+
- test/custom_matchers.rb
|
192
|
+
- test/test_helper.rb
|
193
|
+
- test/functional/test_embedded_document.rb
|
194
|
+
- test/functional/test_associations.rb
|
195
|
+
- test/functional/associations/test_belongs_to_proxy.rb
|
196
|
+
- test/functional/associations/test_many_proxy.rb
|
197
|
+
- test/functional/associations/test_many_embedded_proxy.rb
|
198
|
+
- test/functional/associations/test_many_documents_as_proxy.rb
|
199
|
+
- test/functional/associations/test_many_embedded_polymorphic_proxy.rb
|
200
|
+
- test/functional/associations/test_many_polymorphic_proxy.rb
|
201
|
+
- test/functional/associations/test_belongs_to_polymorphic_proxy.rb
|
202
|
+
- test/functional/test_binary.rb
|
203
|
+
- test/functional/test_dirty.rb
|
204
|
+
- test/functional/test_callbacks.rb
|
205
|
+
- test/functional/test_rails_compatibility.rb
|
206
|
+
- test/functional/test_validations.rb
|
207
|
+
- test/functional/test_logger.rb
|
208
|
+
- test/functional/test_document.rb
|
209
|
+
- test/functional/test_pagination.rb
|
210
|
+
- test/models.rb
|