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

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

View file

@ -51,6 +51,18 @@ describe AASM::SupportingClasses::State do
state.call_action(:entering, record) state.call_action(:entering, record)
end 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 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}) state = new_state(:entering => Proc.new {|r| r.foobar})