Skip to content

Commit

Permalink
Merge pull request #103 from thomet/change_middleware_to_support_rail…
Browse files Browse the repository at this point in the history
…s_app_in_subfolders

Change middleware to support rails app in subfolders
  • Loading branch information
Charlie Somerville committed Mar 9, 2013
2 parents cf3215e + 157718e commit d2b0ffc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/better_errors/middleware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ def allow_ip?(env)

def better_errors_call(env)
case env["PATH_INFO"]
when %r{\A/__better_errors/(?<oid>-?\d+)/(?<method>\w+)\z}
when %r{\A.*/__better_errors/(?<oid>-?\d+)/(?<method>\w+)\z}
internal_call env, $~
when %r{\A/__better_errors/?\z}
when %r{\A.*/__better_errors/?\z}
show_error_page env
else
protected_app_call env
Expand Down
15 changes: 15 additions & 0 deletions spec/better_errors/middleware_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,21 @@ module BetterErrors
app.call("PATH_INFO" => "/__better_errors/1/preform_awesomness")
end

it "should call the internal methods on any subfolder path" do
app.should_receive :internal_call
app.call("PATH_INFO" => "/any_sub/folder/path/__better_errors/1/preform_awesomness")
end

it "should show the error page" do
app.should_receive :show_error_page
app.call("PATH_INFO" => "/__better_errors/")
end

it "should show the error page on any subfolder path" do
app.should_receive :show_error_page
app.call("PATH_INFO" => "/any_sub/folder/path/__better_errors/")
end

it "should not show the error page to a non-local address" do
app.should_not_receive :better_errors_call
app.call("REMOTE_ADDR" => "1.2.3.4")
Expand All @@ -36,6 +46,11 @@ module BetterErrors
status, headers, body = app.call("PATH_INFO" => "/__better_errors")
body.join.should match /No errors have been recorded yet./
end

it "should show that no errors have been recorded on any subfolder path" do
status, headers, body = app.call("PATH_INFO" => "/any_sub/folder/path/__better_errors")
body.join.should match /No errors have been recorded yet./
end
end

context "when handling an error" do
Expand Down

0 comments on commit d2b0ffc

Please sign in to comment.