public
Fork of thoughtbot/shoulda
Description: Makes tests easy on the fingers and the eyes
Homepage: http://www.thoughtbot.com/projects/shoulda
Clone URL: git://github.com/boone/shoulda.git
Replaced error regexes with ActiveRecord default error messages
boone (author)
Wed Sep 10 17:15:19 -0700 2008
commit  84ae4f2744524b7e5385817ebaaaf35263696d2a
tree    57839801a206fdcc6fa57bcd8523b45825e8bcee
parent  25d8b08954f19a3724c133391aca0a9497c82830
...
56
57
58
59
 
 
60
61
62
...
56
57
58
 
59
60
61
62
63
0
@@ -56,7 +56,8 @@ module ThoughtBot # :nodoc:
0
         #
0
         #   @product = Product.new(:tangible => true)
0
         #   assert_bad_value(Product, :price, "0")
0
-        def assert_bad_value(object_or_klass, attribute, value, error_message_to_expect = /invalid/)
0
+        def assert_bad_value(object_or_klass, attribute, value,
0
+                             error_message_to_expect = ::ActiveRecord::Errors.default_error_messages[:invalid])
0
           object = get_instance_of(object_or_klass)
0
           object.send("#{attribute}=", value)
0
           assert !object.valid?, "#{object.class} allowed #{value.inspect} as a value for #{attribute}"
...
36
37
38
39
 
40
41
42
43
44
45
46
 
47
48
49
...
58
59
60
61
 
62
63
64
...
70
71
72
73
 
74
75
76
...
156
157
158
159
 
160
161
162
163
164
165
166
 
167
168
169
...
199
200
201
202
 
203
204
 
205
206
207
208
209
210
211
212
 
 
213
214
215
...
251
252
253
254
 
255
256
257
258
259
260
261
 
262
263
264
...
282
283
284
285
 
286
287
288
289
290
291
292
 
293
294
295
...
317
318
319
320
 
321
322
 
323
324
325
326
327
328
329
330
 
 
331
332
333
...
362
363
364
365
 
366
367
368
369
370
371
372
 
373
374
375
...
605
606
607
608
 
609
610
611
612
613
614
615
 
616
617
618
...
36
37
38
 
39
40
41
42
43
44
45
 
46
47
48
49
...
58
59
60
 
61
62
63
64
...
70
71
72
 
73
74
75
76
...
156
157
158
 
159
160
161
162
163
164
165
 
166
167
168
169
...
199
200
201
 
202
203
 
204
205
206
207
208
209
210
 
 
211
212
213
214
215
...
251
252
253
 
254
255
256
257
258
259
260
 
261
262
263
264
...
282
283
284
 
285
286
287
288
289
290
291
 
292
293
294
295
...
317
318
319
 
320
321
 
322
323
324
325
326
327
328
 
 
329
330
331
332
333
...
362
363
364
 
365
366
367
368
369
370
371
 
372
373
374
375
...
605
606
607
 
608
609
610
611
612
613
614
 
615
616
617
618
0
@@ -36,14 +36,14 @@ module ThoughtBot # :nodoc:
0
         #
0
         # Options:
0
         # * <tt>:message</tt> - value the test expects to find in <tt>errors.on(:attribute)</tt>.
0
-        #   Regexp or string.  Default = <tt>/blank/</tt>
0
+        #   Regexp or string.  Default = <tt>ActiveRecord::Errors.default_error_messages[:blank]</tt>
0
         #
0
         # Example:
0
         #   should_require_attributes :name, :phone_number
0
         #
0
         def should_require_attributes(*attributes)
0
           message = get_options!(attributes, :message)
0
-          message ||= /blank/
0
+          message ||= ::ActiveRecord::Errors.default_error_messages[:blank]
0
           klass = model_class
0
 
0
           attributes.each do |attribute|
0
@@ -58,7 +58,7 @@ module ThoughtBot # :nodoc:
0
         #
0
         # Options:
0
         # * <tt>:message</tt> - value the test expects to find in <tt>errors.on(:attribute)</tt>.
0
-        #   Regexp or string.  Default = <tt>/taken/</tt>
0
+        #   Regexp or string.  Default = <tt>ActiveRecord::Errors.default_error_messages[:taken]</tt>
0
         # * <tt>:scoped_to</tt> - field(s) to scope the uniqueness to.
0
         #
0
         # Examples:
0
@@ -70,7 +70,7 @@ module ThoughtBot # :nodoc:
0
         def should_require_unique_attributes(*attributes)
0
           message, scope = get_options!(attributes, :message, :scoped_to)
0
           scope = [*scope].compact
0
-          message ||= /taken/
0
+          message ||= ::ActiveRecord::Errors.default_error_messages[:taken]
0
 
0
           klass = model_class
0
           attributes.each do |attribute|
0
@@ -156,14 +156,14 @@ module ThoughtBot # :nodoc:
0
         #
0
         # Options:
0
         # * <tt>:message</tt> - value the test expects to find in <tt>errors.on(:attribute)</tt>.
0
-        #   Regexp or string.  Default = <tt>/invalid/</tt>
0
+        #   Regexp or string.  Default = <tt>ActiveRecord::Errors.default_error_messages[:invalid]</tt>
0
         #
0
         # Example:
0
         #   should_not_allow_values_for :isbn, "bad 1", "bad 2"
0
         #
0
         def should_not_allow_values_for(attribute, *bad_values)
0
           message = get_options!(bad_values, :message)
0
-          message ||= /invalid/
0
+          message ||= ::ActiveRecord::Errors.default_error_messages[:invalid]
0
           klass = model_class
0
           bad_values.each do |v|
0
             should "not allow #{attribute} to be set to #{v.inspect}" do
0
@@ -199,17 +199,17 @@ module ThoughtBot # :nodoc:
0
         #
0
         # Options:
0
         # * <tt>:short_message</tt> - value the test expects to find in <tt>errors.on(:attribute)</tt>.
0
-        #   Regexp or string.  Default = <tt>/short/</tt>
0
+        #   Regexp or string.  Default = <tt>ActiveRecord::Errors.default_error_messages[:too_short] % range.first</tt>
0
         # * <tt>:long_message</tt> - value the test expects to find in <tt>errors.on(:attribute)</tt>.
0
-        #   Regexp or string.  Default = <tt>/long/</tt>
0
+        #   Regexp or string.  Default = <tt>ActiveRecord::Errors.default_error_messages[:too_long] % range.last</tt>
0
         #
0
         # Example:
0
         #   should_ensure_length_in_range :password, (6..20)
0
         #
0
         def should_ensure_length_in_range(attribute, range, opts = {})
0
           short_message, long_message = get_options!([opts], :short_message, :long_message)
0
-          short_message ||= /short/
0
-          long_message  ||= /long/
0
+          short_message ||= ::ActiveRecord::Errors.default_error_messages[:too_short] % range.first
0
+          long_message  ||= ::ActiveRecord::Errors.default_error_messages[:too_long] % range.last
0
 
0
           klass = model_class
0
           min_length = range.first
0
@@ -251,14 +251,14 @@ module ThoughtBot # :nodoc:
0
         #
0
         # Options:
0
         # * <tt>:short_message</tt> - value the test expects to find in <tt>errors.on(:attribute)</tt>.
0
-        #   Regexp or string.  Default = <tt>/short/</tt>
0
+        #   Regexp or string.  Default = <tt>ActiveRecord::Errors.default_error_messages[:too_short] % min_length</tt>
0
         #
0
         # Example:
0
         #   should_ensure_length_at_least :name, 3
0
         #
0
         def should_ensure_length_at_least(attribute, min_length, opts = {})
0
           short_message = get_options!([opts], :short_message)
0
-          short_message ||= /short/
0
+          short_message ||= ::ActiveRecord::Errors.default_error_messages[:too_short] % min_length
0
 
0
           klass = model_class
0
 
0
@@ -282,14 +282,14 @@ module ThoughtBot # :nodoc:
0
         #
0
         # Options:
0
         # * <tt>:message</tt> - value the test expects to find in <tt>errors.on(:attribute)</tt>.
0
-        #   Regexp or string.  Default = <tt>/short/</tt>
0
+        #   Regexp or string.  Default = <tt>ActiveRecord::Errors.default_error_messages[:wrong_length] % length</tt>
0
         #
0
         # Example:
0
         #   should_ensure_length_is :ssn, 9
0
         #
0
         def should_ensure_length_is(attribute, length, opts = {})
0
           message = get_options!([opts], :message)
0
-          message ||= /wrong length/
0
+          message ||= ::ActiveRecord::Errors.default_error_messages[:wrong_length] % length
0
 
0
           klass = model_class
0
 
0
@@ -317,17 +317,17 @@ module ThoughtBot # :nodoc:
0
         #
0
         # Options:
0
         # * <tt>:low_message</tt> - value the test expects to find in <tt>errors.on(:attribute)</tt>.
0
-        #   Regexp or string.  Default = <tt>/included/</tt>
0
+        #   Regexp or string.  Default = <tt>ActiveRecord::Errors.default_error_messages[:inclusion]</tt>
0
         # * <tt>:high_message</tt> - value the test expects to find in <tt>errors.on(:attribute)</tt>.
0
-        #   Regexp or string.  Default = <tt>/included/</tt>
0
+        #   Regexp or string.  Default = <tt>ActiveRecord::Errors.default_error_messages[:inclusion]</tt>
0
         #
0
         # Example:
0
         #   should_ensure_value_in_range :age, (0..100)
0
         #
0
         def should_ensure_value_in_range(attribute, range, opts = {})
0
           low_message, high_message = get_options!([opts], :low_message, :high_message)
0
-          low_message  ||= /included/
0
-          high_message ||= /included/
0
+          low_message  ||= ::ActiveRecord::Errors.default_error_messages[:inclusion]
0
+          high_message ||= ::ActiveRecord::Errors.default_error_messages[:inclusion]
0
 
0
           klass = model_class
0
           min   = range.first
0
@@ -362,14 +362,14 @@ module ThoughtBot # :nodoc:
0
         #
0
         # Options:
0
         # * <tt>:message</tt> - value the test expects to find in <tt>errors.on(:attribute)</tt>.
0
-        #   Regexp or string.  Default = <tt>/number/</tt>
0
+        #   Regexp or string.  Default = <tt>ActiveRecord::Errors.default_error_messages[:not_a_number]</tt>
0
         #
0
         # Example:
0
         #   should_only_allow_numeric_values_for :age
0
         #
0
         def should_only_allow_numeric_values_for(*attributes)
0
           message = get_options!(attributes, :message)
0
-          message ||= /number/
0
+          message ||= ::ActiveRecord::Errors.default_error_messages[:not_a_number]
0
           klass = model_class
0
           attributes.each do |attribute|
0
             attribute = attribute.to_sym
0
@@ -605,14 +605,14 @@ module ThoughtBot # :nodoc:
0
         #
0
         # Options:
0
         # * <tt>:message</tt> - value the test expects to find in <tt>errors.on(:attribute)</tt>.
0
-        #   Regexp or string.  Default = <tt>/must be accepted/</tt>
0
+        #   Regexp or string.  Default = <tt>ActiveRecord::Errors.default_error_messages[:accepted]</tt>
0
         #
0
         # Example:
0
         #   should_require_acceptance_of :eula
0
         #
0
         def should_require_acceptance_of(*attributes)
0
           message = get_options!(attributes, :message)
0
-          message ||= /must be accepted/
0
+          message ||= ::ActiveRecord::Errors.default_error_messages[:accepted]
0
           klass = model_class
0
 
0
           attributes.each do |attribute|

Comments