jnunemaker/mongomapper — pull request #335 by mpabst (2011-10-27 23:53:51+00:00)
Title: Changing Railtie to not call DescendantsTracker.clear; test for same

This was a real bugger. But we now know a lot more about active_support, mongo_mapper, railties, thinking_sphinx, and rails bootstrapping. This was the best way we could find to describe this problem:

ThinkingSphinx
1 looks for all the files in app/models
2 deduces a constant name from the file names
3 calls .constantize on the string from 2 to trigger ActiveSupport::Dependencies to go out and autoload that same file.
4 iterates over AR::Base.descendants, looking for index definitions in each of the models

MongoMapper
Calls ActiveSupport::DescendantsTracker.clear, but not ActiveSupport::Dependencies.clear. This means that when TS gets to step 3, the constant is not in DescendantsTracker, but is in Dependencies. So, when TS references the constant, Dependencies sees that it's already loaded and does nothing, meaning the inherited hook on AR::Base isn't called, meaning that the class isn't reinserted into DescendantsTracker, meaning that TS can't find the indexes on that model.

Rails, as of at least 3.0.10 always calls BOTH ActiveSupport::DescendantsTracker.clear and ActiveSupport::Dependencies.clear in the cleanup hook for server requests. This is correct, and gets Dependencies to go ahead and reload the files thus cleared

Long story short, calling one without the other creates a discrepency between the constants which have been loaded and the list of descendants. And there is no need for this call as Rails handles it for us.

Thanks,
Michael and Thomas