提交 2b2f41fd 编写于 作者: V Victor Costan

Fix crash when loading fixture with belongs_to association defined in abstract base class.

上级 7220ffcf
...@@ -669,7 +669,7 @@ def table_rows ...@@ -669,7 +669,7 @@ def table_rows
row[association.foreign_type] = $1 row[association.foreign_type] = $1
end 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) row[fk_name] = ActiveRecord::FixtureSet.identify(value, fk_type)
end end
when :has_many when :has_many
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
require 'models/matey' require 'models/matey'
require 'models/parrot' require 'models/parrot'
require 'models/pirate' require 'models/pirate'
require 'models/doubloon'
require 'models/post' require 'models/post'
require 'models/randomly_named_c1' require 'models/randomly_named_c1'
require 'models/reply' require 'models/reply'
...@@ -903,3 +904,12 @@ class FixturesWithDefaultScopeTest < ActiveRecord::TestCase ...@@ -903,3 +904,12 @@ class FixturesWithDefaultScopeTest < ActiveRecord::TestCase
assert_equal "special", bulbs(:special).name assert_equal "special", bulbs(:special).name
end end
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
blackbeards_doubloon:
pirate: blackbeard
weight: 2
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 @@ def except(adapter_names_to_exclude) ...@@ -266,6 +266,11 @@ def except(adapter_names_to_exclude)
t.string :alias t.string :alias
end 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| create_table :edges, force: true, id: false do |t|
t.column :source_id, :integer, null: false t.column :source_id, :integer, null: false
t.column :sink_id, :integer, null: false t.column :sink_id, :integer, null: false
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册