Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Can't get my state_machine to Enum erate
class VehicleEnum
include DataMapper::Resource
property :id, Serial
property :name, String
property :state, Enum[ :parked, :idling ]
state_machine :initial => :parked do
event :ignite do
transition :parked => :idling
state :idling do
validates_with_method :name_is_fred
def name_is_fred
return true if name == "fred"
return [false, "Only fred can be idling"]
fred = VehicleEnum.create({:name => 'fred'})
fred.ignite or raise "failed: couldn't ignite fred"
fred.clean? or raise "failed: couldn't save an idle fred"
wilma = VehicleEnum.create({:name => 'wilma'})
!wilma.ignite or raise "failed: could ignite wilma"
!wilma.errors.blank? or raise "failed: wilma has no errors"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.