aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/models
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2009-08-04 11:03:57 -0500
committerJoshua Peek <josh@joshpeek.com>2009-08-04 11:03:57 -0500
commitaad5a30bf25d8a3167afd685fc91c99f4f09cc57 (patch)
treef700750ee088e483537fa7ee992a109b834b1ddc /activerecord/test/models
parent55d1d12c32a1b99f3f07d2346b49a63650ba2e9d (diff)
downloadrails-aad5a30bf25d8a3167afd685fc91c99f4f09cc57.tar.gz
rails-aad5a30bf25d8a3167afd685fc91c99f4f09cc57.tar.bz2
rails-aad5a30bf25d8a3167afd685fc91c99f4f09cc57.zip
Add simple support for ActiveModel's StateMachine for ActiveRecord
Diffstat (limited to 'activerecord/test/models')
-rw-r--r--activerecord/test/models/traffic_light.rb27
1 files changed, 27 insertions, 0 deletions
diff --git a/activerecord/test/models/traffic_light.rb b/activerecord/test/models/traffic_light.rb
new file mode 100644
index 0000000000..f8cfddbef9
--- /dev/null
+++ b/activerecord/test/models/traffic_light.rb
@@ -0,0 +1,27 @@
+class TrafficLight < ActiveRecord::Base
+ include ActiveRecord::StateMachine
+
+ state_machine do
+ state :off
+
+ state :red
+ state :green
+ state :yellow
+
+ event :red_on do
+ transitions :to => :red, :from => [:yellow]
+ end
+
+ event :green_on do
+ transitions :to => :green, :from => [:red]
+ end
+
+ event :yellow_on do
+ transitions :to => :yellow, :from => [:green]
+ end
+
+ event :reset do
+ transitions :to => :red, :from => [:off]
+ end
+ end
+end