From 01b5a118d02f9148c9174b289ab4ce2a26d6fc7a Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Mon, 22 Oct 2012 21:23:34 +0200 Subject: [PATCH] spec and fix app --- lib/travis/web/app.rb | 14 +++++++++++--- spec/app_spec.rb | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 spec/app_spec.rb diff --git a/lib/travis/web/app.rb b/lib/travis/web/app.rb index 2bc3ad70..a14fa460 100644 --- a/lib/travis/web/app.rb +++ b/lib/travis/web/app.rb @@ -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 diff --git a/spec/app_spec.rb b/spec/app_spec.rb new file mode 100644 index 00000000..869232f3 --- /dev/null +++ b/spec/app_spec.rb @@ -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