From 01517f8c78b0d36b4c7417f4abb5e4d5a5bdbd01 Mon Sep 17 00:00:00 2001 From: Thibaut Courouble Date: Sat, 5 Mar 2016 12:49:43 -0500 Subject: [PATCH] Add redirections for deleted docs --- lib/app.rb | 8 +++++++- test/app_test.rb | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/app.rb b/lib/app.rb index faef0d55..7740535b 100644 --- a/lib/app.rb +++ b/lib/app.rb @@ -270,8 +270,14 @@ class App < Sinatra::Application settings.news_feed end + DOC_REDIRECTS = { + 'iojs' => 'node', + 'yii1' => 'yii~1.1', + 'python2' => 'python~2.7' + } + get %r{\A/([\w~\.]+)(\-[\w\-]+)?(/.*)?\z} do |doc, type, rest| - return redirect "/node#{type}#{rest}" if doc == 'iojs' + return redirect "/#{DOC_REDIRECTS[doc]}#{type}#{rest}" if DOC_REDIRECTS.key?(doc) return 404 unless @doc = find_doc(doc) if rest.nil? diff --git a/test/app_test.rb b/test/app_test.rb index 01660b47..eebab3aa 100644 --- a/test/app_test.rb +++ b/test/app_test.rb @@ -173,6 +173,12 @@ class AppTest < MiniTest::Spec assert last_response.redirect? assert_equal 'http://example.org/html/?bar=baz', last_response['Location'] end + + it "redirects old docs" do + get '/iojs/' + assert last_response.redirect? + assert_equal 'http://example.org/node/', last_response['Location'] + end end describe "/[doc]-[type]" do @@ -212,6 +218,12 @@ class AppTest < MiniTest::Spec assert last_response.redirect? assert_equal 'http://example.org/css-foo/?bar=baz', last_response['Location'] end + + it "redirects old docs" do + get '/yii1-foo/' + assert last_response.redirect? + assert_equal 'http://example.org/yii~1.1-foo/', last_response['Location'] + end end describe "/[doc+type]/[path]" do @@ -237,6 +249,12 @@ class AppTest < MiniTest::Spec assert last_response.redirect? assert_equal 'http://example.org/css/foo?bar=baz', last_response['Location'] end + + it "redirects old docs" do + get '/python2/foo' + assert last_response.redirect? + assert_equal 'http://example.org/python~2.7/foo', last_response['Location'] + end end describe "/docs.json" do