public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Added :value as interpolation variable available to error messages
iain (author)
Sat Aug 16 12:45:23 -0700 2008
svenfuchs (committer)
Wed Aug 20 08:41:43 -0700 2008
commit  e2b191681e1c8c8b4344f1fc755e48fccdd1d603
tree    3ceb26919e5da195fefc88dae4f88e87a395d02a
parent  c531248938302477c5e52138d59a6c3d1527d963
...
92
93
94
95
96
 
 
97
98
99
100
101
102
103
104
105
 
 
 
 
 
 
 
 
106
107
108
...
92
93
94
 
 
95
96
97
98
99
 
 
 
 
 
 
100
101
102
103
104
105
106
107
108
109
110
0
@@ -92,17 +92,19 @@ module ActiveRecord
0
           :"custom.#{klass.name.underscore}.#{message}" ]
0
       end
0
       
0
-      defaults << options[:default] if options[:default]
0
-      defaults.flatten! << message
0
+      defaults << options.delete(:default)
0
+      defaults = defaults.compact.flatten << message
0
 
0
       model_name = @base.class.name
0
       key = defaults.shift
0
-
0
-      options.merge!({ 
0
-          :default => defaults,
0
-          :model => @base.class.human_name,
0
-          :attribute => @base.class.human_attribute_name(attribute.to_s),
0
-          :scope => [:activerecord, :errors, :messages] })
0
+      value = @base.send(attribute) if @base.respond_to?(attribute)
0
+
0
+      options = { :default => defaults,
0
+        :model => @base.class.human_name,
0
+        :attribute => @base.class.human_attribute_name(attribute.to_s),
0
+        :value => value,
0
+        :scope => [:activerecord, :errors, :messages]
0
+      }.merge(options)
0
 
0
       I18n.translate(key, options)
0
     end
...
48
49
50
51
 
52
53
54
...
56
57
58
59
 
60
61
62
...
48
49
50
 
51
52
53
54
...
56
57
58
 
59
60
61
62
0
@@ -48,7 +48,7 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
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
+      I18n.expects(:translate).with(:"custom.topic.title.invalid", :value => nil, :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
@@ -56,7 +56,7 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
0
       custom_scope = [:activerecord, :errors, :custom, 'topic', :title]
0
       I18n.expects(:translate).with(:reply, {:count => 1, :default => [:topic, '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
+      I18n.expects(:translate).with(:"custom.reply.title.invalid", :value => nil, :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
 

Comments