mirror of
https://github.com/aasm/aasm
synced 2023-03-27 23:22:41 -04:00
added support for from state retrieval (for any given state)
This commit is contained in:
parent
de80feaa39
commit
8f974eed8b
4 changed files with 21 additions and 17 deletions
|
@ -1,5 +1,9 @@
|
|||
# CHANGELOG
|
||||
|
||||
## 3.0.11
|
||||
|
||||
* added class method aasm_from_states_for_state to retrieve all from states (regarding transitions) for a given state
|
||||
|
||||
## 3.0.10
|
||||
|
||||
* added support for transitions from all other states (thanks to Stefan 'swrobel' Wrobel)
|
||||
|
|
|
@ -31,6 +31,10 @@ module AASM
|
|||
end
|
||||
end
|
||||
|
||||
def aasm_from_states_for_state(state)
|
||||
aasm.events.map {|k,v| v.transitions_to_state(:active)}.flatten.map(&:from).flatten
|
||||
end
|
||||
|
||||
# deprecated
|
||||
def aasm_initial_state=(state)
|
||||
AASM::StateMachine[self].initial_state = state
|
||||
|
|
|
@ -28,6 +28,10 @@ module AASM
|
|||
@transitions.select { |t| t.from == state }
|
||||
end
|
||||
|
||||
def transitions_to_state(state)
|
||||
@transitions.select { |t| t.to == state }
|
||||
end
|
||||
|
||||
def all_transitions
|
||||
@transitions
|
||||
end
|
||||
|
|
|
@ -1,30 +1,15 @@
|
|||
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
||||
|
||||
describe AASM, '- class level definitions' do
|
||||
it 'should define a class level aasm_initial_state() method on its including class' do
|
||||
it 'should define a class level methods on its including class' do
|
||||
Foo.should respond_to(:aasm_initial_state)
|
||||
end
|
||||
|
||||
it 'should define a class level aasm_state() method on its including class' do
|
||||
Foo.should respond_to(:aasm_state)
|
||||
end
|
||||
|
||||
it 'should define a class level aasm_event() method on its including class' do
|
||||
Foo.should respond_to(:aasm_event)
|
||||
end
|
||||
|
||||
it 'should define a class level aasm_states() method on its including class' do
|
||||
Foo.should respond_to(:aasm_states)
|
||||
end
|
||||
|
||||
it 'should define a class level aasm_states_for_select() method on its including class' do
|
||||
Foo.should respond_to(:aasm_states_for_select)
|
||||
end
|
||||
|
||||
it 'should define a class level aasm_events() method on its including class' do
|
||||
Foo.should respond_to(:aasm_events)
|
||||
Foo.should respond_to(:aasm_from_states_for_state)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "naming" do
|
||||
|
@ -61,6 +46,13 @@ describe AASM, '- aasm_states_for_select' do
|
|||
end
|
||||
end
|
||||
|
||||
describe "aasm_from_states_for_state" do
|
||||
it "should return all from states for a state" do
|
||||
froms = AuthMachine.aasm_from_states_for_state(:active)
|
||||
[:pending, :passive, :suspended].each {|from| froms.should include(:pending)}
|
||||
end
|
||||
end
|
||||
|
||||
describe AASM, '- instance level definitions' do
|
||||
before(:each) do
|
||||
@foo = Foo.new
|
||||
|
|
Loading…
Add table
Reference in a new issue