-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
-
None
I was playing around with scope methods today and discovered that they don't play well with inheritance in some cases.
I would expect that any scope method defined on a parent class would be available on the subclasses. This behavior is what is seen when all scopes are defined inline as part of the original class definitions, but there is an edge case when a scope is added to a parent after both the parent and child classes are loaded. In this case, the subclass.scopes field will have been dup'd from the parent's scopes field at the time of initialization of the child class. When the parent scope method is called on the child class in this case, the scope definition cannot be found in its copy of scopes and the code attempts to call scoping[:scope][*args] on a nil.
I have some code with a couple failing tests here: https://github.com/md5/mongoid/tree/subclass-scopes