mirror of
https://github.com/aasm/aasm
synced 2023-03-27 23:22:41 -04:00
Adding support to have arrays of procs, strings and symbols
This commit is contained in:
parent
e593ec20d7
commit
f2c9c28ae7
2 changed files with 22 additions and 7 deletions
15
lib/event.rb
15
lib/event.rb
|
@ -31,15 +31,16 @@ module AASM
|
|||
def transitions_from_state?(state)
|
||||
@transitions.any? { |t| t.from == state }
|
||||
end
|
||||
|
||||
def execute_success_callback(obj)
|
||||
case success
|
||||
|
||||
def execute_success_callback(obj, success = nil)
|
||||
callback = success || @success
|
||||
case(callback)
|
||||
when String, Symbol
|
||||
obj.send(success)
|
||||
when Array
|
||||
success.each { |meth| obj.send(meth) }
|
||||
obj.send(callback)
|
||||
when Proc
|
||||
success.call(obj)
|
||||
callback.call(obj)
|
||||
when Array
|
||||
callback.each{|meth|self.execute_success_callback(obj, meth)}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -98,6 +98,20 @@ describe AASM::SupportingClasses::Event, 'when executing the success callback' d
|
|||
model.with_array!
|
||||
end
|
||||
|
||||
it "should call each success callback if passed an array of strings and/or symbols and/or procs" do
|
||||
ThisNameBetterNotBeInUse.instance_eval {
|
||||
aasm_event :with_array_including_procs, :success => [:success_callback1, 'success_callback2', lambda { |obj| obj.proc_success_callback }] do
|
||||
transitions :to => :array, :from => [:initial]
|
||||
end
|
||||
}
|
||||
|
||||
model = ThisNameBetterNotBeInUse.new
|
||||
model.should_receive(:success_callback1)
|
||||
model.should_receive(:success_callback2)
|
||||
model.should_receive(:proc_success_callback)
|
||||
model.with_array_including_procs!
|
||||
end
|
||||
|
||||
it "should call the success callback if it's a proc" do
|
||||
ThisNameBetterNotBeInUse.instance_eval {
|
||||
aasm_event :with_proc, :success => lambda { |obj| obj.proc_success_callback } do
|
||||
|
|
Loading…
Add table
Reference in a new issue