1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Don't pass :within option to the i18n

This commit is contained in:
Rafael Mendonça França 2012-07-20 14:10:25 -03:00
parent 53edd32684
commit 770fa81bba
3 changed files with 24 additions and 2 deletions

View file

@ -9,7 +9,7 @@ module ActiveModel
def validate_each(record, attribute, value)
if include?(record, value)
record.errors.add(attribute, :exclusion, options.except(:in).merge!(:value => value))
record.errors.add(attribute, :exclusion, options.except(:in, :within).merge!(:value => value))
end
end
end

View file

@ -9,7 +9,7 @@ module ActiveModel
def validate_each(record, attribute, value)
unless include?(record, value)
record.errors.add(attribute, :inclusion, options.except(:in).merge!(:value => value))
record.errors.add(attribute, :inclusion, options.except(:in, :within).merge!(:value => value))
end
end
end

View file

@ -159,6 +159,17 @@ class I18nValidationTest < ActiveModel::TestCase
end
end
# validates_inclusion_of using :within w/ mocha
COMMON_CASES.each do |name, validation_options, generate_message_options|
test "validates_inclusion_of using :within on generated message #{name}" do
Person.validates_inclusion_of :title, validation_options.merge(:within => %w(a b c))
@person.title = 'z'
@person.errors.expects(:generate_message).with(:title, :inclusion, generate_message_options.merge(:value => 'z'))
@person.valid?
end
end
# validates_exclusion_of w/ mocha
COMMON_CASES.each do |name, validation_options, generate_message_options|
@ -170,6 +181,17 @@ class I18nValidationTest < ActiveModel::TestCase
end
end
# validates_exclusion_of using :within w/ mocha
COMMON_CASES.each do |name, validation_options, generate_message_options|
test "validates_exclusion_of using :within generated message #{name}" do
Person.validates_exclusion_of :title, validation_options.merge(:within => %w(a b c))
@person.title = 'a'
@person.errors.expects(:generate_message).with(:title, :exclusion, generate_message_options.merge(:value => 'a'))
@person.valid?
end
end
# validates_numericality_of without :only_integer w/ mocha
COMMON_CASES.each do |name, validation_options, generate_message_options|