diff options
Diffstat (limited to 'actionpack/test')
-rw-r--r-- | actionpack/test/controller/integration_test.rb | 6 | ||||
-rw-r--r-- | actionpack/test/controller/mime_responds_test.rb | 6 | ||||
-rw-r--r-- | actionpack/test/controller/new_base/base_test.rb | 4 | ||||
-rw-r--r-- | actionpack/test/controller/test_test.rb | 14 | ||||
-rw-r--r-- | actionpack/test/dispatch/cookies_test.rb | 79 | ||||
-rw-r--r-- | actionpack/test/dispatch/test_request_test.rb | 24 | ||||
-rw-r--r-- | actionpack/test/fixtures/sprockets/app/javascripts/extra.js | 0 | ||||
-rw-r--r-- | actionpack/test/fixtures/sprockets/app/stylesheets/extra.css | 0 | ||||
-rw-r--r-- | actionpack/test/template/sprockets_helper_test.rb | 12 |
9 files changed, 116 insertions, 29 deletions
diff --git a/actionpack/test/controller/integration_test.rb b/actionpack/test/controller/integration_test.rb index 01dc2f2091..23709e44e2 100644 --- a/actionpack/test/controller/integration_test.rb +++ b/actionpack/test/controller/integration_test.rb @@ -492,6 +492,8 @@ class ApplicationIntegrationTest < ActionDispatch::IntegrationTest end routes.draw do + match '', :to => 'application_integration_test/test#index', :as => :empty_string + match 'foo', :to => 'application_integration_test/test#index', :as => :foo match 'bar', :to => 'application_integration_test/test#index', :as => :bar end @@ -501,11 +503,15 @@ class ApplicationIntegrationTest < ActionDispatch::IntegrationTest end test "includes route helpers" do + assert_equal '/', empty_string_path assert_equal '/foo', foo_path assert_equal '/bar', bar_path end test "route helpers after controller access" do + get '/' + assert_equal '/', empty_string_path + get '/foo' assert_equal '/foo', foo_path diff --git a/actionpack/test/controller/mime_responds_test.rb b/actionpack/test/controller/mime_responds_test.rb index 4a5e597500..26270571cf 100644 --- a/actionpack/test/controller/mime_responds_test.rb +++ b/actionpack/test/controller/mime_responds_test.rb @@ -498,6 +498,12 @@ class RespondToControllerTest < ActionController::TestCase assert_equal '<html><div id="iphone">Hello iPhone future from iPhone!</div></html>', @response.body assert_equal "text/html", @response.content_type end + + def test_invalid_format + get :using_defaults, :format => "invalidformat" + assert_equal " ", @response.body + assert_equal "text/html", @response.content_type + end end class RespondWithController < ActionController::Base diff --git a/actionpack/test/controller/new_base/base_test.rb b/actionpack/test/controller/new_base/base_test.rb index 8fa5d20372..ed244513a5 100644 --- a/actionpack/test/controller/new_base/base_test.rb +++ b/actionpack/test/controller/new_base/base_test.rb @@ -40,7 +40,7 @@ module Dispatching class ContainedEmptyController < ActionController::Base ; end class ContainedSubEmptyController < ContainedEmptyController ; end class ContainedNonDefaultPathController < ActionController::Base - def self.controller_path; "i_am_extremly_not_default"; end + def self.controller_path; "i_am_extremely_not_default"; end end end @@ -89,7 +89,7 @@ module Dispatching end test "namespaced non-default controller path" do - assert_equal 'i_am_extremly_not_default', Submodule::ContainedNonDefaultPathController.controller_path + assert_equal 'i_am_extremely_not_default', Submodule::ContainedNonDefaultPathController.controller_path assert_equal Submodule::ContainedNonDefaultPathController.controller_path, Submodule::ContainedNonDefaultPathController.new.controller_path end diff --git a/actionpack/test/controller/test_test.rb b/actionpack/test/controller/test_test.rb index 5896222a0a..f48b73b63a 100644 --- a/actionpack/test/controller/test_test.rb +++ b/actionpack/test/controller/test_test.rb @@ -493,6 +493,16 @@ XML ) end + def test_params_passing_with_fixnums + get :test_params, :page => {:name => "Page name", :month => 4, :year => 2004, :day => 6} + parsed_params = eval(@response.body) + assert_equal( + {'controller' => 'test_test/test', 'action' => 'test_params', + 'page' => {'name' => "Page name", 'month' => '4', 'year' => '2004', 'day' => '6'}}, + parsed_params + ) + end + def test_params_passing_with_frozen_values assert_nothing_raised do get :test_params, :frozen => 'icy'.freeze, :frozens => ['icy'.freeze].freeze @@ -583,13 +593,13 @@ XML end def test_should_have_knowledge_of_client_side_cookie_state_even_if_they_are_not_set - @request.cookies['foo'] = 'bar' + cookies['foo'] = 'bar' get :no_op assert_equal 'bar', cookies['foo'] end def test_should_detect_if_cookie_is_deleted - @request.cookies['foo'] = 'bar' + cookies['foo'] = 'bar' get :delete_cookie assert_nil cookies['foo'] end diff --git a/actionpack/test/dispatch/cookies_test.rb b/actionpack/test/dispatch/cookies_test.rb index e42c39f527..8e5fd97cc6 100644 --- a/actionpack/test/dispatch/cookies_test.rb +++ b/actionpack/test/dispatch/cookies_test.rb @@ -417,7 +417,7 @@ class CookiesTest < ActionController::TestCase assert_cookie_header "user_name=; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT" end - + def test_cookies_hash_is_indifferent_access get :symbol_key assert_equal "david", cookies[:user_name] @@ -430,54 +430,95 @@ class CookiesTest < ActionController::TestCase def test_setting_request_cookies_is_indifferent_access - @request.cookies.clear - @request.cookies[:user_name] = "andrew" + cookies.clear + cookies[:user_name] = "andrew" get :string_key_mock - assert_equal "david", cookies[:user_name] + assert_equal "david", cookies['user_name'] - @request.cookies.clear - @request.cookies['user_name'] = "andrew" + cookies.clear + cookies['user_name'] = "andrew" get :symbol_key_mock - assert_equal "david", cookies['user_name'] + assert_equal "david", cookies[:user_name] end def test_cookies_retained_across_requests get :symbol_key - assert_equal "user_name=david; path=/", @response.headers["Set-Cookie"] + assert_cookie_header "user_name=david; path=/" assert_equal "david", cookies[:user_name] get :noop assert_nil @response.headers["Set-Cookie"] - assert_equal "user_name=david", @request.env['HTTP_COOKIE'] assert_equal "david", cookies[:user_name] get :noop assert_nil @response.headers["Set-Cookie"] - assert_equal "user_name=david", @request.env['HTTP_COOKIE'] assert_equal "david", cookies[:user_name] end def test_cookies_can_be_cleared get :symbol_key - assert_equal "user_name=david; path=/", @response.headers["Set-Cookie"] assert_equal "david", cookies[:user_name] - @request.cookies.clear + cookies.clear get :noop - assert_nil @response.headers["Set-Cookie"] - assert_nil @request.env['HTTP_COOKIE'] assert_nil cookies[:user_name] get :symbol_key - assert_equal "user_name=david; path=/", @response.headers["Set-Cookie"] assert_equal "david", cookies[:user_name] end - def test_cookies_are_escaped - @request.cookies[:user_ids] = '1;2' + def test_can_set_http_cookie_header + @request.env['HTTP_COOKIE'] = 'user_name=david' + get :noop + assert_equal 'david', cookies['user_name'] + assert_equal 'david', cookies[:user_name] + + get :noop + assert_equal 'david', cookies['user_name'] + assert_equal 'david', cookies[:user_name] + + @request.env['HTTP_COOKIE'] = 'user_name=andrew' + get :noop + assert_equal 'andrew', cookies['user_name'] + assert_equal 'andrew', cookies[:user_name] + end + + def test_can_set_request_cookies + @request.cookies['user_name'] = 'david' + get :noop + assert_equal 'david', cookies['user_name'] + assert_equal 'david', cookies[:user_name] + + get :noop + assert_equal 'david', cookies['user_name'] + assert_equal 'david', cookies[:user_name] + + @request.cookies[:user_name] = 'andrew' + get :noop + assert_equal 'andrew', cookies['user_name'] + assert_equal 'andrew', cookies[:user_name] + end + + def test_cookies_precedence_over_http_cookie + @request.env['HTTP_COOKIE'] = 'user_name=andrew' + get :authenticate + assert_equal 'david', cookies['user_name'] + assert_equal 'david', cookies[:user_name] + + get :noop + assert_equal 'david', cookies['user_name'] + assert_equal 'david', cookies[:user_name] + end + + def test_cookies_precedence_over_request_cookies + @request.cookies['user_name'] = 'andrew' + get :authenticate + assert_equal 'david', cookies['user_name'] + assert_equal 'david', cookies[:user_name] + get :noop - assert_equal "user_ids=1%3B2", @request.env['HTTP_COOKIE'] - assert_equal "1;2", cookies[:user_ids] + assert_equal 'david', cookies['user_name'] + assert_equal 'david', cookies[:user_name] end private diff --git a/actionpack/test/dispatch/test_request_test.rb b/actionpack/test/dispatch/test_request_test.rb index 81a8c24525..aa115608ef 100644 --- a/actionpack/test/dispatch/test_request_test.rb +++ b/actionpack/test/dispatch/test_request_test.rb @@ -34,12 +34,24 @@ class TestRequestTest < ActiveSupport::TestCase assert_equal({}, req.cookies) assert_equal nil, req.env["HTTP_COOKIE"] - req.cookies["user_name"] = "david" - assert_equal({"user_name" => "david"}, req.cookies) - assert_equal "user_name=david", req.env["HTTP_COOKIE"] + req.cookie_jar["user_name"] = "david" + assert_cookies({"user_name" => "david"}, req.cookie_jar) - req.cookies["login"] = "XJ-122" - assert_equal({"user_name" => "david", "login" => "XJ-122"}, req.cookies) - assert_equal %w(login=XJ-122 user_name=david), req.env["HTTP_COOKIE"].split(/; /).sort + req.cookie_jar["login"] = "XJ-122" + assert_cookies({"user_name" => "david", "login" => "XJ-122"}, req.cookie_jar) + + req.cookie_jar.delete(:login) + assert_cookies({"user_name" => "david"}, req.cookie_jar) + + req.cookie_jar.clear + assert_cookies({}, req.cookie_jar) + + req.cookie_jar.update(:user_name => "david") + assert_cookies({"user_name" => "david"}, req.cookie_jar) end + + private + def assert_cookies(expected, cookie_jar) + assert_equal(expected, cookie_jar.instance_variable_get("@cookies")) + end end diff --git a/actionpack/test/fixtures/sprockets/app/javascripts/extra.js b/actionpack/test/fixtures/sprockets/app/javascripts/extra.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/actionpack/test/fixtures/sprockets/app/javascripts/extra.js diff --git a/actionpack/test/fixtures/sprockets/app/stylesheets/extra.css b/actionpack/test/fixtures/sprockets/app/stylesheets/extra.css new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/actionpack/test/fixtures/sprockets/app/stylesheets/extra.css diff --git a/actionpack/test/template/sprockets_helper_test.rb b/actionpack/test/template/sprockets_helper_test.rb index b26315083c..b1317d0a35 100644 --- a/actionpack/test/template/sprockets_helper_test.rb +++ b/actionpack/test/template/sprockets_helper_test.rb @@ -57,6 +57,12 @@ class SprocketsHelperTest < ActionView::TestCase asset_path("http://www.example.com/video/play.mp4") end + test "asset path with relative url root" do + @controller.config.relative_url_root = "/collaboration/hieraki" + assert_equal "/collaboration/hieraki/images/logo.gif", + asset_path("/images/logo.gif") + end + test "javascript path" do assert_equal "/assets/application-d41d8cd98f00b204e9800998ecf8427e.js", asset_path(:application, "js") @@ -88,6 +94,9 @@ class SprocketsHelperTest < ActionView::TestCase assert_equal "<script src=\"/assets/xmlhr-d41d8cd98f00b204e9800998ecf8427e.js?body=1\" type=\"text/javascript\"></script>\n<script src=\"/assets/application-d41d8cd98f00b204e9800998ecf8427e.js?body=1\" type=\"text/javascript\"></script>", javascript_include_tag(:application, :debug => true) + + assert_equal "<script src=\"/assets/xmlhr-d41d8cd98f00b204e9800998ecf8427e.js\" type=\"text/javascript\"></script>\n<script src=\"/assets/extra-d41d8cd98f00b204e9800998ecf8427e.js\" type=\"text/javascript\"></script>", + javascript_include_tag("xmlhr", "extra") end test "stylesheet path" do @@ -121,5 +130,8 @@ class SprocketsHelperTest < ActionView::TestCase assert_equal "<link href=\"/assets/style-d41d8cd98f00b204e9800998ecf8427e.css?body=1\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<link href=\"/assets/application-68b329da9893e34099c7d8ad5cb9c940.css?body=1\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />", stylesheet_link_tag(:application, :debug => true) + + assert_equal "<link href=\"/assets/style-d41d8cd98f00b204e9800998ecf8427e.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<link href=\"/assets/extra-d41d8cd98f00b204e9800998ecf8427e.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />", + stylesheet_link_tag("style", "extra") end end |