aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/journey/router_test.rb
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2016-08-06 18:54:50 +0200
committerXavier Noria <fxn@hashref.com>2016-08-06 18:54:50 +0200
commit35b3de8021e68649cac963bd82a74cc75d1f60f0 (patch)
treed37f9096be6ee54a13d3c04cc8e1c5a9ba0d99ec /actionpack/test/journey/router_test.rb
parent628e51ff109334223094e30ad1365188bbd7f9c6 (diff)
downloadrails-35b3de8021e68649cac963bd82a74cc75d1f60f0.tar.gz
rails-35b3de8021e68649cac963bd82a74cc75d1f60f0.tar.bz2
rails-35b3de8021e68649cac963bd82a74cc75d1f60f0.zip
applies new string literal convention in actionpack/test
The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
Diffstat (limited to 'actionpack/test/journey/router_test.rb')
-rw-r--r--actionpack/test/journey/router_test.rb170
1 files changed, 85 insertions, 85 deletions
diff --git a/actionpack/test/journey/router_test.rb b/actionpack/test/journey/router_test.rb
index 75caf56d32..fb595e8bea 100644
--- a/actionpack/test/journey/router_test.rb
+++ b/actionpack/test/journey/router_test.rb
@@ -1,4 +1,4 @@
-require 'abstract_unit'
+require "abstract_unit"
module ActionDispatch
module Journey
@@ -15,9 +15,9 @@ module ActionDispatch
end
def test_dashes
- get '/foo-bar-baz', to: 'foo#bar'
+ get "/foo-bar-baz", to: "foo#bar"
- env = rails_env 'PATH_INFO' => '/foo-bar-baz'
+ env = rails_env "PATH_INFO" => "/foo-bar-baz"
called = false
router.recognize(env) do |r, params|
called = true
@@ -26,10 +26,10 @@ module ActionDispatch
end
def test_unicode
- get '/ほげ', to: 'foo#bar'
+ get "/ほげ", to: "foo#bar"
#match the escaped version of /ほげ
- env = rails_env 'PATH_INFO' => '/%E3%81%BB%E3%81%92'
+ env = rails_env "PATH_INFO" => "/%E3%81%BB%E3%81%92"
called = false
router.recognize(env) do |r, params|
called = true
@@ -41,7 +41,7 @@ module ActionDispatch
get "/whois/:domain", :domain => /\w+\.[\w\.]+/, to: "foo#bar"
get "/whois/:id(.:format)", to: "foo#baz"
- env = rails_env 'PATH_INFO' => '/whois/example.com'
+ env = rails_env "PATH_INFO" => "/whois/example.com"
list = []
router.recognize(env) do |r, params|
@@ -51,39 +51,39 @@ module ActionDispatch
r = list.first
- assert_equal '/whois/:domain(.:format)', r.path.spec.to_s
+ assert_equal "/whois/:domain(.:format)", r.path.spec.to_s
end
def test_required_parts_verified_are_anchored
get "/foo/:id", :id => /\d/, anchor: false, to: "foo#bar"
assert_raises(ActionController::UrlGenerationError) do
- @formatter.generate(nil, { :controller => "foo", :action => "bar", :id => '10' }, { })
+ @formatter.generate(nil, { :controller => "foo", :action => "bar", :id => "10" }, { })
end
end
def test_required_parts_are_verified_when_building
get "/foo/:id", :id => /\d+/, anchor: false, to: "foo#bar"
- path, _ = @formatter.generate(nil, { :controller => "foo", :action => "bar", :id => '10' }, { })
- assert_equal '/foo/10', path
+ path, _ = @formatter.generate(nil, { :controller => "foo", :action => "bar", :id => "10" }, { })
+ assert_equal "/foo/10", path
assert_raises(ActionController::UrlGenerationError) do
- @formatter.generate(nil, { :id => 'aa' }, { })
+ @formatter.generate(nil, { :id => "aa" }, { })
end
end
def test_only_required_parts_are_verified
get "/foo(/:id)", :id => /\d/, :to => "foo#bar"
- path, _ = @formatter.generate(nil, { :controller => "foo", :action => "bar", :id => '10' }, { })
- assert_equal '/foo/10', path
+ path, _ = @formatter.generate(nil, { :controller => "foo", :action => "bar", :id => "10" }, { })
+ assert_equal "/foo/10", path
path, _ = @formatter.generate(nil, { :controller => "foo", :action => "bar" }, { })
- assert_equal '/foo', path
+ assert_equal "/foo", path
- path, _ = @formatter.generate(nil, { :controller => "foo", :action => "bar", :id => 'aa' }, { })
- assert_equal '/foo/aa', path
+ path, _ = @formatter.generate(nil, { :controller => "foo", :action => "bar", :id => "aa" }, { })
+ assert_equal "/foo/aa", path
end
def test_knows_what_parts_are_missing_from_named_route
@@ -109,31 +109,31 @@ module ActionDispatch
def test_X_Cascade
get "/messages(.:format)", to: "foo#bar"
- resp = router.serve(rails_env({ 'REQUEST_METHOD' => 'GET', 'PATH_INFO' => '/lol' }))
- assert_equal ['Not Found'], resp.last
- assert_equal 'pass', resp[1]['X-Cascade']
+ resp = router.serve(rails_env({ "REQUEST_METHOD" => "GET", "PATH_INFO" => "/lol" }))
+ assert_equal ["Not Found"], resp.last
+ assert_equal "pass", resp[1]["X-Cascade"]
assert_equal 404, resp.first
end
def test_clear_trailing_slash_from_script_name_on_root_unanchored_routes
- app = lambda { |env| [200, {}, ['success!']] }
- get '/weblog', :to => app
+ app = lambda { |env| [200, {}, ["success!"]] }
+ get "/weblog", :to => app
- env = rack_env('SCRIPT_NAME' => '', 'PATH_INFO' => '/weblog')
+ env = rack_env("SCRIPT_NAME" => "", "PATH_INFO" => "/weblog")
resp = route_set.call env
- assert_equal ['success!'], resp.last
- assert_equal '', env['SCRIPT_NAME']
+ assert_equal ["success!"], resp.last
+ assert_equal "", env["SCRIPT_NAME"]
end
def test_defaults_merge_correctly
- get '/foo(/:id)', to: "foo#bar", id: nil
+ get "/foo(/:id)", to: "foo#bar", id: nil
- env = rails_env 'PATH_INFO' => '/foo/10'
+ env = rails_env "PATH_INFO" => "/foo/10"
router.recognize(env) do |r, params|
- assert_equal({:id => '10', :controller => "foo", :action => "bar"}, params)
+ assert_equal({:id => "10", :controller => "foo", :action => "bar"}, params)
end
- env = rails_env 'PATH_INFO' => '/foo'
+ env = rails_env "PATH_INFO" => "/foo"
router.recognize(env) do |r, params|
assert_equal({:id => nil, :controller => "foo", :action => "bar"}, params)
end
@@ -142,25 +142,25 @@ module ActionDispatch
def test_recognize_with_unbound_regexp
get "/foo", anchor: false, to: "foo#bar"
- env = rails_env 'PATH_INFO' => '/foo/bar'
+ env = rails_env "PATH_INFO" => "/foo/bar"
router.recognize(env) { |*_| }
- assert_equal '/foo', env.env['SCRIPT_NAME']
- assert_equal '/bar', env.env['PATH_INFO']
+ assert_equal "/foo", env.env["SCRIPT_NAME"]
+ assert_equal "/bar", env.env["PATH_INFO"]
end
def test_bound_regexp_keeps_path_info
get "/foo", to: "foo#bar"
- env = rails_env 'PATH_INFO' => '/foo'
+ env = rails_env "PATH_INFO" => "/foo"
- before = env.env['SCRIPT_NAME']
+ before = env.env["SCRIPT_NAME"]
router.recognize(env) { |*_| }
- assert_equal before, env.env['SCRIPT_NAME']
- assert_equal '/foo', env.env['PATH_INFO']
+ assert_equal before, env.env["SCRIPT_NAME"]
+ assert_equal "/foo", env.env["PATH_INFO"]
end
def test_path_not_found
@@ -172,7 +172,7 @@ module ActionDispatch
].each do |path|
get path, to: "foo#bar"
end
- env = rails_env 'PATH_INFO' => '/messages/unknown/path'
+ env = rails_env "PATH_INFO" => "/messages/unknown/path"
yielded = false
router.recognize(env) do |*whatever|
@@ -184,22 +184,22 @@ module ActionDispatch
def test_required_part_in_recall
get "/messages/:a/:b", to: "foo#bar"
- path, _ = @formatter.generate(nil, { :controller => "foo", :action => "bar", :a => 'a' }, { :b => 'b' })
+ path, _ = @formatter.generate(nil, { :controller => "foo", :action => "bar", :a => "a" }, { :b => "b" })
assert_equal "/messages/a/b", path
end
def test_splat_in_recall
get "/*path", to: "foo#bar"
- path, _ = @formatter.generate(nil, { :controller => "foo", :action => "bar" }, { :path => 'b' })
+ path, _ = @formatter.generate(nil, { :controller => "foo", :action => "bar" }, { :path => "b" })
assert_equal "/b", path
end
def test_recall_should_be_used_when_scoring
- get "/messages/:action(/:id(.:format))", to: 'foo#bar'
- get "/messages/:id(.:format)", to: 'bar#baz'
+ get "/messages/:action(/:id(.:format))", to: "foo#bar"
+ get "/messages/:id(.:format)", to: "bar#baz"
- path, _ = @formatter.generate(nil, { :controller => "foo", :id => 10 }, { :action => 'index' })
+ path, _ = @formatter.generate(nil, { :controller => "foo", :id => 10 }, { :action => "index" })
assert_equal "/messages/index/10", path
end
@@ -207,10 +207,10 @@ module ActionDispatch
get "/:controller(/:action(.:format))", to: "tasks#lol"
params = { :controller => "tasks", :format => nil }
- extras = { :action => 'lol' }
+ extras = { :action => "lol" }
path, _ = @formatter.generate(nil, params, extras)
- assert_equal '/tasks', path
+ assert_equal "/tasks", path
end
def test_generate_slash
@@ -219,11 +219,11 @@ module ActionDispatch
get "/", Hash[params]
path, _ = @formatter.generate(nil, Hash[params], {})
- assert_equal '/', path
+ assert_equal "/", path
end
def test_generate_calls_param_proc
- get '/:controller(/:action)', to: "foo#bar"
+ get "/:controller(/:action)", to: "foo#bar"
parameterized = []
params = [ [:controller, "tasks"],
@@ -239,36 +239,36 @@ module ActionDispatch
end
def test_generate_id
- get '/:controller(/:action)', to: 'foo#bar'
+ get "/:controller(/:action)", to: "foo#bar"
path, params = @formatter.generate(
nil, {:id=>1, :controller=>"tasks", :action=>"show"}, {})
- assert_equal '/tasks/show', path
+ assert_equal "/tasks/show", path
assert_equal({:id => 1}, params)
end
def test_generate_escapes
- get '/:controller(/:action)', to: "foo#bar"
+ get "/:controller(/:action)", to: "foo#bar"
path, _ = @formatter.generate(nil,
{ :controller => "tasks",
:action => "a/b c+d",
}, {})
- assert_equal '/tasks/a%2Fb%20c+d', path
+ assert_equal "/tasks/a%2Fb%20c+d", path
end
def test_generate_escapes_with_namespaced_controller
- get '/:controller(/:action)', to: "foo#bar"
+ get "/:controller(/:action)", to: "foo#bar"
path, _ = @formatter.generate(
nil, { :controller => "admin/tasks",
:action => "a/b c+d",
}, {})
- assert_equal '/admin/tasks/a%2Fb%20c+d', path
+ assert_equal "/admin/tasks/a%2Fb%20c+d", path
end
def test_generate_extra_params
- get '/:controller(/:action)', to: "foo#bar"
+ get "/:controller(/:action)", to: "foo#bar"
path, params = @formatter.generate(
nil, { :id => 1,
@@ -276,12 +276,12 @@ module ActionDispatch
:action => "show",
:relative_url_root => nil
}, {})
- assert_equal '/tasks/show', path
+ assert_equal "/tasks/show", path
assert_equal({:id => 1, :relative_url_root => nil}, params)
end
def test_generate_missing_keys_no_matches_different_format_keys
- get '/:controller/:action/:name', to: "foo#bar"
+ get "/:controller/:action/:name", to: "foo#bar"
primarty_parameters = {
:id => 1,
:controller => "tasks",
@@ -289,9 +289,9 @@ module ActionDispatch
:relative_url_root => nil
}
redirection_parameters = {
- 'action'=>'show',
+ "action"=>"show",
}
- missing_key = 'name'
+ missing_key = "name"
missing_parameters ={
missing_key => "task_1"
}
@@ -307,37 +307,37 @@ module ActionDispatch
end
def test_generate_uses_recall_if_needed
- get '/:controller(/:action(/:id))', to: "foo#bar"
+ get "/:controller(/:action(/:id))", to: "foo#bar"
path, params = @formatter.generate(
nil,
{:controller =>"tasks", :id => 10},
{:action =>"index"})
- assert_equal '/tasks/index/10', path
+ assert_equal "/tasks/index/10", path
assert_equal({}, params)
end
def test_generate_with_name
- get '/:controller(/:action)', to: 'foo#bar', as: 'tasks'
+ get "/:controller(/:action)", to: "foo#bar", as: "tasks"
path, params = @formatter.generate(
"tasks",
{:controller=>"tasks"},
{:controller=>"tasks", :action=>"index"})
- assert_equal '/tasks', path
+ assert_equal "/tasks", path
assert_equal({}, params)
end
{
- '/content' => { :controller => 'content' },
- '/content/list' => { :controller => 'content', :action => 'list' },
- '/content/show/10' => { :controller => 'content', :action => 'show', :id => "10" },
+ "/content" => { :controller => "content" },
+ "/content/list" => { :controller => "content", :action => "list" },
+ "/content/show/10" => { :controller => "content", :action => "show", :id => "10" },
}.each do |request_path, expected|
define_method("test_recognize_#{expected.keys.map(&:to_s).join('_')}") do
- get "/:controller(/:action(/:id))", to: 'foo#bar'
+ get "/:controller(/:action(/:id))", to: "foo#bar"
route = @routes.first
- env = rails_env 'PATH_INFO' => request_path
+ env = rails_env "PATH_INFO" => request_path
called = false
router.recognize(env) do |r, params|
@@ -351,13 +351,13 @@ module ActionDispatch
end
{
- :segment => ['/a%2Fb%20c+d/splat', { :segment => 'a/b c+d', :splat => 'splat' }],
- :splat => ['/segment/a/b%20c+d', { :segment => 'segment', :splat => 'a/b c+d' }]
+ :segment => ["/a%2Fb%20c+d/splat", { :segment => "a/b c+d", :splat => "splat" }],
+ :splat => ["/segment/a/b%20c+d", { :segment => "segment", :splat => "a/b c+d" }]
}.each do |name, (request_path, expected)|
define_method("test_recognize_#{name}") do
- get '/:segment/*splat', to: 'foo#bar'
+ get "/:segment/*splat", to: "foo#bar"
- env = rails_env 'PATH_INFO' => request_path
+ env = rails_env "PATH_INFO" => request_path
called = false
route = @routes.first
@@ -375,12 +375,12 @@ module ActionDispatch
get "/:controller(/:action(/:id))", { :controller => /.+?/ }
route = @routes.first
- env = rails_env 'PATH_INFO' => '/admin/users/show/10'
+ env = rails_env "PATH_INFO" => "/admin/users/show/10"
called = false
expected = {
- :controller => 'admin/users',
- :action => 'show',
- :id => '10'
+ :controller => "admin/users",
+ :action => "show",
+ :id => "10"
}
router.recognize(env) do |r, params|
@@ -395,8 +395,8 @@ module ActionDispatch
get "/books(/:action(.:format))", controller: "books"
route = @routes.first
- env = rails_env 'PATH_INFO' => '/books/list.rss'
- expected = { :controller => 'books', :action => 'list', :format => 'rss' }
+ env = rails_env "PATH_INFO" => "/books/list.rss"
+ expected = { :controller => "books", :action => "list", :format => "rss" }
called = false
router.recognize(env) do |r, params|
assert_equal route, r
@@ -408,11 +408,11 @@ module ActionDispatch
end
def test_recognize_head_route
- match "/books(/:action(.:format))", via: 'head', to: 'foo#bar'
+ match "/books(/:action(.:format))", via: "head", to: "foo#bar"
env = rails_env(
- 'PATH_INFO' => '/books/list.rss',
- 'REQUEST_METHOD' => 'HEAD'
+ "PATH_INFO" => "/books/list.rss",
+ "REQUEST_METHOD" => "HEAD"
)
called = false
@@ -424,9 +424,9 @@ module ActionDispatch
end
def test_recognize_head_request_as_get_route
- get "/books(/:action(.:format))", to: 'foo#bar'
+ get "/books(/:action(.:format))", to: "foo#bar"
- env = rails_env 'PATH_INFO' => '/books/list.rss',
+ env = rails_env "PATH_INFO" => "/books/list.rss",
"REQUEST_METHOD" => "HEAD"
called = false
@@ -440,7 +440,7 @@ module ActionDispatch
def test_recognize_cares_about_get_verbs
match "/books(/:action(.:format))", to: "foo#bar", via: :get
- env = rails_env 'PATH_INFO' => '/books/list.rss',
+ env = rails_env "PATH_INFO" => "/books/list.rss",
"REQUEST_METHOD" => "POST"
called = false
@@ -454,7 +454,7 @@ module ActionDispatch
def test_recognize_cares_about_post_verbs
match "/books(/:action(.:format))", to: "foo#bar", via: :post
- env = rails_env 'PATH_INFO' => '/books/list.rss',
+ env = rails_env "PATH_INFO" => "/books/list.rss",
"REQUEST_METHOD" => "POST"
called = false
@@ -469,7 +469,7 @@ module ActionDispatch
match "/books(/:action(.:format))", to: "foo#bar", via: [:post, :get]
%w( POST GET ).each do |verb|
- env = rails_env 'PATH_INFO' => '/books/list.rss',
+ env = rails_env "PATH_INFO" => "/books/list.rss",
"REQUEST_METHOD" => verb
called = false
@@ -480,8 +480,8 @@ module ActionDispatch
assert called
end
- env = rails_env 'PATH_INFO' => '/books/list.rss',
- "REQUEST_METHOD" => 'PUT'
+ env = rails_env "PATH_INFO" => "/books/list.rss",
+ "REQUEST_METHOD" => "PUT"
called = false
router.recognize(env) do |r, params|