55class Propshaft ::ServerTest < ActiveSupport ::TestCase
66 include Rack ::Test ::Methods
77
8+ class RackApp
9+ attr_reader :calls
10+
11+ def initialize
12+ @calls = [ ]
13+ end
14+
15+ def call ( env )
16+ @calls << env
17+ [ 200 , { } , [ "OK" ] ]
18+ end
19+ end
20+
821 setup do
922 @assembly = Propshaft ::Assembly . new ( ActiveSupport ::OrderedOptions . new . tap { |config |
1023 config . paths = [ Pathname . new ( "#{ __dir__ } /../fixtures/assets/vendor" ) , Pathname . new ( "#{ __dir__ } /../fixtures/assets/first_path" ) ]
1124 config . output_path = Pathname . new ( "#{ __dir__ } ../fixtures/output" )
25+ config . prefix = "/assets"
1226 } )
1327
28+ @rack_app = RackApp . new
1429 @assembly . compilers . register "text/css" , Propshaft ::Compiler ::CssAssetUrls
15- @server = Propshaft ::Server . new ( @assembly )
30+ @server = Propshaft ::Server . new ( @rack_app , @assembly )
31+ end
32+
33+ test "forward requests not under prefix" do
34+ get "/test"
35+ assert_not_empty @rack_app . calls
36+ end
37+
38+ test "forward requests that aren't GET or HEAD" do
39+ asset = @assembly . load_path . find ( "foobar/source/test.css" )
40+ post "/assets/#{ asset . digested_path } "
41+ assert_not_empty @rack_app . calls
1642 end
1743
1844 test "serve a compiled file" do
1945 asset = @assembly . load_path . find ( "foobar/source/test.css" )
20- get "/#{ asset . digested_path } "
46+ get "/assets/ #{ asset . digested_path } "
2147
2248 assert_equal 200 , last_response . status
23- assert_equal "62" , last_response . headers [ 'content-length' ]
49+ assert_equal last_response . body . bytesize . to_s , last_response . headers [ 'content-length' ]
2450 assert_equal "text/css" , last_response . headers [ 'content-type' ]
2551 assert_equal "Accept-Encoding" , last_response . headers [ 'vary' ]
2652 assert_equal "\" #{ asset . digest } \" " , last_response . headers [ 'etag' ]
2753 assert_equal "public, max-age=31536000, immutable" , last_response . headers [ 'cache-control' ]
28- assert_equal ".hero { background: url(\" /foobar/source/file-3e6a1297.jpg\" ) }\n " ,
54+ assert_equal ".hero { background: url(\" /assets/ foobar/source/file-3e6a1297.jpg\" ) }\n " ,
2955 last_response . body
3056 end
3157
3258 test "serve a predigested file" do
3359 asset = @assembly . load_path . find ( "file-already-abcdefVWXYZ0123456789_-.digested.css" )
34- get "/#{ asset . digested_path } "
60+ get "/assets/ #{ asset . digested_path } "
3561 assert_equal 200 , last_response . status
3662 end
3763
3864 test "serve a sourcemap" do
3965 asset = @assembly . load_path . find ( "file-is-a-sourcemap.js.map" )
40- get "/#{ asset . digested_path } "
66+ get "/assets/ #{ asset . digested_path } "
4167 assert_equal 200 , last_response . status
4268 end
4369
4470 test "not found" do
45- get "/not-found.js"
71+ get "/assets/ not-found.js"
4672
4773 assert_equal 404 , last_response . status
4874 assert_equal "9" , last_response . headers [ 'content-length' ]
@@ -55,17 +81,12 @@ class Propshaft::ServerTest < ActiveSupport::TestCase
5581
5682 test "not found if digest does not match" do
5783 asset = @assembly . load_path . find ( "foobar/source/test.css" )
58- get "/#{ asset . logical_path } "
84+ get "/assets/ #{ asset . logical_path } "
5985 assert_equal 404 , last_response . status
6086 end
6187
6288 private
63- def default_app
64- builder = Rack ::Builder . new
65- builder . run @server
66- end
67-
6889 def app
69- @app ||= Rack ::Lint . new ( default_app )
90+ @app ||= Rack ::Lint . new ( @server )
7091 end
7192end
0 commit comments