@ -11,6 +11,16 @@ class AppTest < MiniTest::Spec
App
App
end
end
before do
current_session . env ( 'HTTPS' , 'on' )
end
it 'redirects to HTTPS' do
get 'http://example.com/test?q=1' , { } , 'HTTPS' = > 'off'
assert last_response . redirect?
assert_equal 'https://example.com/test?q=1' , last_response [ 'Location' ]
end
describe " / " do
describe " / " do
it " works " do
it " works " do
get '/'
get '/'
@ -20,13 +30,13 @@ class AppTest < MiniTest::Spec
it " redirects to / # q= when there is a 'q' query param " do
it " redirects to / # q= when there is a 'q' query param " do
get '/search' , q : 'foo'
get '/search' , q : 'foo'
assert last_response . redirect?
assert last_response . redirect?
assert_equal 'http ://example.org/#q=foo', last_response [ 'Location' ]
assert_equal 'http s ://example.org/#q=foo', last_response [ 'Location' ]
end
end
it " redirects without the query string " do
it " redirects without the query string " do
get '/' , foo : 'bar'
get '/' , foo : 'bar'
assert last_response . redirect?
assert last_response . redirect?
assert_equal 'http ://example.org/', last_response [ 'Location' ]
assert_equal 'http s ://example.org/', last_response [ 'Location' ]
end
end
it " sets default size " do
it " sets default size " do
@ -52,7 +62,7 @@ class AppTest < MiniTest::Spec
%w( offline about news help ) . each do | page |
%w( offline about news help ) . each do | page |
get " / #{ page } " , { } , 'HTTP_USER_AGENT' = > MODERN_BROWSER
get " / #{ page } " , { } , 'HTTP_USER_AGENT' = > MODERN_BROWSER
assert last_response . redirect?
assert last_response . redirect?
assert_equal " http ://example.org/# / #{ page } " , last_response [ 'Location' ]
assert_equal " http s ://example.org/# / #{ page } " , last_response [ 'Location' ]
end
end
end
end
@ -61,7 +71,7 @@ class AppTest < MiniTest::Spec
set_cookie ( 'foo=bar' )
set_cookie ( 'foo=bar' )
get " / #{ page } " , { } , 'HTTP_USER_AGENT' = > MODERN_BROWSER
get " / #{ page } " , { } , 'HTTP_USER_AGENT' = > MODERN_BROWSER
assert last_response . redirect?
assert last_response . redirect?
assert_equal 'http ://example.org/', last_response [ 'Location' ]
assert_equal 'http s ://example.org/', last_response [ 'Location' ]
assert last_response [ 'Set-Cookie' ] . start_with? ( " initial_path=%2F #{ page } ; path=/; expires= " )
assert last_response [ 'Set-Cookie' ] . start_with? ( " initial_path=%2F #{ page } ; path=/; expires= " )
end
end
end
end
@ -71,11 +81,11 @@ class AppTest < MiniTest::Spec
it " redirects to / # q= " do
it " redirects to / # q= " do
get '/search'
get '/search'
assert last_response . redirect?
assert last_response . redirect?
assert_equal 'http ://example.org/#q=', last_response [ 'Location' ]
assert_equal 'http s ://example.org/#q=', last_response [ 'Location' ]
get '/search' , q : 'foo'
get '/search' , q : 'foo'
assert last_response . redirect?
assert last_response . redirect?
assert_equal 'http ://example.org/#q=foo', last_response [ 'Location' ]
assert_equal 'http s ://example.org/#q=foo', last_response [ 'Location' ]
end
end
end
end
@ -148,7 +158,7 @@ class AppTest < MiniTest::Spec
set_cookie ( 'docs=html~5' )
set_cookie ( 'docs=html~5' )
get '/html~5/' , { } , 'HTTP_USER_AGENT' = > MODERN_BROWSER
get '/html~5/' , { } , 'HTTP_USER_AGENT' = > MODERN_BROWSER
assert last_response . redirect?
assert last_response . redirect?
assert_equal 'http ://example.org/', last_response [ 'Location' ]
assert_equal 'http s ://example.org/', last_response [ 'Location' ]
assert last_response [ 'Set-Cookie' ] . start_with? ( " initial_path=%2Fhtml%7E5%2F; path=/; expires= " )
assert last_response [ 'Set-Cookie' ] . start_with? ( " initial_path=%2Fhtml%7E5%2F; path=/; expires= " )
end
end
@ -161,13 +171,13 @@ class AppTest < MiniTest::Spec
set_cookie ( 'docs=html~5' )
set_cookie ( 'docs=html~5' )
get '/html/' , { } , 'HTTP_USER_AGENT' = > MODERN_BROWSER
get '/html/' , { } , 'HTTP_USER_AGENT' = > MODERN_BROWSER
assert last_response . redirect?
assert last_response . redirect?
assert_equal 'http ://example.org/', last_response [ 'Location' ]
assert_equal 'http s ://example.org/', last_response [ 'Location' ]
assert last_response [ 'Set-Cookie' ] . start_with? ( " initial_path=%2Fhtml%2F; path=/; expires= " )
assert last_response [ 'Set-Cookie' ] . start_with? ( " initial_path=%2Fhtml%2F; path=/; expires= " )
end
end
it " renders when the doc exists and is enabled, and the request is from Googlebot " do
it " renders when the doc exists and is enabled, and the request is from Googlebot " do
set_cookie ( 'docs=html' )
set_cookie ( 'docs=html' )
get '/html/' , { } , 'HTTP_USER_AGENT' = > 'Mozilla/5.0 (compatible; Googlebot/2.1; +http ://www.google.com/bot.html)'
get '/html/' , { } , 'HTTP_USER_AGENT' = > 'Mozilla/5.0 (compatible; Googlebot/2.1; +http s ://www.google.com/bot.html)'
assert last_response . ok?
assert last_response . ok?
end
end
@ -187,17 +197,17 @@ class AppTest < MiniTest::Spec
it " redirects with trailing slash " do
it " redirects with trailing slash " do
get '/html'
get '/html'
assert last_response . redirect?
assert last_response . redirect?
assert_equal 'http ://example.org/html/', last_response [ 'Location' ]
assert_equal 'http s ://example.org/html/', last_response [ 'Location' ]
get '/html' , bar : 'baz'
get '/html' , bar : 'baz'
assert last_response . redirect?
assert last_response . redirect?
assert_equal 'http ://example.org/html/?bar=baz', last_response [ 'Location' ]
assert_equal 'http s ://example.org/html/?bar=baz', last_response [ 'Location' ]
end
end
it " redirects old docs " do
it " redirects old docs " do
get '/iojs/'
get '/iojs/'
assert last_response . redirect?
assert last_response . redirect?
assert_equal 'http ://example.org/node/', last_response [ 'Location' ]
assert_equal 'http s ://example.org/node/', last_response [ 'Location' ]
end
end
end
end
@ -232,17 +242,17 @@ class AppTest < MiniTest::Spec
it " redirects with trailing slash " do
it " redirects with trailing slash " do
get '/css-foo'
get '/css-foo'
assert last_response . redirect?
assert last_response . redirect?
assert_equal 'http ://example.org/css-foo/', last_response [ 'Location' ]
assert_equal 'http s ://example.org/css-foo/', last_response [ 'Location' ]
get '/css-foo' , bar : 'baz'
get '/css-foo' , bar : 'baz'
assert last_response . redirect?
assert last_response . redirect?
assert_equal 'http ://example.org/css-foo/?bar=baz', last_response [ 'Location' ]
assert_equal 'http s ://example.org/css-foo/?bar=baz', last_response [ 'Location' ]
end
end
it " redirects old docs " do
it " redirects old docs " do
get '/yii1-foo/'
get '/yii1-foo/'
assert last_response . redirect?
assert last_response . redirect?
assert_equal 'http ://example.org/yii~1.1-foo/', last_response [ 'Location' ]
assert_equal 'http s ://example.org/yii~1.1-foo/', last_response [ 'Location' ]
end
end
end
end
@ -263,17 +273,17 @@ class AppTest < MiniTest::Spec
it " redirects without trailing slash " do
it " redirects without trailing slash " do
get '/css/foo/'
get '/css/foo/'
assert last_response . redirect?
assert last_response . redirect?
assert_equal 'http ://example.org/css/foo', last_response [ 'Location' ]
assert_equal 'http s ://example.org/css/foo', last_response [ 'Location' ]
get '/css/foo/' , bar : 'baz'
get '/css/foo/' , bar : 'baz'
assert last_response . redirect?
assert last_response . redirect?
assert_equal 'http ://example.org/css/foo?bar=baz', last_response [ 'Location' ]
assert_equal 'http s ://example.org/css/foo?bar=baz', last_response [ 'Location' ]
end
end
it " redirects old docs " do
it " redirects old docs " do
get '/python2/foo'
get '/python2/foo'
assert last_response . redirect?
assert last_response . redirect?
assert_equal 'http ://example.org/python~2.7/foo', last_response [ 'Location' ]
assert_equal 'http s ://example.org/python~2.7/foo', last_response [ 'Location' ]
end
end
end
end
@ -281,7 +291,7 @@ class AppTest < MiniTest::Spec
it " returns to the asset path " do
it " returns to the asset path " do
get '/docs.json'
get '/docs.json'
assert last_response . redirect?
assert last_response . redirect?
assert_equal 'http ://example.org/assets/docs.json', last_response [ 'Location' ]
assert_equal 'http s ://example.org/assets/docs.json', last_response [ 'Location' ]
end
end
end
end
@ -289,7 +299,7 @@ class AppTest < MiniTest::Spec
it " returns to the asset path " do
it " returns to the asset path " do
get '/application.js'
get '/application.js'
assert last_response . redirect?
assert last_response . redirect?
assert_equal 'http ://example.org/assets/application.js', last_response [ 'Location' ]
assert_equal 'http s ://example.org/assets/application.js', last_response [ 'Location' ]
end
end
end
end
@ -297,7 +307,7 @@ class AppTest < MiniTest::Spec
it " returns to the asset path " do
it " returns to the asset path " do
get '/application.css'
get '/application.css'
assert last_response . redirect?
assert last_response . redirect?
assert_equal 'http ://example.org/assets/application.css', last_response [ 'Location' ]
assert_equal 'http s ://example.org/assets/application.css', last_response [ 'Location' ]
end
end
end
end