shoulda-matchers icon indicating copy to clipboard operation
shoulda-matchers copied to clipboard

Add support for foreign_type

Open mswiszcz opened this issue 4 years ago • 2 comments

Allows to create tests checking set foreign_type

class Visitor < ActiveRecord::Base
  belongs_to :location, foreign_type: :facility_type, polymorphic: true
end

class Hotel < Location
  has_many :visitors, inverse_of: :location, foreign_type: :facility_type, as: :location
end

class PrisonCell < Location
  has_one :visitor, inverse_of: :location, foreign_type: :facility_type, as: :location
end
expect(Visitor.new).to belong_to(:location).with_foreign_type(:facility_type)
expect(Hotel.new).to have_many(:visitors).with_foreign_type(:facility_type)
expect(PrisonCell.new).to have_one(:visitor).with_foreign_type(:facility_type)

mswiszcz avatar Mar 05 '21 23:03 mswiszcz

Can someone rerun those checks? Seems like a dependency / gems server was temporarily unavailable

mswiszcz avatar Mar 06 '21 00:03 mswiszcz

@mswiszcz Yup! Re-running now.

mcmire avatar Mar 06 '21 00:03 mcmire

I think this would be a nice addition, @mswiszcz do you still plan to address the feedback? If not I can address it and give you credits.

matsales28 avatar Jan 12 '24 14:01 matsales28

hey @matsales28, I totally forgot about that PR after changing project, sorry about that. Please feel free to take that over as I don't have much time at the moment to finish it

mswiszcz avatar Jan 12 '24 17:01 mswiszcz

I'm closing this PR in favor of #1609

matsales28 avatar Feb 02 '24 16:02 matsales28