spec and fix app
This commit is contained in:
parent
d6986a7806
commit
01b5a118d0
|
@ -60,7 +60,7 @@ class Travis::Web::App
|
||||||
'ETag' => version,
|
'ETag' => version,
|
||||||
'Last-Modified' => last_modified.httpdate,
|
'Last-Modified' => last_modified.httpdate,
|
||||||
'Expires' => (last_modified + age).httpdate,
|
'Expires' => (last_modified + age).httpdate,
|
||||||
'Vary' => ''
|
'Vary' => vary_for(file)
|
||||||
}
|
}
|
||||||
|
|
||||||
[ 200, headers, [ content ] ]
|
[ 200, headers, [ content ] ]
|
||||||
|
@ -92,12 +92,20 @@ class Travis::Web::App
|
||||||
|
|
||||||
def cache_control(file)
|
def cache_control(file)
|
||||||
case route_for(file)
|
case route_for(file)
|
||||||
when '/' then "public, must-revalidate"
|
when '/' then "public, must-revalidate"
|
||||||
when 'version' then "no-cache"
|
when '/version' then "no-cache"
|
||||||
else "public, max-age=#{age}"
|
else "public, max-age=#{age}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def vary_for(file)
|
||||||
|
case route_for(file)
|
||||||
|
when '/' then 'Accept'
|
||||||
|
when '/version' then '*'
|
||||||
|
else ''
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def mime_type(file)
|
def mime_type(file)
|
||||||
Rack::Mime.mime_type File.extname(file)
|
Rack::Mime.mime_type File.extname(file)
|
||||||
end
|
end
|
||||||
|
|
33
spec/app_spec.rb
Normal file
33
spec/app_spec.rb
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe Travis::Web::App do
|
||||||
|
before do
|
||||||
|
current_session.global_env['HTTP_ACCEPT'] = '*/*'
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'catch all' do
|
||||||
|
before { get('/foo/bar') }
|
||||||
|
example { last_response.should be_ok }
|
||||||
|
example { headers['Content-Location'].should be == '/' }
|
||||||
|
example { headers['Cache-Control'].should include('must-revalidate') }
|
||||||
|
example { headers['Cache-Control'].should include('public') }
|
||||||
|
example { headers['Vary'].should include('Accept') }
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'assets' do
|
||||||
|
before { get('/favicon.ico') }
|
||||||
|
example { last_response.should be_ok }
|
||||||
|
example { headers['Content-Location'].should be == '/favicon.ico' }
|
||||||
|
example { headers['Cache-Control'].should_not include('must-revalidate') }
|
||||||
|
example { headers['Cache-Control'].should include('public') }
|
||||||
|
example { headers['Vary'].split(',').should_not include('Accept') }
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'version' do
|
||||||
|
before { get('/version') }
|
||||||
|
example { last_response.should be_ok }
|
||||||
|
example { headers['Content-Location'].should be == '/version' }
|
||||||
|
example { headers['Cache-Control'].should be == 'no-cache' }
|
||||||
|
example { headers['Vary'].split(',').should_not include('Accept') }
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user