mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 16:34:31 +08:00
FEATURE: new search filter - #category-slug
This commit is contained in:
@ -526,6 +526,24 @@ describe Search do
|
||||
expect(Search.execute('sam order:latest').posts.map(&:id)).to eq([post2.id, post1.id])
|
||||
|
||||
end
|
||||
|
||||
it 'supports category slug' do
|
||||
# main category
|
||||
category = Fabricate(:category, name: 'category 24', slug: 'category-24')
|
||||
topic = Fabricate(:topic, created_at: 3.months.ago, category: category)
|
||||
post = Fabricate(:post, raw: 'hi this is a test 123', topic: topic)
|
||||
|
||||
expect(Search.execute('this is a test #category-24').posts.length).to eq(1)
|
||||
expect(Search.execute('this is a test #category-25').posts.length).to eq(0)
|
||||
|
||||
# sub category
|
||||
sub_category = Fabricate(:category, name: 'sub category', slug: 'sub-category', parent_category_id: category.id)
|
||||
second_topic = Fabricate(:topic, created_at: 3.months.ago, category: sub_category)
|
||||
second_topic_post = Fabricate(:post, raw: 'hi testing again 123', topic: second_topic)
|
||||
|
||||
expect(Search.execute('testing again #category-24:sub-category').posts.length).to eq(1)
|
||||
expect(Search.execute('testing again #sub-category').posts.length).to eq(0)
|
||||
end
|
||||
end
|
||||
|
||||
it 'can parse complex strings using ts_query helper' do
|
||||
@ -566,4 +584,3 @@ describe Search do
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user