Let's consider a class with definition as shared below:
# a_type :string
class Foo < ActiveRecord::Base
enum a_type: { fir: 'first', sec: 'second' }
validates :a_type, presence: true, inclusion: { in: a_types.keys }
end
Rspec:
describe 'Validations' do
it { is_expected.to validate_presence_of(:a_type) }
it { is_expected.to validate_inclusion_of(:a_type).in_array(Foo.a_types.keys) }
end
Failure/Error: it { is_expected.to validate_inclusion_of(:a_type).in_array(Foo.a_types.keys) }
ArgumentError: 'shoulda-matchers test string' is not a valid a_type
Is this the expected behavior for this? Please help
I did try to explore ValidateInclusionOfMatcher from shoulda-matcher repo but couldn't find anything concrete.
It is not very clear why would validate inclusion fail and how does it check based on subject first and then apply ARBITRARY_OUTSIDE_STRING which results in above error.
My understanding is that it should check above behavior, one with value passed in subject using factorybot and other by replacing a_type to some random value.