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

Events as constants (same as state) #550

Open
bwillis opened this issue Apr 13, 2018 · 2 comments
Open

Events as constants (same as state) #550

bwillis opened this issue Apr 13, 2018 · 2 comments

Comments

@bwillis
Copy link

bwillis commented Apr 13, 2018

When getting started with aasm we found the state constants really useful, but felt like we were missing them for events. Has this been considered before or does anyone else think it would be useful?

@anilmaurya
Copy link
Member

I am not sure if events constants are really useful for others. Can you share some code snippets where you found that events constants are useful.

@bwillis
Copy link
Author

bwillis commented Apr 25, 2018

Mostly it's been in specs when invoking a state change through an indirect interface:

# Class snippet
class AasmObject
  include AASM
  EVENTS = [
    EVENT_DO_THE_THING,
  ].freeze
end

# Spec snippet
let(:event) { AasmObject::EVENT_DO_THE_THING }
subject(:run_event) { put :update, params: { event: event } }

it do
  expect { run_event }
  .to change { aasm_object.reload.state.to_sym }
  .from(AasmObject::STATE_INITIAL)
  .to(AasmObject::STATE_THING_DONE)
end

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

No branches or pull requests

2 participants