mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Substitute value into validates_format_of message
Signed-off-by: Michael Koziarski <michael@koziarski.com>
This commit is contained in:
parent
ef0ea782b1
commit
f6e921f956
2 changed files with 7 additions and 1 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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 ) )
|
||||
|
||||
|
|
Loading…
Reference in a new issue