aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/journey
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/test/journey')
-rw-r--r--actionpack/test/journey/path/pattern_test.rb22
-rw-r--r--actionpack/test/journey/route_test.rb36
-rw-r--r--actionpack/test/journey/router_test.rb100
3 files changed, 79 insertions, 79 deletions
diff --git a/actionpack/test/journey/path/pattern_test.rb b/actionpack/test/journey/path/pattern_test.rb
index 7b013cbbc6..224ab689fc 100644
--- a/actionpack/test/journey/path/pattern_test.rb
+++ b/actionpack/test/journey/path/pattern_test.rb
@@ -23,7 +23,7 @@ module ActionDispatch
define_method(:"test_to_regexp_#{path}") do
path = Pattern.build(
path,
- { :controller => /.+/ },
+ { controller: /.+/ },
SEPARATORS,
true
)
@@ -47,7 +47,7 @@ module ActionDispatch
define_method(:"test_to_non_anchored_regexp_#{path}") do
path = Pattern.build(
path,
- { :controller => /.+/ },
+ { controller: /.+/ },
SEPARATORS,
false
)
@@ -70,7 +70,7 @@ module ActionDispatch
define_method(:"test_names_#{path}") do
path = Pattern.build(
path,
- { :controller => /.+/ },
+ { controller: /.+/ },
SEPARATORS,
true
)
@@ -81,7 +81,7 @@ module ActionDispatch
def test_to_regexp_with_extended_group
path = Pattern.build(
"/page/:name",
- { :name => /
+ { name: /
#ROFL
(tender|love
#MAO
@@ -108,7 +108,7 @@ module ActionDispatch
def test_to_regexp_match_non_optional
path = Pattern.build(
"/:name",
- { :name => /\d+/ },
+ { name: /\d+/ },
SEPARATORS,
true
)
@@ -119,7 +119,7 @@ module ActionDispatch
def test_to_regexp_with_group
path = Pattern.build(
"/page/:name",
- { :name => /(tender|love)/ },
+ { name: /(tender|love)/ },
SEPARATORS,
true
)
@@ -129,7 +129,7 @@ module ActionDispatch
end
def test_ast_sets_regular_expressions
- requirements = { :name => /(tender|love)/, :value => /./ }
+ requirements = { name: /(tender|love)/, value: /./ }
path = Pattern.build(
"/page/:name/:value",
requirements,
@@ -147,7 +147,7 @@ module ActionDispatch
def test_match_data_with_group
path = Pattern.build(
"/page/:name",
- { :name => /(tender|love)/ },
+ { name: /(tender|love)/ },
SEPARATORS,
true
)
@@ -159,7 +159,7 @@ module ActionDispatch
def test_match_data_with_multi_group
path = Pattern.build(
"/page/:name/:id",
- { :name => /t(((ender|love)))()/ },
+ { name: /t(((ender|love)))()/ },
SEPARATORS,
true
)
@@ -174,7 +174,7 @@ module ActionDispatch
z = /\d+/
path = Pattern.build(
"/page/*foo",
- { :foo => z },
+ { foo: z },
SEPARATORS,
true
)
@@ -184,7 +184,7 @@ module ActionDispatch
def test_insensitive_regexp_with_group
path = Pattern.build(
"/page/:name/aaron",
- { :name => /(tender|love)/i },
+ { name: /(tender|love)/i },
SEPARATORS,
true
)
diff --git a/actionpack/test/journey/route_test.rb b/actionpack/test/journey/route_test.rb
index 7e03259827..5364f9de81 100644
--- a/actionpack/test/journey/route_test.rb
+++ b/actionpack/test/journey/route_test.rb
@@ -34,63 +34,63 @@ module ActionDispatch
def test_ip_address
path = Path::Pattern.from_string "/messages/:id(.:format)"
- route = Route.build("name", nil, path, {:ip => "192.168.1.1"}, [],
- { :controller => "foo", :action => "bar" })
+ route = Route.build("name", nil, path, {ip: "192.168.1.1"}, [],
+ { controller: "foo", action: "bar" })
assert_equal "192.168.1.1", route.ip
end
def test_default_ip
path = Path::Pattern.from_string "/messages/:id(.:format)"
route = Route.build("name", nil, path, {}, [],
- { :controller => "foo", :action => "bar" })
+ { controller: "foo", action: "bar" })
assert_equal(//, route.ip)
end
def test_format_with_star
path = Path::Pattern.from_string "/:controller/*extra"
route = Route.build("name", nil, path, {}, [],
- { :controller => "foo", :action => "bar" })
+ { controller: "foo", action: "bar" })
assert_equal "/foo/himom", route.format({
- :controller => "foo",
- :extra => "himom",
+ controller: "foo",
+ extra: "himom",
})
end
def test_connects_all_match
path = Path::Pattern.from_string "/:controller(/:action(/:id(.:format)))"
- route = Route.build("name", nil, path, {:action => "bar"}, [], { :controller => "foo" })
+ route = Route.build("name", nil, path, {action: "bar"}, [], { controller: "foo" })
assert_equal "/foo/bar/10", route.format({
- :controller => "foo",
- :action => "bar",
- :id => 10
+ controller: "foo",
+ action: "bar",
+ id: 10
})
end
def test_extras_are_not_included_if_optional
path = Path::Pattern.from_string "/page/:id(/:action)"
- route = Route.build("name", nil, path, { }, [], { :action => "show" })
+ route = Route.build("name", nil, path, { }, [], { action: "show" })
- assert_equal "/page/10", route.format({ :id => 10 })
+ assert_equal "/page/10", route.format({ id: 10 })
end
def test_extras_are_not_included_if_optional_with_parameter
path = Path::Pattern.from_string "(/sections/:section)/pages/:id"
- route = Route.build("name", nil, path, { }, [], { :action => "show" })
+ route = Route.build("name", nil, path, { }, [], { action: "show" })
- assert_equal "/pages/10", route.format({:id => 10})
+ assert_equal "/pages/10", route.format({id: 10})
end
def test_extras_are_not_included_if_optional_parameter_is_nil
path = Path::Pattern.from_string "(/sections/:section)/pages/:id"
- route = Route.build("name", nil, path, { }, [], { :action => "show" })
+ route = Route.build("name", nil, path, { }, [], { action: "show" })
- assert_equal "/pages/10", route.format({:id => 10, :section => nil})
+ assert_equal "/pages/10", route.format({id: 10, section: nil})
end
def test_score
constraints = {}
- defaults = {:controller=>"pages", :action=>"show"}
+ defaults = {controller: "pages", action: "show"}
path = Path::Pattern.from_string "/page/:id(/:action)(.:format)"
specific = Route.build "name", nil, path, constraints, [:controller, :action], defaults
@@ -98,7 +98,7 @@ module ActionDispatch
path = Path::Pattern.from_string "/:controller(/:action(/:id))(.:format)"
generic = Route.build "name", nil, path, constraints, [], {}
- knowledge = {:id=>20, :controller=>"pages", :action=>"show"}
+ knowledge = {id: 20, controller: "pages", action: "show"}
routes = [specific, generic]
diff --git a/actionpack/test/journey/router_test.rb b/actionpack/test/journey/router_test.rb
index fb595e8bea..97d3bc9845 100644
--- a/actionpack/test/journey/router_test.rb
+++ b/actionpack/test/journey/router_test.rb
@@ -38,7 +38,7 @@ module ActionDispatch
end
def test_regexp_first_precedence
- get "/whois/:domain", :domain => /\w+\.[\w\.]+/, to: "foo#bar"
+ get "/whois/:domain", domain: /\w+\.[\w\.]+/, to: "foo#bar"
get "/whois/:id(.:format)", to: "foo#baz"
env = rails_env "PATH_INFO" => "/whois/example.com"
@@ -55,40 +55,40 @@ module ActionDispatch
end
def test_required_parts_verified_are_anchored
- get "/foo/:id", :id => /\d/, anchor: false, to: "foo#bar"
+ 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"
+ get "/foo/:id", id: /\d+/, anchor: false, to: "foo#bar"
- path, _ = @formatter.generate(nil, { :controller => "foo", :action => "bar", :id => "10" }, { })
+ 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"
+ get "/foo(/:id)", id: /\d/, to: "foo#bar"
- path, _ = @formatter.generate(nil, { :controller => "foo", :action => "bar", :id => "10" }, { })
+ path, _ = @formatter.generate(nil, { controller: "foo", action: "bar", id: "10" }, { })
assert_equal "/foo/10", path
- path, _ = @formatter.generate(nil, { :controller => "foo", :action => "bar" }, { })
+ path, _ = @formatter.generate(nil, { controller: "foo", action: "bar" }, { })
assert_equal "/foo", path
- path, _ = @formatter.generate(nil, { :controller => "foo", :action => "bar", :id => "aa" }, { })
+ 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
route_name = "gorby_thunderhorse"
- get "/foo/:id", :as => route_name, :id => /\d+/, :to => "foo#bar"
+ get "/foo/:id", as: route_name, id: /\d+/, to: "foo#bar"
error = assert_raises(ActionController::UrlGenerationError) do
@formatter.generate(route_name, { }, { })
@@ -117,7 +117,7 @@ module ActionDispatch
def test_clear_trailing_slash_from_script_name_on_root_unanchored_routes
app = lambda { |env| [200, {}, ["success!"]] }
- get "/weblog", :to => app
+ get "/weblog", to: app
env = rack_env("SCRIPT_NAME" => "", "PATH_INFO" => "/weblog")
resp = route_set.call env
@@ -130,12 +130,12 @@ module ActionDispatch
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"
router.recognize(env) do |r, params|
- assert_equal({:id => nil, :controller => "foo", :action => "bar"}, params)
+ assert_equal({id: nil, controller: "foo", action: "bar"}, params)
end
end
@@ -184,14 +184,14 @@ 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
@@ -199,15 +199,15 @@ module ActionDispatch
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
def test_nil_path_parts_are_ignored
get "/:controller(/:action(.:format))", to: "tasks#lol"
- params = { :controller => "tasks", :format => nil }
- extras = { :action => "lol" }
+ params = { controller: "tasks", format: nil }
+ extras = { action: "lol" }
path, _ = @formatter.generate(nil, params, extras)
assert_equal "/tasks", path
@@ -242,17 +242,17 @@ module ActionDispatch
get "/:controller(/:action)", to: "foo#bar"
path, params = @formatter.generate(
- nil, {:id=>1, :controller=>"tasks", :action=>"show"}, {})
+ nil, {id: 1, controller: "tasks", action: "show"}, {})
assert_equal "/tasks/show", path
- assert_equal({:id => 1}, params)
+ assert_equal({id: 1}, params)
end
def test_generate_escapes
get "/:controller(/:action)", to: "foo#bar"
path, _ = @formatter.generate(nil,
- { :controller => "tasks",
- :action => "a/b c+d",
+ { controller: "tasks",
+ action: "a/b c+d",
}, {})
assert_equal "/tasks/a%2Fb%20c+d", path
end
@@ -261,8 +261,8 @@ module ActionDispatch
get "/:controller(/:action)", to: "foo#bar"
path, _ = @formatter.generate(
- nil, { :controller => "admin/tasks",
- :action => "a/b c+d",
+ nil, { controller: "admin/tasks",
+ action: "a/b c+d",
}, {})
assert_equal "/admin/tasks/a%2Fb%20c+d", path
end
@@ -271,22 +271,22 @@ module ActionDispatch
get "/:controller(/:action)", to: "foo#bar"
path, params = @formatter.generate(
- nil, { :id => 1,
- :controller => "tasks",
- :action => "show",
- :relative_url_root => nil
+ nil, { id: 1,
+ controller: "tasks",
+ action: "show",
+ relative_url_root: nil
}, {})
assert_equal "/tasks/show", path
- assert_equal({:id => 1, :relative_url_root => nil}, params)
+ 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"
primarty_parameters = {
- :id => 1,
- :controller => "tasks",
- :action => "show",
- :relative_url_root => nil
+ id: 1,
+ controller: "tasks",
+ action: "show",
+ relative_url_root: nil
}
redirection_parameters = {
"action"=>"show",
@@ -311,8 +311,8 @@ module ActionDispatch
path, params = @formatter.generate(
nil,
- {:controller =>"tasks", :id => 10},
- {:action =>"index"})
+ {controller: "tasks", id: 10},
+ {action: "index"})
assert_equal "/tasks/index/10", path
assert_equal({}, params)
end
@@ -322,16 +322,16 @@ module ActionDispatch
path, params = @formatter.generate(
"tasks",
- {:controller=>"tasks"},
- {:controller=>"tasks", :action=>"index"})
+ {controller: "tasks"},
+ {controller: "tasks", action: "index"})
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"
@@ -342,7 +342,7 @@ module ActionDispatch
router.recognize(env) do |r, params|
assert_equal route, r
- assert_equal({ :action => "bar" }.merge(expected), params)
+ assert_equal({ action: "bar" }.merge(expected), params)
called = true
end
@@ -351,8 +351,8 @@ 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"
@@ -363,7 +363,7 @@ module ActionDispatch
router.recognize(env) do |r, params|
assert_equal route, r
- assert_equal(expected.merge(:controller=>"foo", :action=>"bar"), params)
+ assert_equal(expected.merge(controller: "foo", action: "bar"), params)
called = true
end
@@ -372,15 +372,15 @@ module ActionDispatch
end
def test_namespaced_controller
- get "/:controller(/:action(/:id))", { :controller => /.+?/ }
+ get "/:controller(/:action(/:id))", { controller: /.+?/ }
route = @routes.first
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|
@@ -396,7 +396,7 @@ module ActionDispatch
route = @routes.first
env = rails_env "PATH_INFO" => "/books/list.rss"
- expected = { :controller => "books", :action => "list", :format => "rss" }
+ expected = { controller: "books", action: "list", format: "rss" }
called = false
router.recognize(env) do |r, params|
assert_equal route, r