|
4 | 4 |
|
5 | 5 | RSpec.describe "Managing Posts solved status" do
|
6 | 6 | let(:topic) { Fabricate(:topic) }
|
7 |
| - let(:user) { Fabricate(:trust_level_4) } |
| 7 | + fab!(:user) { Fabricate(:trust_level_4) } |
8 | 8 | let(:p1) { Fabricate(:post, topic: topic) }
|
9 | 9 |
|
10 | 10 | before { SiteSetting.allow_solved_on_all_topics = true }
|
|
39 | 39 | result = Search.execute("carrot")
|
40 | 40 | expect(result.posts.pluck(:id)).to eq([solved_post.id, normal_post.id])
|
41 | 41 | end
|
| 42 | + |
| 43 | + describe "#advanced_search" do |
| 44 | + fab!(:category_enabled) do |
| 45 | + category = Fabricate(:category) |
| 46 | + category_custom_field = |
| 47 | + CategoryCustomField.new( |
| 48 | + category_id: category.id, |
| 49 | + name: ::DiscourseSolved::ENABLE_ACCEPTED_ANSWERS_CUSTOM_FIELD, |
| 50 | + value: "true", |
| 51 | + ) |
| 52 | + category_custom_field.save |
| 53 | + category |
| 54 | + end |
| 55 | + fab!(:category_disabled) do |
| 56 | + category = Fabricate(:category) |
| 57 | + category_custom_field = |
| 58 | + CategoryCustomField.new( |
| 59 | + category_id: category.id, |
| 60 | + name: ::DiscourseSolved::ENABLE_ACCEPTED_ANSWERS_CUSTOM_FIELD, |
| 61 | + value: "false", |
| 62 | + ) |
| 63 | + category_custom_field.save |
| 64 | + category |
| 65 | + end |
| 66 | + fab!(:topic_unsolved) do |
| 67 | + Fabricate( |
| 68 | + :custom_topic, |
| 69 | + user: user, |
| 70 | + category: category_enabled, |
| 71 | + custom_topic_name: ::DiscourseSolved::ACCEPTED_ANSWER_POST_ID_CUSTOM_FIELD, |
| 72 | + ) |
| 73 | + end |
| 74 | + fab!(:topic_solved) do |
| 75 | + Fabricate( |
| 76 | + :custom_topic, |
| 77 | + user: user, |
| 78 | + category: category_enabled, |
| 79 | + custom_topic_name: ::DiscourseSolved::ACCEPTED_ANSWER_POST_ID_CUSTOM_FIELD, |
| 80 | + ) |
| 81 | + end |
| 82 | + fab!(:topic_disabled_1) do |
| 83 | + Fabricate( |
| 84 | + :custom_topic, |
| 85 | + user: user, |
| 86 | + category: category_disabled, |
| 87 | + custom_topic_name: ::DiscourseSolved::ACCEPTED_ANSWER_POST_ID_CUSTOM_FIELD, |
| 88 | + ) |
| 89 | + end |
| 90 | + fab!(:topic_disabled_2) do |
| 91 | + Fabricate( |
| 92 | + :custom_topic, |
| 93 | + user: user, |
| 94 | + category: category_disabled, |
| 95 | + custom_topic_name: "another_custom_field", |
| 96 | + ) |
| 97 | + end |
| 98 | + fab!(:post_unsolved) { Fabricate(:post, topic: topic_unsolved) } |
| 99 | + fab!(:post_solved) do |
| 100 | + post = Fabricate(:post, topic: topic_solved) |
| 101 | + DiscourseSolved.accept_answer!(post, Discourse.system_user) |
| 102 | + post |
| 103 | + end |
| 104 | + fab!(:post_disabled_1) { Fabricate(:post, topic: topic_disabled_1) } |
| 105 | + fab!(:post_disabled_2) { Fabricate(:post, topic: topic_disabled_2) } |
| 106 | + |
| 107 | + before do |
| 108 | + SearchIndexer.enable |
| 109 | + Jobs.run_immediately! |
| 110 | + |
| 111 | + SearchIndexer.index(topic_unsolved, force: true) |
| 112 | + SearchIndexer.index(topic_solved, force: true) |
| 113 | + SearchIndexer.index(topic_disabled_1, force: true) |
| 114 | + SearchIndexer.index(topic_disabled_2, force: true) |
| 115 | + end |
| 116 | + |
| 117 | + after { SearchIndexer.disable } |
| 118 | + |
| 119 | + describe "searches for unsolved topics" do |
| 120 | + describe "when allow solved on all topics is disabled" do |
| 121 | + before { SiteSetting.allow_solved_on_all_topics = false } |
| 122 | + |
| 123 | + it "only returns posts where 'Allow topic owner and staff to mark a reply as the solution' is enabled and post is not solved" do |
| 124 | + result = Search.execute("status:unsolved") |
| 125 | + expect(result.posts.pluck(:id)).to match_array([post_unsolved.id]) |
| 126 | + end |
| 127 | + end |
| 128 | + describe "when allow solved on all topics is enabled" do |
| 129 | + before { SiteSetting.allow_solved_on_all_topics = true } |
| 130 | + it "only returns posts where the post is not solved" do |
| 131 | + result = Search.execute("status:unsolved") |
| 132 | + expect(result.posts.pluck(:id)).to match_array( |
| 133 | + [post_unsolved.id, post_disabled_1.id, post_disabled_2.id], |
| 134 | + ) |
| 135 | + end |
| 136 | + end |
| 137 | + end |
| 138 | + end |
42 | 139 | end
|
43 | 140 |
|
44 | 141 | describe "auto bump" do
|
|
0 commit comments