Skip to content

Commit

Permalink
Merge remote branch 'gpetrica/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
ttilley committed Oct 15, 2009
2 parents 4eea762 + 404a9d3 commit 80d7896
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
19 changes: 15 additions & 4 deletions lib/aasm/state.rb
Expand Up @@ -17,6 +17,21 @@ def ==(state)

def call_action(action, record)
action = @options[action]
if action.is_a? Array
action.each do |a|
_call(a, record)
end
else
_call(action, record)
end
end

def for_select
[name.to_s.gsub(/_/, ' ').capitalize, name.to_s]
end

private
def _call(action, record)
case action
when Symbol, String
record.send(action)
Expand All @@ -26,10 +41,6 @@ def call_action(action, record)
action.each { |a| record.send(a) }
end
end

def for_select
[name.to_s.gsub(/_/, ' ').capitalize, name.to_s]
end
end
end
end
12 changes: 12 additions & 0 deletions spec/unit/state_spec.rb
Expand Up @@ -50,6 +50,18 @@ def new_state(options={})

state.call_action(:entering, record)
end

it 'should send a message to the record for each action' do
state = new_state(:entering => [:a, :b, "c", lambda {|r| r.foobar }])

record = mock('record')
record.should_receive(:a)
record.should_receive(:b)
record.should_receive(:c)
record.should_receive(:foobar)

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 80d7896

Please sign in to comment.