Merge pull request #157 from MichaelXavier/stack-level-too-deep-failed

Fix stack level too deep error due to namespacing
This commit is contained in:
Thorsten Böttger 2014-08-16 12:47:27 +02:00
commit d55dcef93c
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