aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2010-01-30 18:38:01 -0600
committerJoshua Peek <josh@joshpeek.com>2010-01-30 18:38:01 -0600
commitdb49c706b62e7ea2ab93f05399dbfddf5087ee0c (patch)
tree7f369bd2b77d620e344f19ba8156c597e2493f58 /activerecord
parent657d85580e914caf368a8a12ff5642e4d979ab7e (diff)
downloadrails-db49c706b62e7ea2ab93f05399dbfddf5087ee0c.tar.gz
rails-db49c706b62e7ea2ab93f05399dbfddf5087ee0c.tar.bz2
rails-db49c706b62e7ea2ab93f05399dbfddf5087ee0c.zip
Axe AM state machine
We're going do it eventually, get it done before 3.0 is final.
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record.rb1
-rw-r--r--activerecord/lib/active_record/state_machine.rb24
-rw-r--r--activerecord/test/cases/state_machine_test.rb42
-rw-r--r--activerecord/test/models/traffic_light.rb27
4 files changed, 0 insertions, 94 deletions
diff --git a/activerecord/lib/active_record.rb b/activerecord/lib/active_record.rb
index cc0accf90e..0c4cc6a554 100644
--- a/activerecord/lib/active_record.rb
+++ b/activerecord/lib/active_record.rb
@@ -73,7 +73,6 @@ module ActiveRecord
autoload :SchemaDumper
autoload :Serialization
autoload :SessionStore
- autoload :StateMachine
autoload :Timestamp
autoload :Transactions
autoload :Validations
diff --git a/activerecord/lib/active_record/state_machine.rb b/activerecord/lib/active_record/state_machine.rb
deleted file mode 100644
index aebd03344a..0000000000
--- a/activerecord/lib/active_record/state_machine.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-module ActiveRecord
- module StateMachine #:nodoc:
- extend ActiveSupport::Concern
- include ActiveModel::StateMachine
-
- included do
- before_validation :set_initial_state
- validates_presence_of :state
- end
-
- protected
- def write_state(state_machine, state)
- update_attributes! :state => state.to_s
- end
-
- def read_state(state_machine)
- self.state.to_sym
- end
-
- def set_initial_state
- self.state ||= self.class.state_machine.initial_state.to_s
- end
- end
-end
diff --git a/activerecord/test/cases/state_machine_test.rb b/activerecord/test/cases/state_machine_test.rb
deleted file mode 100644
index 5d13668bab..0000000000
--- a/activerecord/test/cases/state_machine_test.rb
+++ /dev/null
@@ -1,42 +0,0 @@
-require 'cases/helper'
-require 'models/traffic_light'
-
-class StateMachineTest < ActiveRecord::TestCase
- def setup
- @light = TrafficLight.create!
- end
-
- test "states initial state" do
- assert @light.off?
- assert_equal :off, @light.current_state
- end
-
- test "transition to a valid state" do
- @light.reset
- assert @light.red?
- assert_equal :red, @light.current_state
-
- @light.green_on
- assert @light.green?
- assert_equal :green, @light.current_state
- end
-
- test "transition does not persist state" do
- @light.reset
- assert_equal :red, @light.current_state
- @light.reload
- assert_equal "off", @light.state
- end
-
- test "transition does persists state" do
- @light.reset!
- assert_equal :red, @light.current_state
- @light.reload
- assert_equal "red", @light.state
- end
-
- test "transition to an invalid state" do
- assert_raise(ActiveModel::StateMachine::InvalidTransition) { @light.yellow_on }
- assert_equal :off, @light.current_state
- end
-end
diff --git a/activerecord/test/models/traffic_light.rb b/activerecord/test/models/traffic_light.rb
deleted file mode 100644
index f8cfddbef9..0000000000
--- a/activerecord/test/models/traffic_light.rb
+++ /dev/null
@@ -1,27 +0,0 @@
-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