aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorJohn D. Hume <duelin.markers@gmail.com>2008-05-28 23:35:56 -0400
committerMichael Koziarski <michael@koziarski.com>2008-05-31 16:58:24 -0700
commit61036a60eb4677d0b1bc0f9c5ca47ad856301431 (patch)
tree358f33c47a4abe3730d34480af066d56a7d67861 /activerecord
parenta6e79083273dfb1a62aa8ff02db07454c65729ff (diff)
downloadrails-61036a60eb4677d0b1bc0f9c5ca47ad856301431.tar.gz
rails-61036a60eb4677d0b1bc0f9c5ca47ad856301431.tar.bz2
rails-61036a60eb4677d0b1bc0f9c5ca47ad856301431.zip
Substitute value into validates_format_of message
Signed-off-by: Michael Koziarski <michael@koziarski.com>
Diffstat (limited to 'activerecord')
-rwxr-xr-xactiverecord/lib/active_record/validations.rb2
-rwxr-xr-xactiverecord/test/cases/validations_test.rb6
2 files changed, 7 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/validations.rb b/activerecord/lib/active_record/validations.rb
index 0e150bddb2..c97aafb126 100755
--- a/activerecord/lib/active_record/validations.rb
+++ b/activerecord/lib/active_record/validations.rb
@@ -692,7 +692,7 @@ module ActiveRecord
raise(ArgumentError, "A regular expression must be supplied as the :with option of the configuration hash") unless configuration[:with].is_a?(Regexp)
validates_each(attr_names, configuration) do |record, attr_name, value|
- record.errors.add(attr_name, configuration[:message]) unless value.to_s =~ configuration[:with]
+ record.errors.add(attr_name, configuration[:message] % value) unless value.to_s =~ configuration[:with]
end
end
diff --git a/activerecord/test/cases/validations_test.rb b/activerecord/test/cases/validations_test.rb
index a4d9da4806..7b71647d25 100755
--- a/activerecord/test/cases/validations_test.rb
+++ b/activerecord/test/cases/validations_test.rb
@@ -583,6 +583,12 @@ class ValidationsTest < ActiveRecord::TestCase
assert_nil t.errors.on(:title)
end
+ def test_validate_format_with_formatted_message
+ Topic.validates_format_of(:title, :with => /^Valid Title$/, :message => "can't be %s")
+ t = Topic.create(:title => 'Invalid title')
+ assert_equal "can't be Invalid title", t.errors.on(:title)
+ end
+
def test_validates_inclusion_of
Topic.validates_inclusion_of( :title, :in => %w( a b c d e f g ) )