aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2018-05-02 04:50:20 +0900
committerGitHub <noreply@github.com>2018-05-02 04:50:20 +0900
commit1848610d1847d21e7f18b440b23c9a6192e0133c (patch)
tree79210ed864390bd9405abe62873aaad21bf317aa /activerecord/test/cases
parente24eeef3d42eac4f6fdd9a63bcde2a054e839af9 (diff)
parent66280b9eb9a3263971377f80f23ef29428c3b974 (diff)
downloadrails-1848610d1847d21e7f18b440b23c9a6192e0133c.tar.gz
rails-1848610d1847d21e7f18b440b23c9a6192e0133c.tar.bz2
rails-1848610d1847d21e7f18b440b23c9a6192e0133c.zip
Merge pull request #32784 from jpawlyn/allow-belongs-to-create-for-new-record
Allow a belonging to object to be created from a new record
Diffstat (limited to 'activerecord/test/cases')
-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")