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