rails/rails — pull request #4980 by bradediger (2012-02-09 21:31:47+00:00)
Title: Clear template extension memoize cache on register_template_handler

Some gems like to monkey around with ActionView in a railtie. The one that prompted this issue for a client of mine was [best_in_place](https://github.com/bernat/best_in_place/blob/0d8434246dc20713df3de076c49817fb3aaeb376/lib/best_in_place/railtie.rb#L4).

Currently, ActionView::Template::Handlers.extensions memoizes itself into a cvar the first time it's touched. So after it's called, register_template_handlers has no effect on the recognized set of extensions. In the application in question, the problematic gem loaded before prototype-rails could register its RJS handler, and so any RJS templates raised a MissingTemplate.

This commit fixes register_template_handlers to clear the memoization cache so that the extensions list is always accurate. Added a test differentiating my fix from 3-1-stable.

I also removed memoization from LookupContext#default_handlers, since it would exhibit the same problem. It just calls Template::Handlers.extensions, which is memoized anyway, so I don't think this incurs any appreciable slowdown.

If this is an acceptable fix, I can also port to 3-2-stable and master. Neither 3-2-stable nor master appear to have the LookupContext issue, as that code has been refactored since 3.1. But the Template::Handlers.extensions issue exists from 3.1 through today on master.

Thanks!