From 45550f8b9cabe1a87d568445e46a0d65ec2c8d2f Mon Sep 17 00:00:00 2001 From: Daniel Huckstep Date: Mon, 18 Feb 2013 19:00:16 -0500 Subject: [PATCH] Fix around_transition pausing not being marked as unsupported for rubinius --- CHANGELOG.md | 1 + lib/state_machine/transition.rb | 8 +++++++- test/unit/transition_collection_test.rb | 4 ++-- test/unit/transition_test.rb | 2 +- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e906c6a1..a21ee3fd 100644 --- a/CHANGELOG.md +++ b/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] diff --git a/lib/state_machine/transition.rb b/lib/state_machine/transition.rb index 7dd0801e..27b32532 100644 --- a/lib/state_machine/transition.rb +++ b/lib/state_machine/transition.rb @@ -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 @@ -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) diff --git a/test/unit/transition_collection_test.rb b/test/unit/transition_collection_test.rb index 7346fe13..6925074f 100644 --- a/test/unit/transition_collection_test.rb +++ b/test/unit/transition_collection_test.rb @@ -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 @@ -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 diff --git a/test/unit/transition_test.rb b/test/unit/transition_test.rb index 5e05e60d..984f4637 100644 --- a/test/unit/transition_test.rb +++ b/test/unit/transition_test.rb @@ -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}