-
-
Save davidjbeveridge/909415 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Don't know about better, but fewer lines: | |
def mock_controller | |
['test_request','test_response'].each {|fname| require "action_dispatch/testing/#{fname}" } | |
controller = ApplicationController.new | |
controller.perform_caching = true | |
controller.cache_store = ActiveSupport::Cache::MemoryStore.new | |
['request','response'].each {|r| controller.send("#{r}=", ActionDispatch.const_get("Test#{r.capitalize}").new) } | |
controller.initialize_template_class controller.response | |
controller.assign_shortcuts controller.request, controller.response | |
controller.default_url_options.merge!(DefaultUrlOptions) if defined?(DefaultUrlOptions) | |
controller | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Agreed. It would be really nice if ApplicationController.new simply did that; but I suppose there are probably good reasons it doesn't. If nothing else, not attaching the Request and Response keeps us from being enslaved to the Request/Reply pattern. I suppose you could rewrite Rails just a bit to use Command/Event and support a completely different kind of application... don't know why you would though.