diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2008-04-10 13:48:43 +0000 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2008-04-10 13:48:43 +0000 |
commit | c67e985994362290308073ed2793dd8e7f2a76db (patch) | |
tree | d229b7ce6d8615ad0e392d93b9823bc9d44cac37 /activerecord | |
parent | 95fdc82fb2a46b7f7746a82de1e2db350371106d (diff) | |
download | rails-c67e985994362290308073ed2793dd8e7f2a76db.tar.gz rails-c67e985994362290308073ed2793dd8e7f2a76db.tar.bz2 rails-c67e985994362290308073ed2793dd8e7f2a76db.zip |
Ensure that save on child object fails for invalid belongs_to association. Closes #11555. [rubyruy]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9247 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/CHANGELOG | 2 | ||||
-rwxr-xr-x | activerecord/lib/active_record/associations.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/associations/belongs_to_associations_test.rb | 12 |
3 files changed, 16 insertions, 0 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index dfe6f988c2..76d76cb0dd 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Ensure that save on child object fails for invalid belongs_to association. Closes #11555. [rubyruy] + * Add support for interleaving migrations by storing which migrations have run in the new schema_migrations table. Closes #11493 [jordi] * ActiveRecord::Base#sum defaults to 0 if no rows are returned. Closes #11550 [kamal] diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index 7d27b0607a..3ea933875d 100755 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -922,6 +922,8 @@ module ActiveRecord ) end + add_single_associated_save_callbacks(reflection.name) + configure_dependency_for_belongs_to(reflection) end diff --git a/activerecord/test/cases/associations/belongs_to_associations_test.rb b/activerecord/test/cases/associations/belongs_to_associations_test.rb index b8ec9117af..75f236aca0 100644 --- a/activerecord/test/cases/associations/belongs_to_associations_test.rb +++ b/activerecord/test/cases/associations/belongs_to_associations_test.rb @@ -377,4 +377,16 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase assert companies(:first_client).readonly_firm.readonly? end + def test_save_fails_for_invalid_belongs_to + log = AuditLog.new + assert log.valid? + + log.build_developer # Build invalid association + assert !log.developer.valid? + assert !log.valid? + assert_equal "is invalid", log.errors.on("developer") + + assert !log.save + end + end |