|
9 | 9 | before { SearchIndexer.enable }
|
10 | 10 | after { SearchIndexer.disable }
|
11 | 11 |
|
| 12 | + fab!(:parent_category) { Fabricate(:category, name: "animals") } |
| 13 | + fab!(:category) { Fabricate(:category, parent_category: parent_category, name: "amazing-cat") } |
| 14 | + |
| 15 | + fab!(:tag_funny) { Fabricate(:tag, name: "funny") } |
| 16 | + fab!(:tag_sad) { Fabricate(:tag, name: "sad") } |
| 17 | + fab!(:tag_hidden) { Fabricate(:tag, name: "hidden") } |
| 18 | + fab!(:staff_tag_group) do |
| 19 | + tag_group = Fabricate.build(:tag_group, name: "Staff only", tag_names: ["hidden"]) |
| 20 | + |
| 21 | + tag_group.permissions = [ |
| 22 | + [Group::AUTO_GROUPS[:staff], TagGroupPermission.permission_types[:full]], |
| 23 | + ] |
| 24 | + tag_group.save! |
| 25 | + tag_group |
| 26 | + end |
| 27 | + fab!(:topic_with_tags) do |
| 28 | + Fabricate(:topic, category: category, tags: [tag_funny, tag_sad, tag_hidden]) |
| 29 | + end |
| 30 | + |
12 | 31 | describe "#process" do
|
13 | 32 | it "can handle no results" do
|
14 |
| - post1 = Fabricate(:post) |
| 33 | + post1 = Fabricate(:post, topic: topic_with_tags) |
15 | 34 | search = described_class.new(bot_user: bot_user, post: post1, args: nil)
|
16 | 35 |
|
17 | 36 | results = search.process(query: "order:fake ABDDCDCEDGDG")
|
|
42 | 61 | hyde_embedding,
|
43 | 62 | )
|
44 | 63 |
|
45 |
| - post1 = Fabricate(:post) |
| 64 | + post1 = Fabricate(:post, topic: topic_with_tags) |
46 | 65 | search = described_class.new(bot_user: bot_user, post: post1, args: nil)
|
47 | 66 |
|
48 | 67 | DiscourseAi::Embeddings::VectorRepresentations::AllMpnetBaseV2
|
|
60 | 79 | it "supports subfolder properly" do
|
61 | 80 | Discourse.stubs(:base_path).returns("/subfolder")
|
62 | 81 |
|
63 |
| - post1 = Fabricate(:post) |
| 82 | + post1 = Fabricate(:post, topic: topic_with_tags) |
64 | 83 |
|
65 | 84 | search = described_class.new(bot_user: bot_user, post: post1, args: nil)
|
66 | 85 |
|
67 | 86 | results = search.process(limit: 1, user: post1.user.username)
|
68 | 87 | expect(results[:rows].to_s).to include("/subfolder" + post1.url)
|
69 | 88 | end
|
70 | 89 |
|
| 90 | + it "returns category and tags" do |
| 91 | + post1 = Fabricate(:post, topic: topic_with_tags) |
| 92 | + search = described_class.new(bot_user: bot_user, post: post1, args: nil) |
| 93 | + results = search.process(user: post1.user.username) |
| 94 | + |
| 95 | + row = results[:rows].first |
| 96 | + category = row[results[:column_names].index("category")] |
| 97 | + |
| 98 | + expect(category).to eq("animals > amazing-cat") |
| 99 | + |
| 100 | + tags = row[results[:column_names].index("tags")] |
| 101 | + expect(tags).to eq("funny, sad") |
| 102 | + end |
| 103 | + |
71 | 104 | it "can handle limits" do
|
72 |
| - post1 = Fabricate(:post) |
| 105 | + post1 = Fabricate(:post, topic: topic_with_tags) |
73 | 106 | _post2 = Fabricate(:post, user: post1.user)
|
74 | 107 | _post3 = Fabricate(:post, user: post1.user)
|
75 | 108 |
|
|
78 | 111 |
|
79 | 112 | results = search.process(limit: 2, user: post1.user.username)
|
80 | 113 |
|
81 |
| - expect(results[:column_names].length).to eq(4) |
82 | 114 | expect(results[:rows].length).to eq(2)
|
83 | 115 |
|
84 | 116 | # just searching for everything
|
|
0 commit comments