From 8bbaa94c8125cf3efc0ec05cee5bf3193fbf5cf7 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Sat, 5 Apr 2014 11:02:18 -0700 Subject: Fix setup of adding _flash_types test. Adding flash types to a controller within any of the tests will result in a global state change of the controller under test. This patch will prevent state leaks and allow us to run the test in random order. --- actionpack/test/controller/flash_test.rb | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'actionpack') diff --git a/actionpack/test/controller/flash_test.rb b/actionpack/test/controller/flash_test.rb index 25a4857eba..ff5587d768 100644 --- a/actionpack/test/controller/flash_test.rb +++ b/actionpack/test/controller/flash_test.rb @@ -210,20 +210,29 @@ class FlashTest < ActionController::TestCase end def test_redirect_to_with_adding_flash_types - @controller.class.add_flash_types :foo + original_controller = @controller + test_controller_with_flash_type_foo = Class.new(TestController) do + add_flash_types :foo + end + @controller = test_controller_with_flash_type_foo.new get :redirect_with_foo_flash assert_equal "for great justice", @controller.send(:flash)[:foo] + ensure + @controller = original_controller end - class SubclassesTestController < TestController; end - def test_add_flash_type_to_subclasses - TestController.add_flash_types :foo - assert SubclassesTestController._flash_types.include?(:foo) + test_controller_with_flash_type_foo = Class.new(TestController) do + add_flash_types :foo + end + subclass_controller_with_no_flash_type = Class.new(test_controller_with_flash_type_foo) + assert subclass_controller_with_no_flash_type._flash_types.include?(:foo) end def test_do_not_add_flash_type_to_parent_class - SubclassesTestController.add_flash_types :bar + subclass_controller_with_flash_type_bar = Class.new(TestController) do + add_flash_types :bar + end assert_not TestController._flash_types.include?(:bar) end end -- cgit v1.2.3 From a44d7107df9b71f747bb0075df05ce9dcac05822 Mon Sep 17 00:00:00 2001 From: Vipul A M Date: Mon, 7 Apr 2014 10:34:17 +0530 Subject: Remove unused `subclass_controller_with_flash_type_bar` var from flash test. --- actionpack/test/controller/flash_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack') diff --git a/actionpack/test/controller/flash_test.rb b/actionpack/test/controller/flash_test.rb index ff5587d768..3720a920d0 100644 --- a/actionpack/test/controller/flash_test.rb +++ b/actionpack/test/controller/flash_test.rb @@ -229,8 +229,8 @@ class FlashTest < ActionController::TestCase assert subclass_controller_with_no_flash_type._flash_types.include?(:foo) end - def test_do_not_add_flash_type_to_parent_class - subclass_controller_with_flash_type_bar = Class.new(TestController) do + def test_does_not_add_flash_type_to_parent_class + Class.new(TestController) do add_flash_types :bar end assert_not TestController._flash_types.include?(:bar) -- cgit v1.2.3 From 85e424de6c9dea71edeb51d966014673c9631df3 Mon Sep 17 00:00:00 2001 From: Andriel Nuernberg Date: Wed, 9 Apr 2014 13:48:53 -0300 Subject: Avoid URI parsing This parsing is unecessary once the Request object already has the needed information. --- actionpack/lib/action_dispatch/middleware/ssl.rb | 13 ++++++++----- actionpack/test/dispatch/ssl_test.rb | 7 +++++++ 2 files changed, 15 insertions(+), 5 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/middleware/ssl.rb b/actionpack/lib/action_dispatch/middleware/ssl.rb index 999c022535..0c7caef25d 100644 --- a/actionpack/lib/action_dispatch/middleware/ssl.rb +++ b/actionpack/lib/action_dispatch/middleware/ssl.rb @@ -32,11 +32,14 @@ module ActionDispatch private def redirect_to_https(request) - url = URI(request.url) - url.scheme = "https" - url.host = @host if @host - url.port = @port if @port - headers = { 'Content-Type' => 'text/html', 'Location' => url.to_s } + host = @host || request.host + port = @port || request.port + + location = "https://#{host}" + location << ":#{port}" if port != 80 + location << request.fullpath + + headers = { 'Content-Type' => 'text/html', 'Location' => location } [301, headers, []] end diff --git a/actionpack/test/dispatch/ssl_test.rb b/actionpack/test/dispatch/ssl_test.rb index 94969f795a..c3598c5e8e 100644 --- a/actionpack/test/dispatch/ssl_test.rb +++ b/actionpack/test/dispatch/ssl_test.rb @@ -196,6 +196,13 @@ class SSLTest < ActionDispatch::IntegrationTest response.headers['Location'] end + def test_redirect_to_host_with_port + self.app = ActionDispatch::SSL.new(default_app, :host => "ssl.example.org:443") + get "http://example.org/path?key=value" + assert_equal "https://ssl.example.org:443/path?key=value", + response.headers['Location'] + end + def test_redirect_to_secure_host_when_on_subdomain self.app = ActionDispatch::SSL.new(default_app, :host => "ssl.example.org") get "http://ssl.example.org/path?key=value" -- cgit v1.2.3