Eager error message

This commit is contained in:
Phil Pirozhkov 2016-03-15 22:54:35 +03:00
parent 24b1ad99ec
commit b891895617
2 changed files with 15 additions and 4 deletions

View File

@ -3,18 +3,18 @@ module AASM
class UnknownStateMachineError < RuntimeError; end
class InvalidTransition < RuntimeError
attr_reader :object, :event_name, :state_machine_name, :failures
attr_reader :object, :event_name, :originating_state, :failures
def initialize(object, event_name, state_machine_name, failures = [])
@object, @event_name, @state_machine_name, @failures = object, event_name, state_machine_name, failures
@object, @event_name, @originating_state, @failures = object, event_name, object.aasm(state_machine_name).current_state, failures
end
def message
"Event '#{event_name}' cannot transition from '#{object.aasm(state_machine_name).current_state}'. #{reasoning}"
"Event '#{event_name}' cannot transition from '#{originating_state}'. #{reasoning}"
end
def reasoning
"Failed callback(s): #{@failures}." unless failures.empty?
"Failed callback(s): #{failures}." unless failures.empty?
end
end

View File

@ -0,0 +1,11 @@
require 'spec_helper'
describe AASM::InvalidTransition do
it 'should not be lazy detecting originating state' do
process = ProcessWithNewDsl.new
expect { process.stop! }.to raise_error do |err|
process.start
expect(err.message).to eql("Event 'stop' cannot transition from 'sleeping'. ")
end
end
end