Skip to content

Commit

Permalink
allow providing any argument for :on_transition callback (fix for issue
Browse files Browse the repository at this point in the history
  • Loading branch information
alto committed May 11, 2014
1 parent d9472c7 commit 7f9be4a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
3 changes: 1 addition & 2 deletions lib/aasm/event.rb
Expand Up @@ -103,8 +103,7 @@ def _fire(obj, test, to_state=nil, *args)
# If to_state is not nil it either contains a potential
# to_state or an arg
unless to_state == nil
if to_state.respond_to?(:to_sym) &&
!transitions.map(&:to).flatten.include?(to_state.to_sym)
if !to_state.respond_to?(:to_sym) || !transitions.map(&:to).flatten.include?(to_state.to_sym)
args.unshift(to_state)
to_state = nil
end
Expand Down
27 changes: 22 additions & 5 deletions spec/unit/callbacks_spec.rb
Expand Up @@ -33,20 +33,37 @@
cb.close!(:arg1, :arg2)
end

it "should call the proper methods given a to state as the first arg" do
it "should call the callbacks given the to-state as argument" do
cb = CallbackWithStateArg.new
cb.should_receive(:before_method).with(:arg1).once.ordered
cb.should_receive(:transition_method).with(:arg1).once.ordered
cb.should_receive(:transition_method).never
cb.should_receive(:transition_method2).with(:arg1).once.ordered
cb.should_receive(:after_method).with(:arg1).once.ordered
cb.close!(:arg1)
cb.close!(:out_to_lunch, :arg1)

cb = CallbackWithStateArg.new
some_object = double('some object')
cb.should_receive(:before_method).with(some_object).once.ordered
cb.should_receive(:transition_method2).with(some_object).once.ordered
cb.should_receive(:after_method).with(some_object).once.ordered
cb.close!(:out_to_lunch, some_object)
end

it "should call the proper methods just with arguments" do
cb = CallbackWithStateArg.new
cb.should_receive(:before_method).with(:arg1).once.ordered
cb.should_receive(:transition_method).with(:arg1).once.ordered
cb.should_receive(:transition_method).never
cb.should_receive(:transition_method2).with(:arg1).once.ordered
cb.should_receive(:after_method).with(:arg1).once.ordered
cb.close!(:out_to_lunch, :arg1)
cb.close!(:arg1)

cb = CallbackWithStateArg.new
some_object = double('some object')
cb.should_receive(:before_method).with(some_object).once.ordered
cb.should_receive(:transition_method).with(some_object).once.ordered
cb.should_receive(:transition_method).never
cb.should_receive(:after_method).with(some_object).once.ordered
cb.close!(some_object)
end
end

Expand Down

0 comments on commit 7f9be4a

Please sign in to comment.