spec and fix app

This commit is contained in:
Konstantin Haase 2012-10-22 21:23:34 +02:00
parent d6986a7806
commit 01b5a118d0
2 changed files with 44 additions and 3 deletions

View File

@ -60,7 +60,7 @@ class Travis::Web::App
'ETag' => version,
'Last-Modified' => last_modified.httpdate,
'Expires' => (last_modified + age).httpdate,
'Vary' => ''
'Vary' => vary_for(file)
}
[ 200, headers, [ content ] ]
@ -92,12 +92,20 @@ class Travis::Web::App
def cache_control(file)
case route_for(file)
when '/' then "public, must-revalidate"
when 'version' then "no-cache"
when '/' then "public, must-revalidate"
when '/version' then "no-cache"
else "public, max-age=#{age}"
end
end
def vary_for(file)
case route_for(file)
when '/' then 'Accept'
when '/version' then '*'
else ''
end
end
def mime_type(file)
Rack::Mime.mime_type File.extname(file)
end

33
spec/app_spec.rb Normal file
View 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