From c67e985994362290308073ed2793dd8e7f2a76db Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Thu, 10 Apr 2008 13:48:43 +0000 Subject: 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 --- .../test/cases/associations/belongs_to_associations_test.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'activerecord/test/cases') 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 -- cgit v1.2.3