wiki pages: use names instead of ids in urls.

Switching to using wiki names in URLs instead of IDs:

* https://danbooru.donami.us/wiki_pages/vocaloid
* https://danbooru.donami.us/wiki_pages/hatsune_miku

ID numbers can still be used, but they redirect to the name instead:

* https://danbooru.donami.us/wiki_pages/11 (redirects to /wiki_pages/touhou).

Numeric tags are prefixed with '~' to distinguish them from IDs:

* https://danbooru.donami.us/wiki_pages/2019 (the wiki with id 2019)
* https://danbooru.donami.us/wiki_pages/~2019 (the wiki for the tag named 2019)

The tag names 'new' and 'search' are disallowed to prevent conflicts
with existing routes:

* https://danbooru.donami.us/wiki_pages/new
* https://danbooru.donami.us/wiki_pages/search
This commit is contained in:
evazion
2019-10-31 04:07:21 -05:00
parent 0ccfb3f5f6
commit 3a908f84bb
14 changed files with 76 additions and 38 deletions

View File

@@ -40,13 +40,29 @@ class WikiPagesControllerTest < ActionDispatch::IntegrationTest
end
end
should "render" do
get wiki_page_path(@wiki_page)
should "redirect to the title for an id" do
get wiki_page_path(@wiki_page.id)
assert_redirected_to wiki_page_path(@wiki_page.title)
get wiki_page_path(@wiki_page.id), as: :json
assert_response :success
end
should "distinguish between an id and a title" do
as(@user) { @wiki_page.update(title: "2019") }
get wiki_page_path("~2019")
assert_response :success
get wiki_page_path(@wiki_page.id)
assert_redirected_to wiki_page_path("~2019")
get wiki_page_path("2019")
assert_response 404
end
should "render for a title" do
get wiki_page_path(:id => @wiki_page.title)
get wiki_page_path(@wiki_page.title)
assert_response :success
end
@@ -64,8 +80,9 @@ class WikiPagesControllerTest < ActionDispatch::IntegrationTest
as_user do
@wiki_page.update(title: "-aaa")
end
get wiki_page_path(:id => @wiki_page.id)
assert_response :success
get wiki_page_path(@wiki_page.id)
assert_redirected_to wiki_page_path(@wiki_page.title)
end
end

View File

@@ -695,7 +695,7 @@ class PostTest < ActiveSupport::TestCase
context "that already exists" do
setup do
%W(___ ~foo _foo foo_ foo__bar foo*bar foo,bar foo\abar café 東方).each do |tag|
%W(___ ~foo _foo foo_ foo__bar foo*bar foo,bar foo\abar café 東方 new search).each do |tag|
build(:tag, name: tag).save(validate: false)
end
end
@@ -710,6 +710,8 @@ class PostTest < ActiveSupport::TestCase
assert_invalid_tag("foo\abar")
assert_invalid_tag("café")
assert_invalid_tag("東方")
assert_invalid_tag("new")
assert_invalid_tag("search")
end
end