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:
commit
76fff96fdb
3 changed files with 19 additions and 3 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue