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

Simpler access to state names of AASM #814

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/aasm/instance_base.rb
Expand Up @@ -57,6 +57,10 @@ def states(options={}, *args)
end
end

def state_names
self.states.map(&:name)
end

def events(options={}, *args)
state = options[:state] || current_state
events = @instance.class.aasm(@name).events.select {|e| e.transitions_from_state?(state) }
Expand Down
6 changes: 6 additions & 0 deletions spec/unit/states_on_one_line_example_spec.rb
Expand Up @@ -13,4 +13,10 @@
expect(example.aasm(:one_line).states.map(&:name)).to eq [:initial, :first, :second]
end
end

describe 'states_names' do
it 'should have all 3 states defined' do
expect(example.aasm(:one_line).state_names).to eq [:initial, :first, :second]
end
end
end