Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

State :exit called when all transitions fail

#7

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.

Reported by Nathaniel Bibler · September 19th, 2008 @ 12:22 AM

State: new
Milestone: none
Assigned to: Scott Barron Scott Barron

Activity

  1. Nathaniel Bibler
    Nathaniel Bibler
    • 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.

    September 19th, 2008 @ 12:26 AM

  2. Nathaniel Bibler
    Nathaniel Bibler

    If it's any easier for you to check out, I've also got this modification on GitHub.

    September 19th, 2008 @ 12:31 AM

  3. rubyist
    rubyist

    Thanks for the patch, Nathaniel, I'll check this out today.

    -Scott

    September 19th, 2008 @ 07:12 AM

  4. Nathaniel Bibler
    Nathaniel Bibler

    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:

    1. OldState.exit
    2. SuccessfulTransition.on_success
    3. NewState.enter

    With the above mentioned patch, the sequence is as follows:

    1. SuccessfulTransition.on_success
    2. OldState.exit
    3. NewState.enter

    I figured I'd mention it while I was thinking about it and it wasn't yet adopted. :-D

    September 19th, 2008 @ 10:04 AM

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.