DEV: Use proper wording for contexts in specs

This commit is contained in:
Loïc Guitaut 2022-07-27 18:14:14 +02:00 committed by Loïc Guitaut
parent 02987e05d5
commit 3eaac56797
337 changed files with 2172 additions and 2723 deletions

View File

@ -7,7 +7,7 @@ GIT
GIT
remote: https://github.com/discourse/rubocop-discourse.git
revision: 5afeae107d3c003bf5bcf75457501ee7c1248fd2
revision: 9642e65f3767e5fd1d4e1aec4b617179f4128909
specs:
rubocop-discourse (2.5.0)
rubocop (>= 1.1.0)

View File

@ -85,7 +85,7 @@ RSpec.describe "Local Dates" do
expect(cooked).to include("data-countdown=")
end
context 'ranges' do
describe 'ranges' do
it 'generates ranges without time' do
raw = "[date-range from=2022-01-06 to=2022-01-08]"
cooked = Fabricate(:post, raw: raw).cooked

View File

@ -19,7 +19,7 @@ RSpec.describe PrettyText do
freeze_time
end
context 'emails simplified rendering' do
describe 'emails simplified rendering' do
it 'works with default markup' do
cooked = PrettyText.cook("[date=2018-05-08]")
cooked_mail = generate_html("2018-05-08T00:00:00Z UTC",
@ -70,7 +70,7 @@ RSpec.describe PrettyText do
end
end
context 'excerpt simplified rendering' do
describe 'excerpt simplified rendering' do
let(:post) { Fabricate(:post, raw: '[date=2019-10-16 time=14:00:00 format="LLLL" timezone="America/New_York"]') }
it 'adds UTC' do
@ -79,7 +79,7 @@ RSpec.describe PrettyText do
end
end
context 'special quotes' do
describe 'special quotes' do
it 'converts special quotes to regular quotes' do
# german
post = Fabricate(:post, raw: '[date=2019-10-16 time=14:00:00 format="LLLL" timezone=„America/New_York“]')
@ -97,7 +97,7 @@ RSpec.describe PrettyText do
end
end
context 'french quotes' do
describe 'french quotes' do
let(:post) { Fabricate(:post, raw: '[date=2019-10-16 time=14:00:00 format="LLLL" timezone=«America/New_York»]') }
it 'converts french quotes to regular quotes' do

View File

@ -133,12 +133,11 @@ RSpec.describe DiscourseNarrativeBot::AdvancedUserNarrative do
expect(Topic.last.title).to eq(I18n.t('discourse_narrative_bot.advanced_user_narrative.title'))
end
end
end
describe "#input" do
context 'edit tutorial' do
context 'when editing tutorial' do
before do
narrative.set_data(user,
state: :tutorial_edit,
@ -150,7 +149,7 @@ RSpec.describe DiscourseNarrativeBot::AdvancedUserNarrative do
)
end
describe 'when post is not in the right topic' do
context 'when post is not in the right topic' do
it 'should not do anything' do
other_post
narrative.expects(:enqueue_timeout_job).with(user).never
@ -160,7 +159,7 @@ RSpec.describe DiscourseNarrativeBot::AdvancedUserNarrative do
end
end
describe 'when user replies to the post' do
context 'when user replies to the post' do
it 'should create the right reply' do
post
narrative.expects(:enqueue_timeout_job).with(user).once
@ -174,7 +173,7 @@ RSpec.describe DiscourseNarrativeBot::AdvancedUserNarrative do
))
end
describe 'when reply contains the skip trigger' do
context 'when reply contains the skip trigger' do
it 'should create the right reply' do
post.update!(raw: "@#{discobot_username} #{skip_trigger.upcase}")
described_class.any_instance.expects(:enqueue_timeout_job).with(user)
@ -192,7 +191,7 @@ RSpec.describe DiscourseNarrativeBot::AdvancedUserNarrative do
end
end
describe 'when user edits the right post' do
context 'when user edits the right post' do
let(:post_2) { Fabricate(:post, user: post.user, topic: post.topic) }
it 'should create the right reply' do
@ -214,7 +213,7 @@ RSpec.describe DiscourseNarrativeBot::AdvancedUserNarrative do
end
end
context 'delete tutorial' do
context 'when deleting tutorial' do
before do
narrative.set_data(user,
state: :tutorial_delete,
@ -223,7 +222,7 @@ RSpec.describe DiscourseNarrativeBot::AdvancedUserNarrative do
)
end
describe 'when user replies to the topic' do
context 'when user replies to the topic' do
it 'should create the right reply' do
narrative.expects(:enqueue_timeout_job).with(user).once
@ -237,7 +236,7 @@ RSpec.describe DiscourseNarrativeBot::AdvancedUserNarrative do
expect(narrative.get_data(user)[:state].to_sym).to eq(:tutorial_delete)
end
describe 'when reply contains the skip trigger' do
context 'when reply contains the skip trigger' do
it 'should create the right reply' do
post.update!(raw: skip_trigger.upcase)
described_class.any_instance.expects(:enqueue_timeout_job).with(user)
@ -255,7 +254,7 @@ RSpec.describe DiscourseNarrativeBot::AdvancedUserNarrative do
end
end
describe 'when user destroys a post in a different topic' do
context 'when user destroys a post in a different topic' do
it 'should not do anything' do
other_post
narrative.expects(:enqueue_timeout_job).with(user).never
@ -266,7 +265,7 @@ RSpec.describe DiscourseNarrativeBot::AdvancedUserNarrative do
end
end
describe 'when user deletes a post in the right topic' do
context 'when user deletes a post in the right topic' do
it 'should create the right reply' do
post
@ -304,7 +303,7 @@ RSpec.describe DiscourseNarrativeBot::AdvancedUserNarrative do
end
end
context 'undelete post tutorial' do
context 'when undeleting post tutorial' do
before do
narrative.set_data(user,
state: :tutorial_recover,
@ -313,7 +312,7 @@ RSpec.describe DiscourseNarrativeBot::AdvancedUserNarrative do
)
end
describe 'when posts are configured to be deleted immediately' do
context 'when posts are configured to be deleted immediately' do
before do
SiteSetting.delete_removed_posts_after = 0
end
@ -337,7 +336,7 @@ RSpec.describe DiscourseNarrativeBot::AdvancedUserNarrative do
end
end
describe 'when user replies to the topic' do
context 'when user replies to the topic' do
it 'should create the right reply' do
narrative.set_data(user, narrative.get_data(user).merge(
tutorial_recover: { post_id: '1' }
@ -355,7 +354,7 @@ RSpec.describe DiscourseNarrativeBot::AdvancedUserNarrative do
expect(narrative.get_data(user)[:state].to_sym).to eq(:tutorial_recover)
end
describe 'when reply contains the skip trigger' do
context 'when reply contains the skip trigger' do
it 'should create the right reply' do
parent_category = Fabricate(:category, name: 'a')
_category = Fabricate(:category, parent_category: parent_category, name: 'b')
@ -377,7 +376,7 @@ RSpec.describe DiscourseNarrativeBot::AdvancedUserNarrative do
end
end
describe 'when user recovers a post in a different topic' do
context 'when user recovers a post in a different topic' do
it 'should not do anything' do
other_post
narrative.expects(:enqueue_timeout_job).with(user).never
@ -389,7 +388,7 @@ RSpec.describe DiscourseNarrativeBot::AdvancedUserNarrative do
end
end
describe 'when user recovers a post in the right topic' do
context 'when user recovers a post in the right topic' do
it 'should create the right reply' do
parent_category = Fabricate(:category, name: 'a')
_category = Fabricate(:category, parent_category: parent_category, name: 'b')
@ -412,7 +411,7 @@ RSpec.describe DiscourseNarrativeBot::AdvancedUserNarrative do
end
end
context 'category hashtag tutorial' do
context 'with category hashtag tutorial' do
before do
narrative.set_data(user,
state: :tutorial_category_hashtag,
@ -421,7 +420,7 @@ RSpec.describe DiscourseNarrativeBot::AdvancedUserNarrative do
)
end
describe 'when post is not in the right topic' do
context 'when post is not in the right topic' do
it 'should not do anything' do
other_post
narrative.expects(:enqueue_timeout_job).with(user).never
@ -434,7 +433,7 @@ RSpec.describe DiscourseNarrativeBot::AdvancedUserNarrative do
end
end
describe 'when user replies to the topic' do
context 'when user replies to the topic' do
it 'should create the right reply' do
narrative.input(:reply, user, post: post)
new_post = Post.last
@ -446,7 +445,7 @@ RSpec.describe DiscourseNarrativeBot::AdvancedUserNarrative do
expect(narrative.get_data(user)[:state].to_sym).to eq(:tutorial_category_hashtag)
end
describe 'when reply contains the skip trigger' do
context 'when reply contains the skip trigger' do
it 'should create the right reply' do
post.update!(raw: skip_trigger)
described_class.any_instance.expects(:enqueue_timeout_job).with(user)
@ -481,7 +480,7 @@ RSpec.describe DiscourseNarrativeBot::AdvancedUserNarrative do
end
end
context 'topic notification level tutorial' do
context 'with topic notification level tutorial' do
before do
narrative.set_data(user,
state: :tutorial_change_topic_notification_level,
@ -490,7 +489,7 @@ RSpec.describe DiscourseNarrativeBot::AdvancedUserNarrative do
)
end
describe 'when notification level is changed for another topic' do
context 'when notification level is changed for another topic' do
it 'should not do anything' do
other_topic
user
@ -508,7 +507,7 @@ RSpec.describe DiscourseNarrativeBot::AdvancedUserNarrative do
end
end
describe 'when user replies to the topic' do
context 'when user replies to the topic' do
it 'should create the right reply' do
narrative.input(:reply, user, post: post)
new_post = Post.last
@ -520,7 +519,7 @@ RSpec.describe DiscourseNarrativeBot::AdvancedUserNarrative do
expect(narrative.get_data(user)[:state].to_sym).to eq(:tutorial_change_topic_notification_level)
end
describe 'when reply contains the skip trigger' do
context 'when reply contains the skip trigger' do
it 'should create the right reply' do
post.update!(raw: skip_trigger)
described_class.any_instance.expects(:enqueue_timeout_job).with(user)
@ -538,7 +537,7 @@ RSpec.describe DiscourseNarrativeBot::AdvancedUserNarrative do
end
end
describe 'when user changed the topic notification level' do
context 'when user changed the topic notification level' do
it 'should create the right reply' do
TopicUser.change(
user.id,
@ -557,7 +556,7 @@ RSpec.describe DiscourseNarrativeBot::AdvancedUserNarrative do
end
end
describe 'when user cannot create polls' do
context 'when user cannot create polls' do
it 'should create the right reply (polls disabled)' do
SiteSetting.poll_enabled = false
@ -598,7 +597,7 @@ RSpec.describe DiscourseNarrativeBot::AdvancedUserNarrative do
end
end
context 'poll tutorial' do
context 'with poll tutorial' do
before do
narrative.set_data(user,
state: :tutorial_poll,
@ -620,7 +619,7 @@ RSpec.describe DiscourseNarrativeBot::AdvancedUserNarrative do
expect(post.errors[:base].size).to eq(0)
end
describe 'when post is not in the right topic' do
context 'when post is not in the right topic' do
it 'should not do anything' do
other_post
narrative.expects(:enqueue_timeout_job).with(user).never
@ -630,7 +629,7 @@ RSpec.describe DiscourseNarrativeBot::AdvancedUserNarrative do
end
end
describe 'when user replies to the topic' do
context 'when user replies to the topic' do
it 'should create the right reply' do
narrative.input(:reply, user, post: post)
new_post = Post.last
@ -639,7 +638,7 @@ RSpec.describe DiscourseNarrativeBot::AdvancedUserNarrative do
expect(narrative.get_data(user)[:state].to_sym).to eq(:tutorial_poll)
end
describe 'when reply contains the skip trigger' do
context 'when reply contains the skip trigger' do
it 'should create the right reply' do
post.update!(raw: skip_trigger)
described_class.any_instance.expects(:enqueue_timeout_job).with(user)
@ -672,7 +671,7 @@ RSpec.describe DiscourseNarrativeBot::AdvancedUserNarrative do
end
end
context "details tutorial" do
context "with details tutorial" do
before do
narrative.set_data(user,
state: :tutorial_details,
@ -681,7 +680,7 @@ RSpec.describe DiscourseNarrativeBot::AdvancedUserNarrative do
)
end
describe 'when post is not in the right topic' do
context 'when post is not in the right topic' do
it 'should not do anything' do
other_post
narrative.expects(:enqueue_timeout_job).with(user).never
@ -691,7 +690,7 @@ RSpec.describe DiscourseNarrativeBot::AdvancedUserNarrative do
end
end
describe 'when user replies to the topic' do
context 'when user replies to the topic' do
it 'should create the right reply' do
narrative.input(:reply, user, post: post)
@ -699,7 +698,7 @@ RSpec.describe DiscourseNarrativeBot::AdvancedUserNarrative do
expect(narrative.get_data(user)[:state].to_sym).to eq(:tutorial_details)
end
describe 'when reply contains the skip trigger' do
context 'when reply contains the skip trigger' do
it 'should create the right reply' do
post.update!(raw: skip_trigger)

View File

@ -49,7 +49,7 @@ RSpec.describe DiscourseNarrativeBot::TrackSelector do
end
describe '#select' do
context 'in a PM with discobot' do
context 'when in a PM with discobot' do
let(:first_post) { Fabricate(:post, user: discobot_user) }
let(:topic) do
@ -63,7 +63,7 @@ RSpec.describe DiscourseNarrativeBot::TrackSelector do
let(:post) { Fabricate(:post, topic: topic, user: user) }
context 'during a tutorial track' do
context 'while in a tutorial track' do
before do
narrative.set_data(user,
state: :tutorial_formatting,
@ -146,7 +146,7 @@ RSpec.describe DiscourseNarrativeBot::TrackSelector do
end
end
describe 'when user thank the bot' do
context 'when user thank the bot' do
it 'should like the post' do
post.update!(raw: 'thanks!')
@ -176,7 +176,7 @@ RSpec.describe DiscourseNarrativeBot::TrackSelector do
.to eq("tutorial_bookmark")
end
describe 'reset trigger in surrounded by quotes' do
context 'when reset trigger in surrounded by quotes' do
it 'should reset the track' do
post.update!(
raw: "'#{described_class.reset_trigger} #{DiscourseNarrativeBot::NewUserNarrative.reset_trigger}'"
@ -189,8 +189,8 @@ RSpec.describe DiscourseNarrativeBot::TrackSelector do
end
end
describe 'reset trigger in a middle of a sentence' do
describe 'when post is less than reset trigger exact match limit' do
context 'when reset trigger in a middle of a sentence' do
context 'when post is less than reset trigger exact match limit' do
it 'should reset the track' do
post.update!(
raw: "I would like to #{described_class.reset_trigger} #{DiscourseNarrativeBot::NewUserNarrative.reset_trigger} now"
@ -203,7 +203,7 @@ RSpec.describe DiscourseNarrativeBot::TrackSelector do
end
end
describe 'when post exceeds reset trigger exact match limit' do
context 'when post exceeds reset trigger exact match limit' do
it 'should not reset the track' do
post.update!(
raw: "I would like to #{described_class.reset_trigger} #{DiscourseNarrativeBot::NewUserNarrative.reset_trigger} now #{'a' * described_class::RESET_TRIGGER_EXACT_MATCH_LENGTH}"
@ -233,7 +233,7 @@ RSpec.describe DiscourseNarrativeBot::TrackSelector do
end
end
context 'at the end of a tutorial track' do
context 'when at the end of a tutorial track' do
before do
narrative.set_data(user,
state: :end,
@ -242,7 +242,7 @@ RSpec.describe DiscourseNarrativeBot::TrackSelector do
)
end
context 'generic replies' do
context 'with generic replies' do
after do
Discourse.redis.del("#{described_class::GENERIC_REPLIES_COUNT_PREFIX}#{user.id}")
end
@ -290,7 +290,7 @@ RSpec.describe DiscourseNarrativeBot::TrackSelector do
expect(new_post.raw).to eq(random_mention_reply)
end
describe 'when asking discobot for help' do
context 'when asking discobot for help' do
it 'should create the right reply' do
post.update!(raw: 'show me what you can do @discobot display help')
described_class.new(:reply, user, post_id: post.id).select
@ -298,7 +298,7 @@ RSpec.describe DiscourseNarrativeBot::TrackSelector do
expect(Post.last.raw).to include(help_message)
end
describe 'as an admin or moderator' do
context 'as an admin or moderator' do
it 'should include the commands to start the advanced user track' do
user.update!(moderator: true)
post.update!(raw: 'Show me what you can do @discobot display help')
@ -311,7 +311,7 @@ RSpec.describe DiscourseNarrativeBot::TrackSelector do
end
end
describe 'as a user that has completed the new user track' do
context 'as a user that has completed the new user track' do
it 'should include the commands to start the advanced user track' do
narrative.set_data(user,
state: :end,
@ -335,7 +335,7 @@ RSpec.describe DiscourseNarrativeBot::TrackSelector do
end
end
describe 'when discobot is asked to roll dice' do
context 'when discobot is asked to roll dice' do
before do
narrative.set_data(user,
state: :end,
@ -353,7 +353,7 @@ RSpec.describe DiscourseNarrativeBot::TrackSelector do
))
end
describe 'when range of dice request is too high' do
context 'when range of dice request is too high' do
before do
srand(1)
end
@ -376,7 +376,7 @@ RSpec.describe DiscourseNarrativeBot::TrackSelector do
end
end
describe 'when number of dice to roll is too high' do
context 'when number of dice to roll is too high' do
it 'should create the right reply' do
post.update!(raw: "roll #{DiscourseNarrativeBot::Dice::MAXIMUM_NUM_OF_DICE + 1}d1")
described_class.new(:reply, user, post_id: post.id).select
@ -392,7 +392,7 @@ RSpec.describe DiscourseNarrativeBot::TrackSelector do
end
end
describe 'when dice combination is invalid' do
context 'when dice combination is invalid' do
it 'should create the right reply' do
post.update!(raw: "roll 0d1")
described_class.new(:reply, user, post_id: post.id).select
@ -407,7 +407,7 @@ RSpec.describe DiscourseNarrativeBot::TrackSelector do
end
context 'when in a normal PM with discobot' do
describe 'when discobot is replied to' do
context 'when discobot is replied to' do
it 'should create the right reply' do
SiteSetting.discourse_narrative_bot_disable_public_replies = true
post.update!(raw: 'Show me what you can do @discobot')
@ -439,16 +439,16 @@ RSpec.describe DiscourseNarrativeBot::TrackSelector do
end
end
context 'random discobot mentions' do
context 'with random discobot mentions' do
let(:topic) { Fabricate(:topic) }
let(:post) { Fabricate(:post, topic: topic, user: user) }
describe 'when discobot public replies are disabled' do
context 'when discobot public replies are disabled' do
before do
SiteSetting.discourse_narrative_bot_disable_public_replies = true
end
describe 'when discobot is mentioned' do
context 'when discobot is mentioned' do
it 'should not reply' do
post.update!(raw: 'Show me what you can do @discobot')
@ -459,7 +459,7 @@ RSpec.describe DiscourseNarrativeBot::TrackSelector do
end
end
describe 'when discobot is mentioned' do
context 'when discobot is mentioned' do
it 'should create the right reply' do
post.update!(raw: 'Show me what you can do @discobot')
described_class.new(:reply, user, post_id: post.id).select
@ -496,7 +496,7 @@ RSpec.describe DiscourseNarrativeBot::TrackSelector do
expect(new_post.raw).to eq(random_mention_reply)
end
describe 'rate limiting random reply message in public topic' do
context 'with rate limiting random reply message in public topic' do
let(:topic) { Fabricate(:topic) }
let(:other_post) { Fabricate(:post, raw: '@discobot show me something', topic: topic) }
let(:post) { Fabricate(:post, topic: topic) }
@ -505,7 +505,7 @@ RSpec.describe DiscourseNarrativeBot::TrackSelector do
Discourse.redis.flushdb
end
describe 'when random reply massage has been displayed in the last 6 hours' do
context 'when random reply massage has been displayed in the last 6 hours' do
it 'should not do anything' do
Discourse.redis.set(
"#{described_class::PUBLIC_DISPLAY_BOT_HELP_KEY}:#{other_post.topic_id}",
@ -522,7 +522,7 @@ RSpec.describe DiscourseNarrativeBot::TrackSelector do
end
end
describe 'when random reply message has not been displayed in the last 6 hours' do
context 'when random reply message has not been displayed in the last 6 hours' do
it 'should create the right reply' do
Discourse.redis.set(
"#{described_class::PUBLIC_DISPLAY_BOT_HELP_KEY}:#{other_post.topic_id}",
@ -540,7 +540,7 @@ RSpec.describe DiscourseNarrativeBot::TrackSelector do
end
end
describe 'when random reply message has been displayed in the last 10 replies' do
context 'when random reply message has been displayed in the last 10 replies' do
it 'should not do anything' do
described_class.new(:reply, user, post_id: other_post.id).select
expect(Post.last.raw).to eq(random_mention_reply)
@ -559,7 +559,7 @@ RSpec.describe DiscourseNarrativeBot::TrackSelector do
end
end
describe 'when asking discobot for help' do
context 'when asking discobot for help' do
it 'should create the right reply' do
post.update!(raw: '@discobot display help')
described_class.new(:reply, user, post_id: post.id).select
@ -568,8 +568,8 @@ RSpec.describe DiscourseNarrativeBot::TrackSelector do
end
end
describe 'when asking discobot to start new user track' do
describe 'invalid text' do
context 'when asking discobot to start new user track' do
context 'with invalid text' do
it 'should not trigger the bot' do
post.update!(raw: "`@discobot #{I18n.t('discourse_narrative_bot.track_selector.reset_trigger')} #{I18n.t(DiscourseNarrativeBot::NewUserNarrative.reset_trigger)}`")
@ -579,7 +579,7 @@ RSpec.describe DiscourseNarrativeBot::TrackSelector do
end
end
describe 'when discobot is asked to roll dice' do
context 'when discobot is asked to roll dice' do
it 'should create the right reply' do
post.update!(raw: '@discobot roll 2d1')
described_class.new(:reply, user, post_id: post.id).select
@ -591,7 +591,7 @@ RSpec.describe DiscourseNarrativeBot::TrackSelector do
))
end
describe 'when dice roll is requested incorrectly' do
context 'when dice roll is requested incorrectly' do
it 'should create the right reply' do
post.update!(raw: 'roll 2d1 @discobot')
described_class.new(:reply, user, post_id: post.id).select
@ -600,7 +600,7 @@ RSpec.describe DiscourseNarrativeBot::TrackSelector do
end
end
describe 'when roll dice command is present inside a quote' do
context 'when roll dice command is present inside a quote' do
it 'should ignore the command' do
user
post.update!(raw: "[quote=\"Donkey, post:6, topic:1\"]\n@discobot roll 2d1\n[/quote]")
@ -611,7 +611,7 @@ RSpec.describe DiscourseNarrativeBot::TrackSelector do
end
end
describe 'when a quote is requested' do
context 'when a quote is requested' do
it 'should create the right reply' do
post.update!(raw: "@discobot quote")
@ -624,7 +624,7 @@ RSpec.describe DiscourseNarrativeBot::TrackSelector do
))
end
describe 'when quote is requested incorrectly' do
context 'when quote is requested incorrectly' do
it 'should create the right reply' do
post.update!(raw: 'quote @discobot')
described_class.new(:reply, user, post_id: post.id).select
@ -633,7 +633,7 @@ RSpec.describe DiscourseNarrativeBot::TrackSelector do
end
end
describe 'when quote command is present inside a onebox or quote' do
context 'when quote command is present inside a onebox or quote' do
it 'should ignore the command' do
user
post.update!(raw: "[quote=\"Donkey, post:6, topic:1\"]\n@discobot quote\n[/quote]")
@ -643,7 +643,7 @@ RSpec.describe DiscourseNarrativeBot::TrackSelector do
end
end
describe 'when user requesting quote has a preferred locale' do
context 'when user requesting quote has a preferred locale' do
before do
SiteSetting.allow_user_locale = true
user.update!(locale: 'it')
@ -662,7 +662,7 @@ RSpec.describe DiscourseNarrativeBot::TrackSelector do
end
end
describe 'when magic 8 ball is requested' do
context 'when magic 8 ball is requested' do
before do
srand(1)
end
@ -677,8 +677,8 @@ RSpec.describe DiscourseNarrativeBot::TrackSelector do
end
end
describe 'when bot is asked to reset/start a track' do
describe 'when user likes a post containing a reset trigger' do
context 'when bot is asked to reset/start a track' do
context 'when user likes a post containing a reset trigger' do
it 'should not start the track' do
another_post = Fabricate(:post,
user: Fabricate(:user),
@ -694,7 +694,7 @@ RSpec.describe DiscourseNarrativeBot::TrackSelector do
end
end
describe "when new and advanced user triggers overlap" do
context "when new and advanced user triggers overlap" do
before do
@overrides = []
@ -723,7 +723,7 @@ RSpec.describe DiscourseNarrativeBot::TrackSelector do
end
end
context 'pm to self' do
context 'when sending pm to self' do
let(:other_topic) do
topic_allowed_user = Fabricate.build(:topic_allowed_user, user: user)
Fabricate(:private_message_topic, topic_allowed_users: [topic_allowed_user])
@ -731,7 +731,7 @@ RSpec.describe DiscourseNarrativeBot::TrackSelector do
let(:other_post) { Fabricate(:post, topic: other_topic) }
describe 'when a new message is made' do
context 'when a new message is made' do
it 'should not do anything' do
other_post
@ -741,7 +741,7 @@ RSpec.describe DiscourseNarrativeBot::TrackSelector do
end
end
context 'pms to bot' do
context 'when sending pms to bot' do
let(:other_topic) do
topic_allowed_user = Fabricate.build(:topic_allowed_user, user: user)
bot = Fabricate.build(:topic_allowed_user, user: discobot_user)
@ -750,7 +750,7 @@ RSpec.describe DiscourseNarrativeBot::TrackSelector do
let(:other_post) { Fabricate(:post, topic: other_topic) }
describe 'when a new like is made' do
context 'when a new like is made' do
it 'should not do anything' do
other_post
expect { described_class.new(:like, user, post_id: other_post.id).select }
@ -758,7 +758,7 @@ RSpec.describe DiscourseNarrativeBot::TrackSelector do
end
end
describe 'when a new message is made' do
context 'when a new message is made' do
it 'should create the right reply' do
described_class.new(:reply, user, post_id: other_post.id).select
@ -766,7 +766,7 @@ RSpec.describe DiscourseNarrativeBot::TrackSelector do
end
end
describe 'when user thanks the bot' do
context 'when user thanks the bot' do
it 'should like the post' do
other_post.update!(raw: 'thanks!')

View File

@ -19,7 +19,7 @@ RSpec.describe Jobs::DiscourseNarrativeBot::RemapOldBotImages do
end
end
context 'subfolder' do
context 'with subfolder' do
let!(:post) do
Fabricate(:post,
user: ::DiscourseNarrativeBot::Base.new.discobot_user,

View File

@ -14,7 +14,7 @@ RSpec.describe "Discobot welcome post" do
end
end
context 'When discourse_narrative_bot_welcome_post_delay is greater than 0' do
context 'when discourse_narrative_bot_welcome_post_delay is greater than 0' do
before do
SiteSetting.discourse_narrative_bot_welcome_post_delay = 5
end

View File

@ -32,7 +32,7 @@ RSpec.describe User do
end
describe 'welcome post' do
context 'disabled' do
context 'when disabled' do
before do
SiteSetting.disable_discourse_narrative_bot_welcome_post = true
end
@ -57,7 +57,7 @@ RSpec.describe User do
end
end
context 'enabled' do
context 'when enabled' do
before do
SiteSetting.disable_discourse_narrative_bot_welcome_post = false
end

View File

@ -103,7 +103,7 @@ RSpec.describe "DiscoursePoll endpoints" do
end
end
context "number poll" do
context "with number poll" do
let(:post) { Fabricate(:post, raw: "[poll type=number min=1 max=20 step=1 public=true]\n[/poll]") }
it 'should return the right response' do

View File

@ -3,7 +3,6 @@
require "rails_helper"
RSpec.describe Admin::UsersController do
let(:admin) { Fabricate(:admin) }
before { sign_in(admin) }
@ -11,7 +10,7 @@ RSpec.describe Admin::UsersController do
describe '#destroy' do
let(:delete_me) { Fabricate(:user) }
context "user has voted" do
context "when user has voted" do
let!(:topic) { Fabricate(:topic, user: admin) }
let!(:post) { Fabricate(:post, topic: topic, user: admin, raw: "[poll]\n- a\n- b\n[/poll]") }
@ -26,5 +25,4 @@ RSpec.describe Admin::UsersController do
end
end
end
end

View File

@ -16,10 +16,10 @@ RSpec.describe PollOptionSerializer do
poll.poll_votes.create!(poll_option_id: poll.poll_options.first.id, user_id: voter.id)
end
context 'poll results are public' do
context 'when poll results are public' do
let(:post) { Fabricate(:post, raw: "[poll]\n- A\n- B\n[/poll]") }
context 'user is not staff' do
context 'when user is not staff' do
let(:user) { Fabricate(:user) }
it 'include votes' do
@ -30,10 +30,10 @@ RSpec.describe PollOptionSerializer do
end
end
context 'poll results are staff only' do
context 'when poll results are staff only' do
let(:post) { Fabricate(:post, raw: "[poll results=staff_only]\n- A\n- B\n[/poll]") }
context 'user is not staff' do
context 'when user is not staff' do
let(:user) { Fabricate(:user) }
it 'doesnt include votes' do
@ -43,7 +43,7 @@ RSpec.describe PollOptionSerializer do
end
end
context 'user staff' do
context 'when user is staff' do
let(:admin) { Fabricate(:admin) }
it 'includes votes' do

View File

@ -5,12 +5,12 @@ RSpec.describe 'SiteSetting.styleguide_admin_only' do
SiteSetting.styleguide_enabled = true
end
context 'styleguide is admin only' do
context 'when styleguide is admin only' do
before do
SiteSetting.styleguide_admin_only = true
end
context 'user is admin' do
context 'when user is admin' do
before do
sign_in(Fabricate(:admin))
end
@ -21,7 +21,7 @@ RSpec.describe 'SiteSetting.styleguide_admin_only' do
end
end
context 'user is not admin' do
context 'when user is not admin' do
before do
sign_in(Fabricate(:user))
end
@ -39,7 +39,7 @@ RSpec.describe 'SiteSetting.styleguide_enabled' do
sign_in(Fabricate(:admin))
end
context 'style is enabled' do
context 'when style is enabled' do
before do
SiteSetting.styleguide_enabled = true
end
@ -50,7 +50,7 @@ RSpec.describe 'SiteSetting.styleguide_enabled' do
end
end
context 'styleguide is disabled' do
context 'when styleguide is disabled' do
before do
SiteSetting.styleguide_enabled = false
end

View File

@ -6,14 +6,14 @@ RSpec.describe 'Styleguide assets' do
sign_in(Fabricate(:admin))
end
context 'visits homepage' do
context 'when visiting homepage' do
it 'doesnt load styleguide assets' do
get '/'
expect(response.body).to_not include('styleguide')
end
end
context 'visits styleguide' do
context 'when visiting styleguide' do
it 'loads styleguide assets' do
get '/styleguide'
expect(response.body).to include('styleguide')

View File

@ -2,7 +2,6 @@
# frozen_string_literal: true
RSpec.describe ApplicationHelper do
describe "preload_script" do
def preload_link(url)
<<~HTML
@ -111,37 +110,45 @@ RSpec.describe ApplicationHelper do
)
helper.request.env[:resolved_theme_id] = dark_theme.id
end
context "on desktop" do
context "when on desktop" do
before do
session[:mobile_view] = '0'
end
context "when logo_dark is not set" do
it "will return site_logo_url instead" do
expect(helper.application_logo_url).to eq(SiteSetting.site_logo_url)
end
end
context "when logo_dark is set" do
before do
SiteSetting.logo_dark = Fabricate(:upload, url: '/images/logo-dark.png')
end
it "will return site_logo_dark_url" do
expect(helper.application_logo_url).to eq(SiteSetting.site_logo_dark_url)
end
end
end
context "on mobile" do
context "when on mobile" do
before do
session[:mobile_view] = '1'
end
context "when mobile_logo_dark is not set" do
it "will return site_mobile_logo_url instead" do
expect(helper.application_logo_url).to eq(SiteSetting.site_mobile_logo_url)
end
end
context "when mobile_logo_dark is set" do
before do
SiteSetting.mobile_logo_dark = Fabricate(:upload, url: '/images/mobile-logo-dark.png')
end
it "will return site_mobile_logo_dark_url" do
expect(helper.application_logo_url).to eq(SiteSetting.site_mobile_logo_dark_url)
end
@ -203,8 +210,8 @@ RSpec.describe ApplicationHelper do
end
end
describe "mobile_view?" do
context "enable_mobile_theme is true" do
describe "#mobile_view?" do
context "when enable_mobile_theme is true" do
before do
SiteSetting.enable_mobile_theme = true
end
@ -219,7 +226,7 @@ RSpec.describe ApplicationHelper do
expect(helper.mobile_view?).to eq(false)
end
context "mobile_view session is cleared" do
context "when mobile_view session is cleared" do
before do
params[:mobile_view] = 'auto'
end
@ -237,7 +244,7 @@ RSpec.describe ApplicationHelper do
end
end
context "mobile_view is not set" do
context "when mobile_view is not set" do
it "is false if user agent is not mobile" do
controller.request.stubs(:user_agent).returns('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36')
expect(helper.mobile_view?).to be_falsey
@ -275,7 +282,7 @@ RSpec.describe ApplicationHelper do
end
end
context "enable_mobile_theme is false" do
context "when enable_mobile_theme is false" do
before do
SiteSetting.enable_mobile_theme = false
end
@ -290,7 +297,7 @@ RSpec.describe ApplicationHelper do
expect(helper.mobile_view?).to eq(false)
end
context "mobile_view is not set" do
context "when mobile_view is not set" do
it "is false if user agent is not mobile" do
controller.request.stubs(:user_agent).returns('Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.17 Safari/537.36')
expect(helper.mobile_view?).to eq(false)
@ -418,7 +425,6 @@ RSpec.describe ApplicationHelper do
end
describe 'crawlable_meta_data' do
it 'Supports ASCII URLs with odd chars' do
result = helper.crawlable_meta_data(
url: (+"http://localhost/ión").force_encoding("ASCII-8BIT").freeze
@ -427,7 +433,7 @@ RSpec.describe ApplicationHelper do
expect(result).to include("ión")
end
context "opengraph image" do
context "with opengraph image" do
it 'returns the correct image' do
SiteSetting.opengraph_image = Fabricate(:upload,
url: '/images/og-image.png'
@ -544,7 +550,7 @@ RSpec.describe ApplicationHelper do
expect(cs_stylesheets).not_to include("(prefers-color-scheme: dark)")
end
context "custom light scheme" do
context "with custom light scheme" do
before do
@new_cs = Fabricate(:color_scheme, name: 'Flamboyant')
user.user_option.color_scheme_id = @new_cs.id
@ -576,7 +582,7 @@ RSpec.describe ApplicationHelper do
end
end
context "dark scheme with user option and/or cookies" do
context "with dark scheme with user option and/or cookies" do
before do
user.user_option.dark_scheme_id = -1
user.user_option.save!
@ -615,7 +621,6 @@ RSpec.describe ApplicationHelper do
color_stylesheets = helper.discourse_color_scheme_stylesheets
expect(color_stylesheets).not_to include("(prefers-color-scheme: dark)")
end
end
end

View File

@ -3,7 +3,6 @@
require "import_export"
RSpec.describe ImportExport::Importer do
before do
STDOUT.stubs(:write)
end
@ -18,7 +17,6 @@ RSpec.describe ImportExport::Importer do
end
describe '.perform' do
it 'topics and users' do
data = import_data.dup
data[:categories] = nil
@ -32,7 +30,7 @@ RSpec.describe ImportExport::Importer do
.and change { User.count }.by(2)
end
context 'categories and groups' do
context 'with categories and groups' do
it 'works' do
data = import_data.dup
data[:topics] = nil
@ -105,7 +103,5 @@ RSpec.describe ImportExport::Importer do
.and change { Topic.count }.by(8)
.and change { User.count }.by(2)
end
end
end

View File

@ -1,7 +1,7 @@
# frozen_string_literal: true
RSpec.describe "auto reject reviewable users" do
context "reviewable users" do
describe "reviewable users" do
fab!(:old_user) { Fabricate(:reviewable, created_at: 80.days.ago) }
it "does not send email to rejected user" do

View File

@ -2,7 +2,6 @@
# frozen_string_literal: true
RSpec.describe "category tag restrictions" do
def filter_allowed_tags(opts = {})
DiscourseTagging.filter_allowed_tags(Guardian.new(user), opts)
end
@ -22,7 +21,7 @@ RSpec.describe "category tag restrictions" do
SiteSetting.min_trust_level_to_tag_topics = 0
end
context "tags restricted to one category" do
context "with tags restricted to one category" do
fab!(:category_with_tags) { Fabricate(:category) }
fab!(:other_category) { Fabricate(:category) }
@ -94,7 +93,7 @@ RSpec.describe "category tag restrictions" do
expect { other_category.update(allowed_tags: [tag1.name, 'tag-stuff', tag2.name, 'another-tag']) }.to change { Tag.count }.by(2)
end
context 'required tags from tag group' do
context 'with required tags from tag group' do
fab!(:tag_group) { Fabricate(:tag_group, tags: [tag1, tag3]) }
before { category_with_tags.update!(category_required_tag_groups: [CategoryRequiredTagGroup.new(tag_group: tag_group, min_count: 1)]) }
@ -105,7 +104,7 @@ RSpec.describe "category tag restrictions" do
end
end
context 'category allows other tags to be used' do
context 'when category allows other tags to be used' do
before do
category_with_tags.update!(allow_global_tags: true)
end
@ -128,7 +127,7 @@ RSpec.describe "category tag restrictions" do
expect_same_tag_names(filter_allowed_tags(for_input: true, category: other_category, selected_tags: [tag3.name], term: 'tag'), [tag4])
end
context 'required tags from tag group' do
context 'with required tags from tag group' do
fab!(:tag_group) { Fabricate(:tag_group, tags: [tag1, tag3]) }
before { category_with_tags.update!(category_required_tag_groups: [CategoryRequiredTagGroup.new(tag_group: tag_group, min_count: 1)]) }
@ -141,7 +140,7 @@ RSpec.describe "category tag restrictions" do
end
end
context "tag groups restricted to a category" do
context "with tag groups restricted to a category" do
fab!(:tag_group1) { Fabricate(:tag_group) }
fab!(:category) { Fabricate(:category) }
fab!(:other_category) { Fabricate(:category) }
@ -188,7 +187,7 @@ RSpec.describe "category tag restrictions" do
expect_same_tag_names(filter_allowed_tags(for_input: true, term: 'with:c'), [tag_with_colon])
end
context 'required tags from tag group' do
context 'with required tags from tag group' do
fab!(:tag_group) { Fabricate(:tag_group, tags: [tag1, tag3]) }
before { category.update!(category_required_tag_groups: [CategoryRequiredTagGroup.new(tag_group: tag_group, min_count: 1)]) }
@ -199,7 +198,7 @@ RSpec.describe "category tag restrictions" do
end
end
context 'category allows other tags to be used' do
context 'when category allows other tags to be used' do
before do
category.update!(allow_global_tags: true)
end
@ -222,7 +221,7 @@ RSpec.describe "category tag restrictions" do
expect_same_tag_names(filter_allowed_tags(for_input: true, category: other_category), [tag1])
end
context 'required tags from tag group' do
context 'with required tags from tag group' do
fab!(:tag_group) { Fabricate(:tag_group, tags: [tag1, tag3]) }
before { category.update!(category_required_tag_groups: [CategoryRequiredTagGroup.new(tag_group: tag_group, min_count: 1)]) }
@ -233,7 +232,7 @@ RSpec.describe "category tag restrictions" do
end
end
context 'another category has restricted tags using groups' do
context 'when another category has restricted tags using groups' do
fab!(:category2) { Fabricate(:category) }
fab!(:tag_group2) { Fabricate(:tag_group) }
@ -260,7 +259,7 @@ RSpec.describe "category tag restrictions" do
end
end
context 'another category has restricted tags' do
context 'when another category has restricted tags' do
fab!(:category2) { Fabricate(:category) }
it "doesn't filter tags that are also restricted in another category" do
@ -274,7 +273,7 @@ RSpec.describe "category tag restrictions" do
end
end
context "tag groups with parent tag" do
context "with tag groups with parent tag" do
it "for input field, filter_allowed_tags returns results based on whether parent tag is present or not" do
tag_group = Fabricate(:tag_group, parent_tag_id: tag1.id)
tag_group.tags = [tag3, tag4]
@ -318,7 +317,7 @@ RSpec.describe "category tag restrictions" do
expect_same_tag_names(filter_allowed_tags(for_input: true, selected_tags: [tag3.name]), [tag4, common])
end
context 'required tags from tag group' do
context 'with required tags from tag group' do
fab!(:tag_group) { Fabricate(:tag_group, tags: [tag1, tag2]) }
fab!(:category) { Fabricate(:category, category_required_tag_groups: [CategoryRequiredTagGroup.new(tag_group: tag_group, min_count: 1)]) }
@ -331,7 +330,7 @@ RSpec.describe "category tag restrictions" do
end
end
context "and category restrictions" do
context "with category restrictions" do
fab!(:car_category) { Fabricate(:category) }
fab!(:other_category) { Fabricate(:category) }
fab!(:makes) { Fabricate(:tag_group, name: "Makes") }
@ -395,7 +394,7 @@ RSpec.describe "category tag restrictions" do
expect(post.topic.tags.map(&:name).sort).to eq(['ford', 'mustang'])
end
context "limit one tag from each group" do
context "with limit one tag from each group" do
before do
makes.update(one_per_topic: true)
honda_group.update(one_per_topic: true)
@ -460,7 +459,7 @@ RSpec.describe "tag topic counts per category" do
expect(CategoryTagStat.where(category: category, tag: tag2).sum(:topic_count)).to eq(1)
end
context "topic with 2 tags" do
context "with topic with 2 tags" do
fab!(:topic) { Fabricate(:topic, category: category, tags: [tag1, tag2]) }
fab!(:post) { Fabricate(:post, user: topic.user, topic: topic) }
@ -492,7 +491,7 @@ RSpec.describe "tag topic counts per category" do
end
end
context "topic with one tag" do
context "with topic with one tag" do
fab!(:topic) { Fabricate(:topic, tags: [tag1], category: category) }
fab!(:post) { Fabricate(:post, user: topic.user, topic: topic) }

View File

@ -11,7 +11,7 @@ RSpec.describe "Outbound Email" do
[message, result]
end
context "email custom headers" do
describe "email custom headers" do
it "discards the custom header if it is one that has already been set based on arguments" do
SiteSetting.email_custom_headers = "Precedence: bulk"
post = Fabricate(:post)

View File

@ -1,8 +1,7 @@
# frozen_string_literal: true
RSpec.describe EmailStyle do
context "ERB evaluation" do
describe "ERB evaluation" do
it "does not evaluate ERB outside of the email itself" do
SiteSetting.email_custom_template = "<hello>%{email_content}</hello><%= (111 * 333) %>"
html = Email::Renderer.new(UserNotifications.signup(Fabricate(:user))).html
@ -23,7 +22,7 @@ RSpec.describe EmailStyle do
SiteSetting.remove_override!(:email_custom_css)
end
context 'invite' do
context 'with invite' do
fab!(:invite) { Fabricate(:invite) }
let(:invite_mail) { InviteMailer.send_invite(invite) }
@ -48,7 +47,7 @@ RSpec.describe EmailStyle do
end
end
context 'user_replied' do
context 'when user_replied' do
let(:response_by_user) { Fabricate(:user, name: "John Doe") }
let(:category) { Fabricate(:category, name: 'India') }
let(:topic) { Fabricate(:topic, category: category, title: "Super cool topic") }
@ -80,7 +79,7 @@ RSpec.describe EmailStyle do
# TODO: translation override
end
context 'signup' do
context 'with signup' do
let(:signup_mail) { UserNotifications.signup(Fabricate(:user)) }
subject(:mail_html) { Email::Renderer.new(signup_mail).html }
@ -89,7 +88,7 @@ RSpec.describe EmailStyle do
expect(mail_html).to include('activate-account')
end
context 'translation override' do
context 'with translation override' do
before do
TranslationOverride.upsert!(
SiteSetting.default_locale,
@ -121,7 +120,7 @@ RSpec.describe EmailStyle do
end
end
context 'digest' do
context 'with digest' do
fab!(:popular_topic) { Fabricate(:topic, user: Fabricate(:coding_horror), created_at: 1.hour.ago) }
let(:summary_email) { UserNotifications.digest(Fabricate(:user)) }
subject(:mail_html) { Email::Renderer.new(summary_email).html }

View File

@ -2,13 +2,12 @@
# frozen_string_literal: true
RSpec.describe "spammers on same IP" do
let(:ip_address) { '182.189.119.174' }
let!(:spammer1) { Fabricate(:user, ip_address: ip_address) }
let!(:spammer2) { Fabricate(:user, ip_address: ip_address) }
let(:spammer3) { Fabricate(:user, ip_address: ip_address) }
context 'flag_sockpuppets is disabled' do
context 'when flag_sockpuppets is disabled' do
let!(:first_post) { create_post(user: spammer1) }
let!(:second_post) { create_post(user: spammer2, topic: first_post.topic) }
@ -18,7 +17,7 @@ RSpec.describe "spammers on same IP" do
end
end
context 'flag_sockpuppets is enabled' do
context 'when flag_sockpuppets is enabled' do
before do
SiteSetting.flag_sockpuppets = true
end
@ -27,10 +26,10 @@ RSpec.describe "spammers on same IP" do
SiteSetting.flag_sockpuppets = false
end
context 'first spammer starts a topic' do
context 'when first spammer starts a topic' do
let!(:first_post) { create_post(user: spammer1) }
context 'second spammer replies' do
context 'when second spammer replies' do
let!(:second_post) { create_post(user: spammer2, topic: first_post.topic) }
it 'should increase spam count' do
@ -38,7 +37,7 @@ RSpec.describe "spammers on same IP" do
expect(second_post.reload.spam_count).to eq(1)
end
context 'third spam post' do
context 'with third spam post' do
let!(:third_post) { create_post(user: spammer3, topic: first_post.topic) }
it 'should increase spam count' do
@ -50,13 +49,13 @@ RSpec.describe "spammers on same IP" do
end
end
context 'first user is not new' do
context 'when first user is not new' do
let!(:old_user) { Fabricate(:user, ip_address: ip_address, created_at: 2.days.ago, trust_level: TrustLevel[1]) }
context 'first user starts a topic' do
context 'when first user starts a topic' do
let!(:first_post) { create_post(user: old_user) }
context 'a reply by a new user at the same IP address' do
context 'with a reply by a new user at the same IP address' do
let!(:second_post) { create_post(user: spammer2, topic: first_post.topic) }
it 'should increase the spam count correctly' do
@ -67,5 +66,4 @@ RSpec.describe "spammers on same IP" do
end
end
end
end

View File

@ -2,7 +2,6 @@
# frozen_string_literal: true
RSpec.describe "spam rules for users" do
describe 'auto-silence users based on flagging' do
fab!(:admin) { Fabricate(:admin) } # needed to send a system message
fab!(:moderator) { Fabricate(:moderator) }
@ -16,10 +15,10 @@ RSpec.describe "spam rules for users" do
SiteSetting.num_users_to_silence_new_user = 2
end
context 'spammer is a new user' do
context 'when spammer is a new user' do
fab!(:spammer) { Fabricate(:user, trust_level: TrustLevel[0]) }
context 'spammer post is not flagged enough times' do
context 'when spammer post is not flagged enough times' do
let!(:spam_post) { create_post(user: spammer) }
let!(:spam_post2) { create_post(user: spammer) }
@ -31,7 +30,7 @@ RSpec.describe "spam rules for users" do
expect(spam_post.reload).to_not be_hidden
end
context 'spam posts are flagged enough times, but not by enough users' do
context 'when spam posts are flagged enough times, but not by enough users' do
it 'should not hide the post' do
PostActionCreator.create(user1, spam_post2, :spam)
@ -41,7 +40,7 @@ RSpec.describe "spam rules for users" do
end
end
context 'one spam post is flagged enough times by enough users' do
context 'when one spam post is flagged enough times by enough users' do
fab!(:another_topic) { Fabricate(:topic) }
let!(:private_messages_count) { spammer.private_topics_count }
let!(:mod_pm_count) { moderator.private_topics_count }
@ -57,14 +56,14 @@ RSpec.describe "spam rules for users" do
expect(spammer.reload.private_topics_count).to eq(private_messages_count + 1)
end
context "a post is deleted" do
context "when a post is deleted" do
it 'should silence the spammer' do
spam_post.trash!(moderator); spammer.reload
expect(spammer.reload).to be_silenced
end
end
context "spammer becomes trust level 1" do
context "when spammer becomes trust level 1" do
it 'should silence the spammer' do
spammer.change_trust_level!(TrustLevel[1]); spammer.reload
expect(spammer.reload).to be_silenced
@ -72,7 +71,7 @@ RSpec.describe "spam rules for users" do
end
end
context 'hide_post_sensitivity' do
context 'with hide_post_sensitivity' do
it 'should silence the spammer' do
Reviewable.set_priorities(high: 2.0)
SiteSetting.hide_post_sensitivity = Reviewable.sensitivity[:low]
@ -84,10 +83,10 @@ RSpec.describe "spam rules for users" do
end
end
context "spammer has trust level basic" do
context "when spammer has trust level basic" do
let(:spammer) { Fabricate(:user, trust_level: TrustLevel[1]) }
context 'one spam post is flagged enough times by enough users' do
context 'when one spam post is flagged enough times by enough users' do
let!(:spam_post) { Fabricate(:post, user: spammer) }
let!(:private_messages_count) { spammer.private_topics_count }

View File

@ -4,10 +4,10 @@
RSpec.describe Topic do
let(:job_klass) { Jobs::CloseTopic }
context 'creating a topic without auto-close' do
context 'when creating a topic without auto-close' do
let(:topic) { Fabricate(:topic, category: category) }
context 'uncategorized' do
context 'when uncategorized' do
let(:category) { nil }
it 'should not schedule the topic to auto-close' do
@ -16,7 +16,7 @@ RSpec.describe Topic do
end
end
context 'category without default auto-close' do
context 'with category without default auto-close' do
let(:category) { Fabricate(:category, auto_close_hours: nil) }
it 'should not schedule the topic to auto-close' do
@ -25,12 +25,12 @@ RSpec.describe Topic do
end
end
context 'jobs may be queued' do
context 'when jobs may be queued' do
before do
freeze_time
end
context 'category has a default auto-close' do
context 'when category has a default auto-close' do
let(:category) { Fabricate(:category, auto_close_hours: 2.0) }
it 'should schedule the topic to auto-close' do
@ -42,7 +42,7 @@ RSpec.describe Topic do
expect(topic.public_topic_timer.execute_at).to be_within_one_second_of(2.hours.from_now)
end
context 'topic was created by staff user' do
context 'when topic was created by staff user' do
let(:admin) { Fabricate(:admin) }
let(:staff_topic) { Fabricate(:topic, user: admin, category: category) }
@ -56,7 +56,7 @@ RSpec.describe Topic do
expect(topic_status_update.user).to eq(Discourse.system_user)
end
context 'topic is closed manually' do
context 'when topic is closed manually' do
it 'should remove the schedule to auto-close the topic' do
topic_timer_id = staff_topic.public_topic_timer.id
@ -68,7 +68,7 @@ RSpec.describe Topic do
end
end
context 'topic was created by a non-staff user' do
context 'when topic was created by a non-staff user' do
let(:regular_user) { Fabricate(:user) }
let(:regular_user_topic) { Fabricate(:topic, user: regular_user, category: category) }

View File

@ -9,7 +9,7 @@ RSpec.describe "Topic Thumbnails" do
fab!(:topic) { Fabricate(:topic, image_upload_id: image.id) }
fab!(:user) { Fabricate(:user) }
context 'latest' do
describe 'latest' do
def get_topic
Discourse.redis.del(topic.thumbnail_job_redis_key(Topic.thumbnail_sizes))
Discourse.redis.del(topic.thumbnail_job_redis_key([]))

View File

@ -21,7 +21,7 @@ RSpec.describe WatchedWord do
WordWatcher.clear_cache!
end
context "block" do
context "with block" do
def should_block_post(manager)
expect {
result = manager.perform
@ -88,7 +88,7 @@ RSpec.describe WatchedWord do
end
end
context "require_approval" do
context "with require_approval" do
it "should queue the post for approval" do
manager = NewPostManager.new(tl2_user, raw: "My dog's name is #{require_approval_word.word}.", topic_id: topic.id)
result = manager.perform
@ -130,7 +130,7 @@ RSpec.describe WatchedWord do
end
end
context "flag" do
context "with flag" do
def should_flag_post(author, raw, topic)
post = Fabricate(:post, raw: raw, topic: topic, user: author)
expect {

View File

@ -113,7 +113,7 @@ RSpec.describe "fallbacks" do
end
end
context "in a multi-threaded environment" do
context "when in a multi-threaded environment" do
it "finds the fallback translation" do
I18n.backend.store_translations(:en, test: "en test")

View File

@ -1,10 +1,9 @@
# frozen_string_literal: true
RSpec.describe Jobs::AutoQueueHandler do
subject { Jobs::AutoQueueHandler.new.execute({}) }
context "old flagged post" do
describe "old flagged post" do
fab!(:spam_result) do
PostActionCreator.new(
Fabricate(:user),
@ -38,7 +37,7 @@ RSpec.describe Jobs::AutoQueueHandler do
end
end
context "reviewables" do
describe "reviewables" do
fab!(:new_post) { Fabricate(:reviewable_queued_post, created_at: 59.days.ago) }
fab!(:old_post) { Fabricate(:reviewable_queued_post, created_at: 61.days.ago) }
fab!(:new_user) { Fabricate(:reviewable, created_at: 10.days.ago) }
@ -62,5 +61,4 @@ RSpec.describe Jobs::AutoQueueHandler do
expect(old_user.reload.pending?).to eq(true)
end
end
end

View File

@ -106,7 +106,7 @@ RSpec.describe Jobs::BulkInvite do
expect(new_staged_user.user_fields[user_field.id.to_s]).to eq('value 3')
end
context 'invites are more than 200' do
context 'when there are more than 200 invites' do
let(:bulk_invites) { [] }
before do

View File

@ -14,19 +14,19 @@ RSpec.describe Jobs::CleanUpUnusedStagedUsers do
context "when staged user is old enough" do
before { staged_user.update!(created_at: 2.years.ago) }
context "regular staged user" do
context "with regular staged user" do
it "deletes the staged user" do
expect { described_class.new.execute({}) }.to change { User.count }.by(-1)
expect(User.exists?(staged_user.id)).to eq(false)
end
end
context "staged admin" do
context "with staged admin" do
before { staged_user.update!(admin: true) }
include_examples "does not delete"
end
context "staged moderator" do
context "with staged moderator" do
before { staged_user.update!(moderator: true) }
include_examples "does not delete"
end

View File

@ -3,8 +3,7 @@
RSpec.describe Jobs::EnqueueDigestEmails do
describe '#target_users' do
context 'disabled digests' do
context 'with disabled digests' do
before { SiteSetting.default_email_digest_frequency = 0 }
let!(:user_no_digests) { Fabricate(:active_user, last_emailed_at: 8.days.ago, last_seen_at: 10.days.ago) }
@ -13,8 +12,7 @@ RSpec.describe Jobs::EnqueueDigestEmails do
end
end
context 'unapproved users' do
context 'with unapproved users' do
before do
SiteSetting.must_approve_users = true
end
@ -38,7 +36,7 @@ RSpec.describe Jobs::EnqueueDigestEmails do
end
end
context 'staged users' do
context 'with staged users' do
let!(:staged_user) { Fabricate(:active_user, staged: true, last_emailed_at: 1.year.ago, last_seen_at: 1.year.ago) }
it "doesn't return staged users" do
@ -46,16 +44,15 @@ RSpec.describe Jobs::EnqueueDigestEmails do
end
end
context 'recently emailed' do
context 'when recently emailed' do
let!(:user_emailed_recently) { Fabricate(:active_user, last_emailed_at: 6.days.ago) }
it "doesn't return users who have been emailed recently" do
expect(Jobs::EnqueueDigestEmails.new.target_user_ids.include?(user_emailed_recently.id)).to eq(false)
end
end
context "inactive user" do
context "with inactive user" do
let!(:inactive_user) { Fabricate(:user, active: false) }
it "doesn't return users who have been emailed recently" do
@ -63,7 +60,7 @@ RSpec.describe Jobs::EnqueueDigestEmails do
end
end
context "suspended user" do
context "with suspended user" do
let!(:suspended_user) { Fabricate(:user, suspended_till: 1.week.from_now, suspended_at: 1.day.ago) }
it "doesn't return users who are suspended" do
@ -71,7 +68,7 @@ RSpec.describe Jobs::EnqueueDigestEmails do
end
end
context 'visited the site this week' do
context 'when visited the site this week' do
let(:user_visited_this_week) { Fabricate(:active_user, last_seen_at: 6.days.ago) }
it "doesn't return users who have been emailed recently" do
@ -80,7 +77,7 @@ RSpec.describe Jobs::EnqueueDigestEmails do
end
end
context 'visited the site a year ago' do
context 'when visited the site a year ago' do
let!(:user_visited_a_year_ago) { Fabricate(:active_user, last_seen_at: 370.days.ago) }
it "doesn't return the user who have not visited the site for more than 365 days" do
@ -88,7 +85,7 @@ RSpec.describe Jobs::EnqueueDigestEmails do
end
end
context 'regular users' do
context 'with regular users' do
let!(:user) { Fabricate(:active_user, last_seen_at: (SiteSetting.suppress_digest_email_after_days - 1).days.ago) }
it "returns the user" do
@ -96,7 +93,7 @@ RSpec.describe Jobs::EnqueueDigestEmails do
end
end
context 'too many bounces' do
context 'with too many bounces' do
let!(:bounce_user) { Fabricate(:active_user, last_seen_at: 6.month.ago) }
it "doesn't return users with too many bounces" do
@ -105,7 +102,7 @@ RSpec.describe Jobs::EnqueueDigestEmails do
end
end
context "no primary email" do
context "with no primary email" do
let!(:user) { Fabricate(:active_user, last_seen_at: 2.months.ago) }
it "doesn't return users with no primary emails" do
@ -116,7 +113,6 @@ RSpec.describe Jobs::EnqueueDigestEmails do
end
describe '#execute' do
let(:user) { Fabricate(:user) }
it "limits jobs enqueued per max_digests_enqueued_per_30_mins_per_site" do
@ -146,7 +142,7 @@ RSpec.describe Jobs::EnqueueDigestEmails do
end
end
context "digest emails are enabled" do
context "when digest emails are enabled" do
before do
Jobs::EnqueueDigestEmails.any_instance.expects(:target_user_ids).returns([user.id])
end
@ -160,7 +156,7 @@ RSpec.describe Jobs::EnqueueDigestEmails do
end
end
context "private email" do
context "with private email" do
before do
Jobs::EnqueueDigestEmails.any_instance.expects(:target_user_ids).never
SiteSetting.private_email = true
@ -173,7 +169,7 @@ RSpec.describe Jobs::EnqueueDigestEmails do
end
end
context "digest emails are disabled" do
context "when digest emails are disabled" do
before do
Jobs::EnqueueDigestEmails.any_instance.expects(:target_user_ids).never
SiteSetting.disable_digest_emails = true
@ -185,7 +181,5 @@ RSpec.describe Jobs::EnqueueDigestEmails do
end
end
end
end
end

View File

@ -1,7 +1,7 @@
# frozen_string_literal: true
RSpec.describe Jobs::EnsureS3UploadsExistence do
context "S3 inventory enabled" do
context "with S3 inventory enabled" do
before do
setup_s3
SiteSetting.enable_s3_inventory = true
@ -27,7 +27,7 @@ RSpec.describe Jobs::EnsureS3UploadsExistence do
end
end
context "S3 inventory disabled" do
context "with S3 inventory disabled" do
before { SiteSetting.enable_s3_inventory = false }
it "doesn't execute" do

View File

@ -109,7 +109,7 @@ RSpec.describe Jobs::ExportUserArchive do
end
end
context 'user_archive posts' do
describe 'user_archive posts' do
let(:component) { 'user_archive' }
let(:subsubcategory) { Fabricate(:category_with_definition, parent_category_id: subcategory.id) }
let(:subsubtopic) { Fabricate(:topic, category: subsubcategory) }
@ -181,7 +181,7 @@ RSpec.describe Jobs::ExportUserArchive do
end
end
context 'preferences' do
describe 'preferences' do
let(:component) { 'preferences' }
before do
@ -206,7 +206,7 @@ RSpec.describe Jobs::ExportUserArchive do
end
end
context 'auth tokens' do
describe 'auth tokens' do
let(:component) { 'auth_tokens' }
before do
@ -225,7 +225,7 @@ RSpec.describe Jobs::ExportUserArchive do
expect(data[0]['user_agent']).to eq('MyWebBrowser')
end
context 'auth token logs' do
context 'with auth token logs' do
let(:component) { 'auth_token_logs' }
it 'includes details such as the path' do
data, _csv_out = make_component_csv
@ -237,7 +237,7 @@ RSpec.describe Jobs::ExportUserArchive do
end
end
context 'badges' do
describe 'badges' do
let(:component) { 'badges' }
let(:badge1) { Fabricate(:badge) }
@ -264,10 +264,9 @@ RSpec.describe Jobs::ExportUserArchive do
expect(data[2]['granted_manually']).to eq('true')
expect(Post.find(data[3]['post_id'])).to_not be_nil
end
end
context 'bookmarks' do
describe 'bookmarks' do
let(:component) { 'bookmarks' }
let(:name) { 'Collect my thoughts on this' }
@ -321,7 +320,7 @@ RSpec.describe Jobs::ExportUserArchive do
end
end
context 'category_preferences' do
describe 'category_preferences' do
let(:component) { 'category_preferences' }
let(:subsubcategory) { Fabricate(:category_with_definition, parent_category_id: subcategory.id, name: "User Archive Subcategory") }
@ -394,7 +393,7 @@ RSpec.describe Jobs::ExportUserArchive do
end
end
context 'flags' do
describe 'flags' do
let(:component) { 'flags' }
let(:other_post) { Fabricate(:post, user: admin) }
let(:post3) { Fabricate(:post) }
@ -429,7 +428,7 @@ RSpec.describe Jobs::ExportUserArchive do
end
end
context 'likes' do
describe 'likes' do
let(:component) { 'likes' }
let(:other_post) { Fabricate(:post, user: admin) }
let(:post3) { Fabricate(:post) }
@ -452,7 +451,7 @@ RSpec.describe Jobs::ExportUserArchive do
end
end
context 'queued posts' do
describe 'queued posts' do
let(:component) { 'queued_posts' }
let(:reviewable_post) { Fabricate(:reviewable_queued_post, topic: topic, created_by: user) }
let(:reviewable_topic) { Fabricate(:reviewable_queued_post_topic, category: category, created_by: user) }
@ -478,7 +477,7 @@ RSpec.describe Jobs::ExportUserArchive do
end
end
context 'visits' do
describe 'visits' do
let(:component) { 'visits' }
it 'correctly exports the UserVisit table' do

View File

@ -33,7 +33,7 @@ RSpec.describe Jobs::FeatureTopicUsers do
end
end
context "participant count" do
context "with participant count" do
let!(:post) { create_post }
let(:topic) { post.topic }

View File

@ -1,7 +1,6 @@
# frozen_string_literal: true
RSpec.describe Jobs::GrantAnniversaryBadges do
let(:granter) { described_class.new }
it "doesn't award to a user who is less than a year old" do
@ -86,7 +85,7 @@ RSpec.describe Jobs::GrantAnniversaryBadges do
expect(badge.count).to eq(1)
end
context "repeated grants" do
context "with repeated grants" do
it "won't award twice in the same year" do
user = Fabricate(:user, created_at: 400.days.ago)
Fabricate(:post, user: user, created_at: 1.week.ago)
@ -132,5 +131,4 @@ RSpec.describe Jobs::GrantAnniversaryBadges do
expect(badge.count).to eq(2)
end
end
end

View File

@ -17,7 +17,7 @@ RSpec.describe Jobs::InvalidateInactiveAdmins do
fab!(:not_seen_admin) { Fabricate(:admin, last_seen_at: 370.days.ago) }
before { not_seen_admin.email_tokens.update_all(confirmed: true) }
context 'invalidate_inactive_admin_email_after_days = 365' do
context 'when invalidate_inactive_admin_email_after_days = 365' do
before do
SiteSetting.invalidate_inactive_admin_email_after_days = 365
end
@ -65,7 +65,7 @@ RSpec.describe Jobs::InvalidateInactiveAdmins do
end
end
context 'invalidate_inactive_admin_email_after_days = 0 to disable this feature' do
context 'when invalidate_inactive_admin_email_after_days = 0 to disable this feature' do
before do
SiteSetting.invalidate_inactive_admin_email_after_days = 0
end

View File

@ -110,7 +110,7 @@ RSpec.describe Jobs do
Jobs.enqueue(:process_post, post_id: 1)
end
context 'and current_site_id option is given and does not match the current connection' do
context 'when current_site_id option is given and does not match the current connection' do
before do
Sidekiq::Client.stubs(:enqueue)
Jobs::ProcessPost.any_instance.stubs(:execute).returns(true)

View File

@ -1,7 +1,6 @@
# frozen_string_literal: true
RSpec.describe Jobs::NotifyMailingListSubscribers do
fab!(:mailing_list_user) { Fabricate(:user) }
before { mailing_list_user.user_option.update(mailing_list_mode: true, mailing_list_mode_frequency: 1) }
@ -88,68 +87,67 @@ RSpec.describe Jobs::NotifyMailingListSubscribers do
end
context "with a valid post from another user" do
context "to an inactive user" do
context "when to an inactive user" do
before { mailing_list_user.update(active: false) }
include_examples "no emails"
end
context "to a silenced user" do
context "when to a silenced user" do
before { mailing_list_user.update(silenced_till: 1.year.from_now) }
include_examples "no emails"
end
context "to a suspended user" do
context "when to a suspended user" do
before { mailing_list_user.update(suspended_till: 1.day.from_now) }
include_examples "no emails"
end
context "to an anonymous user" do
context "when to an anonymous user" do
fab!(:mailing_list_user) { Fabricate(:anonymous) }
include_examples "no emails"
end
context "to an user who has disabled mailing list mode" do
context "when to an user who has disabled mailing list mode" do
before { mailing_list_user.user_option.update(mailing_list_mode: false) }
include_examples "no emails"
end
context "to an user who has frequency set to 'always'" do
context "when to an user who has frequency set to 'always'" do
before { mailing_list_user.user_option.update(mailing_list_mode_frequency: 1) }
include_examples "one email"
end
context "to an user who has frequency set to 'no echo'" do
context "when to an user who has frequency set to 'no echo'" do
before { mailing_list_user.user_option.update(mailing_list_mode_frequency: 2) }
include_examples "one email"
end
context "from a muted user" do
context "when from a muted user" do
before { MutedUser.create(user: mailing_list_user, muted_user: user) }
include_examples "no emails"
end
context "from an ignored user" do
context "when from an ignored user" do
before { Fabricate(:ignored_user, user: mailing_list_user, ignored_user: user) }
include_examples "no emails"
end
context "from a muted topic" do
context "when from a muted topic" do
before { TopicUser.create(user: mailing_list_user, topic: post.topic, notification_level: TopicUser.notification_levels[:muted]) }
include_examples "no emails"
end
context "from a muted category" do
context "when from a muted category" do
before { CategoryUser.create(user: mailing_list_user, category: post.topic.category, notification_level: CategoryUser.notification_levels[:muted]) }
include_examples "no emails"
end
context "mute all categories by default setting" do
context "with mute all categories by default setting" do
before { SiteSetting.mute_all_categories_by_default = true }
include_examples "no emails"
end
context "mute all categories by default setting but user is watching category" do
context "with mute all categories by default setting but user is watching category" do
before do
SiteSetting.mute_all_categories_by_default = true
CategoryUser.create(user: mailing_list_user, category: post.topic.category, notification_level: CategoryUser.notification_levels[:watching])
@ -157,7 +155,7 @@ RSpec.describe Jobs::NotifyMailingListSubscribers do
include_examples "one email"
end
context "mute all categories by default setting but user is watching tag" do
context "with mute all categories by default setting but user is watching tag" do
before do
SiteSetting.mute_all_categories_by_default = true
TagUser.create(user: mailing_list_user, tag: tag, notification_level: TagUser.notification_levels[:watching])
@ -165,7 +163,7 @@ RSpec.describe Jobs::NotifyMailingListSubscribers do
include_examples "one email"
end
context "mute all categories by default setting but user is watching topic" do
context "with mute all categories by default setting but user is watching topic" do
before do
SiteSetting.mute_all_categories_by_default = true
TopicUser.create(user: mailing_list_user, topic: post.topic, notification_level: TopicUser.notification_levels[:watching])
@ -173,12 +171,12 @@ RSpec.describe Jobs::NotifyMailingListSubscribers do
include_examples "one email"
end
context "from a muted tag" do
context "when from a muted tag" do
before { TagUser.create(user: mailing_list_user, tag: tag, notification_level: TagUser.notification_levels[:muted]) }
include_examples "no emails"
end
context "max emails per day was reached" do
context "when max emails per day was reached" do
before { SiteSetting.max_emails_per_day_per_user = 2 }
it "doesn't send any emails" do
@ -224,8 +222,7 @@ RSpec.describe Jobs::NotifyMailingListSubscribers do
end
end
context "bounce score was reached" do
context "when bounce score was reached" do
it "doesn't send any emails" do
mailing_list_user.user_stat.update(bounce_score: SiteSetting.bounce_score_threshold + 1)
@ -240,30 +237,26 @@ RSpec.describe Jobs::NotifyMailingListSubscribers do
reason_type: SkippedEmailLog.reason_types[:exceeded_bounces_limit]
)).to eq(true)
end
end
end
context "with a valid post from same user" do
fab!(:post) { Fabricate(:post, user: mailing_list_user) }
context "to an user who has frequency set to 'daily'" do
context "when to an user who has frequency set to 'daily'" do
before { mailing_list_user.user_option.update(mailing_list_mode_frequency: 0) }
include_examples "no emails"
end
context "to an user who has frequency set to 'always'" do
context "when to an user who has frequency set to 'always'" do
before { mailing_list_user.user_option.update(mailing_list_mode_frequency: 1) }
include_examples "one email"
end
context "to an user who has frequency set to 'no echo'" do
context "when to an user who has frequency set to 'no echo'" do
before { mailing_list_user.user_option.update(mailing_list_mode_frequency: 2) }
include_examples "no emails"
end
end
end
end

View File

@ -1,7 +1,6 @@
# frozen_string_literal: true
RSpec.describe ::Jobs::NotifyTagChange do
fab!(:user) { Fabricate(:user) }
fab!(:regular_user) { Fabricate(:trust_level_4) }
fab!(:post) { Fabricate(:post, user: regular_user) }
@ -50,7 +49,7 @@ RSpec.describe ::Jobs::NotifyTagChange do
expect { described_class.new.execute(post_id: post.id, notified_user_ids: [regular_user.id]) }.not_to change { Notification.count }
end
context 'hidden tag' do
describe 'hidden tag' do
let!(:hidden_group) { Fabricate(:group, name: 'hidden_group') }
let!(:hidden_tag_group) { Fabricate(:tag_group, name: 'hidden', permissions: [[hidden_group.id, :full]]) }
let!(:topic_user) { Fabricate(:topic_user, user: user, topic: post.topic, notification_level: TopicUser.notification_levels[:watching]) }

View File

@ -3,7 +3,7 @@
RSpec.describe Jobs::PendingQueuedPostsReminder do
let(:job) { described_class.new }
context "notify_about_queued_posts_after is 0" do
context "when notify_about_queued_posts_after is 0" do
before { SiteSetting.notify_about_queued_posts_after = 0 }
it "never emails" do
@ -14,7 +14,7 @@ RSpec.describe Jobs::PendingQueuedPostsReminder do
end
end
context "notify_about_queued_posts_after accepts a float" do
context "when notify_about_queued_posts_after accepts a float" do
before do
SiteSetting.notify_about_queued_posts_after = 0.25
job.last_notified_id = nil
@ -32,13 +32,12 @@ RSpec.describe Jobs::PendingQueuedPostsReminder do
end
end
context "notify_about_queued_posts_after is 24" do
context "when notify_about_queued_posts_after is 24" do
before do
SiteSetting.notify_about_queued_posts_after = 24
end
context "when we haven't been notified in a while" do
before do
job.last_notified_id = nil
end

View File

@ -15,7 +15,7 @@ RSpec.describe Jobs::PendingReviewablesReminder do
expect(execute.sent_reminder).to eq(false)
end
context "notify_about_flags_after is 0" do
context "when notify_about_flags_after is 0" do
before { SiteSetting.notify_about_flags_after = 0 }
it "never notifies" do
@ -24,7 +24,7 @@ RSpec.describe Jobs::PendingReviewablesReminder do
end
end
context "notify_about_flags_after accepts a float" do
context "when notify_about_flags_after accepts a float" do
before { SiteSetting.notify_about_flags_after = 0.25 }
it "doesn't send message when flags are less than 15 minutes old" do
@ -38,7 +38,7 @@ RSpec.describe Jobs::PendingReviewablesReminder do
end
end
context "notify_about_flags_after is 48" do
context "when notify_about_flags_after is 48" do
before do
SiteSetting.notify_about_flags_after = 48
described_class.clear_key
@ -68,7 +68,7 @@ RSpec.describe Jobs::PendingReviewablesReminder do
expect(execute.sent_reminder).to eq(true)
end
context "reviewable_default_visibility" do
context "with reviewable_default_visibility" do
before do
create_flag(49.hours.ago)
create_flag(51.hours.ago)

View File

@ -1,8 +1,7 @@
# frozen_string_literal: true
RSpec.describe Jobs::PendingUsersReminder do
context 'must_approve_users is true' do
context 'when must_approve_users is true' do
before do
SiteSetting.must_approve_users = true
Jobs::PendingUsersReminder.any_instance.stubs(:previous_newest_username).returns(nil)
@ -13,7 +12,7 @@ RSpec.describe Jobs::PendingUsersReminder do
Jobs::PendingUsersReminder.new.execute({})
end
context "there are pending users" do
context "when there are pending users" do
before do
Fabricate(:moderator, approved: true, approved_by_id: -1, approved_at: 1.week.ago)
Group.refresh_automatic_group!(:moderators)
@ -49,7 +48,7 @@ RSpec.describe Jobs::PendingUsersReminder do
end
end
context 'must_approve_users is false' do
context 'when must_approve_users is false' do
before do
SiteSetting.must_approve_users = false
end

View File

@ -1,11 +1,9 @@
# frozen_string_literal: true
RSpec.describe Jobs::PollMailbox do
let(:poller) { Jobs::PollMailbox.new }
describe ".execute" do
it "does no polling if pop3_polling_enabled is false" do
SiteSetting.expects(:pop3_polling_enabled).returns(false)
poller.expects(:poll_pop3).never
@ -17,7 +15,6 @@ RSpec.describe Jobs::PollMailbox do
poller.expects(:poll_pop3).once
poller.execute({})
end
end
describe ".poll_pop3" do
@ -39,7 +36,7 @@ RSpec.describe Jobs::PollMailbox do
EMAIL
end
context "pop errors" do
context "with pop errors" do
before do
Discourse.expects(:handle_job_exception).at_least_once
end
@ -114,7 +111,7 @@ RSpec.describe Jobs::PollMailbox do
poller.poll_pop3
end
context "has emails" do
context "when has emails" do
let(:oldmail) { file_from_fixtures("old_destination.eml", "emails").read }
before do
@ -173,7 +170,5 @@ RSpec.describe Jobs::PollMailbox do
I18n.t("emails.incoming.errors.bounced_email_error")
)
end
end
end

View File

@ -253,7 +253,7 @@ RSpec.describe Jobs::GroupSmtpEmail do
end
end
context "group is deleted" do
context "when group is deleted" do
it "returns without sending email" do
group.destroy
subject.execute(args)

View File

@ -4,7 +4,7 @@ RSpec.describe Jobs::RemoveBanner do
fab!(:topic) { Fabricate(:topic) }
fab!(:user) { topic.user }
context 'topic is not bannered until' do
context 'when topic is not bannered until' do
it 'doesnt enqueue a future job to remove it' do
expect do
topic.make_banner!(user)
@ -12,8 +12,8 @@ RSpec.describe Jobs::RemoveBanner do
end
end
context 'topic is bannered until' do
context 'bannered_until is a valid date' do
context 'when topic is bannered until' do
context 'when bannered_until is a valid date' do
it 'enqueues a future job to remove it' do
bannered_until = 5.days.from_now
@ -36,7 +36,7 @@ RSpec.describe Jobs::RemoveBanner do
end
end
context 'bannered_until is an invalid date' do
context 'when bannered_until is an invalid date' do
it 'doesnt enqueue a future job to remove it' do
expect do
expect do

View File

@ -17,7 +17,7 @@ RSpec.describe Jobs::SyncAclsForUploads do
run_job
end
context "external storage enabled" do
context "with external storage enabled" do
before do
setup_s3
stub_s3_store

View File

@ -1,7 +1,6 @@
# frozen_string_literal: true
RSpec.describe Jobs::Tl3Promotions do
def create_qualifying_stats(user)
user.create_user_stat if user.user_stat.nil?
user.user_stat.update!(
@ -44,7 +43,7 @@ RSpec.describe Jobs::Tl3Promotions do
run_job
end
context "tl3 user who doesn't qualify for tl3 anymore" do
context "with tl3 user who doesn't qualify for tl3 anymore" do
def create_leader_user
user = Fabricate(:user, trust_level: TrustLevel[2])
TrustLevel3Requirements.any_instance.stubs(:requirements_met?).returns(true)

View File

@ -1,7 +1,6 @@
# frozen_string_literal: true
RSpec.describe Jobs::UserEmail do
before do
SiteSetting.email_time_window_mins = 10
end
@ -23,7 +22,7 @@ RSpec.describe Jobs::UserEmail do
expect { Jobs::UserEmail.new.execute(type: :no_method, user_id: user.id) }.to raise_error(Discourse::InvalidParameters)
end
context 'digest can be generated' do
context 'when digest can be generated' do
fab!(:user) { Fabricate(:user, last_seen_at: 8.days.ago, last_emailed_at: 8.days.ago) }
fab!(:popular_topic) { Fabricate(:topic, user: Fabricate(:admin), created_at: 1.hour.ago) }
@ -38,7 +37,7 @@ RSpec.describe Jobs::UserEmail do
expect(ActionMailer::Base.deliveries).to eq([])
end
context 'not emailed recently' do
context 'when not emailed recently' do
before do
freeze_time
user.update!(last_emailed_at: 8.days.ago)
@ -51,7 +50,7 @@ RSpec.describe Jobs::UserEmail do
end
end
context 'recently emailed' do
context 'when recently emailed' do
before do
freeze_time
user.update!(last_emailed_at: 2.hours.ago)
@ -66,8 +65,7 @@ RSpec.describe Jobs::UserEmail do
end
end
context "bounce score" do
context "with bounce score" do
it "always sends critical emails when bounce score threshold has been reached" do
email_token = Fabricate(:email_token)
user.user_stat.update(bounce_score: SiteSetting.bounce_score_threshold + 1)
@ -81,10 +79,9 @@ RSpec.describe Jobs::UserEmail do
user.email
)
end
end
context 'to_address' do
context 'with to_address' do
it 'overwrites a to_address when present' do
Jobs::UserEmail.new.execute(type: :confirm_new_email, user_id: user.id, to_address: 'jake@adventuretime.ooo')
@ -94,7 +91,7 @@ RSpec.describe Jobs::UserEmail do
end
end
context "disable_emails setting" do
context "with disable_emails setting" do
it "sends when no" do
SiteSetting.disable_emails = 'no'
Jobs::UserEmail.new.execute(type: :confirm_new_email, user_id: user.id)
@ -112,7 +109,7 @@ RSpec.describe Jobs::UserEmail do
end
end
context "recently seen" do
context "when recently seen" do
fab!(:post) { Fabricate(:post, user: user) }
fab!(:notification) { Fabricate(
:notification,
@ -246,7 +243,7 @@ RSpec.describe Jobs::UserEmail do
end
end
context "email_log" do
context "with email_log" do
fab!(:post) { Fabricate(:post, created_at: 30.seconds.ago) }
before do
@ -317,8 +314,7 @@ RSpec.describe Jobs::UserEmail do
end
end
context 'args' do
context 'with args' do
it 'passes a token as an argument when a token is present' do
Jobs::UserEmail.new.execute(type: :forgot_password, user_id: user.id, email_token: 'asdfasdf')
@ -328,7 +324,7 @@ RSpec.describe Jobs::UserEmail do
expect(mail.body).to include("asdfasdf")
end
context "confirm_new_email" do
context "with confirm_new_email" do
let(:email_token) { Fabricate(:email_token, user: user) }
before do
EmailChangeRequest.create!(
@ -368,7 +364,7 @@ RSpec.describe Jobs::UserEmail do
end
end
context "post" do
context "with post" do
fab!(:post) { Fabricate(:post, user: user) }
it "doesn't send the email if you've seen the post" do
@ -392,7 +388,7 @@ RSpec.describe Jobs::UserEmail do
expect(ActionMailer::Base.deliveries).to eq([])
end
context 'user is suspended' do
context 'when user is suspended' do
it "doesn't send email for a pm from a regular user" do
Jobs::UserEmail.new.execute(type: :user_private_message, user_id: suspended.id, post_id: post.id)
@ -443,7 +439,7 @@ RSpec.describe Jobs::UserEmail do
end
end
context 'user is anonymous' do
context 'when user is anonymous' do
before { SiteSetting.allow_anonymous_posting = true }
it "doesn't send email for a pm from a regular user" do
@ -462,7 +458,7 @@ RSpec.describe Jobs::UserEmail do
end
end
context 'notification' do
context 'with notification' do
fab!(:post) { Fabricate(:post, user: user) }
fab!(:notification) {
Fabricate(:notification,
@ -541,7 +537,7 @@ RSpec.describe Jobs::UserEmail do
expect(ActionMailer::Base.deliveries.first.to).to contain_exactly(user.email)
end
context "recently seen" do
context "when recently seen" do
it "doesn't send an email to a user that's been recently seen" do
user.update!(last_seen_at: 9.minutes.ago)
@ -572,7 +568,7 @@ RSpec.describe Jobs::UserEmail do
end
end
context 'max_emails_per_day_per_user limit is reached' do
context 'when max_emails_per_day_per_user limit is reached' do
before do
SiteSetting.max_emails_per_day_per_user = 2
2.times { Fabricate(:email_log, user: user, email_type: 'blah', to_address: user.email) }
@ -718,7 +714,7 @@ RSpec.describe Jobs::UserEmail do
expect(ActionMailer::Base.deliveries).to eq([])
end
context 'user is suspended' do
context 'when user is suspended' do
it "doesn't send email for a pm from a regular user" do
msg, err = Jobs::UserEmail.new.message_for_email(
suspended,
@ -731,7 +727,7 @@ RSpec.describe Jobs::UserEmail do
expect(err).not_to eq(nil)
end
context 'pm from staff' do
context 'with pm from staff' do
before do
@pm_from_staff = Fabricate(:post, user: Fabricate(:moderator))
@pm_from_staff.topic.topic_allowed_users.create!(user_id: suspended.id)
@ -768,7 +764,7 @@ RSpec.describe Jobs::UserEmail do
end
end
context 'user is anonymous' do
context 'when user is anonymous' do
before { SiteSetting.allow_anonymous_posting = true }
it "doesn't send email for a pm from a regular user" do
@ -802,6 +798,5 @@ RSpec.describe Jobs::UserEmail do
end
end
end
end
end

View File

@ -100,7 +100,7 @@ RSpec.describe AdminUserIndexQuery do
expect(query.find_users).not_to include(inactive_user)
end
context 'and a suspended pending user' do
context 'with a suspended pending user' do
fab!(:suspended_user) { Fabricate(:user, approved: false, suspended_at: 1.hour.ago, suspended_till: 20.years.from_now) }
it "doesn't return the suspended user" do
query = ::AdminUserIndexQuery.new(query: 'pending')
@ -182,7 +182,7 @@ RSpec.describe AdminUserIndexQuery do
describe "filtering" do
context "exact email bypass" do
context "with exact email bypass" do
it "can correctly bypass expensive ilike query" do
user = Fabricate(:user, email: 'sam@Sam.com')
@ -208,7 +208,7 @@ RSpec.describe AdminUserIndexQuery do
end
end
context "by email fragment" do
context "with email fragment" do
before(:each) { Fabricate(:user, email: "test1@example.com") }
@ -224,7 +224,7 @@ RSpec.describe AdminUserIndexQuery do
end
context "by username fragment" do
context "with username fragment" do
before(:each) { Fabricate(:user, username: "test_user_1") }
@ -239,7 +239,7 @@ RSpec.describe AdminUserIndexQuery do
end
end
context "by ip address fragment" do
context "with ip address fragment" do
fab!(:user) { Fabricate(:user, ip_address: "117.207.94.9") }

View File

@ -4,9 +4,7 @@
require 'archetype'
RSpec.describe Archetype do
context 'default archetype' do
describe 'default archetype' do
it 'has an Archetype by default' do
expect(Archetype.list).to be_present
end
@ -15,8 +13,7 @@ RSpec.describe Archetype do
expect(Archetype.list.first.id).to eq(Archetype.default)
end
context 'duplicate' do
context 'with duplicate' do
before do
@old_size = Archetype.list.size
Archetype.register(Archetype.default)
@ -25,20 +22,15 @@ RSpec.describe Archetype do
it 'does not add the same archetype twice' do
expect(Archetype.list.size).to eq(@old_size)
end
end
end
context 'register an archetype' do
describe 'register an archetype' do
it 'has one more element' do
@list = Archetype.list.dup
Archetype.register('glados')
expect(Archetype.list.size).to eq(@list.size + 1)
expect(Archetype.list.find { |a| a.id == 'glados' }).to be_present
end
end
end

View File

@ -50,7 +50,7 @@ RSpec.describe Auth::DefaultCurrentUserProvider do
expect(provider.current_user).to eq(nil)
end
context "server header api" do
describe "server header api" do
it "raises for a revoked key" do
api_key = ApiKey.create!
params = { "HTTP_API_USERNAME" => user.username.downcase, "HTTP_API_KEY" => api_key.key }
@ -214,7 +214,7 @@ RSpec.describe Auth::DefaultCurrentUserProvider do
end
end
context "rate limiting" do
context "with rate limiting" do
before do
RateLimiter.enable
end
@ -435,7 +435,7 @@ RSpec.describe Auth::DefaultCurrentUserProvider do
end
context "events" do
describe "events" do
before do
@refreshes = 0
@ -472,8 +472,7 @@ RSpec.describe Auth::DefaultCurrentUserProvider do
end
end
context "rate limiting" do
describe "rate limiting" do
before do
RateLimiter.enable
end
@ -622,7 +621,7 @@ RSpec.describe Auth::DefaultCurrentUserProvider do
expect(user.staged).to eq(false)
end
context "user api" do
describe "user api" do
fab! :user do
Fabricate(:user)
end
@ -705,8 +704,7 @@ RSpec.describe Auth::DefaultCurrentUserProvider do
end
end
context "rate limiting" do
context "with rate limiting" do
before do
RateLimiter.enable
end

View File

@ -29,7 +29,7 @@ RSpec.describe Auth::DiscordAuthenticator do
let(:authenticator) { described_class.new }
context 'after_authenticate' do
describe 'after_authenticate' do
it 'works normally' do
result = authenticator.after_authenticate(hash)
expect(result.user).to eq(nil)

View File

@ -19,7 +19,7 @@ RSpec.describe Auth::FacebookAuthenticator do
let(:authenticator) { Auth::FacebookAuthenticator.new }
context 'after_authenticate' do
describe 'after_authenticate' do
it 'can authenticate and create a user record for already existing users' do
user = Fabricate(:user)
result = authenticator.after_authenticate(hash.deep_merge(info: { email: user.email }))
@ -46,7 +46,7 @@ RSpec.describe Auth::FacebookAuthenticator do
end
end
context 'description_for_user' do
describe 'description_for_user' do
fab!(:user) { Fabricate(:user) }
it 'returns empty string if no entry for user' do
@ -59,7 +59,7 @@ RSpec.describe Auth::FacebookAuthenticator do
end
end
context 'revoke' do
describe 'revoke' do
fab!(:user) { Fabricate(:user) }
let(:authenticator) { Auth::FacebookAuthenticator.new }
@ -82,5 +82,4 @@ RSpec.describe Auth::FacebookAuthenticator do
end
end
end
end

View File

@ -24,7 +24,7 @@ RSpec.describe Auth::GithubAuthenticator do
let(:authenticator) { described_class.new }
fab!(:user) { Fabricate(:user) }
context 'after_authenticate' do
describe 'after_authenticate' do
let(:data) { auth_token_for(user) }
it 'can authenticate and create a user record for already existing users' do
@ -247,10 +247,9 @@ RSpec.describe Auth::GithubAuthenticator do
expect(UserAssociatedAccount.exists?(user_id: user1.id)).to eq(false)
expect(UserAssociatedAccount.exists?(user_id: user2.id)).to eq(true)
end
end
context 'revoke' do
describe 'revoke' do
fab!(:user) { Fabricate(:user) }
let(:authenticator) { Auth::GithubAuthenticator.new }
@ -258,13 +257,12 @@ RSpec.describe Auth::GithubAuthenticator do
expect { authenticator.revoke(user) }.to raise_error(Discourse::NotFound)
end
it 'revokes correctly' do
UserAssociatedAccount.create!(provider_name: "github", user_id: user.id, provider_uid: 100, info: { nickname: "boris" })
expect(authenticator.can_revoke?).to eq(true)
expect(authenticator.revoke(user)).to eq(true)
expect(authenticator.description_for_user(user)).to eq("")
end
it 'revokes correctly' do
UserAssociatedAccount.create!(provider_name: "github", user_id: user.id, provider_uid: 100, info: { nickname: "boris" })
expect(authenticator.can_revoke?).to eq(true)
expect(authenticator.revoke(user)).to eq(true)
expect(authenticator.description_for_user(user)).to eq("")
end
end
describe 'avatar retrieval' do

View File

@ -29,7 +29,7 @@ RSpec.describe Auth::GoogleOAuth2Authenticator do
expect(result.user).to eq(nil)
end
context 'after_authenticate' do
describe 'after_authenticate' do
it 'can authenticate and create a user record for already existing users' do
authenticator = Auth::GoogleOAuth2Authenticator.new
user = Fabricate(:user)
@ -111,7 +111,7 @@ RSpec.describe Auth::GoogleOAuth2Authenticator do
expect(result.name).to eq("Jane Doe")
end
context "provides groups" do
describe "provides groups" do
before do
SiteSetting.google_oauth2_hd = "domain.com"
group1 = OmniAuth::AuthHash.new(id: "12345", name: "group1")
@ -137,7 +137,7 @@ RSpec.describe Auth::GoogleOAuth2Authenticator do
)
end
context "enabled" do
context "when enabled" do
before do
SiteSetting.google_oauth2_hd_groups = true
end
@ -154,7 +154,7 @@ RSpec.describe Auth::GoogleOAuth2Authenticator do
end
end
context "disabled" do
context "when disabled" do
before do
SiteSetting.google_oauth2_hd_groups = false
end
@ -167,7 +167,7 @@ RSpec.describe Auth::GoogleOAuth2Authenticator do
end
end
context 'revoke' do
describe 'revoke' do
fab!(:user) { Fabricate(:user) }
let(:authenticator) { Auth::GoogleOAuth2Authenticator.new }
@ -175,12 +175,11 @@ RSpec.describe Auth::GoogleOAuth2Authenticator do
expect { authenticator.revoke(user) }.to raise_error(Discourse::NotFound)
end
it 'revokes correctly' do
UserAssociatedAccount.create!(provider_name: "google_oauth2", user_id: user.id, provider_uid: 12345)
expect(authenticator.can_revoke?).to eq(true)
expect(authenticator.revoke(user)).to eq(true)
expect(authenticator.description_for_user(user)).to eq("")
end
it 'revokes correctly' do
UserAssociatedAccount.create!(provider_name: "google_oauth2", user_id: user.id, provider_uid: 12345)
expect(authenticator.can_revoke?).to eq(true)
expect(authenticator.revoke(user)).to eq(true)
expect(authenticator.description_for_user(user)).to eq("")
end
end
end

View File

@ -85,12 +85,12 @@ RSpec.describe Auth::OmniAuthStrategies::DiscourseGoogleOauth2 do
OmniAuth.config.test_mode = false
end
context 'request_groups is true' do
context 'when request_groups is true' do
before do
@options[:request_groups] = true
end
context 'groups request successful' do
context 'when groups request successful' do
before do
@strategy = build_strategy(successful_groups_token)
end
@ -100,7 +100,7 @@ RSpec.describe Auth::OmniAuthStrategies::DiscourseGoogleOauth2 do
end
end
context 'groups request unsuccessful' do
context 'when groups request unsuccessful' do
before do
@strategy = build_strategy(unsuccessful_groups_token)
end
@ -111,7 +111,7 @@ RSpec.describe Auth::OmniAuthStrategies::DiscourseGoogleOauth2 do
end
end
context 'request_groups is not true' do
context 'when request_groups is not true' do
before do
@options[:request_groups] = false
@strategy = build_strategy(successful_groups_token)

View File

@ -1,7 +1,6 @@
# frozen_string_literal: true
RSpec.describe Auth::TwitterAuthenticator do
it "takes over account if email is supplied" do
auth = Auth::TwitterAuthenticator.new
@ -51,7 +50,7 @@ RSpec.describe Auth::TwitterAuthenticator do
expect(UserAssociatedAccount.exists?(provider_name: "twitter", user_id: user2.id)).to eq(true)
end
context 'revoke' do
describe 'revoke' do
fab!(:user) { Fabricate(:user) }
let(:authenticator) { Auth::TwitterAuthenticator.new }
@ -65,7 +64,5 @@ RSpec.describe Auth::TwitterAuthenticator do
expect(authenticator.revoke(user)).to eq(true)
expect(authenticator.description_for_user(user)).to eq("")
end
end
end

View File

@ -3,7 +3,7 @@
require_relative "shared_context_for_backup_restore"
RSpec.describe BackupRestore::BackupFileHandler, type: :multisite do
include_context "shared stuff"
include_context "with shared stuff"
it "works with old backup file format" do
test_multisite_connection("second") do

View File

@ -3,7 +3,7 @@
require_relative 'shared_context_for_backup_restore'
RSpec.describe BackupRestore::BackupFileHandler do
include_context "shared stuff"
include_context "with shared stuff"
it "works with current backup file format" do
expect_decompress_and_clean_up_to_work(

View File

@ -3,14 +3,14 @@
require_relative "shared_context_for_backup_restore"
RSpec.describe BackupRestore::DatabaseRestorer, type: :multisite do
include_context "shared stuff"
include_context "with shared stuff"
let(:current_db) { RailsMultisite::ConnectionManagement.current_db }
subject { BackupRestore::DatabaseRestorer.new(logger, current_db) }
describe "#restore" do
context "database connection" do
context "with database connection" do
it "reconnects to the correct database" do
RailsMultisite::ConnectionManagement.establish_connection(db: "second")
execute_stubbed_restore

View File

@ -3,7 +3,7 @@
require_relative 'shared_context_for_backup_restore'
RSpec.describe BackupRestore::DatabaseRestorer do
include_context "shared stuff"
include_context "with shared stuff"
let(:current_db) { RailsMultisite::ConnectionManagement.current_db }
@ -79,7 +79,7 @@ RSpec.describe BackupRestore::DatabaseRestorer do
end
end
context "rewrites database dump" do
describe "rewrites database dump" do
let(:logger) do
Class.new do
attr_reader :log_messages
@ -124,7 +124,7 @@ RSpec.describe BackupRestore::DatabaseRestorer do
end
end
context "database connection" do
describe "database connection" do
it 'it is not erroring for non-multisite' do
expect { execute_stubbed_restore }.not_to raise_error
end
@ -144,7 +144,7 @@ RSpec.describe BackupRestore::DatabaseRestorer do
end
end
context "readonly functions" do
describe "readonly functions" do
before do
BackupRestore::DatabaseRestorer.stubs(:core_migration_files).returns(
Dir[Rails.root.join("spec/fixtures/db/post_migrate/drop_column/**/*.rb")]

View File

@ -3,7 +3,7 @@
require_relative 'shared_context_for_backup_restore'
RSpec.describe BackupRestore::MetaDataHandler do
include_context "shared stuff"
include_context "with shared stuff"
let!(:backup_filename) { 'discourse-2019-11-18-143242-v20191108000414.tar.gz' }
@ -22,7 +22,7 @@ RSpec.describe BackupRestore::MetaDataHandler do
BackupRestore::MetaDataHandler.new(logger, filename, tmp_directory).validate
end
context "metadata file" do
describe "metadata file" do
it "extracts metadata from file when metadata file exists" do
metadata = '{"source":"discourse","version":20160329101122}'
@ -67,7 +67,7 @@ RSpec.describe BackupRestore::MetaDataHandler do
end
end
context "filename" do
describe "filename" do
it "extracts metadata from filename when metadata file does not exist" do
with_metadata_file(nil) do |dir|
expect(validate_metadata(backup_filename, dir))

View File

@ -77,7 +77,7 @@ RSpec.describe BackupRestore::S3BackupStore do
it_behaves_like "backup store"
it_behaves_like "remote backup store"
context "S3 specific behavior" do
describe "S3 specific behavior" do
before { create_backups }
after { remove_backups }

View File

@ -1,6 +1,6 @@
# frozen_string_literal: true
RSpec.shared_context "shared stuff" do
RSpec.shared_context "with shared stuff" do
let!(:logger) do
Class.new do
def log(message, ex = nil); end

View File

@ -1,7 +1,7 @@
# frozen_string_literal: true
# rubocop:disable Discourse/OnlyTopLevelMultisiteSpecs
RSpec.shared_context "backups" do
RSpec.shared_context "with backups" do
before { create_backups }
after { remove_backups }
@ -46,7 +46,7 @@ RSpec.shared_examples "backup store" do
end
context "with backup files" do
include_context "backups"
include_context "with backups"
describe "#files" do
it "sorts files by last modified date in descending order" do
@ -214,7 +214,7 @@ RSpec.shared_examples "remote backup store" do
end
context "with backups" do
include_context "backups"
include_context "with backups"
describe "#upload_file" do
def upload_file

View File

@ -3,7 +3,7 @@
require_relative "shared_context_for_backup_restore"
RSpec.describe BackupRestore::SystemInterface, type: :multisite do
include_context "shared stuff"
include_context "with shared stuff"
subject { BackupRestore::SystemInterface.new(logger) }

View File

@ -3,11 +3,11 @@
require_relative 'shared_context_for_backup_restore'
RSpec.describe BackupRestore::SystemInterface do
include_context "shared stuff"
include_context "with shared stuff"
subject { BackupRestore::SystemInterface.new(logger) }
context "readonly mode" do
describe "readonly mode" do
after do
Discourse::READONLY_KEYS.each { |key| Discourse.redis.del(key) }
end
@ -171,7 +171,7 @@ RSpec.describe BackupRestore::SystemInterface do
end
describe "#flush_redis" do
context "Sidekiq" do
context "with Sidekiq" do
after { Sidekiq.unpause! }
it "doesn't unpause Sidekiq" do

View File

@ -4,7 +4,7 @@
require_relative 'shared_context_for_backup_restore'
RSpec.describe BackupRestore::UploadsRestorer do
include_context "shared stuff"
include_context "with shared stuff"
subject { BackupRestore::UploadsRestorer.new(logger) }
@ -94,7 +94,7 @@ RSpec.describe BackupRestore::UploadsRestorer do
Regexp.escape("//#{bucket}") + %q*\.s3(?:\.dualstack\.[a-z0-9\-]+?|[.\-][a-z0-9\-]+?)?\.amazonaws\.com* + Regexp.escape(path)
end
context "uploads" do
describe "uploads" do
let!(:multisite) { { name: "multisite", value: true } }
let!(:no_multisite) { { name: "multisite", value: false } }
let!(:source_db_name) { { name: "db_name", value: "foo" } }
@ -104,7 +104,7 @@ RSpec.describe BackupRestore::UploadsRestorer do
let(:target_site_name) { target_site_type == multisite ? "second" : "default" }
let(:target_hostname) { target_site_type == multisite ? "test2.localhost" : "test.localhost" }
shared_context "no uploads" do
shared_context "with no uploads" do
it "does nothing when temporary uploads directory is missing or empty" do
store_class.any_instance.expects(:copy_from).never
@ -132,7 +132,7 @@ RSpec.describe BackupRestore::UploadsRestorer do
end
end
shared_context "restores uploads" do
shared_context "when restoring uploads" do
before do
Upload.where("id > 0").destroy_all
Fabricate(:optimized_image)
@ -242,34 +242,34 @@ RSpec.describe BackupRestore::UploadsRestorer do
end
end
context "currently stored locally" do
context "when currently stored locally" do
before do
SiteSetting.enable_s3_uploads = false
end
let!(:store_class) { FileStore::LocalStore }
include_context "no uploads"
include_context "restores uploads"
include_context "with no uploads"
include_context "when restoring uploads"
context "remaps" do
context "with remaps" do
include_examples "without metadata"
context "uploads previously stored locally" do
context "when uploads previously stored locally" do
let!(:s3_base_url) { { name: "s3_base_url", value: nil } }
let!(:s3_cdn_url) { { name: "s3_cdn_url", value: nil } }
context "from regular site" do
context "with regular site as source" do
let!(:source_site_type) { no_multisite }
context "to regular site" do
context "with regular site as target" do
let!(:target_site_type) { no_multisite }
include_examples "common remaps"
include_examples "remaps from local storage"
end
context "to multisite", type: :multisite do
context "with multisite as target", type: :multisite do
let!(:target_site_type) { multisite }
include_examples "common remaps"
@ -277,17 +277,17 @@ RSpec.describe BackupRestore::UploadsRestorer do
end
end
context "from multisite" do
context "with multisite as source" do
let!(:source_site_type) { multisite }
context "to regular site" do
context "with regular site as target" do
let!(:target_site_type) { no_multisite }
include_examples "common remaps"
include_examples "remaps from local storage"
end
context "to multisite", type: :multisite do
context "with multisite as target", type: :multisite do
let!(:target_site_type) { multisite }
include_examples "common remaps"
@ -296,7 +296,7 @@ RSpec.describe BackupRestore::UploadsRestorer do
end
end
context "uploads previously stored on S3" do
context "with uploads previously stored on S3" do
let!(:s3_base_url) { { name: "s3_base_url", value: "//old-bucket.s3-us-east-1.amazonaws.com" } }
let!(:s3_cdn_url) { { name: "s3_cdn_url", value: "https://s3-cdn.example.com" } }
@ -346,17 +346,17 @@ RSpec.describe BackupRestore::UploadsRestorer do
end
end
context "from regular site" do
context "with regular site as source" do
let!(:source_site_type) { no_multisite }
context "to regular site" do
context "with regular site as target" do
let!(:target_site_type) { no_multisite }
include_examples "common remaps"
include_examples "regular site remaps from S3"
end
context "to multisite", type: :multisite do
context "with multisite as target", type: :multisite do
let!(:target_site_type) { multisite }
include_examples "common remaps"
@ -364,17 +364,17 @@ RSpec.describe BackupRestore::UploadsRestorer do
end
end
context "from multisite" do
context "with multisite as source" do
let!(:source_site_type) { multisite }
context "to regular site" do
context "with regular site as target" do
let!(:target_site_type) { no_multisite }
include_examples "common remaps"
include_examples "multisite remaps from S3"
end
context "to multisite", type: :multisite do
context "with multisite as target", type: :multisite do
let!(:target_site_type) { no_multisite }
include_examples "common remaps"
@ -385,34 +385,34 @@ RSpec.describe BackupRestore::UploadsRestorer do
end
end
context "currently stored on S3" do
context "when currently stored on S3" do
before do
setup_s3
end
let!(:store_class) { FileStore::S3Store }
include_context "no uploads"
include_context "restores uploads"
include_context "with no uploads"
include_context "when restoring uploads"
context "remaps" do
context "with remaps" do
include_examples "without metadata"
context "uploads previously stored locally" do
context "with uploads previously stored locally" do
let!(:s3_base_url) { { name: "s3_base_url", value: nil } }
let!(:s3_cdn_url) { { name: "s3_cdn_url", value: nil } }
context "from regular site" do
context "with regular site as source" do
let!(:source_site_type) { no_multisite }
context "to regular site" do
context "with regular site as target" do
let!(:target_site_type) { no_multisite }
include_examples "common remaps"
include_examples "remaps from local storage"
end
context "to multisite", type: :multisite do
context "with multisite as target", type: :multisite do
let!(:target_site_type) { no_multisite }
include_examples "common remaps"
@ -420,17 +420,17 @@ RSpec.describe BackupRestore::UploadsRestorer do
end
end
context "from multisite" do
context "with multisite as source" do
let!(:source_site_type) { multisite }
context "to regular site" do
context "with regular site as target" do
let!(:target_site_type) { no_multisite }
include_examples "common remaps"
include_examples "remaps from local storage"
end
context "to multisite", type: :multisite do
context "with multisite as target", type: :multisite do
let!(:target_site_type) { multisite }
include_examples "common remaps"
@ -439,7 +439,7 @@ RSpec.describe BackupRestore::UploadsRestorer do
end
end
context "uploads previously stored on S3" do
context "with uploads previously stored on S3" do
let!(:s3_base_url) { { name: "s3_base_url", value: "//old-bucket.s3-us-east-1.amazonaws.com" } }
let!(:s3_cdn_url) { { name: "s3_cdn_url", value: "https://s3-cdn.example.com" } }
@ -510,10 +510,10 @@ RSpec.describe BackupRestore::UploadsRestorer do
end
end
context "from regular site" do
context "with regular site as source" do
let!(:source_site_type) { no_multisite }
context "to regular site" do
context "with regular site as target" do
let!(:target_site_name) { "default" }
let!(:target_hostname) { "test.localhost" }
@ -521,7 +521,7 @@ RSpec.describe BackupRestore::UploadsRestorer do
include_examples "regular site remaps from S3"
end
context "to multisite", type: :multisite do
context "with multisite as target", type: :multisite do
let!(:target_site_name) { "second" }
let!(:target_hostname) { "test2.localhost" }
@ -530,17 +530,17 @@ RSpec.describe BackupRestore::UploadsRestorer do
end
end
context "from multisite" do
context "with multisite as source" do
let!(:source_site_type) { multisite }
context "to regular site" do
context "with regular site as target" do
let!(:target_site_type) { no_multisite }
include_examples "common remaps"
include_examples "multisite remaps from S3"
end
context "to multisite", type: :multisite do
context "with multisite as target", type: :multisite do
let!(:target_site_type) { multisite }
include_examples "common remaps"

View File

@ -61,7 +61,7 @@ RSpec.describe CommonPasswords do
end
end
context "missing password file" do
describe "missing password file" do
it "tolerates it" do
File.stubs(:readlines).with(described_class::PASSWORD_FILE).raises(Errno::ENOENT)
expect(described_class.common_password?("password")).to eq(false)

View File

@ -4,8 +4,7 @@
require 'composer_messages_finder'
RSpec.describe ComposerMessagesFinder do
context "delegates work" do
describe "delegates work" do
let(:user) { Fabricate.build(:user) }
let(:finder) { ComposerMessagesFinder.new(user, composer_action: 'createTopic') }
@ -19,13 +18,12 @@ RSpec.describe ComposerMessagesFinder do
finder.expects(:check_get_a_room).once
finder.find
end
end
describe '.check_education_message' do
let(:user) { Fabricate.build(:user) }
context 'creating topic' do
context 'when creating topic' do
let(:finder) { ComposerMessagesFinder.new(user, composer_action: 'createTopic') }
before do
@ -43,10 +41,10 @@ RSpec.describe ComposerMessagesFinder do
end
end
context 'private message' do
context 'with private message' do
fab!(:topic) { Fabricate(:private_message_topic) }
context 'starting a new private message' do
context 'when starting a new private message' do
let(:finder) { ComposerMessagesFinder.new(user, composer_action: 'createTopic', topic_id: topic.id) }
it 'should return an empty string' do
@ -54,7 +52,7 @@ RSpec.describe ComposerMessagesFinder do
end
end
context 'replying to a private message' do
context 'when replying to a private message' do
let(:finder) { ComposerMessagesFinder.new(user, composer_action: 'reply', topic_id: topic.id) }
it 'should return an empty string' do
@ -63,7 +61,7 @@ RSpec.describe ComposerMessagesFinder do
end
end
context 'creating reply' do
context 'when creating reply' do
let(:finder) { ComposerMessagesFinder.new(user, composer_action: 'reply') }
before do
@ -85,7 +83,7 @@ RSpec.describe ComposerMessagesFinder do
describe '.check_new_user_many_replies' do
let(:user) { Fabricate.build(:user) }
context 'replying' do
context 'when replying' do
let(:finder) { ComposerMessagesFinder.new(user, composer_action: 'reply') }
it "has no message when `posted_too_much_in_topic?` is false" do
@ -105,7 +103,7 @@ RSpec.describe ComposerMessagesFinder do
let(:finder) { ComposerMessagesFinder.new(user, composer_action: 'createTopic') }
fab!(:user) { Fabricate(:user) }
context "success" do
context "with success" do
let!(:message) { finder.check_avatar_notification }
it "returns an avatar upgrade message" do
@ -174,7 +172,7 @@ RSpec.describe ComposerMessagesFinder do
expect(ComposerMessagesFinder.new(user, composer_action: 'reply').check_sequential_replies).to be_blank
end
context "reply" do
context "with reply" do
let(:finder) { ComposerMessagesFinder.new(user, composer_action: 'reply', topic_id: topic.id) }
it "does not give a message to users who are still in the 'education' phase" do
@ -207,7 +205,7 @@ RSpec.describe ComposerMessagesFinder do
expect(finder.check_sequential_replies).to be_blank
end
context "success" do
context "with success" do
let!(:message) { finder.check_sequential_replies }
it "returns a message" do
@ -249,7 +247,7 @@ RSpec.describe ComposerMessagesFinder do
expect(ComposerMessagesFinder.new(user, composer_action: 'reply').check_dominating_topic).to be_blank
end
context "reply" do
context "with reply" do
let(:finder) { ComposerMessagesFinder.new(user, composer_action: 'reply', topic_id: topic.id) }
it "does not give a message to users who are still in the 'education' phase" do
@ -292,7 +290,7 @@ RSpec.describe ComposerMessagesFinder do
expect(finder.check_dominating_topic).to be_blank
end
context "success" do
context "with success" do
let!(:message) { finder.check_dominating_topic }
it "returns a message" do
@ -349,7 +347,7 @@ RSpec.describe ComposerMessagesFinder do
expect(UserHistory.exists_for_user?(user, :notified_about_get_a_room)).to eq(false)
end
context "reply" do
context "with reply" do
let(:finder) { ComposerMessagesFinder.new(user, composer_action: 'reply', topic_id: topic.id, post_id: op.id) }
it "does not give a message to users who are still in the 'education' phase" do
@ -415,7 +413,7 @@ RSpec.describe ComposerMessagesFinder do
end
end
context "success" do
context "with success" do
let!(:message) { finder.check_get_a_room(min_users_posted: 2) }
it "works as expected" do
@ -440,8 +438,8 @@ RSpec.describe ComposerMessagesFinder do
expect(described_class.new(user, composer_action: 'reply').check_reviving_old_topic).to be_blank
end
context "a reply" do
context "warn_reviving_old_topic_age is 180 days" do
context "with a reply" do
context "when warn_reviving_old_topic_age is 180 days" do
before do
SiteSetting.warn_reviving_old_topic_age = 180
end
@ -459,7 +457,7 @@ RSpec.describe ComposerMessagesFinder do
end
end
context "warn_reviving_old_topic_age is 0" do
context "when warn_reviving_old_topic_age is 0" do
before do
SiteSetting.warn_reviving_old_topic_age = 0
end
@ -503,5 +501,4 @@ RSpec.describe ComposerMessagesFinder do
expect(edit_post_finder.find).to eq(nil)
end
end
end

View File

@ -30,7 +30,7 @@ RSpec.describe Compression::Engine do
end
end
context 'working with zip files' do
context 'when working with zip files' do
let(:extension) { '.zip' }
it 'decompress the folder and inspect files correctly' do
@ -43,7 +43,7 @@ RSpec.describe Compression::Engine do
end
end
context 'working with .tar.gz files' do
context 'when working with .tar.gz files' do
let(:extension) { '.tar.gz' }
it 'decompress the folder and inspect files correctly' do
@ -56,7 +56,7 @@ RSpec.describe Compression::Engine do
end
end
context 'working with .tar files' do
context 'when working with .tar files' do
let(:extension) { '.tar' }
it 'decompress the folder and inspect files correctly' do

View File

@ -15,13 +15,11 @@ class TestCachedCounting
end
RSpec.describe CachedCounting do
it "should be default disabled in test" do
expect(CachedCounting.enabled?).to eq(false)
end
context "backing implementation" do
describe "backing implementation" do
it "can correctly check for flush to db lock" do
CachedCounting.clear_flush_to_db_lock!
@ -55,7 +53,7 @@ RSpec.describe CachedCounting do
end
end
context "active record" do
describe "active record" do
class RailsCacheCounter < ActiveRecord::Base
include CachedCounting
self.table_name = "posts"

View File

@ -27,7 +27,7 @@ RSpec.describe CategoryHashtag do
expect(Category.query_from_hashtag_slug("non-existent#{CategoryHashtag::SEPARATOR}#{parent_category.slug}")).to eq(nil)
end
context "multi-level categories" do
context "with multi-level categories" do
before do
SiteSetting.max_category_nesting = 3
end

View File

@ -1,7 +1,7 @@
# frozen_string_literal: true
RSpec.describe HasCustomFields do
context "custom_fields" do
describe "custom_fields" do
before do
DB.exec("create temporary table custom_fields_test_items(id SERIAL primary key)")
DB.exec("create temporary table custom_fields_test_item_custom_fields(id SERIAL primary key, custom_fields_test_item_id int, name varchar(256) not null, value text, created_at TIMESTAMP, updated_at TIMESTAMP)")

View File

@ -1,7 +1,7 @@
# frozen_string_literal: true
RSpec.describe HasSearchData do
context "belongs to its model" do
describe "belongs to its model" do
before do
DB.exec("create temporary table model_items(id SERIAL primary key)")
DB.exec("create temporary table model_item_search_data(model_item_id int primary key, search_data tsvector, raw_data text, locale text)")

View File

@ -1,12 +1,11 @@
# frozen_string_literal: true
RSpec.describe Positionable do
def positions
TestItem.order('position asc, id asc').pluck(:id)
end
context "move_to" do
describe "move_to" do
before do
class TestItem < ActiveRecord::Base
include Positionable

View File

@ -1,7 +1,7 @@
# frozen_string_literal: true
RSpec.describe Searchable do
context "has search data" do
describe "has search data" do
before do
DB.exec("create temporary table searchable_records(id SERIAL primary key)")
DB.exec("create temporary table searchable_record_search_data(searchable_record_id int primary key, search_data tsvector, raw_data text, locale text)")

View File

@ -409,7 +409,7 @@ RSpec.describe SecondFactorManager do
end
end
context 'backup codes' do
describe 'backup codes' do
describe '#generate_backup_codes' do
it 'should generate and store 10 backup codes' do
backup_codes = user.generate_backup_codes

View File

@ -249,12 +249,12 @@ RSpec.describe CookedPostProcessor do
end
end
context "processing images" do
context "when processing images" do
before do
SiteSetting.responsive_post_image_sizes = ""
end
context "responsive images" do
context "with responsive images" do
before { SiteSetting.responsive_post_image_sizes = "1|1.5|3" }
it "includes responsive images on demand" do
@ -361,7 +361,7 @@ RSpec.describe CookedPostProcessor do
cpp.post_process
end
context "valid" do
context "when valid" do
let(:image_sizes) { { "http://foo.bar/image.png" => { "width" => 111, "height" => 222 } } }
it "uses them" do
@ -371,17 +371,17 @@ RSpec.describe CookedPostProcessor do
end
end
context "invalid width" do
context "with invalid width" do
let(:image_sizes) { { "http://foo.bar/image.png" => { "width" => 0, "height" => 222 } } }
include_examples "leave dimensions alone"
end
context "invalid height" do
context "with invalid height" do
let(:image_sizes) { { "http://foo.bar/image.png" => { "width" => 111, "height" => 0 } } }
include_examples "leave dimensions alone"
end
context "invalid width & height" do
context "with invalid width & height" do
let(:image_sizes) { { "http://foo.bar/image.png" => { "width" => 0, "height" => 0 } } }
include_examples "leave dimensions alone"
end
@ -433,7 +433,7 @@ RSpec.describe CookedPostProcessor do
expect(cpp).to be_dirty
end
describe 'when image is inside onebox' do
context 'when image is inside onebox' do
let(:url) { 'https://image.com/my-avatar' }
let(:post) { Fabricate(:post, raw: url) }
@ -452,7 +452,7 @@ RSpec.describe CookedPostProcessor do
end
end
describe 'when image is an svg' do
context 'when image is an svg' do
fab!(:post) do
Fabricate(:post, raw: "<img src=\"/#{Discourse.store.upload_path}/original/1X/1234567890123456.svg\">")
end
@ -467,7 +467,7 @@ RSpec.describe CookedPostProcessor do
HTML
end
describe 'when image src is an URL' do
context 'when image src is an URL' do
let(:post) do
Fabricate(:post, raw: "<img src=\"http://test.discourse/#{upload_path}/original/1X/1234567890123456.svg?somepamas\">")
end
@ -482,7 +482,7 @@ RSpec.describe CookedPostProcessor do
end
end
context "s3_uploads" do
context "with s3_uploads" do
let(:upload) { Fabricate(:secure_upload_s3) }
before do
@ -746,7 +746,7 @@ RSpec.describe CookedPostProcessor do
end
context "topic image" do
context "with topic image" do
fab!(:post) { Fabricate(:post_with_uploaded_image) }
let(:cpp) { CookedPostProcessor.new(post) }
@ -822,7 +822,7 @@ RSpec.describe CookedPostProcessor do
expect(post.reload.image_upload_id).to eq(upload2.id)
end
context "post image" do
context "with post image" do
let(:reply) { Fabricate(:post_with_uploaded_image, post_number: 2) }
let(:cpp) { CookedPostProcessor.new(reply) }
@ -838,18 +838,15 @@ RSpec.describe CookedPostProcessor do
end
describe "#extract_images" do
let(:post) { build(:post_with_plenty_of_images) }
let(:cpp) { CookedPostProcessor.new(post) }
it "does not extract emojis or images inside oneboxes or quotes" do
expect(cpp.extract_images.length).to eq(0)
end
end
describe "#get_size_from_attributes" do
let(:post) { build(:post) }
let(:cpp) { CookedPostProcessor.new(post) }
@ -879,11 +876,9 @@ RSpec.describe CookedPostProcessor do
img = { 'src' => nil, 'height' => 100 }
expect(cpp.get_size_from_attributes(img)).to be_nil
end
end
describe "#get_size_from_image_sizes" do
let(:post) { build(:post) }
let(:cpp) { CookedPostProcessor.new(post) }
@ -891,11 +886,9 @@ RSpec.describe CookedPostProcessor do
image_sizes = { "http://my.discourse.org/image.png" => { "width" => 111, "height" => 222 } }
expect(cpp.get_size_from_image_sizes("/image.png", image_sizes)).to eq([111, 222])
end
end
describe "#get_size" do
let(:post) { build(:post) }
let(:cpp) { CookedPostProcessor.new(post) }
@ -917,7 +910,6 @@ RSpec.describe CookedPostProcessor do
end
describe "#is_valid_image_url?" do
let(:post) { build(:post) }
let(:cpp) { CookedPostProcessor.new(post) }
@ -936,11 +928,9 @@ RSpec.describe CookedPostProcessor do
it "doesn't throw an exception with a bad URI" do
expect(cpp.is_valid_image_url?("http://do<main.com")).to eq(nil)
end
end
describe "#get_filename" do
let(:post) { build(:post) }
let(:cpp) { CookedPostProcessor.new(post) }
@ -957,7 +947,6 @@ RSpec.describe CookedPostProcessor do
upload = build(:upload, original_filename: "blob.png")
expect(cpp.get_filename(upload, "http://domain.com/image.png")).to eq(I18n.t('upload.pasted_image_filename'))
end
end
describe "#convert_to_link" do
@ -995,7 +984,7 @@ RSpec.describe CookedPostProcessor do
expect(doc.css('img.animated').size).to eq(1)
end
context "giphy/tenor images" do
context "with giphy/tenor images" do
before do
CookedPostProcessor.any_instance.stubs(:get_size).with("https://media2.giphy.com/media/7Oifk90VrCdNe/giphy.webp").returns([311, 280])
CookedPostProcessor.any_instance.stubs(:get_size).with("https://media1.tenor.com/images/20c7ddd5e84c7427954f430439c5209d/tenor.gif").returns([833, 104])
@ -1226,7 +1215,6 @@ RSpec.describe CookedPostProcessor do
end
describe "#post_process_oneboxes with square image" do
it "generates a onebox-avatar class" do
url = 'https://square-image.com/onebox'
@ -1256,11 +1244,9 @@ RSpec.describe CookedPostProcessor do
expect(cpp.doc.to_s).not_to include('aspect-image')
expect(cpp.doc.to_s).to include('onebox-avatar')
end
end
describe "#optimize_urls" do
let(:post) { build(:post_with_uploads_and_links) }
let(:cpp) { CookedPostProcessor.new(post) }
@ -1277,7 +1263,6 @@ RSpec.describe CookedPostProcessor do
end
context "when CDN is enabled" do
it "uses schemaless CDN url for http uploads" do
Rails.configuration.action_controller.stubs(:asset_host).returns("http://my.cdn.com")
cpp.optimize_urls
@ -1332,7 +1317,7 @@ RSpec.describe CookedPostProcessor do
HTML
end
context "s3_uploads" do
context "with s3_uploads" do
before do
Rails.configuration.action_controller.stubs(:asset_host).returns("https://local.cdn.com")
@ -1405,7 +1390,7 @@ RSpec.describe CookedPostProcessor do
HTML
end
context "media uploads" do
context "with media uploads" do
fab!(:image_upload) { Fabricate(:upload) }
fab!(:audio_upload) { Fabricate(:upload, extension: "ogg") }
fab!(:video_upload) { Fabricate(:upload, extension: "mov") }
@ -1543,7 +1528,6 @@ RSpec.describe CookedPostProcessor do
end
describe "#is_a_hyperlink?" do
let(:post) { build(:post) }
let(:cpp) { CookedPostProcessor.new(post) }
let(:doc) { Nokogiri::HTML5::fragment('<body><div><a><img id="linked_image"></a><p><img id="standard_image"></p></div></body>') }
@ -1557,13 +1541,12 @@ RSpec.describe CookedPostProcessor do
img = doc.css("img#standard_image").first
expect(cpp.is_a_hyperlink?(img)).to eq(false)
end
end
context "grant badges" do
describe "grant badges" do
let(:cpp) { CookedPostProcessor.new(post) }
context "emoji inside a quote" do
context "with emoji inside a quote" do
let(:post) { Fabricate(:post, raw: "time to eat some sweet \n[quote]\n:candy:\n[/quote]\n mmmm") }
it "doesn't award a badge when the emoji is in a quote" do
@ -1572,7 +1555,7 @@ RSpec.describe CookedPostProcessor do
end
end
context "emoji in the text" do
context "with emoji in the text" do
let(:post) { Fabricate(:post, raw: "time to eat some sweet :candy: mmmm") }
it "awards a badge for using an emoji" do
@ -1581,7 +1564,7 @@ RSpec.describe CookedPostProcessor do
end
end
context "onebox" do
context "with onebox" do
before do
Oneboxer.stubs(:onebox).with(anything, anything).returns(nil)
Oneboxer.stubs(:onebox).with('https://discourse.org', anything).returns("<aside class=\"onebox allowlistedgeneric\">the rest of the onebox</aside>")
@ -1613,7 +1596,7 @@ RSpec.describe CookedPostProcessor do
end
end
context "reply_by_email" do
context "with reply_by_email" do
let(:post) { Fabricate(:post, raw: "This is a **reply** via email ;)", via_email: true, post_number: 2) }
it "awards a badge for replying via email" do
@ -1624,7 +1607,7 @@ RSpec.describe CookedPostProcessor do
end
context "quote processing" do
describe "quote processing" do
let(:cpp) { CookedPostProcessor.new(cp) }
let(:pp) { Fabricate(:post, raw: "This post is ripe for quoting!") }
@ -1656,7 +1639,7 @@ RSpec.describe CookedPostProcessor do
end
end
context "external discourse instance quote" do
context "with external discourse instance quote" do
let(:external_raw) do
<<~RAW.strip
[quote="random_guy_not_from_our_discourse, post:2004, topic:401"]
@ -1674,7 +1657,7 @@ RSpec.describe CookedPostProcessor do
end
end
context "full quote on direct reply" do
describe "full quote on direct reply" do
fab!(:topic) { Fabricate(:topic) }
let!(:post) { Fabricate(:post, topic: topic, raw: 'this is the "first" post') }
@ -1803,7 +1786,7 @@ RSpec.describe CookedPostProcessor do
end
end
context "full quote on direct reply with full name prioritization" do
describe "full quote on direct reply with full name prioritization" do
fab!(:user) { Fabricate(:user, name: "james, john, the third") }
fab!(:topic) { Fabricate(:topic) }
let!(:post) { Fabricate(:post, user: user, topic: topic, raw: 'this is the "first" post') }
@ -1935,7 +1918,7 @@ RSpec.describe CookedPostProcessor do
end
end
context "prioritizes full name in quotes" do
describe "prioritizes full name in quotes" do
fab!(:user) { Fabricate(:user, name: "james, john, the third") }
fab!(:topic) { Fabricate(:topic) }
let!(:post) { Fabricate(:post, user: user, topic: topic, raw: 'this is the "first" post') }

View File

@ -1,7 +1,6 @@
# frozen_string_literal: true
RSpec.describe CrawlerDetection do
def crawler!(user_agent, via = nil)
if (!CrawlerDetection.crawler?(user_agent, via))
raise "#{user_agent} should be a crawler!"
@ -14,8 +13,7 @@ RSpec.describe CrawlerDetection do
end
end
describe "crawler?" do
describe ".crawler?" do
it "can be amended via site settings" do
SiteSetting.crawler_user_agents = 'Mooble|Kaboodle+*'
@ -67,7 +65,7 @@ RSpec.describe CrawlerDetection do
end
describe 'show_browser_update?' do
describe '.show_browser_update?' do
it 'always returns false if setting is empty' do
SiteSetting.browser_update_user_agents = ""
@ -83,12 +81,12 @@ RSpec.describe CrawlerDetection do
end
end
describe 'allow_crawler?' do
describe '.allow_crawler?' do
it 'returns true if allowlist and blocklist are blank' do
expect(CrawlerDetection.allow_crawler?('Googlebot/2.1 (+http://www.google.com/bot.html)')).to eq(true)
end
context 'allowlist is set' do
context 'when allowlist is set' do
before do
SiteSetting.allowed_crawler_user_agents = 'Googlebot|Twitterbot'
end
@ -105,7 +103,7 @@ RSpec.describe CrawlerDetection do
expect(CrawlerDetection.allow_crawler?('')).to eq(false)
end
context 'and blocklist is set' do
context 'when blocklist is set' do
before do
SiteSetting.blocked_crawler_user_agents = 'Googlebot-Image'
end
@ -116,7 +114,7 @@ RSpec.describe CrawlerDetection do
end
end
context 'blocklist is set' do
context 'when blocklist is set' do
before do
SiteSetting.blocked_crawler_user_agents = 'Googlebot|Twitterbot'
end
@ -135,7 +133,7 @@ RSpec.describe CrawlerDetection do
end
end
describe 'is_blocked_crawler?' do
describe '.is_blocked_crawler?' do
it 'is false if user agent is a crawler and no allowlist or blocklist is defined' do
expect(CrawlerDetection.is_blocked_crawler?('Twitterbot')).to eq(false)
end

View File

@ -3,13 +3,12 @@
require 'discourse_plugin_registry'
RSpec.describe DiscoursePluginRegistry do
class TestRegistry < DiscoursePluginRegistry; end
let(:registry) { TestRegistry }
let(:registry_instance) { registry.new }
context '::define_register' do
describe '.define_register' do
let(:fresh_registry) { Class.new(TestRegistry) }
let(:plugin_class) do
@ -39,7 +38,7 @@ RSpec.describe DiscoursePluginRegistry do
expect(fresh_registry.test_things[:test]).to eq(nil)
end
context '::define_filtered_register' do
describe '.define_filtered_register' do
it 'works' do
fresh_registry.define_filtered_register(:test_things)
expect(fresh_registry.test_things.length).to eq(0)
@ -262,5 +261,4 @@ RSpec.describe DiscoursePluginRegistry do
expect(registry.seed_data["admin_quick_start_filename"]).to eq(File.expand_path("../docs/BANANA-QUICK-START.md", __FILE__))
end
end
end

View File

@ -3,24 +3,23 @@
require 'discourse'
RSpec.describe Discourse do
before do
RailsMultisite::ConnectionManagement.stubs(:current_hostname).returns('foo.com')
end
context 'current_hostname' do
describe 'current_hostname' do
it 'returns the hostname from the current db connection' do
expect(Discourse.current_hostname).to eq('foo.com')
end
end
context 'avatar_sizes' do
describe 'avatar_sizes' do
it 'returns a list of integers' do
expect(Discourse.avatar_sizes).to contain_exactly(20, 25, 30, 32, 37, 40, 45, 48, 50, 60, 64, 67, 75, 90, 96, 120, 135, 180, 240, 360)
end
end
context 'running_in_rack' do
describe 'running_in_rack' do
after do
ENV.delete("DISCOURSE_RUNNING_IN_RACK")
end
@ -32,7 +31,7 @@ RSpec.describe Discourse do
end
end
context 'base_url' do
describe 'base_url' do
context 'when https is off' do
before do
SiteSetting.force_https = false
@ -64,7 +63,7 @@ RSpec.describe Discourse do
end
end
context "asset_filter_options" do
describe "asset_filter_options" do
it "obmits path if request is missing" do
opts = Discourse.asset_filter_options(:js, nil)
expect(opts[:path]).to be_blank
@ -77,7 +76,7 @@ RSpec.describe Discourse do
end
end
context 'plugins' do
describe 'plugins' do
let(:plugin_class) do
Class.new(Plugin::Instance) do
attr_accessor :enabled
@ -129,7 +128,7 @@ RSpec.describe Discourse do
end
context 'authenticators' do
describe 'authenticators' do
it 'returns inbuilt authenticators' do
expect(Discourse.authenticators).to match_array(Discourse::BUILTIN_AUTH.map(&:authenticator))
end
@ -167,7 +166,7 @@ RSpec.describe Discourse do
end
end
context 'enabled_authenticators' do
describe 'enabled_authenticators' do
it 'only returns enabled authenticators' do
expect(Discourse.enabled_authenticators.length).to be(0)
expect { SiteSetting.enable_twitter_logins = true }
@ -178,7 +177,6 @@ RSpec.describe Discourse do
end
describe '#site_contact_user' do
fab!(:admin) { Fabricate(:admin) }
fab!(:another_admin) { Fabricate(:admin) }
@ -201,7 +199,6 @@ RSpec.describe Discourse do
end
describe "#store" do
it "returns LocalStore by default" do
expect(Discourse.store).to be_a(FileStore::LocalStore)
end
@ -213,10 +210,9 @@ RSpec.describe Discourse do
SiteSetting.s3_secret_access_key = "s3_secret_access_key"
expect(Discourse.store).to be_a(FileStore::S3Store)
end
end
context 'readonly mode' do
describe 'readonly mode' do
let(:readonly_mode_key) { Discourse::READONLY_MODE_KEY }
let(:readonly_mode_ttl) { Discourse::READONLY_MODE_KEY_TTL }
let(:user_readonly_mode_key) { Discourse::USER_READONLY_MODE_KEY }
@ -244,7 +240,7 @@ RSpec.describe Discourse do
expect(Discourse.redis.get(readonly_mode_key)).to eq(nil)
end
context 'user enabled readonly mode' do
context 'when user enabled readonly mode' do
it "adds a key in redis and publish a message through the message bus" do
expect(Discourse.redis.get(user_readonly_mode_key)).to eq(nil)
end
@ -252,7 +248,7 @@ RSpec.describe Discourse do
end
describe ".disable_readonly_mode" do
context 'user disabled readonly mode' do
context 'when user disabled readonly mode' do
it "removes readonly key in redis and publish a message through the message bus" do
message = MessageBus.track_publish { Discourse.disable_readonly_mode(user_readonly_mode_key) }.first
assert_readonly_mode_disabled(message, user_readonly_mode_key)
@ -320,7 +316,6 @@ RSpec.describe Discourse do
end
describe "#handle_exception" do
class TempSidekiqLogger
attr_accessor :exception, :context
@ -341,7 +336,6 @@ RSpec.describe Discourse do
end
describe "#job_exception_stats" do
class FakeTestError < StandardError
end

View File

@ -6,7 +6,6 @@ require 'discourse_tagging'
# More tests are found in the category_tag_spec integration specs
RSpec.describe DiscourseTagging do
fab!(:admin) { Fabricate(:admin) }
fab!(:user) { Fabricate(:user) }
let(:guardian) { Guardian.new(user) }
@ -40,7 +39,7 @@ RSpec.describe DiscourseTagging do
expect(tags).to contain_exactly(tag1.name, tag3.name)
end
context 'tag with colon' do
context 'with tag with colon' do
fab!(:tag_with_colon) { Fabricate(:tag, name: 'with:colon') }
it "can use it as selected tag" do
@ -240,7 +239,7 @@ RSpec.describe DiscourseTagging do
end
context 'empty term' do
context 'with empty term' do
it "works with an empty term" do
tags = DiscourseTagging.filter_allowed_tags(Guardian.new(user),
term: '',
@ -250,7 +249,7 @@ RSpec.describe DiscourseTagging do
end
end
context 'tag synonyms' do
context 'with tag synonyms' do
fab!(:base_tag) { Fabricate(:tag, name: 'discourse') }
fab!(:synonym) { Fabricate(:tag, name: 'discource', target_tag: base_tag) }
@ -320,7 +319,7 @@ RSpec.describe DiscourseTagging do
end
describe 'tag_topic_by_names' do
context 'visible but restricted tags' do
context 'with visible but restricted tags' do
fab!(:topic) { Fabricate(:topic) }
before do
@ -357,7 +356,7 @@ RSpec.describe DiscourseTagging do
expect(tag_changed_event[:params].second[:new_tag_names]).to eq(['alpha'])
end
context 'non-staff users in tag group groups' do
context 'with non-staff users in tag group groups' do
fab!(:non_staff_group) { Fabricate(:group, name: 'non_staff_group') }
before do
@ -424,7 +423,7 @@ RSpec.describe DiscourseTagging do
expect(topic.reload.tags.pluck(:name)).to eq([tag1.name])
end
context 'respects category minimum_required_tags setting' do
context 'when respecting category minimum_required_tags setting' do
fab!(:category) { Fabricate(:category, minimum_required_tags: 2) }
fab!(:topic) { Fabricate(:topic, category: category) }
@ -453,7 +452,7 @@ RSpec.describe DiscourseTagging do
end
end
context 'hidden tags' do
context 'with hidden tags' do
fab!(:hidden_tag) { Fabricate(:tag) }
let!(:staff_tag_group) { Fabricate(:tag_group, permissions: { "staff" => 1 }, tag_names: [hidden_tag.name]) }
fab!(:topic) { Fabricate(:topic, user: user) }
@ -476,7 +475,7 @@ RSpec.describe DiscourseTagging do
end
end
context 'tag group with parent tag' do
context 'with tag group with parent tag' do
let(:topic) { Fabricate(:topic, user: user) }
let(:post) { Fabricate(:post, user: user, topic: topic, post_number: 1) }
let(:tag_group) { Fabricate(:tag_group, parent_tag_id: tag1.id) }
@ -522,7 +521,7 @@ RSpec.describe DiscourseTagging do
end
end
context "enforces required tags from a tag group" do
context "when enforcing required tags from a tag group" do
fab!(:category) { Fabricate(:category) }
fab!(:tag_group) { Fabricate(:tag_group) }
fab!(:topic) { Fabricate(:topic, category: category) }
@ -567,7 +566,7 @@ RSpec.describe DiscourseTagging do
end
end
context 'tag synonyms' do
context 'with tag synonyms' do
fab!(:topic) { Fabricate(:topic) }
fab!(:syn1) { Fabricate(:tag, name: 'synonym1', target_tag: tag1) }
@ -603,7 +602,7 @@ RSpec.describe DiscourseTagging do
expect(described_class.tags_for_saving(['newtag'], guardian)).to eq([])
end
context "can tag topics but not create tags" do
describe "can tag topics but not create tags" do
before do
guardian.stubs(:can_create_tag?).returns(false)
guardian.stubs(:can_tag_topics?).returns(true)
@ -620,7 +619,7 @@ RSpec.describe DiscourseTagging do
end
end
context "can tag topics and create tags" do
describe "can tag topics and create tags" do
before do
guardian.stubs(:can_create_tag?).returns(true)
guardian.stubs(:can_tag_topics?).returns(true)

View File

@ -10,13 +10,13 @@ RSpec.describe DiscourseUpdates do
subject { DiscourseUpdates.check_version }
context 'version check was done at the current installed version' do
context 'when version check was done at the current installed version' do
before do
DiscourseUpdates.last_installed_version = Discourse::VERSION::STRING
end
context 'a good version check request happened recently' do
context 'and server is up-to-date' do
context 'when a good version check request happened recently' do
context 'when server is up-to-date' do
let(:time) { 12.hours.ago }
before { stub_data(Discourse::VERSION::STRING, 0, false, time) }
@ -33,7 +33,7 @@ RSpec.describe DiscourseUpdates do
end
end
context 'and server is not up-to-date' do
context 'when server is not up-to-date' do
let(:time) { 12.hours.ago }
before { stub_data('0.9.0', 2, false, time) }
@ -50,7 +50,7 @@ RSpec.describe DiscourseUpdates do
end
end
context 'a version check has never been performed' do
context 'when a version check has never been performed' do
before { stub_data(nil, nil, false, nil) }
it 'returns the installed version' do
@ -77,7 +77,7 @@ RSpec.describe DiscourseUpdates do
# These cases should never happen anymore, but keep the specs to be sure
# they're handled in a sane way.
context 'old version check data' do
context 'with old version check data' do
shared_examples "queue version check and report that version is ok" do
it 'queues a version check' do
expect_enqueued_with(job: :version_check) do
@ -94,19 +94,19 @@ RSpec.describe DiscourseUpdates do
end
end
context 'installed is latest' do
context 'when installed is latest' do
before { stub_data(Discourse::VERSION::STRING, 1, false, 8.hours.ago) }
include_examples "queue version check and report that version is ok"
end
context 'installed does not match latest version, but missing_versions_count is 0' do
context 'when installed does not match latest version, but missing_versions_count is 0' do
before { stub_data('0.10.10.123', 0, false, 8.hours.ago) }
include_examples "queue version check and report that version is ok"
end
end
end
context 'version check was done at a different installed version' do
context 'when version check was done at a different installed version' do
before do
DiscourseUpdates.last_installed_version = '0.9.1'
end
@ -127,18 +127,18 @@ RSpec.describe DiscourseUpdates do
end
end
context 'missing_versions_count is 0' do
context 'when missing_versions_count is 0' do
before { stub_data('0.9.7', 0, false, 8.hours.ago) }
include_examples "when last_installed_version is old"
end
context 'missing_versions_count is not 0' do
context 'when missing_versions_count is not 0' do
before { stub_data('0.9.7', 1, false, 8.hours.ago) }
include_examples "when last_installed_version is old"
end
end
context 'new features' do
describe 'new features' do
fab!(:admin) { Fabricate(:admin) }
fab!(:admin2) { Fabricate(:admin) }
let!(:last_item_date) { 5.minutes.ago }

View File

@ -66,7 +66,7 @@ RSpec.describe DistributedMutex do
}.to raise_error(ThreadError)
end
context "readonly redis" do
describe "readonly redis" do
before do
Discourse.redis.slaveof "127.0.0.1", "65534"
end
@ -91,7 +91,7 @@ RSpec.describe DistributedMutex do
end
end
context "executions" do
describe "executions" do
it "should not allow critical sections to overlap" do
connections = 3.times.map { DiscourseRedis.new }

View File

@ -3,7 +3,6 @@
require 'email/message_builder'
RSpec.describe Email::MessageBuilder do
let(:to_address) { "jake@adventuretime.ooo" }
let(:subject) { "Tree Trunks has made some apple pie!" }
let(:body) { "oh my glob Jake, Tree Trunks just made the tastiest apple pie ever!" }
@ -32,8 +31,7 @@ RSpec.describe Email::MessageBuilder do
expect(header_args['X-Auto-Response-Suppress']).to eq("All")
end
context "reply by email" do
describe "reply by email" do
context "without allow_reply_by_email" do
it "does not have a X-Discourse-Reply-Key" do
expect(header_args['X-Discourse-Reply-Key']).to be_blank
@ -47,7 +45,7 @@ RSpec.describe Email::MessageBuilder do
context "with allow_reply_by_email" do
let(:reply_by_email_builder) { Email::MessageBuilder.new(to_address, allow_reply_by_email: true) }
context "With the SiteSetting enabled" do
context "with the SiteSetting enabled" do
before do
SiteSetting.stubs(:reply_by_email_enabled?).returns(true)
SiteSetting.stubs(:reply_by_email_address).returns("r+%{reply_key}@reply.myforum.com")
@ -72,7 +70,7 @@ RSpec.describe Email::MessageBuilder do
end
end
context "With the SiteSetting disabled" do
context "with the SiteSetting disabled" do
before do
SiteSetting.stubs(:reply_by_email_enabled?).returns(false)
end
@ -96,7 +94,7 @@ RSpec.describe Email::MessageBuilder do
)
end
context "With the SiteSetting enabled" do
context "with the SiteSetting enabled" do
before do
SiteSetting.stubs(:reply_by_email_enabled?).returns(true)
@ -113,7 +111,7 @@ RSpec.describe Email::MessageBuilder do
end
end
context "With the SiteSetting disabled" do
context "with the SiteSetting disabled" do
before do
SiteSetting.stubs(:reply_by_email_enabled?).returns(false)
end
@ -130,8 +128,7 @@ RSpec.describe Email::MessageBuilder do
end
context "custom headers" do
describe "custom headers" do
let(:custom_headers_string) { " Precedence : bulk | :: | No-colon | No-Value: | Multi-colon : : value : : | Auto-Submitted : auto-generated " }
let(:custom_headers_result) { { "Precedence" => "bulk", "Multi-colon" => ": value : :", "Auto-Submitted" => "auto-generated" } }
@ -149,8 +146,7 @@ RSpec.describe Email::MessageBuilder do
end
context "header args" do
describe "header args" do
let(:additional_opts) { {} }
let(:message_with_header_args) do
Email::MessageBuilder.new(
@ -209,8 +205,7 @@ RSpec.describe Email::MessageBuilder do
end
end
context "unsubscribe link" do
describe "unsubscribe link" do
context "with add_unsubscribe_link false" do
it "has no unsubscribe header by default" do
expect(builder.header_args['List-Unsubscribe']).to be_blank
@ -246,7 +241,7 @@ RSpec.describe Email::MessageBuilder do
end
context "template_args" do
describe "template_args" do
let(:template_args) { builder.template_args }
it "has site title as email_prefix when `SiteSetting.email_prefix` is not present" do
@ -267,7 +262,7 @@ RSpec.describe Email::MessageBuilder do
end
end
context "email prefix in subject" do
describe "email prefix in subject" do
context "when use_site_subject is true" do
let(:message_with_email_prefix) { Email::MessageBuilder.new(to_address,
body: 'hello world',
@ -280,8 +275,7 @@ RSpec.describe Email::MessageBuilder do
end
end
context "subject_template" do
describe "subject_template" do
let(:templated_builder) { Email::MessageBuilder.new(to_address, template: 'mystery') }
let(:rendered_template) { "rendered template" }
@ -319,11 +313,9 @@ RSpec.describe Email::MessageBuilder do
expect(templated_builder.subject).to match("customized subject")
end
end
end
context "from field" do
describe "from field" do
it "has the default from" do
SiteSetting.title = ""
expect(build_args[:from]).to eq(SiteSetting.notification_email)

View File

@ -69,7 +69,7 @@ RSpec.describe Email::Processor do
end
end
context "known error" do
describe "known error" do
let(:mail) { "From: #{from}\nTo: bar@foo.com" }
let(:mail2) { "From: #{from}\nTo: foo@foo.com" }
let(:mail3) { "From: #{from}\nTo: foobar@foo.com" }
@ -97,7 +97,7 @@ RSpec.describe Email::Processor do
end
end
context "unrecognized error" do
describe "unrecognized error" do
let(:mail) { "Date: Fri, 15 Jan 2016 00:12:43 +0100\nFrom: #{from}\nTo: bar@foo.com\nSubject: FOO BAR\n\nFoo foo bar bar?" }
let(:mail2) { "Date: Fri, 15 Jan 2016 00:12:43 +0100\nFrom: #{from}\nTo: foo@foo.com\nSubject: BAR BAR\n\nBar bar bar bar?" }
@ -140,7 +140,7 @@ RSpec.describe Email::Processor do
end
end
context "from reply to email address" do
describe "from reply to email address" do
let(:mail) { "Date: Fri, 15 Jan 2016 00:12:43 +0100\nFrom: reply@bar.com\nTo: reply@bar.com\nSubject: FOO BAR\n\nFoo foo bar bar?" }
it "ignores the email" do
@ -152,7 +152,7 @@ RSpec.describe Email::Processor do
end
end
context "mailinglist mirror" do
describe "mailinglist mirror" do
before do
SiteSetting.email_in = true
Fabricate(:mailinglist_mirror_category)

View File

@ -3,7 +3,6 @@
require "email/receiver"
RSpec.describe Email::Receiver do
before do
SiteSetting.email_in = true
SiteSetting.reply_by_email_address = "reply+%{reply_key}@bar.com"
@ -108,7 +107,7 @@ RSpec.describe Email::Receiver do
)
end
context "bounces" do
describe "bounces" do
it "raises a BouncerEmailError" do
expect { process(:bounced_email) }.to raise_error(Email::Receiver::BouncedEmailError)
expect(IncomingEmail.last.is_bounce).to eq(true)
@ -194,8 +193,7 @@ RSpec.describe Email::Receiver do
end.to raise_error(Email::Receiver::BadDestinationAddress)
end
context "bounces to VERP" do
describe "bounces to VERP" do
let(:bounce_key) { "14b08c855160d67f2e0c2f8ef36e251e" }
let(:bounce_key_2) { "b542fb5a9bacda6d28cc061d18e4eb83" }
fab!(:user) { Fabricate(:user, email: "linux-admin@b-s-c.co.jp") }
@ -244,8 +242,7 @@ RSpec.describe Email::Receiver do
end
end
context "reply" do
describe "reply" do
let(:reply_key) { "4f97315cc828096c9cb34c6f1a0d6fe8" }
fab!(:category) { Fabricate(:category) }
fab!(:user) { Fabricate(:user, email: "discourse@bar.com") }
@ -306,8 +303,7 @@ RSpec.describe Email::Receiver do
expect { process(:reply_user_matching) }.to raise_error(Email::Receiver::TopicNotFoundError)
end
context "a closed topic" do
context "with a closed topic" do
before do
topic.update_columns(closed: true)
end
@ -827,8 +823,7 @@ RSpec.describe Email::Receiver do
end
end
context "new message to a group" do
describe "new message to a group" do
fab!(:group) { Fabricate(:group, incoming_email: "team@bar.com|meat@bar.com") }
it "handles encoded display names" do
@ -1203,7 +1198,7 @@ RSpec.describe Email::Receiver do
end
end
context "emailing a group by email_username and following reply flow" do
context "when emailing a group by email_username and following reply flow" do
let!(:original_inbound_email_topic) do
group.update!(
email_username: "team@somesmtpaddress.com",
@ -1368,8 +1363,7 @@ RSpec.describe Email::Receiver do
end
end
context "new topic in a category" do
describe "new topic in a category" do
fab!(:category) { Fabricate(:category, email_in: "category@bar.com|category@foo.com", email_in_allow_strangers: false) }
it "raises a StrangersNotAllowedError when 'email_in_allow_strangers' is disabled" do
@ -1508,8 +1502,7 @@ RSpec.describe Email::Receiver do
end
end
context "new topic in a category that allows strangers" do
describe "new topic in a category that allows strangers" do
fab!(:category) { Fabricate(:category, email_in: "category@bar.com|category@foo.com", email_in_allow_strangers: true) }
it "lets an email in from a stranger" do
@ -1530,7 +1523,6 @@ RSpec.describe Email::Receiver do
end
describe "#reply_by_email_address_regex" do
before do
SiteSetting.reply_by_email_address = nil
SiteSetting.alternative_reply_by_email_addresses = nil
@ -1558,7 +1550,7 @@ RSpec.describe Email::Receiver do
end
context "check_address" do
describe "check_address" do
before do
SiteSetting.reply_by_email_address = "foo+%{reply_key}@bar.com"
end
@ -1581,7 +1573,7 @@ RSpec.describe Email::Receiver do
end
end
context "staged users" do
describe "staged users" do
before do
SiteSetting.enable_staged_users = true
end
@ -1652,7 +1644,7 @@ RSpec.describe Email::Receiver do
include_examples "does not create staged users", :blocklist_allowlist_email, Email::Receiver::EmailNotAllowed
end
context "blocklist and allowlist for To and Cc" do
context "with blocklist and allowlist for To and Cc" do
before do
Fabricate(:group, incoming_email: "some_group@bar.com")
end
@ -1714,7 +1706,7 @@ RSpec.describe Email::Receiver do
end
end
context "email is a reply" do
context "when email is a reply" do
let(:reply_key) { "4f97315cc828096c9cb34c6f1a0d6fe8" }
fab!(:category) { Fabricate(:category) }
fab!(:user) { Fabricate(:user, email: "discourse@bar.com") }
@ -1739,7 +1731,7 @@ RSpec.describe Email::Receiver do
include_examples "does not create staged users", :reply_and_forwarded
end
context "forwarded email to category that doesn't allow strangers" do
context "with forwarded email to category that doesn't allow strangers" do
before do
category.update!(email_in: "team@bar.com", email_in_allow_strangers: false)
end
@ -1749,7 +1741,7 @@ RSpec.describe Email::Receiver do
end
end
context "replying without key is allowed" do
context "when replying without key is allowed" do
fab!(:group) { Fabricate(:group, incoming_email: "team@bar.com") }
let!(:topic) do
SiteSetting.find_related_post_with_key = false
@ -1789,7 +1781,7 @@ RSpec.describe Email::Receiver do
end
end
context "mailing list mirror" do
describe "mailing list mirror" do
fab!(:category) { Fabricate(:mailinglist_mirror_category) }
before do
@ -1818,7 +1810,7 @@ RSpec.describe Email::Receiver do
expect { process(:mailinglist_short_message) }.to change { Topic.count }
end
context "read-only category" do
context "with read-only category" do
before do
category.set_permissions(everyone: :readonly)
category.save!
@ -1864,7 +1856,6 @@ RSpec.describe Email::Receiver do
end
describe "#select_body" do
let(:email) {
<<~EMAIL
MIME-Version: 1.0
@ -2028,8 +2019,7 @@ RSpec.describe Email::Receiver do
end
end
context "find_related_post" do
describe "find_related_post" do
let(:user) { Fabricate(:user) }
let(:group) { Fabricate(:group, users: [user]) }

View File

@ -15,11 +15,11 @@ RSpec.describe Email::Sender do
)
end
context "disable_emails is enabled" do
context "when disable_emails is enabled" do
fab!(:user) { Fabricate(:user) }
fab!(:moderator) { Fabricate(:moderator) }
context "disable_emails is enabled for everyone" do
context "when disable_emails is enabled for everyone" do
before { SiteSetting.disable_emails = "yes" }
it "doesn't deliver mail when mails are disabled" do
@ -44,7 +44,7 @@ RSpec.describe Email::Sender do
end
end
context "disable_emails is enabled for non-staff users" do
context "when disable_emails is enabled for non-staff users" do
before { SiteSetting.disable_emails = "non-staff" }
it "doesn't deliver mail to normal user" do
@ -106,7 +106,7 @@ RSpec.describe Email::Sender do
Email::Sender.new(message, :hello).send
end
context "host_for" do
describe ".host_for" do
it "defaults to localhost" do
expect(Email::Sender.host_for(nil)).to eq("localhost")
end
@ -126,7 +126,6 @@ RSpec.describe Email::Sender do
end
context 'with a valid message' do
let(:reply_key) { "abcd" * 8 }
let(:message) do
@ -145,7 +144,7 @@ RSpec.describe Email::Sender do
email_sender.send
end
context "doesn't add return_path when no plus addressing" do
context "when no plus addressing" do
before { SiteSetting.reply_by_email_address = '%{reply_key}@test.com' }
it 'should not set the return_path' do
@ -154,7 +153,7 @@ RSpec.describe Email::Sender do
end
end
context "adds return_path with plus addressing" do
context "with plus addressing" do
before { SiteSetting.reply_by_email_address = 'replies+%{reply_key}@test.com' }
it 'should set the return_path' do
@ -163,7 +162,7 @@ RSpec.describe Email::Sender do
end
end
context "adds a List-ID header to identify the forum" do
context "when topic id is present" do
fab!(:category) { Fabricate(:category, name: 'Name With Space') }
fab!(:topic) { Fabricate(:topic, category: category) }
fab!(:post) { Fabricate(:post, topic: topic) }
@ -181,8 +180,7 @@ RSpec.describe Email::Sender do
end
end
context "adds a Message-ID header even when topic id is not present" do
context "when topic id is not present" do
it 'should add the right header' do
email_sender.send
@ -190,7 +188,7 @@ RSpec.describe Email::Sender do
end
end
context "replaces reply_key in custom headers" do
context "when reply_key is present" do
fab!(:user) { Fabricate(:user) }
let(:email_sender) { Email::Sender.new(message, :valid_type, user) }
let(:reply_key) { PostReplyKey.find_by!(post_id: post.id, user_id: user.id).reply_key }
@ -227,7 +225,7 @@ RSpec.describe Email::Sender do
end
end
context "adds Precedence header" do
describe "adds Precedence header" do
fab!(:topic) { Fabricate(:topic) }
fab!(:post) { Fabricate(:post, topic: topic) }
@ -242,7 +240,7 @@ RSpec.describe Email::Sender do
end
end
context "removes custom Discourse headers from topic notification mails" do
describe "removes custom Discourse headers from topic notification mails" do
fab!(:topic) { Fabricate(:topic) }
fab!(:post) { Fabricate(:post, topic: topic) }
@ -259,7 +257,7 @@ RSpec.describe Email::Sender do
end
end
context "removes custom Discourse headers from digest/registration/other mails" do
describe "removes custom Discourse headers from digest/registration/other mails" do
it 'should remove the right headers' do
email_sender.send
expect(message.header['X-Discourse-Topic-Id']).not_to be_present
@ -268,7 +266,7 @@ RSpec.describe Email::Sender do
end
end
context "email threading" do
context "with email threading" do
let(:random_message_id_suffix) { "5f1330cfd941f323d7f99b9e" }
fab!(:topic) { Fabricate(:topic) }
@ -369,7 +367,7 @@ RSpec.describe Email::Sender do
end
context "merges custom mandrill header" do
describe "merges custom mandrill header" do
before do
ActionMailer::Base.smtp_settings[:address] = "smtp.mandrillapp.com"
message.header['X-MC-Metadata'] = { foo: "bar" }.to_json
@ -381,7 +379,7 @@ RSpec.describe Email::Sender do
end
end
context "merges custom sparkpost header" do
describe "merges custom sparkpost header" do
before do
ActionMailer::Base.smtp_settings[:address] = "smtp.sparkpostmail.com"
message.header['X-MSYS-API'] = { foo: "bar" }.to_json
@ -393,7 +391,7 @@ RSpec.describe Email::Sender do
end
end
context 'email logs' do
context 'with email logs' do
let(:email_log) { EmailLog.last }
it 'should create the right log' do
@ -457,7 +455,7 @@ RSpec.describe Email::Sender do
end
end
context "email log with a post id and topic id" do
context "with email log with a post id and topic id" do
let(:topic) { post.topic }
before do
@ -475,7 +473,7 @@ RSpec.describe Email::Sender do
end
end
context 'email parts' do
context 'with email parts' do
it 'should contain the right message' do
email_sender.send
@ -686,7 +684,6 @@ RSpec.describe Email::Sender do
end
context 'with a deleted post' do
it 'should skip sending the email' do
post = Fabricate(:post, deleted_at: 1.day.ago)
@ -705,7 +702,6 @@ RSpec.describe Email::Sender do
end
context 'with a deleted topic' do
it 'should skip sending the email' do
post = Fabricate(:post, topic: Fabricate(:topic, deleted_at: 1.day.ago))

View File

@ -18,7 +18,7 @@ RSpec.describe Email::Styles do
Nokogiri::HTML5.fragment(styler.to_html)
end
context "basic formatter" do
describe "basic formatter" do
it "adds a max-width to large images" do
frag = basic_fragment("<img height='auto' width='auto' src='gigantic.jpg'>")
expect(frag.at("img")["style"]).to match("max-width")
@ -48,7 +48,7 @@ RSpec.describe Email::Styles do
end
context "html template formatter" do
describe "html template formatter" do
it "attaches a style to h3 tags" do
frag = html_fragment("<h3>hello</h3>")
expect(frag.at('h3')['style']).to be_present
@ -106,7 +106,7 @@ RSpec.describe Email::Styles do
end
end
context "rewriting protocol relative URLs to the forum" do
describe "rewriting protocol relative URLs to the forum" do
it "doesn't rewrite a url to another site" do
frag = html_fragment('<a href="//youtube.com/discourse">hello</a>')
expect(frag.at('a')['href']).to eq("//youtube.com/discourse")
@ -156,7 +156,7 @@ RSpec.describe Email::Styles do
end
context "dark mode emails" do
describe "dark mode emails" do
it "adds dark_mode_styles when site setting active" do
frag = html_fragment('<div class="body">test</div>')
styler = Email::Styles.new(frag)
@ -169,7 +169,7 @@ RSpec.describe Email::Styles do
end
end
context "strip_avatars_and_emojis" do
describe "strip_avatars_and_emojis" do
it "works for lonesome emoji with no title" do
emoji = "<img src='/images/emoji/twitter/crying_cat_face.png'>"
style = Email::Styles.new(emoji)
@ -192,7 +192,7 @@ RSpec.describe Email::Styles do
end
end
context "onebox_styles" do
describe "onebox_styles" do
it "renders quote as <blockquote>" do
fragment = html_fragment('<aside class="quote"> <div class="title"> <div class="quote-controls"> <i class="fa fa-chevron-down" title="expand/collapse"></i><a href="/t/xyz/123" title="go to the quoted post" class="back"></a> </div> <img alt="" width="20" height="20" src="https://cdn-enterprise.discourse.org/boingboing/user_avatar/bbs.boingboing.net/techapj/40/54379_1.png" class="avatar">techAPJ: </div> <blockquote> <p>lorem ipsum</p> </blockquote> </aside>')
expect(fragment.to_s.squish).to match(/^<blockquote.+<\/blockquote>$/)
@ -208,7 +208,7 @@ RSpec.describe Email::Styles do
end
end
context "replace_secure_media_urls" do
describe "replace_secure_media_urls" do
before do
setup_s3
SiteSetting.secure_media = true
@ -258,7 +258,7 @@ RSpec.describe Email::Styles do
end
context "inline_secure_images" do
describe "inline_secure_images" do
before do
setup_s3
SiteSetting.secure_media = true

View File

@ -126,7 +126,7 @@ RSpec.describe EmailUpdater do
let(:user) { Fabricate(:user, email: old_email) }
let(:updater) { EmailUpdater.new(guardian: user.guardian, user: user) }
context "changing primary email" do
context "when changing primary email" do
before do
expect_enqueued_with(job: :critical_user_email, args: { type: :confirm_new_email, to_address: new_email }) do
updater.change_to(new_email)
@ -145,7 +145,7 @@ RSpec.describe EmailUpdater do
expect(updater.change_req.new_email_token.email).to eq(new_email)
end
context 'confirming an invalid token' do
context 'when confirming an invalid token' do
it "produces an error" do
updater.confirm('random')
expect(updater.errors).to be_present
@ -153,7 +153,7 @@ RSpec.describe EmailUpdater do
end
end
context 'confirming a valid token' do
context 'when confirming a valid token' do
it "updates the user's email" do
event = DiscourseEvent.track_events {
expect_enqueued_with(job: :critical_user_email, args: { type: :notify_old_email, to_address: old_email }) do
@ -173,14 +173,14 @@ RSpec.describe EmailUpdater do
end
end
context "adding an email" do
context "when adding an email" do
before do
expect_enqueued_with(job: :critical_user_email, args: { type: :confirm_new_email, to_address: new_email }) do
updater.change_to(new_email, add: true)
end
end
context 'confirming a valid token' do
context 'when confirming a valid token' do
it "adds a user email" do
expect(UserHistory.where(action: UserHistory.actions[:add_email], acting_user_id: user.id).last).to be_present
@ -201,7 +201,7 @@ RSpec.describe EmailUpdater do
end
end
context 'that was deleted before' do
context 'when it was deleted before' do
it 'works' do
expect_enqueued_with(job: :critical_user_email, args: { type: :notify_old_email_add, to_address: old_email }) do
updater.confirm(updater.change_req.new_email_token.token)
@ -225,7 +225,7 @@ RSpec.describe EmailUpdater do
end
end
context "max_allowed_secondary_emails" do
context "with max_allowed_secondary_emails" do
let(:secondary_email_1) { "secondary_1@email.com" }
let(:secondary_email_2) { "secondary_2@email.com" }
@ -265,7 +265,7 @@ RSpec.describe EmailUpdater do
expect(updater.change_req.new_email_token).to be_blank
end
context 'confirming an invalid token' do
context 'when confirming an invalid token' do
it "produces an error" do
updater.confirm('random')
expect(updater.errors).to be_present
@ -273,7 +273,7 @@ RSpec.describe EmailUpdater do
end
end
context 'confirming a valid token' do
context 'when confirming a valid token' do
before do
expect_enqueued_with(job: :critical_user_email, args: { type: :confirm_new_email, to_address: new_email }) do
@old_token = updater.change_req.old_email_token.token
@ -299,7 +299,7 @@ RSpec.describe EmailUpdater do
expect(updater.change_req.new_email_token.email).to eq(new_email)
end
context "completing the new update process" do
context "when completing the new update process" do
before do
expect_not_enqueued_with(job: :critical_user_email, args: { type: :notify_old_email, to_address: old_email }) do
updater.confirm(updater.change_req.new_email_token.token)
@ -317,7 +317,7 @@ RSpec.describe EmailUpdater do
end
end
context 'hide_email_address_taken is enabled' do
context 'when hide_email_address_taken is enabled' do
before do
SiteSetting.hide_email_address_taken = true
end

View File

@ -6,7 +6,7 @@ RSpec.describe Encodings do
Encodings.to_utf8(string)
end
context "unicode" do
describe "unicode" do
let(:expected) { 'Το σύστημα γραφής είναι ένα συμβολικό, οπτικό σύστημα καταγραφής της γλώσσας.' }
it "correctly encodes UTF-8 as UTF-8" do

View File

@ -44,7 +44,7 @@ RSpec.describe Enum do
end
end
context "allows to specify number of first enum member" do
describe "allows to specify number of first enum member" do
it "number of first enum member should be 0 " do
start_enum = Enum.new(:jake, :finn, :princess_bubblegum, :peppermint_butler, start: 0)
expect(start_enum[:princess_bubblegum]).to eq(2)

View File

@ -8,7 +8,7 @@ RSpec.describe FileStore::BaseStore do
expect(described_class.new.get_path_for_upload(upload)).to eq(expected_path)
end
context "empty URL" do
context "with empty URL" do
before do
upload.update!(url: "")
end
@ -32,8 +32,8 @@ RSpec.describe FileStore::BaseStore do
end
end
context "existing URL" do
context "regular site" do
context "with existing URL" do
context "with regular site" do
it "returns the correct path for files stored on local storage" do
upload.update!(url: "/uploads/default/original/1X/63b76551662ccea1a594e161c37dd35188d77657.jpeg")
expect_correct_path("original/1X/63b76551662ccea1a594e161c37dd35188d77657.jpeg")
@ -51,7 +51,7 @@ RSpec.describe FileStore::BaseStore do
end
end
context "multisite" do
context "with multisite" do
it "returns the correct path for files stored on local storage" do
upload.update!(url: "/uploads/foo/original/1X/63b76551662ccea1a594e161c37dd35188d77657.jpeg")
expect_correct_path("original/1X/63b76551662ccea1a594e161c37dd35188d77657.jpeg")
@ -83,7 +83,7 @@ RSpec.describe FileStore::BaseStore do
let!(:upload) { Fabricate.build(:upload, id: 100) }
let!(:optimized_path) { "optimized/1X/#{upload.sha1}_1_100x200.png" }
context "empty URL" do
context "with empty URL" do
it 'should return the right path' do
optimized = Fabricate.build(:optimized_image, upload: upload, version: 1)
expect(FileStore::BaseStore.new.get_path_for_optimized_image(optimized)).to eq(optimized_path)
@ -95,7 +95,7 @@ RSpec.describe FileStore::BaseStore do
end
end
context "existing URL" do
context "with existing URL" do
let!(:optimized) { Fabricate.build(:optimized_image, upload: upload, version: 1) }
let!(:optimized_path) { "optimized/1X/#{upload.sha1}_1_100x200.jpg" }
@ -103,7 +103,7 @@ RSpec.describe FileStore::BaseStore do
expect(described_class.new.get_path_for_optimized_image(optimized)).to eq(optimized_path)
end
context "regular site" do
context "with regular site" do
it "returns the correct path for files stored on local storage" do
optimized.update!(url: "/uploads/default/optimized/1X/#{upload.sha1}_1_100x200.jpg")
expect_correct_optimized_path
@ -115,7 +115,7 @@ RSpec.describe FileStore::BaseStore do
end
end
context "multisite" do
context "with multisite" do
it "returns the correct path for files stored on local storage" do
optimized.update!(url: "/uploads/foo/optimized/1X/#{upload.sha1}_1_100x200.jpg")
expect_correct_optimized_path

View File

@ -24,7 +24,7 @@ RSpec.describe FileStore::S3Store do
SiteSetting.s3_region = 'us-west-1'
end
context 'uploading to s3' do
describe 'uploading to s3' do
let(:etag) { "etag" }
describe "#store_upload" do
@ -189,7 +189,7 @@ RSpec.describe FileStore::S3Store do
end
end
context 'copying files in S3' do
describe 'copying files in S3' do
describe '#copy_file' do
it "copies the from in S3 with the right paths" do
upload.update!(
@ -211,7 +211,7 @@ RSpec.describe FileStore::S3Store do
end
end
context 'removal from s3' do
describe 'removal from s3' do
describe "#remove_upload" do
it "removes the file from s3 with the right paths" do
upload_key = Discourse.store.get_path_for_upload(upload)
@ -380,7 +380,7 @@ RSpec.describe FileStore::S3Store do
end
end
context 'update ACL' do
describe 'update ACL' do
before do
SiteSetting.authorized_extensions = "pdf|png"
end

View File

@ -3,7 +3,6 @@
require 'final_destination'
RSpec.describe FinalDestination do
let(:opts) do
{
ignore_redirects: ['https://ignore-me.com'],
@ -82,7 +81,6 @@ RSpec.describe FinalDestination do
end
describe '.resolve' do
it "has a ready status code before anything happens" do
expect(fd('https://eviltrout.com').status).to eq(:ready)
end
@ -118,7 +116,7 @@ RSpec.describe FinalDestination do
expect(final.status).to eq(:resolved)
end
context "underscores in URLs" do
context "with underscores in URLs" do
before do
stub_request(:head, 'https://some_thing.example.com').to_return(doc_response)
end
@ -202,7 +200,7 @@ RSpec.describe FinalDestination do
expect { final.resolve }.to raise_error(Excon::Errors::ExpectationFailed, "connect timeout reached: https://codinghorror.com/blog")
end
context 'follows canonical links' do
context 'when following canonical links' do
it 'resolves the canonical link as the final destination' do
canonical_follow("https://eviltrout.com", "https://codinghorror.com/blog")
stub_request(:head, "https://codinghorror.com/blog").to_return(doc_response)
@ -260,7 +258,7 @@ RSpec.describe FinalDestination do
end
end
context "GET can be forced" do
context "when forcing GET" do
before do
stub_request(:head, 'https://force.get.com/posts?page=4')
stub_request(:get, 'https://force.get.com/posts?page=4')
@ -305,7 +303,7 @@ RSpec.describe FinalDestination do
end
context "HEAD not supported" do
context "when HEAD not supported" do
before do
stub_request(:get, 'https://eviltrout.com').to_return(
status: 301,
@ -410,7 +408,7 @@ RSpec.describe FinalDestination do
expect(final.status).to eq(:resolved)
end
context "content_type" do
context "with content_type" do
before do
stub_request(:head, "https://eviltrout.com/this/is/an/image").to_return(image_response)
end
@ -475,7 +473,7 @@ RSpec.describe FinalDestination do
end
describe '.validate_uri' do
context "host lookups" do
context "with host lookups" do
it "works for various hosts" do
expect(fd('https://private-host.com').validate_uri).to eq(false)
expect(fd('https://eviltrout.com:443').validate_uri).to eq(true)
@ -626,5 +624,4 @@ RSpec.describe FinalDestination do
.to eq('https://ru.wikipedia.org/wiki/%D0%A1%D0%B2%D0%BE%D0%B1%D0%BE')
end
end
end

View File

@ -76,7 +76,7 @@ RSpec.describe "translate accelerator" do
end
end
context "plugins" do
describe "plugins" do
before do
DiscoursePluginRegistry.register_locale(
'foo',
@ -236,7 +236,7 @@ RSpec.describe "translate accelerator" do
end
end
context "translation precedence" do
describe "translation precedence" do
def translation_should_equal(key, expected_value)
I18n.locale = :en
expect(I18n.t(key, locale: :de)).to eq(expected_value)

View File

@ -3,7 +3,6 @@
require 'cache'
RSpec.describe Gaps do
it 'returns no gaps for empty data' do
expect(Gaps.new(nil, nil)).to be_blank
end
@ -16,7 +15,7 @@ RSpec.describe Gaps do
expect(Gaps.new([1, 2, 3], [1, 2, 3])).to be_blank
end
context "single element gap" do
describe "single element gap" do
let(:gap) { Gaps.new([1, 3], [1, 2, 3]) }
it 'has a gap for post 3' do
@ -26,7 +25,7 @@ RSpec.describe Gaps do
end
end
context "larger gap" do
describe "larger gap" do
let(:gap) { Gaps.new([1, 2, 3, 6, 7], [1, 2, 3, 4, 5, 6, 7]) }
it 'has a gap for post 6' do
@ -36,7 +35,7 @@ RSpec.describe Gaps do
end
end
context "multiple gaps" do
describe "multiple gaps" do
let(:gap) { Gaps.new([1, 5, 6, 7, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) }
it 'has both gaps' do
@ -47,7 +46,7 @@ RSpec.describe Gaps do
end
end
context "a gap in the beginning" do
describe "a gap in the beginning" do
let(:gap) { Gaps.new([2, 3, 4], [1, 2, 3, 4]) }
it 'has the gap' do
@ -57,7 +56,7 @@ RSpec.describe Gaps do
end
end
context "a gap in the ending" do
describe "a gap in the ending" do
let(:gap) { Gaps.new([1, 2, 3], [1, 2, 3, 4]) }
it 'has the gap' do
@ -67,7 +66,7 @@ RSpec.describe Gaps do
end
end
context "a large gap in the ending" do
describe "a large gap in the ending" do
let(:gap) { Gaps.new([1, 2, 3], [1, 2, 3, 4, 5, 6]) }
it 'has the gap' do
@ -76,5 +75,4 @@ RSpec.describe Gaps do
expect(gap.after[3]).to eq([4, 5, 6])
end
end
end

View File

@ -7,8 +7,7 @@ class GlobalPathInstance
end
RSpec.describe GlobalPath do
context 'cdn_relative_path' do
describe '.cdn_relative_path' do
def cdn_relative_path(p)
GlobalPathInstance.cdn_relative_path(p)
end
@ -28,7 +27,7 @@ RSpec.describe GlobalPath do
end
end
describe '#upload_cdn_path' do
describe '.upload_cdn_path' do
it 'generates correctly when S3 bucket has a folder' do
global_setting :s3_access_key_id, 's3_access_key_id'
global_setting :s3_secret_access_key, 's3_secret_access_key'

View File

@ -45,7 +45,7 @@ RSpec.describe UserGuardian do
Guardian.new(user)
end
context 'anon user' do
context 'with anon user' do
let(:guardian) { Guardian.new }
it "should return the right value" do
@ -53,7 +53,7 @@ RSpec.describe UserGuardian do
end
end
context 'current user' do
context 'with current user' do
it "can not set uploads not owned by current user" do
expect(guardian.can_pick_avatar?(user_avatar, users_upload)).to eq(true)
expect(guardian.can_pick_avatar?(user_avatar, already_uploaded)).to eq(true)
@ -78,8 +78,7 @@ RSpec.describe UserGuardian do
end
end
context 'moderator' do
context 'with moderator' do
let :guardian do
Guardian.new(moderator)
end
@ -93,7 +92,7 @@ RSpec.describe UserGuardian do
end
end
context 'admin' do
context 'with admin' do
let :guardian do
Guardian.new(admin)
end
@ -106,7 +105,6 @@ RSpec.describe UserGuardian do
end
describe "#can_see_profile?" do
it "is false for no user" do
expect(Guardian.new.can_see_profile?(nil)).to eq(false)
end
@ -115,7 +113,7 @@ RSpec.describe UserGuardian do
expect(Guardian.new.can_see_profile?(user)).to eq(true)
end
context "hidden profile" do
context "with hidden profile" do
# Mixing Fabricate.build() and Fabricate() could cause ID clashes, so override :user
fab!(:user) { Fabricate(:user) }
@ -229,7 +227,7 @@ RSpec.describe UserGuardian do
end
end
context "delete myself" do
context "when deleting myself" do
let(:guardian) { Guardian.new(user) }
include_examples "can_delete_user examples"
@ -469,7 +467,7 @@ RSpec.describe UserGuardian do
expect(Guardian.new(admin_user).can_change_tracking_preferences?(admin_user)).to eq(true)
end
context "allow_changing_staged_user_tracking is false" do
context "when allow_changing_staged_user_tracking is false" do
before { SiteSetting.allow_changing_staged_user_tracking = false }
it "is false to staged user" do
@ -481,7 +479,7 @@ RSpec.describe UserGuardian do
end
end
context "allow_changing_staged_user_tracking is true" do
context "when allow_changing_staged_user_tracking is true" do
before { SiteSetting.allow_changing_staged_user_tracking = true }
it "is true to staged user" do

View File

@ -1,7 +1,6 @@
# frozen_string_literal: true
RSpec.describe Guardian do
fab!(:user) { Fabricate(:user) }
fab!(:another_user) { Fabricate(:user) }
fab!(:member) { Fabricate(:user) }
@ -283,7 +282,7 @@ RSpec.describe Guardian do
expect(Guardian.new(user).can_send_private_message?(another_user)).to be_falsey
end
context "enable_personal_messages is false" do
context "when enable_personal_messages is false" do
before { SiteSetting.enable_personal_messages = false }
it "returns false if user is not staff member" do
@ -296,7 +295,7 @@ RSpec.describe Guardian do
end
end
context "target user is suspended" do
context "when target user is suspended" do
it "returns true for staff" do
expect(Guardian.new(admin).can_send_private_message?(suspended_user)).to be_truthy
expect(Guardian.new(moderator).can_send_private_message?(suspended_user)).to be_truthy
@ -307,7 +306,7 @@ RSpec.describe Guardian do
end
end
context "author is silenced" do
context "when author is silenced" do
before do
user.silenced_till = 1.year.from_now
user.save
@ -375,7 +374,7 @@ RSpec.describe Guardian do
expect(Guardian.new(user).can_send_private_message?(group)).to eq(true)
end
context 'target user has private message disabled' do
context 'when target user has private message disabled' do
before do
another_user.user_option.update!(allow_private_messages: false)
end
@ -928,7 +927,7 @@ RSpec.describe Guardian do
describe 'a PostRevision' do
fab!(:post_revision) { Fabricate(:post_revision) }
context 'edit_history_visible_to_public is true' do
context 'when edit_history_visible_to_public is true' do
before { SiteSetting.edit_history_visible_to_public = true }
it 'is false for nil' do
@ -944,7 +943,7 @@ RSpec.describe Guardian do
end
end
context 'edit_history_visible_to_public is false' do
context 'when edit_history_visible_to_public is false' do
before { SiteSetting.edit_history_visible_to_public = false }
it 'is true for staff' do
@ -1040,7 +1039,7 @@ RSpec.describe Guardian do
expect(Guardian.new(topic.user).can_create?(Post, topic)).to be_falsey
end
context 'closed topic' do
context 'with closed topic' do
before do
topic.closed = true
end
@ -1066,12 +1065,12 @@ RSpec.describe Guardian do
end
end
context 'archived topic' do
context 'with archived topic' do
before do
topic.archived = true
end
context 'regular users' do
context 'with regular users' do
it "doesn't allow new posts from regular users" do
expect(Guardian.new(coding_horror).can_create?(Post, topic)).to be_falsey
end
@ -1090,7 +1089,7 @@ RSpec.describe Guardian do
end
end
context "trashed topic" do
context "with trashed topic" do
before do
topic.deleted_at = Time.now
end
@ -1108,7 +1107,7 @@ RSpec.describe Guardian do
end
end
context "system message" do
context "with system message" do
fab!(:private_message) {
Fabricate(
:topic,
@ -1127,7 +1126,7 @@ RSpec.describe Guardian do
end
context "private message" do
context "with private message" do
fab!(:private_message) { Fabricate(:topic, archetype: Archetype.private_message, category_id: nil) }
before { user.save! }
@ -1220,7 +1219,7 @@ RSpec.describe Guardian do
end
end
context 'category group moderation is enabled' do
context 'when category group moderation is enabled' do
fab!(:group_user) { Fabricate(:group_user) }
before do
@ -1281,7 +1280,7 @@ RSpec.describe Guardian do
end
context 'can_convert_topic?' do
describe '#can_convert_topic?' do
it 'returns false with a nil object' do
expect(Guardian.new(user).can_convert_topic?(nil)).to be_falsey
end
@ -1480,7 +1479,7 @@ RSpec.describe Guardian do
expect(Guardian.new(post.user).can_edit?(post)).to be_truthy
end
context "shared drafts" do
context "with shared drafts" do
fab!(:category) { Fabricate(:category) }
let(:topic) { Fabricate(:topic, category: category) }
@ -1507,7 +1506,7 @@ RSpec.describe Guardian do
end
end
context 'category group moderation is enabled' do
context 'when category group moderation is enabled' do
fab!(:cat_mod_user) { Fabricate(:user) }
before do
@ -1527,7 +1526,7 @@ RSpec.describe Guardian do
describe 'post edit time limits' do
context 'post is older than post_edit_time_limit' do
context 'when post is older than post_edit_time_limit' do
let(:topic) { Fabricate(:topic) }
let(:old_post) { Fabricate(:post, topic: topic, user: topic.user, created_at: 6.minutes.ago) }
@ -1557,7 +1556,7 @@ RSpec.describe Guardian do
expect(Guardian.new(coding_horror).can_edit?(old_post)).to be_truthy
end
context "unlimited owner edits on first post" do
context "when unlimited owner edits on first post" do
let(:owner) { old_post.user }
it "returns true when the post topic's category allow_unlimited_owner_edits_on_first_post" do
@ -1583,7 +1582,7 @@ RSpec.describe Guardian do
end
end
context 'post is older than tl2_post_edit_time_limit' do
context 'when post is older than tl2_post_edit_time_limit' do
let(:old_post) { build(:post, topic: topic, user: topic.user, created_at: 12.minutes.ago) }
before do
@ -1614,7 +1613,7 @@ RSpec.describe Guardian do
end
end
context "first post of a static page doc" do
context "with first post of a static page doc" do
let!(:tos_topic) { Fabricate(:topic, user: Discourse.system_user) }
let!(:tos_first_post) { build(:post, topic: tos_topic, user: tos_topic.user) }
before { SiteSetting.tos_topic_id = tos_topic.id }
@ -1641,7 +1640,7 @@ RSpec.describe Guardian do
expect(Guardian.new(coding_horror).can_edit?(topic)).to be_falsey
end
context 'first post is hidden' do
context 'when first post is hidden' do
let!(:topic) { Fabricate(:topic, user: user) }
let!(:post) { Fabricate(:post, topic: topic, user: topic.user, hidden: true, hidden_at: Time.zone.now) }
@ -1652,7 +1651,7 @@ RSpec.describe Guardian do
end
end
context "locked" do
context "when locked" do
let(:post) { Fabricate(:post, locked_by_id: admin.id) }
let(:topic) { post.topic }
@ -1662,7 +1661,7 @@ RSpec.describe Guardian do
end
end
context 'not archived' do
context 'when not archived' do
it 'returns true as a moderator' do
expect(Guardian.new(moderator).can_edit?(topic)).to eq(true)
end
@ -1702,7 +1701,7 @@ RSpec.describe Guardian do
end
end
context 'private message' do
context 'with private message' do
it 'returns false at trust level 3' do
topic.archetype = 'private_message'
expect(Guardian.new(trust_level_3).can_edit?(topic)).to eq(false)
@ -1714,7 +1713,7 @@ RSpec.describe Guardian do
end
end
context 'archived' do
context 'when archived' do
let(:archived_topic) { build(:topic, user: user, archived: true) }
it 'returns true as a moderator' do
@ -1743,7 +1742,7 @@ RSpec.describe Guardian do
end
end
context 'very old' do
context 'when very old' do
let(:old_topic) { build(:topic, user: user, created_at: 6.minutes.ago) }
before { SiteSetting.post_edit_time_limit = 5 }
@ -1809,8 +1808,7 @@ RSpec.describe Guardian do
end
context 'can_moderate?' do
describe '#can_moderate?' do
it 'returns false with a nil object' do
expect(Guardian.new(user).can_moderate?(nil)).to be_falsey
end
@ -1823,8 +1821,7 @@ RSpec.describe Guardian do
end
end
context 'a Topic' do
context 'with a Topic' do
it 'returns false when not logged in' do
expect(Guardian.new.can_moderate?(topic)).to be_falsey
end
@ -1844,13 +1841,10 @@ RSpec.describe Guardian do
it 'returns true when trust level 4' do
expect(Guardian.new(trust_level_4).can_moderate?(topic)).to be_truthy
end
end
end
context 'can_see_flags?' do
describe '#can_see_flags?' do
it "returns false when there is no post" do
expect(Guardian.new(moderator).can_see_flags?(nil)).to be_falsey
end
@ -1872,7 +1866,7 @@ RSpec.describe Guardian do
end
end
context "can_review_topic?" do
describe "#can_review_topic?" do
it 'returns false with a nil object' do
expect(Guardian.new(user).can_review_topic?(nil)).to eq(false)
end
@ -1893,7 +1887,7 @@ RSpec.describe Guardian do
end
end
context "can_close_topic?" do
describe "#can_close_topic?" do
it 'returns false with a nil object' do
expect(Guardian.new(user).can_close_topic?(nil)).to eq(false)
end
@ -1914,7 +1908,7 @@ RSpec.describe Guardian do
end
end
context "can_archive_topic?" do
describe "#can_archive_topic?" do
it 'returns false with a nil object' do
expect(Guardian.new(user).can_archive_topic?(nil)).to eq(false)
end
@ -1935,7 +1929,7 @@ RSpec.describe Guardian do
end
end
context "can_edit_staff_notes?" do
describe "#can_edit_staff_notes?" do
it 'returns false with a nil object' do
expect(Guardian.new(user).can_edit_staff_notes?(nil)).to eq(false)
end
@ -1956,7 +1950,7 @@ RSpec.describe Guardian do
end
end
context "can_create_topic?" do
describe "#can_create_topic?" do
it 'returns true for staff user' do
expect(Guardian.new(moderator).can_create_topic?(topic)).to eq(true)
end
@ -1990,14 +1984,12 @@ RSpec.describe Guardian do
end
end
context 'can_move_posts?' do
describe '#can_move_posts?' do
it 'returns false with a nil object' do
expect(Guardian.new(user).can_move_posts?(nil)).to be_falsey
end
context 'a Topic' do
context 'with a Topic' do
it 'returns false when not logged in' do
expect(Guardian.new.can_move_posts?(topic)).to be_falsey
end
@ -2013,18 +2005,15 @@ RSpec.describe Guardian do
it 'returns true when an admin' do
expect(Guardian.new(admin).can_move_posts?(topic)).to be_truthy
end
end
end
context 'can_delete?' do
describe '#can_delete?' do
it 'returns false with a nil object' do
expect(Guardian.new(user).can_delete?(nil)).to be_falsey
end
context 'a Topic' do
context 'with a Topic' do
before do
# pretend we have a real topic
topic.id = 9999999
@ -2068,7 +2057,7 @@ RSpec.describe Guardian do
expect(Guardian.new(topic.user).can_delete?(topic)).to be_falsey
end
context 'category group moderation is enabled' do
context 'when category group moderation is enabled' do
fab!(:group_user) { Fabricate(:group_user) }
before do
@ -2085,11 +2074,9 @@ RSpec.describe Guardian do
expect(Guardian.new(group_user.user).can_delete?(topic)).to be_truthy
end
end
end
context 'a Post' do
context 'with a Post' do
before do
post.post_number = 2
end
@ -2155,7 +2142,7 @@ RSpec.describe Guardian do
expect(Guardian.new(admin).can_delete?(post)).to be_falsey
end
context 'the topic is archived' do
context 'when the topic is archived' do
before do
post.topic.archived = true
end
@ -2168,11 +2155,9 @@ RSpec.describe Guardian do
expect(Guardian.new(post.user).can_delete?(post)).to be_falsey
end
end
end
context 'a Category' do
context 'with a Category' do
let(:category) { build(:category, user: moderator) }
it 'returns false when not logged in' do
@ -2206,10 +2191,9 @@ RSpec.describe Guardian do
category.expects(:has_children?).returns(true)
expect(Guardian.new(admin).can_delete?(category)).to be_falsey
end
end
context 'can_suspend?' do
describe '#can_suspend?' do
it 'returns false when a user tries to suspend another user' do
expect(Guardian.new(user).can_suspend?(coding_horror)).to be_falsey
end
@ -2227,7 +2211,7 @@ RSpec.describe Guardian do
end
end
context 'a PostAction' do
context 'with a PostAction' do
let(:post_action) {
user.id = 1
post.id = 1
@ -2254,13 +2238,10 @@ RSpec.describe Guardian do
it "returns true if it's yours" do
expect(Guardian.new(user).can_delete?(post_action)).to be_truthy
end
end
end
context 'can_approve?' do
describe '#can_approve?' do
it "wont allow a non-logged in user to approve" do
expect(Guardian.new.can_approve?(user)).to be_falsey
end
@ -2286,10 +2267,9 @@ RSpec.describe Guardian do
it "allows a moderator to approve a user" do
expect(Guardian.new(moderator).can_approve?(user)).to be_truthy
end
end
context 'can_grant_admin?' do
describe '#can_grant_admin?' do
it "wont allow a non logged in user to grant an admin's access" do
expect(Guardian.new.can_grant_admin?(another_admin)).to be_falsey
end
@ -2318,7 +2298,7 @@ RSpec.describe Guardian do
end
end
context 'can_revoke_admin?' do
describe '#can_revoke_admin?' do
it "wont allow a non logged in user to revoke an admin's access" do
expect(Guardian.new.can_revoke_admin?(another_admin)).to be_falsey
end
@ -2343,8 +2323,7 @@ RSpec.describe Guardian do
end
end
context 'can_grant_moderation?' do
describe '#can_grant_moderation?' do
it "wont allow a non logged in user to grant an moderator's access" do
expect(Guardian.new.can_grant_moderation?(user)).to be_falsey
end
@ -2375,7 +2354,7 @@ RSpec.describe Guardian do
end
end
context 'can_revoke_moderation?' do
describe '#can_revoke_moderation?' do
it "wont allow a non logged in user to revoke an moderator's access" do
expect(Guardian.new.can_revoke_moderation?(moderator)).to be_falsey
end
@ -2406,8 +2385,7 @@ RSpec.describe Guardian do
end
end
context "can_see_invite_details?" do
describe "#can_see_invite_details?" do
it 'is false without a logged in user' do
expect(Guardian.new(nil).can_see_invite_details?(user)).to be_falsey
end
@ -2421,8 +2399,7 @@ RSpec.describe Guardian do
end
end
context "can_access_forum?" do
describe "#can_access_forum?" do
let(:unapproved_user) { Fabricate.build(:user) }
context "when must_approve_users is false" do
@ -2461,12 +2438,10 @@ RSpec.describe Guardian do
unapproved_user.approved = true
expect(Guardian.new(unapproved_user).can_access_forum?).to be_truthy
end
end
end
describe "can_delete_all_posts?" do
describe "#can_delete_all_posts?" do
it "is false without a logged in user" do
expect(Guardian.new(nil).can_delete_all_posts?(user)).to be_falsey
end
@ -3176,7 +3151,7 @@ RSpec.describe Guardian do
let!(:theme) { Fabricate(:theme) }
let!(:theme2) { Fabricate(:theme) }
context "allowlist mode" do
context "when in allowlist mode" do
before do
global_setting :allowed_theme_repos, " https://magic.com/repo.git, https://x.com/git"
end
@ -3267,7 +3242,7 @@ RSpec.describe Guardian do
expect(Guardian.new(trust_level_4).can_wiki?(post)).to be_truthy
end
context 'post is older than post_edit_time_limit' do
context 'when post is older than post_edit_time_limit' do
let(:old_post) { build(:post, user: trust_level_2, created_at: 6.minutes.ago) }
before do
SiteSetting.min_trust_to_allow_self_wiki = 2
@ -3289,7 +3264,7 @@ RSpec.describe Guardian do
end
describe "Tags" do
context "tagging disabled" do
context "with tagging disabled" do
before do
SiteSetting.tagging_enabled = false
end
@ -3307,13 +3282,13 @@ RSpec.describe Guardian do
end
end
context "tagging is enabled" do
context "when tagging is enabled" do
before do
SiteSetting.tagging_enabled = true
SiteSetting.min_trust_level_to_tag_topics = 1
end
context 'min_trust_to_create_tag is 3' do
context 'when min_trust_to_create_tag is 3' do
before do
SiteSetting.min_trust_to_create_tag = 3
end
@ -3349,7 +3324,7 @@ RSpec.describe Guardian do
end
end
context 'min_trust_to_create_tag is "staff"' do
context 'when min_trust_to_create_tag is "staff"' do
before do
SiteSetting.min_trust_to_create_tag = 'staff'
end
@ -3364,7 +3339,7 @@ RSpec.describe Guardian do
end
end
context 'min_trust_to_create_tag is "admin"' do
context 'when min_trust_to_create_tag is "admin"' do
before do
SiteSetting.min_trust_to_create_tag = 'admin'
end
@ -3380,7 +3355,7 @@ RSpec.describe Guardian do
end
end
context "tagging PMs" do
context "when tagging PMs" do
it "pm_tags_allowed_for_groups contains everyone" do
SiteSetting.pm_tags_allowed_for_groups = "#{Group::AUTO_GROUPS[:everyone]}"
@ -3397,7 +3372,7 @@ RSpec.describe Guardian do
end
end
describe(:can_see_group) do
describe "#can_see_group?" do
it 'Correctly handles owner visible groups' do
group = Group.new(name: 'group', visibility_level: Group.visibility_levels[:owners])
@ -3470,10 +3445,9 @@ RSpec.describe Guardian do
expect(Guardian.new.can_see_group?(group)).to eq(true)
end
end
describe(:can_see_group_members) do
describe "#can_see_group_members?" do
it 'Correctly handles group members visibility for owner' do
group = Group.new(name: 'group', members_visibility_level: Group.visibility_levels[:owners])
@ -3669,12 +3643,12 @@ RSpec.describe Guardian do
end
end
context 'topic featured link category restriction' do
describe 'topic featured link category restriction' do
before { SiteSetting.topic_featured_link_enabled = true }
let(:guardian) { Guardian.new(user) }
let(:uncategorized) { Category.find(SiteSetting.uncategorized_category_id) }
context "uncategorized" do
context "when uncategorized" do
fab!(:link_category) { Fabricate(:link_category) }
it "allows featured links if uncategorized allows it" do
@ -3704,7 +3678,7 @@ RSpec.describe Guardian do
end
end
context "suspension reasons" do
describe "suspension reasons" do
it "will be shown by default" do
expect(Guardian.new.can_see_suspension_reason?(user)).to eq(true)
end
@ -3729,14 +3703,14 @@ RSpec.describe Guardian do
end
describe '#can_remove_allowed_users?' do
context 'staff users' do
context 'with staff users' do
it 'should be true' do
expect(Guardian.new(moderator).can_remove_allowed_users?(topic))
.to eq(true)
end
end
context 'trust_level >= 2 user' do
context 'with trust_level >= 2 user' do
fab!(:topic_creator) { build(:user, trust_level: 2) }
fab!(:topic) { Fabricate(:topic, user: topic_creator) }
@ -3751,7 +3725,7 @@ RSpec.describe Guardian do
end
end
context 'normal user' do
context 'with normal user' do
fab!(:topic) { Fabricate(:topic, user: Fabricate(:user, trust_level: 1)) }
before do
@ -3797,7 +3771,7 @@ RSpec.describe Guardian do
end
end
context "anonymous users" do
context "with anonymous users" do
fab!(:topic) { Fabricate(:topic) }
it 'should be false' do
@ -3884,8 +3858,8 @@ RSpec.describe Guardian do
end
end
describe "can_see_site_contact_details" do
context "login_required is enabled" do
describe "#can_see_site_contact_details?" do
context "when login_required is enabled" do
before do
SiteSetting.login_required = true
end
@ -3899,7 +3873,7 @@ RSpec.describe Guardian do
end
end
context "login_required is disabled" do
context "when login_required is disabled" do
before do
SiteSetting.login_required = false
end

View File

@ -3,7 +3,6 @@
require 'has_errors'
RSpec.describe HasErrors do
class ErrorTestClass
include HasErrors
end
@ -18,7 +17,7 @@ RSpec.describe HasErrors do
expect(error_test.errors).to be_blank
end
context "validate_child" do
describe "validate_child" do
it "adds the errors from invalid AR objects" do
expect(error_test.validate_child(invalid_topic)).to eq(false)
expect(error_test.errors).to be_present
@ -32,7 +31,7 @@ RSpec.describe HasErrors do
end
end
context "rollback_from_errors!" do
describe "rollback_from_errors!" do
it "triggers a rollback" do
invalid_topic.valid?
@ -42,7 +41,7 @@ RSpec.describe HasErrors do
end
end
context "rollback_with_error!" do
describe "rollback_with_error!" do
it "triggers a rollback" do
expect do
@ -52,5 +51,4 @@ RSpec.describe HasErrors do
expect(error_test.errors[:base]).to include("You can only send warnings to one user at a time.")
end
end
end

Some files were not shown because too many files have changed in this diff Show More