Closed benzelano closed 13 years ago
Hey RailsCanuck -
I’m unable to reproduce this scenario. If you could provide a test case with full code that demonstrates this behavior, that would be great. The error only occurs when state_machine is unable to find the method referenced in the callback. This would indicate to me that something strange was going on with the objects you were interacting with.
Feel free to reopen if you can find a case that I can reproduce.
RailsCanuck opened this issue
I have several classes that I am using state_machine for my rails app and I am getting the following error while using state_machine in only one of these classes, the rest work fine which is confusing. The class name is Shipment and it has several classes that inherit from Shipment including DropShipment and OutgoingShipment.
@@@ NoMethodError: undefined method
arity’ for nil:NilClass from /activesupport-3.0.3/lib/active_support/whiny_nil.rb:48:in
method_missing’ from /state_machine-0.9.4/lib/state_machine/eval_helpers.rb:56:inevaluate_method’ from /state_machine-0.9.4/lib/state_machine/callback.rb:196:in
block in run_methods’ from /state_machine-0.9.4/lib/state_machine/callback.rb:195:ineach’ from /state_machine-0.9.4/lib/state_machine/callback.rb:195:in
run_methods’ from /state_machine-0.9.4/lib/state_machine/callback.rb:158:incall’ from /state_machine-0.9.4/lib/state_machine/transition.rb:379:in
block (2 levels) in after’ from /state_machine-0.9.4/lib/state_machine/transition.rb:379:ineach’ from /state_machine-0.9.4/lib/state_machine/transition.rb:379:in
block in after’ from /state_machine-0.9.4/lib/state_machine/transition.rb:377:incatch’ from /state_machine-0.9.4/lib/state_machine/transition.rb:377:in
after’ from /state_machine-0.9.4/lib/state_machine/transition.rb:193:inrun_callbacks’ from /state_machine-0.9.4/lib/state_machine/transition_collection.rb:126:in
run_callbacks’ from /state_machine-0.9.4/lib/state_machine/transition_collection.rb:211:inrun_callbacks’ from /state_machine-0.9.4/lib/state_machine/transition_collection.rb:63:in
block (2 levels) in perform’ from /state_machine-0.9.4/lib/state_machine/transition_collection.rb:63:incatch’ ... 16 levels... from /state_machine-0.9.4/lib/state_machine/transition_collection.rb:153:in
each’ from /state_machine-0.9.4/lib/state_machine/transition_collection.rb:153:inblock in run_actions’ from /state_machine-0.9.4/lib/state_machine/transition_collection.rb:169:in
catch_exceptions’ from /state_machine-0.9.4/lib/state_machine/transition_collection.rb:147:inrun_actions’ from /state_machine-0.9.4/lib/state_machine/transition_collection.rb:60:in
perform’ from /state_machine-0.9.4/lib/state_machine/transition.rb:162:inperform’ from /state_machine-0.9.4/lib/state_machine/event.rb:207:in
fire’ from /state_machine-0.9.4/lib/state_machine/event.rb:258:inblock in add_actions’ from /state_machine-0.9.4/lib/state_machine/machine.rb:537:in
call’ from /state_machine-0.9.4/lib/state_machine/machine.rb:537:in `block (2 levels) in define_instance_method’ @@@The error occur when using the callback where I have
@@@ state_machine :status, :initial => :pending do event :ship do transition :confirm_shipping => :shipping end after_transition :confirm_shipping => :shipping, :do => :check_order_completion end
def check_order_completion orders.map(&:complete) end @@@
It is quite clear that somehow the method being passed in ’:check_order_completion’ has a null object. As a band-aid I changed the method call from a symbol to a string as follows and all works fine.
@@@ after_transition :confirm_shipping => :shipping, :do => ’check_order_completion’ @@@
This issue was bothering me for a while but once I looked at the state_machine source code and noticed that the callback accepts symbols, blocks, or strings then that helped to solve my problem but I thought it would be worth noting the bug on the null object being passed into evaluate_method in eval_helpers.
original LH ticket
This ticket has 0 attachment(s).