DEV: Server-side category routing changes

The routes for categories are changing. The scheme that I intend to move
us to is:

/c/*slug_path/(:id)/ENDPOINT
/c/*slug_path/(:id)

This commit adds support for the new scheme to the server side without
dropping support for existing URLs. It is necessary to support existing
URLs for two reasons:

 * This commit does not change any client side routing code,
 * Posts that contain category hashtags that refer to a root category
   are baked into URLs that do not fit this new scheme, (/c/[id]-[slug])
This commit is contained in:
Daniel Waterworth
2019-10-30 17:22:32 +00:00
parent 4434f419c6
commit d84c34ad75
4 changed files with 87 additions and 78 deletions

View File

@ -380,19 +380,15 @@ RSpec.describe ListController do
let(:child_category) { Fabricate(:category_with_definition, parent_category: category) }
context "with valid slug" do
it "redirects to the child category" do
get "/c/#{category.slug}/#{child_category.slug}/l/latest", params: {
id: child_category.id
}
expect(response).to redirect_to(child_category.url)
it "succeeds" do
get "/c/#{category.slug}/#{child_category.slug}/#{child_category.id}/l/latest"
expect(response.status).to eq(200)
end
end
context "with invalid slug" do
it "redirects to child category" do
get "/c/random_slug/another_random_slug/l/latest", params: {
id: child_category.id
}
xit "redirects" do
get "/c/random_slug/another_random_slug/#{child_category.id}/l/latest"
expect(response).to redirect_to(child_category.url)
end
end