How do I write an Rspec test for an ActiveRecord polymorphic association

552 Views Asked by At

Has anyone found a way to write an rspec example for an ActiveRecord polymorphic association?

I'm used to using Thoughtbot's shoulda matches, but I think polymorphic's are beyond it's scope?

Just for clarity my models would have a similar pattern to this:

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

There are 0 best solutions below