aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/test/cases/validations/i18n_validation_test.rb
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2010-05-15 21:55:16 +0200
committerJosé Valim <jose.valim@gmail.com>2010-05-15 21:55:16 +0200
commitd6cbb27e7b260c970bf7d07dc0b0591ed82cee2a (patch)
treeccd57aa2f19b43943ae6fb8e34fbb34b3a673726 /activemodel/test/cases/validations/i18n_validation_test.rb
parentf055bc05d515b80c89b99b775546b954f270bc5c (diff)
downloadrails-d6cbb27e7b260c970bf7d07dc0b0591ed82cee2a.tar.gz
rails-d6cbb27e7b260c970bf7d07dc0b0591ed82cee2a.tar.bz2
rails-d6cbb27e7b260c970bf7d07dc0b0591ed82cee2a.zip
Revert "Make ActiveModel::Errors#add_on_blank and #add_on_empty accept an options hash and make various Validators pass their (filtered) options."
Having a huge array to whitelist options is not the proper way to handle this case. This means that the ActiveModel::Errors object should know about the options given in *all* validators and break the extensibility added by the validators itself. If the intent is to whitelist options before sending them to I18n, each validator should clean its respective options instead of throwing the responsibility to the Errors object. This reverts commit bc1c8d58ec45593acba614d1d0fecb49adef08ff.
Diffstat (limited to 'activemodel/test/cases/validations/i18n_validation_test.rb')
-rw-r--r--activemodel/test/cases/validations/i18n_validation_test.rb64
1 files changed, 32 insertions, 32 deletions
diff --git a/activemodel/test/cases/validations/i18n_validation_test.rb b/activemodel/test/cases/validations/i18n_validation_test.rb
index eff2b78e74..547d80f46e 100644
--- a/activemodel/test/cases/validations/i18n_validation_test.rb
+++ b/activemodel/test/cases/validations/i18n_validation_test.rb
@@ -22,23 +22,23 @@ class I18nValidationTest < ActiveModel::TestCase
end
def test_errors_add_on_empty_generates_message
- @person.errors.expects(:generate_message).with(:title, :empty, {})
+ @person.errors.expects(:generate_message).with(:title, :empty, {:default => nil})
@person.errors.add_on_empty :title
end
def test_errors_add_on_empty_generates_message_with_custom_default_message
- @person.errors.expects(:generate_message).with(:title, :empty, {:message => 'custom'})
- @person.errors.add_on_empty :title, :message => 'custom'
+ @person.errors.expects(:generate_message).with(:title, :empty, {:default => 'custom'})
+ @person.errors.add_on_empty :title, 'custom'
end
def test_errors_add_on_blank_generates_message
- @person.errors.expects(:generate_message).with(:title, :blank, {})
+ @person.errors.expects(:generate_message).with(:title, :blank, {:default => nil})
@person.errors.add_on_blank :title
end
def test_errors_add_on_blank_generates_message_with_custom_default_message
- @person.errors.expects(:generate_message).with(:title, :blank, {:message => 'custom'})
- @person.errors.add_on_blank :title, :message => 'custom'
+ @person.errors.expects(:generate_message).with(:title, :blank, {:default => 'custom'})
+ @person.errors.add_on_blank :title, 'custom'
end
def test_full_message_encoding
@@ -66,14 +66,14 @@ class I18nValidationTest < ActiveModel::TestCase
def test_validates_confirmation_of_generates_message
Person.validates_confirmation_of :title
@person.title_confirmation = 'foo'
- @person.errors.expects(:generate_message).with(:title, :confirmation, {})
+ @person.errors.expects(:generate_message).with(:title, :confirmation, {:default => nil})
@person.valid?
end
def test_validates_confirmation_of_generates_message_with_custom_default_message
Person.validates_confirmation_of :title, :message => 'custom'
@person.title_confirmation = 'foo'
- @person.errors.expects(:generate_message).with(:title, :confirmation, {:message => 'custom'})
+ @person.errors.expects(:generate_message).with(:title, :confirmation, {:default => 'custom'})
@person.valid?
end
@@ -81,13 +81,13 @@ class I18nValidationTest < ActiveModel::TestCase
def test_validates_acceptance_of_generates_message
Person.validates_acceptance_of :title, :allow_nil => false
- @person.errors.expects(:generate_message).with(:title, :accepted, {})
+ @person.errors.expects(:generate_message).with(:title, :accepted, {:default => nil})
@person.valid?
end
def test_validates_acceptance_of_generates_message_with_custom_default_message
Person.validates_acceptance_of :title, :message => 'custom', :allow_nil => false
- @person.errors.expects(:generate_message).with(:title, :accepted, {:message => 'custom'})
+ @person.errors.expects(:generate_message).with(:title, :accepted, {:default => 'custom'})
@person.valid?
end
@@ -95,13 +95,13 @@ class I18nValidationTest < ActiveModel::TestCase
def test_validates_presence_of_generates_message
Person.validates_presence_of :title
- @person.errors.expects(:generate_message).with(:title, :blank, {})
+ @person.errors.expects(:generate_message).with(:title, :blank, {:default => nil})
@person.valid?
end
def test_validates_presence_of_generates_message_with_custom_default_message
Person.validates_presence_of :title, :message => 'custom'
- @person.errors.expects(:generate_message).with(:title, :blank, {:message => 'custom'})
+ @person.errors.expects(:generate_message).with(:title, :blank, {:default => 'custom'})
@person.valid?
end
@@ -109,27 +109,27 @@ class I18nValidationTest < ActiveModel::TestCase
def test_validates_length_of_within_generates_message_with_title_too_short
Person.validates_length_of :title, :within => 3..5
- @person.errors.expects(:generate_message).with(:title, :too_short, {:count => 3})
+ @person.errors.expects(:generate_message).with(:title, :too_short, {:count => 3, :default => nil})
@person.valid?
end
def test_validates_length_of_within_generates_message_with_title_too_short_and_custom_default_message
Person.validates_length_of :title, :within => 3..5, :too_short => 'custom'
- @person.errors.expects(:generate_message).with(:title, :too_short, {:count => 3, :message => 'custom'})
+ @person.errors.expects(:generate_message).with(:title, :too_short, {:count => 3, :default => 'custom'})
@person.valid?
end
def test_validates_length_of_within_generates_message_with_title_too_long
Person.validates_length_of :title, :within => 3..5
@person.title = 'this title is too long'
- @person.errors.expects(:generate_message).with(:title, :too_long, {:count => 5})
+ @person.errors.expects(:generate_message).with(:title, :too_long, {:count => 5, :default => nil})
@person.valid?
end
def test_validates_length_of_within_generates_message_with_title_too_long_and_custom_default_message
Person.validates_length_of :title, :within => 3..5, :too_long => 'custom'
@person.title = 'this title is too long'
- @person.errors.expects(:generate_message).with(:title, :too_long, {:count => 5, :message => 'custom'})
+ @person.errors.expects(:generate_message).with(:title, :too_long, {:count => 5, :default => 'custom'})
@person.valid?
end
@@ -137,13 +137,13 @@ class I18nValidationTest < ActiveModel::TestCase
def test_validates_length_of_is_generates_message
Person.validates_length_of :title, :is => 5
- @person.errors.expects(:generate_message).with(:title, :wrong_length, {:count => 5})
+ @person.errors.expects(:generate_message).with(:title, :wrong_length, {:count => 5, :default => nil})
@person.valid?
end
def test_validates_length_of_is_generates_message_with_custom_default_message
Person.validates_length_of :title, :is => 5, :message => 'custom'
- @person.errors.expects(:generate_message).with(:title, :wrong_length, {:count => 5, :message => 'custom'})
+ @person.errors.expects(:generate_message).with(:title, :wrong_length, {:count => 5, :default => 'custom'})
@person.valid?
end
@@ -152,14 +152,14 @@ class I18nValidationTest < ActiveModel::TestCase
def test_validates_format_of_generates_message
Person.validates_format_of :title, :with => /^[1-9][0-9]*$/
@person.title = '72x'
- @person.errors.expects(:generate_message).with(:title, :invalid, {:value => '72x'})
+ @person.errors.expects(:generate_message).with(:title, :invalid, {:value => '72x', :default => nil})
@person.valid?
end
def test_validates_format_of_generates_message_with_custom_default_message
Person.validates_format_of :title, :with => /^[1-9][0-9]*$/, :message => 'custom'
@person.title = '72x'
- @person.errors.expects(:generate_message).with(:title, :invalid, {:value => '72x', :message => 'custom'})
+ @person.errors.expects(:generate_message).with(:title, :invalid, {:value => '72x', :default => 'custom'})
@person.valid?
end
@@ -168,14 +168,14 @@ class I18nValidationTest < ActiveModel::TestCase
def test_validates_inclusion_of_generates_message
Person.validates_inclusion_of :title, :in => %w(a b c)
@person.title = 'z'
- @person.errors.expects(:generate_message).with(:title, :inclusion, {:value => 'z'})
+ @person.errors.expects(:generate_message).with(:title, :inclusion, {:value => 'z', :default => nil})
@person.valid?
end
def test_validates_inclusion_of_generates_message_with_custom_default_message
Person.validates_inclusion_of :title, :in => %w(a b c), :message => 'custom'
@person.title = 'z'
- @person.errors.expects(:generate_message).with(:title, :inclusion, {:value => 'z', :message => 'custom'})
+ @person.errors.expects(:generate_message).with(:title, :inclusion, {:value => 'z', :default => 'custom'})
@person.valid?
end
@@ -184,14 +184,14 @@ class I18nValidationTest < ActiveModel::TestCase
def test_validates_exclusion_of_generates_message
Person.validates_exclusion_of :title, :in => %w(a b c)
@person.title = 'a'
- @person.errors.expects(:generate_message).with(:title, :exclusion, {:value => 'a'})
+ @person.errors.expects(:generate_message).with(:title, :exclusion, {:value => 'a', :default => nil})
@person.valid?
end
def test_validates_exclusion_of_generates_message_with_custom_default_message
Person.validates_exclusion_of :title, :in => %w(a b c), :message => 'custom'
@person.title = 'a'
- @person.errors.expects(:generate_message).with(:title, :exclusion, {:value => 'a', :message => 'custom'})
+ @person.errors.expects(:generate_message).with(:title, :exclusion, {:value => 'a', :default => 'custom'})
@person.valid?
end
@@ -200,14 +200,14 @@ class I18nValidationTest < ActiveModel::TestCase
def test_validates_numericality_of_generates_message
Person.validates_numericality_of :title
@person.title = 'a'
- @person.errors.expects(:generate_message).with(:title, :not_a_number, {:value => 'a'})
+ @person.errors.expects(:generate_message).with(:title, :not_a_number, {:value => 'a', :default => nil})
@person.valid?
end
def test_validates_numericality_of_generates_message_with_custom_default_message
Person.validates_numericality_of :title, :message => 'custom'
@person.title = 'a'
- @person.errors.expects(:generate_message).with(:title, :not_a_number, {:value => 'a', :message => 'custom'})
+ @person.errors.expects(:generate_message).with(:title, :not_a_number, {:value => 'a', :default => 'custom'})
@person.valid?
end
@@ -216,14 +216,14 @@ class I18nValidationTest < ActiveModel::TestCase
def test_validates_numericality_of_only_integer_generates_message
Person.validates_numericality_of :title, :only_integer => true
@person.title = '0.0'
- @person.errors.expects(:generate_message).with(:title, :not_an_integer, {:value => '0.0'})
+ @person.errors.expects(:generate_message).with(:title, :not_an_integer, {:value => '0.0', :default => nil})
@person.valid?
end
def test_validates_numericality_of_only_integer_generates_message_with_custom_default_message
Person.validates_numericality_of :title, :only_integer => true, :message => 'custom'
@person.title = '0.0'
- @person.errors.expects(:generate_message).with(:title, :not_an_integer, {:value => '0.0', :message => 'custom'})
+ @person.errors.expects(:generate_message).with(:title, :not_an_integer, {:value => '0.0', :default => 'custom'})
@person.valid?
end
@@ -232,14 +232,14 @@ class I18nValidationTest < ActiveModel::TestCase
def test_validates_numericality_of_odd_generates_message
Person.validates_numericality_of :title, :only_integer => true, :odd => true
@person.title = 0
- @person.errors.expects(:generate_message).with(:title, :odd, {:value => 0})
+ @person.errors.expects(:generate_message).with(:title, :odd, {:value => 0, :default => nil})
@person.valid?
end
def test_validates_numericality_of_odd_generates_message_with_custom_default_message
Person.validates_numericality_of :title, :only_integer => true, :odd => true, :message => 'custom'
@person.title = 0
- @person.errors.expects(:generate_message).with(:title, :odd, {:value => 0, :message => 'custom'})
+ @person.errors.expects(:generate_message).with(:title, :odd, {:value => 0, :default => 'custom'})
@person.valid?
end
@@ -248,14 +248,14 @@ class I18nValidationTest < ActiveModel::TestCase
def test_validates_numericality_of_less_than_generates_message
Person.validates_numericality_of :title, :only_integer => true, :less_than => 0
@person.title = 1
- @person.errors.expects(:generate_message).with(:title, :less_than, {:value => 1, :count => 0})
+ @person.errors.expects(:generate_message).with(:title, :less_than, {:value => 1, :count => 0, :default => nil})
@person.valid?
end
def test_validates_numericality_of_less_than_odd_generates_message_with_custom_default_message
Person.validates_numericality_of :title, :only_integer => true, :less_than => 0, :message => 'custom'
@person.title = 1
- @person.errors.expects(:generate_message).with(:title, :less_than, {:value => 1, :count => 0, :message => 'custom'})
+ @person.errors.expects(:generate_message).with(:title, :less_than, {:value => 1, :count => 0, :default => 'custom'})
@person.valid?
end