mirror of
https://github.com/aasm/aasm
synced 2023-03-27 23:22:41 -04:00
transitions_from_state considers missing from state
This commit is contained in:
parent
ab29f0abd4
commit
40b9848571
2 changed files with 18 additions and 1 deletions
|
@ -26,7 +26,7 @@ module AASM
|
||||||
end
|
end
|
||||||
|
|
||||||
def transitions_from_state(state)
|
def transitions_from_state(state)
|
||||||
@transitions.select { |t| t.from == state }
|
@transitions.select { |t| t.from.nil? or t.from == state }
|
||||||
end
|
end
|
||||||
|
|
||||||
def transitions_to_state?(state)
|
def transitions_to_state?(state)
|
||||||
|
|
|
@ -58,6 +58,23 @@ describe 'transition inspection' do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'transition inspection without from' do
|
||||||
|
let(:event) do
|
||||||
|
AASM::Event.new(:run) do
|
||||||
|
transitions :to => :running
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should support inspecting transitions from other states' do
|
||||||
|
expect(event.transitions_from_state(:sleeping).map(&:to)).to eq([:running])
|
||||||
|
expect(event.transitions_from_state?(:sleeping)).to be_true
|
||||||
|
|
||||||
|
expect(event.transitions_from_state(:cleaning).map(&:to)).to eq([:running])
|
||||||
|
expect(event.transitions_from_state?(:cleaning)).to be_true
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
describe 'firing an event' do
|
describe 'firing an event' do
|
||||||
it 'should return nil if the transitions are empty' do
|
it 'should return nil if the transitions are empty' do
|
||||||
obj = double('object', :aasm => double('aasm', :current_state => 'open'))
|
obj = double('object', :aasm => double('aasm', :current_state => 'open'))
|
||||||
|
|
Loading…
Add table
Reference in a new issue