是否有人找到了为ActiveRecord多态关联编写rspec示例的方法?
我习惯使用Thoughtbot的shoulda匹配,但我认为多态的超出了它的范围?
为了清楚起见,我的模型会有类似的模式:
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