Fix passing alt=default param

This commit is contained in:
Piotr Sarnacki 2013-03-05 21:08:14 +01:00
parent 1e6067f54c
commit 4bdd1834c4
2 changed files with 6 additions and 5 deletions

View File

@ -7,7 +7,7 @@ class Travis::Web::App::AltVersions
def call(env) def call(env)
alt = alt_from_params(env) || alt_from_cookie(env) alt = alt_from_params(env) || alt_from_cookie(env)
env['travis.alt'] = alt if alt env['travis.alt'] = alt if alt && alt != 'default'
status, headers, body = app.call(env) status, headers, body = app.call(env)
headers['Set-Cookie'] = cookie(alt) if alt headers['Set-Cookie'] = cookie(alt) if alt
[status, headers, body] [status, headers, body]
@ -16,14 +16,14 @@ class Travis::Web::App::AltVersions
private private
def cookie(alt) def cookie(alt)
"alt=#{alt}; path=/; max-age=#{alt == 'default' ? 0 : 86400}" "alt=#{alt == 'default' ? '' : alt}; path=/; max-age=#{alt == 'default' ? 0 : 86400}"
end end
def alt_from_params(env) def alt_from_params(env)
$1 if env['QUERY_STRING'] =~ /alt=([^&]*)/ $1 if env['QUERY_STRING'] =~ /alt=([^&]+)/
end end
def alt_from_cookie(env) def alt_from_cookie(env)
$1 if env['HTTP_COOKIE'] =~ /alt=([^;]*)/ $1 if env['HTTP_COOKIE'] =~ /alt=([^;]+)/
end end
end end

View File

@ -47,7 +47,8 @@ describe Travis::Web::App do
context 'passing default as an alt param' do context 'passing default as an alt param' do
before { get('/?alt=default') } before { get('/?alt=default') }
example { headers['Set-Cookie'].should == 'alt=default; path=/; max-age=0' } example { last_response.body.should_not =~ /\/assets\/[^\/]+\/scripts\/app.js/ }
example { headers['Set-Cookie'].should == 'alt=; path=/; max-age=0' }
end end
end end
end end