Permalink
Browse files

Fix: Transition shouldn't raise exception if state is persisted as a …

…string
  • Loading branch information...
1 parent dee8f11 commit 395b55442e9c3cb1bb9ea53d7ac4ff0732cda6ee @clemens committed Oct 11, 2012
Showing with 10 additions and 1 deletion.
  1. +1 −1 lib/simple_states/event.rb
  2. +9 −0 test/states_test.rb
@@ -48,7 +48,7 @@ def skip?(object, args)
end
def can_transition?(object)
- !options.from || object.state && Array(options.from).include?(object.state)
+ !options.from || object.state && Array(options.from).include?(object.state.to_sym)
end
def run_callbacks(object, type, args)
View
@@ -29,6 +29,15 @@ class StatesTest < Test::Unit::TestCase
assert_raises(SimpleStates::TransitionException) { object.start }
end
+ test "doesn't raise TransitionException if the state is persisted as a string" do
+ klass = create_class { states :created, :started; event :start, :from => :created, :to => :started }
+ klass.class_eval { def state=(state); @state = state.to_s; end }
+
+ object = klass.new
+
+ assert_nothing_raised(SimpleStates::TransitionException) { object.start }
+ end
+
test "state? returns true if the object has the given state" do
object = create_class { event :start, :from => :created, :to => :started }.new

0 comments on commit 395b554

Please sign in to comment.