Created
January 14, 2014 19:53
-
-
Save grosser/8424534 to your computer and use it in GitHub Desktop.
hacks that help getting a rails 2 app run like a rails 3 app
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
# test | |
if Rails::VERSION::MAJOR == 2 | |
# make integration tests use rack response, so we can test our middlewares | |
# and not only the pure controller response | |
ActionController::Base.class_eval do | |
# this is usually done just-in-time by #process but we need to do it earlier | |
include ActionController::Integration::ControllerCapture | |
# then we hide last_instantiation from #process | |
def self.last_instantiation;end | |
end | |
ActionController::Integration::Session.class_eval do | |
def process_with_rackify(*args) | |
process_without_rackify(*args) | |
ensure | |
# needed e.g. inside of assert_redirect_to | |
capture = ActionController::Integration::ControllerCapture::ClassMethods | |
# not set by original #process | |
@response.redirected_to = @response.headers["Location"] if @response | |
if @controller = capture.send(:class_variable_get, :@@last_instantiation) | |
@request = @controller.request | |
@response.template = @controller.response.template if @response && @controller.response | |
@controller.send(:set_test_assigns) | |
end | |
end | |
alias_method_chain :process, :rackify | |
end | |
end | |
# test | |
if Rails::VERSION::MAJOR == 2 | |
# set default accept to text/html as rails 3 does | |
def initialize_default_values_with_accept(*args) | |
@env["HTTP_ACCEPT"] ||= "text/html" | |
initialize_default_values_without_accept(*args) | |
end | |
alias_method_chain :initialize_default_values, :accept unless method_defined?(:initialize_default_values_without_accept) | |
# reset format before request as rails 3 does | |
def recycle_with_format_reset! | |
@format = nil | |
recycle_without_format_reset! | |
end | |
alias_method_chain :recycle!, :format_reset unless method_defined?(:recycle_without_format_reset!) | |
end | |
#test | |
if Rails::VERSION::MAJOR == 2 | |
# make integration tests use rack response, so we can test our middlewares | |
# and not only the pure controller response | |
ActionController::Base.class_eval do | |
# this is usually done just-in-time by #process but we need to do it earlier | |
include ActionController::Integration::ControllerCapture | |
# then we hide last_instantiation from #process | |
def self.last_instantiation;end | |
end | |
ActionController::Integration::Session.class_eval do | |
def process_with_rackify(*args) | |
process_without_rackify(*args) | |
ensure | |
# needed e.g. inside of assert_redirect_to | |
capture = ActionController::Integration::ControllerCapture::ClassMethods | |
# not set by original #process | |
@response.redirected_to = @response.headers["Location"] if @response | |
if @controller = capture.send(:class_variable_get, :@@last_instantiation) | |
@request = @controller.request | |
@response.template = @controller.response.template if @response && @controller.response | |
@controller.send(:set_test_assigns) | |
end | |
end | |
alias_method_chain :process, :rackify | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment