From e96da0a7beb483ed5e8a8096ff67b09ecc5ca7a1 Mon Sep 17 00:00:00 2001 From: Andrew White Date: Mon, 20 Feb 2017 13:54:06 +0000 Subject: Only accept symbols and strings for Mapper#direct --- .../test/dispatch/routing/custom_url_helpers_test.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'actionpack/test/dispatch/routing') diff --git a/actionpack/test/dispatch/routing/custom_url_helpers_test.rb b/actionpack/test/dispatch/routing/custom_url_helpers_test.rb index a55ee8e9b0..bf4b323cf0 100644 --- a/actionpack/test/dispatch/routing/custom_url_helpers_test.rb +++ b/actionpack/test/dispatch/routing/custom_url_helpers_test.rb @@ -31,6 +31,7 @@ class TestCustomUrlHelpers < ActionDispatch::IntegrationTest end direct(:website) { "http://www.rubyonrails.org" } + direct("string") { "http://www.rubyonrails.org" } direct(:linkable) { |linkable| [:"#{linkable.linkable_type}", { id: linkable.id }] } direct(:params) { |params| params } direct(:symbol) { :basket } @@ -61,6 +62,9 @@ class TestCustomUrlHelpers < ActionDispatch::IntegrationTest assert_equal "http://www.rubyonrails.org", website_path assert_equal "http://www.rubyonrails.org", Routes.url_helpers.website_path + assert_equal "http://www.rubyonrails.org", string_path + assert_equal "http://www.rubyonrails.org", Routes.url_helpers.string_path + assert_equal "/categories/1", linkable_path(@category) assert_equal "/categories/1", Routes.url_helpers.linkable_path(@category) assert_equal "/collections/2", linkable_path(@collection) @@ -92,6 +96,9 @@ class TestCustomUrlHelpers < ActionDispatch::IntegrationTest assert_equal "http://www.rubyonrails.org", website_url assert_equal "http://www.rubyonrails.org", Routes.url_helpers.website_url + assert_equal "http://www.rubyonrails.org", string_url + assert_equal "http://www.rubyonrails.org", Routes.url_helpers.string_url + assert_equal "http://www.example.com/categories/1", linkable_url(@category) assert_equal "http://www.example.com/categories/1", Routes.url_helpers.linkable_url(@category) assert_equal "http://www.example.com/collections/2", linkable_url(@collection) @@ -118,4 +125,14 @@ class TestCustomUrlHelpers < ActionDispatch::IntegrationTest assert_equal "http://www.example.com/products?size=20", defaults_url(size: 20) assert_equal "http://www.example.com/products?size=20", Routes.url_helpers.defaults_url(size: 20) end + + def test_raises_argument_error + routes = ActionDispatch::Routing::RouteSet.new + + assert_raises ArgumentError do + routes.draw do + direct(1) { "http://www.rubyonrails.org" } + end + end + end end -- cgit v1.2.3