Skip to content

Commit

Permalink
Fix around_transition pausing not being marked as unsupported for rub…
Browse files Browse the repository at this point in the history
…inius
  • Loading branch information
darkhelmet authored and obrie committed Feb 19, 2013
1 parent 00ec068 commit 45550f8
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
@@ -1,5 +1,6 @@
# master

* Fix around_transition pausing not being marked as unsupported for rubinius [Daniel Huckstep]
* Fix all / any / same matchers not being able to be used in :from / :to options in transitions and callbacks
* Fix ActiveModel locale paths not being loaded properly under certain JRuby environments [Brad Heller]
* Remove dependency on the validation_class_methods plugin for Sequel 2.12.0+ [Casey Howard]
Expand Down
8 changes: 7 additions & 1 deletion lib/state_machine/transition.rb
Expand Up @@ -84,6 +84,12 @@ class Transition
# Whether the transition is only existing temporarily for the object
attr_writer :transient

# Determines whether the curreny ruby implementation supports pausing and
# resuming transitions
def self.pause_supported?
RUBY_PLATFORM != 'java' && (!defined?(RUBY_ENGINE) || RUBY_ENGINE != 'rbx')
end

# Creates a new, specific transition
def initialize(object, machine, event, from_name, to_name, read_state = true) #:nodoc:
@object = object
Expand Down Expand Up @@ -355,7 +361,7 @@ def pausable
# around callbacks when the remainder of the callback will be executed at
# a later point in time.
def pause
raise ArgumentError, 'around_transition callbacks cannot be called in multiple execution contexts in java implementations of Ruby. Use before/after_transitions instead.' if RUBY_PLATFORM == 'java'
raise ArgumentError, 'around_transition callbacks cannot be called in multiple execution contexts in java implementations of Ruby. Use before/after_transitions instead.' unless self.class.pause_supported?

unless @resume_block
require 'continuation' unless defined?(callcc)
Expand Down
4 changes: 2 additions & 2 deletions test/unit/transition_collection_test.rb
Expand Up @@ -1152,7 +1152,7 @@ def test_should_run_after_callbacks_on_subsequent_perform
end
end

if RUBY_PLATFORM != 'java'
if StateMachine::Transition.pause_supported?
class TransitionCollectionWithSkippedAfterCallbacksAndAroundCallbacksTest < Test::Unit::TestCase
def setup
@klass = Class.new
Expand Down Expand Up @@ -2137,7 +2137,7 @@ def test_should_marshal_during_after_callbacks
end
end

if RUBY_PLATFORM != 'java'
if StateMachine::Transition.pause_supported?
def test_should_marshal_during_around_callbacks_before_yield
@machine.around_transition {|object, transition, block| Marshal.dump(object); block.call}
assert_nothing_raised do
Expand Down
2 changes: 1 addition & 1 deletion test/unit/transition_test.rb
Expand Up @@ -1221,7 +1221,7 @@ def test_should_not_run_after_callbacks
assert !@run
end

if RUBY_PLATFORM != 'java'
if StateMachine::Transition.pause_supported?
def test_should_run_around_callbacks_before_yield
@machine.around_transition {|block| @run = true; block.call}

Expand Down

0 comments on commit 45550f8

Please sign in to comment.