Skip to content

Instantly share code, notes, and snippets.

@ahoward
Created April 7, 2011 22:45
Show Gist options
  • Save ahoward/908947 to your computer and use it in GitHub Desktop.
Save ahoward/908947 to your computer and use it in GitHub Desktop.
## TODO wtf!? there must be an easier way... please help!
#
def mock_controller
require 'action_dispatch/testing/test_request.rb'
require 'action_dispatch/testing/test_response.rb'
store = ActiveSupport::Cache::MemoryStore.new
controller = ApplicationController.new
controller.perform_caching = true
controller.cache_store = store
request = ActionDispatch::TestRequest.new
response = ActionDispatch::TestResponse.new
controller.request = request
controller.response = response
controller.send(:initialize_template_class, response)
controller.send(:assign_shortcuts, request, response)
controller.send(:default_url_options).merge!(DefaultUrlOptions) if defined?(DefaultUrlOptions)
controller
end
@davidjbeveridge
Copy link

Don't know if this is actually an improvement, but it's shorter.
https://gist.github.com/909415

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment