aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/autosave_association_test.rb
diff options
context:
space:
mode:
authorJan Varwig <jan@varwig.org>2011-11-27 11:47:45 +0100
committerJan Varwig <jan@varwig.org>2011-11-27 22:29:56 +0100
commitcba5a3a367f0f9d3be042c0782716fdfd4930f1c (patch)
treefc17fcfffd367e294e2f57818981094dc577ffe9 /activerecord/test/cases/autosave_association_test.rb
parent3c81fc3b91ddfd4d115a7001640588eb93249261 (diff)
downloadrails-cba5a3a367f0f9d3be042c0782716fdfd4930f1c.tar.gz
rails-cba5a3a367f0f9d3be042c0782716fdfd4930f1c.tar.bz2
rails-cba5a3a367f0f9d3be042c0782716fdfd4930f1c.zip
Test case and fix for rails/rails#3450
Asssigning a parent id to a belongs_to association actually updates the object that is validated when the association has :validates => true
Diffstat (limited to 'activerecord/test/cases/autosave_association_test.rb')
-rw-r--r--activerecord/test/cases/autosave_association_test.rb11
1 files changed, 11 insertions, 0 deletions
diff --git a/activerecord/test/cases/autosave_association_test.rb b/activerecord/test/cases/autosave_association_test.rb
index 4ad2cdfc7e..4c3f2bda57 100644
--- a/activerecord/test/cases/autosave_association_test.rb
+++ b/activerecord/test/cases/autosave_association_test.rb
@@ -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