如何为ActiveRecord多态关联编写Rspec测试

时间:2013-09-09 10:52:44

标签: ruby-on-rails-3 activerecord rspec polymorphic-associations shoulda

是否有人找到了为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

0 个答案:

没有答案