Hello!
I'm implementing a model with a serialized field (ActiveRecord::Store).
class MyClass << ApplicationRecord
store :settings, accessors: [:send_notifiaction,
:another_field,
:and_another], coder: Hash
after_initialize :set_default_settings
validates :send_notification, inclusion: { in: [true, false] }
private
def set_default_settings
self.send_notification ||= true
self.another_field ||= 'test_value'
self.and_another ||= 'another_value'
end
end
Since the send_notification is an accessor I can't really say that it's a boolean field.
Testing it with validates_inclusion_of produces a warning
You are using
validate_inclusion_ofto assert that a boolean column (...)
I can't seem to be able to disable the warning and IMHO it's not an expected behaviour in this case. Can you suggest a workaround for this case? Maybe I should be testing it in another way...
Thanks in advance,
Chris
Hey, sorry for the late reply on this, I was out.
You're right; you shouldn't be getting a warning in this case.
You could try being explicit:
it { should allow_values(true, false).for(:send_notification) }
it { should_not allow_values('anything else').for(:send_notification) }
Thanks a lot! 馃憤
I'm actually going to keep this open since it's a legitimate bug and we should definitely fix this.
Hey folks. In an effort to lighten our load as maintainers and be able to serve you better in the future, the shoulda-matchers team is working on cleaning out the cobwebs in this repo by pruning the backlog. As there are few of us, there are a lot of items that will simply never earn our attention in a reasonable time frame, and rather than giving you an empty promise, we think it makes more sense to focus on more recent issues. That means, unfortunately, that we must close this issue.
Don't take this the wrong way: our aim is not to diminish the effort people have made or dismiss problems that have been raised. If you feel that we should reopen this issue, then please let us know so that we can reprioritize it. Thanks!