FIX: Include entire slug path in permalinks

This is a temporary fix since these URLs should contain the id as well.
This commit is contained in:
Daniel Waterworth
2020-03-19 14:56:28 +00:00
parent 145c90419d
commit 1b24a7b993
2 changed files with 52 additions and 25 deletions

View File

@@ -661,36 +661,68 @@ describe Category do
end
describe "#url" do
it "builds a url for normal categories" do
category = Fabricate(:category_with_definition, name: "cats")
expect(category.url).to eq "/c/cats"
before_all do
SiteSetting.max_category_nesting = 3
end
fab!(:category) { Fabricate(:category, name: "root") }
fab!(:sub_category) do
Fabricate(
:category,
name: "child",
parent_category_id: category.id,
)
end
fab!(:sub_sub_category) do
Fabricate(
:category,
name: "child_of_child",
parent_category_id: sub_category.id,
)
end
describe "for normal categories" do
it "builds a url" do
expect(category.url).to eq("/c/root")
end
end
describe "for subcategories" do
it "includes the parent category" do
parent_category = Fabricate(:category_with_definition, name: "parent")
it "builds a url" do
expect(sub_category.url).to eq("/c/root/child")
end
end
subcategory =
Fabricate(
:category_with_definition,
name: "child",
parent_category_id: parent_category.id
)
expect(subcategory.url).to eq "/c/parent/child"
describe "for sub-sub-categories" do
it "builds a url" do
expect(sub_sub_category.url)
.to eq("/c/root/child/child-of-child")
end
end
end
describe "#url_with_id" do
fab!(:category) { Fabricate(:category_with_definition, name: 'cats') }
fab!(:category) do
Fabricate(
:category_with_definition,
name: 'cats',
)
end
it "includes the id in the URL" do
expect(category.url_with_id).to eq("/c/cats/#{category.id}")
end
context "child category" do
fab!(:child_category) { Fabricate(:category_with_definition, parent_category_id: category.id, name: 'dogs') }
fab!(:child_category) do
Fabricate(
:category,
parent_category_id: category.id,
name: 'dogs',
)
end
it "includes the id in the URL" do
expect(child_category.url_with_id).to eq("/c/cats/dogs/#{child_category.id}")