shoulda-matchers
shoulda-matchers copied to clipboard
feat: Add `have_delegated_type` matcher
On this PR, we're adding the matcher for the delegated_type macro, which is basically a belongs_to polymorphic association where you define the possible classes the polymorphic relation can act as.
Currently, it is hard to check those possible classes as Rails does not expose them in any way, so we need to check if the methods for those classes are defined, which is not ideal.
class Vehicle < ActiveRecord::Base
delegated_type :drivable, types: %w(Car Truck)
end
# Usage
RSpec.describe Vehicle, type: :model do
it { should have_delegated_type(:drivable) }
end