Different nested validations should not be ignore [#3638 status:resolved]
This commit is contained in:
parent
35933822de
commit
363545aa20
|
@ -260,7 +260,8 @@ module ActiveRecord
|
||||||
if reflection.options[:autosave]
|
if reflection.options[:autosave]
|
||||||
association.errors.each do |attribute, message|
|
association.errors.each do |attribute, message|
|
||||||
attribute = "#{reflection.name}.#{attribute}"
|
attribute = "#{reflection.name}.#{attribute}"
|
||||||
errors[attribute] << message if errors[attribute].empty?
|
errors[attribute] << message
|
||||||
|
errors[attribute].uniq!
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
errors.add(reflection.name)
|
errors.add(reflection.name)
|
||||||
|
|
|
@ -794,6 +794,14 @@ class TestAutosaveAssociationOnAHasOneAssociation < ActiveRecord::TestCase
|
||||||
assert @pirate.errors[:catchphrase].any?
|
assert @pirate.errors[:catchphrase].any?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_should_not_ignore_different_error_messages_on_the_same_attribute
|
||||||
|
Ship.validates_format_of :name, :with => /\w/
|
||||||
|
@pirate.ship.name = ""
|
||||||
|
@pirate.catchphrase = nil
|
||||||
|
assert @pirate.invalid?
|
||||||
|
assert_equal ["can't be blank", "is invalid"], @pirate.errors[:"ship.name"]
|
||||||
|
end
|
||||||
|
|
||||||
def test_should_still_allow_to_bypass_validations_on_the_associated_model
|
def test_should_still_allow_to_bypass_validations_on_the_associated_model
|
||||||
@pirate.catchphrase = ''
|
@pirate.catchphrase = ''
|
||||||
@pirate.ship.name = ''
|
@pirate.ship.name = ''
|
||||||
|
|
Loading…
Reference in New Issue