mirror of
https://github.com/discourse/discourse-solved.git
synced 2026-11-01 09:58:24 -05:00
DEV: Introduce syntax_tree for ruby formatting (#217)
This commit is contained in:
@@ -55,3 +55,12 @@ jobs:
|
||||
- name: Rubocop
|
||||
if: ${{ !cancelled() }}
|
||||
run: bundle exec rubocop .
|
||||
|
||||
- name: Syntax Tree
|
||||
if: ${{ !cancelled() }}
|
||||
run: |
|
||||
if test -f .streerc; then
|
||||
bundle exec stree check Gemfile $(git ls-files '*.rb') $(git ls-files '*.rake')
|
||||
else
|
||||
echo "Stree config not detected for this repository. Skipping."
|
||||
fi
|
||||
|
||||
@@ -80,7 +80,7 @@ jobs:
|
||||
|
||||
- name: Get yarn cache directory
|
||||
id: yarn-cache-dir
|
||||
run: echo "::set-output name=dir::$(yarn cache dir)"
|
||||
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Yarn cache
|
||||
uses: actions/cache@v3
|
||||
@@ -130,7 +130,7 @@ jobs:
|
||||
shell: bash
|
||||
run: |
|
||||
if [ 0 -lt $(find plugins/${{ github.event.repository.name }}/spec -type f -name "*.rb" 2> /dev/null | wc -l) ]; then
|
||||
echo "::set-output name=files_exist::true"
|
||||
echo "files_exist=true" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
- name: Plugin RSpec
|
||||
@@ -142,7 +142,7 @@ jobs:
|
||||
shell: bash
|
||||
run: |
|
||||
if [ 0 -lt $(find plugins/${{ github.event.repository.name }}/test/javascripts -type f \( -name "*.js" -or -name "*.es6" \) 2> /dev/null | wc -l) ]; then
|
||||
echo "::set-output name=files_exist::true"
|
||||
echo "files_exist=true" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
- name: Plugin QUnit
|
||||
|
||||
+1
-1
@@ -1,2 +1,2 @@
|
||||
inherit_gem:
|
||||
rubocop-discourse: default.yml
|
||||
rubocop-discourse: stree-compat.yml
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
source 'https://rubygems.org'
|
||||
source "https://rubygems.org"
|
||||
|
||||
group :development do
|
||||
gem 'rubocop-discourse'
|
||||
gem "rubocop-discourse"
|
||||
gem "syntax_tree"
|
||||
end
|
||||
|
||||
@@ -6,6 +6,7 @@ GEM
|
||||
parallel (1.22.1)
|
||||
parser (3.1.2.1)
|
||||
ast (~> 2.4.1)
|
||||
prettier_print (1.1.0)
|
||||
rainbow (3.1.1)
|
||||
regexp_parser (2.6.0)
|
||||
rexml (3.2.5)
|
||||
@@ -27,6 +28,8 @@ GEM
|
||||
rubocop-rspec (2.13.2)
|
||||
rubocop (~> 1.33)
|
||||
ruby-progressbar (1.11.0)
|
||||
syntax_tree (5.0.1)
|
||||
prettier_print (>= 1.1.0)
|
||||
unicode-display_width (2.3.0)
|
||||
|
||||
PLATFORMS
|
||||
@@ -34,6 +37,7 @@ PLATFORMS
|
||||
|
||||
DEPENDENCIES
|
||||
rubocop-discourse
|
||||
syntax_tree
|
||||
|
||||
BUNDLED WITH
|
||||
2.1.4
|
||||
|
||||
@@ -4,11 +4,9 @@ class FirstAcceptedPostSolutionValidator
|
||||
def self.check(post, trust_level:)
|
||||
return false if post.archetype != Archetype.default
|
||||
return false if !post&.user&.human?
|
||||
return true if trust_level == 'any'
|
||||
return true if trust_level == "any"
|
||||
|
||||
if TrustLevel.compare(post&.user&.trust_level, trust_level.to_i)
|
||||
return false
|
||||
end
|
||||
return false if TrustLevel.compare(post&.user&.trust_level, trust_level.to_i)
|
||||
|
||||
if !UserAction.where(user_id: post&.user_id, action_type: UserAction::SOLVED).exists?
|
||||
return true
|
||||
|
||||
@@ -12,9 +12,9 @@ class EnsuresUniqueAcceptedAnswerPostId < ActiveRecord::Migration[5.2]
|
||||
SQL
|
||||
|
||||
add_index :topic_custom_fields,
|
||||
:topic_id,
|
||||
name: :idx_topic_custom_fields_accepted_answer,
|
||||
unique: true,
|
||||
where: "name = 'accepted_answer_post_id'"
|
||||
:topic_id,
|
||||
name: :idx_topic_custom_fields_accepted_answer,
|
||||
unique: true,
|
||||
where: "name = 'accepted_answer_post_id'"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -18,7 +18,7 @@ class RenameBadges < ActiveRecord::Migration[6.1]
|
||||
"sv" => "Kundtjänst",
|
||||
"tr_TR" => "Yardım masası",
|
||||
"zh_CN" => "帮助台",
|
||||
"zh_TW" => "服務台"
|
||||
"zh_TW" => "服務台",
|
||||
}
|
||||
|
||||
TECH_SUPPORT_TRANSLATIONS = {
|
||||
@@ -43,11 +43,12 @@ class RenameBadges < ActiveRecord::Migration[6.1]
|
||||
"sv" => "Teknisk support",
|
||||
"tr_TR" => "Teknik Destek",
|
||||
"zh_CN" => "技术支持",
|
||||
"zh_TW" => "技術支援"
|
||||
"zh_TW" => "技術支援",
|
||||
}
|
||||
|
||||
def up
|
||||
default_locale = DB.query_single("SELECT value FROM site_settings WHERE name = 'default_locale'").first || "en"
|
||||
default_locale =
|
||||
DB.query_single("SELECT value FROM site_settings WHERE name = 'default_locale'").first || "en"
|
||||
|
||||
sql = <<~SQL
|
||||
UPDATE badges
|
||||
|
||||
@@ -1,38 +1,55 @@
|
||||
# encoding: utf-8
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
require 'composer_messages_finder'
|
||||
require "rails_helper"
|
||||
require "composer_messages_finder"
|
||||
|
||||
describe ComposerMessagesFinder do
|
||||
describe '.check_topic_is_solved' do
|
||||
fab!(:user) { Fabricate(:user) }
|
||||
describe ".check_topic_is_solved" do
|
||||
fab!(:user) { Fabricate(:user) }
|
||||
fab!(:topic) { Fabricate(:topic) }
|
||||
fab!(:post) { Fabricate(:post, topic: topic, user: Fabricate(:user)) }
|
||||
|
||||
before do
|
||||
SiteSetting.disable_solved_education_message = false
|
||||
end
|
||||
before { SiteSetting.disable_solved_education_message = false }
|
||||
|
||||
it "does not show message without a topic id" do
|
||||
expect(described_class.new(user, composer_action: 'createTopic').check_topic_is_solved).to be_blank
|
||||
expect(described_class.new(user, composer_action: 'reply').check_topic_is_solved).to be_blank
|
||||
expect(
|
||||
described_class.new(user, composer_action: "createTopic").check_topic_is_solved,
|
||||
).to be_blank
|
||||
expect(described_class.new(user, composer_action: "reply").check_topic_is_solved).to be_blank
|
||||
end
|
||||
|
||||
describe "a reply" do
|
||||
it "does not show message if topic is not solved" do
|
||||
expect(described_class.new(user, composer_action: 'reply', topic_id: topic.id).check_topic_is_solved).to be_blank
|
||||
expect(
|
||||
described_class.new(
|
||||
user,
|
||||
composer_action: "reply",
|
||||
topic_id: topic.id,
|
||||
).check_topic_is_solved,
|
||||
).to be_blank
|
||||
end
|
||||
|
||||
it "does not show message if disable_solved_education_message is true" do
|
||||
SiteSetting.disable_solved_education_message = true
|
||||
DiscourseSolved.accept_answer!(post, Discourse.system_user)
|
||||
expect(described_class.new(user, composer_action: 'reply', topic_id: topic.id).check_topic_is_solved).to be_blank
|
||||
expect(
|
||||
described_class.new(
|
||||
user,
|
||||
composer_action: "reply",
|
||||
topic_id: topic.id,
|
||||
).check_topic_is_solved,
|
||||
).to be_blank
|
||||
end
|
||||
|
||||
it "shows message if the topic is solved" do
|
||||
DiscourseSolved.accept_answer!(post, Discourse.system_user)
|
||||
message = described_class.new(user, composer_action: 'reply', topic_id: topic.id).check_topic_is_solved
|
||||
message =
|
||||
described_class.new(
|
||||
user,
|
||||
composer_action: "reply",
|
||||
topic_id: topic.id,
|
||||
).check_topic_is_solved
|
||||
expect(message).not_to be_blank
|
||||
expect(message[:body]).to include("This topic has been solved")
|
||||
end
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
require 'post_revisor'
|
||||
require "rails_helper"
|
||||
require "post_revisor"
|
||||
|
||||
describe PostRevisor do
|
||||
fab!(:category) { Fabricate(:category_with_definition) }
|
||||
@@ -17,20 +17,22 @@ describe PostRevisor do
|
||||
topic = Fabricate(:topic, category: Fabricate(:category_with_definition))
|
||||
post = Fabricate(:post, topic: topic)
|
||||
|
||||
messages = MessageBus.track_publish("/topic/#{topic.id}") do
|
||||
described_class.new(post).revise!(admin, { category_id: category.id })
|
||||
end
|
||||
messages =
|
||||
MessageBus.track_publish("/topic/#{topic.id}") do
|
||||
described_class.new(post).revise!(admin, { category_id: category.id })
|
||||
end
|
||||
|
||||
expect(messages.first.data[:refresh_stream]).to eq(nil)
|
||||
|
||||
messages = MessageBus.track_publish("/topic/#{topic.id}") do
|
||||
described_class.new(post).revise!(admin, { category_id: category_solved.id })
|
||||
end
|
||||
messages =
|
||||
MessageBus.track_publish("/topic/#{topic.id}") do
|
||||
described_class.new(post).revise!(admin, { category_id: category_solved.id })
|
||||
end
|
||||
|
||||
expect(messages.first.data[:refresh_stream]).to eq(true)
|
||||
end
|
||||
|
||||
describe 'Allowing solved via tags' do
|
||||
describe "Allowing solved via tags" do
|
||||
before do
|
||||
SiteSetting.solved_enabled = true
|
||||
SiteSetting.tagging_enabled = true
|
||||
@@ -42,22 +44,24 @@ describe PostRevisor do
|
||||
fab!(:topic) { Fabricate(:topic) }
|
||||
let(:post) { Fabricate(:post, topic: topic) }
|
||||
|
||||
it 'sets the refresh option after adding an allowed tag' do
|
||||
it "sets the refresh option after adding an allowed tag" do
|
||||
SiteSetting.enable_solved_tags = tag1.name
|
||||
|
||||
messages = MessageBus.track_publish("/topic/#{topic.id}") do
|
||||
described_class.new(post).revise!(admin, tags: [tag1.name])
|
||||
end
|
||||
messages =
|
||||
MessageBus.track_publish("/topic/#{topic.id}") do
|
||||
described_class.new(post).revise!(admin, tags: [tag1.name])
|
||||
end
|
||||
|
||||
expect(messages.first.data[:refresh_stream]).to eq(true)
|
||||
end
|
||||
|
||||
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('|')
|
||||
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("|")
|
||||
|
||||
messages = MessageBus.track_publish("/topic/#{topic.id}") do
|
||||
described_class.new(post).revise!(admin, tags: [tag2.name])
|
||||
end
|
||||
messages =
|
||||
MessageBus.track_publish("/topic/#{topic.id}") do
|
||||
described_class.new(post).revise!(admin, tags: [tag2.name])
|
||||
end
|
||||
|
||||
expect(messages.first.data[:refresh_stream]).to eq(true)
|
||||
end
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
Fabricator(:solved_web_hook, from: :web_hook) do
|
||||
transient solved_hook: WebHookEventType.find_by(name: 'solved')
|
||||
transient solved_hook: WebHookEventType.find_by(name: "solved")
|
||||
|
||||
after_build do |web_hook, transients|
|
||||
web_hook.web_hook_event_types = [transients[:solved_hook]]
|
||||
end
|
||||
after_build { |web_hook, transients| web_hook.web_hook_event_types = [transients[:solved_hook]] }
|
||||
end
|
||||
|
||||
@@ -1,18 +1,16 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe "Managing Posts solved status" do
|
||||
let(:topic) { Fabricate(:topic) }
|
||||
let(:user) { Fabricate(:trust_level_4) }
|
||||
let(:p1) { Fabricate(:post, topic: topic) }
|
||||
|
||||
before do
|
||||
SiteSetting.allow_solved_on_all_topics = true
|
||||
end
|
||||
before { SiteSetting.allow_solved_on_all_topics = true }
|
||||
|
||||
describe 'auto bump' do
|
||||
it 'does not automatically bump solved topics' do
|
||||
describe "auto bump" do
|
||||
it "does not automatically bump solved topics" do
|
||||
category = Fabricate(:category_with_definition)
|
||||
|
||||
post = create_post(category: category)
|
||||
@@ -36,13 +34,13 @@ RSpec.describe "Managing Posts solved status" do
|
||||
end
|
||||
end
|
||||
|
||||
describe 'accepting a post as the answer' do
|
||||
describe "accepting a post as the answer" do
|
||||
before do
|
||||
sign_in(user)
|
||||
SiteSetting.solved_topics_auto_close_hours = 2
|
||||
end
|
||||
|
||||
it 'can mark a post as the accepted answer correctly' do
|
||||
it "can mark a post as the accepted answer correctly" do
|
||||
freeze_time
|
||||
|
||||
post "/solution/accept.json", params: { id: p1.id }
|
||||
@@ -52,20 +50,18 @@ RSpec.describe "Managing Posts solved status" do
|
||||
|
||||
topic.reload
|
||||
|
||||
expect(topic.public_topic_timer.status_type)
|
||||
.to eq(TopicTimer.types[:silent_close])
|
||||
expect(topic.public_topic_timer.status_type).to eq(TopicTimer.types[:silent_close])
|
||||
|
||||
expect(topic.custom_fields[
|
||||
DiscourseSolved::AUTO_CLOSE_TOPIC_TIMER_CUSTOM_FIELD
|
||||
].to_i).to eq(topic.public_topic_timer.id)
|
||||
expect(topic.custom_fields[DiscourseSolved::AUTO_CLOSE_TOPIC_TIMER_CUSTOM_FIELD].to_i).to eq(
|
||||
topic.public_topic_timer.id,
|
||||
)
|
||||
|
||||
expect(topic.public_topic_timer.execute_at)
|
||||
.to eq_time(Time.zone.now + 2.hours)
|
||||
expect(topic.public_topic_timer.execute_at).to eq_time(Time.zone.now + 2.hours)
|
||||
|
||||
expect(topic.public_topic_timer.based_on_last_post).to eq(true)
|
||||
end
|
||||
|
||||
it 'sends notifications to correct users' do
|
||||
it "sends notifications to correct users" do
|
||||
SiteSetting.notify_on_staff_accept_solved = true
|
||||
user = Fabricate(:user)
|
||||
topic = Fabricate(:topic, user: user)
|
||||
@@ -74,11 +70,9 @@ RSpec.describe "Managing Posts solved status" do
|
||||
op = topic.user
|
||||
user = post.user
|
||||
|
||||
expect {
|
||||
DiscourseSolved.accept_answer!(post, Discourse.system_user)
|
||||
}.to \
|
||||
change { user.notifications.count }.by(1) &
|
||||
change { op.notifications.count }.by(1)
|
||||
expect { DiscourseSolved.accept_answer!(post, Discourse.system_user) }.to change {
|
||||
user.notifications.count
|
||||
}.by(1) & change { op.notifications.count }.by(1)
|
||||
|
||||
notification = user.notifications.last
|
||||
expect(notification.notification_type).to eq(Notification.types[:custom])
|
||||
@@ -91,7 +85,7 @@ RSpec.describe "Managing Posts solved status" do
|
||||
expect(notification.post_number).to eq(post.post_number)
|
||||
end
|
||||
|
||||
it 'does not set a timer when the topic is closed' do
|
||||
it "does not set a timer when the topic is closed" do
|
||||
topic.update!(closed: true)
|
||||
post "/solution/accept.json", params: { id: p1.id }
|
||||
|
||||
@@ -105,7 +99,7 @@ RSpec.describe "Managing Posts solved status" do
|
||||
expect(topic.closed).to eq(true)
|
||||
end
|
||||
|
||||
it 'works with staff and trashed topics' do
|
||||
it "works with staff and trashed topics" do
|
||||
topic.trash!(Discourse.system_user)
|
||||
|
||||
post "/solution/accept.json", params: { id: p1.id }
|
||||
@@ -119,7 +113,7 @@ RSpec.describe "Managing Posts solved status" do
|
||||
expect(p1.custom_fields["is_accepted_answer"]).to eq("true")
|
||||
end
|
||||
|
||||
it 'does not allow you to accept a whisper' do
|
||||
it "does not allow you to accept a whisper" do
|
||||
whisper = Fabricate(:post, topic: topic, post_type: Post.types[:whisper])
|
||||
sign_in(Fabricate(:admin))
|
||||
|
||||
@@ -127,7 +121,7 @@ RSpec.describe "Managing Posts solved status" do
|
||||
expect(response.status).to eq(403)
|
||||
end
|
||||
|
||||
it 'triggers a webhook' do
|
||||
it "triggers a webhook" do
|
||||
Fabricate(:solved_web_hook)
|
||||
post "/solution/accept.json", params: { id: p1.id }
|
||||
|
||||
@@ -139,21 +133,19 @@ RSpec.describe "Managing Posts solved status" do
|
||||
end
|
||||
end
|
||||
|
||||
describe '#unaccept' do
|
||||
before do
|
||||
sign_in(user)
|
||||
end
|
||||
describe "#unaccept" do
|
||||
before { sign_in(user) }
|
||||
|
||||
describe 'when solved_topics_auto_close_hours is enabled' do
|
||||
describe "when solved_topics_auto_close_hours is enabled" do
|
||||
before do
|
||||
SiteSetting.solved_topics_auto_close_hours = 2
|
||||
DiscourseSolved.accept_answer!(p1, user)
|
||||
end
|
||||
|
||||
it 'should unmark the post as solved' do
|
||||
expect do
|
||||
post "/solution/unaccept.json", params: { id: p1.id }
|
||||
end.to change { topic.reload.public_topic_timer }.to(nil)
|
||||
it "should unmark the post as solved" do
|
||||
expect do post "/solution/unaccept.json", params: { id: p1.id } end.to change {
|
||||
topic.reload.public_topic_timer
|
||||
}.to(nil)
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
p1.reload
|
||||
@@ -161,10 +153,9 @@ RSpec.describe "Managing Posts solved status" do
|
||||
expect(p1.custom_fields["is_accepted_answer"]).to eq(nil)
|
||||
expect(p1.topic.custom_fields["accepted_answer_post_id"]).to eq(nil)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
it 'triggers a webhook' do
|
||||
it "triggers a webhook" do
|
||||
Fabricate(:solved_web_hook)
|
||||
post "/solution/unaccept.json", params: { id: p1.id }
|
||||
|
||||
@@ -176,7 +167,7 @@ RSpec.describe "Managing Posts solved status" do
|
||||
end
|
||||
end
|
||||
|
||||
context 'with group moderators' do
|
||||
context "with group moderators" do
|
||||
fab!(:group_user) { Fabricate(:group_user) }
|
||||
let(:user_gm) { group_user.user }
|
||||
let(:group) { group_user.group }
|
||||
@@ -187,7 +178,7 @@ RSpec.describe "Managing Posts solved status" do
|
||||
sign_in(user_gm)
|
||||
end
|
||||
|
||||
it 'can accept a solution' do
|
||||
it "can accept a solution" do
|
||||
post "/solution/accept.json", params: { id: p1.id }
|
||||
expect(response.status).to eq(200)
|
||||
end
|
||||
|
||||
@@ -1,71 +1,76 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
require "rails_helper"
|
||||
|
||||
describe FirstAcceptedPostSolutionValidator do
|
||||
fab!(:user_tl1) { Fabricate(:user, trust_level: TrustLevel[1]) }
|
||||
|
||||
context 'when user is under max trust level' do
|
||||
context 'with no post accepted yet' do
|
||||
it 'validates the post' do
|
||||
context "when user is under max trust level" do
|
||||
context "with no post accepted yet" do
|
||||
it "validates the post" do
|
||||
post_1 = create_post(user: user_tl1)
|
||||
expect(described_class.check(post_1, trust_level: TrustLevel[2])).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with already had accepted posts' do
|
||||
context "with already had accepted posts" do
|
||||
before do
|
||||
accepted_post = create_post(user: user_tl1)
|
||||
DiscourseSolved.accept_answer!(accepted_post, Discourse.system_user)
|
||||
end
|
||||
|
||||
it 'doesn’t validate the post' do
|
||||
it "doesn’t validate the post" do
|
||||
post_1 = create_post(user: user_tl1)
|
||||
expect(described_class.check(post_1, trust_level: TrustLevel[2])).to eq(false)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when a user is above or equal max trust level' do
|
||||
context 'with no post accepted yet' do
|
||||
it 'doesn’t validate the post' do
|
||||
context "when a user is above or equal max trust level" do
|
||||
context "with no post accepted yet" do
|
||||
it "doesn’t validate the post" do
|
||||
post_1 = create_post(user: user_tl1)
|
||||
expect(described_class.check(post_1, trust_level: TrustLevel[1])).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when a post is already accepted' do
|
||||
context "when a post is already accepted" do
|
||||
before do
|
||||
accepted_post = create_post(user: user_tl1)
|
||||
DiscourseSolved.accept_answer!(accepted_post, Discourse.system_user)
|
||||
end
|
||||
|
||||
it 'doesn’t validate the post' do
|
||||
it "doesn’t validate the post" do
|
||||
post_1 = create_post(user: user_tl1)
|
||||
expect(described_class.check(post_1, trust_level: TrustLevel[1])).to eq(false)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when using any trust level' do
|
||||
it 'validates the post' do
|
||||
context "when using any trust level" do
|
||||
it "validates the post" do
|
||||
post_1 = create_post(user: user_tl1)
|
||||
expect(described_class.check(post_1, trust_level: 'any')).to eq(true)
|
||||
expect(described_class.check(post_1, trust_level: "any")).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when user is system' do
|
||||
it 'doesn’t validate the post' do
|
||||
context "when user is system" do
|
||||
it "doesn’t validate the post" do
|
||||
post_1 = create_post(user: Discourse.system_user)
|
||||
expect(described_class.check(post_1, trust_level: 'any')).to eq(false)
|
||||
expect(described_class.check(post_1, trust_level: "any")).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when post is a PM' do
|
||||
it 'doesn’t validate the post' do
|
||||
context "when post is a PM" do
|
||||
it "doesn’t validate the post" do
|
||||
Group.refresh_automatic_groups!
|
||||
post_1 = create_post(user: user_tl1, target_usernames: [user_tl1.username], archetype: Archetype.private_message)
|
||||
expect(described_class.check(post_1, trust_level: 'any')).to eq(false)
|
||||
post_1 =
|
||||
create_post(
|
||||
user: user_tl1,
|
||||
target_usernames: [user_tl1.username],
|
||||
archetype: Archetype.private_message,
|
||||
)
|
||||
expect(described_class.check(post_1, trust_level: "any")).to eq(false)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
require_dependency 'site'
|
||||
require "rails_helper"
|
||||
require_dependency "site"
|
||||
|
||||
describe Site do
|
||||
let(:category) { Fabricate(:category) }
|
||||
let(:guardian) { Guardian.new }
|
||||
|
||||
before do
|
||||
SiteSetting.show_filter_by_solved_status = true
|
||||
end
|
||||
before { SiteSetting.show_filter_by_solved_status = true }
|
||||
|
||||
it "includes `enable_accepted_answers` custom field for categories" do
|
||||
category.custom_fields["enable_accepted_answers"] = true
|
||||
|
||||
@@ -1,21 +1,19 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe ListController do
|
||||
fab!(:p1) { Fabricate(:post) }
|
||||
fab!(:p2) { Fabricate(:post, topic: p1.topic) }
|
||||
fab!(:p3) { Fabricate(:post, topic: p1.topic) }
|
||||
|
||||
before do
|
||||
SiteSetting.allow_solved_on_all_topics = true
|
||||
end
|
||||
before { SiteSetting.allow_solved_on_all_topics = true }
|
||||
|
||||
it 'shows the user who posted the accepted answer second' do
|
||||
it "shows the user who posted the accepted answer second" do
|
||||
TopicFeaturedUsers.ensure_consistency!
|
||||
DiscourseSolved.accept_answer!(p3, p1.user, topic: p1.topic)
|
||||
|
||||
get '/latest.json'
|
||||
get "/latest.json"
|
||||
posters = response.parsed_body["topic_list"]["topics"].first["posters"]
|
||||
expect(posters[0]["user_id"]).to eq(p1.user_id)
|
||||
expect(posters[1]["user_id"]).to eq(p3.user_id)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe TopicsController do
|
||||
let(:p1) { Fabricate(:post, like_count: 1) }
|
||||
@@ -9,34 +9,37 @@ RSpec.describe TopicsController do
|
||||
|
||||
def schema_json(answerCount)
|
||||
if answerCount > 0
|
||||
answer_json = ',"acceptedAnswer":{"@type":"Answer","text":"%{answer_text}","upvoteCount":%{answer_likes},"dateCreated":"%{answered_at}","url":"%{answer_url}","author":{"@type":"Person","name":"%{username2}"}}' % {
|
||||
answer_text: p2.excerpt,
|
||||
answer_likes: p2.like_count,
|
||||
answered_at: p2.created_at.as_json,
|
||||
answer_url: p2.full_url,
|
||||
username2: p2.user&.username
|
||||
}
|
||||
answer_json =
|
||||
',"acceptedAnswer":{"@type":"Answer","text":"%{answer_text}","upvoteCount":%{answer_likes},"dateCreated":"%{answered_at}","url":"%{answer_url}","author":{"@type":"Person","name":"%{username2}"}}' %
|
||||
{
|
||||
answer_text: p2.excerpt,
|
||||
answer_likes: p2.like_count,
|
||||
answered_at: p2.created_at.as_json,
|
||||
answer_url: p2.full_url,
|
||||
username2: p2.user&.username,
|
||||
}
|
||||
else
|
||||
answer_json = ""
|
||||
end
|
||||
|
||||
'<script type="application/ld+json">{"@context":"http://schema.org","@type":"QAPage","name":"%{title}","mainEntity":{"@type":"Question","name":"%{title}","text":"%{question_text}","upvoteCount":%{question_likes},"answerCount":%{answerCount},"dateCreated":"%{created_at}","author":{"@type":"Person","name":"%{username1}"}%{answer_json}}}</script>' % {
|
||||
title: topic.title,
|
||||
question_text: p1.excerpt,
|
||||
question_likes: p1.like_count,
|
||||
answerCount: answerCount,
|
||||
created_at: topic.created_at.as_json,
|
||||
username1: topic.user&.name,
|
||||
answer_json: answer_json
|
||||
}
|
||||
# rubocop:todo Layout/LineLength
|
||||
'<script type="application/ld+json">{"@context":"http://schema.org","@type":"QAPage","name":"%{title}","mainEntity":{"@type":"Question","name":"%{title}","text":"%{question_text}","upvoteCount":%{question_likes},"answerCount":%{answerCount},"dateCreated":"%{created_at}","author":{"@type":"Person","name":"%{username1}"}%{answer_json}}}</script>' %
|
||||
# rubocop:enable Layout/LineLength
|
||||
{
|
||||
title: topic.title,
|
||||
question_text: p1.excerpt,
|
||||
question_likes: p1.like_count,
|
||||
answerCount: answerCount,
|
||||
created_at: topic.created_at.as_json,
|
||||
username1: topic.user&.name,
|
||||
answer_json: answer_json,
|
||||
}
|
||||
end
|
||||
|
||||
context 'with solved enabled on every topic' do
|
||||
before do
|
||||
SiteSetting.allow_solved_on_all_topics = true
|
||||
end
|
||||
context "with solved enabled on every topic" do
|
||||
before { SiteSetting.allow_solved_on_all_topics = true }
|
||||
|
||||
it 'should include correct schema information in header' do
|
||||
it "should include correct schema information in header" do
|
||||
get "/t/#{topic.slug}/#{topic.id}"
|
||||
|
||||
expect(response.body).to include(schema_json(0))
|
||||
@@ -51,7 +54,7 @@ RSpec.describe TopicsController do
|
||||
expect(response.body).to include(schema_json(1))
|
||||
end
|
||||
|
||||
it 'should include quoted content in schema information' do
|
||||
it "should include quoted content in schema information" do
|
||||
post = topic.first_post
|
||||
post.raw = "[quote]This is a quoted text.[/quote]"
|
||||
post.save!
|
||||
@@ -63,12 +66,12 @@ RSpec.describe TopicsController do
|
||||
end
|
||||
end
|
||||
|
||||
context 'with solved enabled for topics with specific tags' do
|
||||
context "with solved enabled for topics with specific tags" do
|
||||
let(:tag) { Fabricate(:tag) }
|
||||
|
||||
before { SiteSetting.enable_solved_tags = tag.name }
|
||||
|
||||
it 'includes the correct schema information' do
|
||||
it "includes the correct schema information" do
|
||||
DiscourseTagging.add_or_create_tags_by_name(topic, [tag.name])
|
||||
p2.custom_fields["is_accepted_answer"] = true
|
||||
p2.save_custom_fields
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
require "rails_helper"
|
||||
|
||||
describe TopicAnswerMixin do
|
||||
let(:topic) { Fabricate(:topic) }
|
||||
@@ -17,7 +17,7 @@ describe TopicAnswerMixin do
|
||||
TopicListItemSerializer,
|
||||
SearchTopicListItemSerializer,
|
||||
SuggestedTopicSerializer,
|
||||
UserSummarySerializer::TopicSerializer
|
||||
UserSummarySerializer::TopicSerializer,
|
||||
].each do |serializer|
|
||||
json = serializer.new(topic, scope: guardian, root: false).as_json
|
||||
expect(json[:has_accepted_answer]).to be_truthy
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
require "rails_helper"
|
||||
|
||||
describe UserCardSerializer do
|
||||
let(:user) { Fabricate(:user) }
|
||||
|
||||
Reference in New Issue
Block a user