spec/mongoid/samples/traffic_light.rb in edge-state-machine-0.0.3 vs spec/mongoid/samples/traffic_light.rb in edge-state-machine-0.9.0

- old
+ new

@@ -42,5 +42,36 @@ end class MongoConditionalValidatingTrafficLight < MongoTrafficLight validates :name, :presence => true, :length => { :within => 20..40 }, :confirmation => true, :if => :red? end + +class MongoTrafficLightNoScope + include Mongoid::Document + include Mongoid::EdgeStateMachine + field :state + + state_machine do + persisted_to :state + state :off + + state :red + state :green + state :yellow + + event :red_on do + transition :to => :red, :from => [:yellow] + end + + event :green_on do + transition :to => :green, :from => [:red] + end + + event :yellow_on do + transition :to => :yellow, :from => [:green] + end + + event :reset do + transition :to => :red, :from => [:off] + end + end +end