2021-10-04 15:55:09 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-27 22:27:38 -04:00
|
|
|
RSpec.describe ReviewableScoreSerializer do
|
2021-10-04 15:55:09 -04:00
|
|
|
fab!(:reviewable) { Fabricate(:reviewable_flagged_post) }
|
|
|
|
fab!(:admin) { Fabricate(:admin) }
|
|
|
|
|
|
|
|
describe '#reason' do
|
2022-07-27 12:14:14 -04:00
|
|
|
context 'with regular links' do
|
2021-10-04 15:55:09 -04:00
|
|
|
it 'adds a link for watched words' do
|
|
|
|
serialized = serialized_score('watched_word')
|
|
|
|
link_url = "#{Discourse.base_url}/admin/customize/watched_words"
|
2021-10-07 11:41:57 -04:00
|
|
|
watched_words_link = "<a href=\"#{link_url}\">#{I18n.t('reviewables.reasons.links.watched_word')}</a>"
|
2021-10-04 15:55:09 -04:00
|
|
|
|
|
|
|
expect(serialized.reason).to include(watched_words_link)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'adds a link for category settings' do
|
|
|
|
category = Fabricate.build(:category)
|
|
|
|
reviewable.category = category
|
|
|
|
serialized = serialized_score('category')
|
|
|
|
link_url = "#{Discourse.base_url}/c/#{category.name}/edit/settings"
|
2021-10-07 11:41:57 -04:00
|
|
|
category_link = "<a href=\"#{link_url}\">#{I18n.t('reviewables.reasons.links.category')}</a>"
|
2021-10-04 15:55:09 -04:00
|
|
|
|
|
|
|
expect(serialized.reason).to include(category_link)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
context 'with site setting links' do
|
2021-10-04 15:55:09 -04:00
|
|
|
reasons = %w[
|
2021-10-11 09:24:41 -04:00
|
|
|
post_count trust_level new_topics_unless_trust_level fast_typer auto_silence_regex
|
2021-10-04 15:55:09 -04:00
|
|
|
staged must_approve_users invite_only email_spam suspect_user contains_media
|
|
|
|
]
|
|
|
|
|
|
|
|
reasons.each do |r|
|
|
|
|
it "addd a link to a site setting for the #{r} reason" do
|
|
|
|
serialized = serialized_score(r)
|
2021-10-07 11:41:57 -04:00
|
|
|
setting_name = described_class::REASONS_AND_SETTINGS[r.to_sym]
|
2021-10-04 15:55:09 -04:00
|
|
|
link_url = "#{Discourse.base_url}/admin/site_settings/category/all_results?filter=#{setting_name}"
|
|
|
|
link = "<a href=\"#{link_url}\">#{setting_name.gsub('_', ' ')}</a>"
|
|
|
|
|
|
|
|
expect(serialized.reason).to include(link)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-10-07 11:41:57 -04:00
|
|
|
describe '#setting_name_for_reason' do
|
|
|
|
after { DiscoursePluginRegistry.reset_register!(:reviewable_score_links) }
|
|
|
|
|
|
|
|
describe 'when a plugin adds a setting name to linkify' do
|
|
|
|
it 'gets the setting name from the registry' do
|
|
|
|
reason = :plugin_reason
|
|
|
|
setting_name = 'max_username_length'
|
|
|
|
DiscoursePluginRegistry.register_reviewable_score_link(
|
|
|
|
{ reason: reason, setting: setting_name },
|
|
|
|
Plugin::Instance.new
|
|
|
|
)
|
|
|
|
|
|
|
|
score = serialized_score(reason)
|
|
|
|
|
|
|
|
expect(score.setting_name_for_reason(reason)).to eq(setting_name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-10-04 15:55:09 -04:00
|
|
|
def serialized_score(reason)
|
|
|
|
score = ReviewableScore.new(
|
|
|
|
reviewable: reviewable,
|
|
|
|
reason: reason
|
|
|
|
)
|
|
|
|
|
|
|
|
described_class.new(score, scope: Guardian.new(admin), root: nil)
|
|
|
|
end
|
|
|
|
end
|