提交 46ea7698 编写于 作者: A Akira Matsuda

URL helper methods on controllers are public methods

上级 666897a0
...@@ -226,7 +226,7 @@ def test_url_options_override ...@@ -226,7 +226,7 @@ def test_url_options_override
get :from_view, params: { route: "from_view_url" } get :from_view, params: { route: "from_view_url" }
assert_equal "http://www.override.com/from_view", @response.body assert_equal "http://www.override.com/from_view", @response.body
assert_equal "http://www.override.com/from_view", @controller.send(:from_view_url) assert_equal "http://www.override.com/from_view", @controller.from_view_url
assert_equal "http://www.override.com/default_url_options/index", @controller.url_for(controller: "default_url_options") assert_equal "http://www.override.com/default_url_options/index", @controller.url_for(controller: "default_url_options")
end end
end end
...@@ -263,7 +263,7 @@ def test_default_url_options_override ...@@ -263,7 +263,7 @@ def test_default_url_options_override
get :from_view, params: { route: "from_view_url" } get :from_view, params: { route: "from_view_url" }
assert_equal "http://www.override.com/from_view?locale=en", @response.body assert_equal "http://www.override.com/from_view?locale=en", @response.body
assert_equal "http://www.override.com/from_view?locale=en", @controller.send(:from_view_url) assert_equal "http://www.override.com/from_view?locale=en", @controller.from_view_url
assert_equal "http://www.override.com/default_url_options/new?locale=en", @controller.url_for(controller: "default_url_options") assert_equal "http://www.override.com/default_url_options/new?locale=en", @controller.url_for(controller: "default_url_options")
end end
end end
...@@ -283,16 +283,16 @@ def test_default_url_options_are_used_in_non_positional_parameters ...@@ -283,16 +283,16 @@ def test_default_url_options_are_used_in_non_positional_parameters
get :from_view, params: { route: "description_path(1)" } get :from_view, params: { route: "description_path(1)" }
assert_equal "/en/descriptions/1", @response.body assert_equal "/en/descriptions/1", @response.body
assert_equal "/en/descriptions", @controller.send(:descriptions_path) assert_equal "/en/descriptions", @controller.descriptions_path
assert_equal "/pl/descriptions", @controller.send(:descriptions_path, "pl") assert_equal "/pl/descriptions", @controller.descriptions_path("pl")
assert_equal "/pl/descriptions", @controller.send(:descriptions_path, locale: "pl") assert_equal "/pl/descriptions", @controller.descriptions_path(locale: "pl")
assert_equal "/pl/descriptions.xml", @controller.send(:descriptions_path, "pl", "xml") assert_equal "/pl/descriptions.xml", @controller.descriptions_path("pl", "xml")
assert_equal "/en/descriptions.xml", @controller.send(:descriptions_path, format: "xml") assert_equal "/en/descriptions.xml", @controller.descriptions_path(format: "xml")
assert_equal "/en/descriptions/1", @controller.send(:description_path, 1) assert_equal "/en/descriptions/1", @controller.description_path(1)
assert_equal "/pl/descriptions/1", @controller.send(:description_path, "pl", 1) assert_equal "/pl/descriptions/1", @controller.description_path("pl", 1)
assert_equal "/pl/descriptions/1", @controller.send(:description_path, 1, locale: "pl") assert_equal "/pl/descriptions/1", @controller.description_path(1, locale: "pl")
assert_equal "/pl/descriptions/1.xml", @controller.send(:description_path, "pl", 1, "xml") assert_equal "/pl/descriptions/1.xml", @controller.description_path("pl", 1, "xml")
assert_equal "/en/descriptions/1.xml", @controller.send(:description_path, 1, format: "xml") assert_equal "/en/descriptions/1.xml", @controller.description_path(1, format: "xml")
end end
end end
end end
...@@ -331,7 +331,7 @@ def test_named_routes_with_path_without_doing_a_request_first ...@@ -331,7 +331,7 @@ def test_named_routes_with_path_without_doing_a_request_first
resources :things resources :things
end end
assert_equal "/things", @controller.send(:things_path) assert_equal "/things", @controller.things_path
end end
end end
end end
...@@ -418,7 +418,7 @@ def test_basic_named_route ...@@ -418,7 +418,7 @@ def test_basic_named_route
rs.draw do rs.draw do
root to: "content#list", as: "home" root to: "content#list", as: "home"
end end
assert_equal("http://test.host/", setup_for_named_route.send(:home_url)) assert_equal("http://test.host/", setup_for_named_route.home_url)
end end
def test_named_route_with_option def test_named_route_with_option
...@@ -427,7 +427,7 @@ def test_named_route_with_option ...@@ -427,7 +427,7 @@ def test_named_route_with_option
end end
assert_equal("http://test.host/page/new%20stuff", assert_equal("http://test.host/page/new%20stuff",
setup_for_named_route.send(:page_url, title: "new stuff")) setup_for_named_route.page_url(title: "new stuff"))
end end
def test_named_route_with_default def test_named_route_with_default
...@@ -436,7 +436,7 @@ def test_named_route_with_default ...@@ -436,7 +436,7 @@ def test_named_route_with_default
end end
assert_equal("http://test.host/page/AboutRails", assert_equal("http://test.host/page/AboutRails",
setup_for_named_route.send(:page_url, title: "AboutRails")) setup_for_named_route.page_url(title: "AboutRails"))
end end
def test_named_route_with_path_prefix def test_named_route_with_path_prefix
...@@ -446,8 +446,7 @@ def test_named_route_with_path_prefix ...@@ -446,8 +446,7 @@ def test_named_route_with_path_prefix
end end
end end
assert_equal("http://test.host/my/page", assert_equal("http://test.host/my/page", setup_for_named_route.page_url)
setup_for_named_route.send(:page_url))
end end
def test_named_route_with_blank_path_prefix def test_named_route_with_blank_path_prefix
...@@ -457,8 +456,7 @@ def test_named_route_with_blank_path_prefix ...@@ -457,8 +456,7 @@ def test_named_route_with_blank_path_prefix
end end
end end
assert_equal("http://test.host/page", assert_equal("http://test.host/page", setup_for_named_route.page_url)
setup_for_named_route.send(:page_url))
end end
def test_named_route_with_nested_controller def test_named_route_with_nested_controller
...@@ -466,8 +464,7 @@ def test_named_route_with_nested_controller ...@@ -466,8 +464,7 @@ def test_named_route_with_nested_controller
get "admin/user" => "admin/user#index", :as => "users" get "admin/user" => "admin/user#index", :as => "users"
end end
assert_equal("http://test.host/admin/user", assert_equal("http://test.host/admin/user", setup_for_named_route.users_url)
setup_for_named_route.send(:users_url))
end end
def test_optimised_named_route_with_host def test_optimised_named_route_with_host
...@@ -495,8 +492,8 @@ def test_named_route_root ...@@ -495,8 +492,8 @@ def test_named_route_root
root to: "hello#index" root to: "hello#index"
end end
routes = setup_for_named_route routes = setup_for_named_route
assert_equal("http://test.host/", routes.send(:root_url)) assert_equal("http://test.host/", routes.root_url)
assert_equal("/", routes.send(:root_path)) assert_equal("/", routes.root_path)
end end
def test_named_route_root_without_hash def test_named_route_root_without_hash
...@@ -504,8 +501,8 @@ def test_named_route_root_without_hash ...@@ -504,8 +501,8 @@ def test_named_route_root_without_hash
root "hello#index" root "hello#index"
end end
routes = setup_for_named_route routes = setup_for_named_route
assert_equal("http://test.host/", routes.send(:root_url)) assert_equal("http://test.host/", routes.root_url)
assert_equal("/", routes.send(:root_path)) assert_equal("/", routes.root_path)
end end
def test_named_route_root_with_hash def test_named_route_root_with_hash
...@@ -514,8 +511,8 @@ def test_named_route_root_with_hash ...@@ -514,8 +511,8 @@ def test_named_route_root_with_hash
end end
routes = setup_for_named_route routes = setup_for_named_route
assert_equal("http://test.host/", routes.send(:index_url)) assert_equal("http://test.host/", routes.index_url)
assert_equal("/", routes.send(:index_path)) assert_equal("/", routes.index_path)
end end
def test_root_without_path_raises_argument_error def test_root_without_path_raises_argument_error
...@@ -530,8 +527,8 @@ def test_named_route_root_with_trailing_slash ...@@ -530,8 +527,8 @@ def test_named_route_root_with_trailing_slash
end end
routes = setup_for_named_route(trailing_slash: true) routes = setup_for_named_route(trailing_slash: true)
assert_equal("http://test.host/", routes.send(:root_url)) assert_equal("http://test.host/", routes.root_url)
assert_equal("http://test.host/?foo=bar", routes.send(:root_url, foo: :bar)) assert_equal("http://test.host/?foo=bar", routes.root_url(foo: :bar))
end end
def test_named_route_with_regexps def test_named_route_with_regexps
...@@ -547,7 +544,7 @@ def test_named_route_with_regexps ...@@ -547,7 +544,7 @@ def test_named_route_with_regexps
routes = setup_for_named_route routes = setup_for_named_route
assert_equal "http://test.host/page/2005/6/10/hi", assert_equal "http://test.host/page/2005/6/10/hi",
routes.send(:article_url, title: "hi", day: 10, year: 2005, month: 6) routes.article_url(title: "hi", day: 10, year: 2005, month: 6)
end end
def test_changing_controller def test_changing_controller
...@@ -585,7 +582,7 @@ def test_paths_slashes_unescaped_with_ordered_parameters ...@@ -585,7 +582,7 @@ def test_paths_slashes_unescaped_with_ordered_parameters
end end
# No / to %2F in URI, only for query params. # No / to %2F in URI, only for query params.
assert_equal("/file/hello/world", setup_for_named_route.send(:path_path, ["hello", "world"])) assert_equal("/file/hello/world", setup_for_named_route.path_path(["hello", "world"]))
end end
def test_non_controllers_cannot_be_matched def test_non_controllers_cannot_be_matched
...@@ -715,7 +712,7 @@ def test_both_requirement_and_optional ...@@ -715,7 +712,7 @@ def test_both_requirement_and_optional
assert_equal "/test", url_for(rs, controller: "post", action: "show") assert_equal "/test", url_for(rs, controller: "post", action: "show")
assert_equal "/test", url_for(rs, controller: "post", action: "show", year: nil) assert_equal "/test", url_for(rs, controller: "post", action: "show", year: nil)
assert_equal("http://test.host/test", setup_for_named_route.send(:blog_url)) assert_equal("http://test.host/test", setup_for_named_route.blog_url)
end end
def test_set_to_nil_forgets def test_set_to_nil_forgets
...@@ -765,7 +762,7 @@ def test_named_root_url_generation_with_controller_and_action ...@@ -765,7 +762,7 @@ def test_named_root_url_generation_with_controller_and_action
assert_equal "/", url_for(rs, controller: "content", action: "index") assert_equal "/", url_for(rs, controller: "content", action: "index")
assert_equal "/", url_for(rs, controller: "content") assert_equal "/", url_for(rs, controller: "content")
assert_equal("http://test.host/", setup_for_named_route.send(:home_url)) assert_equal("http://test.host/", setup_for_named_route.home_url)
end end
def test_named_route_method def test_named_route_method
...@@ -877,7 +874,7 @@ def test_failed_constraints_raises_exception_with_violated_constraints ...@@ -877,7 +874,7 @@ def test_failed_constraints_raises_exception_with_violated_constraints
end end
assert_raise(ActionController::UrlGenerationError) do assert_raise(ActionController::UrlGenerationError) do
setup_for_named_route.send(:foo_with_requirement_url, "I am Against the constraints") setup_for_named_route.foo_with_requirement_url("I am Against the constraints")
end end
end end
...@@ -1042,78 +1039,78 @@ def setup_named_route_test ...@@ -1042,78 +1039,78 @@ def setup_named_route_test
def test_named_route_url_method def test_named_route_url_method
controller = setup_named_route_test controller = setup_named_route_test
assert_equal "http://test.host/people/5", controller.send(:show_url, id: 5) assert_equal "http://test.host/people/5", controller.show_url(id: 5)
assert_equal "/people/5", controller.send(:show_path, id: 5) assert_equal "/people/5", controller.show_path(id: 5)
assert_equal "http://test.host/people", controller.send(:index_url) assert_equal "http://test.host/people", controller.index_url
assert_equal "/people", controller.send(:index_path) assert_equal "/people", controller.index_path
assert_equal "http://test.host/admin/users", controller.send(:users_url) assert_equal "http://test.host/admin/users", controller.users_url
assert_equal "/admin/users", controller.send(:users_path) assert_equal "/admin/users", controller.users_path
end end
def test_named_route_url_method_with_anchor def test_named_route_url_method_with_anchor
controller = setup_named_route_test controller = setup_named_route_test
assert_equal "http://test.host/people/5#location", controller.send(:show_url, id: 5, anchor: "location") assert_equal "http://test.host/people/5#location", controller.show_url(id: 5, anchor: "location")
assert_equal "/people/5#location", controller.send(:show_path, id: 5, anchor: "location") assert_equal "/people/5#location", controller.show_path(id: 5, anchor: "location")
assert_equal "http://test.host/people#location", controller.send(:index_url, anchor: "location") assert_equal "http://test.host/people#location", controller.index_url(anchor: "location")
assert_equal "/people#location", controller.send(:index_path, anchor: "location") assert_equal "/people#location", controller.index_path(anchor: "location")
assert_equal "http://test.host/admin/users#location", controller.send(:users_url, anchor: "location") assert_equal "http://test.host/admin/users#location", controller.users_url(anchor: "location")
assert_equal "/admin/users#location", controller.send(:users_path, anchor: "location") assert_equal "/admin/users#location", controller.users_path(anchor: "location")
assert_equal "http://test.host/people/go/7/hello/joe/5#location", assert_equal "http://test.host/people/go/7/hello/joe/5#location",
controller.send(:multi_url, 7, "hello", 5, anchor: "location") controller.multi_url(7, "hello", 5, anchor: "location")
assert_equal "http://test.host/people/go/7/hello/joe/5?baz=bar#location", assert_equal "http://test.host/people/go/7/hello/joe/5?baz=bar#location",
controller.send(:multi_url, 7, "hello", 5, baz: "bar", anchor: "location") controller.multi_url(7, "hello", 5, baz: "bar", anchor: "location")
assert_equal "http://test.host/people?baz=bar#location", assert_equal "http://test.host/people?baz=bar#location",
controller.send(:index_url, baz: "bar", anchor: "location") controller.index_url(baz: "bar", anchor: "location")
assert_equal "http://test.host/people", controller.send(:index_url, anchor: nil) assert_equal "http://test.host/people", controller.index_url(anchor: nil)
assert_equal "http://test.host/people", controller.send(:index_url, anchor: false) assert_equal "http://test.host/people", controller.index_url(anchor: false)
end end
def test_named_route_url_method_with_port def test_named_route_url_method_with_port
controller = setup_named_route_test controller = setup_named_route_test
assert_equal "http://test.host:8080/people/5", controller.send(:show_url, 5, port: 8080) assert_equal "http://test.host:8080/people/5", controller.show_url(5, port: 8080)
end end
def test_named_route_url_method_with_host def test_named_route_url_method_with_host
controller = setup_named_route_test controller = setup_named_route_test
assert_equal "http://some.example.com/people/5", controller.send(:show_url, 5, host: "some.example.com") assert_equal "http://some.example.com/people/5", controller.show_url(5, host: "some.example.com")
end end
def test_named_route_url_method_with_protocol def test_named_route_url_method_with_protocol
controller = setup_named_route_test controller = setup_named_route_test
assert_equal "https://test.host/people/5", controller.send(:show_url, 5, protocol: "https") assert_equal "https://test.host/people/5", controller.show_url(5, protocol: "https")
end end
def test_named_route_url_method_with_ordered_parameters def test_named_route_url_method_with_ordered_parameters
controller = setup_named_route_test controller = setup_named_route_test
assert_equal "http://test.host/people/go/7/hello/joe/5", assert_equal "http://test.host/people/go/7/hello/joe/5",
controller.send(:multi_url, 7, "hello", 5) controller.multi_url(7, "hello", 5)
end end
def test_named_route_url_method_with_ordered_parameters_and_hash def test_named_route_url_method_with_ordered_parameters_and_hash
controller = setup_named_route_test controller = setup_named_route_test
assert_equal "http://test.host/people/go/7/hello/joe/5?baz=bar", assert_equal "http://test.host/people/go/7/hello/joe/5?baz=bar",
controller.send(:multi_url, 7, "hello", 5, baz: "bar") controller.multi_url(7, "hello", 5, baz: "bar")
end end
def test_named_route_url_method_with_ordered_parameters_and_empty_hash def test_named_route_url_method_with_ordered_parameters_and_empty_hash
controller = setup_named_route_test controller = setup_named_route_test
assert_equal "http://test.host/people/go/7/hello/joe/5", assert_equal "http://test.host/people/go/7/hello/joe/5",
controller.send(:multi_url, 7, "hello", 5, {}) controller.multi_url(7, "hello", 5, {})
end end
def test_named_route_url_method_with_no_positional_arguments def test_named_route_url_method_with_no_positional_arguments
controller = setup_named_route_test controller = setup_named_route_test
assert_equal "http://test.host/people?baz=bar", assert_equal "http://test.host/people?baz=bar",
controller.send(:index_url, baz: "bar") controller.index_url(baz: "bar")
end end
def test_draw_default_route def test_draw_default_route
......
...@@ -290,11 +290,11 @@ def test_named_routes ...@@ -290,11 +290,11 @@ def test_named_routes
controller = kls.new controller = kls.new
assert_respond_to controller, :home_url assert_respond_to controller, :home_url
assert_equal "http://www.basecamphq.com/home/sweet/home/again", assert_equal "http://www.basecamphq.com/home/sweet/home/again",
controller.send(:home_url, host: "www.basecamphq.com", user: "again") controller.home_url(host: "www.basecamphq.com", user: "again")
assert_equal("/home/sweet/home/alabama", controller.send(:home_path, user: "alabama", host: "unused")) assert_equal("/home/sweet/home/alabama", controller.home_path(user: "alabama", host: "unused"))
assert_equal("http://www.basecamphq.com/home/sweet/home/alabama", controller.send(:home_url, user: "alabama", host: "www.basecamphq.com")) assert_equal("http://www.basecamphq.com/home/sweet/home/alabama", controller.home_url(user: "alabama", host: "www.basecamphq.com"))
assert_equal("http://www.basecamphq.com/this/is/verbose", controller.send(:no_args_url, host: "www.basecamphq.com")) assert_equal("http://www.basecamphq.com/this/is/verbose", controller.no_args_url(host: "www.basecamphq.com"))
end end
end end
...@@ -308,7 +308,7 @@ def test_relative_url_root_is_respected_for_named_routes ...@@ -308,7 +308,7 @@ def test_relative_url_root_is_respected_for_named_routes
controller = kls.new controller = kls.new
assert_equal "http://www.basecamphq.com/subdir/home/sweet/home/again", assert_equal "http://www.basecamphq.com/subdir/home/sweet/home/again",
controller.send(:home_url, host: "www.basecamphq.com", user: "again", script_name: "/subdir") controller.home_url(host: "www.basecamphq.com", user: "again", script_name: "/subdir")
end end
end end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册