Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Deprecate Error#on(attribute) in favour of Errors#[attribute]

  • Loading branch information...
commit 37283a6aaec244cb484e24b3e9ff165e89eadd64 1 parent 4367f39
@lifo lifo authored
View
8 activemodel/lib/active_model/deprecated_error_methods.rb
@@ -1,10 +1,10 @@
module ActiveModel
module DeprecatedErrorMethods
def on(attribute)
- # message = "Errors#on have been deprecated, use Errors#[] instead.\n"
- # message << "Also note that the behaviour of Errors#[] has changed. Errors#[] now always returns an Array and an empty Array when "
- # message << "there are not errors on the specified attribute."
- # ActiveSupport::Deprecation.warn(message)
+ message = "Errors#on have been deprecated, use Errors#[] instead.\n"
+ message << "Also note that the behaviour of Errors#[] has changed. Errors#[] now always returns an Array and an empty Array when "
+ message << "there are not errors on the specified attribute."
+ ActiveSupport::Deprecation.warn(message)
errors = self[attribute]
errors.size < 2 ? errors.first : errors
View
4 activemodel/test/cases/validations/exclusion_validation_test.rb
@@ -24,7 +24,7 @@ def test_validates_exclusion_of_with_formatted_message
t = Topic.create("title" => "monkey")
assert !t.valid?
- assert t.errors.on(:title)
- assert_equal "option monkey is restricted", t.errors.on(:title)
+ assert t.errors[:title].any?
+ assert_equal ["option monkey is restricted"], t.errors[:title]
end
end
View
2  activemodel/test/cases/validations/format_validation_test.rb
@@ -66,7 +66,7 @@ def test_validate_format_numeric
def test_validate_format_with_formatted_message
Topic.validates_format_of(:title, :with => /^Valid Title$/, :message => "can't be {{value}}")
t = Topic.create(:title => 'Invalid title')
- assert_equal "can't be Invalid title", t.errors.on(:title)
+ assert_equal ["can't be Invalid title"], t.errors[:title]
end
def test_validates_format_of_with_custom_error_using_quotes
View
60 activemodel/test/cases/validations/i18n_validation_test.rb
@@ -389,7 +389,7 @@ def test_validates_confirmation_of_finds_custom_model_key_translation
Topic.validates_confirmation_of :title
@topic.title_confirmation = 'foo'
@topic.valid?
- assert_equal 'custom message', @topic.errors.on(:title)
+ assert_equal ['custom message'], @topic.errors[:title]
end
def test_validates_confirmation_of_finds_global_default_translation
@@ -398,7 +398,7 @@ def test_validates_confirmation_of_finds_global_default_translation
Topic.validates_confirmation_of :title
@topic.title_confirmation = 'foo'
@topic.valid?
- assert_equal 'global message', @topic.errors.on(:title)
+ assert_equal ['global message'], @topic.errors[:title]
end
# validates_acceptance_of w/o mocha
@@ -409,7 +409,7 @@ def test_validates_acceptance_of_finds_custom_model_key_translation
Topic.validates_acceptance_of :title, :allow_nil => false
@topic.valid?
- assert_equal 'custom message', @topic.errors.on(:title)
+ assert_equal ['custom message'], @topic.errors[:title]
end
def test_validates_acceptance_of_finds_global_default_translation
@@ -417,7 +417,7 @@ def test_validates_acceptance_of_finds_global_default_translation
Topic.validates_acceptance_of :title, :allow_nil => false
@topic.valid?
- assert_equal 'global message', @topic.errors.on(:title)
+ assert_equal ['global message'], @topic.errors[:title]
end
# validates_presence_of w/o mocha
@@ -428,7 +428,7 @@ def test_validates_presence_of_finds_custom_model_key_translation
Topic.validates_presence_of :title
@topic.valid?
- assert_equal 'custom message', @topic.errors.on(:title)
+ assert_equal ['custom message'], @topic.errors[:title]
end
def test_validates_presence_of_finds_global_default_translation
@@ -436,7 +436,7 @@ def test_validates_presence_of_finds_global_default_translation
Topic.validates_presence_of :title
@topic.valid?
- assert_equal 'global message', @topic.errors.on(:title)
+ assert_equal ['global message'], @topic.errors[:title]
end
# validates_length_of :within w/o mocha
@@ -447,7 +447,7 @@ def test_validates_length_of_within_finds_custom_model_key_translation
Topic.validates_length_of :title, :within => 3..5
@topic.valid?
- assert_equal 'custom message', @topic.errors.on(:title)
+ assert_equal ['custom message'], @topic.errors[:title]
end
def test_validates_length_of_within_finds_global_default_translation
@@ -455,7 +455,7 @@ def test_validates_length_of_within_finds_global_default_translation
Topic.validates_length_of :title, :within => 3..5
@topic.valid?
- assert_equal 'global message', @topic.errors.on(:title)
+ assert_equal ['global message'], @topic.errors[:title]
end
# validates_length_of :is w/o mocha
@@ -466,7 +466,7 @@ def test_validates_length_of_is_finds_custom_model_key_translation
Topic.validates_length_of :title, :is => 5
@topic.valid?
- assert_equal 'custom message', @topic.errors.on(:title)
+ assert_equal ['custom message'], @topic.errors[:title]
end
def test_validates_length_of_is_finds_global_default_translation
@@ -474,7 +474,7 @@ def test_validates_length_of_is_finds_global_default_translation
Topic.validates_length_of :title, :is => 5
@topic.valid?
- assert_equal 'global message', @topic.errors.on(:title)
+ assert_equal ['global message'], @topic.errors[:title]
end
def test_validates_length_of_is_finds_custom_model_key_translation
@@ -483,7 +483,7 @@ def test_validates_length_of_is_finds_custom_model_key_translation
Topic.validates_length_of :title, :is => 5
@topic.valid?
- assert_equal 'custom message', @topic.errors.on(:title)
+ assert_equal ['custom message'], @topic.errors[:title]
end
def test_validates_length_of_is_finds_global_default_translation
@@ -491,7 +491,7 @@ def test_validates_length_of_is_finds_global_default_translation
Topic.validates_length_of :title, :is => 5
@topic.valid?
- assert_equal 'global message', @topic.errors.on(:title)
+ assert_equal ['global message'], @topic.errors[:title]
end
@@ -503,7 +503,7 @@ def test_validates_format_of_finds_custom_model_key_translation
Topic.validates_format_of :title, :with => /^[1-9][0-9]*$/
@topic.valid?
- assert_equal 'custom message', @topic.errors.on(:title)
+ assert_equal ['custom message'], @topic.errors[:title]
end
def test_validates_format_of_finds_global_default_translation
@@ -511,7 +511,7 @@ def test_validates_format_of_finds_global_default_translation
Topic.validates_format_of :title, :with => /^[1-9][0-9]*$/
@topic.valid?
- assert_equal 'global message', @topic.errors.on(:title)
+ assert_equal ['global message'], @topic.errors[:title]
end
# validates_inclusion_of w/o mocha
@@ -522,7 +522,7 @@ def test_validates_inclusion_of_finds_custom_model_key_translation
Topic.validates_inclusion_of :title, :in => %w(a b c)
@topic.valid?
- assert_equal 'custom message', @topic.errors.on(:title)
+ assert_equal ['custom message'], @topic.errors[:title]
end
def test_validates_inclusion_of_finds_global_default_translation
@@ -530,7 +530,7 @@ def test_validates_inclusion_of_finds_global_default_translation
Topic.validates_inclusion_of :title, :in => %w(a b c)
@topic.valid?
- assert_equal 'global message', @topic.errors.on(:title)
+ assert_equal ['global message'], @topic.errors[:title]
end
# validates_exclusion_of w/o mocha
@@ -542,7 +542,7 @@ def test_validates_exclusion_of_finds_custom_model_key_translation
Topic.validates_exclusion_of :title, :in => %w(a b c)
@topic.title = 'a'
@topic.valid?
- assert_equal 'custom message', @topic.errors.on(:title)
+ assert_equal ['custom message'], @topic.errors[:title]
end
def test_validates_exclusion_of_finds_global_default_translation
@@ -551,7 +551,7 @@ def test_validates_exclusion_of_finds_global_default_translation
Topic.validates_exclusion_of :title, :in => %w(a b c)
@topic.title = 'a'
@topic.valid?
- assert_equal 'global message', @topic.errors.on(:title)
+ assert_equal ['global message'], @topic.errors[:title]
end
# validates_numericality_of without :only_integer w/o mocha
@@ -563,7 +563,7 @@ def test_validates_numericality_of_finds_custom_model_key_translation
Topic.validates_numericality_of :title
@topic.title = 'a'
@topic.valid?
- assert_equal 'custom message', @topic.errors.on(:title)
+ assert_equal ['custom message'], @topic.errors[:title]
end
def test_validates_numericality_of_finds_global_default_translation
@@ -572,7 +572,7 @@ def test_validates_numericality_of_finds_global_default_translation
Topic.validates_numericality_of :title, :only_integer => true
@topic.title = 'a'
@topic.valid?
- assert_equal 'global message', @topic.errors.on(:title)
+ assert_equal ['global message'], @topic.errors[:title]
end
# validates_numericality_of with :only_integer w/o mocha
@@ -584,7 +584,7 @@ def test_validates_numericality_of_only_integer_finds_custom_model_key_translati
Topic.validates_numericality_of :title, :only_integer => true
@topic.title = 'a'
@topic.valid?
- assert_equal 'custom message', @topic.errors.on(:title)
+ assert_equal ['custom message'], @topic.errors[:title]
end
def test_validates_numericality_of_only_integer_finds_global_default_translation
@@ -593,7 +593,7 @@ def test_validates_numericality_of_only_integer_finds_global_default_translation
Topic.validates_numericality_of :title, :only_integer => true
@topic.title = 'a'
@topic.valid?
- assert_equal 'global message', @topic.errors.on(:title)
+ assert_equal ['global message'], @topic.errors[:title]
end
# validates_numericality_of :odd w/o mocha
@@ -605,7 +605,7 @@ def test_validates_numericality_of_odd_finds_custom_model_key_translation
Topic.validates_numericality_of :title, :only_integer => true, :odd => true
@topic.title = 0
@topic.valid?
- assert_equal 'custom message', @topic.errors.on(:title)
+ assert_equal ['custom message'], @topic.errors[:title]
end
def test_validates_numericality_of_odd_finds_global_default_translation
@@ -614,7 +614,7 @@ def test_validates_numericality_of_odd_finds_global_default_translation
Topic.validates_numericality_of :title, :only_integer => true, :odd => true
@topic.title = 0
@topic.valid?
- assert_equal 'global message', @topic.errors.on(:title)
+ assert_equal ['global message'], @topic.errors[:title]
end
# validates_numericality_of :less_than w/o mocha
@@ -626,7 +626,7 @@ def test_validates_numericality_of_less_than_finds_custom_model_key_translation
Topic.validates_numericality_of :title, :only_integer => true, :less_than => 0
@topic.title = 1
@topic.valid?
- assert_equal 'custom message', @topic.errors.on(:title)
+ assert_equal ['custom message'], @topic.errors[:title]
end
def test_validates_numericality_of_less_than_finds_global_default_translation
@@ -635,7 +635,7 @@ def test_validates_numericality_of_less_than_finds_global_default_translation
Topic.validates_numericality_of :title, :only_integer => true, :less_than => 0
@topic.title = 1
@topic.valid?
- assert_equal 'global message', @topic.errors.on(:title)
+ assert_equal ['global message'], @topic.errors[:title]
end
def test_validations_with_message_symbol_must_translate
@@ -643,7 +643,7 @@ def test_validations_with_message_symbol_must_translate
Topic.validates_presence_of :title, :message => :custom_error
@topic.title = nil
@topic.valid?
- assert_equal "I am a custom error", @topic.errors.on(:title)
+ assert_equal ["I am a custom error"], @topic.errors[:title]
end
def test_validates_with_message_symbol_must_translate_per_attribute
@@ -651,7 +651,7 @@ def test_validates_with_message_symbol_must_translate_per_attribute
Topic.validates_presence_of :title, :message => :custom_error
@topic.title = nil
@topic.valid?
- assert_equal "I am a custom error", @topic.errors.on(:title)
+ assert_equal ["I am a custom error"], @topic.errors[:title]
end
def test_validates_with_message_symbol_must_translate_per_model
@@ -659,14 +659,14 @@ def test_validates_with_message_symbol_must_translate_per_model
Topic.validates_presence_of :title, :message => :custom_error
@topic.title = nil
@topic.valid?
- assert_equal "I am a custom error", @topic.errors.on(:title)
+ assert_equal ["I am a custom error"], @topic.errors[:title]
end
def test_validates_with_message_string
Topic.validates_presence_of :title, :message => "I am a custom error"
@topic.title = nil
@topic.valid?
- assert_equal "I am a custom error", @topic.errors.on(:title)
+ assert_equal ["I am a custom error"], @topic.errors[:title]
end
end
View
8 activemodel/test/cases/validations/inclusion_validation_test.rb
@@ -21,8 +21,8 @@ def test_validates_inclusion_of
assert t.valid?
t.title = "uhoh"
assert !t.valid?
- assert t.errors.on(:title)
- assert_equal "is not included in the list", t.errors.on(:title)
+ assert t.errors[:title].any?
+ assert_equal ["is not included in the list"], t.errors[:title]
assert_raise(ArgumentError) { Topic.validates_inclusion_of( :title, :in => nil ) }
assert_raise(ArgumentError) { Topic.validates_inclusion_of( :title, :in => 0) }
@@ -47,8 +47,8 @@ def test_validates_inclusion_of_with_formatted_message
t = Topic.create("title" => "uhoh", "content" => "abc")
assert !t.valid?
- assert t.errors.on(:title)
- assert_equal "option uhoh is not in the list", t.errors.on(:title)
+ assert t.errors[:title].any?
+ assert_equal ["option uhoh is not in the list"], t.errors[:title]
end
def test_validates_inclusion_of_with_custom_error_using_quotes
View
52 activemodel/test/cases/validations/length_validation_test.rb
@@ -36,17 +36,17 @@ def test_validates_length_of_using_minimum
t.title = "not"
assert !t.valid?
- assert t.errors.on(:title)
- assert_equal "is too short (minimum is 5 characters)", t.errors.on(:title)
+ assert t.errors[:title].any?
+ assert_equal ["is too short (minimum is 5 characters)"], t.errors[:title]
t.title = ""
assert !t.valid?
- assert t.errors.on(:title)
- assert_equal "is too short (minimum is 5 characters)", t.errors.on(:title)
+ assert t.errors[:title].any?
+ assert_equal ["is too short (minimum is 5 characters)"], t.errors[:title]
t.title = nil
assert !t.valid?
- assert t.errors.on(:title)
+ assert t.errors[:title].any?
assert_equal ["is too short (minimum is 5 characters)"], t.errors["title"]
end
@@ -68,8 +68,8 @@ def test_validates_length_of_using_maximum
t.title = "notvalid"
assert !t.valid?
- assert t.errors.on(:title)
- assert_equal "is too long (maximum is 5 characters)", t.errors.on(:title)
+ assert t.errors[:title].any?
+ assert_equal ["is too long (maximum is 5 characters)"], t.errors[:title]
t.title = ""
assert t.valid?
@@ -93,14 +93,14 @@ def test_validates_length_of_using_within
t = Topic.new("title" => "a!", "content" => "I'm ooooooooh so very long")
assert !t.valid?
- assert_equal "is too short (minimum is 3 characters)", t.errors.on(:title)
- assert_equal "is too long (maximum is 5 characters)", t.errors.on(:content)
+ assert_equal ["is too short (minimum is 3 characters)"], t.errors[:title]
+ assert_equal ["is too long (maximum is 5 characters)"], t.errors[:content]
t.title = nil
t.content = nil
assert !t.valid?
- assert_equal "is too short (minimum is 3 characters)", t.errors.on(:title)
- assert_equal "is too short (minimum is 3 characters)", t.errors.on(:content)
+ assert_equal ["is too short (minimum is 3 characters)"], t.errors[:title]
+ assert_equal ["is too short (minimum is 3 characters)"], t.errors[:content]
t.title = "abe"
t.content = "mad"
@@ -122,8 +122,8 @@ def test_optionally_validates_length_of_using_within_on_create
t = Topic.create("title" => "thisisnotvalid", "content" => "whatever")
assert !t.save
- assert t.errors.on(:title)
- assert_equal "my string is too long: 10", t.errors.on(:title)
+ assert t.errors[:title].any?
+ assert_equal ["my string is too long: 10"], t.errors[:title]
t.title = "butthisis"
assert t.save
@@ -143,17 +143,17 @@ def test_optionally_validates_length_of_using_within_on_update
t = Topic.create("title" => "vali", "content" => "whatever")
assert !t.save
- assert t.errors.on(:title)
+ assert t.errors[:title].any?
t.title = "not"
assert !t.save
- assert t.errors.on(:title)
- assert_equal "my string is too short: 5", t.errors.on(:title)
+ assert t.errors[:title].any?
+ assert_equal ["my string is too short: 5"], t.errors[:title]
t.title = "valid"
t.content = "andthisistoolong"
assert !t.save
- assert t.errors.on(:content)
+ assert t.errors[:content].any?
t.content = "iamfine"
assert t.save
@@ -167,8 +167,8 @@ def test_validates_length_of_using_is
t.title = "notvalid"
assert !t.valid?
- assert t.errors.on(:title)
- assert_equal "is the wrong length (should be 5 characters)", t.errors.on(:title)
+ assert t.errors[:title].any?
+ assert_equal ["is the wrong length (should be 5 characters)"], t.errors[:title]
t.title = ""
assert !t.valid?
@@ -208,7 +208,7 @@ def test_validates_length_with_globally_modified_error_message
t = Topic.create(:title => 'too short')
assert !t.valid?
- assert_equal 'tu est trops petit hombre 10', t.errors.on(:title)
+ assert_equal ['tu est trops petit hombre 10'], t.errors[:title]
end
def test_validates_length_of_nasty_params
@@ -226,23 +226,23 @@ def test_validates_length_of_custom_errors_for_minimum_with_message
Topic.validates_length_of( :title, :minimum=>5, :message=>"boo {{count}}" )
t = Topic.create("title" => "uhoh", "content" => "whatever")
assert !t.valid?
- assert t.errors.on(:title)
- assert_equal "boo 5", t.errors.on(:title)
+ assert t.errors[:title].any?
+ assert_equal ["boo 5"], t.errors[:title]
end
def test_validates_length_of_custom_errors_for_minimum_with_too_short
Topic.validates_length_of( :title, :minimum=>5, :too_short=>"hoo {{count}}" )
t = Topic.create("title" => "uhoh", "content" => "whatever")
assert !t.valid?
- assert t.errors.on(:title)
- assert_equal "hoo 5", t.errors.on(:title)
+ assert t.errors[:title].any?
+ assert_equal ["hoo 5"], t.errors[:title]
end
def test_validates_length_of_custom_errors_for_maximum_with_message
Topic.validates_length_of( :title, :maximum=>5, :message=>"boo {{count}}" )
t = Topic.create("title" => "uhohuhoh", "content" => "whatever")
assert !t.valid?
- assert t.errors.on(:title)
+ assert t.errors[:title].any?
assert_equal ["boo 5"], t.errors[:title]
end
@@ -374,7 +374,7 @@ def test_optionally_validates_length_of_using_within_on_update_utf8
t.title = "1二三4"
assert !t.save
assert t.errors[:title].any?
- assert_equal "短すぎます: 5", t.errors.on(:title)
+ assert_equal ["短すぎます: 5"], t.errors[:title]
t.title = "一二三四五六七八九十A"
assert !t.save
View
4 activemodel/test/cases/validations/numericality_validation_test.rb
@@ -110,13 +110,13 @@ def test_validates_numericality_with_numeric_message
topic = Topic.new("title" => "numeric test", "approved" => 10)
assert !topic.valid?
- assert_equal "smaller than 4", topic.errors.on(:approved)
+ assert_equal ["smaller than 4"], topic.errors[:approved]
Topic.validates_numericality_of :approved, :greater_than => 4, :message => "greater than {{count}}"
topic = Topic.new("title" => "numeric test", "approved" => 1)
assert !topic.valid?
- assert_equal "greater than 4", topic.errors.on(:approved)
+ assert_equal ["greater than 4"], topic.errors[:approved]
end
private
View
26 activemodel/test/cases/validations_test.rb
@@ -80,7 +80,7 @@ def test_errors_on_base
errors = []
r.errors.each_full { |error| errors << error }
- assert_equal "Reply is not dignifying", r.errors.on_base
+ assert_equal ["Reply is not dignifying"], r.errors[:base]
assert errors.include?("Title Empty")
assert errors.include?("Reply is not dignifying")
@@ -141,4 +141,28 @@ def test_invalid_should_be_the_opposite_of_valid
t.title = 'Things are going to change'
assert !t.invalid?
end
+
+ def test_deprecated_error_messages_on
+ Topic.validates_presence_of :title
+
+ t = Topic.new
+ assert t.invalid?
+
+ [:title, "title"].each do |attribute|
+ assert_deprecated { assert_equal "can't be blank", t.errors.on(attribute) }
+ end
+
+ Topic.validates_each(:title) do |record, attribute|
+ record.errors[attribute] << "invalid"
+ end
+
+ assert t.invalid?
+
+ [:title, "title"].each do |attribute|
+ assert_deprecated do
+ assert t.errors.on(attribute).include?("invalid")
+ assert t.errors.on(attribute).include?("can't be blank")
+ end
+ end
+ end
end
View
4 activerecord/test/cases/associations/has_one_associations_test.rb
@@ -183,7 +183,7 @@ def test_failing_build_association
account = firm.build_account
assert !account.save
- assert_equal "can't be empty", account.errors.on("credit_limit")
+ assert_equal ["can't be empty"], account.errors["credit_limit"]
end
def test_build_association_twice_without_saving_affects_nothing
@@ -219,7 +219,7 @@ def test_failing_build_association
assert_equal account, firm.account
assert !account.save
assert_equal account, firm.account
- assert_equal "can't be empty", account.errors.on("credit_limit")
+ assert_equal ["can't be empty"], account.errors["credit_limit"]
end
def test_create
View
32 activerecord/test/cases/autosave_association_test.rb
@@ -47,7 +47,7 @@ def test_save_fails_for_invalid_has_one
assert !firm.account.valid?
assert !firm.valid?
assert !firm.save
- assert_equal "is invalid", firm.errors.on("account")
+ assert_equal ["is invalid"], firm.errors["account"]
end
def test_save_succeeds_for_invalid_has_one_with_validate_false
@@ -133,7 +133,7 @@ def test_save_fails_for_invalid_belongs_to
assert !log.developer.valid?
assert !log.valid?
assert !log.save
- assert_equal "is invalid", log.errors.on("developer")
+ assert_equal ["is invalid"], log.errors["developer"]
end
def test_save_succeeds_for_invalid_belongs_to_with_validate_false
@@ -623,16 +623,16 @@ def test_should_automatically_save_bang_the_associated_model
def test_should_automatically_validate_the_associated_model
@pirate.ship.name = ''
- assert !@pirate.valid?
- assert !@pirate.errors.on(:ship_name).blank?
+ assert @pirate.invalid?
+ assert @pirate.errors[:ship_name].any?
end
def test_should_merge_errors_on_the_associated_models_onto_the_parent_even_if_it_is_not_valid
@pirate.ship.name = nil
@pirate.catchphrase = nil
- assert !@pirate.valid?
- assert !@pirate.errors.on(:ship_name).blank?
- assert !@pirate.errors.on(:catchphrase).blank?
+ assert @pirate.invalid?
+ assert @pirate.errors[:ship_name].any?
+ assert @pirate.errors[:catchphrase].any?
end
def test_should_still_allow_to_bypass_validations_on_the_associated_model
@@ -720,9 +720,9 @@ def test_should_automatically_validate_the_associated_model
def test_should_merge_errors_on_the_associated_model_onto_the_parent_even_if_it_is_not_valid
@ship.name = nil
@ship.pirate.catchphrase = nil
- assert !@ship.valid?
- assert !@ship.errors.on(:name).blank?
- assert !@ship.errors.on(:pirate_catchphrase).blank?
+ assert @ship.invalid?
+ assert @ship.errors[:name].any?
+ assert @ship.errors[:pirate_catchphrase].any?
end
def test_should_still_allow_to_bypass_validations_on_the_associated_model
@@ -784,16 +784,16 @@ def test_should_automatically_validate_the_associated_models
@pirate.send(@association_name).each { |child| child.name = '' }
assert !@pirate.valid?
- assert_equal "can't be blank", @pirate.errors.on("#{@association_name}_name")
- assert @pirate.errors.on(@association_name).blank?
+ assert_equal ["can't be blank"], @pirate.errors["#{@association_name}_name"]
+ assert @pirate.errors[@association_name].empty?
end
def test_should_not_use_default_invalid_error_on_associated_models
@pirate.send(@association_name).build(:name => '')
assert !@pirate.valid?
- assert_equal "can't be blank", @pirate.errors.on("#{@association_name}_name")
- assert @pirate.errors.on(@association_name).blank?
+ assert_equal ["can't be blank"], @pirate.errors["#{@association_name}_name"]
+ assert @pirate.errors[@association_name].empty?
end
def test_should_merge_errors_on_the_associated_models_onto_the_parent_even_if_it_is_not_valid
@@ -801,8 +801,8 @@ def test_should_merge_errors_on_the_associated_models_onto_the_parent_even_if_it
@pirate.catchphrase = nil
assert !@pirate.valid?
- assert_equal "can't be blank", @pirate.errors.on("#{@association_name}_name")
- assert !@pirate.errors.on(:catchphrase).blank?
+ assert_equal ["can't be blank"], @pirate.errors["#{@association_name}_name"]
+ assert @pirate.errors[:catchphrase].any?
end
def test_should_allow_to_bypass_validations_on_the_associated_models_on_update
View
6 activerecord/test/cases/validations/association_validation_test.rb
@@ -14,7 +14,7 @@ def test_validates_size_of_association
assert_nothing_raised { Owner.validates_size_of :pets, :minimum => 1 }
o = Owner.new('name' => 'nopets')
assert !o.save
- assert o.errors.on(:pets)
+ assert o.errors[:pets].any?
pet = o.pets.build('name' => 'apet')
assert o.valid?
end
@@ -25,14 +25,14 @@ def test_validates_size_of_association_using_within
assert_nothing_raised { Owner.validates_size_of :pets, :within => 1..2 }
o = Owner.new('name' => 'nopets')
assert !o.save
- assert o.errors.on(:pets)
+ assert o.errors[:pets].any?
pet = o.pets.build('name' => 'apet')
assert o.valid?
2.times { o.pets.build('name' => 'apet') }
assert !o.save
- assert o.errors.on(:pets)
+ assert o.errors[:pets].any?
end
end
View
4 activerecord/test/cases/validations/i18n_validation_test.rb
@@ -76,7 +76,7 @@ def test_validates_associated_finds_custom_model_key_translation
Topic.validates_associated :replies
replied_topic.valid?
- assert_equal 'custom message', replied_topic.errors.on(:replies)
+ assert_equal ['custom message'], replied_topic.errors[:replies]
end
def test_validates_associated_finds_global_default_translation
@@ -84,6 +84,6 @@ def test_validates_associated_finds_global_default_translation
Topic.validates_associated :replies
replied_topic.valid?
- assert_equal 'global message', replied_topic.errors.on(:replies)
+ assert_equal ['global message'], replied_topic.errors[:replies]
end
end
View
4 activerecord/test/cases/validations_test.rb
@@ -28,7 +28,7 @@ def test_error_on_create
r.title = "Wrong Create"
assert !r.valid?
assert r.errors.invalid?("title"), "A reply with a bad title should mark that attribute as invalid"
- assert_equal "is Wrong Create", r.errors.on(:title), "A reply with a bad content should contain an error"
+ assert_equal ["is Wrong Create"], r.errors[:title], "A reply with a bad content should contain an error"
end
def test_error_on_update
@@ -41,7 +41,7 @@ def test_error_on_update
assert !r.save, "Second save should fail"
assert r.errors.invalid?("title"), "A reply with a bad title should mark that attribute as invalid"
- assert_equal "is Wrong Update", r.errors.on(:title), "A reply with a bad content should contain an error"
+ assert_equal ["is Wrong Update"], r.errors[:title], "A reply with a bad content should contain an error"
end
def test_invalid_record_exception
Please sign in to comment.
Something went wrong with that request. Please try again.