2021-01-20 05:26:37 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-12-23 15:36:08 -05:00
|
|
|
require "rails_helper"
|
|
|
|
require "post_revisor"
|
2021-01-20 05:26:37 -05:00
|
|
|
|
|
|
|
describe PostRevisor do
|
|
|
|
fab!(:category) { Fabricate(:category_with_definition) }
|
2021-09-17 10:12:47 -04:00
|
|
|
fab!(:admin) { Fabricate(:admin) }
|
2021-01-20 05:26:37 -05:00
|
|
|
|
|
|
|
fab!(:category_solved) do
|
|
|
|
category = Fabricate(:category_with_definition)
|
|
|
|
category.upsert_custom_fields("enable_accepted_answers" => "true")
|
|
|
|
category
|
|
|
|
end
|
|
|
|
|
|
|
|
it "refreshes post stream when topic category changes to a solved category" do
|
|
|
|
topic = Fabricate(:topic, category: Fabricate(:category_with_definition))
|
|
|
|
post = Fabricate(:post, topic: topic)
|
|
|
|
|
2022-12-23 15:36:08 -05:00
|
|
|
messages =
|
|
|
|
MessageBus.track_publish("/topic/#{topic.id}") do
|
|
|
|
described_class.new(post).revise!(admin, { category_id: category.id })
|
|
|
|
end
|
2021-01-20 05:26:37 -05:00
|
|
|
|
|
|
|
expect(messages.first.data[:refresh_stream]).to eq(nil)
|
|
|
|
|
2022-12-23 15:36:08 -05:00
|
|
|
messages =
|
|
|
|
MessageBus.track_publish("/topic/#{topic.id}") do
|
|
|
|
described_class.new(post).revise!(admin, { category_id: category_solved.id })
|
|
|
|
end
|
2021-01-20 05:26:37 -05:00
|
|
|
|
|
|
|
expect(messages.first.data[:refresh_stream]).to eq(true)
|
|
|
|
end
|
2021-09-17 10:12:47 -04:00
|
|
|
|
2022-12-23 15:36:08 -05:00
|
|
|
describe "Allowing solved via tags" do
|
2021-09-17 10:12:47 -04:00
|
|
|
before do
|
|
|
|
SiteSetting.solved_enabled = true
|
|
|
|
SiteSetting.tagging_enabled = true
|
|
|
|
end
|
|
|
|
|
|
|
|
fab!(:tag1) { Fabricate(:tag) }
|
|
|
|
fab!(:tag2) { Fabricate(:tag) }
|
|
|
|
|
|
|
|
fab!(:topic) { Fabricate(:topic) }
|
|
|
|
let(:post) { Fabricate(:post, topic: topic) }
|
|
|
|
|
2022-12-23 15:36:08 -05:00
|
|
|
it "sets the refresh option after adding an allowed tag" do
|
2021-09-17 10:12:47 -04:00
|
|
|
SiteSetting.enable_solved_tags = tag1.name
|
|
|
|
|
2022-12-23 15:36:08 -05:00
|
|
|
messages =
|
|
|
|
MessageBus.track_publish("/topic/#{topic.id}") do
|
|
|
|
described_class.new(post).revise!(admin, tags: [tag1.name])
|
|
|
|
end
|
2021-09-17 10:12:47 -04:00
|
|
|
|
|
|
|
expect(messages.first.data[:refresh_stream]).to eq(true)
|
|
|
|
end
|
|
|
|
|
2022-12-23 15:36:08 -05:00
|
|
|
it "sets the refresh option if the added tag matches any of the allowed tags" do
|
|
|
|
SiteSetting.enable_solved_tags = [tag1, tag2].map(&:name).join("|")
|
2021-09-17 10:12:47 -04:00
|
|
|
|
2022-12-23 15:36:08 -05:00
|
|
|
messages =
|
|
|
|
MessageBus.track_publish("/topic/#{topic.id}") do
|
|
|
|
described_class.new(post).revise!(admin, tags: [tag2.name])
|
|
|
|
end
|
2021-09-17 10:12:47 -04:00
|
|
|
|
|
|
|
expect(messages.first.data[:refresh_stream]).to eq(true)
|
|
|
|
end
|
|
|
|
end
|
2021-01-20 05:26:37 -05:00
|
|
|
end
|