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:
Bianca Nenciu
2020-12-18 16:05:01 +02:00
committed by GitHub
parent 142e0ae062
commit 806f05f851
4 changed files with 43 additions and 10 deletions

View File

@ -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