mirror of
https://github.com/freeCodeCamp/devdocs
synced 2024-11-16 19:48:10 +01:00
parent
10fc8cf779
commit
6ce3aa2667
2 changed files with 28 additions and 8 deletions
18
lib/app.rb
18
lib/app.rb
|
@ -98,15 +98,19 @@ class App < Sinatra::Application
|
|||
browser.ie? && %w(6 7 8 9).include?(browser.version)
|
||||
end
|
||||
|
||||
def doc_index_urls
|
||||
cookie = cookies[:docs]
|
||||
def docs
|
||||
@docs ||= begin
|
||||
cookie = cookies[:docs]
|
||||
|
||||
docs = if cookie.nil? || cookie.empty?
|
||||
settings.default_docs
|
||||
else
|
||||
cookie.split('/')
|
||||
docs = if cookie.nil? || cookie.empty?
|
||||
settings.default_docs
|
||||
else
|
||||
cookie.split('/')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def doc_index_urls
|
||||
docs.inject [] do |result, slug|
|
||||
if doc = settings.docs[slug]
|
||||
result << File.join('', settings.docs_prefix, doc['index_path']) + "?#{doc['mtime']}"
|
||||
|
@ -212,6 +216,8 @@ class App < Sinatra::Application
|
|||
redirect "/#{doc}#{type}/#{query_string_for_redirection}"
|
||||
elsif rest.length > 1 && rest.end_with?('/')
|
||||
redirect "/#{doc}#{type}#{rest[0...-1]}#{query_string_for_redirection}"
|
||||
elsif docs.include?(doc) && browser.modern?
|
||||
redirect "/##{request.path}", 302
|
||||
else
|
||||
erb :other
|
||||
end
|
||||
|
|
|
@ -95,8 +95,22 @@ class AppTest < MiniTest::Spec
|
|||
end
|
||||
|
||||
describe "/[doc]" do
|
||||
it "works when the doc exists" do
|
||||
get '/html/'
|
||||
it "renders when the doc exists and isn't enabled" do
|
||||
set_cookie('docs=css')
|
||||
get '/html/', {}, 'HTTP_USER_AGENT' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:39.0) Gecko/20100101 Firefox/39.0'
|
||||
assert last_response.ok?
|
||||
end
|
||||
|
||||
it "redirects to root when the doc exists and is enabled" do
|
||||
set_cookie('docs=html')
|
||||
get '/html/', {}, 'HTTP_USER_AGENT' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:39.0) Gecko/20100101 Firefox/39.0'
|
||||
assert last_response.redirect?
|
||||
assert_equal 'http://example.org/#/html/', last_response['Location']
|
||||
end
|
||||
|
||||
it "renders when the doc exists and is enabled, and the request is from Googlebot" do
|
||||
set_cookie('docs=html')
|
||||
get '/html/', {}, 'HTTP_USER_AGENT' => 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)'
|
||||
assert last_response.ok?
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue