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

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 UnknownStateMachineError < RuntimeError; end
class InvalidTransition < RuntimeError 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 = []) 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 end
def message 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 end
def reasoning def reasoning
"Failed callback(s): #{@failures}." unless failures.empty? "Failed callback(s): #{failures}." unless failures.empty?
end end
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