state-machines / state_machines

Adds support for creating state machines for attributes on any Ruby class
https://github.com/state-machines/state_machines
MIT License
814 stars 91 forks source link

Validation with state as constant aren't working #73

Open disastrous-charly opened 4 years ago

disastrous-charly commented 4 years ago

Hi, Writing this issue because I use your gem and I have one small issue :

My state are constant, like that : STATES = [ STATE_INTERNAL_DELIVERY = 'internal_delivery', STATE_DELIVERABLES_PENDING_REVIEW = 'deliverables_pending_review', STATE_FINISHING_STEP = 'finishing_step' ].freeze

and I'm trying to do a validation with : state STATE_FINISHING_STEP, STATE_DELIVERABLES_PENDING_REVIEW, STATE_INTERNAL_DELIVERY do validate :validate_delivery_possible end

Which will run only on the last state.

But if I do this :

state 'deliverables_pending_review', 'internal_delivery', 'finishing_step' do validate :validate_delivery_possible end

It's running as expected.

Do you know why ?

seuros commented 4 years ago

Try defining the STATE_* constants outside the array.