The force_ssl function in rails 3.1 is hardcoded to ignore the development environment, but not test. This is giving me redirect errors in my (minitest) tests. Is the solution to set up my test server to support ssl (if so, how?). If not, should I monkey patch force_ssl to ignore requests in test?
def force_ssl(options = {})
host = options.delete(:host)
before_filter(options) do
if !request.ssl? && !Rails.env.development?
redirect_options = {:protocol => 'https://', :status => :moved_permanently}
redirect_options.merge!(:host => host) if host
flash.keep
redirect_to redirect_options
end
end
end
EDIT Found this chain, which confirms other people think this an issue, but doesn’t look like there’s a committed fix yet: https://github.com/rails/rails/pull/2630
Another option instead of monkey patching the entire application is to just override
force_sslin your test suite alone. For example, intest/test_helper.rbyou can add this: