Skip to content

Commit

Permalink
added 405 for sinatra
Browse files Browse the repository at this point in the history
  • Loading branch information
joshbuddy committed May 3, 2010
1 parent be417b4 commit 56d2035
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
24 changes: 22 additions & 2 deletions lib/usher/interface/sinatra.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def generate(name, *params)
def route!(base=self.class, pass_block=nil)
if base.router and match = catch(:request_method) { base.router.recognize(@request, @request.path_info) }
if match.is_a?(Symbol)
route_missing #FIXME this should really respond with a 405
route_eval { status 405 }
else
@block_params = match.params.map { |p| p.last }
(@params ||= {}).merge!(match.params_as_hash)
Expand Down Expand Up @@ -80,7 +80,8 @@ def router
:ignore_trailing_delimiters => true,
:generator => Usher::Util::Generators::URL.new,
:delimiters => ['/', '.', '-'],
:valid_regex => '[0-9A-Za-z\$_\+!\*\',]+')
:valid_regex => '[0-9A-Za-z\$_\+!\*\',]+',
:throw_on_request_method_miss => true)
block_given? ? yield(@router) : @router
end

Expand Down Expand Up @@ -118,6 +119,25 @@ def configure!
</html>
HTML
end
error 405 do
content_type 'text/html'

(<<-HTML).gsub(/^ {17}/, '')
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
body { text-align:center;font-family:helvetica,arial;font-size:22px;
color:#888;margin:20px}
#c {margin:0 auto;width:500px;text-align:left}
</style>
</head>
<body>
<h2>Sinatra sorta knows this ditty, but the request method is not allowed.</h2>
</body>
</html>
HTML
end
end

@_configured = true
Expand Down
10 changes: 10 additions & 0 deletions spec/private/sinatra/recognize_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,14 @@
end
end

describe "method not allowed" do

it "should correctly generate a not found page without images and return a 405" do
@app.post('/bar') { 'found' }
response = @app.call_with_mock_request('/bar')
response.status.should == 405
response.body.should_not match(/__sinatra__/)
end
end

end

0 comments on commit 56d2035

Please sign in to comment.