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

Merge pull request #217 from awsmsrc/feature/reference_object_in_invalid_transition

reference state machine object and event in invalid transition error so ...
This commit is contained in:
Thorsten Böttger 2015-03-07 22:55:19 +13:00
commit 76fff96fdb
3 changed files with 19 additions and 3 deletions

View file

@ -129,7 +129,7 @@ private
end
if AASM::StateMachine[self.class].config.whiny_transitions
raise AASM::InvalidTransition, "Event '#{event_name}' cannot transition from '#{aasm.current_state}'"
raise AASM::InvalidTransition.new(self, event_name)
else
false
end

View file

@ -1,5 +1,16 @@
module AASM
class InvalidTransition < RuntimeError; end
class InvalidTransition < RuntimeError
attr_reader :object, :event_name
def initialize(object, event_name)
@object, @event_name = object, event_name
end
def message
"Event '#{event_name}' cannot transition from '#{object.aasm.current_state}'"
end
end
class UndefinedState < RuntimeError; end
class NoDirectAssignmentError < RuntimeError; end
end

View file

@ -4,7 +4,12 @@ describe 'transitions' do
it 'should raise an exception when whiny' do
process = ProcessWithNewDsl.new
expect { process.stop! }.to raise_error(AASM::InvalidTransition)
expect { process.stop! }.to raise_error do |err|
expect(err.class).to eql(AASM::InvalidTransition)
expect(err.message).to eql("Event 'stop' cannot transition from 'sleeping'")
expect(err.object).to eql(process)
expect(err.event_name).to eql(:stop)
end
expect(process).to be_sleeping
end