Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

…string
  • Loading branch information...
commit 395b55442e9c3cb1bb9ea53d7ac4ff0732cda6ee 1 parent dee8f11
@clemens clemens authored
Showing with 10 additions and 1 deletion.
  1. +1 −1  lib/simple_states/event.rb
  2. +9 −0 test/states_test.rb
View
2  lib/simple_states/event.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
9 test/states_test.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.