require File.dirname(__FILE__) + '/joinfix_test_helper' # # hm as # class HasManyAsMigration < ActiveRecord::Migration def self.up create_table :hm_as_parents do |t| t.column :field, :string end create_table :hm_as_children do |t| t.column :polymorphic_parent_id, :integer t.column :polymorphic_parent_type, :string t.column :field, :string end end def self.down drop_table :hm_as_parents drop_table :hm_as_children end end class HmAsParent < ActiveRecord::Base has_many :hm_as_children, :as => :polymorphic_parent end class HmAsChild < ActiveRecord::Base belongs_to :polymorphic_parent, :polymorphic => true end class HasManyAsTest < Test::Unit::TestCase fixtures :hm_as_parents, :hm_as_children def test_has_many_as setup_fixtures( :hm_as_parents => %Q{ parent_entry: field: parent value hm_as_children: child_one: field: one child_two: field: two}, :hm_as_children => "") assert_fixtures( :hm_as_parents => %Q{ parent_entry: id: 1 field: parent value}, :hm_as_children => %Q{ child_one: id: 1 polymorphic_parent_id: 1 polymorphic_parent_type: HmAsParent field: one child_two: id: 2 polymorphic_parent_id: 1 polymorphic_parent_type: HmAsParent field: two}) end end