Skip to content

Commit

Permalink
Raise a helpful error message on #mount misuse
Browse files Browse the repository at this point in the history
  • Loading branch information
carllerche committed Jul 10, 2012
1 parent 89dc481 commit afa68eb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions actionpack/lib/action_dispatch/routing/mapper.rb
Expand Up @@ -430,6 +430,10 @@ def mount(app, options = nil)
if options if options
path = options.delete(:at) path = options.delete(:at)
else else
unless Hash === app
raise ArgumentError, "must be called with mount point"
end

options = app options = app
app, path = options.find { |k, v| k.respond_to?(:call) } app, path = options.find { |k, v| k.respond_to?(:call) }
options.delete(app) if app options.delete(app) if app
Expand Down
9 changes: 9 additions & 0 deletions actionpack/test/dispatch/mapper_test.rb
Expand Up @@ -98,6 +98,15 @@ def test_map_wildcard_with_format_true
mapper.get '/*path', :to => 'pages#show', :format => true mapper.get '/*path', :to => 'pages#show', :format => true
assert_equal '/*path.:format', fakeset.conditions.first[:path_info] assert_equal '/*path.:format', fakeset.conditions.first[:path_info]
end end

def test_raising_helpful_error_on_invalid_arguments
fakeset = FakeSet.new
mapper = Mapper.new fakeset
app = lambda { |env| [200, {}, [""]] }
assert_raises ArgumentError do
mapper.mount app
end
end
end end
end end
end end

0 comments on commit afa68eb

Please sign in to comment.