Permalink
Browse files

Merge pull request #6 from j-wilkins/from_array

allow passing an array as a :from option
  • Loading branch information...
2 parents c564e95 + 7f17581 commit ed05a3e2b3941358eb70cdd59674f6c89437ec3e Sven Fuchs committed Apr 22, 2012
Showing with 29 additions and 3 deletions.
  1. +1 −1 lib/simple_states.rb
  2. +28 −2 test/assertions_test.rb
View
@@ -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
@@ -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

0 comments on commit ed05a3e

Please sign in to comment.