No, there is no simple shoulda-matchers validation for distinct HABTM associations. distinct
is just one of a large family of query mechanisms that can be utilized as part of a specifying a scope and there is no explicit support for testing it in shoulda.
You're getting the NoMethodError
because distinct
is not an instance method of shoulda's AssociationMatcher
(see https://github.com/thoughtbot/shoulda-matchers/blob/master/lib/shoulda/matchers/active_record/association_matcher.rb for complete list).
As a related aside which you may already be aware of, distinct
does not ensure uniqueness of the relation, it only ensures that you get a distinct result set when you query.