From cfb5479a8ded1b7ab829cf02155e43e54c4bc725 Mon Sep 17 00:00:00 2001 From: Ahmed AbdelHalim <347712+a14m@users.noreply.github.com> Date: Mon, 10 Dec 2018 15:19:23 +0100 Subject: [PATCH] Update InvalidTransition to include state_machine_name For easier debugging and error handling for models with multiple state_machines. This non-breaking change add the state_machine name to the attributes of the InvalidTransition error --- lib/aasm/errors.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/aasm/errors.rb b/lib/aasm/errors.rb index 751fd35..6950699 100644 --- a/lib/aasm/errors.rb +++ b/lib/aasm/errors.rb @@ -3,10 +3,11 @@ module AASM class UnknownStateMachineError < RuntimeError; end class InvalidTransition < RuntimeError - attr_reader :object, :event_name, :originating_state, :failures + attr_reader :object, :event_name, :originating_state, :failures, :state_machine def initialize(object, event_name, state_machine_name, failures = []) @object, @event_name, @originating_state, @failures = object, event_name, object.aasm(state_machine_name).current_state, failures + @state_machine = state_machine_name super("Event '#{event_name}' cannot transition from '#{originating_state}'.#{reasoning}") end