2009-03-10 00:31:04 -04:00
|
|
|
require 'abstract_unit'
|
|
|
|
|
2010-07-29 08:12:25 -04:00
|
|
|
module StaticTests
|
|
|
|
def test_serves_dynamic_content
|
2010-10-04 12:06:04 -04:00
|
|
|
assert_equal "Hello, World!", get("/nofile").body
|
2009-03-10 00:31:04 -04:00
|
|
|
end
|
|
|
|
|
2010-07-29 08:12:25 -04:00
|
|
|
def test_serves_static_index_at_root
|
2010-10-04 12:06:04 -04:00
|
|
|
assert_html "/index.html", get("/index.html")
|
|
|
|
assert_html "/index.html", get("/index")
|
|
|
|
assert_html "/index.html", get("/")
|
|
|
|
assert_html "/index.html", get("")
|
2009-03-10 00:31:04 -04:00
|
|
|
end
|
|
|
|
|
2010-07-29 08:12:25 -04:00
|
|
|
def test_serves_static_file_in_directory
|
2010-10-04 12:06:04 -04:00
|
|
|
assert_html "/foo/bar.html", get("/foo/bar.html")
|
|
|
|
assert_html "/foo/bar.html", get("/foo/bar/")
|
|
|
|
assert_html "/foo/bar.html", get("/foo/bar")
|
2009-03-10 00:31:04 -04:00
|
|
|
end
|
|
|
|
|
2010-07-29 08:12:25 -04:00
|
|
|
def test_serves_static_index_file_in_directory
|
2010-10-04 12:06:04 -04:00
|
|
|
assert_html "/foo/index.html", get("/foo/index.html")
|
|
|
|
assert_html "/foo/index.html", get("/foo/")
|
|
|
|
assert_html "/foo/index.html", get("/foo")
|
2009-03-10 00:31:04 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2010-10-04 12:06:04 -04:00
|
|
|
|
|
|
|
def assert_html(body, response)
|
|
|
|
assert_equal body, response.body
|
|
|
|
assert_equal "text/html", response.headers["Content-Type"]
|
|
|
|
end
|
|
|
|
|
2009-03-10 00:31:04 -04:00
|
|
|
def get(path)
|
2010-10-04 12:06:04 -04:00
|
|
|
Rack::MockRequest.new(@app).request("GET", path)
|
2009-03-10 00:31:04 -04:00
|
|
|
end
|
|
|
|
end
|
2010-07-29 08:12:25 -04:00
|
|
|
|
|
|
|
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
|
2011-04-15 14:09:39 -04:00
|
|
|
end
|