diff options
author | Alex Kitchens <alexcameron98@gmail.com> | 2017-06-08 16:11:45 -0500 |
---|---|---|
committer | Alex Kitchens <alexcameron98@gmail.com> | 2017-06-08 16:32:10 -0500 |
commit | 9048a70f34b8109be24b2da1009a2f4607ec66bf (patch) | |
tree | 94e47a04f2a311be048adbdce298dc9e0fe74f09 /activerecord/test/cases/associations/has_one_associations_test.rb | |
parent | 73715f29ab4c56ebcd74403903ebd691677ef318 (diff) | |
download | rails-9048a70f34b8109be24b2da1009a2f4607ec66bf.tar.gz rails-9048a70f34b8109be24b2da1009a2f4607ec66bf.tar.bz2 rails-9048a70f34b8109be24b2da1009a2f4607ec66bf.zip |
Raise on create for singular association when parent is unpersisted
A collection association will raise on `#create_association` when the parent is
unpersisted. A singular association should do the same. This addresses
issue #29219.
Diffstat (limited to 'activerecord/test/cases/associations/has_one_associations_test.rb')
-rw-r--r-- | activerecord/test/cases/associations/has_one_associations_test.rb | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/has_one_associations_test.rb b/activerecord/test/cases/associations/has_one_associations_test.rb index 7c11d2e7fc..bf3b8dcd63 100644 --- a/activerecord/test/cases/associations/has_one_associations_test.rb +++ b/activerecord/test/cases/associations/has_one_associations_test.rb @@ -307,6 +307,15 @@ class HasOneAssociationsTest < ActiveRecord::TestCase end end + def test_create_when_parent_is_new_raises + firm = Firm.new + error = assert_raise(ActiveRecord::RecordNotSaved) do + firm.create_account + end + + assert_equal "You cannot call create unless the parent is saved", error.message + end + def test_reload_association odegy = companies(:odegy) |