Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Transition shouldn't raise exception if state is persisted as a string #10

Merged
merged 1 commit into from
Oct 11, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/simple_states/event.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def skip?(object, args)
end end


def can_transition?(object) 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 end


def run_callbacks(object, type, args) def run_callbacks(object, type, args)
Expand Down
9 changes: 9 additions & 0 deletions test/states_test.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ class StatesTest < Test::Unit::TestCase
assert_raises(SimpleStates::TransitionException) { object.start } assert_raises(SimpleStates::TransitionException) { object.start }
end 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 test "state? returns true if the object has the given state" do
object = create_class { event :start, :from => :created, :to => :started }.new object = create_class { event :start, :from => :created, :to => :started }.new


Expand Down