有没有人找到为 ActiveRecord 多态关联编写 rspec 示例的方法?
我习惯使用 Thoughtbot 的应该匹配,但我认为多态超出了它的范围?
为清楚起见,我的模型将具有与此类似的模式:
class Person < ActiveRecord::Base
attr_accessible :name
has_one :address, as: :location_data_source
accepts_nested_attributes_for :address
end
class Company < ActiveRecord::Base
attr_accessible :name
has_one :address, as: :location_data_source
accepts_nested_attributes_for :address
end
class Address < ActiveRecord::Base
attr_accessible :street, :city
belongs_to :location_data_source, polymorphic: true
end