pluginaweek/state_machine — Issue #145: State machine fails when using symbol values
Author: apneadiving
Created: 2011-12-05 15:51:19+00:00
State: open

Hi,

Background:
Using Mongoid, Rails 3.0.10, state_machine 1.1.0

Working with a legacy app, I'm implementing a state machine to clean up.
The code is stuffed with many `object.status == :foo` so I'd like the statuses to remain symbols.

This in mind, I added the following in the state_machine:

state :in_creation, :value => :in_creation
state :in_progress, :value => :in_progress
state :in_review, :value => :in_review
state :completed, :value => :completed
state :paused, :value => :paused
state :canceled, :value => :canceled

And in console:
pry(#)> @project.can_cancel?
=> true
pry(#)> @project.status
=> :in_creation
pry(#)> @project.cancel
=> false
pry(#)> @project.status
=> "in_creation"

So it's annoying because:
* I can't go from one status to another
* Status is changed from symbol to text after fail

So I commented the lines fixing the values and it works:

pry(#)> @project.status
=> "in_creation"
pry(#)> @project.cancel
=> true
pry(#)> @project.status
=> "canceled"
pry(#)> @project.status
=> "canceled"

So I deduce there is something wrong with the `:value` statement. Is it due to Mongoid?

Thanks in advance.

Benjamin