Easier debugging when refactoring Rails controllers
When refactoring a big controller with lots of before filters, it’s common (for me anyway) to get into a situation where tests start failing due to before filters redirecting. Today I made it a lot easier to debug these failing tests by adding this to my ApplicationController:
def redirect_to_with_logging(*args)
logger.debug "Redirect: #{args.inspect} from #{caller[0]}"
redirect_to_without_logging *args
end
alias_method_chain :redirect_to, :logging
This will log where the new redirect is coming from, and make it a lot easier to figure out what is breaking your tests. Enjoy.
