diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2018-04-22 04:16:44 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2018-04-22 04:16:44 +0900 |
commit | f2151c3b3cc969ab95faccaae181ce10c4373cf7 (patch) | |
tree | 2a8680c0fbb5eb69fc2e0abe419da1be7138aaaf /activerecord/test | |
parent | aa941c9ce19924589e508f6a1e4bc2d8361a89ae (diff) | |
download | rails-f2151c3b3cc969ab95faccaae181ce10c4373cf7.tar.gz rails-f2151c3b3cc969ab95faccaae181ce10c4373cf7.tar.bz2 rails-f2151c3b3cc969ab95faccaae181ce10c4373cf7.zip |
Using existing models for building multiple has_one through tests
Follow up of #32514.
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/associations/has_one_through_associations_test.rb | 28 | ||||
-rw-r--r-- | activerecord/test/models/game.rb | 7 | ||||
-rw-r--r-- | activerecord/test/models/game_board.rb | 7 | ||||
-rw-r--r-- | activerecord/test/models/game_collection.rb | 5 | ||||
-rw-r--r-- | activerecord/test/models/game_owner.rb | 5 | ||||
-rw-r--r-- | activerecord/test/models/member_detail.rb | 1 | ||||
-rw-r--r-- | activerecord/test/schema/schema.rb | 16 |
7 files changed, 15 insertions, 54 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 003b82e50e..0309663943 100644 --- a/activerecord/test/cases/associations/has_one_through_associations_test.rb +++ b/activerecord/test/cases/associations/has_one_through_associations_test.rb @@ -22,10 +22,6 @@ 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, @@ -69,21 +65,21 @@ class HasOneThroughAssociationsTest < ActiveRecord::TestCase 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 + member_type = MemberType.create! + member = Member.create! + member_detail_with_one_association = MemberDetail.new(member_type: member_type) + assert_predicate member_detail_with_one_association.member, :new_record? + member_detail_with_two_associations = MemberDetail.new(member_type: member_type, admittable: member) + assert_predicate member_detail_with_two_associations.member, :new_record? 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 + member_type = MemberType.create! + member = Member.create! + member_detail_with_one_association = MemberDetail.create!(member_type: member_type) + assert_not_predicate member_detail_with_one_association.member, :new_record? + member_detail_with_two_associations = MemberDetail.create!(member_type: member_type, admittable: member) + assert_not_predicate member_detail_with_two_associations.member, :new_record? end def test_creating_association_sets_both_parent_ids_for_new diff --git a/activerecord/test/models/game.rb b/activerecord/test/models/game.rb deleted file mode 100644 index 0c33075b12..0000000000 --- a/activerecord/test/models/game.rb +++ /dev/null @@ -1,7 +0,0 @@ -# frozen_string_literal: true - -class Game < ActiveRecord::Base - has_one :game_board - belongs_to :game_owner - belongs_to :game_collection -end diff --git a/activerecord/test/models/game_board.rb b/activerecord/test/models/game_board.rb deleted file mode 100644 index 01d082eddb..0000000000 --- a/activerecord/test/models/game_board.rb +++ /dev/null @@ -1,7 +0,0 @@ -# frozen_string_literal: true - -class GameBoard < ActiveRecord::Base - belongs_to :game - has_one :game_owner, through: :game - has_one :game_collection, through: :game -end diff --git a/activerecord/test/models/game_collection.rb b/activerecord/test/models/game_collection.rb deleted file mode 100644 index 853876b0bd..0000000000 --- a/activerecord/test/models/game_collection.rb +++ /dev/null @@ -1,5 +0,0 @@ -# frozen_string_literal: true - -class GameCollection < ActiveRecord::Base - has_many :games -end diff --git a/activerecord/test/models/game_owner.rb b/activerecord/test/models/game_owner.rb deleted file mode 100644 index 82be3e75b2..0000000000 --- a/activerecord/test/models/game_owner.rb +++ /dev/null @@ -1,5 +0,0 @@ -# frozen_string_literal: true - -class GameOwner < ActiveRecord::Base - has_many :games -end diff --git a/activerecord/test/models/member_detail.rb b/activerecord/test/models/member_detail.rb index 87f7aab9a2..e121a849d0 100644 --- a/activerecord/test/models/member_detail.rb +++ b/activerecord/test/models/member_detail.rb @@ -5,6 +5,7 @@ class MemberDetail < ActiveRecord::Base belongs_to :organization has_one :member_type, through: :member has_one :membership, through: :member + has_one :admittable, through: :member, source_type: "Member" has_many :organization_member_details, through: :organization, source: :member_details end diff --git a/activerecord/test/schema/schema.rb b/activerecord/test/schema/schema.rb index 274879d4af..92ad25ef76 100644 --- a/activerecord/test/schema/schema.rb +++ b/activerecord/test/schema/schema.rb @@ -364,19 +364,6 @@ ActiveRecord::Schema.define do t.integer :follower_id end - create_table :games, force: true do |t| - t.integer :game_owner_id - t.integer :game_collection_id - end - - create_table :game_boards, force: true do |t| - t.integer :game_id - end - - create_table :game_collections, force: true - - create_table :game_owners, force: true - create_table :goofy_string_id, force: true, id: false do |t| t.string :id, null: false t.string :info @@ -499,7 +486,8 @@ ActiveRecord::Schema.define do create_table :members, force: true do |t| t.string :name - t.integer :member_type_id + t.references :member_type, index: false + t.references :admittable, polymorphic: true, index: false end create_table :member_details, force: true do |t| |