mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 17:46:05 -05:00
Fix subcategories links from search
This commit is contained in:
parent
22af3fe085
commit
f723f11443
3 changed files with 22 additions and 1 deletions
|
@ -353,6 +353,12 @@ SQL
|
||||||
def uncategorized?
|
def uncategorized?
|
||||||
id == SiteSetting.uncategorized_category_id
|
id == SiteSetting.uncategorized_category_id
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def url
|
||||||
|
url = "/category"
|
||||||
|
url << "/#{parent_category.slug}" if parent_category_id
|
||||||
|
url << "/#{slug}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# == Schema Information
|
# == Schema Information
|
||||||
|
|
|
@ -24,7 +24,7 @@ class Search
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.from_category(c)
|
def self.from_category(c)
|
||||||
SearchResult.new(type: :category, id: c.id, title: c.name, url: "/category/#{c.slug}").tap do |r|
|
SearchResult.new(type: :category, id: c.id, title: c.name, url: c.url).tap do |r|
|
||||||
r.color = c.color
|
r.color = c.color
|
||||||
r.text_color = c.text_color
|
r.text_color = c.text_color
|
||||||
end
|
end
|
||||||
|
|
|
@ -348,6 +348,21 @@ describe Category do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "#url" do
|
||||||
|
it "builds a url for normal categories" do
|
||||||
|
category = Fabricate(:category, name: "cats")
|
||||||
|
expect(category.url).to eq "/category/cats"
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "for subcategories" do
|
||||||
|
it "includes the parent category" do
|
||||||
|
parent_category = Fabricate(:category, name: "parent")
|
||||||
|
subcategory = Fabricate(:category, name: "child",
|
||||||
|
parent_category_id: parent_category.id)
|
||||||
|
expect(subcategory.url).to eq "/category/parent/child"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "parent categories" do
|
describe "parent categories" do
|
||||||
let(:user) { Fabricate(:user) }
|
let(:user) { Fabricate(:user) }
|
||||||
|
|
Loading…
Reference in a new issue