Skip to content

Commit

Permalink
Changed state change actions to allow halting the chain
Browse files Browse the repository at this point in the history
  • Loading branch information
wildfalcon committed Nov 30, 2009
1 parent 4c70b0f commit 88d4d0c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/aasm/state.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ def ==(state)

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
Expand Down
11 changes: 11 additions & 0 deletions spec/unit/state_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@ def new_state(options={})
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})

Expand Down

0 comments on commit 88d4d0c

Please sign in to comment.