mirror of
https://github.com/aasm/aasm
synced 2023-03-27 23:22:41 -04:00
deprecate usage of AASM.aasm_from_states_for_state (getter method)
This commit is contained in:
parent
9fa60651b4
commit
45250d09e2
3 changed files with 15 additions and 10 deletions
|
@ -36,13 +36,10 @@ module AASM
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# is this better?: aasm.states.name.from_states
|
# TODO remove this method in v4.0.0
|
||||||
def aasm_from_states_for_state(state, options={})
|
def aasm_from_states_for_state(state, options={})
|
||||||
if options[:transition]
|
warn ".aasm_from_states_for_state is deprecated and will be removed in version 4.0.0; please use .aasm.from_states_for_state instead!"
|
||||||
aasm.events[options[:transition]].transitions_to_state(state).flatten.map(&:from).flatten
|
aasm.from_states_for_state(state, options)
|
||||||
else
|
|
||||||
aasm.events.map {|k,v| v.transitions_to_state(state)}.flatten.map(&:from).flatten
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO remove this method in v4.0.0
|
# TODO remove this method in v4.0.0
|
||||||
|
|
|
@ -76,5 +76,13 @@ module AASM
|
||||||
states.map { |state| state.for_select }
|
states.map { |state| state.for_select }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def from_states_for_state(state, options={})
|
||||||
|
if options[:transition]
|
||||||
|
events[options[:transition]].transitions_to_state(state).flatten.map(&:from).flatten
|
||||||
|
else
|
||||||
|
events.map {|k,v| v.transitions_to_state(state)}.flatten.map(&:from).flatten
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -81,15 +81,15 @@ describe 'aasm.states_for_select' do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe :aasm_from_states_for_state do
|
describe 'aasm.from_states_for_state' do
|
||||||
it "should return all from states for a state" do
|
it "should return all from states for a state" do
|
||||||
AuthMachine.should respond_to(:aasm_from_states_for_state)
|
AuthMachine.aasm.should respond_to(:from_states_for_state)
|
||||||
froms = AuthMachine.aasm_from_states_for_state(:active)
|
froms = AuthMachine.aasm.from_states_for_state(:active)
|
||||||
[:pending, :passive, :suspended].each {|from| froms.should include(from)}
|
[:pending, :passive, :suspended].each {|from| froms.should include(from)}
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should return from states for a state for a particular transition only" do
|
it "should return from states for a state for a particular transition only" do
|
||||||
froms = AuthMachine.aasm_from_states_for_state(:active, :transition => :unsuspend)
|
froms = AuthMachine.aasm.from_states_for_state(:active, :transition => :unsuspend)
|
||||||
[:suspended].each {|from| froms.should include(from)}
|
[:suspended].each {|from| froms.should include(from)}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue