Skip to content

Commit

Permalink
Fix: Transition shouldn't raise exception if state is persisted as a …
Browse files Browse the repository at this point in the history
…string
  • Loading branch information
clemens committed Oct 11, 2012
1 parent dee8f11 commit 395b554
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/simple_states/event.rb
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions test/states_test.rb
Expand Up @@ -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

Expand Down

0 comments on commit 395b554

Please sign in to comment.