mirror of
https://github.com/discourse/discourse.git
synced 2025-05-24 03:36:18 +08:00
DEV: Apply syntax_tree formatting to plugins/*
This commit is contained in:
@ -18,79 +18,76 @@ RSpec.describe User do
|
||||
SiteSetting.discourse_narrative_bot_enabled = true
|
||||
end
|
||||
|
||||
describe 'when a user is created' do
|
||||
it 'should initiate the bot' do
|
||||
describe "when a user is created" do
|
||||
it "should initiate the bot" do
|
||||
NotificationEmailer.expects(:process_notification).never
|
||||
|
||||
user
|
||||
|
||||
expected_raw = i18n_t('discourse_narrative_bot.new_user_narrative.hello.message',
|
||||
username: user.username, title: SiteSetting.title
|
||||
)
|
||||
expected_raw =
|
||||
i18n_t(
|
||||
"discourse_narrative_bot.new_user_narrative.hello.message",
|
||||
username: user.username,
|
||||
title: SiteSetting.title,
|
||||
)
|
||||
|
||||
expect(Post.last.raw).to include(expected_raw.chomp)
|
||||
end
|
||||
|
||||
describe 'welcome post' do
|
||||
context 'when disabled' do
|
||||
before do
|
||||
SiteSetting.disable_discourse_narrative_bot_welcome_post = true
|
||||
end
|
||||
describe "welcome post" do
|
||||
context "when disabled" do
|
||||
before { SiteSetting.disable_discourse_narrative_bot_welcome_post = true }
|
||||
|
||||
it 'should not initiate the bot' do
|
||||
it "should not initiate the bot" do
|
||||
expect { user }.to_not change { Post.count }
|
||||
end
|
||||
end
|
||||
|
||||
context 'with title emoji disabled' do
|
||||
context "with title emoji disabled" do
|
||||
before do
|
||||
SiteSetting.disable_discourse_narrative_bot_welcome_post = false
|
||||
SiteSetting.max_emojis_in_title = 0
|
||||
end
|
||||
|
||||
it 'initiates the bot' do
|
||||
it "initiates the bot" do
|
||||
expect { user }.to change { Topic.count }.by(1)
|
||||
|
||||
expect(Topic.last.title).to eq(i18n_t(
|
||||
'discourse_narrative_bot.new_user_narrative.hello.title'
|
||||
).gsub(/:robot:/, '').strip)
|
||||
expect(Topic.last.title).to eq(
|
||||
i18n_t("discourse_narrative_bot.new_user_narrative.hello.title").gsub(
|
||||
/:robot:/,
|
||||
"",
|
||||
).strip,
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when enabled' do
|
||||
before do
|
||||
SiteSetting.disable_discourse_narrative_bot_welcome_post = false
|
||||
end
|
||||
context "when enabled" do
|
||||
before { SiteSetting.disable_discourse_narrative_bot_welcome_post = false }
|
||||
|
||||
it 'initiate the bot' do
|
||||
it "initiate the bot" do
|
||||
expect { user }.to change { Topic.count }.by(1)
|
||||
|
||||
expect(Topic.last.title).to eq(i18n_t(
|
||||
'discourse_narrative_bot.new_user_narrative.hello.title'
|
||||
))
|
||||
expect(Topic.last.title).to eq(
|
||||
i18n_t("discourse_narrative_bot.new_user_narrative.hello.title"),
|
||||
)
|
||||
end
|
||||
|
||||
describe "when send welcome message is selected" do
|
||||
before do
|
||||
SiteSetting.discourse_narrative_bot_welcome_post_type = 'welcome_message'
|
||||
end
|
||||
before { SiteSetting.discourse_narrative_bot_welcome_post_type = "welcome_message" }
|
||||
|
||||
it 'should send the right welcome message' do
|
||||
it "should send the right welcome message" do
|
||||
expect { user }.to change { Topic.count }.by(1)
|
||||
|
||||
expect(Topic.last.title).to eq(i18n_t(
|
||||
"system_messages.welcome_user.subject_template",
|
||||
site_name: SiteSetting.title
|
||||
))
|
||||
expect(Topic.last.title).to eq(
|
||||
i18n_t("system_messages.welcome_user.subject_template", site_name: SiteSetting.title),
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when welcome message is configured to be delayed' do
|
||||
before do
|
||||
SiteSetting.discourse_narrative_bot_welcome_post_delay = 100
|
||||
end
|
||||
describe "when welcome message is configured to be delayed" do
|
||||
before { SiteSetting.discourse_narrative_bot_welcome_post_delay = 100 }
|
||||
|
||||
it 'should delay the welcome post until user logs in' do
|
||||
it "should delay the welcome post until user logs in" do
|
||||
user
|
||||
|
||||
expect(Jobs::NarrativeInit.jobs.count).to eq(0)
|
||||
@ -99,41 +96,37 @@ RSpec.describe User do
|
||||
end
|
||||
end
|
||||
|
||||
context 'when user is staged' do
|
||||
context "when user is staged" do
|
||||
let(:user) { Fabricate(:user, staged: true) }
|
||||
|
||||
it 'should not initiate the bot' do
|
||||
it "should not initiate the bot" do
|
||||
expect { user }.to_not change { Post.count }
|
||||
end
|
||||
end
|
||||
|
||||
context 'when user skipped the new user tips' do
|
||||
context "when user skipped the new user tips" do
|
||||
let(:user) { Fabricate(:user) }
|
||||
|
||||
it 'should not initiate the bot' do
|
||||
it "should not initiate the bot" do
|
||||
SiteSetting.default_other_skip_new_user_tips = true
|
||||
expect { user }.to_not change { Post.count }
|
||||
end
|
||||
|
||||
it 'should delete the existing PM' do
|
||||
it "should delete the existing PM" do
|
||||
user.user_option.skip_new_user_tips = true
|
||||
|
||||
expect {
|
||||
user.user_option.save!
|
||||
}.to change { Topic.count }.by(-1)
|
||||
.and not_change { UserHistory.count }
|
||||
.and change { user.unread_high_priority_notifications }.by(-1)
|
||||
.and change { user.notifications.count }.by(-1)
|
||||
expect { user.user_option.save! }.to change { Topic.count }.by(-1).and not_change {
|
||||
UserHistory.count
|
||||
}.and change { user.unread_high_priority_notifications }.by(-1).and change {
|
||||
user.notifications.count
|
||||
}.by(-1)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when user is anonymous?' do
|
||||
before do
|
||||
SiteSetting.allow_anonymous_posting = true
|
||||
end
|
||||
|
||||
it 'should initiate bot for real user only' do
|
||||
context "when user is anonymous?" do
|
||||
before { SiteSetting.allow_anonymous_posting = true }
|
||||
|
||||
it "should initiate bot for real user only" do
|
||||
user = Fabricate(:user, trust_level: 1)
|
||||
shadow = AnonymousShadowCreator.get(user)
|
||||
|
||||
@ -145,21 +138,19 @@ RSpec.describe User do
|
||||
context "when user's username should be ignored" do
|
||||
let(:user) { Fabricate.build(:user) }
|
||||
|
||||
before do
|
||||
SiteSetting.discourse_narrative_bot_ignored_usernames = 'discourse|test'
|
||||
end
|
||||
before { SiteSetting.discourse_narrative_bot_ignored_usernames = "discourse|test" }
|
||||
|
||||
['discourse', 'test'].each do |username|
|
||||
it 'should not initiate the bot' do
|
||||
%w[discourse test].each do |username|
|
||||
it "should not initiate the bot" do
|
||||
expect { user.update!(username: username) }.to_not change { Post.count }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when a user has been destroyed' do
|
||||
describe "when a user has been destroyed" do
|
||||
it "should clean up plugin's store" do
|
||||
DiscourseNarrativeBot::Store.set(user.id, 'test')
|
||||
DiscourseNarrativeBot::Store.set(user.id, "test")
|
||||
|
||||
user.destroy!
|
||||
|
||||
@ -167,8 +158,8 @@ RSpec.describe User do
|
||||
end
|
||||
end
|
||||
|
||||
describe '#manually_disabled_discobot?' do
|
||||
it 'returns true if the user manually disabled new user tips' do
|
||||
describe "#manually_disabled_discobot?" do
|
||||
it "returns true if the user manually disabled new user tips" do
|
||||
user.user_option.skip_new_user_tips = true
|
||||
|
||||
expect(user.manually_disabled_discobot?).to eq(true)
|
||||
|
Reference in New Issue
Block a user