Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add a test case that demonstrates correct use of custom initial states

  • Loading branch information...
commit 9aba515ef04eb4ae5b5c95f2c35d94b6cbf8d81f 1 parent b0a27b4
@michaelklishin michaelklishin authored
Showing with 33 additions and 0 deletions.
  1. +33 −0 test/custom_initial_state_test.rb
View
33 test/custom_initial_state_test.rb
@@ -0,0 +1,33 @@
+require 'test_helper'
+
+class CustomInitialStateTest < Test::Unit::TestCase
+ class Stateful
+ include SimpleStates
+
+ attr_accessor :state
+
+ states :unconfirmed, :confirmed, :rejected, :deployed, :missing
+
+ self.initial_state = :unconfirmed
+
+ event :confirm, :from => :unconfirmed, :to => :confirmed
+ event :reject, :from => :confirmed, :to => :rejected
+ event :reject, :from => :unconfirmed, :to => :rejected
+ event :reject, :from => :deployed, :to => :rejected
+ event :reject, :from => :missing, :to => :rejected
+
+ event :deploy, :from => :confirmed, :to => :deployed
+ event :scratch, :from => :deployed, :to => :missing
+ event :recover, :from => :missing, :to => :deployed
+ end
+
+ test "assumes :created as default initial state" do
+ assert_equal :unconfirmed, Stateful.initial_state
+
+ obj = Stateful.new
+ assert_equal :unconfirmed, obj.state
+
+ obj.confirm
+ assert_equal :confirmed, obj.state
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.