1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #4429 from marcinbunsch/1923-force-ssl-redirect-keep-flash

When force redirecting to SSL, make sure that the session is kept
This commit is contained in:
José Valim 2012-01-12 11:47:59 -08:00
commit ef1dfb62d7
2 changed files with 38 additions and 1 deletions

View file

@ -29,6 +29,7 @@ module ActionController
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

View file

@ -26,6 +26,23 @@ class ForceSSLExceptAction < ForceSSLController
force_ssl :except => :banana
end
class ForceSSLFlash < ForceSSLController
force_ssl :except => [:banana, :set_flash, :use_flash]
def set_flash
flash["that"] = "hello"
redirect_to '/force_ssl_flash/cheeseburger'
end
def use_flash
@flash_copy = {}.update flash
@flashy = flash["that"]
render :inline => "hello"
end
end
class ForceSSLControllerLevelTest < ActionController::TestCase
tests ForceSSLControllerLevel
@ -101,3 +118,22 @@ class ForceSSLExcludeDevelopmentTest < ActionController::TestCase
assert_response 200
end
end
class ForceSSLFlashTest < ActionController::TestCase
tests ForceSSLFlash
def test_cheeseburger_redirects_to_https
get :set_flash
assert_response 302
assert_equal "http://test.host/force_ssl_flash/cheeseburger", redirect_to_url
get :cheeseburger
assert_response 301
assert_equal "https://test.host/force_ssl_flash/cheeseburger", redirect_to_url
get :use_flash
assert_equal "hello", assigns["flash_copy"]["that"]
assert_equal "hello", assigns["flashy"]
end
end