public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Cleaned up ActiveRecord i18n scoping
iain (author)
Wed Aug 13 16:28:31 -0700 2008
svenfuchs (committer)
Thu Aug 14 01:48:33 -0700 2008
commit  ffeab4e0c171aecced4ddbe29b82aed064be9bdb
tree    58d8bb134b04e457a6ccd9ee33babbc803f31876
parent  d0ee883e7c01dabf039525b80b7f43673e987265
...
189
190
191
192
 
193
194
195
196
197
198
 
 
199
200
 
201
202
203
...
189
190
191
 
192
193
194
195
196
 
 
197
198
199
 
200
201
202
203
0
@@ -189,15 +189,15 @@ module ActionView
0
           end
0
           options[:object_name] ||= params.first
0
 
0
-          I18n.with_options :locale => options[:locale], :scope => [:active_record, :error] do |locale|
0
+          I18n.with_options :locale => options[:locale], :scope => [:activerecord, :errors, :template] do |locale|
0
             header_message = if options.include?(:header_message)
0
               options[:header_message]
0
             else
0
               object_name = options[:object_name].to_s.gsub('_', ' ')
0
-              object_name = I18n.t(object_name, :default => object_name)
0
-              locale.t :header_message, :count => count, :object_name => object_name
0
+              object_name = I18n.t(object_name, :default => object_name, :scope => [:activerecord, :models], :count => 1)
0
+              locale.t :header, :count => count, :model => object_name
0
             end
0
-            message = options.include?(:message) ? options[:message] : locale.t(:message)
0
+            message = options.include?(:message) ? options[:message] : locale.t(:body)
0
             error_messages = objects.sum {|object| object.errors.full_messages.map {|msg| content_tag(:li, msg) } }.join
0
 
0
             contents = ''
...
74
75
76
77
78
79
80
81
82
83
 
 
 
 
 
 
 
 
 
84
85
86
87
88
 
...
74
75
76
 
 
 
 
 
 
 
77
78
79
80
81
82
83
84
85
86
87
88
 
89
90
0
@@ -74,14 +74,16 @@
0
         }
0
       }
0
     },
0
-    :active_record => {
0
-      :error => {
0
-        :header_message => {
0
-          :one => "1 error prohibited this {{object_name}} from being saved", 
0
-          :many => "{{count}} errors prohibited this {{object_name}} from being saved"
0
-        },
0
-        :message => "There were problems with the following fields:"
0
+    :activerecord => {
0
+      :errors => {
0
+        :template => {
0
+          :header => {
0
+            :one => "1 error prohibited this {{model}} from being saved", 
0
+            :many => "{{count}} errors prohibited this {{model}} from being saved"
0
+          },
0
+          :body => "There were problems with the following fields:"
0
+        }
0
       }
0
     }
0
   }
0
-}
0
\ No newline at end of file
0
+}
...
10
11
12
13
14
 
 
15
16
17
18
 
 
19
20
21
22
23
24
 
 
 
25
26
27
28
29
30
 
 
31
32
33
34
35
36
 
 
37
38
39
40
41
42
 
 
43
44
45
46
47
 
...
10
11
12
 
 
13
14
15
16
 
 
17
18
19
20
21
 
 
 
22
23
24
25
26
27
28
 
 
29
30
31
32
33
34
 
 
35
36
37
38
39
40
 
 
41
42
43
44
45
 
46
47
0
@@ -10,37 +10,37 @@ class ActiveRecordHelperI18nTest < Test::Unit::TestCase
0
       @object_name = 'book'
0
       stubs(:content_tag).returns 'content_tag'
0
 
0
-      I18n.stubs(:t).with(:'header_message', :locale => 'en-US', :scope => [:active_record, :error], :count => 1, :object_name => '').returns "1 error prohibited this  from being saved"
0
-      I18n.stubs(:t).with(:'message', :locale => 'en-US', :scope => [:active_record, :error]).returns 'There were problems with the following fields:'
0
+      I18n.stubs(:t).with(:'header', :locale => 'en-US', :scope => [:activerecord, :errors, :template], :count => 1, :model => '').returns "1 error prohibited this  from being saved"
0
+      I18n.stubs(:t).with(:'body', :locale => 'en-US', :scope => [:activerecord, :errors, :template]).returns 'There were problems with the following fields:'
0
     end
0
 
0
-    def test_error_messages_for_given_a_header_message_option_it_does_not_translate_header_message
0
-      I18n.expects(:translate).with(:'header_message', :locale => 'en-US', :scope => [:active_record, :error], :count => 1, :object_name => '').never
0
+    def test_error_messages_for_given_a_header_option_it_does_not_translate_header_message
0
+      I18n.expects(:translate).with(:'header', :locale => 'en-US', :scope => [:activerecord, :errors, :template], :count => 1, :model => '').never
0
       error_messages_for(:object => @object, :header_message => 'header message', :locale => 'en-US')
0
     end
0
 
0
-    def test_error_messages_for_given_no_header_message_option_it_translates_header_message
0
-      I18n.expects(:t).with(:'header_message', :locale => 'en-US', :scope => [:active_record, :error], :count => 1, :object_name => '').returns 'header message'
0
-      I18n.expects(:t).with('', :default => '').once.returns ''
0
+    def test_error_messages_for_given_no_header_option_it_translates_header_message
0
+      I18n.expects(:t).with(:'header', :locale => 'en-US', :scope => [:activerecord, :errors, :template], :count => 1, :model => '').returns 'header message'
0
+      I18n.expects(:t).with('', :default => '', :count => 1, :scope => [:activerecord, :models]).once.returns ''
0
       error_messages_for(:object => @object, :locale => 'en-US')
0
     end
0
 
0
     def test_error_messages_for_given_a_message_option_it_does_not_translate_message
0
-      I18n.expects(:t).with(:'message', :locale => 'en-US', :scope => [:active_record, :error]).never
0
-      I18n.expects(:t).with('', :default => '').once.returns ''
0
+      I18n.expects(:t).with(:'body', :locale => 'en-US', :scope => [:activerecord, :errors, :template]).never
0
+      I18n.expects(:t).with('', :default => '', :count => 1, :scope => [:activerecord, :models]).once.returns ''
0
       error_messages_for(:object => @object, :message => 'message', :locale => 'en-US')
0
     end
0
 
0
     def test_error_messages_for_given_no_message_option_it_translates_message
0
-      I18n.expects(:t).with(:'message', :locale => 'en-US', :scope => [:active_record, :error]).returns 'There were problems with the following fields:'
0
-      I18n.expects(:t).with('', :default => '').once.returns ''
0
+      I18n.expects(:t).with(:'body', :locale => 'en-US', :scope => [:activerecord, :errors, :template]).returns 'There were problems with the following fields:'
0
+      I18n.expects(:t).with('', :default => '', :count => 1, :scope => [:activerecord, :models]).once.returns ''
0
       error_messages_for(:object => @object, :locale => 'en-US')
0
     end
0
     
0
     def test_error_messages_for_given_object_name_it_translates_object_name
0
-      I18n.expects(:t).with(:header_message, :locale => 'en-US', :scope => [:active_record, :error], :count => 1, :object_name => @object_name).returns "1 error prohibited this #{@object_name} from being saved"
0
-      I18n.expects(:t).with(@object_name, :default => @object_name).once.returns @object_name
0
+      I18n.expects(:t).with(:header, :locale => 'en-US', :scope => [:activerecord, :errors, :template], :count => 1, :model => @object_name).returns "1 error prohibited this #{@object_name} from being saved"
0
+      I18n.expects(:t).with(@object_name, :default => @object_name, :count => 1, :scope => [:activerecord, :models]).once.returns @object_name
0
       error_messages_for(:object => @object, :locale => 'en-US', :object_name => @object_name)
0
     end
0
   end
0
-end
0
\ No newline at end of file
0
+end
...
1220
1221
1222
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1223
1224
1225
1226
1227
 
 
 
 
 
 
 
 
 
 
 
 
1228
1229
1230
1231
1232
...
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
 
 
 
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
 
1252
1253
1254
0
@@ -1220,13 +1220,35 @@ module ActiveRecord #:nodoc:
0
         subclasses.each { |klass| klass.reset_inheritable_attributes; klass.reset_column_information }
0
       end
0
 
0
+      def self_and_descendents_from_active_record#nodoc:
0
+        klass = self
0
+        classes = [klass]
0
+        while klass != klass.base_class  
0
+          classes << klass = klass.superclass
0
+        end
0
+        classes
0
+      rescue
0
+        # OPTIMIZE this rescue is to fix this test: ./test/cases/reflection_test.rb:56:in `test_human_name_for_column'
0
+        # Appearantly the method base_class causes some trouble.
0
+        # It now works for sure.
0
+        [self]
0
+      end
0
+
0
       # Transforms attribute key names into a more humane format, such as "First name" instead of "first_name". Example:
0
       #   Person.human_attribute_name("first_name") # => "First name"
0
-      # Deprecated in favor of just calling "first_name".humanize
0
-      def human_attribute_name(attribute_key_name) #:nodoc:
0
-        attribute_key_name.humanize
0
+      # This used to be depricated in favor of humanize, but is now preferred, because it automatically uses the I18n
0
+      # module now.
0
+      # Specify +options+ with additional translating options.
0
+      def human_attribute_name(attribute_key_name, options = {})
0
+        defaults = self_and_descendents_from_active_record.map do |klass|
0
+          :"#{klass.name.underscore}.#{attribute_key_name}"
0
+        end
0
+        defaults << options[:default] if options[:default]
0
+        defaults.flatten!
0
+        defaults << attribute_key_name.humanize
0
+        options[:count] ||= 1
0
+        I18n.translate(defaults.shift, options.merge(:default => defaults, :scope => [:activerecord, :attributes]))
0
       end
0
-
0
       # True if this isn't a concrete subclass needing a STI type condition.
0
       def descends_from_active_record?
0
         if superclass.abstract_class?
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
25
26
27
 
...
1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 
28
29
0
@@ -1,26 +1,28 @@
0
 { :'en-US' => {
0
-    :active_record => {
0
-      :error_messages => {
0
-        :inclusion => "is not included in the list",
0
-        :exclusion => "is reserved",
0
-        :invalid => "is invalid",
0
-        :confirmation => "doesn't match confirmation",
0
-        :accepted  => "must be accepted",
0
-        :empty => "can't be empty",
0
-        :blank => "can't be blank",
0
-        :too_long => "is too long (maximum is {{count}} characters)",
0
-        :too_short => "is too short (minimum is {{count}} characters)",
0
-        :wrong_length => "is the wrong length (should be {{count}} characters)",
0
-        :taken => "has already been taken",
0
-        :not_a_number => "is not a number",
0
-        :greater_than => "must be greater than {{count}}",
0
-        :greater_than_or_equal_to => "must be greater than or equal to {{count}}",
0
-        :equal_to => "must be equal to {{count}}",
0
-        :less_than => "must be less than {{count}}",
0
-        :less_than_or_equal_to => "must be less than or equal to {{count}}",
0
-        :odd => "must be odd",
0
-        :even => "must be even"
0
-      }            
0
+    :activerecord => {
0
+      :errors => {
0
+        :messages => {
0
+          :inclusion => "is not included in the list",
0
+          :exclusion => "is reserved",
0
+          :invalid => "is invalid",
0
+          :confirmation => "doesn't match confirmation",
0
+          :accepted  => "must be accepted",
0
+          :empty => "can't be empty",
0
+          :blank => "can't be blank",
0
+          :too_long => "is too long (maximum is {{count}} characters)",
0
+          :too_short => "is too short (minimum is {{count}} characters)",
0
+          :wrong_length => "is the wrong length (should be {{count}} characters)",
0
+          :taken => "has already been taken",
0
+          :not_a_number => "is not a number",
0
+          :greater_than => "must be greater than {{count}}",
0
+          :greater_than_or_equal_to => "must be greater than or equal to {{count}}",
0
+          :equal_to => "must be equal to {{count}}",
0
+          :less_than => "must be less than {{count}}",
0
+          :less_than_or_equal_to => "must be less than or equal to {{count}}",
0
+          :odd => "must be odd",
0
+          :even => "must be even"
0
+        }            
0
+      }
0
     }
0
   }
0
-}
0
\ No newline at end of file
0
+}
...
21
22
23
24
25
 
 
26
27
28
...
38
39
40
41
 
42
43
44
45
46
 
 
 
 
 
47
48
49
 
50
51
52
53
54
55
56
 
57
58
59
...
61
62
63
64
 
65
66
67
68
69
70
71
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
73
 
 
 
 
 
 
 
74
75
76
...
166
167
168
169
170
171
 
 
 
172
173
174
...
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
...
398
399
400
401
402
 
403
404
405
...
441
442
443
444
445
 
446
447
448
...
544
545
546
547
548
 
549
550
551
 
552
553
554
...
563
564
565
566
567
 
568
569
570
...
662
663
664
665
666
 
667
668
669
...
701
702
703
704
705
 
706
707
708
...
736
737
738
739
740
 
741
742
743
...
771
772
773
774
775
 
776
777
778
...
814
815
816
817
818
 
819
820
821
...
864
865
866
867
868
 
869
870
871
...
873
874
875
876
877
 
878
879
880
...
883
884
885
886
887
 
888
889
890
891
 
892
893
894
...
21
22
23
 
 
24
25
26
27
28
...
38
39
40
 
41
42
43
 
 
 
44
45
46
47
48
49
50
 
51
52
53
54
55
56
57
 
58
59
60
61
...
63
64
65
 
66
67
68
69
 
 
 
 
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
 
101
102
103
104
105
106
107
108
109
110
...
200
201
202
 
 
 
203
204
205
206
207
208
...
253
254
255
 
 
 
 
 
 
 
 
 
 
256
257
258
...
422
423
424
 
 
425
426
427
428
...
464
465
466
 
 
467
468
469
470
...
566
567
568
 
 
569
570
 
 
571
572
573
574
...
583
584
585
 
 
586
587
588
589
...
681
682
683
 
 
684
685
686
687
...
719
720
721
 
 
722
723
724
725
...
753
754
755
 
 
756
757
758
759
...
787
788
789
 
 
790
791
792
793
...
829
830
831
 
 
832
833
834
835
...
878
879
880
 
 
881
882
883
884
...
886
887
888
 
 
889
890
891
892
...
895
896
897
 
 
898
899
900
 
 
901
902
903
904
0
@@ -21,8 +21,8 @@ module ActiveRecord
0
     
0
     class << self
0
       def default_error_messages
0
-        ActiveSupport::Deprecation.warn("ActiveRecord::Errors.default_error_messages has been deprecated. Please use I18n.translate('active_record.error_messages').")
0
-        I18n.translate 'active_record.error_messages'
0
+        ActiveSupport::Deprecation.warn("ActiveRecord::Errors.default_error_messages has been deprecated. Please use I18n.translate('activerecord.errors.messages').")
0
+        I18n.translate 'activerecord.errors.messages'
0
       end
0
     end
0
 
0
@@ -38,22 +38,24 @@ module ActiveRecord
0
       add(:base, msg)
0
     end
0
 
0
-    # Adds an error message (+msg+) to the +attribute+, which will be returned on a call to <tt>on(attribute)</tt>
0
+    # Adds an error message (+messsage+) to the +attribute+, which will be returned on a call to <tt>on(attribute)</tt>
0
     # for the same attribute and ensure that this error object returns false when asked if <tt>empty?</tt>. More than one
0
     # error can be added to the same +attribute+ in which case an array will be returned on a call to <tt>on(attribute)</tt>.
0
-    # If no +msg+ is supplied, "invalid" is assumed.
0
-    def add(attribute, message = nil)
0
-      message ||= I18n.translate :"active_record.error_messages.invalid"
0
+    # If no +messsage+ is supplied, :invalid is assumed.
0
+    # If +message+ is a Symbol, it will be translated, using the appropriate scope (see translate_error).
0
+    def add(attribute, message = nil, options = {})
0
+      message ||= :invalid
0
+      message = generate_message(attribute, message, options) if message.is_a?(Symbol)
0
       @errors[attribute.to_s] ||= []
0
       @errors[attribute.to_s] << message
0
-    end    
0
+    end
0
 
0
     # Will add an error message to each of the attributes in +attributes+ that is empty.
0
     def add_on_empty(attributes, custom_message = nil)
0
       for attr in [attributes].flatten
0
         value = @base.respond_to?(attr.to_s) ? @base.send(attr.to_s) : @base[attr.to_s]
0
         is_empty = value.respond_to?("empty?") ? value.empty? : false        
0
-        add(attr, generate_message(attr, :empty, :default => custom_message)) unless !value.nil? && !is_empty
0
+        add(attr, :empty, :default => custom_message) unless !value.nil? && !is_empty
0
       end
0
     end
0
 
0
@@ -61,16 +63,48 @@ module ActiveRecord
0
     def add_on_blank(attributes, custom_message = nil)
0
       for attr in [attributes].flatten
0
         value = @base.respond_to?(attr.to_s) ? @base.send(attr.to_s) : @base[attr.to_s]
0
-        add(attr, generate_message(attr, :blank, :default => custom_message)) if value.blank?
0
+        add(attr, :blank, :default => custom_message) if value.blank?
0
       end
0
     end
0
     
0
-    def generate_message(attr, key, options = {})
0
-      msgs = base_classes(@base.class).map{|klass| :"custom.#{klass.name.underscore}.#{attr}.#{key}"} 
0
-      msgs << options[:default] if options[:default]
0
-      msgs << key
0
+    # Translates an error message in it's default scope (<tt>activerecord.errrors.messages</tt>).
0
+    # Error messages are first looked up in <tt>custom.MODEL.ATTRIBUTE.MESSAGE</tt>, if it's not there, it's looked up
0
+    # in <tt>custom.MODEL.ATTRIBUTE</tt> and if that is not there it returns the translation of the default message
0
+    # (e.g. <tt>activerecord.errors.messages.MESSAGE</tt>). Both the model name and the attribute name are available for
0
+    # interpolation.
0
+    #
0
+    # When using inheritence in your models, it will check all the inherited models too, but only if the model itself
0
+    # hasn't been found. Say you have <tt>class Admin < User; end</tt> and you wanted the translation for the <tt>:blank</tt>
0
+    # error +message+ for the <tt>title</tt> +attribute+, it looks for these translations:
0
+    # 
0
+    # <ol>
0
+    # <li><tt>activerecord.errors.messages.custom.admin.title.blank</tt></li>
0
+    # <li><tt>activerecord.errors.messages.custom.admin.blank</tt></li>
0
+    # <li><tt>activerecord.errors.messages.custom.user.title.blank</tt></li>
0
+    # <li><tt>activerecord.errors.messages.custom.user.blank</tt></li>
0
+    # <li><tt>activerecord.errors.messages.blank</tt></li>
0
+    # <li>any default you provided through the +options+ hash</li>
0
+    # </ol>
0
+    def generate_message(attribute, message = :invalid, options = {})
0
+
0
+      defaults = @base.class.self_and_descendents_from_active_record.map do |klass| 
0
+        [ :"custom.#{klass.name.underscore}.#{attribute}.#{message}", 
0
+          :"custom.#{klass.name.underscore}.#{message}" ]
0
+      end
0
+      
0
+      defaults << options[:default] if options[:default]
0
+      defaults.flatten! << message
0
+
0
+      model_name = @base.class.name
0
+      key = defaults.shift
0
 
0
-      I18n.t msgs.shift, options.merge(:default => msgs, :scope => [:active_record, :error_messages])
0
+      options.merge!({ 
0
+          :default => defaults,
0
+          :model => I18n.translate(model_name.underscore, :default => model_name.humanize, :scope => [:activerecord, :models], :count => 1),
0
+          :attribute => @base.class.human_attribute_name(attribute.to_s),
0
+          :scope => [:activerecord, :errors, :messages] })
0
+
0
+      I18n.translate(key, options)
0
     end
0
 
0
     # Returns true if the specified +attribute+ has errors associated with it.
0
@@ -166,9 +200,9 @@ module ActiveRecord
0
           if attr == "base"
0
             full_messages << message
0
           else
0
-            key = :"active_record.human_attribute_names.#{@base.class.name.underscore.to_sym}.#{attr}" 
0
-            attr_name = I18n.translate(key, :locale => options[:locale], :default => @base.class.human_attribute_name(attr))
0
-            full_messages << attr_name + " " + message
0
+            #key = :"activerecord.att.#{@base.class.name.underscore.to_sym}.#{attr}" 
0
+            attr_name = @base.class.human_attribute_name(attr)
0
+            full_messages << attr_name + ' ' + message
0
           end
0
         end
0
       end
0
@@ -219,16 +253,6 @@ module ActiveRecord
0
       end
0
     end
0
     
0
-    protected
0
-      
0
-      # TODO maybe this should be on ActiveRecord::Base, maybe #self_and_descendents_from_active_record
0
-      def base_classes(klass)
0
-        classes = [klass]
0
-        while klass != klass.base_class  
0
-          classes << klass = klass.superclass
0
-        end
0
-        classes
0
-      end
0
   end
0
 
0
 
0
@@ -398,8 +422,7 @@ module ActiveRecord
0
 
0
         validates_each(attr_names, configuration) do |record, attr_name, value|
0
           unless record.send("#{attr_name}_confirmation").nil? or value == record.send("#{attr_name}_confirmation")
0
-            message = record.errors.generate_message(attr_name, :confirmation, :default => configuration[:message])
0
-            record.errors.add(attr_name, message) 
0
+            record.errors.add(attr_name, :confirmation, :default => configuration[:message]) 
0
           end
0
         end
0
       end
0
@@ -441,8 +464,7 @@ module ActiveRecord
0
 
0
         validates_each(attr_names,configuration) do |record, attr_name, value|
0
           unless value == configuration[:accept]
0
-            message = record.errors.generate_message(attr_name, :accepted, :default => configuration[:message])
0
-            record.errors.add(attr_name, message) 
0
+            record.errors.add(attr_name, :accepted, :default => configuration[:message]) 
0
           end
0
         end
0
       end
0
@@ -544,11 +566,9 @@ module ActiveRecord
0
             validates_each(attrs, options) do |record, attr, value|
0
               value = options[:tokenizer].call(value) if value.kind_of?(String)
0
               if value.nil? or value.size < option_value.begin
0
-                message = record.errors.generate_message(attr, :too_short, :default => options[:too_short], :count => option_value.begin)                
0
-                record.errors.add(attr, message)
0
+                record.errors.add(attr, :too_short, :default => options[:too_short], :count => option_value.begin)
0
               elsif value.size > option_value.end
0
-                message = record.errors.generate_message(attr, :too_long, :default => options[:too_long], :count => option_value.end)
0
-                record.errors.add(attr, message)
0
+                record.errors.add(attr, :too_long, :default => options[:too_long], :count => option_value.end)
0
               end
0
             end
0
           when :is, :minimum, :maximum
0
@@ -563,8 +583,7 @@ module ActiveRecord
0
               unless !value.nil? and value.size.method(validity_checks[option])[option_value]
0
                 key = message_options[option]
0
                 custom_message = options[:message] || options[key]
0
-                message = record.errors.generate_message(attr, key, :default => custom_message, :count => option_value)
0
-                record.errors.add(attr, message) 
0
+                record.errors.add(attr, key, :default => custom_message, :count => option_value) 
0
               end
0
             end
0
         end
0
@@ -662,8 +681,7 @@ module ActiveRecord
0
 
0
           finder_class.with_exclusive_scope do
0
             if finder_class.exists?([condition_sql, *condition_params])
0
-              message = record.errors.generate_message(attr_name, :taken, :default => configuration[:message], :value => value)
0
-              record.errors.add(attr_name, message)
0
+              record.errors.add(attr_name, :taken, :default => configuration[:message], :value => value)
0
             end
0
           end
0
         end
0
@@ -701,8 +719,7 @@ module ActiveRecord
0
 
0
         validates_each(attr_names, configuration) do |record, attr_name, value|
0
           unless value.to_s =~ configuration[:with]
0
-            message = record.errors.generate_message(attr_name, :invalid, :default => configuration[:message], :value => value)
0
-            record.errors.add(attr_name, message) 
0
+            record.errors.add(attr_name, :invalid, :default => configuration[:message], :value => value) 
0
           end
0
         end
0
       end
0
@@ -736,8 +753,7 @@ module ActiveRecord
0
 
0
         validates_each(attr_names, configuration) do |record, attr_name, value|
0
           unless enum.include?(value)
0
-            message = record.errors.generate_message(attr_name, :inclusion, :default => configuration[:message], :value => value)
0
-            record.errors.add(attr_name, message) 
0
+            record.errors.add(attr_name, :inclusion, :default => configuration[:message], :value => value) 
0
           end
0
         end
0
       end
0
@@ -771,8 +787,7 @@ module ActiveRecord
0
 
0
         validates_each(attr_names, configuration) do |record, attr_name, value|
0
           if enum.include?(value)
0
-            message = record.errors.generate_message(attr_name, :exclusion, :default => configuration[:message], :value => value)
0
-            record.errors.add(attr_name, message) 
0
+            record.errors.add(attr_name, :exclusion, :default => configuration[:message], :value => value) 
0
           end
0
         end
0
       end
0
@@ -814,8 +829,7 @@ module ActiveRecord
0
 
0
         validates_each(attr_names, configuration) do |record, attr_name, value|
0
           unless (value.is_a?(Array) ? value : [value]).inject(true) { |v, r| (r.nil? || r.valid?) && v }
0
-            message = record.errors.generate_message(attr_name, :invalid, :default => configuration[:message], :value => value)
0
-            record.errors.add(attr_name, message)
0
+            record.errors.add(attr_name, :invalid, :default => configuration[:message], :value => value)
0
           end
0
         end
0
       end
0
@@ -864,8 +878,7 @@ module ActiveRecord
0
 
0
           if configuration[:only_integer]
0
             unless raw_value.to_s =~ /\A[+-]?\d+\Z/
0
-              message = record.errors.generate_message(attr_name, :not_a_number, :value => raw_value, :default => configuration[:message])
0
-              record.errors.add(attr_name, message)
0
+              record.errors.add(attr_name, :not_a_number, :value => raw_value, :default => configuration[:message])
0
               next
0
             end
0
             raw_value = raw_value.to_i
0
@@ -873,8 +886,7 @@ module ActiveRecord
0
             begin
0
               raw_value = Kernel.Float(raw_value)
0
             rescue ArgumentError, TypeError
0
-              message = record.errors.generate_message(attr_name, :not_a_number, :value => raw_value, :default => configuration[:message])
0
-              record.errors.add(attr_name, message)
0
+              record.errors.add(attr_name, :not_a_number, :value => raw_value, :default => configuration[:message])
0
               next
0
             end
0
           end
0
@@ -883,12 +895,10 @@ module ActiveRecord
0
             case option
0
               when :odd, :even
0
                 unless raw_value.to_i.method(ALL_NUMERICALITY_CHECKS[option])[]
0
-                  message = record.errors.generate_message(attr_name, option, :value => raw_value, :default => configuration[:message])
0
-                  record.errors.add(attr_name, message) 
0
+                  record.errors.add(attr_name, option, :value => raw_value, :default => configuration[:message]) 
0
                 end
0
               else
0
-                message = record.errors.generate_message(attr_name, option, :default => configuration[:message], :value => raw_value, :count => configuration[option])
0
-                record.errors.add(attr_name, message) unless raw_value.method(ALL_NUMERICALITY_CHECKS[option])[configuration[option]]
0
+                record.errors.add(attr_name, option, :default => configuration[:message], :value => raw_value, :count => configuration[option]) unless raw_value.method(ALL_NUMERICALITY_CHECKS[option])[configuration[option]]
0
             end
0
           end
0
         end
...
6
7
8
9
 
10
11
12
...
43
44
45
46
 
47
48
49
50
 
 
 
 
 
51
52
 
53
54
55
56
 
 
 
 
57
58
59
 
60
61
62
...
79
80
81
82
 
83
84
85
...
344
345
346
347
348
 
 
349
350
351
...
354
355
356
357
 
358
359
360
...
365
366
367
368
369
 
 
370
371
372
...
374
375
376
377
 
378
379
380
...
384
385
386
387
388
 
 
389
390
391
...
393
394
395
396
 
397
398
399
...
403
404
405
406
407
 
 
408
409
410
...
412
413
414
415
 
416
417
418
...
422
423
424
425
426
 
 
427
428
429
...
431
432
433
434
 
435
436
437
...
441
442
443
444
445
 
 
446
447
448
...
450
451
452
453
 
454
455
456
...
461
462
463
464
465
 
 
466
467
468
...
470
471
472
473
 
474
475
476
...
480
481
482
483
484
 
 
485
486
487
...
489
490
491
492
 
493
494
495
...
499
500
501
502
503
 
 
504
505
506
...
509
510
511
512
 
513
514
515
...
520
521
522
523
524
 
 
525
526
527
...
530
531
532
533
 
534
535
536
...
541
542
543
544
545
 
 
546
547
548
...
551
552
553
554
 
555
556
557
...
562
563
564
565
566
 
 
567
568
569
...
572
573
574
575
 
576
577
578
...
583
584
585
586
587
 
 
588
589
590
...
593
594
595
596
 
597
598
599
...
605
606
607
608
609
 
 
610
611
612
...
614
615
616
617
 
618
619
620
...
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
651
652
653
...
798
799
800
801
802
 
...
6
7
8
 
9
10
11
12
...
43
44
45
 
46
47
 
 
 
48
49
50
51
52
53
 
54
55
 
 
 
56
57
58
59
60
61
 
62
63
64
65
...
82
83
84
 
85
86
87
88
...
347
348
349
 
 
350
351
352
353
354
...
357
358
359
 
360
361
362
363
...
368
369
370
 
 
371
372
373
374
375
...
377
378
379
 
380
381
382
383
...
387
388
389
 
 
390
391
392
393
394
...
396
397
398
 
399
400
401
402
...
406
407
408
 
 
409
410
411
412
413
...
415
416
417
 
418
419
420
421
...
425
426
427
 
 
428
429
430
431
432
...
434
435
436
 
437
438
439
440
...
444
445
446
 
 
447
448
449
450
451
...
453
454
455
 
456
457
458
459
...
464
465
466
 
 
467
468
469
470
471
...
473
474
475
 
476
477
478
479
...
483
484
485
 
 
486
487
488
489
490
...
492
493
494
 
495
496
497
498
...
502
503
504
 
 
505
506
507
508
509
...
512
513
514
 
515
516
517
518
...
523
524
525
 
 
526
527
528
529
530
...
533
534
535
 
536
537
538
539
...
544
545
546
 
 
547
548
549
550
551
...
554
555
556
 
557
558
559
560
...
565
566
567
 
 
568
569
570
571
572
...
575
576
577
 
578
579
580
581
...
586
587
588
 
 
589
590
591
592
593
...
596
597
598
 
599
600
601
602
...
608
609
610
 
 
611
612
613
614
615
...
617
618
619
 
620
621
622
623
...
630
631
632
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
...
803
804
805
 
806
807
0
@@ -6,7 +6,7 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
0
   def setup
0
     reset_callbacks Topic
0
     @topic = Topic.new
0
-    I18n.backend.store_translations('en-US', :active_record => {:error_messages => {:custom => nil}})
0
+    I18n.backend.store_translations('en-US', :activerecord => {:errors => {:messages => {:custom => nil}}})
0
   end
0
   
0
   def teardown
0
@@ -43,20 +43,23 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
0
   # ActiveRecord::Errors
0
   uses_mocha 'ActiveRecord::Errors' do
0
     def test_errors_generate_message_translates_custom_model_attribute_key
0
-      global_scope = [:active_record, :error_messages]
0
+      global_scope = [:activerecord, :errors, :messages]
0
       custom_scope = global_scope + [:custom, 'topic', :title]
0
-  
0
-      I18n.expects(:t).with :"custom.topic.title.invalid", :scope => [:active_record, :error_messages], :default => ['default from class def', :invalid]
0
-      @topic.errors.generate_message :title, :invalid, :default => 'default from class def'
0
+
0
+      I18n.expects(:translate).with('topic', {:count => 1, :default => 'Topic', :scope => [:activerecord, :models]}).returns('Topic')
0
+      I18n.expects(:translate).with(:'topic.title', {:count => 1, :default => ['Title'], :scope => [:activerecord, :attributes]}).returns('Title')
0
+      I18n.expects(:translate).with(:"custom.topic.title.invalid", :scope => global_scope, :default => [:"custom.topic.invalid", 'default from class def error 1', :invalid], :attribute => "Title", :model => "Topic").returns('default from class def error 1')
0
+      @topic.errors.generate_message :title, :invalid, :default => 'default from class def error 1'
0
     end
0
-  
0
+
0
     def test_errors_generate_message_translates_custom_model_attribute_keys_with_sti
0
-      custom_scope = [:active_record, :error_messages, :custom, 'topic', :title]
0
-  
0
-      I18n.expects(:t).with :"custom.reply.title.invalid", :scope => [:active_record, :error_messages], :default => [:"custom.topic.title.invalid", 'default from class def', :invalid]
0
+      custom_scope = [:activerecord, :errors, :custom, 'topic', :title]
0
+      I18n.expects(:translate).with('reply', {:count => 1, :default => 'Reply', :scope => [:activerecord, :models]}).returns('Reply')
0
+      I18n.expects(:translate).with(:'reply.title', {:count => 1, :default => [:'topic.title', 'Title'], :scope => [:activerecord, :attributes]}).returns('Title')
0
+      I18n.expects(:translate).with(:"custom.reply.title.invalid", :scope => [:activerecord, :errors, :messages], :default => [:"custom.reply.invalid", :"custom.topic.title.invalid", :"custom.topic.invalid", 'default from class def', :invalid], :model => 'Reply', :attribute => 'Title').returns("default from class def")
0
       Reply.new.errors.generate_message :title, :invalid, :default => 'default from class def'
0
     end
0
-  
0
+
0
     def test_errors_add_on_empty_generates_message
0
       @topic.errors.expects(:generate_message).with(:title, :empty, {:default => nil})
0
       @topic.errors.add_on_empty :title
0
@@ -79,7 +82,7 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
0
   
0
     def test_errors_full_messages_translates_human_attribute_name_for_model_attributes
0
       @topic.errors.instance_variable_set :@errors, { 'title' => 'empty' }
0
-      I18n.expects(:translate).with(:"active_record.human_attribute_names.topic.title", :locale => 'en-US', :default => 'Title').returns('Title')
0
+      I18n.expects(:translate).with(:"topic.title", :default => ['Title'], :scope => [:activerecord, :attributes], :count => 1).returns('Title')
0
       @topic.errors.full_messages :locale => 'en-US'
0
     end
0
   end  
0
@@ -344,8 +347,8 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
0
   # validates_confirmation_of w/o mocha
0
   
0
   def test_validates_confirmation_of_finds_custom_model_key_translation
0
-    I18n.backend.store_translations 'en-US', :active_record => {:error_messages => {:custom => {:topic => {:title => {:confirmation => 'custom message'}}}}}
0
-    I18n.backend.store_translations 'en-US', :active_record => {:error_messages => {:confirmation => 'global message'}}
0
+    I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:custom => {:topic => {:title => {:confirmation => 'custom message'}}}}}}
0
+    I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:confirmation => 'global message'}}}
0
   
0
     Topic.validates_confirmation_of :title
0
     @topic.title_confirmation = 'foo'
0
@@ -354,7 +357,7 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
0
   end
0
   
0
   def test_validates_confirmation_of_finds_global_default_translation
0
-    I18n.backend.store_translations 'en-US', :active_record => {:error_messages => {:confirmation => 'global message'}}
0
+    I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:confirmation => 'global message'}}}
0
   
0
     Topic.validates_confirmation_of :title
0
     @topic.title_confirmation = 'foo'
0
@@ -365,8 +368,8 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
0
   # validates_acceptance_of w/o mocha
0
   
0
   def test_validates_acceptance_of_finds_custom_model_key_translation
0
-    I18n.backend.store_translations 'en-US', :active_record => {:error_messages => {:custom => {:topic => {:title => {:accepted => 'custom message'}}}}}
0
-    I18n.backend.store_translations 'en-US', :active_record => {:error_messages => {:accepted => 'global message'}}
0
+    I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:custom => {:topic => {:title => {:accepted => 'custom message'}}}}}}
0
+    I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:accepted => 'global message'}}}
0
   
0
     Topic.validates_acceptance_of :title, :allow_nil => false
0
     @topic.valid?
0
@@ -374,7 +377,7 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
0
   end
0
   
0
   def test_validates_acceptance_of_finds_global_default_translation
0
-    I18n.backend.store_translations 'en-US', :active_record => {:error_messages => {:accepted => 'global message'}}
0
+    I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:accepted => 'global message'}}}
0
   
0
     Topic.validates_acceptance_of :title, :allow_nil => false
0
     @topic.valid?
0
@@ -384,8 +387,8 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
0
   # validates_presence_of w/o mocha
0
     
0
   def test_validates_presence_of_finds_custom_model_key_translation
0
-    I18n.backend.store_translations 'en-US', :active_record => {:error_messages => {:custom => {:topic => {:title => {:blank => 'custom message'}}}}}
0
-    I18n.backend.store_translations 'en-US', :active_record => {:error_messages => {:blank => 'global message'}}
0
+    I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:custom => {:topic => {:title => {:blank => 'custom message'}}}}}}
0
+    I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:blank => 'global message'}}}
0
   
0
     Topic.validates_presence_of :title
0
     @topic.valid?
0
@@ -393,7 +396,7 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
0
   end
0
   
0
   def test_validates_presence_of_finds_global_default_translation
0
-    I18n.backend.store_translations 'en-US', :active_record => {:error_messages => {:blank => 'global message'}}
0
+    I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:blank => 'global message'}}}
0
   
0
     Topic.validates_presence_of :title
0
     @topic.valid?
0
@@ -403,8 +406,8 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
0
   # validates_length_of :within w/o mocha
0
   
0
   def test_validates_length_of_within_finds_custom_model_key_translation
0
-    I18n.backend.store_translations 'en-US', :active_record => {:error_messages => {:custom => {:topic => {:title => {:too_short => 'custom message'}}}}}
0
-    I18n.backend.store_translations 'en-US', :active_record => {:error_messages => {:too_short => 'global message'}}
0
+    I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:custom => {:topic => {:title => {:too_short => 'custom message'}}}}}}
0
+    I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:too_short => 'global message'}}}
0
   
0
     Topic.validates_length_of :title, :within => 3..5
0
     @topic.valid?
0
@@ -412,7 +415,7 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
0
   end
0
   
0
   def test_validates_length_of_within_finds_global_default_translation
0
-    I18n.backend.store_translations 'en-US', :active_record => {:error_messages => {:too_short => 'global message'}}
0
+    I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:too_short => 'global message'}}}
0
   
0
     Topic.validates_length_of :title, :within => 3..5
0
     @topic.valid?
0
@@ -422,8 +425,8 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
0
   # validates_length_of :is w/o mocha
0
   
0
   def test_validates_length_of_within_finds_custom_model_key_translation
0
-    I18n.backend.store_translations 'en-US', :active_record => {:error_messages => {:custom => {:topic => {:title => {:wrong_length => 'custom message'}}}}}
0
-    I18n.backend.store_translations 'en-US', :active_record => {:error_messages => {:wrong_length => 'global message'}}
0
+    I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:custom => {:topic => {:title => {:wrong_length => 'custom message'}}}}}}
0
+    I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:wrong_length => 'global message'}}}
0
   
0
     Topic.validates_length_of :title, :is => 5
0
     @topic.valid?
0
@@ -431,7 +434,7 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
0
   end
0
   
0
   def test_validates_length_of_within_finds_global_default_translation
0
-    I18n.backend.store_translations 'en-US', :active_record => {:error_messages => {:wrong_length => 'global message'}}
0
+    I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:wrong_length => 'global message'}}}
0
   
0
     Topic.validates_length_of :title, :is => 5
0
     @topic.valid?
0
@@ -441,8 +444,8 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
0
   # validates_uniqueness_of w/o mocha
0
   
0
   def test_validates_length_of_within_finds_custom_model_key_translation
0
-    I18n.backend.store_translations 'en-US', :active_record => {:error_messages => {:custom => {:topic => {:title => {:wrong_length => 'custom message'}}}}}
0
-    I18n.backend.store_translations 'en-US', :active_record => {:error_messages => {:wrong_length => 'global message'}}
0
+    I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:custom => {:topic => {:title => {:wrong_length => 'custom message'}}}}}}
0
+    I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:wrong_length => 'global message'}}}
0
   
0
     Topic.validates_length_of :title, :is => 5
0
     @topic.valid?
0
@@ -450,7 +453,7 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
0
   end
0
   
0
   def test_validates_length_of_within_finds_global_default_translation
0
-    I18n.backend.store_translations 'en-US', :active_record => {:error_messages => {:wrong_length => 'global message'}}
0
+    I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:wrong_length => 'global message'}}}
0
   
0
     Topic.validates_length_of :title, :is => 5
0
     @topic.valid?
0
@@ -461,8 +464,8 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
0
   # validates_format_of w/o mocha
0
   
0
   def test_validates_format_of_finds_custom_model_key_translation
0
-    I18n.backend.store_translations 'en-US', :active_record => {:error_messages => {:custom => {:topic => {:title => {:invalid => 'custom message'}}}}}
0
-    I18n.backend.store_translations 'en-US', :active_record => {:error_messages => {:invalid => 'global message'}}
0
+    I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:custom => {:topic => {:title => {:invalid => 'custom message'}}}}}}
0
+    I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:invalid => 'global message'}}}
0
   
0
     Topic.validates_format_of :title, :with => /^[1-9][0-9]*$/
0
     @topic.valid?
0
@@ -470,7 +473,7 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
0
   end
0
   
0
   def test_validates_format_of_finds_global_default_translation
0
-    I18n.backend.store_translations 'en-US', :active_record => {:error_messages => {:invalid => 'global message'}}
0
+    I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:invalid => 'global message'}}}
0
   
0
     Topic.validates_format_of :title, :with => /^[1-9][0-9]*$/
0
     @topic.valid?
0
@@ -480,8 +483,8 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
0
   # validates_inclusion_of w/o mocha
0
   
0
   def test_validates_inclusion_of_finds_custom_model_key_translation
0
-    I18n.backend.store_translations 'en-US', :active_record => {:error_messages => {:custom => {:topic => {:title => {:inclusion => 'custom message'}}}}}
0
-    I18n.backend.store_translations 'en-US', :active_record => {:error_messages => {:inclusion => 'global message'}}
0
+    I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:custom => {:topic => {:title => {:inclusion => 'custom message'}}}}}}
0
+    I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:inclusion => 'global message'}}}
0
   
0
     Topic.validates_inclusion_of :title, :in => %w(a b c)
0
     @topic.valid?
0
@@ -489,7 +492,7 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
0
   end
0
   
0
   def test_validates_inclusion_of_finds_global_default_translation
0
-    I18n.backend.store_translations 'en-US', :active_record => {:error_messages => {:inclusion => 'global message'}}
0
+    I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:inclusion => 'global message'}}}
0
   
0
     Topic.validates_inclusion_of :title, :in => %w(a b c)
0
     @topic.valid?
0
@@ -499,8 +502,8 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
0
   # validates_exclusion_of w/o mocha
0
   
0
   def test_validates_exclusion_of_finds_custom_model_key_translation
0
-    I18n.backend.store_translations 'en-US', :active_record => {:error_messages => {:custom => {:topic => {:title => {:exclusion => 'custom message'}}}}}
0
-    I18n.backend.store_translations 'en-US', :active_record => {:error_messages => {:exclusion => 'global message'}}
0
+    I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:custom => {:topic => {:title => {:exclusion => 'custom message'}}}}}}
0
+    I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:exclusion => 'global message'}}}
0
   
0
     Topic.validates_exclusion_of :title, :in => %w(a b c)
0
     @topic.title = 'a'
0
@@ -509,7 +512,7 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
0
   end
0
   
0
   def test_validates_exclusion_of_finds_global_default_translation
0
-    I18n.backend.store_translations 'en-US', :active_record => {:error_messages => {:exclusion => 'global message'}}
0
+    I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:exclusion => 'global message'}}}
0
   
0
     Topic.validates_exclusion_of :title, :in => %w(a b c)
0
     @topic.title = 'a'
0
@@ -520,8 +523,8 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
0
   # validates_numericality_of without :only_integer w/o mocha
0
   
0
   def test_validates_numericality_of_finds_custom_model_key_translation
0
-    I18n.backend.store_translations 'en-US', :active_record => {:error_messages => {:custom => {:topic => {:title => {:not_a_number => 'custom message'}}}}}
0
-    I18n.backend.store_translations 'en-US', :active_record => {:error_messages => {:not_a_number => 'global message'}}
0
+    I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:custom => {:topic => {:title => {:not_a_number => 'custom message'}}}}}}
0
+    I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:not_a_number => 'global message'}}}
0
   
0
     Topic.validates_numericality_of :title
0
     @topic.title = 'a'
0
@@ -530,7 +533,7 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
0
   end
0
   
0
   def test_validates_numericality_of_finds_global_default_translation
0
-    I18n.backend.store_translations 'en-US', :active_record => {:error_messages => {:not_a_number => 'global message'}}
0
+    I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:not_a_number => 'global message'}}}
0
   
0
     Topic.validates_numericality_of :title, :only_integer => true
0
     @topic.title = 'a'
0
@@ -541,8 +544,8 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
0
   # validates_numericality_of with :only_integer w/o mocha
0
   
0
   def test_validates_numericality_of_only_integer_finds_custom_model_key_translation
0
-    I18n.backend.store_translations 'en-US', :active_record => {:error_messages => {:custom => {:topic => {:title => {:not_a_number => 'custom message'}}}}}
0
-    I18n.backend.store_translations 'en-US', :active_record => {:error_messages => {:not_a_number => 'global message'}}
0
+    I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:custom => {:topic => {:title => {:not_a_number => 'custom message'}}}}}}
0
+    I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:not_a_number => 'global message'}}}
0
   
0
     Topic.validates_numericality_of :title, :only_integer => true
0
     @topic.title = 'a'
0
@@ -551,7 +554,7 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
0
   end
0
   
0
   def test_validates_numericality_of_only_integer_finds_global_default_translation
0
-    I18n.backend.store_translations 'en-US', :active_record => {:error_messages => {:not_a_number => 'global message'}}
0
+    I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:not_a_number => 'global message'}}}
0
   
0
     Topic.validates_numericality_of :title, :only_integer => true
0
     @topic.title = 'a'
0
@@ -562,8 +565,8 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
0
   # validates_numericality_of :odd w/o mocha
0
   
0
   def test_validates_numericality_of_odd_finds_custom_model_key_translation
0
-    I18n.backend.store_translations 'en-US', :active_record => {:error_messages => {:custom => {:topic => {:title => {:odd => 'custom message'}}}}}
0
-    I18n.backend.store_translations 'en-US', :active_record => {:error_messages => {:odd => 'global message'}}
0
+    I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:custom => {:topic => {:title => {:odd => 'custom message'}}}}}}
0
+    I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:odd => 'global message'}}}
0
   
0
     Topic.validates_numericality_of :title, :only_integer => true, :odd => true
0
     @topic.title = 0
0
@@ -572,7 +575,7 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
0
   end
0
   
0
   def test_validates_numericality_of_odd_finds_global_default_translation
0
-    I18n.backend.store_translations 'en-US', :active_record => {:error_messages => {:odd => 'global message'}}
0
+    I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:odd => 'global message'}}}
0
   
0
     Topic.validates_numericality_of :title, :only_integer => true, :odd => true
0
     @topic.title = 0
0
@@ -583,8 +586,8 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
0
   # validates_numericality_of :less_than w/o mocha
0
   
0
   def test_validates_numericality_of_less_than_finds_custom_model_key_translation
0
-    I18n.backend.store_translations 'en-US', :active_record => {:error_messages => {:custom => {:topic => {:title => {:less_than => 'custom message'}}}}}
0
-    I18n.backend.store_translations 'en-US', :active_record => {:error_messages => {:less_than => 'global message'}}
0
+    I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:custom => {:topic => {:title => {:less_than => 'custom message'}}}}}}
0
+    I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:less_than => 'global message'}}}
0
   
0
     Topic.validates_numericality_of :title, :only_integer => true, :less_than => 0
0
     @topic.title = 1
0
@@ -593,7 +596,7 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
0
   end
0
   
0
   def test_validates_numericality_of_less_than_finds_global_default_translation
0
-    I18n.backend.store_translations 'en-US', :active_record => {:error_messages => {:less_than => 'global message'}}
0
+    I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:less_than => 'global message'}}}
0
   
0
     Topic.validates_numericality_of :title, :only_integer => true, :less_than => 0
0
     @topic.title = 1
0
@@ -605,8 +608,8 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
0
   # validates_associated w/o mocha
0
   
0
   def test_validates_associated_finds_custom_model_key_translation
0
-    I18n.backend.store_translations 'en-US', :active_record => {:error_messages => {:custom => {:topic => {:replies => {:invalid => 'custom message'}}}}}
0
-    I18n.backend.store_translations 'en-US', :active_record => {:error_messages => {:invalid => 'global message'}}
0
+    I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:custom => {:topic => {:replies => {:invalid => 'custom message'}}}}}}
0
+    I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:invalid => 'global message'}}}
0
   
0
     Topic.validates_associated :replies
0
     replied_topic.valid?
0
@@ -614,7 +617,7 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
0
   end
0
   
0
   def test_validates_associated_finds_global_default_translation
0
-    I18n.backend.store_translations 'en-US', :active_record => {:error_messages => {:invalid => 'global message'}}
0
+    I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:invalid => 'global message'}}}
0
   
0
     Topic.validates_associated :replies
0
     replied_topic.valid?
0
@@ -627,27 +630,29 @@ class ActiveRecordValidationsGenerateMessageI18nTests < Test::Unit::TestCase
0
     reset_callbacks Topic
0
     @topic = Topic.new
0
     I18n.backend.store_translations :'en-US', {
0
-      :active_record => {
0
-        :error_messages => {
0
-          :inclusion => "is not included in the list",
0
-          :exclusion => "is reserved",
0
-          :invalid => "is invalid",
0
-          :confirmation => "doesn't match confirmation",
0
-          :accepted  => "must be accepted",
0
-          :empty => "can't be empty",
0
-          :blank => "can't be blank",
0
-          :too_long => "is too long (maximum is {{count}} characters)",
0
-          :too_short => "is too short (minimum is {{count}} characters)",
0
-          :wrong_length => "is the wrong length (should be {{count}} characters)",
0
-          :taken => "has already been taken",
0
-          :not_a_number => "is not a number",
0
-          :greater_than => "must be greater than {{count}}",
0
-          :greater_than_or_equal_to => "must be greater than or equal to {{count}}",
0
-          :equal_to => "must be equal to {{count}}",
0
-          :less_than => "must be less than {{count}}",
0
-          :less_than_or_equal_to => "must be less than or equal to {{count}}",
0
-          :odd => "must be odd",
0
-          :even => "must be even"
0
+      :activerecord => {
0
+        :errors => {
0
+          :messages => {
0
+            :inclusion => "is not included in the list",
0
+            :exclusion => "is reserved",
0
+            :invalid => "is invalid",
0
+            :confirmation => "doesn't match confirmation",
0
+            :accepted  => "must be accepted",
0
+            :empty => "can't be empty",
0
+            :blank => "can't be blank",
0
+            :too_long => "is too long (maximum is {{count}} characters)",
0
+            :too_short => "is too short (minimum is {{count}} characters)",
0
+            :wrong_length => "is the wrong length (should be {{count}} characters)",
0
+            :taken => "has already been taken",
0
+            :not_a_number => "is not a number",
0
+            :greater_than => "must be greater than {{count}}",
0
+            :greater_than_or_equal_to => "must be greater than or equal to {{count}}",
0
+            :equal_to => "must be equal to {{count}}",
0
+            :less_than => "must be less than {{count}}",
0
+            :less_than_or_equal_to => "must be less than or equal to {{count}}",
0
+            :odd => "must be odd",
0
+            :even => "must be even"
0
+          }
0
         }            
0
       }
0
     }
0
@@ -798,4 +803,4 @@ class ActiveRecordValidationsGenerateMessageI18nTests < Test::Unit::TestCase
0
   def test_generate_message_even_with_default_message
0
     assert_equal "must be even", @topic.errors.generate_message(:title, :even, :default => nil, :value => 'title', :count => 10)
0
   end
0
-end
0
\ No newline at end of file
0
+end

Comments