-
Notifications
You must be signed in to change notification settings - Fork 21.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modified ActionDispatch::Static to allow passing multiple roots
- Loading branch information
Showing
6 changed files
with
104 additions
and
21 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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,35 +1,74 @@ | |||
require 'abstract_unit' | require 'abstract_unit' | ||
|
|
||
class StaticTest < ActiveSupport::TestCase | module StaticTests | ||
DummyApp = lambda { |env| | def test_serves_dynamic_content | ||
[200, {"Content-Type" => "text/plain"}, ["Hello, World!"]] | |||
} | |||
App = ActionDispatch::Static.new(DummyApp, "#{FIXTURE_LOAD_PATH}/public") | |||
|
|||
test "serves dynamic content" do | |||
assert_equal "Hello, World!", get("/nofile") | assert_equal "Hello, World!", get("/nofile") | ||
end | end | ||
|
|
||
test "serves static index at root" do | def test_serves_static_index_at_root | ||
assert_equal "/index.html", get("/index.html") | assert_equal "/index.html", get("/index.html") | ||
assert_equal "/index.html", get("/index") | assert_equal "/index.html", get("/index") | ||
assert_equal "/index.html", get("/") | assert_equal "/index.html", get("/") | ||
end | end | ||
|
|
||
test "serves static file in directory" do | def test_serves_static_file_in_directory | ||
assert_equal "/foo/bar.html", get("/foo/bar.html") | 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/") | ||
assert_equal "/foo/bar.html", get("/foo/bar") | assert_equal "/foo/bar.html", get("/foo/bar") | ||
end | end | ||
|
|
||
test "serves static index file in directory" do | def test_serves_static_index_file_in_directory | ||
assert_equal "/foo/index.html", get("/foo/index.html") | assert_equal "/foo/index.html", get("/foo/index.html") | ||
assert_equal "/foo/index.html", get("/foo/") | assert_equal "/foo/index.html", get("/foo/") | ||
assert_equal "/foo/index.html", get("/foo") | assert_equal "/foo/index.html", get("/foo") | ||
end | end | ||
|
|
||
private | private | ||
def get(path) | def get(path) | ||
Rack::MockRequest.new(App).request("GET", path).body | Rack::MockRequest.new(@app).request("GET", path).body | ||
end | end | ||
end | end | ||
|
|||
class StaticTest < ActiveSupport::TestCase | |||
DummyApp = lambda { |env| | |||
[200, {"Content-Type" => "text/plain"}, ["Hello, World!"]] | |||
} | |||
App = ActionDispatch::Static.new(DummyApp, "#{FIXTURE_LOAD_PATH}/public") | |||
|
|||
def setup | |||
@app = App | |||
end | |||
|
|||
include StaticTests | |||
end | |||
|
|||
class MultipleDirectorisStaticTest < ActiveSupport::TestCase | |||
DummyApp = lambda { |env| | |||
[200, {"Content-Type" => "text/plain"}, ["Hello, World!"]] | |||
} | |||
App = ActionDispatch::Static.new(DummyApp, | |||
{ "/" => "#{FIXTURE_LOAD_PATH}/public", | |||
"/blog" => "#{FIXTURE_LOAD_PATH}/blog_public", | |||
"/foo" => "#{FIXTURE_LOAD_PATH}/non_existing_dir" | |||
}) | |||
|
|||
def setup | |||
@app = App | |||
end | |||
|
|||
include StaticTests | |||
|
|||
test "serves files from other mounted directories" do | |||
assert_equal "/blog/index.html", get("/blog/index.html") | |||
assert_equal "/blog/index.html", get("/blog/index") | |||
assert_equal "/blog/index.html", get("/blog/") | |||
|
|||
assert_equal "/blog/blog.html", get("/blog/blog/") | |||
assert_equal "/blog/blog.html", get("/blog/blog.html") | |||
assert_equal "/blog/blog.html", get("/blog/blog") | |||
|
|||
assert_equal "/blog/subdir/index.html", get("/blog/subdir/index.html") | |||
assert_equal "/blog/subdir/index.html", get("/blog/subdir/") | |||
assert_equal "/blog/subdir/index.html", get("/blog/subdir") | |||
end | |||
end |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1 @@ | |||
absolute/* |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1 @@ | |||
/blog/blog.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1 @@ | |||
/blog/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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1 @@ | |||
/blog/subdir/index.html |