aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2018-04-22 04:03:36 +0900
committerGitHub <noreply@github.com>2018-04-22 04:03:36 +0900
commitaa941c9ce19924589e508f6a1e4bc2d8361a89ae (patch)
tree0bc4f8accb22b0f8fe9538b1e2089be442106676 /activerecord/test/cases/associations
parent611e1102d3bd46c4765bec7d57ca8d343c419e33 (diff)
parent99910dddf28faac31d6a3d4800460f1bc308bb83 (diff)
downloadrails-aa941c9ce19924589e508f6a1e4bc2d8361a89ae.tar.gz
rails-aa941c9ce19924589e508f6a1e4bc2d8361a89ae.tar.bz2
rails-aa941c9ce19924589e508f6a1e4bc2d8361a89ae.zip
Merge pull request #32514 from samdec/multiple-has-one-through-associations-build-bug
Fix .new with multiple through associations
Diffstat (limited to 'activerecord/test/cases/associations')
-rw-r--r--activerecord/test/cases/associations/has_one_through_associations_test.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/has_one_through_associations_test.rb b/activerecord/test/cases/associations/has_one_through_associations_test.rb
index 9964f084ac..003b82e50e 100644
--- a/activerecord/test/cases/associations/has_one_through_associations_test.rb
+++ b/activerecord/test/cases/associations/has_one_through_associations_test.rb
@@ -22,6 +22,10 @@ require "models/customer"
require "models/carrier"
require "models/shop_account"
require "models/customer_carrier"
+require "models/game"
+require "models/game_board"
+require "models/game_collection"
+require "models/game_owner"
class HasOneThroughAssociationsTest < ActiveRecord::TestCase
fixtures :member_types, :members, :clubs, :memberships, :sponsors, :organizations, :minivans,
@@ -64,6 +68,24 @@ class HasOneThroughAssociationsTest < ActiveRecord::TestCase
assert_equal clubs(:moustache_club), new_member.club
end
+ def test_building_multiple_associations_builds_through_record
+ game_owner = GameOwner.create
+ game_collection = GameCollection.create
+ game_board_with_one_association = GameBoard.new(game_owner: game_owner)
+ assert_nil game_board_with_one_association.game.id
+ game_board_with_two_associations = GameBoard.new(game_owner: game_owner, game_collection: game_collection)
+ assert_nil game_board_with_two_associations.game.id
+ end
+
+ def test_creating_multiple_associations_creates_through_record
+ game_owner = GameOwner.create
+ game_collection = GameCollection.create
+ game_board_with_one_association = GameBoard.create(game_owner: game_owner)
+ assert_not_nil game_board_with_one_association.game.id
+ game_board_with_two_associations = GameBoard.create(game_owner: game_owner, game_collection: game_collection)
+ assert_not_nil game_board_with_two_associations.game.id
+ end
+
def test_creating_association_sets_both_parent_ids_for_new
member = Member.new(name: "Sean Griffin")
club = Club.new(name: "Da Club")