Merge remote branch 'gpetrica/master'

This commit is contained in:
Travis Tilley 2009-10-14 23:26:24 -04:00
commit 80d7896ece
2 changed files with 27 additions and 4 deletions

View File

@ -17,6 +17,21 @@ module AASM
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)
@ -26,10 +41,6 @@ module AASM
action.each { |a| record.send(a) }
end
end
def for_select
[name.to_s.gsub(/_/, ' ').capitalize, name.to_s]
end
end
end
end

View File

@ -50,6 +50,18 @@ describe AASM::SupportingClasses::State do
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})