benzelano / test_lh_import

1 stars 0 forks source link

undefined method `arity' for nil:NilClass #165

Closed benzelano closed 13 years ago

benzelano commented 13 years ago

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:inmethod_missing’ from /state_machine-0.9.4/lib/state_machine/eval_helpers.rb:56:in evaluate_method’ from /state_machine-0.9.4/lib/state_machine/callback.rb:196:inblock in run_methods’ from /state_machine-0.9.4/lib/state_machine/callback.rb:195:in each’ from /state_machine-0.9.4/lib/state_machine/callback.rb:195:inrun_methods’ from /state_machine-0.9.4/lib/state_machine/callback.rb:158:in call’ from /state_machine-0.9.4/lib/state_machine/transition.rb:379:inblock (2 levels) in after’ from /state_machine-0.9.4/lib/state_machine/transition.rb:379:in each’ from /state_machine-0.9.4/lib/state_machine/transition.rb:379:inblock in after’ from /state_machine-0.9.4/lib/state_machine/transition.rb:377:in catch’ from /state_machine-0.9.4/lib/state_machine/transition.rb:377:inafter’ from /state_machine-0.9.4/lib/state_machine/transition.rb:193:in run_callbacks’ from /state_machine-0.9.4/lib/state_machine/transition_collection.rb:126:inrun_callbacks’ from /state_machine-0.9.4/lib/state_machine/transition_collection.rb:211:in run_callbacks’ from /state_machine-0.9.4/lib/state_machine/transition_collection.rb:63:inblock (2 levels) in perform’ from /state_machine-0.9.4/lib/state_machine/transition_collection.rb:63:in catch’ ... 16 levels... from /state_machine-0.9.4/lib/state_machine/transition_collection.rb:153:ineach’ from /state_machine-0.9.4/lib/state_machine/transition_collection.rb:153:in block in run_actions’ from /state_machine-0.9.4/lib/state_machine/transition_collection.rb:169:incatch_exceptions’ from /state_machine-0.9.4/lib/state_machine/transition_collection.rb:147:in run_actions’ from /state_machine-0.9.4/lib/state_machine/transition_collection.rb:60:inperform’ from /state_machine-0.9.4/lib/state_machine/transition.rb:162:in perform’ from /state_machine-0.9.4/lib/state_machine/event.rb:207:infire’ from /state_machine-0.9.4/lib/state_machine/event.rb:258:in block in add_actions’ from /state_machine-0.9.4/lib/state_machine/machine.rb:537:incall’ 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).

benzelano commented 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.