mirror of
https://github.com/discourse/discourse.git
synced 2025-09-06 09:10:25 +08:00
FIX: Make find_by_slug_path work with default slugs (#11501)
Default slugs are generated by adding '-category' to category ID.
This commit is contained in:
parent
142e0ae062
commit
806f05f851
4 changed files with 43 additions and 10 deletions
|
@ -1185,4 +1185,36 @@ describe Category do
|
|||
end
|
||||
end
|
||||
|
||||
describe "#find_by_slug_path" do
|
||||
it 'works for categories with slugs' do
|
||||
category = Fabricate(:category, slug: 'cat1')
|
||||
|
||||
expect(Category.find_by_slug_path(['cat1'])).to eq(category)
|
||||
end
|
||||
|
||||
it 'works for categories without slugs' do
|
||||
SiteSetting.slug_generation_method = 'none'
|
||||
|
||||
category = Fabricate(:category, slug: 'cat1')
|
||||
|
||||
expect(Category.find_by_slug_path(["#{category.id}-category"])).to eq(category)
|
||||
end
|
||||
|
||||
it 'works for subcategories with slugs' do
|
||||
category = Fabricate(:category, slug: 'cat1')
|
||||
subcategory = Fabricate(:category, slug: 'cat2', parent_category: category)
|
||||
|
||||
expect(Category.find_by_slug_path(['cat1', 'cat2'])).to eq(subcategory)
|
||||
end
|
||||
|
||||
it 'works for subcategories without slugs' do
|
||||
SiteSetting.slug_generation_method = 'none'
|
||||
|
||||
category = Fabricate(:category, slug: 'cat1')
|
||||
subcategory = Fabricate(:category, slug: 'cat2', parent_category: category)
|
||||
|
||||
expect(Category.find_by_slug_path(['cat1', "#{subcategory.id}-category"])).to eq(subcategory)
|
||||
expect(Category.find_by_slug_path(["#{category.id}-category", "#{subcategory.id}-category"])).to eq(subcategory)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue