Closed nickbayley closed 2 years ago
Hi @nickbayley. It seems like this issue is a bit different than the one you linked to, since there is no condition. My question to you is, if your attribute can't be set to anything, then does it make sense to be an enum?
Hi @mcmire! You are right that this example is pointless and silly :) I was trying to make it as simple as possible to illustrate the problem I am having.
My actual use case is something like this:
Model:
class Task < ApplicationRecord
enum status: { open: 0, closed: 10 }
enum closure_code: { complete: 0, duplicate: 10, non_applicable: 20 }
validates :closure_code, absence: true, unless: :closed?
end
Spec:
RSpec.describe Task, type: :model do
context 'when in a status of open' do
subject(:task) { build_stubbed :task, status: :open }
it { is_expected.to validate_absence_of(:closure_code) }
end
context 'when in a status of closed' do
subject(:task) { build_stubbed :task, status: :closed}
it { is_expected.not_to validate_absence_of(:closure_code) }
end
end
I stumbled across this closed issue #1327 and it seems to me that the question was never properly understood. I hope you don't mind me submitting a new issue on it.
Take the following setup:
Model:
Model Spec:
Spec results:
I understand the error and where it comes from. But my question is:
:make
enum has a database integer of1
configured, whilst my:colour
enum doesn't. This means I can't test:colour
withvalidate_absence_of
or am I missing something really obvious?Thanks.