mirror of
https://github.com/aasm/aasm
synced 2023-03-27 23:22:41 -04:00
supporting event inspection for to-states transitions (Event#transitions_to_state?)
This commit is contained in:
parent
1b7dfd628b
commit
ccdb2c9790
3 changed files with 39 additions and 7 deletions
16
CHANGELOG.md
16
CHANGELOG.md
|
@ -1,24 +1,28 @@
|
|||
# CHANGELOG
|
||||
|
||||
## 3.0.14
|
||||
|
||||
* supporting event inspection for to-states transitions (`Event#transitions_to_state?`)
|
||||
|
||||
## 3.0.13
|
||||
|
||||
* supporting ActiveRecord transactions when firing an event
|
||||
* supporting *ActiveRecord* transactions when firing an event
|
||||
|
||||
## 3.0.12
|
||||
|
||||
* aasm_from_states_for_state now supports to filter for specific transition
|
||||
* `aasm_from_states_for_state` now supports to filter for specific transition
|
||||
|
||||
## 3.0.11
|
||||
|
||||
* added class method aasm_from_states_for_state to retrieve all from states (regarding transitions) for a given state
|
||||
* 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)
|
||||
* added support for transitions from all other states (thanks to *Stefan 'swrobel' Wrobel*)
|
||||
|
||||
## 3.0.9
|
||||
|
||||
* guard checks (e.g. may_edit?) now support guard parameters as well
|
||||
* guard checks (e.g. `may_edit?`) now support guard parameters as well
|
||||
|
||||
## 3.0.8
|
||||
|
||||
|
@ -58,7 +62,7 @@
|
|||
* whiny transactions: by default, raise an exception if an event transition is not possible
|
||||
* you may disable whiny transactions
|
||||
|
||||
## 2.4.0
|
||||
## 2.4.0
|
||||
|
||||
* supporting new DSL (which is much shorter)
|
||||
|
||||
|
|
|
@ -21,13 +21,17 @@ module AASM
|
|||
end
|
||||
|
||||
def transitions_from_state?(state)
|
||||
@transitions.any? { |t| t.from == state }
|
||||
transitions_from_state(state).any?
|
||||
end
|
||||
|
||||
def transitions_from_state(state)
|
||||
@transitions.select { |t| t.from == state }
|
||||
end
|
||||
|
||||
def transitions_to_state?(state)
|
||||
transitions_to_state(state).any?
|
||||
end
|
||||
|
||||
def transitions_to_state(state)
|
||||
@transitions.select { |t| t.to == state }
|
||||
end
|
||||
|
|
|
@ -25,6 +25,30 @@ describe 'adding an event' do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'transition inspection' do
|
||||
before do
|
||||
@event = AASM::SupportingClasses::Event.new(:run) do
|
||||
transitions :to => :running, :from => :sleeping
|
||||
end
|
||||
end
|
||||
|
||||
it 'should support inspecting transitions from states' do
|
||||
@event.transitions_from_state(:sleeping).map(&:to).should == [:running]
|
||||
@event.transitions_from_state?(:sleeping).should be_true
|
||||
|
||||
@event.transitions_from_state(:cleaning).map(&:to).should == []
|
||||
@event.transitions_from_state?(:cleaning).should be_false
|
||||
end
|
||||
|
||||
it 'should support inspecting transitions to states' do
|
||||
@event.transitions_to_state(:running).map(&:from).should == [:sleeping]
|
||||
@event.transitions_to_state?(:running).should be_true
|
||||
|
||||
@event.transitions_to_state(:cleaning).map(&:to).should == []
|
||||
@event.transitions_to_state?(:cleaning).should be_false
|
||||
end
|
||||
end
|
||||
|
||||
describe 'firing an event' do
|
||||
it 'should return nil if the transitions are empty' do
|
||||
obj = mock('object')
|
||||
|
|
Loading…
Add table
Reference in a new issue