Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aasm.from_state is not always populated #803

Open
steamwings opened this issue Dec 16, 2022 · 0 comments · May be fixed by #826
Open

aasm.from_state is not always populated #803

steamwings opened this issue Dec 16, 2022 · 0 comments · May be fixed by #826

Comments

@steamwings
Copy link

Describe the bug
aasm.from_state is empty for callbacks when the transition does not define from states. Not specifying from states is very useful when the state should be immediately reachable from any other state.

To Reproduce
Steps to reproduce the behavior:

Here's a small (untested) example that should get the idea across. The important thing is to include a transition with no from (transitions from any state) and a callback that will use aasm.from_state in response to that transition.

aasm do
  state :awake, initial: true
  state :tired
  # other states...
 
  after_all_transitions :log_status_change

  event :coffee do
    transitions to: :awake
  end

  event :party do
    transitions to: :tired
  end
end

def log_status_change
  puts "changing from #{aasm.from_state} to #{aasm.to_state} (event: #{aasm.current_event})"
end

Expected behavior
aasm.to_state is populated in all cases, but aasm.from_state is not populated for events like :coffee and :party in the above example.

@steamwings steamwings changed the title aasm.from_state is not always populated aasm.from_state is not always populated Dec 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant