diff options
Diffstat (limited to 'actionview/test/template/url_helper_test.rb')
-rw-r--r-- | actionview/test/template/url_helper_test.rb | 64 |
1 files changed, 51 insertions, 13 deletions
diff --git a/actionview/test/template/url_helper_test.rb b/actionview/test/template/url_helper_test.rb index 08cb5dfea7..1ab28e4749 100644 --- a/actionview/test/template/url_helper_test.rb +++ b/actionview/test/template/url_helper_test.rb @@ -75,13 +75,29 @@ class UrlHelperTest < ActiveSupport::TestCase assert_equal "javascript:history.back()", url_for(:back) end + def test_url_for_with_array_defaults_to_only_path_true + assert_equal "/other", url_for([:other, { controller: "foo" }]) + end + + def test_url_for_with_array_and_only_path_set_to_false + default_url_options[:host] = "http://example.com" + assert_equal "http://example.com/other", url_for([:other, { controller: "foo", only_path: false }]) + end + def test_to_form_params_with_hash assert_equal( - [{ name: :name, value: "David" }, { name: :nationality, value: "Danish" }], + [{ name: "name", value: "David" }, { name: "nationality", value: "Danish" }], to_form_params(name: "David", nationality: "Danish") ) end + def test_to_form_params_with_hash_having_symbol_and_string_keys + assert_equal( + [{ name: "name", value: "David" }, { name: "nationality", value: "Danish" }], + to_form_params("name" => "David", :nationality => "Danish") + ) + end + def test_to_form_params_with_nested_hash assert_equal( [{ name: "country[name]", value: "Denmark" }], @@ -541,7 +557,7 @@ class UrlHelperTest < ActiveSupport::TestCase def test_current_page_with_escaped_params_with_different_encoding @request = request_for_url("/") - @request.stub(:path, "/category/administra%c3%a7%c3%a3o".dup.force_encoding(Encoding::ASCII_8BIT)) do + @request.stub(:path, (+"/category/administra%c3%a7%c3%a3o").force_encoding(Encoding::ASCII_8BIT)) do assert current_page?(controller: "foo", action: "category", category: "administraĆ§Ć£o") assert current_page?("http://www.example.com/category/administra%c3%a7%c3%a3o") end @@ -697,7 +713,7 @@ end class UrlHelperControllerTest < ActionController::TestCase class UrlHelperController < ActionController::Base - test_routes do + ROUTES = test_routes do get "url_helper_controller_test/url_helper/show/:id", to: "url_helper_controller_test/url_helper#show", as: :show @@ -761,6 +777,11 @@ class UrlHelperControllerTest < ActionController::TestCase helper_method :override_url_helper_path end + def setup + super + @routes = UrlHelperController::ROUTES + end + tests UrlHelperController def test_url_for_shows_only_path @@ -821,7 +842,7 @@ class UrlHelperControllerTest < ActionController::TestCase end class TasksController < ActionController::Base - test_routes do + ROUTES = test_routes do resources :tasks end @@ -843,6 +864,11 @@ end class LinkToUnlessCurrentWithControllerTest < ActionController::TestCase tests TasksController + def setup + super + @routes = TasksController::ROUTES + end + def test_link_to_unless_current_to_current get :index assert_equal "tasks\ntasks", @response.body @@ -875,7 +901,7 @@ class Session end class WorkshopsController < ActionController::Base - test_routes do + ROUTES = test_routes do resources :workshops do resources :sessions end @@ -898,7 +924,7 @@ class WorkshopsController < ActionController::Base end class SessionsController < ActionController::Base - test_routes do + ROUTES = test_routes do resources :workshops do resources :sessions end @@ -925,6 +951,11 @@ class SessionsController < ActionController::Base end class PolymorphicControllerTest < ActionController::TestCase + def setup + super + @routes = WorkshopsController::ROUTES + end + def test_new_resource @controller = WorkshopsController.new @@ -939,6 +970,20 @@ class PolymorphicControllerTest < ActionController::TestCase assert_equal %{/workshops/1\n<a href="/workshops/1">Workshop</a>}, @response.body end + def test_current_page_when_options_does_not_respond_to_to_hash + @controller = WorkshopsController.new + + get :edit, params: { id: 1 } + assert_equal "false", @response.body + end +end + +class PolymorphicSessionsControllerTest < ActionController::TestCase + def setup + super + @routes = SessionsController::ROUTES + end + def test_new_nested_resource @controller = SessionsController.new @@ -959,11 +1004,4 @@ class PolymorphicControllerTest < ActionController::TestCase get :edit, params: { workshop_id: 1, id: 1, format: "json" } assert_equal %{/workshops/1/sessions/1.json\n<a href="/workshops/1/sessions/1.json">Session</a>}, @response.body end - - def test_current_page_when_options_does_not_respond_to_to_hash - @controller = WorkshopsController.new - - get :edit, params: { id: 1 } - assert_equal "false", @response.body - end end |