State :exit called when all transitions fail
Reported by Nathaniel Bibler | September 19th, 2008 @ 12:22 AM
When defining an aasm_state
with an
:exit
option, the defined exit method is currently
executed even if all transitions fail:
class Foo
include AASM
aasm_initial_state :open
aasm_state :open, :exit => :exit
aasm_state :closed
aasm_event :null do
transitions :to => :closed, :from => [:open], :guard => :always_false
end
def always_false
false
end
def exit
end
end
foo = Foo.new
foo.null # => executes foo.exit, even though the guard fails.
This is highly unexpected behavior. The exit method should only be executed during a successful event transition.
Comments and changes to this ticket
-
Nathaniel Bibler September 19th, 2008 @ 12:26 AM
- Tag changed from bug to bug, patch
I've attached a patch which adds a spec to exercise this expectation, as well as a simple fix to pass it.
-
Nathaniel Bibler September 19th, 2008 @ 12:31 AM
If it's any easier for you to check out, I've also got this modification on GitHub.
-
rubyist September 19th, 2008 @ 07:12 AM
Thanks for the patch, Nathaniel, I'll check this out today.
-Scott
-
Nathaniel Bibler September 19th, 2008 @ 10:04 AM
Technically, this patch may change the callback execution sequence in a way which is unexpected. While the specs do not test the order in which callbacks are executed, I imagine this may cause problems down the road.
The previous execution sequence:
- OldState.exit
- SuccessfulTransition.on_success
- NewState.enter
With the above mentioned patch, the sequence is as follows:
- SuccessfulTransition.on_success
- OldState.exit
- NewState.enter
I figured I'd mention it while I was thinking about it and it wasn't yet adopted. :-D
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป
Library for adding state machines to Ruby classes. Includes persistence layers for things like ActiveRecord. Formerly known as acts_as_state_machine.