Unintended side-effect from before_remove_const?

Hey all,

In troubleshooting a failing test for MetaSearch against 3-0-stable, I came across some undesirable (from my side, anyway) behavior in http://github.com/rails/rails/commit/bf87528b53f1422708ec0188d126cfca824ddc5c.

A simple one-liner, it would appear, but AR::Base implements before_remove_const to do a bit of scoped method cleanup... It's the only thing I can see that might cause the problem, which is:

When accessing an AR::Base subclass via a reflection's klass accessor, it seems as though class_attributes which are set up via macros (attr_unsearchable in the MetaSearch case, but I also checked with attr_protected) do not have their values. Commenting that single line:

  constantize(const).before_remove_const if constantize(const).respond_to?(:before_remove_const)

will cause the failures to come and go at will, but removing the only before_remove_const method I can find, in AR::Base, will not get the failures to stop.

This is with Ruby 1.9.2-p0.

Any insights (or even confirmations I'm not insane) would be appreciated. :slight_smile:


Aaaand, nevermind. I was loading fixtures before all of my required libraries were loaded in my tests. That makes me feel a lot better, since I find it less confusing to find that I made a mistake in my library load order than to think that such a minor change introduced such an obscure bug. :slight_smile: