aasm icon indicating copy to clipboard operation
aasm copied to clipboard

fire! and fire with unknown event, crash with NoMethodError

Open pjmartorell opened this issue 7 years ago • 6 comments

When I run fire or fire! with an unknown event (i.e. Model.aasm.fire!(:whatever) ) it raises a NoMethodError (undefined method fire_callbacks' for nil:NilClass), seems that it tries to fire before callbacks even not knowing that the event exists, which is not the expected behaviour.

For me, fire and fire! with an unknown event should not fire callbacks and return an exception like "Unknown event", to be consistent.

pjmartorell avatar Apr 19 '19 23:04 pjmartorell

I agree with your point, are you interested in raising a PR for this ?

anilmaurya avatar Apr 20 '19 04:04 anilmaurya

Yes, I'll do it :) Regarding before callbacks, I'm not sure if they should be triggered or not for an unknown event. How do we handle this case? do we consider the same behaviour for firing a non permitted event than for firing an unknown event, in terms of triggering callbacks?

For me an unpermitted event should trigger before callbacks, but not an unknown event.

What do you think @anilmaurya?

pjmartorell avatar Apr 20 '19 09:04 pjmartorell

I Agree, unpermitted event should trigger before callbacks but unknown event should not trigger callbacks.

anilmaurya avatar Apr 21 '19 13:04 anilmaurya

this should be fixed, as it is possible to call arbitrary methods:

Car.aasm.fire("destroy")

mck9 avatar Mar 27 '20 12:03 mck9

@mck9 'should be fixed' meaning no longer a problem, or that you would like it to be fixed? I suspect the latter.

@anilmaurya was there anything wrong with the PR looks like it's been hanging around for a year?

barisbalic avatar Jul 17 '20 14:07 barisbalic

@barisbalic yes, the latter would be nice. fire should only be allowed to call valid events.

mck9 avatar Jul 21 '20 17:07 mck9