提交 3513f80e 编写于 作者: A Arthur Nogueira Neves

Merge pull request #22371 from yui-knk/better_mount_error

Brush up errors of `ActionDispatch::Routing::Mapper#mount`
......@@ -600,17 +600,20 @@ def match(path, options=nil)
def mount(app, options = nil)
if options
path = options.delete(:at)
else
unless Hash === app
raise ArgumentError, "must be called with mount point"
end
elsif Hash === app
options = app
app, path = options.find { |k, _| k.respond_to?(:call) }
options.delete(app) if app
end
raise "A rack application must be specified" unless path
raise ArgumentError, "A rack application must be specified" unless app.respond_to?(:call)
raise ArgumentError, <<-MSG.strip_heredoc unless path
Must be called with mount point
mount SomeRackApp, at: "some_route"
or
mount(SomeRackApp => "some_route")
MSG
rails_app = rails_app? app
options[:as] ||= app_name(app, rails_app)
......
......@@ -158,7 +158,7 @@ def test_map_wildcard_with_format_true
assert_equal '/*path.:format', fakeset.asts.first.to_s
end
def test_raising_helpful_error_on_invalid_arguments
def test_raising_error_when_path_is_not_passed
fakeset = FakeSet.new
mapper = Mapper.new fakeset
app = lambda { |env| [200, {}, [""]] }
......@@ -166,6 +166,18 @@ def test_raising_helpful_error_on_invalid_arguments
mapper.mount app
end
end
def test_raising_error_when_rack_app_is_not_passed
fakeset = FakeSet.new
mapper = Mapper.new fakeset
assert_raises ArgumentError do
mapper.mount 10, as: "exciting"
end
assert_raises ArgumentError do
mapper.mount as: "exciting"
end
end
end
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册