Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix serving index files with rack static file server [#2180 state:res…
…olved]
- Loading branch information
Showing
5 changed files
with
54 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/foo/bar.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/foo/index.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/index.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
require 'abstract_unit' | ||
|
||
require 'action_controller' | ||
require 'rails/rack' | ||
|
||
class RackStaticTest < ActiveSupport::TestCase | ||
DummyApp = lambda { |env| | ||
[200, {"Content-Type" => "text/plain"}, ["Hello, World!"]] | ||
} | ||
App = Rails::Rack::Static.new(DummyApp) | ||
|
||
test "serves dynamic content" do | ||
assert_equal "Hello, World!", get("/nofile") | ||
end | ||
|
||
test "serves static index at root" do | ||
assert_equal "/index.html", get("/index.html") | ||
assert_equal "/index.html", get("/index") | ||
assert_equal "/index.html", get("/") | ||
end | ||
|
||
test "serves static file in directory" do | ||
assert_equal "/foo/bar.html", get("/foo/bar.html") | ||
assert_equal "/foo/bar.html", get("/foo/bar/") | ||
assert_equal "/foo/bar.html", get("/foo/bar") | ||
end | ||
|
||
test "serves static index file in directory" do | ||
assert_equal "/foo/index.html", get("/foo/index.html") | ||
assert_equal "/foo/index.html", get("/foo/") | ||
assert_equal "/foo/index.html", get("/foo") | ||
end | ||
|
||
private | ||
def get(path) | ||
Rack::MockRequest.new(App).request("GET", path).body | ||
end | ||
end |