Simplify version path separator

Ref #25.
pull/308/merge
Thibaut Courouble 9 years ago
parent fd2907d1bc
commit 16ddcb100c

@ -4,7 +4,7 @@ class app.models.Doc extends app.Model
constructor: ->
super
@reset @
@slug_without_version = @slug.split('~v')[0]
@slug_without_version = @slug.split('~')[0]
@fullName = "#{@name}" + if @version then " #{@version}" else ''
@icon = @slug_without_version
@text = @toEntry().text

@ -123,7 +123,7 @@ class App < Sinatra::Application
def find_doc(slug)
settings.docs[slug] || begin
slug = "#{slug}~v"
slug = "#{slug}~"
settings.docs.each do |_slug, _doc|
return _doc if _slug.start_with?(slug)
end
@ -133,7 +133,7 @@ class App < Sinatra::Application
def user_has_docs?(slug)
docs.include?(slug) || begin
slug = "#{slug}~v"
slug = "#{slug}~"
docs.any? { |_slug| _slug.start_with?(slug) }
end
end

@ -48,7 +48,7 @@ module Docs
def slug
slug = @slug || name.try(:downcase)
version? ? "#{slug}~v#{version}" : slug
version? ? "#{slug}~#{version}" : slug
end
def path

@ -80,11 +80,11 @@ class AppTest < MiniTest::Spec
end
it "works with cookie" do
set_cookie('docs=css/html~v5')
set_cookie('docs=css/html~5')
get '/manifest.appcache'
assert last_response.ok?
assert_includes last_response.body, '/css/index.json?1420139788'
assert_includes last_response.body, '/html~v5/index.json?1420139791'
assert_includes last_response.body, '/html~5/index.json?1420139791'
end
it "ignores invalid docs in the cookie" do
@ -127,17 +127,17 @@ class AppTest < MiniTest::Spec
describe "/[doc]" do
it "renders when the doc exists and isn't enabled" do
set_cookie('docs=html~v5')
get '/html~v4/', {}, 'HTTP_USER_AGENT' => MODERN_BROWSER
set_cookie('docs=html~5')
get '/html~4/', {}, 'HTTP_USER_AGENT' => MODERN_BROWSER
assert last_response.ok?
end
it "redirects via JS cookie when the doc exists and is enabled" do
set_cookie('docs=html~v5')
get '/html~v5/', {}, 'HTTP_USER_AGENT' => MODERN_BROWSER
set_cookie('docs=html~5')
get '/html~5/', {}, 'HTTP_USER_AGENT' => MODERN_BROWSER
assert last_response.redirect?
assert_equal 'http://example.org/', last_response['Location']
assert last_response['Set-Cookie'].start_with?("initial_path=%2Fhtml%7Ev5%2F; path=/; expires=")
assert last_response['Set-Cookie'].start_with?("initial_path=%2Fhtml%7E5%2F; path=/; expires=")
end
it "renders when the doc exists, has no version in the path, and isn't enabled" do
@ -146,7 +146,7 @@ class AppTest < MiniTest::Spec
end
it "redirects via JS cookie when the doc exists, has no version in the path, and a version is enabled" do
set_cookie('docs=html~v5')
set_cookie('docs=html~5')
get '/html/', {}, 'HTTP_USER_AGENT' => MODERN_BROWSER
assert last_response.redirect?
assert_equal 'http://example.org/', last_response['Location']
@ -160,7 +160,7 @@ class AppTest < MiniTest::Spec
end
it "returns 404 when the doc doesn't exist" do
get '/html~v6/'
get '/html~6/'
assert last_response.not_found?
end
@ -177,15 +177,15 @@ class AppTest < MiniTest::Spec
describe "/[doc]-[type]" do
it "works when the doc exists" do
get '/html~v4-foo-bar_42/'
get '/html~4-foo-bar_42/'
assert last_response.ok?
assert_includes last_response.body, 'app.DOC = {"name":"HTML","slug":"html~v4"'
assert_includes last_response.body, 'app.DOC = {"name":"HTML","slug":"html~4"'
end
it "works when the doc has no version in the path and a version exists" do
get '/html-foo-bar_42/'
assert last_response.ok?
assert_includes last_response.body, 'app.DOC = {"name":"HTML","slug":"html~v5"'
assert_includes last_response.body, 'app.DOC = {"name":"HTML","slug":"html~5"'
end
it "returns 404 when the type is blank" do
@ -199,7 +199,7 @@ class AppTest < MiniTest::Spec
end
it "returns 404 when the doc doesn't exist" do
get '/html~v6-bar/'
get '/html~6-bar/'
assert last_response.not_found?
end

@ -1 +1 @@
[{"name":"CSS","slug":"css","type":"mdn","release":null,"mtime":1420139788,"db_size":3460507},{"name":"DOM","slug":"dom","type":"mdn","release":null,"mtime":1420139789,"db_size":11399128},{"name":"DOM Events","slug":"dom_events","type":"mdn","release":null,"mtime":1420139790,"db_size":889020},{"name":"HTML","slug":"html~v5","type":"mdn","version":"5","mtime":1420139791,"db_size":1835647},{"name":"HTML","slug":"html~v4","type":"mdn","version":"4","mtime":1420139790,"db_size":1835646},{"name":"HTTP","slug":"http","type":"rfc","release":null,"mtime":1420139790,"db_size":183083},{"name":"JavaScript","slug":"javascript","type":"mdn","release":null,"mtime":1420139791,"db_size":4125477}]
[{"name":"CSS","slug":"css","type":"mdn","release":null,"mtime":1420139788,"db_size":3460507},{"name":"DOM","slug":"dom","type":"mdn","release":null,"mtime":1420139789,"db_size":11399128},{"name":"DOM Events","slug":"dom_events","type":"mdn","release":null,"mtime":1420139790,"db_size":889020},{"name":"HTML","slug":"html~5","type":"mdn","version":"5","mtime":1420139791,"db_size":1835647},{"name":"HTML","slug":"html~4","type":"mdn","version":"4","mtime":1420139790,"db_size":1835646},{"name":"HTTP","slug":"http","type":"rfc","release":null,"mtime":1420139790,"db_size":183083},{"name":"JavaScript","slug":"javascript","type":"mdn","release":null,"mtime":1420139791,"db_size":4125477}]

@ -45,15 +45,15 @@ class DocsDocTest < MiniTest::Spec
assert_equal 'doc', Docs::Doc.slug
end
it "returns 'doc~v42' when the class is Docs::Doc and its #version is '42'" do
it "returns 'doc~42' when the class is Docs::Doc and its #version is '42'" do
stub(Docs::Doc).version { '42' }
assert_equal 'doc~v42', Docs::Doc.slug
assert_equal 'doc~42', Docs::Doc.slug
end
it "returns 'foo~v42' when #slug has been set to 'foo' and #version to '42'" do
it "returns 'foo~42' when #slug has been set to 'foo' and #version to '42'" do
doc.slug = 'foo'
doc.version = '42'
assert_equal 'foo~v42', doc.slug
assert_equal 'foo~42', doc.slug
end
end

Loading…
Cancel
Save