Skip to content
Browse files

Don't pass `:within` option to the i18n

  • Loading branch information...
1 parent 53edd32 commit 770fa81bbad8a77b41a1b5af3c926e6652acccd6 @rafaelfranca rafaelfranca committed Jul 20, 2012
View
2 activemodel/lib/active_model/validations/exclusion.rb
@@ -9,7 +9,7 @@ class ExclusionValidator < EachValidator #:nodoc:
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
2 activemodel/lib/active_model/validations/inclusion.rb
@@ -9,7 +9,7 @@ class InclusionValidator < EachValidator #:nodoc:
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
22 activemodel/test/cases/validations/i18n_validation_test.rb
@@ -159,6 +159,17 @@ def test_errors_full_messages_uses_format
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 @@ def test_errors_full_messages_uses_format
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|

0 comments on commit 770fa81

Please sign in to comment.
Something went wrong with that request. Please try again.