aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorJolyon Pawlyn <jpawlyn@gmail.com>2018-05-01 19:05:52 +0200
committerJolyon Pawlyn <jpawlyn@gmail.com>2018-05-01 19:05:52 +0200
commit66280b9eb9a3263971377f80f23ef29428c3b974 (patch)
treee004d3af9cef3cedcab5685f57518633f69b211f /activerecord/test
parent24aeccb1c873cb8bbf00ff77cb33432cfe598b3d (diff)
downloadrails-66280b9eb9a3263971377f80f23ef29428c3b974.tar.gz
rails-66280b9eb9a3263971377f80f23ef29428c3b974.tar.bz2
rails-66280b9eb9a3263971377f80f23ef29428c3b974.zip
Allow a belonging to object to be created from a new record
If a 'has one' object is created from a new record, an ActiveRecord::RecordNotSaved error is raised but this behavior was also applied to the reverse scenario.
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/associations/belongs_to_associations_test.rb9
1 files changed, 9 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/belongs_to_associations_test.rb b/activerecord/test/cases/associations/belongs_to_associations_test.rb
index a85b56ac4b..5011a9bbde 100644
--- a/activerecord/test/cases/associations/belongs_to_associations_test.rb
+++ b/activerecord/test/cases/associations/belongs_to_associations_test.rb
@@ -272,6 +272,15 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase
assert_equal apple, citibank.firm
end
+ def test_creating_the_belonging_object_from_new_record
+ citibank = Account.new("credit_limit" => 10)
+ apple = citibank.create_firm("name" => "Apple")
+ assert_equal apple, citibank.firm
+ citibank.save
+ citibank.reload
+ assert_equal apple, citibank.firm
+ end
+
def test_creating_the_belonging_object_with_primary_key
client = Client.create(name: "Primary key client")
apple = client.create_firm_with_primary_key("name" => "Apple")