Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #3768 from janv/master

Test and fix for Issue 3450
  • Loading branch information...
commit ba0b3eee144000b48ec609b75c18d1cdf07a10f3 2 parents a0c61c8 + cba5a3a
@tenderlove tenderlove authored
View
2  activerecord/lib/active_record/autosave_association.rb
@@ -264,7 +264,7 @@ def nested_records_changed_for_autosave?
# 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
11 activerecord/test/cases/autosave_association_test.rb
@@ -347,6 +347,17 @@ def test_build_and_then_save_parent_should_not_reload_target
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
Please sign in to comment.
Something went wrong with that request. Please try again.