1
0
Fork 0
mirror of https://github.com/aasm/aasm synced 2023-03-27 23:22:41 -04:00

Fix stack level too deep error due to namespacing

If you have a state machine with a "failed" event and you transition it
and it fails to transition, AASM will call the "failed" method it
defines but will hit your transition instead and blow the stack.

All other methods in AASM are prefixed with AASM to avoid this, so this
patch does the same thing with the private methods `failed` and `fired`.
This commit is contained in:
Michael Xavier 2014-07-25 09:05:31 -07:00
parent df5841f39d
commit 6dd484fb95
2 changed files with 28 additions and 4 deletions

View file

@ -155,16 +155,16 @@ private
event.fire_callbacks(:before, self)
if new_state_name = event.fire(self, *args)
fired(event, old_state, new_state_name, options, &block)
aasm_fired(event, old_state, new_state_name, options, &block)
else
failed(event_name, old_state)
aasm_failed(event_name, old_state)
end
rescue StandardError => e
event.fire_callbacks(:error, self, e) || raise(e)
end
end
def fired(event, old_state, new_state_name, options)
def aasm_fired(event, old_state, new_state_name, options)
persist = options[:persist]
new_state = aasm.state_object_for_name(new_state_name)
@ -200,7 +200,7 @@ private
persist_successful
end
def failed(event_name, old_state)
def aasm_failed(event_name, old_state)
if self.respond_to?(:aasm_event_failed)
self.aasm_event_failed(event_name, old_state.name)
end

View file

@ -0,0 +1,24 @@
require 'spec_helper'
class SimpleStateMachine
include AASM
aasm do
state :init, :initial => true
state :failed
event :failed do
transitions :from => :init, :to => :failed
end
end
end
describe "event naming" do
let(:state_machine) { SimpleStateMachine.new }
it "allows an event of failed without blowing the stack" do
state_machine.failed
expect { state_machine.failed }.to raise_error(AASM::InvalidTransition)
end
end