Issue with Subclass trying to use the Superclass state machine #64
Closed
Description
Hello,
It seems that subclassing is supported by aasm
but I am getting an error which seems to be related to this.
I am getting:
Failure/Error: @subclass.update_state
NoMethodError:
undefined method `may_fire?' for nil:NilClass
My code looks like this:
class Superclass < ActiveRecord::Base
include AASM
aasm(column: 'state') do
state :missing_details, initial: true
state :invalid_details
state :confirmed_details, after_enter: :after_confirm
state :pending_details_confirmation
end
def update_state
if may_add_details?
add_details!
end
# More stuff
end
end
class Subclass < Superclass
# Subclass specific code
end
After debugging the code, I see that aasm
is looking for the state machine inside Subclass
and not finding it, as intended (or finding an empty state machine)
So, when it looks for the event add_details
it is not finding it and then raising the undefined method
error.
What's the expected behavior here? Is this correct or a bug?
I would expect aasm
to be smart enough to know that:
- There is no state machine in
Subclass
- Use the state machine in
Superclass
Maybe there is something I am doing wrong.
Proposed solutions:
A. Add an inheritance section in the README
B. Change the way aasm
looks up the state machine
I'd appreciate your feedback.
Thanks!
Metadata
Assignees
Labels
No labels