Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

allow passing an array as a :from option #6

Merged
merged 1 commit into from

2 participants

@j-wilkins

If i'm reading the README correctly, I think it says you're supposed to be able to do this, but I was getting
NoMethodError: undefined methodto_sym' for [:started, :warning]:Array`

when I tried to.

The Events class seems like it was ready to handle this as well, so maybe I'm missing something, but if not, this tiny change does away with that NoMethodError

@svenfuchs
Owner

looks good to me, thanks @j-wilkins!

@svenfuchs svenfuchs merged commit ed05a3e into from
@svenfuchs
Owner

This seems to break the build on 1.8.7 though:

http://travis-ci.org/#!/svenfuchs/simple_states/jobs/1146152

@j-wilkins

yikes, sorry. Fixed in #7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 20, 2012
  1. @j-wilkins
This page is out of date. Refresh to see the latest.
Showing with 29 additions and 3 deletions.
  1. +1 −1  lib/simple_states.rb
  2. +28 −2 test/assertions_test.rb
View
2  lib/simple_states.rb
@@ -42,7 +42,7 @@ def add_states(*states)
end
def event(name, options = {})
- add_states(options[:from], options[:to])
+ add_states(*options[:from], options[:to])
self.events += [Event.new(name, options)]
end
end
View
30 test/assertions_test.rb
@@ -16,7 +16,7 @@ class AssertionsTest < Test::Unit::TestCase
end
end
- test "does not raise an exception if an event is received when the object is in one of the expected states (multiple :from states)" do
+ test "does not raise an exception if an event is received when the object is in one of the expected states (multiple :from states using :all)" do
klass = create_class do
event :error, :from => :started, :to => :errored
event :all, :from => :warning
@@ -30,6 +30,19 @@ class AssertionsTest < Test::Unit::TestCase
end
end
+ test "does not raise an exception if an event is received when the object is in one of the expected states (multiple :from states using from: [])" do
+ klass = create_class do
+ event :error, :from => [:started, :warning], :to => :errored
+ end
+
+ object = klass.new
+ object.state = :warning
+
+ assert_nothing_raised(SimpleStates::TransitionException) do
+ object.error
+ end
+ end
+
test "raises an exception if an event is received when the object is not in the expected state (single :from state)" do
klass = create_class do
event :error, :from => :started, :to => :errored
@@ -43,7 +56,7 @@ class AssertionsTest < Test::Unit::TestCase
end
end
- test "raises an exception if an event is received when the object is not in any of the expected states (multiple :from states)" do
+ test "raises an exception if an event is received when the object is not in any of the expected states (multiple :from states using :all)" do
klass = create_class do
event :error, :from => :started, :to => :errored
event :all, :from => :warning
@@ -56,5 +69,18 @@ class AssertionsTest < Test::Unit::TestCase
object.error
end
end
+
+ test "raises an exception if an event is received when the object is not in any of the expected states (multiple :from states using from: [])" do
+ klass = create_class do
+ event :error, :from => [:started, :warning], :to => :errored
+ end
+
+ object = klass.new
+ object.state = :initialized
+
+ assert_raises(SimpleStates::TransitionException) do
+ object.error
+ end
+ end
end
Something went wrong with that request. Please try again.