public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Substitute value into validates_format_of message

Signed-off-by: Michael Koziarski <michael@koziarski.com>
duelinmarkers (author)
Wed May 28 20:35:56 -0700 2008
NZKoz (committer)
Sat May 31 16:59:03 -0700 2008
commit  f6e921f9568d7f2e4807edf8728e6b0df8991816
tree    87d6b37a4ccdfffbc26a7ac6b9f5ef1470d9c073
parent  ef0ea782b1f5cf7b08e74ea3002a16c708f66645
...
692
693
694
695
 
696
697
698
...
692
693
694
 
695
696
697
698
0
@@ -692,7 +692,7 @@ module ActiveRecord
0
         raise(ArgumentError, "A regular expression must be supplied as the :with option of the configuration hash") unless configuration[:with].is_a?(Regexp)
0
 
0
         validates_each(attr_names, configuration) do |record, attr_name, value|
0
-          record.errors.add(attr_name, configuration[:message]) unless value.to_s =~ configuration[:with]
0
+          record.errors.add(attr_name, configuration[:message] % value) unless value.to_s =~ configuration[:with]
0
         end
0
       end
0
 
...
583
584
585
 
 
 
 
 
 
586
587
588
...
583
584
585
586
587
588
589
590
591
592
593
594
0
@@ -583,6 +583,12 @@ class ValidationsTest < ActiveRecord::TestCase
0
     assert_nil t.errors.on(:title)
0
   end
0
 
0
+  def test_validate_format_with_formatted_message
0
+    Topic.validates_format_of(:title, :with => /^Valid Title$/, :message => "can't be %s")
0
+    t = Topic.create(:title => 'Invalid title')
0
+    assert_equal "can't be Invalid title", t.errors.on(:title)
0
+  end
0
+
0
   def test_validates_inclusion_of
0
     Topic.validates_inclusion_of( :title, :in => %w( a b c d e f g ) )
0
 

Comments