mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #20437 from pwnall/abstract_fixtures
Fix crash when loading fixture with belongs_to association defined in abstract base class
This commit is contained in:
commit
c0c3ef3a29
5 changed files with 31 additions and 1 deletions
|
@ -668,7 +668,7 @@ module ActiveRecord
|
|||
row[association.foreign_type] = $1
|
||||
end
|
||||
|
||||
fk_type = association.active_record.type_for_attribute(fk_name).type
|
||||
fk_type = reflection_class.type_for_attribute(fk_name).type
|
||||
row[fk_name] = ActiveRecord::FixtureSet.identify(value, fk_type)
|
||||
end
|
||||
when :has_many
|
||||
|
|
|
@ -16,6 +16,7 @@ require 'models/joke'
|
|||
require 'models/matey'
|
||||
require 'models/parrot'
|
||||
require 'models/pirate'
|
||||
require 'models/doubloon'
|
||||
require 'models/post'
|
||||
require 'models/randomly_named_c1'
|
||||
require 'models/reply'
|
||||
|
@ -903,3 +904,12 @@ class FixturesWithDefaultScopeTest < ActiveRecord::TestCase
|
|||
assert_equal "special", bulbs(:special).name
|
||||
end
|
||||
end
|
||||
|
||||
class FixturesWithAbstractBelongsTo < ActiveRecord::TestCase
|
||||
fixtures :pirates, :doubloons
|
||||
|
||||
test "creates fixtures with belongs_to associations defined in abstract base classes" do
|
||||
assert_not_nil doubloons(:blackbeards_doubloon)
|
||||
assert_equal pirates(:blackbeard), doubloons(:blackbeards_doubloon).pirate
|
||||
end
|
||||
end
|
||||
|
|
3
activerecord/test/fixtures/doubloons.yml
vendored
Normal file
3
activerecord/test/fixtures/doubloons.yml
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
blackbeards_doubloon:
|
||||
pirate: blackbeard
|
||||
weight: 2
|
12
activerecord/test/models/doubloon.rb
Normal file
12
activerecord/test/models/doubloon.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
class AbstractDoubloon < ActiveRecord::Base
|
||||
# This has functionality that might be shared by multiple classes.
|
||||
|
||||
self.abstract_class = true
|
||||
belongs_to :pirate
|
||||
end
|
||||
|
||||
class Doubloon < AbstractDoubloon
|
||||
# This uses an abstract class that defines attributes and associations.
|
||||
|
||||
self.table_name = 'doubloons'
|
||||
end
|
|
@ -266,6 +266,11 @@ ActiveRecord::Schema.define do
|
|||
t.string :alias
|
||||
end
|
||||
|
||||
create_table :doubloons, force: true do |t|
|
||||
t.integer :pirate_id
|
||||
t.integer :weight
|
||||
end
|
||||
|
||||
create_table :edges, force: true, id: false do |t|
|
||||
t.column :source_id, :integer, null: false
|
||||
t.column :sink_id, :integer, null: false
|
||||
|
|
Loading…
Reference in a new issue