Closed tonymarklove closed 8 years ago
Ran into this exact problem, validations added to sub-classed model using STI being applied too broadly. We used this fix and it resolved the issue. Thanks!
Any chance on getting this merged?
@seuros any news?
When a sub-class clones a new copy of the machine the states get updated but the cached
StateContext
was still pointing to the old machine instance. Meaning that eachstate
rule gets evaluated in the context of the parent class.We first noticed this with ActiveRecord objects using single table inheritance. Adding validation rules in
state
s on the sub-class would cause the parent class to also apply those validations.The added test case actually passes without the fix, but I can’t quite figure out why. Something to do with the default definee for
def
in the context of aclass_eval
, I think.In any case,
example_class_method
will cause an undefined method error if it is called onVehicle
, but executes correctly onMotorcycle
with the fix applied.