Merge pull request #3768 from janv/master

Test and fix for Issue 3450
This commit is contained in:
Aaron Patterson
2011-11-28 09:35:43 -08:00
2 changed files with 12 additions and 1 deletions

View File

@@ -264,7 +264,7 @@ module ActiveRecord
# turned on for the association.
def validate_single_association(reflection)
association = association_instance_get(reflection.name)
record = association && association.target
record = association && association.reader
association_valid?(reflection, record) if record
end

View File

@@ -347,6 +347,17 @@ class TestDefaultAutosaveAssociationOnABelongsToAssociation < ActiveRecord::Test
client.save!
assert_no_queries { assert_equal apple, client.firm }
end
def test_validation_does_not_validate_stale_association_target
valid_developer = Developer.create!(:name => "Dude", :salary => 50_000)
invalid_developer = Developer.new()
auditlog = AuditLog.new(:message => "foo")
auditlog.developer = invalid_developer
auditlog.developer_id = valid_developer.id
assert auditlog.valid?
end
end
class TestDefaultAutosaveAssociationOnAHasManyAssociation < ActiveRecord::TestCase