1
0
Fork 0
mirror of https://github.com/aasm/aasm synced 2023-03-27 23:22:41 -04:00

Changed state change actions to allow halting the chain

This commit is contained in:
Wildfalcon 2009-11-30 16:38:00 +00:00
parent 4c70b0fc54
commit 88d4d0c126
2 changed files with 16 additions and 3 deletions

View file

@ -18,9 +18,11 @@ module AASM
def call_action(action, record)
action = @options[action]
action.is_a?(Array) ?
action.each {|a| _call_action(a, record)} :
_call_action(action, record)
catch :halt_aasm_chain do
action.is_a?(Array) ?
action.each {|a| _call_action(a, record)} :
_call_action(action, record)
end
end
def display_name

View file

@ -63,6 +63,17 @@ describe AASM::SupportingClasses::State do
state.call_action(:entering, record)
end
it "should stop calling actions if one of them raises :halt_aasm_chain" do
state = new_state(:entering => [:a, :b, :c])
record = mock('record')
record.should_receive(:a)
record.should_receive(:b).and_throw(:halt_aasm_chain)
record.should_not_receive(:c)
state.call_action(:entering, record)
end
it 'should call a proc, passing in the record for an action if the action is present' do
state = new_state(:entering => Proc.new {|r| r.foobar})