mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
remove Strexp
This was a useless object. We can just directly construct a Path::Pattern object without a Strexp object.
This commit is contained in:
parent
4868692687
commit
947ebe9a6d
8 changed files with 73 additions and 115 deletions
|
@ -1,5 +1,3 @@
|
||||||
require 'action_dispatch/journey/router/strexp'
|
|
||||||
|
|
||||||
module ActionDispatch
|
module ActionDispatch
|
||||||
module Journey # :nodoc:
|
module Journey # :nodoc:
|
||||||
module Path # :nodoc:
|
module Path # :nodoc:
|
||||||
|
@ -7,13 +5,19 @@ module ActionDispatch
|
||||||
attr_reader :spec, :requirements, :anchored
|
attr_reader :spec, :requirements, :anchored
|
||||||
|
|
||||||
def self.from_string string
|
def self.from_string string
|
||||||
new Journey::Router::Strexp.build(string, {}, ["/.?"]), true
|
build(string, {}, ["/.?"], true)
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize(strexp, anchored)
|
def self.build(path, requirements, separators, anchored)
|
||||||
@spec = strexp.ast
|
parser = Journey::Parser.new
|
||||||
@requirements = strexp.requirements
|
ast = parser.parse path
|
||||||
@separators = strexp.separators.join
|
new ast, requirements, separators, anchored
|
||||||
|
end
|
||||||
|
|
||||||
|
def initialize(ast, requirements, separators, anchored)
|
||||||
|
@spec = ast
|
||||||
|
@requirements = requirements
|
||||||
|
@separators = separators.join
|
||||||
@anchored = anchored
|
@anchored = anchored
|
||||||
|
|
||||||
@names = nil
|
@names = nil
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
require 'action_dispatch/journey/router/utils'
|
require 'action_dispatch/journey/router/utils'
|
||||||
require 'action_dispatch/journey/router/strexp'
|
|
||||||
require 'action_dispatch/journey/routes'
|
require 'action_dispatch/journey/routes'
|
||||||
require 'action_dispatch/journey/formatter'
|
require 'action_dispatch/journey/formatter'
|
||||||
|
|
||||||
|
|
|
@ -1,26 +0,0 @@
|
||||||
module ActionDispatch
|
|
||||||
module Journey # :nodoc:
|
|
||||||
class Router # :nodoc:
|
|
||||||
class Strexp # :nodoc:
|
|
||||||
class << self
|
|
||||||
alias :compile :new
|
|
||||||
end
|
|
||||||
|
|
||||||
attr_reader :path, :requirements, :separators, :ast
|
|
||||||
|
|
||||||
def self.build(path, requirements, separators)
|
|
||||||
parser = Journey::Parser.new
|
|
||||||
ast = parser.parse path
|
|
||||||
new ast, path, requirements, separators
|
|
||||||
end
|
|
||||||
|
|
||||||
def initialize(ast, path, requirements, separators)
|
|
||||||
@ast = ast
|
|
||||||
@path = path
|
|
||||||
@requirements = requirements
|
|
||||||
@separators = separators
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -537,13 +537,7 @@ module ActionDispatch
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_path(path, ast, requirements, anchor)
|
def build_path(path, ast, requirements, anchor)
|
||||||
strexp = Journey::Router::Strexp.new(
|
pattern = Journey::Path::Pattern.new(ast, requirements, SEPARATORS, anchor)
|
||||||
ast,
|
|
||||||
path,
|
|
||||||
requirements,
|
|
||||||
SEPARATORS)
|
|
||||||
|
|
||||||
pattern = Journey::Path::Pattern.new(strexp, anchor)
|
|
||||||
|
|
||||||
builder = Journey::GTG::Builder.new ast
|
builder = Journey::GTG::Builder.new ast
|
||||||
|
|
||||||
|
|
|
@ -19,12 +19,12 @@ module ActionDispatch
|
||||||
'/:foo|*bar' => %r{\A/(?:([^/.?]+)|(.+))\Z},
|
'/:foo|*bar' => %r{\A/(?:([^/.?]+)|(.+))\Z},
|
||||||
}.each do |path, expected|
|
}.each do |path, expected|
|
||||||
define_method(:"test_to_regexp_#{path}") do
|
define_method(:"test_to_regexp_#{path}") do
|
||||||
strexp = Router::Strexp.build(
|
path = Pattern.build(
|
||||||
path,
|
path,
|
||||||
{ :controller => /.+/ },
|
{ :controller => /.+/ },
|
||||||
["/", ".", "?"]
|
["/", ".", "?"],
|
||||||
|
true
|
||||||
)
|
)
|
||||||
path = Pattern.new strexp, true
|
|
||||||
assert_equal(expected, path.to_regexp)
|
assert_equal(expected, path.to_regexp)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -43,12 +43,12 @@ module ActionDispatch
|
||||||
'/:foo|*bar' => %r{\A/(?:([^/.?]+)|(.+))},
|
'/:foo|*bar' => %r{\A/(?:([^/.?]+)|(.+))},
|
||||||
}.each do |path, expected|
|
}.each do |path, expected|
|
||||||
define_method(:"test_to_non_anchored_regexp_#{path}") do
|
define_method(:"test_to_non_anchored_regexp_#{path}") do
|
||||||
strexp = Router::Strexp.build(
|
path = Pattern.build(
|
||||||
path,
|
path,
|
||||||
{ :controller => /.+/ },
|
{ :controller => /.+/ },
|
||||||
["/", ".", "?"]
|
["/", ".", "?"],
|
||||||
|
false
|
||||||
)
|
)
|
||||||
path = Pattern.new strexp, false
|
|
||||||
assert_equal(expected, path.to_regexp)
|
assert_equal(expected, path.to_regexp)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -66,27 +66,27 @@ module ActionDispatch
|
||||||
'/:controller/*foo/bar' => %w{ controller foo },
|
'/:controller/*foo/bar' => %w{ controller foo },
|
||||||
}.each do |path, expected|
|
}.each do |path, expected|
|
||||||
define_method(:"test_names_#{path}") do
|
define_method(:"test_names_#{path}") do
|
||||||
strexp = Router::Strexp.build(
|
path = Pattern.build(
|
||||||
path,
|
path,
|
||||||
{ :controller => /.+/ },
|
{ :controller => /.+/ },
|
||||||
["/", ".", "?"]
|
["/", ".", "?"],
|
||||||
|
true
|
||||||
)
|
)
|
||||||
path = Pattern.new strexp, true
|
|
||||||
assert_equal(expected, path.names)
|
assert_equal(expected, path.names)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_to_regexp_with_extended_group
|
def test_to_regexp_with_extended_group
|
||||||
strexp = Router::Strexp.build(
|
path = Pattern.build(
|
||||||
'/page/:name',
|
'/page/:name',
|
||||||
{ :name => /
|
{ :name => /
|
||||||
#ROFL
|
#ROFL
|
||||||
(tender|love
|
(tender|love
|
||||||
#MAO
|
#MAO
|
||||||
)/x },
|
)/x },
|
||||||
["/", ".", "?"]
|
["/", ".", "?"],
|
||||||
|
true
|
||||||
)
|
)
|
||||||
path = Pattern.new strexp, true
|
|
||||||
assert_match(path, '/page/tender')
|
assert_match(path, '/page/tender')
|
||||||
assert_match(path, '/page/love')
|
assert_match(path, '/page/love')
|
||||||
assert_no_match(path, '/page/loving')
|
assert_no_match(path, '/page/loving')
|
||||||
|
@ -104,23 +104,23 @@ module ActionDispatch
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_to_regexp_match_non_optional
|
def test_to_regexp_match_non_optional
|
||||||
strexp = Router::Strexp.build(
|
path = Pattern.build(
|
||||||
'/:name',
|
'/:name',
|
||||||
{ :name => /\d+/ },
|
{ :name => /\d+/ },
|
||||||
["/", ".", "?"]
|
["/", ".", "?"],
|
||||||
|
true
|
||||||
)
|
)
|
||||||
path = Pattern.new strexp, true
|
|
||||||
assert_match(path, '/123')
|
assert_match(path, '/123')
|
||||||
assert_no_match(path, '/')
|
assert_no_match(path, '/')
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_to_regexp_with_group
|
def test_to_regexp_with_group
|
||||||
strexp = Router::Strexp.build(
|
path = Pattern.build(
|
||||||
'/page/:name',
|
'/page/:name',
|
||||||
{ :name => /(tender|love)/ },
|
{ :name => /(tender|love)/ },
|
||||||
["/", ".", "?"]
|
["/", ".", "?"],
|
||||||
|
true
|
||||||
)
|
)
|
||||||
path = Pattern.new strexp, true
|
|
||||||
assert_match(path, '/page/tender')
|
assert_match(path, '/page/tender')
|
||||||
assert_match(path, '/page/love')
|
assert_match(path, '/page/love')
|
||||||
assert_no_match(path, '/page/loving')
|
assert_no_match(path, '/page/loving')
|
||||||
|
@ -128,15 +128,13 @@ module ActionDispatch
|
||||||
|
|
||||||
def test_ast_sets_regular_expressions
|
def test_ast_sets_regular_expressions
|
||||||
requirements = { :name => /(tender|love)/, :value => /./ }
|
requirements = { :name => /(tender|love)/, :value => /./ }
|
||||||
strexp = Router::Strexp.build(
|
path = Pattern.build(
|
||||||
'/page/:name/:value',
|
'/page/:name/:value',
|
||||||
requirements,
|
requirements,
|
||||||
["/", ".", "?"]
|
["/", ".", "?"],
|
||||||
|
true
|
||||||
)
|
)
|
||||||
|
|
||||||
assert_equal requirements, strexp.requirements
|
|
||||||
|
|
||||||
path = Pattern.new strexp, true
|
|
||||||
nodes = path.ast.grep(Nodes::Symbol)
|
nodes = path.ast.grep(Nodes::Symbol)
|
||||||
assert_equal 2, nodes.length
|
assert_equal 2, nodes.length
|
||||||
nodes.each do |node|
|
nodes.each do |node|
|
||||||
|
@ -145,24 +143,24 @@ module ActionDispatch
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_match_data_with_group
|
def test_match_data_with_group
|
||||||
strexp = Router::Strexp.build(
|
path = Pattern.build(
|
||||||
'/page/:name',
|
'/page/:name',
|
||||||
{ :name => /(tender|love)/ },
|
{ :name => /(tender|love)/ },
|
||||||
["/", ".", "?"]
|
["/", ".", "?"],
|
||||||
|
true
|
||||||
)
|
)
|
||||||
path = Pattern.new strexp, true
|
|
||||||
match = path.match '/page/tender'
|
match = path.match '/page/tender'
|
||||||
assert_equal 'tender', match[1]
|
assert_equal 'tender', match[1]
|
||||||
assert_equal 2, match.length
|
assert_equal 2, match.length
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_match_data_with_multi_group
|
def test_match_data_with_multi_group
|
||||||
strexp = Router::Strexp.build(
|
path = Pattern.build(
|
||||||
'/page/:name/:id',
|
'/page/:name/:id',
|
||||||
{ :name => /t(((ender|love)))()/ },
|
{ :name => /t(((ender|love)))()/ },
|
||||||
["/", ".", "?"]
|
["/", ".", "?"],
|
||||||
|
true
|
||||||
)
|
)
|
||||||
path = Pattern.new strexp, true
|
|
||||||
match = path.match '/page/tender/10'
|
match = path.match '/page/tender/10'
|
||||||
assert_equal 'tender', match[1]
|
assert_equal 'tender', match[1]
|
||||||
assert_equal '10', match[2]
|
assert_equal '10', match[2]
|
||||||
|
@ -172,30 +170,29 @@ module ActionDispatch
|
||||||
|
|
||||||
def test_star_with_custom_re
|
def test_star_with_custom_re
|
||||||
z = /\d+/
|
z = /\d+/
|
||||||
strexp = Router::Strexp.build(
|
path = Pattern.build(
|
||||||
'/page/*foo',
|
'/page/*foo',
|
||||||
{ :foo => z },
|
{ :foo => z },
|
||||||
["/", ".", "?"]
|
["/", ".", "?"],
|
||||||
|
true
|
||||||
)
|
)
|
||||||
path = Pattern.new strexp, true
|
|
||||||
assert_equal(%r{\A/page/(#{z})\Z}, path.to_regexp)
|
assert_equal(%r{\A/page/(#{z})\Z}, path.to_regexp)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_insensitive_regexp_with_group
|
def test_insensitive_regexp_with_group
|
||||||
strexp = Router::Strexp.build(
|
path = Pattern.build(
|
||||||
'/page/:name/aaron',
|
'/page/:name/aaron',
|
||||||
{ :name => /(tender|love)/i },
|
{ :name => /(tender|love)/i },
|
||||||
["/", ".", "?"]
|
["/", ".", "?"],
|
||||||
|
true
|
||||||
)
|
)
|
||||||
path = Pattern.new strexp, true
|
|
||||||
assert_match(path, '/page/TENDER/aaron')
|
assert_match(path, '/page/TENDER/aaron')
|
||||||
assert_match(path, '/page/loVE/aaron')
|
assert_match(path, '/page/loVE/aaron')
|
||||||
assert_no_match(path, '/page/loVE/AAron')
|
assert_no_match(path, '/page/loVE/AAron')
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_to_regexp_with_strexp
|
def test_to_regexp_with_strexp
|
||||||
strexp = Router::Strexp.build('/:controller', { }, ["/", ".", "?"])
|
path = Pattern.build('/:controller', { }, ["/", ".", "?"], true)
|
||||||
path = Pattern.new strexp, true
|
|
||||||
x = %r{\A/([^/.?]+)\Z}
|
x = %r{\A/([^/.?]+)\Z}
|
||||||
|
|
||||||
assert_equal(x.source, path.source)
|
assert_equal(x.source, path.source)
|
||||||
|
|
|
@ -26,8 +26,7 @@ module ActionDispatch
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_path_requirements_override_defaults
|
def test_path_requirements_override_defaults
|
||||||
strexp = Router::Strexp.build(':name', { name: /love/ }, ['/'])
|
path = Path::Pattern.build(':name', { name: /love/ }, ['/'], true)
|
||||||
path = Path::Pattern.new strexp, true
|
|
||||||
defaults = { name: 'tender' }
|
defaults = { name: 'tender' }
|
||||||
route = Route.new('name', nil, path, nil, [], defaults)
|
route = Route.new('name', nil, path, nil, [], defaults)
|
||||||
assert_equal(/love/, route.requirements[:name])
|
assert_equal(/love/, route.requirements[:name])
|
||||||
|
|
|
@ -32,8 +32,7 @@ module ActionDispatch
|
||||||
def test_dashes
|
def test_dashes
|
||||||
router = Router.new(routes)
|
router = Router.new(routes)
|
||||||
|
|
||||||
exp = Router::Strexp.build '/foo-bar-baz', {}, ['/.?']
|
path = Path::Pattern.build '/foo-bar-baz', {}, ['/.?'], true
|
||||||
path = Path::Pattern.new exp, true
|
|
||||||
|
|
||||||
routes.add_route nil, path, {}, [], {:id => nil}, {}
|
routes.add_route nil, path, {}, [], {:id => nil}, {}
|
||||||
|
|
||||||
|
@ -49,8 +48,7 @@ module ActionDispatch
|
||||||
router = Router.new(routes)
|
router = Router.new(routes)
|
||||||
|
|
||||||
#match the escaped version of /ほげ
|
#match the escaped version of /ほげ
|
||||||
exp = Router::Strexp.build '/%E3%81%BB%E3%81%92', {}, ['/.?']
|
path = Path::Pattern.build '/%E3%81%BB%E3%81%92', {}, ['/.?'], true
|
||||||
path = Path::Pattern.new exp, true
|
|
||||||
|
|
||||||
routes.add_route nil, path, {}, [], {:id => nil}, {}
|
routes.add_route nil, path, {}, [], {:id => nil}, {}
|
||||||
|
|
||||||
|
@ -68,8 +66,7 @@ module ActionDispatch
|
||||||
|
|
||||||
requirements = { :hello => /world/ }
|
requirements = { :hello => /world/ }
|
||||||
|
|
||||||
exp = Router::Strexp.build '/foo(/:id)', {}, ['/.?']
|
path = Path::Pattern.build '/foo(/:id)', {}, ['/.?'], true
|
||||||
path = Path::Pattern.new exp, true
|
|
||||||
|
|
||||||
routes.add_route nil, path, requirements, [], {:id => nil}, {}
|
routes.add_route nil, path, requirements, [], {:id => nil}, {}
|
||||||
|
|
||||||
|
@ -88,8 +85,7 @@ module ActionDispatch
|
||||||
|
|
||||||
requirements = { :hello => /mom/ }
|
requirements = { :hello => /mom/ }
|
||||||
|
|
||||||
exp = Router::Strexp.build '/foo(/:id)', {}, ['/.?']
|
path = Path::Pattern.build '/foo(/:id)', {}, ['/.?'], true
|
||||||
path = Path::Pattern.new exp, true
|
|
||||||
|
|
||||||
router.routes.add_route nil, path, requirements, [], {:id => nil}, {}
|
router.routes.add_route nil, path, requirements, [], {:id => nil}, {}
|
||||||
|
|
||||||
|
@ -115,8 +111,7 @@ module ActionDispatch
|
||||||
def test_request_class_overrides_path_info
|
def test_request_class_overrides_path_info
|
||||||
router = Router.new(routes)
|
router = Router.new(routes)
|
||||||
|
|
||||||
exp = Router::Strexp.build '/bar', {}, ['/.?']
|
path = Path::Pattern.build '/bar', {}, ['/.?'], true
|
||||||
path = Path::Pattern.new exp, true
|
|
||||||
|
|
||||||
routes.add_route nil, path, {}, [], {}, {}
|
routes.add_route nil, path, {}, [], {}, {}
|
||||||
|
|
||||||
|
@ -133,8 +128,8 @@ module ActionDispatch
|
||||||
|
|
||||||
def test_regexp_first_precedence
|
def test_regexp_first_precedence
|
||||||
add_routes @router, [
|
add_routes @router, [
|
||||||
Router::Strexp.build("/whois/:domain", {:domain => /\w+\.[\w\.]+/}, ['/', '.', '?']),
|
Path::Pattern.build("/whois/:domain", {:domain => /\w+\.[\w\.]+/}, ['/', '.', '?'], true),
|
||||||
Router::Strexp.build("/whois/:id(.:format)", {}, ['/', '.', '?'])
|
Path::Pattern.build("/whois/:id(.:format)", {}, ['/', '.', '?'], true)
|
||||||
]
|
]
|
||||||
|
|
||||||
env = rails_env 'PATH_INFO' => '/whois/example.com'
|
env = rails_env 'PATH_INFO' => '/whois/example.com'
|
||||||
|
@ -152,8 +147,8 @@ module ActionDispatch
|
||||||
|
|
||||||
def test_required_parts_verified_are_anchored
|
def test_required_parts_verified_are_anchored
|
||||||
add_routes @router, [
|
add_routes @router, [
|
||||||
Router::Strexp.build("/foo/:id", { :id => /\d/ }, ['/', '.', '?'])
|
Path::Pattern.build("/foo/:id", { :id => /\d/ }, ['/', '.', '?'], false)
|
||||||
], false
|
]
|
||||||
|
|
||||||
assert_raises(ActionController::UrlGenerationError) do
|
assert_raises(ActionController::UrlGenerationError) do
|
||||||
@formatter.generate(nil, { :id => '10' }, { })
|
@formatter.generate(nil, { :id => '10' }, { })
|
||||||
|
@ -162,8 +157,8 @@ module ActionDispatch
|
||||||
|
|
||||||
def test_required_parts_are_verified_when_building
|
def test_required_parts_are_verified_when_building
|
||||||
add_routes @router, [
|
add_routes @router, [
|
||||||
Router::Strexp.build("/foo/:id", { :id => /\d+/ }, ['/', '.', '?'])
|
Path::Pattern.build("/foo/:id", { :id => /\d+/ }, ['/', '.', '?'], false)
|
||||||
], false
|
]
|
||||||
|
|
||||||
path, _ = @formatter.generate(nil, { :id => '10' }, { })
|
path, _ = @formatter.generate(nil, { :id => '10' }, { })
|
||||||
assert_equal '/foo/10', path
|
assert_equal '/foo/10', path
|
||||||
|
@ -175,8 +170,8 @@ module ActionDispatch
|
||||||
|
|
||||||
def test_only_required_parts_are_verified
|
def test_only_required_parts_are_verified
|
||||||
add_routes @router, [
|
add_routes @router, [
|
||||||
Router::Strexp.build("/foo(/:id)", {:id => /\d/}, ['/', '.', '?'])
|
Path::Pattern.build("/foo(/:id)", {:id => /\d/}, ['/', '.', '?'], false)
|
||||||
], false
|
]
|
||||||
|
|
||||||
path, _ = @formatter.generate(nil, { :id => '10' }, { })
|
path, _ = @formatter.generate(nil, { :id => '10' }, { })
|
||||||
assert_equal '/foo/10', path
|
assert_equal '/foo/10', path
|
||||||
|
@ -190,8 +185,7 @@ module ActionDispatch
|
||||||
|
|
||||||
def test_knows_what_parts_are_missing_from_named_route
|
def test_knows_what_parts_are_missing_from_named_route
|
||||||
route_name = "gorby_thunderhorse"
|
route_name = "gorby_thunderhorse"
|
||||||
pattern = Router::Strexp.build("/foo/:id", { :id => /\d+/ }, ['/', '.', '?'])
|
path = Path::Pattern.build("/foo/:id", { :id => /\d+/ }, ['/', '.', '?'], false)
|
||||||
path = Path::Pattern.new pattern, false
|
|
||||||
@router.routes.add_route nil, path, {}, [], {}, route_name
|
@router.routes.add_route nil, path, {}, [], {}, route_name
|
||||||
|
|
||||||
error = assert_raises(ActionController::UrlGenerationError) do
|
error = assert_raises(ActionController::UrlGenerationError) do
|
||||||
|
@ -249,8 +243,8 @@ module ActionDispatch
|
||||||
|
|
||||||
def test_recognize_with_unbound_regexp
|
def test_recognize_with_unbound_regexp
|
||||||
add_routes @router, [
|
add_routes @router, [
|
||||||
Router::Strexp.build("/foo", { }, ['/', '.', '?'])
|
Path::Pattern.build("/foo", { }, ['/', '.', '?'], false)
|
||||||
], false
|
]
|
||||||
|
|
||||||
env = rails_env 'PATH_INFO' => '/foo/bar'
|
env = rails_env 'PATH_INFO' => '/foo/bar'
|
||||||
|
|
||||||
|
@ -262,8 +256,8 @@ module ActionDispatch
|
||||||
|
|
||||||
def test_bound_regexp_keeps_path_info
|
def test_bound_regexp_keeps_path_info
|
||||||
add_routes @router, [
|
add_routes @router, [
|
||||||
Router::Strexp.build("/foo", { }, ['/', '.', '?'])
|
Path::Pattern.build("/foo", { }, ['/', '.', '?'], true)
|
||||||
], true
|
]
|
||||||
|
|
||||||
env = rails_env 'PATH_INFO' => '/foo'
|
env = rails_env 'PATH_INFO' => '/foo'
|
||||||
|
|
||||||
|
@ -329,8 +323,7 @@ module ActionDispatch
|
||||||
def test_generate_slash
|
def test_generate_slash
|
||||||
params = [ [:controller, "tasks"],
|
params = [ [:controller, "tasks"],
|
||||||
[:action, "show"] ]
|
[:action, "show"] ]
|
||||||
str = Router::Strexp.build("/", Hash[params], ['/', '.', '?'])
|
path = Path::Pattern.build("/", Hash[params], ['/', '.', '?'], true)
|
||||||
path = Path::Pattern.new str, true
|
|
||||||
|
|
||||||
@router.routes.add_route @app, path, {}, [], {}, {}
|
@router.routes.add_route @app, path, {}, [], {}, {}
|
||||||
|
|
||||||
|
@ -498,12 +491,12 @@ module ActionDispatch
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_namespaced_controller
|
def test_namespaced_controller
|
||||||
strexp = Router::Strexp.build(
|
path = Path::Pattern.build(
|
||||||
"/:controller(/:action(/:id))",
|
"/:controller(/:action(/:id))",
|
||||||
{ :controller => /.+?/ },
|
{ :controller => /.+?/ },
|
||||||
["/", ".", "?"]
|
["/", ".", "?"],
|
||||||
|
true
|
||||||
)
|
)
|
||||||
path = Path::Pattern.new strexp, true
|
|
||||||
app = Object.new
|
app = Object.new
|
||||||
route = @router.routes.add_route(app, path, {}, [], {}, {})
|
route = @router.routes.add_route(app, path, {}, [], {}, {})
|
||||||
|
|
||||||
|
@ -615,7 +608,7 @@ module ActionDispatch
|
||||||
if String === path
|
if String === path
|
||||||
path = Path::Pattern.from_string path
|
path = Path::Pattern.from_string path
|
||||||
else
|
else
|
||||||
path = Path::Pattern.new path, anchor
|
path
|
||||||
end
|
end
|
||||||
router.routes.add_route @app, path, {}, [], {}, {}
|
router.routes.add_route @app, path, {}, [], {}, {}
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,8 +9,7 @@ module ActionDispatch
|
||||||
|
|
||||||
def test_clear
|
def test_clear
|
||||||
routes = Routes.new
|
routes = Routes.new
|
||||||
exp = Router::Strexp.build '/foo(/:id)', {}, ['/.?']
|
path = Path::Pattern.build '/foo(/:id)', {}, ['/.?'], true
|
||||||
path = Path::Pattern.new exp, true
|
|
||||||
requirements = { :hello => /world/ }
|
requirements = { :hello => /world/ }
|
||||||
|
|
||||||
routes.add_route nil, path, requirements, [], {:id => nil}, {}
|
routes.add_route nil, path, requirements, [], {:id => nil}, {}
|
||||||
|
@ -49,10 +48,9 @@ module ActionDispatch
|
||||||
assert_equal [anchored_route], @routes.anchored_routes
|
assert_equal [anchored_route], @routes.anchored_routes
|
||||||
assert_equal [], @routes.custom_routes
|
assert_equal [], @routes.custom_routes
|
||||||
|
|
||||||
strexp = Router::Strexp.build(
|
path = Path::Pattern.build(
|
||||||
"/hello/:who", { who: /\d/ }, ['/', '.', '?']
|
"/hello/:who", { who: /\d/ }, ['/', '.', '?'], false
|
||||||
)
|
)
|
||||||
path = Path::Pattern.new strexp, true
|
|
||||||
|
|
||||||
custom_route = @routes.add_route nil, path, {}, [], {}, {}
|
custom_route = @routes.add_route nil, path, {}, [], {}, {}
|
||||||
assert_equal [custom_route], @routes.custom_routes
|
assert_equal [custom_route], @routes.custom_routes
|
||||||
|
|
Loading…
Reference in a new issue