diff options
Diffstat (limited to 'actionpack/test/controller/force_ssl_test.rb')
-rw-r--r-- | actionpack/test/controller/force_ssl_test.rb | 80 |
1 files changed, 39 insertions, 41 deletions
diff --git a/actionpack/test/controller/force_ssl_test.rb b/actionpack/test/controller/force_ssl_test.rb index 03a9c9ae78..2b3859aa57 100644 --- a/actionpack/test/controller/force_ssl_test.rb +++ b/actionpack/test/controller/force_ssl_test.rb @@ -1,4 +1,4 @@ -require 'abstract_unit' +require "abstract_unit" class ForceSSLController < ActionController::Base def banana @@ -15,15 +15,15 @@ class ForceSSLControllerLevel < ForceSSLController end class ForceSSLCustomOptions < ForceSSLController - force_ssl :host => "secure.example.com", :only => :redirect_host - force_ssl :port => 8443, :only => :redirect_port - force_ssl :subdomain => 'secure', :only => :redirect_subdomain - force_ssl :domain => 'secure.com', :only => :redirect_domain - force_ssl :path => '/foo', :only => :redirect_path - force_ssl :status => :found, :only => :redirect_status - force_ssl :flash => { :message => 'Foo, Bar!' }, :only => :redirect_flash - force_ssl :alert => 'Foo, Bar!', :only => :redirect_alert - force_ssl :notice => 'Foo, Bar!', :only => :redirect_notice + force_ssl host: "secure.example.com", only: :redirect_host + force_ssl port: 8443, only: :redirect_port + force_ssl subdomain: "secure", only: :redirect_subdomain + force_ssl domain: "secure.com", only: :redirect_domain + force_ssl path: "/foo", only: :redirect_path + force_ssl status: :found, only: :redirect_status + force_ssl flash: { message: "Foo, Bar!" }, only: :redirect_flash + force_ssl alert: "Foo, Bar!", only: :redirect_alert + force_ssl notice: "Foo, Bar!", only: :redirect_notice def force_ssl_action render plain: action_name @@ -53,42 +53,42 @@ class ForceSSLCustomOptions < ForceSSLController end class ForceSSLOnlyAction < ForceSSLController - force_ssl :only => :cheeseburger + force_ssl only: :cheeseburger end class ForceSSLExceptAction < ForceSSLController - force_ssl :except => :banana + force_ssl except: :banana end class ForceSSLIfCondition < ForceSSLController - force_ssl :if => :use_force_ssl? + force_ssl if: :use_force_ssl? def use_force_ssl? - action_name == 'cheeseburger' + action_name == "cheeseburger" end end class ForceSSLFlash < ForceSSLController - force_ssl :except => [:banana, :set_flash, :use_flash] + force_ssl except: [:banana, :set_flash, :use_flash] def set_flash flash["that"] = "hello" - redirect_to '/force_ssl_flash/cheeseburger' + redirect_to "/force_ssl_flash/cheeseburger" end def use_flash @flash_copy = {}.update flash @flashy = flash["that"] - render :inline => "hello" + render inline: "hello" end end class RedirectToSSL < ForceSSLController def banana - force_ssl_redirect || render(plain: 'monkey') + force_ssl_redirect || render(plain: "monkey") end def cheeseburger - force_ssl_redirect('secure.cheeseburger.host') || render(plain: 'ihaz') + force_ssl_redirect("secure.cheeseburger.host") || render(plain: "ihaz") end end @@ -114,7 +114,7 @@ end class ForceSSLCustomOptionsTest < ActionController::TestCase def setup - @request.env['HTTP_HOST'] = 'www.example.com:80' + @request.env["HTTP_HOST"] = "www.example.com:80" end def test_redirect_to_custom_host @@ -229,15 +229,13 @@ class ForceSSLFlashTest < ActionController::TestCase assert_response 302 assert_equal "http://test.host/force_ssl_flash/cheeseburger", redirect_to_url - # FIXME: AC::TestCase#build_request_uri doesn't build a new uri if PATH_INFO exists - @request.env.delete('PATH_INFO') + @request.env.delete("PATH_INFO") get :cheeseburger assert_response 301 assert_equal "https://test.host/force_ssl_flash/cheeseburger", redirect_to_url - # FIXME: AC::TestCase#build_request_uri doesn't build a new uri if PATH_INFO exists - @request.env.delete('PATH_INFO') + @request.env.delete("PATH_INFO") get :use_flash assert_equal "hello", @controller.instance_variable_get("@flash_copy")["that"] @@ -251,15 +249,15 @@ class ForceSSLDuplicateRoutesTest < ActionController::TestCase def test_force_ssl_redirects_to_same_path with_routing do |set| set.draw do - get '/foo', :to => 'force_ssl_controller_level#banana' - get '/bar', :to => 'force_ssl_controller_level#banana' + get "/foo", to: "force_ssl_controller_level#banana" + get "/bar", to: "force_ssl_controller_level#banana" end - @request.env['PATH_INFO'] = '/bar' + @request.env["PATH_INFO"] = "/bar" get :banana assert_response 301 - assert_equal 'https://test.host/bar', redirect_to_url + assert_equal "https://test.host/bar", redirect_to_url end end end @@ -270,12 +268,12 @@ class ForceSSLFormatTest < ActionController::TestCase def test_force_ssl_redirects_to_same_format with_routing do |set| set.draw do - get '/foo', :to => 'force_ssl_controller_level#banana' + get "/foo", to: "force_ssl_controller_level#banana" end get :banana, format: :json assert_response 301 - assert_equal 'https://test.host/foo.json', redirect_to_url + assert_equal "https://test.host/foo.json", redirect_to_url end end end @@ -286,18 +284,18 @@ class ForceSSLOptionalSegmentsTest < ActionController::TestCase def test_force_ssl_redirects_to_same_format with_routing do |set| set.draw do - scope '(:locale)' do - defaults :locale => 'en' do - get '/foo', :to => 'force_ssl_controller_level#banana' + scope "(:locale)" do + defaults locale: "en" do + get "/foo", to: "force_ssl_controller_level#banana" end end end - @request.env['PATH_INFO'] = '/en/foo' - get :banana, params: { locale: 'en' } - assert_equal 'en', @controller.params[:locale] + @request.env["PATH_INFO"] = "/en/foo" + get :banana, params: { locale: "en" } + assert_equal "en", @controller.params[:locale] assert_response 301 - assert_equal 'https://test.host/en/foo', redirect_to_url + assert_equal "https://test.host/en/foo", redirect_to_url end end end @@ -316,17 +314,17 @@ class RedirectToSSLTest < ActionController::TestCase end def test_cheeseburgers_does_not_redirect_if_already_https - request.env['HTTPS'] = 'on' + request.env["HTTPS"] = "on" get :cheeseburger assert_response 200 - assert_equal 'ihaz', response.body + assert_equal "ihaz", response.body end end class ForceSSLControllerLevelTest < ActionController::TestCase def test_no_redirect_websocket_ssl_request - request.env['rack.url_scheme'] = 'wss' - request.env['Upgrade'] = 'websocket' + request.env["rack.url_scheme"] = "wss" + request.env["Upgrade"] = "websocket" get :cheeseburger assert_response 200 end |