diff --git a/Gemfile.lock b/Gemfile.lock index a6881fc67b..4d73ec747f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) diff --git a/plugins/discourse-local-dates/spec/integration/local_dates_spec.rb b/plugins/discourse-local-dates/spec/integration/local_dates_spec.rb index 651a12ea89..6d4425660e 100644 --- a/plugins/discourse-local-dates/spec/integration/local_dates_spec.rb +++ b/plugins/discourse-local-dates/spec/integration/local_dates_spec.rb @@ -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 diff --git a/plugins/discourse-local-dates/spec/lib/pretty_text_spec.rb b/plugins/discourse-local-dates/spec/lib/pretty_text_spec.rb index 326c9dabb3..0f4af09ae6 100644 --- a/plugins/discourse-local-dates/spec/lib/pretty_text_spec.rb +++ b/plugins/discourse-local-dates/spec/lib/pretty_text_spec.rb @@ -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 diff --git a/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/advanced_user_narrative_spec.rb b/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/advanced_user_narrative_spec.rb index c04ef0008c..cd89d1b5a9 100644 --- a/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/advanced_user_narrative_spec.rb +++ b/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/advanced_user_narrative_spec.rb @@ -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) diff --git a/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/track_selector_spec.rb b/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/track_selector_spec.rb index f1b68d154d..543192f6cf 100644 --- a/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/track_selector_spec.rb +++ b/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/track_selector_spec.rb @@ -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!') diff --git a/plugins/discourse-narrative-bot/spec/jobs/onceoff/remap_old_bot_images_spec.rb b/plugins/discourse-narrative-bot/spec/jobs/onceoff/remap_old_bot_images_spec.rb index 6b0326b7f5..61d9455b0b 100644 --- a/plugins/discourse-narrative-bot/spec/jobs/onceoff/remap_old_bot_images_spec.rb +++ b/plugins/discourse-narrative-bot/spec/jobs/onceoff/remap_old_bot_images_spec.rb @@ -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, diff --git a/plugins/discourse-narrative-bot/spec/requests/discobot_welcome_post_spec.rb b/plugins/discourse-narrative-bot/spec/requests/discobot_welcome_post_spec.rb index 6fa4be2b9d..e57c9ed457 100644 --- a/plugins/discourse-narrative-bot/spec/requests/discobot_welcome_post_spec.rb +++ b/plugins/discourse-narrative-bot/spec/requests/discobot_welcome_post_spec.rb @@ -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 diff --git a/plugins/discourse-narrative-bot/spec/user_spec.rb b/plugins/discourse-narrative-bot/spec/user_spec.rb index 7b3d51b6f0..d7036373f6 100644 --- a/plugins/discourse-narrative-bot/spec/user_spec.rb +++ b/plugins/discourse-narrative-bot/spec/user_spec.rb @@ -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 diff --git a/plugins/poll/spec/integration/poll_endpoints_spec.rb b/plugins/poll/spec/integration/poll_endpoints_spec.rb index 0fd3723646..9fff1972a8 100644 --- a/plugins/poll/spec/integration/poll_endpoints_spec.rb +++ b/plugins/poll/spec/integration/poll_endpoints_spec.rb @@ -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 diff --git a/plugins/poll/spec/requests/users_controller_spec.rb b/plugins/poll/spec/requests/users_controller_spec.rb index 87b354ea48..78e387de6e 100644 --- a/plugins/poll/spec/requests/users_controller_spec.rb +++ b/plugins/poll/spec/requests/users_controller_spec.rb @@ -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 diff --git a/plugins/poll/spec/serializers/poll_option_serializer_spec.rb b/plugins/poll/spec/serializers/poll_option_serializer_spec.rb index 1a31df9838..ad46e77961 100644 --- a/plugins/poll/spec/serializers/poll_option_serializer_spec.rb +++ b/plugins/poll/spec/serializers/poll_option_serializer_spec.rb @@ -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 'doesn’t 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 diff --git a/plugins/styleguide/spec/integration/access_spec.rb b/plugins/styleguide/spec/integration/access_spec.rb index cf5081f299..568d35eafa 100644 --- a/plugins/styleguide/spec/integration/access_spec.rb +++ b/plugins/styleguide/spec/integration/access_spec.rb @@ -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 diff --git a/plugins/styleguide/spec/integration/assets_spec.rb b/plugins/styleguide/spec/integration/assets_spec.rb index ad555711a6..e4d6f2cfa0 100644 --- a/plugins/styleguide/spec/integration/assets_spec.rb +++ b/plugins/styleguide/spec/integration/assets_spec.rb @@ -6,14 +6,14 @@ RSpec.describe 'Styleguide assets' do sign_in(Fabricate(:admin)) end - context 'visits homepage' do + context 'when visiting homepage' do it 'doesn’t 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') diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index 1dac777d6e..f4c25c979a 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -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 diff --git a/spec/import_export/importer_spec.rb b/spec/import_export/importer_spec.rb index ad75f2ade7..b9f6581aad 100644 --- a/spec/import_export/importer_spec.rb +++ b/spec/import_export/importer_spec.rb @@ -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 diff --git a/spec/integration/auto_reject_reviewable_users_spec.rb b/spec/integration/auto_reject_reviewable_users_spec.rb index f51d41705c..f993f097c2 100644 --- a/spec/integration/auto_reject_reviewable_users_spec.rb +++ b/spec/integration/auto_reject_reviewable_users_spec.rb @@ -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 diff --git a/spec/integration/category_tag_spec.rb b/spec/integration/category_tag_spec.rb index 4650f02cd3..59bee8e897 100644 --- a/spec/integration/category_tag_spec.rb +++ b/spec/integration/category_tag_spec.rb @@ -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) } diff --git a/spec/integration/email_outbound_spec.rb b/spec/integration/email_outbound_spec.rb index eaeebbe3ea..fea69ea7c4 100644 --- a/spec/integration/email_outbound_spec.rb +++ b/spec/integration/email_outbound_spec.rb @@ -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) diff --git a/spec/integration/email_style_spec.rb b/spec/integration/email_style_spec.rb index b23cbe35e5..a53cff48e2 100644 --- a/spec/integration/email_style_spec.rb +++ b/spec/integration/email_style_spec.rb @@ -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 = "%{email_content}<%= (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 } diff --git a/spec/integration/same_ip_spammers_spec.rb b/spec/integration/same_ip_spammers_spec.rb index b7cde6e3f6..a586891cf4 100644 --- a/spec/integration/same_ip_spammers_spec.rb +++ b/spec/integration/same_ip_spammers_spec.rb @@ -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 diff --git a/spec/integration/spam_rules_spec.rb b/spec/integration/spam_rules_spec.rb index cfc22442d8..bf89f47868 100644 --- a/spec/integration/spam_rules_spec.rb +++ b/spec/integration/spam_rules_spec.rb @@ -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 } diff --git a/spec/integration/topic_auto_close_spec.rb b/spec/integration/topic_auto_close_spec.rb index 11d851678e..95821bc30e 100644 --- a/spec/integration/topic_auto_close_spec.rb +++ b/spec/integration/topic_auto_close_spec.rb @@ -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) } diff --git a/spec/integration/topic_thumbnail_spec.rb b/spec/integration/topic_thumbnail_spec.rb index 9245716b14..9a51836c5a 100644 --- a/spec/integration/topic_thumbnail_spec.rb +++ b/spec/integration/topic_thumbnail_spec.rb @@ -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([])) diff --git a/spec/integration/watched_words_spec.rb b/spec/integration/watched_words_spec.rb index 0aec8298d1..f776bafe99 100644 --- a/spec/integration/watched_words_spec.rb +++ b/spec/integration/watched_words_spec.rb @@ -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 { diff --git a/spec/integrity/i18n_spec.rb b/spec/integrity/i18n_spec.rb index 0205584c24..b175e8a459 100644 --- a/spec/integrity/i18n_spec.rb +++ b/spec/integrity/i18n_spec.rb @@ -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") diff --git a/spec/jobs/auto_queue_handler_spec.rb b/spec/jobs/auto_queue_handler_spec.rb index ece2af8473..6fb6c2a900 100644 --- a/spec/jobs/auto_queue_handler_spec.rb +++ b/spec/jobs/auto_queue_handler_spec.rb @@ -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 diff --git a/spec/jobs/bulk_invite_spec.rb b/spec/jobs/bulk_invite_spec.rb index 0bbddc17b4..9d0984551d 100644 --- a/spec/jobs/bulk_invite_spec.rb +++ b/spec/jobs/bulk_invite_spec.rb @@ -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 diff --git a/spec/jobs/clean_up_unused_staged_users_spec.rb b/spec/jobs/clean_up_unused_staged_users_spec.rb index c083887115..daaad64912 100644 --- a/spec/jobs/clean_up_unused_staged_users_spec.rb +++ b/spec/jobs/clean_up_unused_staged_users_spec.rb @@ -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 diff --git a/spec/jobs/enqueue_digest_emails_spec.rb b/spec/jobs/enqueue_digest_emails_spec.rb index 958c7a5064..82b18c8c64 100644 --- a/spec/jobs/enqueue_digest_emails_spec.rb +++ b/spec/jobs/enqueue_digest_emails_spec.rb @@ -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 diff --git a/spec/jobs/ensure_s3_uploads_existence_spec.rb b/spec/jobs/ensure_s3_uploads_existence_spec.rb index aef97c2258..84d6e6c812 100644 --- a/spec/jobs/ensure_s3_uploads_existence_spec.rb +++ b/spec/jobs/ensure_s3_uploads_existence_spec.rb @@ -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 diff --git a/spec/jobs/export_user_archive_spec.rb b/spec/jobs/export_user_archive_spec.rb index 15eb36313a..09f86a331f 100644 --- a/spec/jobs/export_user_archive_spec.rb +++ b/spec/jobs/export_user_archive_spec.rb @@ -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 diff --git a/spec/jobs/feature_topic_users_spec.rb b/spec/jobs/feature_topic_users_spec.rb index bae3f19a6d..3fa7eba092 100644 --- a/spec/jobs/feature_topic_users_spec.rb +++ b/spec/jobs/feature_topic_users_spec.rb @@ -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 } diff --git a/spec/jobs/grant_anniversary_badges_spec.rb b/spec/jobs/grant_anniversary_badges_spec.rb index e2e2b70c84..ae5cad056c 100644 --- a/spec/jobs/grant_anniversary_badges_spec.rb +++ b/spec/jobs/grant_anniversary_badges_spec.rb @@ -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 diff --git a/spec/jobs/invalidate_inactive_admins_spec.rb b/spec/jobs/invalidate_inactive_admins_spec.rb index ca84c2e857..8994e9f730 100644 --- a/spec/jobs/invalidate_inactive_admins_spec.rb +++ b/spec/jobs/invalidate_inactive_admins_spec.rb @@ -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 diff --git a/spec/jobs/jobs_spec.rb b/spec/jobs/jobs_spec.rb index f5ce9e2ccd..09c4252dec 100644 --- a/spec/jobs/jobs_spec.rb +++ b/spec/jobs/jobs_spec.rb @@ -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) diff --git a/spec/jobs/notify_mailing_list_subscribers_spec.rb b/spec/jobs/notify_mailing_list_subscribers_spec.rb index ceed63d598..ace5161f91 100644 --- a/spec/jobs/notify_mailing_list_subscribers_spec.rb +++ b/spec/jobs/notify_mailing_list_subscribers_spec.rb @@ -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 diff --git a/spec/jobs/notify_tag_change_spec.rb b/spec/jobs/notify_tag_change_spec.rb index efe15c959f..f0fab3d519 100644 --- a/spec/jobs/notify_tag_change_spec.rb +++ b/spec/jobs/notify_tag_change_spec.rb @@ -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]) } diff --git a/spec/jobs/pending_queued_posts_reminder_spec.rb b/spec/jobs/pending_queued_posts_reminder_spec.rb index fde2b66e0b..7611556dd5 100644 --- a/spec/jobs/pending_queued_posts_reminder_spec.rb +++ b/spec/jobs/pending_queued_posts_reminder_spec.rb @@ -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 diff --git a/spec/jobs/pending_reviewables_reminder_spec.rb b/spec/jobs/pending_reviewables_reminder_spec.rb index c93928c35d..2b6d4deafd 100644 --- a/spec/jobs/pending_reviewables_reminder_spec.rb +++ b/spec/jobs/pending_reviewables_reminder_spec.rb @@ -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) diff --git a/spec/jobs/pending_users_reminder_spec.rb b/spec/jobs/pending_users_reminder_spec.rb index d3a9c4d011..c482231d6e 100644 --- a/spec/jobs/pending_users_reminder_spec.rb +++ b/spec/jobs/pending_users_reminder_spec.rb @@ -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 diff --git a/spec/jobs/poll_mailbox_spec.rb b/spec/jobs/poll_mailbox_spec.rb index 1f5e59e764..3ba8fe72fe 100644 --- a/spec/jobs/poll_mailbox_spec.rb +++ b/spec/jobs/poll_mailbox_spec.rb @@ -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 diff --git a/spec/jobs/regular/group_smtp_email_spec.rb b/spec/jobs/regular/group_smtp_email_spec.rb index b85ef6d3ca..01bc1ec1de 100644 --- a/spec/jobs/regular/group_smtp_email_spec.rb +++ b/spec/jobs/regular/group_smtp_email_spec.rb @@ -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) diff --git a/spec/jobs/remove_banner_spec.rb b/spec/jobs/remove_banner_spec.rb index f218d801fc..6456568eb1 100644 --- a/spec/jobs/remove_banner_spec.rb +++ b/spec/jobs/remove_banner_spec.rb @@ -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 'doesn’t 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 'doesn’t enqueue a future job to remove it' do expect do expect do diff --git a/spec/jobs/sync_acls_for_uploads_spec.rb b/spec/jobs/sync_acls_for_uploads_spec.rb index 87d5e42d26..a7b43162ca 100644 --- a/spec/jobs/sync_acls_for_uploads_spec.rb +++ b/spec/jobs/sync_acls_for_uploads_spec.rb @@ -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 diff --git a/spec/jobs/tl3_promotions_spec.rb b/spec/jobs/tl3_promotions_spec.rb index 5c43b378e9..770bb39c16 100644 --- a/spec/jobs/tl3_promotions_spec.rb +++ b/spec/jobs/tl3_promotions_spec.rb @@ -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) diff --git a/spec/jobs/user_email_spec.rb b/spec/jobs/user_email_spec.rb index 3025fbe474..efda1132b6 100644 --- a/spec/jobs/user_email_spec.rb +++ b/spec/jobs/user_email_spec.rb @@ -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 diff --git a/spec/lib/admin_user_index_query_spec.rb b/spec/lib/admin_user_index_query_spec.rb index d9519d33ea..4bce40f83e 100644 --- a/spec/lib/admin_user_index_query_spec.rb +++ b/spec/lib/admin_user_index_query_spec.rb @@ -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") } diff --git a/spec/lib/archetype_spec.rb b/spec/lib/archetype_spec.rb index 1f662c7b89..9b5a6b6945 100644 --- a/spec/lib/archetype_spec.rb +++ b/spec/lib/archetype_spec.rb @@ -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 diff --git a/spec/lib/auth/default_current_user_provider_spec.rb b/spec/lib/auth/default_current_user_provider_spec.rb index b26d91afa9..bd470e547e 100644 --- a/spec/lib/auth/default_current_user_provider_spec.rb +++ b/spec/lib/auth/default_current_user_provider_spec.rb @@ -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 diff --git a/spec/lib/auth/discord_authenticator_spec.rb b/spec/lib/auth/discord_authenticator_spec.rb index ab925bedc7..cff7c662f4 100644 --- a/spec/lib/auth/discord_authenticator_spec.rb +++ b/spec/lib/auth/discord_authenticator_spec.rb @@ -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) diff --git a/spec/lib/auth/facebook_authenticator_spec.rb b/spec/lib/auth/facebook_authenticator_spec.rb index 8237d3a67d..4a39fe5c46 100644 --- a/spec/lib/auth/facebook_authenticator_spec.rb +++ b/spec/lib/auth/facebook_authenticator_spec.rb @@ -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 diff --git a/spec/lib/auth/github_authenticator_spec.rb b/spec/lib/auth/github_authenticator_spec.rb index ce2dc26492..15020a9636 100644 --- a/spec/lib/auth/github_authenticator_spec.rb +++ b/spec/lib/auth/github_authenticator_spec.rb @@ -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 diff --git a/spec/lib/auth/google_oauth2_authenticator_spec.rb b/spec/lib/auth/google_oauth2_authenticator_spec.rb index e00b51d40c..661ef1f25c 100644 --- a/spec/lib/auth/google_oauth2_authenticator_spec.rb +++ b/spec/lib/auth/google_oauth2_authenticator_spec.rb @@ -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 diff --git a/spec/lib/auth/omniauth_strategies/discourse_google_oauth2_spec.rb b/spec/lib/auth/omniauth_strategies/discourse_google_oauth2_spec.rb index db4adc1c26..37229ecae4 100644 --- a/spec/lib/auth/omniauth_strategies/discourse_google_oauth2_spec.rb +++ b/spec/lib/auth/omniauth_strategies/discourse_google_oauth2_spec.rb @@ -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) diff --git a/spec/lib/auth/twitter_authenticator_spec.rb b/spec/lib/auth/twitter_authenticator_spec.rb index 0e2863c3f4..14f5c834a6 100644 --- a/spec/lib/auth/twitter_authenticator_spec.rb +++ b/spec/lib/auth/twitter_authenticator_spec.rb @@ -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 diff --git a/spec/lib/backup_restore/backup_file_handler_multisite_spec.rb b/spec/lib/backup_restore/backup_file_handler_multisite_spec.rb index c7d4417093..5a0b1f6de1 100644 --- a/spec/lib/backup_restore/backup_file_handler_multisite_spec.rb +++ b/spec/lib/backup_restore/backup_file_handler_multisite_spec.rb @@ -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 diff --git a/spec/lib/backup_restore/backup_file_handler_spec.rb b/spec/lib/backup_restore/backup_file_handler_spec.rb index 5b35a6c4ff..8803de7890 100644 --- a/spec/lib/backup_restore/backup_file_handler_spec.rb +++ b/spec/lib/backup_restore/backup_file_handler_spec.rb @@ -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( diff --git a/spec/lib/backup_restore/database_restorer_multisite_spec.rb b/spec/lib/backup_restore/database_restorer_multisite_spec.rb index ec3fc81954..19044c1f72 100644 --- a/spec/lib/backup_restore/database_restorer_multisite_spec.rb +++ b/spec/lib/backup_restore/database_restorer_multisite_spec.rb @@ -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 diff --git a/spec/lib/backup_restore/database_restorer_spec.rb b/spec/lib/backup_restore/database_restorer_spec.rb index 1f2de1a8ef..e8d69c0723 100644 --- a/spec/lib/backup_restore/database_restorer_spec.rb +++ b/spec/lib/backup_restore/database_restorer_spec.rb @@ -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")] diff --git a/spec/lib/backup_restore/meta_data_handler_spec.rb b/spec/lib/backup_restore/meta_data_handler_spec.rb index 6ea18c4837..9dd08f0e82 100644 --- a/spec/lib/backup_restore/meta_data_handler_spec.rb +++ b/spec/lib/backup_restore/meta_data_handler_spec.rb @@ -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)) diff --git a/spec/lib/backup_restore/s3_backup_store_spec.rb b/spec/lib/backup_restore/s3_backup_store_spec.rb index dbe62f6c46..4aad803cfd 100644 --- a/spec/lib/backup_restore/s3_backup_store_spec.rb +++ b/spec/lib/backup_restore/s3_backup_store_spec.rb @@ -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 } diff --git a/spec/lib/backup_restore/shared_context_for_backup_restore.rb b/spec/lib/backup_restore/shared_context_for_backup_restore.rb index 66047d1bc3..5ad59e604f 100644 --- a/spec/lib/backup_restore/shared_context_for_backup_restore.rb +++ b/spec/lib/backup_restore/shared_context_for_backup_restore.rb @@ -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 diff --git a/spec/lib/backup_restore/shared_examples_for_backup_store.rb b/spec/lib/backup_restore/shared_examples_for_backup_store.rb index b65dadd9d8..eeb8ee2e05 100644 --- a/spec/lib/backup_restore/shared_examples_for_backup_store.rb +++ b/spec/lib/backup_restore/shared_examples_for_backup_store.rb @@ -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 diff --git a/spec/lib/backup_restore/system_interface_multisite_spec.rb b/spec/lib/backup_restore/system_interface_multisite_spec.rb index 6587a71669..e9d93e6e3f 100644 --- a/spec/lib/backup_restore/system_interface_multisite_spec.rb +++ b/spec/lib/backup_restore/system_interface_multisite_spec.rb @@ -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) } diff --git a/spec/lib/backup_restore/system_interface_spec.rb b/spec/lib/backup_restore/system_interface_spec.rb index 8c5c295c2f..20a701d8d3 100644 --- a/spec/lib/backup_restore/system_interface_spec.rb +++ b/spec/lib/backup_restore/system_interface_spec.rb @@ -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 diff --git a/spec/lib/backup_restore/uploads_restorer_spec.rb b/spec/lib/backup_restore/uploads_restorer_spec.rb index 0b55fbeeba..3314358e9e 100644 --- a/spec/lib/backup_restore/uploads_restorer_spec.rb +++ b/spec/lib/backup_restore/uploads_restorer_spec.rb @@ -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" diff --git a/spec/lib/common_passwords/common_passwords_spec.rb b/spec/lib/common_passwords/common_passwords_spec.rb index 8d3ebf2499..fba5e6804f 100644 --- a/spec/lib/common_passwords/common_passwords_spec.rb +++ b/spec/lib/common_passwords/common_passwords_spec.rb @@ -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) diff --git a/spec/lib/composer_messages_finder_spec.rb b/spec/lib/composer_messages_finder_spec.rb index e52ff3e73f..e6bbac2144 100644 --- a/spec/lib/composer_messages_finder_spec.rb +++ b/spec/lib/composer_messages_finder_spec.rb @@ -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 diff --git a/spec/lib/compression/engine_spec.rb b/spec/lib/compression/engine_spec.rb index 913c5da072..6e96e5a226 100644 --- a/spec/lib/compression/engine_spec.rb +++ b/spec/lib/compression/engine_spec.rb @@ -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 diff --git a/spec/lib/concern/cached_counting_spec.rb b/spec/lib/concern/cached_counting_spec.rb index 44976a3737..260744902d 100644 --- a/spec/lib/concern/cached_counting_spec.rb +++ b/spec/lib/concern/cached_counting_spec.rb @@ -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" diff --git a/spec/lib/concern/category_hashtag_spec.rb b/spec/lib/concern/category_hashtag_spec.rb index 94bcb3f7d0..57d687beb2 100644 --- a/spec/lib/concern/category_hashtag_spec.rb +++ b/spec/lib/concern/category_hashtag_spec.rb @@ -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 diff --git a/spec/lib/concern/has_custom_fields_spec.rb b/spec/lib/concern/has_custom_fields_spec.rb index 698d82604c..af0bbaebd8 100644 --- a/spec/lib/concern/has_custom_fields_spec.rb +++ b/spec/lib/concern/has_custom_fields_spec.rb @@ -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)") diff --git a/spec/lib/concern/has_search_data_spec.rb b/spec/lib/concern/has_search_data_spec.rb index e0a0583af1..74f4fbb66d 100644 --- a/spec/lib/concern/has_search_data_spec.rb +++ b/spec/lib/concern/has_search_data_spec.rb @@ -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)") diff --git a/spec/lib/concern/positionable_spec.rb b/spec/lib/concern/positionable_spec.rb index b491ab1090..f4a5746386 100644 --- a/spec/lib/concern/positionable_spec.rb +++ b/spec/lib/concern/positionable_spec.rb @@ -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 diff --git a/spec/lib/concern/searchable_spec.rb b/spec/lib/concern/searchable_spec.rb index 75e3cafa08..b92b0eb4af 100644 --- a/spec/lib/concern/searchable_spec.rb +++ b/spec/lib/concern/searchable_spec.rb @@ -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)") diff --git a/spec/lib/concern/second_factor_manager_spec.rb b/spec/lib/concern/second_factor_manager_spec.rb index 1f0dd30cd8..a30b726e73 100644 --- a/spec/lib/concern/second_factor_manager_spec.rb +++ b/spec/lib/concern/second_factor_manager_spec.rb @@ -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 diff --git a/spec/lib/cooked_post_processor_spec.rb b/spec/lib/cooked_post_processor_spec.rb index 2dc678159c..4c633b5a54 100644 --- a/spec/lib/cooked_post_processor_spec.rb +++ b/spec/lib/cooked_post_processor_spec.rb @@ -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: "") 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: "") 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

') } @@ -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("") @@ -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') } diff --git a/spec/lib/crawler_detection_spec.rb b/spec/lib/crawler_detection_spec.rb index 905950a1e6..91c8ff3255 100644 --- a/spec/lib/crawler_detection_spec.rb +++ b/spec/lib/crawler_detection_spec.rb @@ -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 diff --git a/spec/lib/discourse_plugin_registry_spec.rb b/spec/lib/discourse_plugin_registry_spec.rb index 78c8852670..162a2f051e 100644 --- a/spec/lib/discourse_plugin_registry_spec.rb +++ b/spec/lib/discourse_plugin_registry_spec.rb @@ -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 diff --git a/spec/lib/discourse_spec.rb b/spec/lib/discourse_spec.rb index 653d626834..a26a54bfb2 100644 --- a/spec/lib/discourse_spec.rb +++ b/spec/lib/discourse_spec.rb @@ -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 diff --git a/spec/lib/discourse_tagging_spec.rb b/spec/lib/discourse_tagging_spec.rb index acf7f821fd..ddcd88916d 100644 --- a/spec/lib/discourse_tagging_spec.rb +++ b/spec/lib/discourse_tagging_spec.rb @@ -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) diff --git a/spec/lib/discourse_updates_spec.rb b/spec/lib/discourse_updates_spec.rb index 140d7e33ca..e3ad55311e 100644 --- a/spec/lib/discourse_updates_spec.rb +++ b/spec/lib/discourse_updates_spec.rb @@ -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 } diff --git a/spec/lib/distributed_mutex_spec.rb b/spec/lib/distributed_mutex_spec.rb index aaa25161c7..accd753a62 100644 --- a/spec/lib/distributed_mutex_spec.rb +++ b/spec/lib/distributed_mutex_spec.rb @@ -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 } diff --git a/spec/lib/email/message_builder_spec.rb b/spec/lib/email/message_builder_spec.rb index 0f0c795a19..00487992c0 100644 --- a/spec/lib/email/message_builder_spec.rb +++ b/spec/lib/email/message_builder_spec.rb @@ -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) diff --git a/spec/lib/email/processor_spec.rb b/spec/lib/email/processor_spec.rb index c0a52ffd1b..4fd1c0c112 100644 --- a/spec/lib/email/processor_spec.rb +++ b/spec/lib/email/processor_spec.rb @@ -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) diff --git a/spec/lib/email/receiver_spec.rb b/spec/lib/email/receiver_spec.rb index de77d2acd1..306afa83e4 100644 --- a/spec/lib/email/receiver_spec.rb +++ b/spec/lib/email/receiver_spec.rb @@ -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]) } diff --git a/spec/lib/email/sender_spec.rb b/spec/lib/email/sender_spec.rb index 92c29a9423..f448a93b61 100644 --- a/spec/lib/email/sender_spec.rb +++ b/spec/lib/email/sender_spec.rb @@ -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)) diff --git a/spec/lib/email/styles_spec.rb b/spec/lib/email/styles_spec.rb index a150ea8176..f7372a810c 100644 --- a/spec/lib/email/styles_spec.rb +++ b/spec/lib/email/styles_spec.rb @@ -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("") 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("

hello

") 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('hello') 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('
test
') 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 = "" 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
" do fragment = html_fragment('') expect(fragment.to_s.squish).to match(/^$/) @@ -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 diff --git a/spec/lib/email_updater_spec.rb b/spec/lib/email_updater_spec.rb index 7416fd9127..0c8b4c6531 100644 --- a/spec/lib/email_updater_spec.rb +++ b/spec/lib/email_updater_spec.rb @@ -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 diff --git a/spec/lib/encodings_spec.rb b/spec/lib/encodings_spec.rb index be94d5a8e1..bf3a5e0f02 100644 --- a/spec/lib/encodings_spec.rb +++ b/spec/lib/encodings_spec.rb @@ -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 diff --git a/spec/lib/enum_spec.rb b/spec/lib/enum_spec.rb index 99db4f1703..e0c1f51b35 100644 --- a/spec/lib/enum_spec.rb +++ b/spec/lib/enum_spec.rb @@ -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) diff --git a/spec/lib/file_store/base_store_spec.rb b/spec/lib/file_store/base_store_spec.rb index 0a8cba20a8..6ea506fadd 100644 --- a/spec/lib/file_store/base_store_spec.rb +++ b/spec/lib/file_store/base_store_spec.rb @@ -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 diff --git a/spec/lib/file_store/s3_store_spec.rb b/spec/lib/file_store/s3_store_spec.rb index bfebbe7531..bff47c3ce8 100644 --- a/spec/lib/file_store/s3_store_spec.rb +++ b/spec/lib/file_store/s3_store_spec.rb @@ -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 diff --git a/spec/lib/final_destination_spec.rb b/spec/lib/final_destination_spec.rb index 2782f7b894..0e00d508d8 100644 --- a/spec/lib/final_destination_spec.rb +++ b/spec/lib/final_destination_spec.rb @@ -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 diff --git a/spec/lib/freedom_patches/translate_accelerator_spec.rb b/spec/lib/freedom_patches/translate_accelerator_spec.rb index 4903b066af..c3a6592577 100644 --- a/spec/lib/freedom_patches/translate_accelerator_spec.rb +++ b/spec/lib/freedom_patches/translate_accelerator_spec.rb @@ -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) diff --git a/spec/lib/gaps_spec.rb b/spec/lib/gaps_spec.rb index 9cd2cbfb7f..aeab2f87e5 100644 --- a/spec/lib/gaps_spec.rb +++ b/spec/lib/gaps_spec.rb @@ -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 diff --git a/spec/lib/global_path_spec.rb b/spec/lib/global_path_spec.rb index 40c063817e..9846dca06f 100644 --- a/spec/lib/global_path_spec.rb +++ b/spec/lib/global_path_spec.rb @@ -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' diff --git a/spec/lib/guardian/user_guardian_spec.rb b/spec/lib/guardian/user_guardian_spec.rb index 9015e8d554..3b10a6fbe1 100644 --- a/spec/lib/guardian/user_guardian_spec.rb +++ b/spec/lib/guardian/user_guardian_spec.rb @@ -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 diff --git a/spec/lib/guardian_spec.rb b/spec/lib/guardian_spec.rb index f773cf23e3..b8b0780176 100644 --- a/spec/lib/guardian_spec.rb +++ b/spec/lib/guardian_spec.rb @@ -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 diff --git a/spec/lib/has_errors_spec.rb b/spec/lib/has_errors_spec.rb index 436039706c..a63b31ef88 100644 --- a/spec/lib/has_errors_spec.rb +++ b/spec/lib/has_errors_spec.rb @@ -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 diff --git a/spec/lib/hijack_spec.rb b/spec/lib/hijack_spec.rb index c05985f105..0e806fd7ab 100644 --- a/spec/lib/hijack_spec.rb +++ b/spec/lib/hijack_spec.rb @@ -30,7 +30,7 @@ RSpec.describe Hijack do Hijack::Tester.new end - context "Request Tracker integration" do + describe "Request Tracker integration" do let :logger do lambda do |env, data| @calls += 1 diff --git a/spec/lib/imap/sync_spec.rb b/spec/lib/imap/sync_spec.rb index d7f66fd052..e68ba4a681 100644 --- a/spec/lib/imap/sync_spec.rb +++ b/spec/lib/imap/sync_spec.rb @@ -3,7 +3,6 @@ require 'imap/sync' RSpec.describe Imap::Sync do - before do SiteSetting.tagging_enabled = true SiteSetting.pm_tags_allowed_for_groups = "1|2|3" @@ -39,7 +38,7 @@ RSpec.describe Imap::Sync do ) end - context 'no previous sync' do + describe 'no previous sync' do let(:from) { 'john@free.fr' } let(:subject) { 'Testing email post' } let(:message_id) { "#{SecureRandom.hex}@example.com" } @@ -169,7 +168,7 @@ RSpec.describe Imap::Sync do end end - context 'previous sync' do + describe 'previous sync' do let(:subject) { 'Testing email post' } let(:first_from) { 'john@free.fr' } @@ -527,7 +526,7 @@ RSpec.describe Imap::Sync do end - context 'invalidated previous sync' do + describe 'invalidated previous sync' do let(:subject) { 'Testing email post' } let(:first_from) { 'john@free.fr' } diff --git a/spec/lib/inline_oneboxer_spec.rb b/spec/lib/inline_oneboxer_spec.rb index 52321f84e2..18acb78f5e 100644 --- a/spec/lib/inline_oneboxer_spec.rb +++ b/spec/lib/inline_oneboxer_spec.rb @@ -20,7 +20,7 @@ RSpec.describe InlineOneboxer do expect(results).to be_blank end - context "caching" do + describe "caching" do fab!(:topic) { Fabricate(:topic) } before do @@ -351,7 +351,7 @@ RSpec.describe InlineOneboxer do end end - context "register_local_handler" do + describe ".register_local_handler" do it "calls registered local handler" do InlineOneboxer.register_local_handler('wizard') do |url, route| { url: url, title: 'Custom Onebox for Wizard' } diff --git a/spec/lib/js_locale_helper_spec.rb b/spec/lib/js_locale_helper_spec.rb index 5a28c82454..775db523eb 100644 --- a/spec/lib/js_locale_helper_spec.rb +++ b/spec/lib/js_locale_helper_spec.rb @@ -31,7 +31,7 @@ RSpec.describe JsLocaleHelper do end - context "message format" do + describe "message format" do def message_format_filename(locale) Rails.root + "lib/javascripts/locale/#{locale}.js" end diff --git a/spec/lib/middleware/anonymous_cache_spec.rb b/spec/lib/middleware/anonymous_cache_spec.rb index 3dfa03b918..71f0428435 100644 --- a/spec/lib/middleware/anonymous_cache_spec.rb +++ b/spec/lib/middleware/anonymous_cache_spec.rb @@ -12,7 +12,7 @@ RSpec.describe Middleware::AnonymousCache do Middleware::AnonymousCache::Helper.new(env(opts)) end - context "cacheable?" do + describe "#cacheable?" do it "true by default" do expect(new_helper.cacheable?).to eq(true) end @@ -38,7 +38,7 @@ RSpec.describe Middleware::AnonymousCache do end end - context "per theme cache" do + describe "per theme cache" do it "handles theme keys" do theme = Fabricate(:theme, user_selectable: true) @@ -93,7 +93,7 @@ RSpec.describe Middleware::AnonymousCache do expect(key1).not_to eq(key2) end - context "cached" do + context "when cached" do let!(:helper) do new_helper("ANON_CACHE_DURATION" => 10) end @@ -151,7 +151,7 @@ RSpec.describe Middleware::AnonymousCache do end end - context 'background request rate limit' do + describe 'background request rate limit' do it 'will rate limit background requests' do app = Middleware::AnonymousCache.new( @@ -194,7 +194,7 @@ RSpec.describe Middleware::AnonymousCache do end end - context 'force_anonymous!' do + describe '#force_anonymous!' do before do RateLimiter.enable end @@ -260,7 +260,7 @@ RSpec.describe Middleware::AnonymousCache do end end - context 'invalid request payload' do + describe 'invalid request payload' do it 'returns 413 for GET request with payload' do status, headers, _ = middleware.call(env.tap do |environment| environment[Rack::RACK_INPUT].write("test") @@ -271,7 +271,7 @@ RSpec.describe Middleware::AnonymousCache do end end - context "crawler blocking" do + describe "crawler blocking" do let :non_crawler do { "HTTP_USER_AGENT" => diff --git a/spec/lib/middleware/request_tracker_spec.rb b/spec/lib/middleware/request_tracker_spec.rb index 00edd39b87..721c836ce4 100644 --- a/spec/lib/middleware/request_tracker_spec.rb +++ b/spec/lib/middleware/request_tracker_spec.rb @@ -23,7 +23,7 @@ RSpec.describe Middleware::RequestTracker do CachedCounting.disable end - context "full request" do + describe "full request" do it "can handle rogue user agents" do agent = (+"Evil Googlebot String \xc3\x28").force_encoding("Windows-1252") @@ -36,7 +36,7 @@ RSpec.describe Middleware::RequestTracker do end end - context "log_request" do + describe "log_request" do before do freeze_time ApplicationRequest.clear_cache! @@ -126,7 +126,7 @@ RSpec.describe Middleware::RequestTracker do expect(ApplicationRequest.page_view_anon.first.count).to eq(1) end - context "ignore anonymous page views" do + context "when ignoring anonymous page views" do let(:anon_data) do Middleware::RequestTracker.get_data(env( "HTTP_USER_AGENT" => "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.72 Safari/537.36" @@ -180,7 +180,7 @@ RSpec.describe Middleware::RequestTracker do end end - context "rate limiting" do + describe "rate limiting" do before do RateLimiter.enable RateLimiter.clear_all_global! @@ -549,7 +549,7 @@ RSpec.describe Middleware::RequestTracker do end end - context "callbacks" do + describe "callbacks" do def app(result, sql_calls: 0, redis_calls: 0) lambda do |env| sql_calls.times do diff --git a/spec/lib/new_post_manager_spec.rb b/spec/lib/new_post_manager_spec.rb index 4241ab72b5..f904074b99 100644 --- a/spec/lib/new_post_manager_spec.rb +++ b/spec/lib/new_post_manager_spec.rb @@ -6,7 +6,7 @@ RSpec.describe NewPostManager do fab!(:user) { Fabricate(:user) } fab!(:topic) { Fabricate(:topic) } - context "default action" do + describe "default action" do it "creates the post by default" do manager = NewPostManager.new(user, raw: 'this is a new post', topic_id: topic.id) result = manager.perform @@ -18,7 +18,7 @@ RSpec.describe NewPostManager do end end - context "default action" do + describe "default action" do fab!(:other_user) { Fabricate(:user) } it "doesn't enqueue private messages" do @@ -101,7 +101,7 @@ RSpec.describe NewPostManager do end end - context "default handler" do + describe "default handler" do let(:manager) { NewPostManager.new(user, raw: 'this is new post content', topic_id: topic.id) } context 'with the settings zeroed out' do @@ -117,7 +117,7 @@ RSpec.describe NewPostManager do end end - context 'basic post/topic count restrictions' do + context 'with basic post/topic count restrictions' do before do SiteSetting.approve_post_count = 1 end @@ -324,7 +324,7 @@ RSpec.describe NewPostManager do end end - context "new topic handler" do + describe "new topic handler" do let(:manager) { NewPostManager.new(user, raw: 'this is new topic content', title: 'new topic title') } context 'with a high trust level setting for new topics' do before do @@ -337,11 +337,9 @@ RSpec.describe NewPostManager do expect(result.reason).to eq(:new_topics_unless_trust_level) end end - end - context "extensibility priority" do - + describe "extensibility priority" do after do NewPostManager.clear_handlers! end @@ -365,11 +363,9 @@ RSpec.describe NewPostManager do NewPostManager.add_handler(101, &c) expect(NewPostManager.handlers).to eq([c, a, b]) end - end - context "extensibility" do - + describe "extensibility" do before do @counter = 0 @@ -465,11 +461,9 @@ RSpec.describe NewPostManager do expect(result.post).to be_present expect(@counter).to be(0) end - end - context "user needs approval?" do - + describe "user needs approval?" do let :user do user = Fabricate.build(:user, trust_level: 0) user_stat = UserStat.new(post_count: 0) @@ -661,7 +655,7 @@ RSpec.describe NewPostManager do end end - context "via email" do + describe "via email" do let(:manager) do NewPostManager.new( topic.user, @@ -690,7 +684,7 @@ RSpec.describe NewPostManager do end end - context "via email with a spam failure" do + describe "via email with a spam failure" do let(:user) { Fabricate(:user) } let(:admin) { Fabricate(:admin) } @@ -725,7 +719,7 @@ RSpec.describe NewPostManager do end end - context "via email with an authentication results failure" do + describe "via email with an authentication results failure" do let(:user) { Fabricate(:user) } let(:admin) { Fabricate(:admin) } @@ -759,7 +753,7 @@ RSpec.describe NewPostManager do end end - context "private message via email" do + describe "private message via email" do it "doesn't enqueue authentication results failure" do manager = NewPostManager.new( topic.user, @@ -788,5 +782,4 @@ RSpec.describe NewPostManager do expect(result.action).to eq(:create_post) end end - end diff --git a/spec/lib/onebox/engine/allowlisted_generic_onebox_spec.rb b/spec/lib/onebox/engine/allowlisted_generic_onebox_spec.rb index 23c1733491..4064fde840 100644 --- a/spec/lib/onebox/engine/allowlisted_generic_onebox_spec.rb +++ b/spec/lib/onebox/engine/allowlisted_generic_onebox_spec.rb @@ -90,7 +90,7 @@ RSpec.describe Onebox::Engine::AllowlistedGenericOnebox do end describe 'canonical link' do - context 'uses canonical link if available' do + context 'when using canonical link if available' do let(:mobile_url) { "https://m.etsy.com/in-en/listing/87673424/personalized-word-pillow-case-letter" } let(:canonical_url) { "https://www.etsy.com/in-en/listing/87673424/personalized-word-pillow-case-letter" } before do @@ -111,7 +111,7 @@ RSpec.describe Onebox::Engine::AllowlistedGenericOnebox do end end - context 'does not use canonical link for Discourse topics' do + context 'when not using canonical link for Discourse topics' do let(:discourse_topic_url) { "https://meta.discourse.org/t/congratulations-most-stars-in-2013-github-octoverse/12483" } let(:discourse_topic_reply_url) { "https://meta.discourse.org/t/congratulations-most-stars-in-2013-github-octoverse/12483/2" } before do @@ -164,7 +164,7 @@ RSpec.describe Onebox::Engine::AllowlistedGenericOnebox do end describe 'missing description' do - context 'works without description if image is present' do + context 'when working without description if image is present' do before do stub_request(:get, "https://edition.cnn.com/2020/05/15/health/gallery/coronavirus-people-adopting-pets-photos/index.html") .to_return(status: 200, body: onebox_response('cnn')) @@ -183,7 +183,7 @@ RSpec.describe Onebox::Engine::AllowlistedGenericOnebox do end end - context 'uses basic meta description when necessary' do + context 'when using basic meta description when necessary' do before do stub_request(:get, "https://www.reddit.com/r/colors/comments/b4d5xm/literally_nothing_black_edition/") .to_return(status: 200, body: onebox_response('reddit_image')) @@ -204,7 +204,7 @@ RSpec.describe Onebox::Engine::AllowlistedGenericOnebox do end describe 'article html hosts' do - context 'returns article_html for hosts in article_html_hosts' do + context 'when returning article_html for hosts in article_html_hosts' do before do stub_request(:get, "https://www.imdb.com/title/tt0108002/") .to_return(status: 200, body: onebox_response('imdb')) diff --git a/spec/lib/onebox/engine/amazon_onebox_spec.rb b/spec/lib/onebox/engine/amazon_onebox_spec.rb index f9be9bc696..ad624b6c9c 100644 --- a/spec/lib/onebox/engine/amazon_onebox_spec.rb +++ b/spec/lib/onebox/engine/amazon_onebox_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true RSpec.describe Onebox::Engine::AmazonOnebox do - context "regular amazon page" do + describe "regular amazon page" do before do @link = "https://www.amazon.com/Knit-Noro-Accessories-Colorful-Little/dp/193609620X" @uri = "https://www.amazon.com/dp/193609620X" @@ -10,7 +10,7 @@ RSpec.describe Onebox::Engine::AmazonOnebox do .to_return(status: 200, body: onebox_response("amazon")) end - include_context "engines" + include_context "with engines" it_behaves_like "an engine" describe "works with international domains" do @@ -101,7 +101,7 @@ RSpec.describe Onebox::Engine::AmazonOnebox do end end - context "amazon with opengraph" do + describe "amazon with opengraph" do let(:link) { "https://www.amazon.com/dp/B01MFXN4Y2" } let(:html) { described_class.new(link).to_html } @@ -128,7 +128,7 @@ RSpec.describe Onebox::Engine::AmazonOnebox do end end - context "amazon book page" do + describe "amazon book page" do let(:link) { "https://www.amazon.com/dp/B00AYQNR46" } let(:html) { described_class.new(link).to_html } @@ -156,7 +156,7 @@ RSpec.describe Onebox::Engine::AmazonOnebox do end end - context "amazon ebook page" do + describe "amazon ebook page" do let(:link) { "https://www.amazon.com/dp/193435659X" } let(:html) { described_class.new(link).to_html } @@ -192,7 +192,7 @@ RSpec.describe Onebox::Engine::AmazonOnebox do end end - context "non-standard response from Amazon" do + describe "non-standard response from Amazon" do let(:link) { "https://www.amazon.com/dp/B0123ABCD3210" } let(:onebox) { described_class.new(link) } @@ -215,7 +215,7 @@ RSpec.describe Onebox::Engine::AmazonOnebox do end end - context "alternate page layout response from Amazon" do + describe "alternate page layout response from Amazon" do let(:link) { "https://www.amazon.com/dp/B07FQ7M16H" } let(:html) { described_class.new(link).to_html } diff --git a/spec/lib/onebox/engine/github_actions_onebox_spec.rb b/spec/lib/onebox/engine/github_actions_onebox_spec.rb index 8a24337c84..fb5b80b91d 100644 --- a/spec/lib/onebox/engine/github_actions_onebox_spec.rb +++ b/spec/lib/onebox/engine/github_actions_onebox_spec.rb @@ -12,7 +12,7 @@ RSpec.describe Onebox::Engine::GithubActionsOnebox do .to_return(status: 200, body: onebox_response("githubactions_pr_run")) end - include_context "engines" + include_context "with engines" it_behaves_like "an engine" describe "#to_html" do @@ -34,7 +34,7 @@ RSpec.describe Onebox::Engine::GithubActionsOnebox do .to_return(status: 200, body: onebox_response("githubactions_actions_run")) end - include_context "engines" + include_context "with engines" it_behaves_like "an engine" describe "#to_html" do diff --git a/spec/lib/onebox/engine/github_blob_onebox_spec.rb b/spec/lib/onebox/engine/github_blob_onebox_spec.rb index 6a25d8cfac..6f926990e1 100644 --- a/spec/lib/onebox/engine/github_blob_onebox_spec.rb +++ b/spec/lib/onebox/engine/github_blob_onebox_spec.rb @@ -8,7 +8,7 @@ RSpec.describe Onebox::Engine::GithubBlobOnebox do .to_return(status: 200, body: onebox_response(described_class.onebox_name)) end - include_context "engines" + include_context "with engines" it_behaves_like "an engine" describe "#to_html" do diff --git a/spec/lib/onebox/engine/github_commit_onebox_spec.rb b/spec/lib/onebox/engine/github_commit_onebox_spec.rb index a0a26b2be3..ec1d8a1e19 100644 --- a/spec/lib/onebox/engine/github_commit_onebox_spec.rb +++ b/spec/lib/onebox/engine/github_commit_onebox_spec.rb @@ -9,7 +9,7 @@ RSpec.describe Onebox::Engine::GithubCommitOnebox do stub_request(:get, @uri).to_return(status: 200, body: onebox_response("githubcommit")) end - include_context "engines" + include_context "with engines" it_behaves_like "an engine" describe "#to_html" do @@ -64,7 +64,7 @@ RSpec.describe Onebox::Engine::GithubCommitOnebox do .to_return(status: 200, body: onebox_response("githubcommit")) end - include_context "engines" + include_context "with engines" # TODO: fix test to make sure it's not failing when matching object # it_behaves_like "an engine" diff --git a/spec/lib/onebox/engine/github_folder_onebox_spec.rb b/spec/lib/onebox/engine/github_folder_onebox_spec.rb index 849821ac88..86505c5931 100644 --- a/spec/lib/onebox/engine/github_folder_onebox_spec.rb +++ b/spec/lib/onebox/engine/github_folder_onebox_spec.rb @@ -9,7 +9,7 @@ RSpec.describe Onebox::Engine::GithubFolderOnebox do stub_request(:get, @uri).to_return(status: 200, body: onebox_response(described_class.onebox_name)) end - include_context "engines" + include_context "with engines" it_behaves_like "an engine" describe "#to_html" do diff --git a/spec/lib/onebox/engine/github_gist_onebox_spec.rb b/spec/lib/onebox/engine/github_gist_onebox_spec.rb index 167c3a23f5..6cbb285e00 100644 --- a/spec/lib/onebox/engine/github_gist_onebox_spec.rb +++ b/spec/lib/onebox/engine/github_gist_onebox_spec.rb @@ -8,7 +8,7 @@ RSpec.describe Onebox::Engine::GithubGistOnebox do .to_return(status: 200, body: onebox_response(described_class.onebox_name)) end - include_context "engines" + include_context "with engines" it_behaves_like "an engine" describe "#data" do diff --git a/spec/lib/onebox/engine/github_pullrequest_onebox_spec.rb b/spec/lib/onebox/engine/github_pullrequest_onebox_spec.rb index af11fbfc66..546ff00438 100644 --- a/spec/lib/onebox/engine/github_pullrequest_onebox_spec.rb +++ b/spec/lib/onebox/engine/github_pullrequest_onebox_spec.rb @@ -8,7 +8,7 @@ RSpec.describe Onebox::Engine::GithubPullRequestOnebox do stub_request(:get, @uri).to_return(status: 200, body: onebox_response(described_class.onebox_name)) end - include_context "engines" + include_context "with engines" it_behaves_like "an engine" describe "#to_html" do diff --git a/spec/lib/onebox/engine/gitlab_blob_onebox_spec.rb b/spec/lib/onebox/engine/gitlab_blob_onebox_spec.rb index 9cbf0769cc..ec812b66bc 100644 --- a/spec/lib/onebox/engine/gitlab_blob_onebox_spec.rb +++ b/spec/lib/onebox/engine/gitlab_blob_onebox_spec.rb @@ -8,7 +8,7 @@ RSpec.describe Onebox::Engine::GitlabBlobOnebox do .to_return(status: 200, body: onebox_response(described_class.onebox_name)) end - include_context "engines" + include_context "with engines" it_behaves_like "an engine" describe "#to_html" do diff --git a/spec/lib/onebox/engine/google_docs_onebox_spec.rb b/spec/lib/onebox/engine/google_docs_onebox_spec.rb index 4326930e00..214fe05dab 100644 --- a/spec/lib/onebox/engine/google_docs_onebox_spec.rb +++ b/spec/lib/onebox/engine/google_docs_onebox_spec.rb @@ -7,7 +7,7 @@ RSpec.describe Onebox::Engine::GoogleDocsOnebox do stub_request(:get, @link).to_return(status: 200, body: onebox_response("googledocs")) end - include_context "engines" + include_context "with engines" it_behaves_like "an engine" describe "#to_html" do diff --git a/spec/lib/onebox/engine/google_play_app_onebox_spec.rb b/spec/lib/onebox/engine/google_play_app_onebox_spec.rb index 8df0dcea5f..43bf0437e1 100644 --- a/spec/lib/onebox/engine/google_play_app_onebox_spec.rb +++ b/spec/lib/onebox/engine/google_play_app_onebox_spec.rb @@ -8,7 +8,7 @@ RSpec.describe Onebox::Engine::GooglePlayAppOnebox do .to_return(status: 200, body: onebox_response("googleplayapp")) end - include_context "engines" + include_context "with engines" it_behaves_like "an engine" describe "#to_html" do diff --git a/spec/lib/onebox/engine/hackernews_spec.rb b/spec/lib/onebox/engine/hackernews_spec.rb index c1e448aad7..152ec7adc4 100644 --- a/spec/lib/onebox/engine/hackernews_spec.rb +++ b/spec/lib/onebox/engine/hackernews_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true RSpec.describe Onebox::Engine::HackernewsOnebox do - context "When oneboxing a comment" do + context "when oneboxing a comment" do let(:link) { "https://news.ycombinator.com/item?id=30181167" } let(:api_link) { "https://hacker-news.firebaseio.com/v0/item/30181167.json" } let(:html) { described_class.new(link).to_html } @@ -27,7 +27,7 @@ RSpec.describe Onebox::Engine::HackernewsOnebox do end end - context "When oneboxing a story" do + context "when oneboxing a story" do let(:link) { "https://news.ycombinator.com/item?id=5172905" } let(:api_link) { "https://hacker-news.firebaseio.com/v0/item/5172905.json" } let(:html) { described_class.new(link).to_html } diff --git a/spec/lib/onebox/engine/pubmed_onebox_spec.rb b/spec/lib/onebox/engine/pubmed_onebox_spec.rb index 58450b84d8..135a6b8ae5 100644 --- a/spec/lib/onebox/engine/pubmed_onebox_spec.rb +++ b/spec/lib/onebox/engine/pubmed_onebox_spec.rb @@ -29,7 +29,7 @@ RSpec.describe Onebox::Engine::PubmedOnebox do expect(html).to include(link) end - context "Pubmed electronic print" do + describe "Pubmed electronic print" do let(:link) { "http://www.ncbi.nlm.nih.gov/pubmed/24737116" } let(:xml_link) { "http://www.ncbi.nlm.nih.gov/pubmed/24737116?report=xml&format=text" } let(:html) { described_class.new(link).to_html } @@ -56,7 +56,7 @@ RSpec.describe Onebox::Engine::PubmedOnebox do end end - context "regex URI match" do + describe "regex URI match" do it "matches on specific articles" do expect(match("http://www.ncbi.nlm.nih.gov/pubmed/7288891")).to eq true end diff --git a/spec/lib/onebox/engine/stack_exchange_onebox_spec.rb b/spec/lib/onebox/engine/stack_exchange_onebox_spec.rb index 03f5824e6f..cd7ac3d9ed 100644 --- a/spec/lib/onebox/engine/stack_exchange_onebox_spec.rb +++ b/spec/lib/onebox/engine/stack_exchange_onebox_spec.rb @@ -49,7 +49,7 @@ RSpec.describe Onebox::Engine::StackExchangeOnebox do .to_return(status: 200, body: onebox_response('stackexchange-question')) end - include_context 'engines' + include_context 'with engines' it_behaves_like 'an engine' describe '#to_html' do @@ -80,7 +80,7 @@ RSpec.describe Onebox::Engine::StackExchangeOnebox do .to_return(status: 200, body: onebox_response('stackexchange-answer')) end - include_context 'engines' + include_context 'with engines' it_behaves_like 'an engine' describe '#to_html' do diff --git a/spec/lib/onebox/engine/trello_onebox_spec.rb b/spec/lib/onebox/engine/trello_onebox_spec.rb index 136f4ff7c5..0d795afa23 100644 --- a/spec/lib/onebox/engine/trello_onebox_spec.rb +++ b/spec/lib/onebox/engine/trello_onebox_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true RSpec.describe Onebox::Engine::TrelloOnebox do - context "Boards" do + describe "Boards" do it "should onebox with SEF url corrrectly" do expect(Onebox.preview('https://trello.com/b/nC8QJJoZ/trello-development-roadmap').to_s).to match('iframe src="https://trello.com/b/nC8QJJoZ.html"') end @@ -14,7 +14,7 @@ RSpec.describe Onebox::Engine::TrelloOnebox do end end - context "Cards" do + describe "Cards" do it "should onebox with SEF url corrrectly" do expect(Onebox.preview('https://trello.com/c/NIRpzVDM/1211-what-can-you-expect-from-this-board').to_s).to match('iframe src="https://trello.com/c/NIRpzVDM.html"') end diff --git a/spec/lib/onebox/engine/twitter_status_onebox_spec.rb b/spec/lib/onebox/engine/twitter_status_onebox_spec.rb index d60c2f99a6..6edf74928c 100644 --- a/spec/lib/onebox/engine/twitter_status_onebox_spec.rb +++ b/spec/lib/onebox/engine/twitter_status_onebox_spec.rb @@ -40,7 +40,7 @@ RSpec.describe Onebox::Engine::TwitterStatusOnebox do end end - shared_context "standard tweet info" do + shared_context "with standard tweet info" do before do @link = "https://twitter.com/vyki_e/status/363116819147538433" @onebox_fixture = "twitterstatus" @@ -55,7 +55,7 @@ RSpec.describe Onebox::Engine::TwitterStatusOnebox do let(:retweets_count) { "0" } end - shared_context "quoted tweet info" do + shared_context "with quoted tweet info" do before do @link = "https://twitter.com/metallica/status/1128068672289890305" @onebox_fixture = "twitterstatus_quoted" @@ -72,7 +72,7 @@ RSpec.describe Onebox::Engine::TwitterStatusOnebox do let(:retweets_count) { "201" } end - shared_context "featured image info" do + shared_context "with featured image info" do before do @link = "https://twitter.com/codinghorror/status/1409351083177046020" @onebox_fixture = "twitterstatus_featured_image" @@ -111,8 +111,8 @@ RSpec.describe Onebox::Engine::TwitterStatusOnebox do context "with a standard tweet" do let(:tweet_content) { "I'm a sucker for pledges." } - include_context "standard tweet info" - include_context "engines" + include_context "with standard tweet info" + include_context "with engines" it_behaves_like "an engine" it_behaves_like "#to_html" @@ -123,8 +123,8 @@ RSpec.describe Onebox::Engine::TwitterStatusOnebox do "Thank you to everyone who came out for #MetInParis last night for helping us support @EMMAUSolidarite &" end - include_context "quoted tweet info" - include_context "engines" + include_context "with quoted tweet info" + include_context "with engines" it_behaves_like "an engine" it_behaves_like '#to_html' @@ -136,8 +136,8 @@ RSpec.describe Onebox::Engine::TwitterStatusOnebox do "My first text message from my child! A moment that shall live on in infamy!" end - include_context "featured image info" - include_context "engines" + include_context "with featured image info" + include_context "with engines" it_behaves_like "an engine" it_behaves_like '#to_html' @@ -289,8 +289,8 @@ RSpec.describe Onebox::Engine::TwitterStatusOnebox do } end - include_context "standard tweet info" - include_context "engines" + include_context "with standard tweet info" + include_context "with engines" it_behaves_like "an engine" it_behaves_like "#to_html" @@ -674,8 +674,8 @@ RSpec.describe Onebox::Engine::TwitterStatusOnebox do } end - include_context "quoted tweet info" - include_context "engines" + include_context "with quoted tweet info" + include_context "with engines" it_behaves_like "an engine" it_behaves_like '#to_html' diff --git a/spec/lib/onebox/engine/wikipedia_onebox_spec.rb b/spec/lib/onebox/engine/wikipedia_onebox_spec.rb index 4ad6399249..c55305c3dc 100644 --- a/spec/lib/onebox/engine/wikipedia_onebox_spec.rb +++ b/spec/lib/onebox/engine/wikipedia_onebox_spec.rb @@ -8,7 +8,7 @@ RSpec.describe Onebox::Engine::WikipediaOnebox do .to_return(status: 200, body: onebox_response(described_class.onebox_name)) end - include_context "engines" + include_context "with engines" it_behaves_like "an engine" describe "#to_html" do @@ -21,7 +21,7 @@ RSpec.describe Onebox::Engine::WikipediaOnebox do end end - context "url with section hash" do + describe "url with section hash" do before do @link = "http://en.wikipedia.org/wiki/Billy_Jack#Soundtrack" end @@ -31,7 +31,7 @@ RSpec.describe Onebox::Engine::WikipediaOnebox do end end - context "url with url-encoded section hash" do + describe "url with url-encoded section hash" do before do @link = "https://fr.wikipedia.org/wiki/Th%C3%A9ologie#La_th%C3%A9ologie_selon_Aristote" diff --git a/spec/lib/onebox/helpers_spec.rb b/spec/lib/onebox/helpers_spec.rb index c8f8c1547d..22f97cebde 100644 --- a/spec/lib/onebox/helpers_spec.rb +++ b/spec/lib/onebox/helpers_spec.rb @@ -51,7 +51,7 @@ RSpec.describe Onebox::Helpers do expect(described_class.fetch_html_doc(uri).to_s).to match("success") end - context "canonical link" do + context "with canonical link" do it "follows canonical link" do uri = 'https://www.example.com' stub_request(:get, uri).to_return(status: 200, body: "

invalid

") @@ -133,7 +133,7 @@ RSpec.describe Onebox::Helpers do end describe "user_agent" do - context "default" do + context "with default" do it "has the default Discourse user agent" do stub_request(:get, "http://example.com/some-resource") .with(headers: { "user-agent" => /Discourse Forum Onebox/ }) @@ -143,7 +143,7 @@ RSpec.describe Onebox::Helpers do end end - context "Custom option" do + context "with custom option" do around do |example| previous_options = Onebox.options.to_h Onebox.options = { user_agent: "EvilTroutBot v0.1" } diff --git a/spec/lib/oneboxer_spec.rb b/spec/lib/oneboxer_spec.rb index 2ae8c97de2..b011f6fbbf 100644 --- a/spec/lib/oneboxer_spec.rb +++ b/spec/lib/oneboxer_spec.rb @@ -25,8 +25,7 @@ RSpec.describe Oneboxer do end end - context "local oneboxes" do - + describe "local oneboxes" do def link(url) url = "#{Discourse.base_url}#{url}" %{#{url}} @@ -171,8 +170,7 @@ RSpec.describe Oneboxer do HTML - context "blacklisted domains" do - + context "with blacklisted domains" do it "does not return a onebox if redirect uri final destination is in blacklist" do SiteSetting.blocked_onebox_domains = "kitten.com" @@ -451,7 +449,7 @@ RSpec.describe Oneboxer do expect(Oneboxer.onebox("https://allowlist.ed/iframes", invalidate_oneboxes: true)).to match("iframe src") end - context 'missing attributes' do + describe 'missing attributes' do before do stub_request(:head, url) end @@ -480,7 +478,7 @@ RSpec.describe Oneboxer do end end - context 'instagram' do + describe 'instagram' do it 'providing a token should attempt to use new endpoint' do url = "https://www.instagram.com/p/CHLkBERAiLa" access_token = 'abc123' @@ -558,7 +556,7 @@ RSpec.describe Oneboxer do end end - context 'strategies' do + describe 'strategies' do it "has a 'default' strategy" do expect(Oneboxer.strategies.keys.first).to eq(:default) end @@ -568,7 +566,7 @@ RSpec.describe Oneboxer do expect(Oneboxer.strategies[strategy].keys).not_to eq([]) end - context "using a non-default strategy" do + context "when using a non-default strategy" do let(:hostname) { "my.interesting.site" } let(:url) { "https://#{hostname}/cool/content" } let(:html) do @@ -646,7 +644,7 @@ RSpec.describe Oneboxer do end end - context "register_local_handler" do + describe "register_local_handler" do it "calls registered local handler" do Oneboxer.register_local_handler('wizard') do |url, route| 'Custom Onebox for Wizard' diff --git a/spec/lib/plain_text_to_markdown_spec.rb b/spec/lib/plain_text_to_markdown_spec.rb index e358cf67b2..c6f9af3b70 100644 --- a/spec/lib/plain_text_to_markdown_spec.rb +++ b/spec/lib/plain_text_to_markdown_spec.rb @@ -9,7 +9,7 @@ RSpec.describe PlainTextToMarkdown do let(:nbsp) { " " } - context "quotes" do + describe "quotes" do it "uses the correct quote level" do expect(to_markdown("> foo")).to eq("> foo") expect(to_markdown(">>> foo")).to eq(">>> foo") @@ -47,7 +47,7 @@ RSpec.describe PlainTextToMarkdown do end end - context "special characters" do + describe "special characters" do it "escapes special Markdown characters" do expect(to_markdown('\ backslash')).to eq('\\\\ backslash') expect(to_markdown('` backtick')).to eq('\` backtick') @@ -77,7 +77,7 @@ RSpec.describe PlainTextToMarkdown do end end - context "indentation" do + describe "indentation" do it "does not replace one leading whitespace" do expect(to_markdown(" foo")).to eq(" foo") end @@ -106,7 +106,7 @@ RSpec.describe PlainTextToMarkdown do end end - context "format=flowed" do + describe "format=flowed" do it "concats lines ending with a space" do text = "Lorem ipsum dolor sit amet, consectetur \nadipiscing elit. Quasi vero, inquit, \nperpetua oratio rhetorum solum, non \netiam philosophorum sit." markdown = "Lorem ipsum dolor sit amet, consectetur adipiscing elit\\. Quasi vero, inquit, perpetua oratio rhetorum solum, non etiam philosophorum sit\\." @@ -157,7 +157,7 @@ RSpec.describe PlainTextToMarkdown do end end - context "links" do + describe "links" do it "removes duplicate links" do expect(to_markdown("foo https://www.example.com/foo.html?a=1 bar")) .to eq("foo https://www.example.com/foo.html?a=1 bar") @@ -186,7 +186,7 @@ RSpec.describe PlainTextToMarkdown do end end - context "code" do + describe "code" do it "detects matching Markdown code block within backticks" do expect(to_markdown("foo\n```\n\n```")).to eq("foo\n```\n\n```") end diff --git a/spec/lib/plugin/instance_spec.rb b/spec/lib/plugin/instance_spec.rb index 0556a98594..b22f10c8fd 100644 --- a/spec/lib/plugin/instance_spec.rb +++ b/spec/lib/plugin/instance_spec.rb @@ -1,12 +1,11 @@ # frozen_string_literal: true RSpec.describe Plugin::Instance do - after do DiscoursePluginRegistry.reset! end - context "find_all" do + describe "find_all" do it "can find plugins correctly" do plugins = Plugin::Instance.find_all("#{Rails.root}/spec/fixtures/plugins") expect(plugins.count).to eq(5) @@ -22,14 +21,12 @@ RSpec.describe Plugin::Instance do end end - context "enabling/disabling" do - + describe "enabling/disabling" do it "is enabled by default" do expect(Plugin::Instance.new.enabled?).to eq(true) end context "with a plugin that extends things" do - class Trout attr_accessor :data end @@ -128,7 +125,7 @@ RSpec.describe Plugin::Instance do end end - context "register asset" do + describe "register asset" do it "populates the DiscoursePluginRegistry" do plugin = Plugin::Instance.new nil, "/tmp/test.rb" plugin.register_asset("test.css") @@ -150,7 +147,7 @@ RSpec.describe Plugin::Instance do end end - context "register service worker" do + describe "register service worker" do it "populates the DiscoursePluginRegistry" do plugin = Plugin::Instance.new nil, "/tmp/test.rb" plugin.register_service_worker("test.js") @@ -210,7 +207,7 @@ RSpec.describe Plugin::Instance do expect(authenticator.enabled?).to eq(false) end - context "activate!" do + describe "#activate!" do before do # lets piggy back on another boolean setting, so we don't dirty our SiteSetting object SiteSetting.enable_badges = false @@ -271,7 +268,7 @@ RSpec.describe Plugin::Instance do end end - context "serialized_current_user_fields" do + describe "serialized_current_user_fields" do before do DiscoursePluginRegistry.serialized_current_user_fields << "has_car" end @@ -303,7 +300,7 @@ RSpec.describe Plugin::Instance do end end - context "register_color_scheme" do + describe "#register_color_scheme" do it "can add a color scheme for the first time" do plugin = Plugin::Instance.new nil, "/tmp/test.rb" expect { @@ -380,7 +377,7 @@ RSpec.describe Plugin::Instance do end end - context "locales" do + describe "locales" do let(:plugin_path) { "#{Rails.root}/spec/fixtures/plugins/custom_locales" } let!(:plugin) { Plugin::Instance.new(nil, "#{plugin_path}/plugin.rb") } let(:plural) do diff --git a/spec/lib/plugin/metadata_spec.rb b/spec/lib/plugin/metadata_spec.rb index f7d4d49231..922e6b92c5 100644 --- a/spec/lib/plugin/metadata_spec.rb +++ b/spec/lib/plugin/metadata_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true RSpec.describe Plugin::Metadata do - context "parse" do + describe "parse" do it "correctly parses plugin info" do metadata = Plugin::Metadata.parse < { "width" => 111, "height" => 222 } } } @@ -63,14 +62,14 @@ RSpec.describe PostCreator do expect(post.topic.custom_fields).to eq("hello" => "world") end - context "reply to post number" do + context "with reply to post number" do it "omits reply to post number if received on a new topic" do p = PostCreator.new(user, basic_topic_params.merge(reply_to_post_number: 3)).create expect(p.reply_to_post_number).to be_nil end end - context "invalid title" do + context "with invalid title" do let(:creator_invalid_title) { PostCreator.new(user, basic_topic_params.merge(title: 'a')) } it "has errors" do @@ -79,7 +78,7 @@ RSpec.describe PostCreator do end end - context "invalid raw" do + context "with invalid raw" do let(:creator_invalid_raw) { PostCreator.new(user, basic_topic_params.merge(raw: '')) } it "has errors" do @@ -88,7 +87,7 @@ RSpec.describe PostCreator do end end - context "success" do + context "with success" do before { creator } it "is not hidden" do @@ -477,11 +476,11 @@ RSpec.describe PostCreator do end end - context "tags" do + context "with tags" do let(:tag_names) { ['art', 'science', 'dance'] } let(:creator_with_tags) { PostCreator.new(user, basic_topic_params.merge(tags: tag_names)) } - context "tagging disabled" do + context "with tagging disabled" do before do SiteSetting.tagging_enabled = false end @@ -492,12 +491,12 @@ RSpec.describe PostCreator do end end - context "tagging enabled" do + context "with tagging enabled" do before do SiteSetting.tagging_enabled = true end - context "can create tags" do + context "when can create tags" do before do SiteSetting.min_trust_to_create_tag = 0 SiteSetting.min_trust_level_to_tag_topics = 0 @@ -516,7 +515,7 @@ RSpec.describe PostCreator do end end - context "cannot create tags" do + context "when cannot create tags" do before do SiteSetting.min_trust_to_create_tag = 4 SiteSetting.min_trust_level_to_tag_topics = 0 @@ -529,7 +528,7 @@ RSpec.describe PostCreator do end end - context "automatically tags first posts" do + context "when automatically tagging first posts" do before do SiteSetting.min_trust_to_create_tag = 0 SiteSetting.min_trust_level_to_tag_topics = 0 @@ -587,7 +586,7 @@ RSpec.describe PostCreator do end end - context 'whisper' do + describe 'whisper' do fab!(:topic) { Fabricate(:topic, user: user) } it 'whispers do not mess up the public view' do @@ -665,7 +664,7 @@ RSpec.describe PostCreator do end end - context 'silent' do + describe 'silent' do fab!(:topic) { Fabricate(:topic, user: user) } it 'silent do not mess up the public view' do @@ -695,13 +694,12 @@ RSpec.describe PostCreator do end end - context 'uniqueness' do - + describe 'uniqueness' do fab!(:topic) { Fabricate(:topic, user: user) } let(:basic_topic_params) { { raw: 'test reply', topic_id: topic.id, reply_to_post_number: 4 } } let(:creator) { PostCreator.new(user, basic_topic_params) } - context "disabled" do + context "when disabled" do before do SiteSetting.unique_posts_mins = 0 creator.create @@ -713,7 +711,7 @@ RSpec.describe PostCreator do end end - context 'enabled' do + context 'when enabled' do let(:new_post_creator) { PostCreator.new(user, basic_topic_params) } before do @@ -757,8 +755,7 @@ RSpec.describe PostCreator do end - context "host spam" do - + describe "host spam" do fab!(:topic) { Fabricate(:topic, user: user) } let(:basic_topic_params) { { raw: 'test reply', topic_id: topic.id, reply_to_post_number: 4 } } let(:creator) { PostCreator.new(user, basic_topic_params) } @@ -792,7 +789,7 @@ RSpec.describe PostCreator do end # more integration testing ... maximise our testing - context 'existing topic' do + describe 'existing topic' do fab!(:topic) { Fabricate(:topic, user: user, title: 'topic title with 25 chars') } let(:creator) { PostCreator.new(user, raw: 'test reply', topic_id: topic.id, reply_to_post_number: 4) } @@ -804,7 +801,7 @@ RSpec.describe PostCreator do expect(creator.errors.messages[:base][0]).to match I18n.t(:topic_not_found) end - context 'success' do + context 'with success' do it 'create correctly' do post = creator.create expect(Post.count).to eq(1) @@ -836,7 +833,7 @@ RSpec.describe PostCreator do end end - context "topic stats" do + context "with topic stats" do before do PostCreator.new( coding_horror, @@ -924,7 +921,7 @@ RSpec.describe PostCreator do end end - context 'closed topic' do + describe 'closed topic' do fab!(:topic) { Fabricate(:topic, user: user, closed: true) } let(:creator) { PostCreator.new(user, raw: 'test reply', topic_id: topic.id, reply_to_post_number: 4) } @@ -936,7 +933,7 @@ RSpec.describe PostCreator do end end - context 'missing topic' do + describe 'missing topic' do let(:topic) { Fabricate(:topic, user: user, deleted_at: 5.minutes.ago) } let(:creator) { PostCreator.new(user, raw: 'test reply', topic_id: topic.id, reply_to_post_number: 4) } @@ -948,7 +945,7 @@ RSpec.describe PostCreator do end end - context "cooking options" do + describe "cooking options" do let(:raw) { "this is my awesome message body hello world" } it "passes the cooking options through correctly" do @@ -963,7 +960,7 @@ RSpec.describe PostCreator do end # integration test ... minimise db work - context 'private message' do + describe 'private message' do let(:target_user1) { coding_horror } fab!(:target_user2) { Fabricate(:moderator) } fab!(:unrelated_user) { Fabricate(:user) } @@ -1067,7 +1064,7 @@ RSpec.describe PostCreator do end end - context "warnings" do + describe "warnings" do let(:target_user1) { coding_horror } fab!(:target_user2) { Fabricate(:moderator) } let(:base_args) do @@ -1105,7 +1102,7 @@ RSpec.describe PostCreator do end end - context 'auto closing' do + describe 'auto closing' do it 'closes private messages that have more than N posts' do SiteSetting.auto_close_messages_post_count = 2 @@ -1146,7 +1143,7 @@ RSpec.describe PostCreator do end end - context 'private message to group' do + describe 'private message to group' do let(:target_user1) { coding_horror } fab!(:target_user2) { Fabricate(:moderator) } let(:group) do @@ -1202,7 +1199,7 @@ RSpec.describe PostCreator do end end - context 'setting created_at' do + describe 'setting created_at' do it 'supports Time instances' do freeze_time @@ -1248,7 +1245,7 @@ RSpec.describe PostCreator do end end - context 'disable validations' do + describe 'disable validations' do it 'can save a post' do creator = PostCreator.new(user, raw: 'q', title: 'q', skip_validations: true) creator.create @@ -1268,7 +1265,6 @@ RSpec.describe PostCreator do end describe "embed_url" do - let(:embed_url) { "http://eviltrout.com/stupid-url" } it "creates the topic_embed record" do @@ -1319,7 +1315,7 @@ RSpec.describe PostCreator do expect(post.raw).to eq(" <-- whitespaces -->") end - context "events" do + describe "events" do before do @posts_created = 0 @topics_created = 0 @@ -1350,7 +1346,7 @@ RSpec.describe PostCreator do end end - context "staged users" do + describe "staged users" do fab!(:staged) { Fabricate(:staged) } it "automatically watches all messages it participates in" do @@ -1364,7 +1360,7 @@ RSpec.describe PostCreator do end end - context "topic tracking" do + describe "topic tracking" do it "automatically watches topic based on preference" do user.user_option.notification_level_when_replying = 3 @@ -1486,7 +1482,7 @@ RSpec.describe PostCreator do end end - context 'private message to a user that has disabled private messages' do + describe 'private message to a user that has disabled private messages' do fab!(:another_user) { Fabricate(:user, username: 'HelloWorld') } before do @@ -1522,7 +1518,7 @@ RSpec.describe PostCreator do end end - context "private message to a muted user" do + describe "private message to a muted user" do fab!(:muted_me) { evil_trout } fab!(:another_user) { Fabricate(:user) } @@ -1563,7 +1559,7 @@ RSpec.describe PostCreator do end end - context "private message to an ignored user" do + describe "private message to an ignored user" do fab!(:ignorer) { evil_trout } fab!(:another_user) { Fabricate(:user) } @@ -1605,7 +1601,7 @@ RSpec.describe PostCreator do end - context "private message to user in allow list" do + describe "private message to user in allow list" do fab!(:sender) { evil_trout } fab!(:allowed_user) { Fabricate(:user) } @@ -1651,7 +1647,7 @@ RSpec.describe PostCreator do end end - context "private message to user not in allow list" do + describe "private message to user not in allow list" do fab!(:sender) { evil_trout } fab!(:allowed_user) { Fabricate(:user) } fab!(:not_allowed_user) { Fabricate(:user) } @@ -1693,7 +1689,7 @@ RSpec.describe PostCreator do end end - context "private message when post author is admin who is not in allow list" do + describe "private message when post author is admin who is not in allow list" do fab!(:staff_user) { Fabricate(:admin) } fab!(:allowed_user) { Fabricate(:user) } fab!(:not_allowed_user) { Fabricate(:user) } @@ -1712,7 +1708,7 @@ RSpec.describe PostCreator do end end - context "private message to multiple users and one is not allowed" do + describe "private message to multiple users and one is not allowed" do fab!(:sender) { evil_trout } fab!(:allowed_user) { Fabricate(:user) } fab!(:not_allowed_user) { Fabricate(:user) } @@ -1740,7 +1736,7 @@ RSpec.describe PostCreator do end end - context "private message recipients limit (max_allowed_message_recipients) reached" do + describe "private message recipients limit (max_allowed_message_recipients) reached" do fab!(:target_user1) { coding_horror } fab!(:target_user2) { evil_trout } fab!(:target_user3) { Fabricate(:walter_white) } @@ -1776,10 +1772,10 @@ RSpec.describe PostCreator do end end - context "always succeeds if the user is staff" do + context "if the user is staff" do fab!(:staff_user) { Fabricate(:admin) } - it 'when sending message to multiple recipients' do + it 'succeeds when sending message to multiple recipients' do pc = PostCreator.new( staff_user, title: 'this message is for multiple recipients!', @@ -1828,7 +1824,7 @@ RSpec.describe PostCreator do end end - context "secure media uploads" do + describe "secure media uploads" do fab!(:image_upload) { Fabricate(:upload, secure: true) } fab!(:user2) { Fabricate(:user) } fab!(:public_topic) { Fabricate(:topic) } @@ -1849,7 +1845,7 @@ RSpec.describe PostCreator do end end - context 'queue for review' do + describe 'queue for review' do before { SiteSetting.review_every_post = true } it 'created a reviewable post after creating the post' do diff --git a/spec/lib/post_destroyer_spec.rb b/spec/lib/post_destroyer_spec.rb index 56f120a187..019db8de92 100644 --- a/spec/lib/post_destroyer_spec.rb +++ b/spec/lib/post_destroyer_spec.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true RSpec.describe PostDestroyer do - before do UserActionManager.enable end @@ -12,7 +11,6 @@ RSpec.describe PostDestroyer do let(:post) { create_post } describe "destroy_old_hidden_posts" do - it "destroys posts that have been hidden for 30 days" do now = Time.now @@ -44,7 +42,6 @@ RSpec.describe PostDestroyer do expect(reply3.deleted_at).to eq(nil) expect(reply4.deleted_at).to eq(nil) end - end describe 'destroy_old_stubs' do @@ -214,8 +211,7 @@ RSpec.describe PostDestroyer do expect(recovered_topic.deleted_by_id).to be_nil end - context "recover" do - + context "with recover" do it "doesn't raise an error when the raw doesn't change" do PostRevisor.new(@reply).revise!( @user, @@ -256,7 +252,7 @@ RSpec.describe PostDestroyer do end end - context "recovered by admin" do + context "when recovered by admin" do it "should set user_deleted to false" do PostDestroyer.new(@user, @reply).destroy expect(@reply.reload.user_deleted).to eq(true) @@ -286,7 +282,7 @@ RSpec.describe PostDestroyer do expect(UserAction.where(target_topic_id: post.topic_id, action_type: UserAction::REPLY).count).to eq(1) end - context "recovered by user with access to moderate topic category" do + context "when recovered by user with access to moderate topic category" do fab!(:review_user) { Fabricate(:user) } before do @@ -530,7 +526,7 @@ RSpec.describe PostDestroyer do end end - context "deleted by user with access to moderate topic category" do + context "when deleted by user with access to moderate topic category" do fab!(:review_user) { Fabricate(:user) } before do @@ -606,7 +602,7 @@ RSpec.describe PostDestroyer do end - context 'private message' do + describe 'private message' do fab!(:author) { Fabricate(:user) } fab!(:private_message) { Fabricate(:private_message_topic, user: author) } fab!(:first_post) { Fabricate(:post, topic: private_message, user: author) } @@ -665,8 +661,7 @@ RSpec.describe PostDestroyer do end end - context 'deleting the second post in a topic' do - + describe 'deleting the second post in a topic' do fab!(:user) { Fabricate(:user) } let!(:post) { create_post(user: user) } let(:topic) { post.topic } @@ -690,8 +685,7 @@ RSpec.describe PostDestroyer do expect(topic.highest_post_number).to eq(post.post_number) end - context 'topic_user' do - + context 'with topic_user' do let(:topic_user) { second_user.topic_users.find_by(topic_id: topic.id) } it 'clears the posted flag for the second user' do @@ -704,7 +698,7 @@ RSpec.describe PostDestroyer do end end - context "deleting a post belonging to a deleted topic" do + describe "deleting a post belonging to a deleted topic" do let!(:topic) { post.topic } let(:author) { post.user } @@ -747,7 +741,7 @@ RSpec.describe PostDestroyer do end end - context "deleting a reply belonging to a deleted topic" do + describe "deleting a reply belonging to a deleted topic" do let!(:topic) { post.topic } let!(:reply) { create_post(topic_id: topic.id, user: post.user) } let(:author) { reply.user } @@ -802,7 +796,6 @@ RSpec.describe PostDestroyer do end describe 'after delete' do - fab!(:coding_horror) { coding_horror } fab!(:post) { Fabricate(:post, raw: "Hello @CodingHorror") } @@ -834,8 +827,7 @@ RSpec.describe PostDestroyer do end end - describe 'with a reply' do - + context 'with a reply' do fab!(:reply) { Fabricate(:basic_reply, user: coding_horror, topic: post.topic) } let!(:post_reply) { PostReply.create(post_id: post.id, reply_post_id: reply.id) } @@ -858,12 +850,10 @@ RSpec.describe PostDestroyer do p = Fabricate(:post, user: post.user, topic: post.topic) expect(p.post_number).to eq(3) end - end - end - context '@mentions' do + describe '@mentions' do it 'removes notifications when deleted' do Jobs.run_immediately! user = Fabricate(:evil_trout) diff --git a/spec/lib/post_revisor_spec.rb b/spec/lib/post_revisor_spec.rb index e6e64806bc..f1d0918398 100644 --- a/spec/lib/post_revisor_spec.rb +++ b/spec/lib/post_revisor_spec.rb @@ -3,7 +3,6 @@ require 'post_revisor' RSpec.describe PostRevisor do - fab!(:topic) { Fabricate(:topic) } fab!(:newuser) { Fabricate(:newuser, last_seen_at: Date.today) } fab!(:user) { Fabricate(:user) } @@ -12,7 +11,7 @@ RSpec.describe PostRevisor do fab!(:moderator) { Fabricate(:moderator) } let(:post_args) { { user: newuser, topic: topic } } - context 'TopicChanges' do + describe 'TopicChanges' do let(:tc) { topic.reload PostRevisor::TopicChanges.new(topic, topic.user) @@ -43,7 +42,7 @@ RSpec.describe PostRevisor do end end - context 'editing category' do + describe 'editing category' do it "triggers the :post_edited event with topic_changed?" do category = Fabricate(:category) category.set_permissions(everyone: :full) @@ -124,7 +123,7 @@ RSpec.describe PostRevisor do end end - context 'editing tags' do + describe 'editing tags' do fab!(:post) { Fabricate(:post) } subject { PostRevisor.new(post) } @@ -152,8 +151,7 @@ RSpec.describe PostRevisor do end end - context 'revise wiki' do - + describe 'revise wiki' do before do # There used to be a bug where wiki changes were considered posting "too similar" # so this is enabled and checked @@ -170,7 +168,7 @@ RSpec.describe PostRevisor do end end - context 'revise' do + describe 'revise' do let(:post) { Fabricate(:post, post_args) } let(:first_version_at) { post.last_version_at } @@ -473,7 +471,6 @@ RSpec.describe PostRevisor do end describe 'category topic' do - let!(:category) do category = Fabricate(:category) category.update_column(:topic_id, topic.id) @@ -486,7 +483,7 @@ RSpec.describe PostRevisor do expect(category.description).to be_blank end - context "one paragraph description" do + context "with one paragraph description" do before do subject.revise!(post.user, raw: new_description) category.reload @@ -501,7 +498,7 @@ RSpec.describe PostRevisor do end end - context "multiple paragraph description" do + context "with multiple paragraph description" do before do subject.revise!(post.user, raw: "#{new_description}\n\nOther content goes here.") category.reload @@ -516,7 +513,7 @@ RSpec.describe PostRevisor do end end - context "invalid description without paragraphs" do + context "with invalid description without paragraphs" do before do subject.revise!(post.user, raw: "# This is a title") category.reload @@ -670,8 +667,7 @@ RSpec.describe PostRevisor do end.to change { post.user.user_stat.post_edits_count.to_i }.by(1) end - context 'second poster posts again quickly' do - + context 'when second poster posts again quickly' do it 'is a grace period edit, because the second poster posted again quickly' do SiteSetting.editing_grace_period = 1.minute subject.revise!(changed_by, { raw: 'yet another updated body' }, revised_at: post.updated_at + 10.seconds) @@ -682,7 +678,7 @@ RSpec.describe PostRevisor do end end - context 'passing skip_revision as true' do + context 'when passing skip_revision as true' do before do SiteSetting.editing_grace_period = 1.minute subject.revise!(changed_by, { raw: 'yet another updated body' }, revised_at: post.updated_at + 10.hours, skip_revision: true) @@ -773,7 +769,7 @@ RSpec.describe PostRevisor do end end - context "logging staff edits" do + context "when logging staff edits" do it "doesn't log when a regular user revises a post" do subject.revise!( post.user, @@ -829,7 +825,7 @@ RSpec.describe PostRevisor do end end - context "logging group moderator edits" do + context "when logging group moderator edits" do fab!(:group_user) { Fabricate(:group_user) } fab!(:category) { Fabricate(:category, reviewable_by_group_id: group_user.group.id, topic: topic) } @@ -851,9 +847,8 @@ RSpec.describe PostRevisor do end end - context "staff_edit_locks_post" do - - context "disabled" do + context "with staff_edit_locks_post" do + context "when disabled" do before do SiteSetting.staff_edit_locks_post = false end @@ -870,8 +865,7 @@ RSpec.describe PostRevisor do end end - context "enabled" do - + context "when enabled" do before do SiteSetting.staff_edit_locks_post = true end @@ -943,8 +937,7 @@ RSpec.describe PostRevisor do end end - context "alerts" do - + context "with alerts" do fab!(:mentioned_user) { Fabricate(:user) } before do @@ -965,8 +958,8 @@ RSpec.describe PostRevisor do end - context "tagging" do - context "tagging disabled" do + context "with tagging" do + context "with tagging disabled" do before do SiteSetting.tagging_enabled = false end @@ -979,12 +972,12 @@ RSpec.describe PostRevisor do end end - context "tagging enabled" do + context "with tagging enabled" do before do SiteSetting.tagging_enabled = true end - context "can create tags" do + context "when can create tags" do before do SiteSetting.min_trust_to_create_tag = 0 SiteSetting.min_trust_level_to_tag_topics = 0 @@ -1085,7 +1078,7 @@ RSpec.describe PostRevisor do end end - context "hidden tags" do + context "with hidden tags" do let(:bumped_at) { 1.day.ago } before do @@ -1146,7 +1139,7 @@ RSpec.describe PostRevisor do end end - context "required tag group" do + context "with required tag group" do fab!(:tag1) { Fabricate(:tag) } fab!(:tag2) { Fabricate(:tag) } fab!(:tag3) { Fabricate(:tag) } @@ -1179,7 +1172,7 @@ RSpec.describe PostRevisor do end end - context "cannot create tags" do + context "when cannot create tags" do before do SiteSetting.min_trust_to_create_tag = 4 SiteSetting.min_trust_level_to_tag_topics = 0 @@ -1198,7 +1191,7 @@ RSpec.describe PostRevisor do end end - context "uploads" do + context "with uploads" do let(:image1) { Fabricate(:upload) } let(:image2) { Fabricate(:upload) } let(:image3) { Fabricate(:upload) } @@ -1229,7 +1222,7 @@ RSpec.describe PostRevisor do expect(post.reload.upload_references.pluck(:upload_id)).to contain_exactly(image2.id, image3.id, image4.id) end - context "secure media uploads" do + context "with secure media uploads" do let!(:image5) { Fabricate(:secure_upload) } before do Jobs.run_immediately! diff --git a/spec/lib/pretty_text/helpers_spec.rb b/spec/lib/pretty_text/helpers_spec.rb index f39680ee3c..d1c72183f6 100644 --- a/spec/lib/pretty_text/helpers_spec.rb +++ b/spec/lib/pretty_text/helpers_spec.rb @@ -1,8 +1,7 @@ # frozen_string_literal: true RSpec.describe PrettyText::Helpers do - - context "lookup_upload_urls" do + describe ".lookup_upload_urls" do let(:upload) { Fabricate(:upload) } it "should return cdn url if available" do @@ -16,5 +15,4 @@ RSpec.describe PrettyText::Helpers do expect(result[short_url][:url]).to eq("https://awesome.com#{upload.url}") end end - end diff --git a/spec/lib/pretty_text_spec.rb b/spec/lib/pretty_text_spec.rb index 02580f65ea..4974ead327 100644 --- a/spec/lib/pretty_text_spec.rb +++ b/spec/lib/pretty_text_spec.rb @@ -21,8 +21,7 @@ RSpec.describe PrettyText do let(:wrapped_image) { "" } describe "Quoting" do - - describe "with avatar" do + context "with avatar" do let(:default_avatar) { "//test.localhost/uploads/default/avatars/42d/57c/46ce7ee487/{size}.png" } before do @@ -47,7 +46,7 @@ RSpec.describe PrettyText do expect(cook("[quote=\"EvilTrout, post:2, topic:#{topic.id}\"]\nddd\n[/quote]", topic_id: 1)).to eq(n(expected)) end - context "emojis" do + context "with emojis" do let(:md) do <<~MD > This is a quote with a regular emoji :upside_down_face: @@ -298,7 +297,7 @@ RSpec.describe PrettyText do end end - describe "with primary user group" do + context "with primary user group" do let(:default_avatar) { "//test.localhost/uploads/default/avatars/42d/57c/46ce7ee487/{size}.png" } fab!(:group) { Fabricate(:group) } fab!(:user) { Fabricate(:user, primary_group: group) } @@ -367,8 +366,8 @@ RSpec.describe PrettyText do expect(cooked.scan('quote]').length).to eq(0) end - describe "with letter avatar" do - context "subfolder" do + context "with letter avatar" do + context "with subfolder" do it "should have correct avatar url" do set_subfolder "/forum" md = <<~MD @@ -383,7 +382,6 @@ RSpec.describe PrettyText do end describe "Mentions" do - it "can handle mentions after abbr" do expect(PrettyText.cook("test test\n\n@bob")).to eq("

test test

\n

@bob

") end @@ -422,7 +420,7 @@ RSpec.describe PrettyText do end end - context 'subfolder' do + context 'with subfolder' do it "handles user and group mentions correctly" do set_subfolder "/forum" @@ -466,7 +464,7 @@ RSpec.describe PrettyText do ) end - describe 'when mentions are disabled' do + context 'when mentions are disabled' do before do SiteSetting.enable_mentions = false end @@ -727,7 +725,6 @@ RSpec.describe PrettyText do end describe "Excerpt" do - it "sanitizes attempts to inject invalid attributes" do spinner = "", 100)).to eq("[image]") end - context 'alt tags' do + context 'with alt tags' do it "should keep alt tags" do expect(PrettyText.excerpt("car", 100)).to eq("[car]") end @@ -754,7 +750,7 @@ RSpec.describe PrettyText do end end - context 'title tags' do + context 'with title tags' do it "should keep title tags" do expect(PrettyText.excerpt("", 100)).to eq("[car]") end @@ -796,7 +792,7 @@ RSpec.describe PrettyText do end end - context "emojis" do + context "with emojis" do it "should remove broken emoji" do html = <<~HTML \":bike:\" \":cat:\" \":discourse:\" @@ -987,7 +983,7 @@ RSpec.describe PrettyText do expect(PrettyText.excerpt(emoji_code, 100)).to eq(":heart:") end - context 'option to preserve onebox source' do + context 'with option to preserve onebox source' do it "should return the right excerpt" do onebox = "\n\n\n" expected = "meta.discourse.org" @@ -2166,7 +2162,7 @@ HTML expect(cooked).to match_html(html) end - context "customizing markdown-it rules" do + describe "customizing markdown-it rules" do it 'customizes the markdown-it rules correctly' do cooked = PrettyText.cook('This is some text **bold**', markdown_it_rules: []) @@ -2178,7 +2174,7 @@ HTML end end - context "enabling/disabling features" do + describe "enabling/disabling features" do it "allows features to be overridden" do cooked = PrettyText.cook(':grin: @mention', features_override: []) diff --git a/spec/lib/promotion_spec.rb b/spec/lib/promotion_spec.rb index 2312a4bca5..3f5e6be0f9 100644 --- a/spec/lib/promotion_spec.rb +++ b/spec/lib/promotion_spec.rb @@ -3,7 +3,6 @@ require 'promotion' RSpec.describe Promotion do - describe "review" do it "skips regular users" do # Reviewing users at higher trust levels is expensive, so trigger those reviews in a background job. @@ -14,8 +13,7 @@ RSpec.describe Promotion do end end - context "newuser" do - + describe "newuser" do fab!(:user) { Fabricate(:user, trust_level: TrustLevel[0], created_at: 2.days.ago) } let(:promotion) { Promotion.new(user) } @@ -23,7 +21,7 @@ RSpec.describe Promotion do expect { Promotion.new(nil).review }.not_to raise_error end - context 'that has done nothing' do + context 'when user has done nothing' do let!(:result) { promotion.review } it "returns false" do @@ -35,8 +33,7 @@ RSpec.describe Promotion do end end - context "that has done the requisite things" do - + context "when user has done the requisite things" do before do stat = user.user_stat stat.topics_entered = SiteSetting.tl1_requires_topics_entered @@ -54,7 +51,7 @@ RSpec.describe Promotion do end end - context "that has not done the requisite things" do + context "when user has not done the requisite things" do it "does not promote the user" do user.created_at = 1.minute.ago stat = user.user_stat @@ -67,7 +64,7 @@ RSpec.describe Promotion do end end - context "may send tl1 promotion messages" do + context "when may send tl1 promotion messages" do before do stat = user.user_stat stat.topics_entered = SiteSetting.tl1_requires_topics_entered @@ -112,7 +109,7 @@ RSpec.describe Promotion do end end - context "may send tl2 promotion messages" do + context "when may send tl2 promotion messages" do fab!(:user) { Fabricate(:user, trust_level: TrustLevel[1], created_at: (SiteSetting.tl2_requires_time_spent_mins * 60).minutes.ago) } before do @@ -142,12 +139,11 @@ RSpec.describe Promotion do end end - context "basic" do - + describe "basic" do fab!(:user) { Fabricate(:user, trust_level: TrustLevel[1], created_at: 2.days.ago) } let(:promotion) { Promotion.new(user) } - context 'that has done nothing' do + context 'when has done nothing' do let!(:result) { promotion.review } it "returns false" do @@ -159,8 +155,7 @@ RSpec.describe Promotion do end end - context "that has done the requisite things" do - + context "when has done the requisite things" do before do SiteSetting.tl2_requires_topic_reply_count = 3 @@ -213,11 +208,11 @@ RSpec.describe Promotion do end - context "regular" do + describe "regular" do fab!(:user) { Fabricate(:user, trust_level: TrustLevel[2]) } let(:promotion) { Promotion.new(user) } - context "doesn't qualify for promotion" do + context "when doesn't qualify for promotion" do before do TrustLevel3Requirements.any_instance.expects(:requirements_met?).at_least_once.returns(false) end @@ -241,7 +236,7 @@ RSpec.describe Promotion do end end - context "qualifies for promotion" do + context "when qualifies for promotion" do before do TrustLevel3Requirements.any_instance.expects(:requirements_met?).at_least_once.returns(true) end @@ -262,5 +257,4 @@ RSpec.describe Promotion do end end end - end diff --git a/spec/lib/rate_limiter_spec.rb b/spec/lib/rate_limiter_spec.rb index 4d9774d07c..83af13f8f6 100644 --- a/spec/lib/rate_limiter_spec.rb +++ b/spec/lib/rate_limiter_spec.rb @@ -3,7 +3,6 @@ require 'rate_limiter' RSpec.describe RateLimiter do - fab!(:user) { Fabricate(:user) } fab!(:admin) { Fabricate(:admin) } let(:rate_limiter) { RateLimiter.new(user, "peppermint-butler", 2, 60) } @@ -11,7 +10,7 @@ RSpec.describe RateLimiter do let(:staff_rate_limiter) { RateLimiter.new(user, "peppermind-servant", 5, 40, staff_limit: { max: 10, secs: 80 }) } let(:admin_staff_rate_limiter) { RateLimiter.new(admin, "peppermind-servant", 5, 40, staff_limit: { max: 10, secs: 80 }) } - context 'disabled' do + describe 'disabled' do before do rate_limiter.performed! rate_limiter.performed! @@ -28,10 +27,9 @@ RSpec.describe RateLimiter do it "doesn't raise an error on performed!" do expect { rate_limiter.performed! }.not_to raise_error end - end - context 'enabled' do + describe 'enabled' do before do RateLimiter.enable rate_limiter.clear! @@ -39,10 +37,8 @@ RSpec.describe RateLimiter do admin_staff_rate_limiter.clear! end - context 'aggressive rate limiter' do - + context 'with aggressive rate limiter' do it 'can operate correctly and totally stop limiting' do - freeze_time # 2 requests every 30 seconds @@ -76,12 +72,10 @@ RSpec.describe RateLimiter do expect { limiter.performed! }.not_to raise_error expect { limiter.performed! }.not_to raise_error - end end - context 'global rate limiter' do - + context 'with global rate limiter' do it 'can operate in global mode' do limiter = RateLimiter.new(nil, "test", 2, 30, global: true) limiter.clear! @@ -100,10 +94,9 @@ RSpec.describe RateLimiter do end expect(thrown).to be(true) end - end - context 'handles readonly' do + context 'when handling readonly' do before do # random IP address in the ULA range that does not exist Discourse.redis.without_namespace.slaveof 'fdec:3f5d:d0b7:4c4b:472b:636a:4370:7ac5', '49999' @@ -118,7 +111,7 @@ RSpec.describe RateLimiter do end end - context 'never done' do + context 'when never done' do it "should perform right away" do expect(rate_limiter.can_perform?).to eq(true) end @@ -128,7 +121,7 @@ RSpec.describe RateLimiter do end end - context "remaining" do + context "when remaining" do it "updates correctly" do expect(rate_limiter.remaining).to eq(2) rate_limiter.performed! @@ -138,8 +131,7 @@ RSpec.describe RateLimiter do end end - context 'max is less than or equal to zero' do - + context 'when max is less than or equal to zero' do it 'should raise the right error' do [-1, 0, nil].each do |max| expect do @@ -149,7 +141,7 @@ RSpec.describe RateLimiter do end end - context "multiple calls" do + context "with multiple calls" do before do freeze_time rate_limiter.performed! @@ -224,7 +216,7 @@ RSpec.describe RateLimiter do end end - context "rollback!" do + describe "#rollback!" do before do rate_limiter.rollback! end @@ -237,8 +229,6 @@ RSpec.describe RateLimiter do expect { rate_limiter.performed! }.not_to raise_error end end - end end - end diff --git a/spec/lib/retrieve_title_spec.rb b/spec/lib/retrieve_title_spec.rb index 13c39ae862..7edd62ff08 100644 --- a/spec/lib/retrieve_title_spec.rb +++ b/spec/lib/retrieve_title_spec.rb @@ -1,9 +1,7 @@ # frozen_string_literal: true RSpec.describe RetrieveTitle do - - context "extract_title" do - + describe ".extract_title" do it "will extract the value from the title tag" do title = RetrieveTitle.extract_title( "My Cool Title" @@ -55,7 +53,7 @@ RSpec.describe RetrieveTitle do end end - context "crawl" do + describe ".crawl" do it "can properly extract a title from a url" do stub_request(:get, "https://brelksdjflaskfj.com/amazing") .to_return(status: 200, body: "very amazing") @@ -156,7 +154,7 @@ RSpec.describe RetrieveTitle do end end - context 'fetch_title' do + describe '.fetch_title' do it "does not parse broken title tag" do # webmock does not do chunks stub_request(:get, "https://en.wikipedia.org/wiki/Internet"). diff --git a/spec/lib/rtl_spec.rb b/spec/lib/rtl_spec.rb index 9f051b83e8..f67aa0a5f9 100644 --- a/spec/lib/rtl_spec.rb +++ b/spec/lib/rtl_spec.rb @@ -1,17 +1,15 @@ # frozen_string_literal: true RSpec.describe Rtl do - let(:user) { Fabricate.build(:user) } describe '.css_class' do - - context 'user locale is allowed' do + context 'when user locale is allowed' do before { SiteSetting.allow_user_locale = true } - context 'user locale is RTL' do + context 'when user locale is RTL' do before { user.locale = 'he' } it 'returns rtl class' do @@ -19,18 +17,17 @@ RSpec.describe Rtl do end end - context 'user locale is not RTL' do + context 'when user locale is not RTL' do it 'returns empty class' do expect(Rtl.new(user).css_class).to eq('') end end - end - context 'user locale is not allowed' do + context 'when user locale is not allowed' do before { SiteSetting.allow_user_locale = false } - context 'site default locale is RTL' do + context 'when site default locale is RTL' do before { SiteSetting.default_locale = 'he' } it 'returns rtl class' do @@ -38,10 +35,10 @@ RSpec.describe Rtl do end end - context 'site default locale is LTR' do + context 'when site default locale is LTR' do before { SiteSetting.default_locale = 'en' } - context 'user locale is RTL' do + context 'when user locale is RTL' do before { user.stubs(:locale).returns('he') } it 'returns empty class' do @@ -50,6 +47,5 @@ RSpec.describe Rtl do end end end - end end diff --git a/spec/lib/s3_inventory_spec.rb b/spec/lib/s3_inventory_spec.rb index 6eee5355f1..ab215820d9 100644 --- a/spec/lib/s3_inventory_spec.rb +++ b/spec/lib/s3_inventory_spec.rb @@ -174,7 +174,7 @@ RSpec.describe "S3Inventory" do expect(Discourse.stats.get("missing_s3_uploads")).to eq(2) end - context "s3 inventory configuration" do + describe "s3 inventory configuration" do let(:bucket_name) { "s3-upload-bucket" } let(:subfolder_path) { "subfolder" } before do diff --git a/spec/lib/score_calculator_spec.rb b/spec/lib/score_calculator_spec.rb index 352630eed3..9506ec4a1a 100644 --- a/spec/lib/score_calculator_spec.rb +++ b/spec/lib/score_calculator_spec.rb @@ -3,7 +3,6 @@ require 'score_calculator' RSpec.describe ScoreCalculator do - fab!(:post) { Fabricate(:post, reads: 111) } fab!(:another_post) { Fabricate(:post, topic: post.topic, reads: 222) } let(:topic) { post.topic } @@ -28,11 +27,9 @@ RSpec.describe ScoreCalculator do it "gives the topic a score" do expect(topic.score).to be_present end - end - context 'summary' do - + describe 'summary' do it "won't update the site settings when the site settings don't match" do ScoreCalculator.new(reads: 3).calculate topic.reload @@ -68,7 +65,5 @@ RSpec.describe ScoreCalculator do topic.reload expect(topic.has_summary).to eq(true) end - end - end diff --git a/spec/lib/search_spec.rb b/spec/lib/search_spec.rb index f62e1f41e9..2be1c5dc53 100644 --- a/spec/lib/search_spec.rb +++ b/spec/lib/search_spec.rb @@ -60,7 +60,7 @@ RSpec.describe Search do SiteSetting.tagging_enabled = true end - context "staff tags" do + context "with staff 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, tags: [hidden_tag]) } @@ -85,7 +85,7 @@ RSpec.describe Search do end end - context "accents" do + context "with accents" do fab!(:post_1) { Fabricate(:post, raw: "Cette ****** d'art n'est pas une œuvre") } fab!(:post_2) { Fabricate(:post, raw: "Cette oeuvre d'art n'est pas une *****") } @@ -115,7 +115,7 @@ RSpec.describe Search do end end - context "custom_eager_load" do + describe "custom_eager_load" do fab!(:topic) { Fabricate(:topic) } fab!(:post) { Fabricate(:post, topic: topic) } @@ -146,7 +146,7 @@ RSpec.describe Search do end end - context "users" do + describe "users" do fab!(:user) { Fabricate(:user, username: "DonaldDuck") } fab!(:user2) { Fabricate(:user) } @@ -214,7 +214,7 @@ RSpec.describe Search do end end - context "categories" do + describe "categories" do it "finds topics in sub-sub-categories" do SiteSetting.max_category_nesting = 3 @@ -242,7 +242,7 @@ RSpec.describe Search do end end - context 'post indexing' do + describe 'post indexing' do fab!(:category) { Fabricate(:category_with_definition, name: 'america') } fab!(:topic) { Fabricate(:topic, title: 'sam saffron test topic', category: category) } let!(:post) { Fabricate(:post, topic: topic, raw: 'this fun test ') } @@ -283,7 +283,7 @@ RSpec.describe Search do end end - context 'user indexing' do + describe 'user indexing' do before do @user = Fabricate(:user, username: 'fred', name: 'bob jones') @indexed = @user.user_search_data.search_data @@ -295,7 +295,7 @@ RSpec.describe Search do end end - context 'category indexing' do + describe 'category indexing' do let!(:category) { Fabricate(:category_with_definition, name: 'america') } let!(:topic) { Fabricate(:topic, category: category) } let!(:post) { Fabricate(:post, topic: topic) } @@ -366,7 +366,7 @@ RSpec.describe Search do expect(search.term).to eq('a b c okaylength') end - context 'query sanitization' do + describe 'query sanitization' do let!(:post) { Fabricate(:post, raw: 'hello world') } it 'escapes backslash' do @@ -386,7 +386,7 @@ RSpec.describe Search do expect { Search.execute('evil trout') }.not_to raise_error end - context 'users' do + describe 'users' do let!(:user) { Fabricate(:user) } let(:result) { Search.execute('bruce', type_filter: 'user') } @@ -395,7 +395,7 @@ RSpec.describe Search do expect(result.users[0].id).to eq(user.id) end - context 'hiding user profiles' do + context 'when hiding user profiles' do before { SiteSetting.hide_user_profiles_from_public = true } it 'returns no result for anon' do @@ -409,7 +409,7 @@ RSpec.describe Search do end end - context 'inactive users' do + describe 'inactive users' do let!(:inactive_user) { Fabricate(:inactive_user, active: false) } let(:result) { Search.execute('bruce') } @@ -418,7 +418,7 @@ RSpec.describe Search do end end - context 'staged users' do + describe 'staged users' do let(:staged) { Fabricate(:staged) } let(:result) { Search.execute(staged.username) } @@ -427,7 +427,7 @@ RSpec.describe Search do end end - context 'private messages' do + describe 'private messages' do let!(:post) { Fabricate(:private_message_post) } let(:topic) { post.topic } @@ -533,7 +533,7 @@ RSpec.describe Search do end end - context 'personal_messages filter' do + context 'with personal_messages filter' do it 'does not allow a normal user to search for personal messages of another user' do expect do Search.execute( @@ -562,7 +562,7 @@ RSpec.describe Search do end end - context 'all-pms flag' do + context 'with all-pms flag' do it 'returns matching PMs if the user is an admin' do results = Search.execute('mars in:all-pms', guardian: Guardian.new(admin)) @@ -582,7 +582,7 @@ RSpec.describe Search do end end - context 'personal-direct and group_messages flags' do + context 'with personal-direct and group_messages flags' do let(:current) { Fabricate(:user, admin: true, username: "current_user") } let(:participant) { Fabricate(:user, username: "participant_1") } let(:participant_2) { Fabricate(:user, username: "participant_2") } @@ -610,7 +610,7 @@ RSpec.describe Search do pm.reload end - context "personal-direct flag" do + context "with personal-direct flag" do it 'can find all direct PMs of the current user' do pm = create_pm(users: [current, participant]) _pm_2 = create_pm(users: [participant_2, participant]) @@ -657,7 +657,7 @@ RSpec.describe Search do end end - context "group_messages flag" do + context "with group_messages flag" do it 'returns results correctly for a PM in a given group' do pm = create_pm(users: [participant, participant_2], group: group) @@ -700,7 +700,7 @@ RSpec.describe Search do end end - context 'all topics' do + context 'with all topics' do let!(:u1) { Fabricate(:user, username: 'fred', name: 'bob jones', email: 'foo+1@bar.baz') } let!(:u2) { Fabricate(:user, username: 'bob', name: 'fred jones', email: 'foo+2@bar.baz') } let!(:u3) { Fabricate(:user, username: 'jones', name: 'bob fred', email: 'foo+3@bar.baz') } @@ -765,7 +765,7 @@ RSpec.describe Search do end end - context 'posts' do + context 'with posts' do fab!(:post) do SearchIndexer.enable Fabricate(:post) @@ -935,11 +935,11 @@ RSpec.describe Search do end end - context 'topics' do + describe 'topics' do let(:post) { Fabricate(:post) } let(:topic) { post.topic } - context 'search within topic' do + context 'with search within topic' do def new_post(raw, topic = nil, created_at: nil) topic ||= Fabricate(:topic) Fabricate(:post, topic: topic, topic_id: topic.id, user: topic.user, raw: raw, created_at: created_at) @@ -990,7 +990,7 @@ RSpec.describe Search do end end - context 'searching the OP' do + context 'when searching the OP' do let!(:post) { Fabricate(:post_with_long_raw_content) } let(:result) { Search.execute('hundred', type_filter: 'topic') } @@ -1000,7 +1000,7 @@ RSpec.describe Search do end end - context 'searching for quoted title' do + context 'when searching for quoted title' do it "can find quoted title" do create_post(raw: "this is the raw body", title: "I am a title yeah") result = Search.execute('"a title yeah"') @@ -1009,7 +1009,7 @@ RSpec.describe Search do end end - context "search for a topic by id" do + context "when searching for a topic by id" do let(:result) { Search.execute(topic.id, type_filter: 'topic', search_for_id: true, min_search_term_length: 1) } it 'returns the topic' do @@ -1018,14 +1018,14 @@ RSpec.describe Search do end end - context "search for a topic by url" do + context "when searching for a topic by url" do it 'returns the topic' do result = Search.execute(topic.relative_url, search_for_id: true, type_filter: 'topic') expect(result.posts.length).to eq(1) expect(result.posts.first.id).to eq(post.id) end - context 'restrict_to_archetype' do + context 'with restrict_to_archetype' do let(:personal_message) { Fabricate(:private_message_topic) } let!(:p1) { Fabricate(:post, topic: personal_message, post_number: 1) } @@ -1047,7 +1047,7 @@ RSpec.describe Search do end end - context 'security' do + context 'with security' do def result(current_user) Search.execute('hello', guardian: Guardian.new(current_user)) end @@ -1068,7 +1068,7 @@ RSpec.describe Search do end end - context 'cyrillic topic' do + describe 'cyrillic topic' do let!(:cyrillic_topic) do Fabricate(:topic) do user @@ -1089,7 +1089,7 @@ RSpec.describe Search do expect(Search.execute('canned').posts).to be_present end - context 'categories' do + describe 'categories' do let(:category) { Fabricate(:category_with_definition, name: "monkey Category 2") } let(:topic) { Fabricate(:topic, category: category) } let!(:post) { Fabricate(:post, topic: topic, raw: "snow monkey") } @@ -1185,7 +1185,7 @@ RSpec.describe Search do end end - context 'groups' do + describe 'groups' do def search(user = Fabricate(:user)) Search.execute(group.name, guardian: Guardian.new(user)) end @@ -1196,20 +1196,20 @@ RSpec.describe Search do expect(search.groups.map(&:name)).to eq([group.name]) end - context 'group visibility' do + context 'with group visibility' do let!(:group) { Fabricate(:group) } before do group.update!(visibility_level: 3) end - context 'staff logged in' do + context 'with staff logged in' do it 'shows group' do expect(search(admin).groups.map(&:name)).to eq([group.name]) end end - context 'non staff logged in' do + context 'with non staff logged in' do it 'shows doesn’t show group' do expect(search.groups.map(&:name)).to be_empty end @@ -1217,7 +1217,7 @@ RSpec.describe Search do end end - context 'tags' do + describe 'tags' do def search Search.execute(tag.name) end @@ -1227,7 +1227,7 @@ RSpec.describe Search do let(:tag_group) { Fabricate(:tag_group) } let(:category) { Fabricate(:category_with_definition) } - context 'post searching' do + context 'with post searching' do before do SiteSetting.tagging_enabled = true DiscourseTagging.tag_topic_by_names(post.topic, Guardian.new(Fabricate.build(:admin)), [tag.name, uppercase_tag.name]) @@ -1260,7 +1260,7 @@ RSpec.describe Search do end end - context 'tagging is disabled' do + context 'when tagging is disabled' do before { SiteSetting.tagging_enabled = false } it 'does not include tags' do @@ -1268,7 +1268,7 @@ RSpec.describe Search do end end - context 'tagging is enabled' do + context 'when tagging is enabled' do before { SiteSetting.tagging_enabled = true } it 'returns the tag in the result' do @@ -1295,11 +1295,11 @@ RSpec.describe Search do end end - context 'type_filter' do + describe 'type_filter' do let!(:user) { Fabricate(:user, username: 'amazing', email: 'amazing@amazing.com') } let!(:category) { Fabricate(:category_with_definition, name: 'amazing category', user: user) } - context 'user filter' do + context 'with user filter' do let(:results) { Search.execute('amazing', type_filter: 'user') } it "returns a user result" do @@ -1309,7 +1309,7 @@ RSpec.describe Search do end end - context 'category filter' do + context 'with category filter' do let(:results) { Search.execute('amazing', type_filter: 'category') } it "returns a category result" do @@ -1320,7 +1320,7 @@ RSpec.describe Search do end end - context 'search_context' do + describe 'search_context' do it 'can find a user when using search context' do coding_horror = Fabricate(:coding_horror) post = Fabricate(:post) @@ -1369,7 +1369,7 @@ RSpec.describe Search do end end - context 'Japanese search' do + describe 'Japanese search' do let!(:topic) { Fabricate(:topic) } let!(:post) { Fabricate(:post, topic: topic, raw: 'This is some japanese text 日本が大好きです。') } let!(:topic_2) { Fabricate(:topic, title: '日本の話題、 more japanese text') } @@ -1598,7 +1598,7 @@ RSpec.describe Search do expect(Search.execute("@#{post_1.user.username}").posts).to contain_exactly(post_1) end - context "searching for posts made by users of a group" do + context "when searching for posts made by users of a group" do fab!(:topic) { Fabricate(:topic, created_at: 3.months.ago) } fab!(:user) { Fabricate(:user) } fab!(:user_2) { Fabricate(:user) } @@ -1910,7 +1910,7 @@ RSpec.describe Search do expect(results.posts.length).to eq(0) end - context 'tags' do + context 'with tags' do fab!(:tag1) { Fabricate(:tag, name: 'lunch') } fab!(:tag2) { Fabricate(:tag, name: 'eggs') } fab!(:tag3) { Fabricate(:tag, name: 'sandwiches') } @@ -2097,7 +2097,7 @@ RSpec.describe Search do end end - context "search_log_id" do + describe "search_log_id" do it "returns an id when the search succeeds" do s = Search.new( 'indiana jones', @@ -2115,7 +2115,7 @@ RSpec.describe Search do end end - context 'in:title' do + describe 'in:title' do it 'allows for search in title' do topic = Fabricate(:topic, title: 'I am testing a title search') _post2 = Fabricate(:post, topic: topic, raw: 'this is the second post', post_number: 2) @@ -2145,7 +2145,7 @@ RSpec.describe Search do end end - context 'ignore_diacritics' do + describe 'ignore_diacritics' do before { SiteSetting.search_ignore_accents = true } let!(:post1) { Fabricate(:post, raw: 'สวัสดี Rágis hello') } @@ -2167,7 +2167,7 @@ RSpec.describe Search do end end - context 'include_diacritics' do + describe 'include_diacritics' do before { SiteSetting.search_ignore_accents = false } let!(:post1) { Fabricate(:post, raw: 'สวัสดี Régis hello') } @@ -2188,7 +2188,7 @@ RSpec.describe Search do end end - context 'pagination' do + describe 'pagination' do let(:number_of_results) { 2 } let!(:post1) { Fabricate(:post, raw: 'hello hello hello hello hello') } let!(:post2) { Fabricate(:post, raw: 'hello hello hello hello') } @@ -2236,7 +2236,7 @@ RSpec.describe Search do end end - context 'header in-topic search' do + describe 'header in-topic search' do let!(:topic) { Fabricate(:topic, title: 'This is a topic with a bunch of posts') } let!(:post1) { Fabricate(:post, topic: topic, raw: 'hola amiga') } let!(:post2) { Fabricate(:post, topic: topic, raw: 'hola amigo') } @@ -2255,7 +2255,7 @@ RSpec.describe Search do end end - context 'in:tagged' do + describe 'in:tagged' do it 'allows for searching by presence of any tags' do topic = Fabricate(:topic, title: 'I am testing a tagged search') _post = Fabricate(:post, topic: topic, raw: 'this is the first post') @@ -2273,7 +2273,7 @@ RSpec.describe Search do end end - context 'in:untagged' do + describe 'in:untagged' do it 'allows for searching by presence of no tags' do topic = Fabricate(:topic, title: 'I am testing a untagged search') _post = Fabricate(:post, topic: topic, raw: 'this is the first post') @@ -2286,7 +2286,7 @@ RSpec.describe Search do end end - context 'plugin extensions' do + describe 'plugin extensions' do let!(:post0) { Fabricate(:post, raw: 'this is the first post about advanced filter with length more than 50 chars') } let!(:post1) { Fabricate(:post, raw: 'this is the second post about advanced filter') } @@ -2309,7 +2309,7 @@ RSpec.describe Search do end end - context 'exclude_topics filter' do + describe 'exclude_topics filter' do before { SiteSetting.tagging_enabled = true } let!(:user) { Fabricate(:user) } fab!(:group) { Fabricate(:group, name: 'bruce-world-fans') } diff --git a/spec/lib/second_factor/auth_manager_spec.rb b/spec/lib/second_factor/auth_manager_spec.rb index 4e08ea1ae0..bd39b82399 100644 --- a/spec/lib/second_factor/auth_manager_spec.rb +++ b/spec/lib/second_factor/auth_manager_spec.rb @@ -227,7 +227,7 @@ RSpec.describe SecondFactor::AuthManager do end end - context "returned results object" do + context "with returned results object" do it "has the correct status and contains the return value of the action hook that's called" do action = create_action action.expects(:skip_second_factor_auth?).with({}).returns(true).once diff --git a/spec/lib/site_setting_extension_spec.rb b/spec/lib/site_setting_extension_spec.rb index c51cbad66d..c26024b672 100644 --- a/spec/lib/site_setting_extension_spec.rb +++ b/spec/lib/site_setting_extension_spec.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true RSpec.describe SiteSettingExtension do - # We disable message bus here to avoid a large amount # of unneeded messaging, tests are careful to call refresh # when they need to. @@ -21,7 +20,7 @@ RSpec.describe SiteSettingExtension do end describe '#types' do - context "verify enum sequence" do + context "when verifying enum sequence" do before do @types = SiteSetting.types end @@ -73,7 +72,6 @@ RSpec.describe SiteSettingExtension do end describe "refresh!" do - it "will reset to default if provider vanishes" do settings.setting(:hello, 1) settings.hello = 100 @@ -585,8 +583,7 @@ RSpec.describe SiteSettingExtension do end describe "global override" do - - context "default_locale" do + context "with default_locale" do it "supports adding a default locale via a global" do global_setting :default_locale, 'zh_CN' settings.default_locale = 'en' @@ -835,5 +832,4 @@ RSpec.describe SiteSettingExtension do end end end - end diff --git a/spec/lib/site_settings/type_supervisor_spec.rb b/spec/lib/site_settings/type_supervisor_spec.rb index b1865c24b6..5e4a080174 100644 --- a/spec/lib/site_settings/type_supervisor_spec.rb +++ b/spec/lib/site_settings/type_supervisor_spec.rb @@ -19,7 +19,7 @@ RSpec.describe SiteSettings::TypeSupervisor do end describe '#types' do - context "verify enum sequence" do + context "when verifying enum sequence" do it "'string' should be at 1st position" do expect(SiteSettings::TypeSupervisor.types[:string]).to eq(1) end diff --git a/spec/lib/site_settings/validations_spec.rb b/spec/lib/site_settings/validations_spec.rb index 15c00d6efe..671730f8aa 100644 --- a/spec/lib/site_settings/validations_spec.rb +++ b/spec/lib/site_settings/validations_spec.rb @@ -5,7 +5,7 @@ require 'site_settings/validations' RSpec.describe SiteSettings::Validations do subject { Class.new.include(described_class).new } - context "default_categories" do + describe "default_categories" do fab!(:category) { Fabricate(:category) } it "supports valid categories" do @@ -31,7 +31,7 @@ RSpec.describe SiteSettings::Validations do end end - context "s3 buckets reusage" do + describe "s3 buckets reusage" do let(:error_message) { I18n.t("errors.site_settings.s3_bucket_reused") } shared_examples "s3 bucket validation" do @@ -308,7 +308,7 @@ RSpec.describe SiteSettings::Validations do end end - context "slow_down_crawler_user_agents" do + describe "slow_down_crawler_user_agents" do let(:too_short_message) do I18n.t( "errors.site_settings.slow_down_crawler_user_agent_must_be_at_least_3_characters" diff --git a/spec/lib/slug_spec.rb b/spec/lib/slug_spec.rb index 8e2c239c98..43615d4f3f 100644 --- a/spec/lib/slug_spec.rb +++ b/spec/lib/slug_spec.rb @@ -4,7 +4,6 @@ require 'slug' RSpec.describe Slug do - describe '#for' do let(:default_slug) { 'topic' } @@ -32,7 +31,7 @@ RSpec.describe Slug do expect(Slug.for(":smile: To Infinity and beyond! 🚀 :woman:t5:")).to eq("to-infinity-and-beyond") end - context 'ascii generator' do + context 'with ascii generator' do before { SiteSetting.slug_generation_method = 'ascii' } it 'generates the slug' do @@ -58,7 +57,7 @@ RSpec.describe Slug do end end - context 'encoded generator' do + context 'with encoded generator' do before { SiteSetting.slug_generation_method = 'encoded' } after { SiteSetting.slug_generation_method = 'ascii' } @@ -91,7 +90,7 @@ RSpec.describe Slug do end end - context 'none generator' do + context 'with none generator' do before { SiteSetting.slug_generation_method = 'none' } after { SiteSetting.slug_generation_method = 'ascii' } diff --git a/spec/lib/stylesheet/manager_spec.rb b/spec/lib/stylesheet/manager_spec.rb index 35c3402f08..9a24f9cb33 100644 --- a/spec/lib/stylesheet/manager_spec.rb +++ b/spec/lib/stylesheet/manager_spec.rb @@ -18,7 +18,7 @@ RSpec.describe Stylesheet::Manager do expect(link).not_to eq("") end - context "themes with components" do + describe "themes with components" do let(:child_theme) { Fabricate(:theme, component: true, name: "a component").tap { |c| c.set_field(target: :common, name: "scss", value: ".child_common{.scss{color: red;}}") c.set_field(target: :desktop, name: "scss", value: ".child_desktop{.scss{color: red;}}") @@ -148,7 +148,7 @@ RSpec.describe Stylesheet::Manager do }) end - context "stylesheet order" do + context "with stylesheet order" do let(:z_child_theme) do Fabricate(:theme, component: true, name: "ze component").tap do |z| z.set_field(target: :desktop, name: "scss", value: ".child_desktop{.scss{color: red;}}") @@ -607,7 +607,7 @@ RSpec.describe Stylesheet::Manager do expect(details1[:new_href]).not_to eq(details2[:new_href]) end - context "theme colors" do + context "with theme colors" do let(:theme) { Fabricate(:theme).tap { |t| t.set_field(target: :common, name: "color_definitions", value: ':root {--special: rebeccapurple;}') t.save! @@ -696,7 +696,7 @@ RSpec.describe Stylesheet::Manager do end end - context 'encoded slugs' do + context 'with encoded slugs' do before { SiteSetting.slug_generation_method = 'encoded' } after { SiteSetting.slug_generation_method = 'ascii' } diff --git a/spec/lib/suggested_topics_builder_spec.rb b/spec/lib/suggested_topics_builder_spec.rb index 42cd0ad126..ba24627f81 100644 --- a/spec/lib/suggested_topics_builder_spec.rb +++ b/spec/lib/suggested_topics_builder_spec.rb @@ -3,7 +3,6 @@ require 'suggested_topics_builder' RSpec.describe SuggestedTopicsBuilder do - fab!(:topic) { Fabricate(:topic) } let(:builder) { SuggestedTopicsBuilder.new(topic) } @@ -11,8 +10,7 @@ RSpec.describe SuggestedTopicsBuilder do SiteSetting.suggested_topics = 5 end - context "splicing category results" do - + describe "splicing category results" do def fake_topic(topic_id, category_id) build(:topic, id: topic_id, category_id: category_id) end @@ -57,8 +55,7 @@ RSpec.describe SuggestedTopicsBuilder do expect(builder).to be_full end - context "adding results" do - + describe "adding results" do it "adds nothing with nil results" do builder.add_results(nil) expect(builder.results_left).to eq(5) @@ -66,7 +63,7 @@ RSpec.describe SuggestedTopicsBuilder do expect(builder).not_to be_full end - context "adding topics" do + context "when adding topics" do fab!(:other_topic) { Fabricate(:topic) } before do @@ -81,10 +78,9 @@ RSpec.describe SuggestedTopicsBuilder do expect(builder.excluded_topic_ids.include?(topic.id)).to eq(true) expect(builder.excluded_topic_ids.include?(other_topic.id)).to eq(true) end - end - context "adding topics that are not open" do + context "when adding topics that are not open" do fab!(:archived_topic) { Fabricate(:topic, archived: true) } fab!(:closed_topic) { Fabricate(:topic, closed: true) } fab!(:invisible_topic) { Fabricate(:topic, visible: false) } @@ -96,7 +92,7 @@ RSpec.describe SuggestedTopicsBuilder do end end - context "category definition topics" do + context "when category definition topics" do fab!(:category) { Fabricate(:category_with_definition) } it "doesn't add a category definition topic" do @@ -106,7 +102,5 @@ RSpec.describe SuggestedTopicsBuilder do expect(builder).not_to be_full end end - end - end diff --git a/spec/lib/svg_sprite/svg_sprite_spec.rb b/spec/lib/svg_sprite/svg_sprite_spec.rb index cdaac927fb..40a027e087 100644 --- a/spec/lib/svg_sprite/svg_sprite_spec.rb +++ b/spec/lib/svg_sprite/svg_sprite_spec.rb @@ -151,7 +151,7 @@ RSpec.describe SvgSprite do expect(icons).to include("fly") end - context "s3" do + describe "s3" do let(:upload_s3) { Fabricate(:upload_s3) } before do @@ -283,6 +283,5 @@ RSpec.describe SvgSprite do expect(Upload.exists?(id: upload.id)).to eq(true) expect(SvgSprite.bundle(theme.id)).to match(/my-custom-theme-icon/) end - end end diff --git a/spec/lib/text_cleaner_spec.rb b/spec/lib/text_cleaner_spec.rb index ea1f60c207..42ad5d135b 100644 --- a/spec/lib/text_cleaner_spec.rb +++ b/spec/lib/text_cleaner_spec.rb @@ -3,9 +3,7 @@ require 'text_cleaner' RSpec.describe TextCleaner do - - context "exclamation marks" do - + describe "exclamation marks" do let(:duplicated_string) { "my precious!!!!" } let(:deduplicated_string) { "my precious!" } @@ -16,11 +14,9 @@ RSpec.describe TextCleaner do it "deduplicates ! when enabled" do expect(TextCleaner.clean(duplicated_string, deduplicate_exclamation_marks: true)).to eq(deduplicated_string) end - end - context "question marks" do - + describe "question marks" do let(:duplicated_string) { "please help me????" } let(:deduplicated_string) { "please help me?" } @@ -31,11 +27,9 @@ RSpec.describe TextCleaner do it "deduplicates ? when enabled" do expect(TextCleaner.clean(duplicated_string, deduplicate_question_marks: true)).to eq(deduplicated_string) end - end - context "all upper case text" do - + describe "all upper case text" do let(:all_caps) { "ENTIRE TEXT IS ALL CAPS" } let(:almost_all_caps) { "ENTIRE TEXT iS ALL CAPS" } let(:regular_case) { "entire text is all caps" } @@ -51,11 +45,9 @@ RSpec.describe TextCleaner do it "ignores almost all upper case text when enabled" do expect(TextCleaner.clean(almost_all_caps, replace_all_upper_case: true)).to eq(almost_all_caps) end - end - context "first letter" do - + describe "first letter" do let(:lowercased) { "this is awesome" } let(:capitalized) { "This is awesome" } let(:iletter) { "iLetter" } @@ -71,11 +63,9 @@ RSpec.describe TextCleaner do expect(TextCleaner.clean(capitalized, capitalize_first_letter: true)).to eq(capitalized) expect(TextCleaner.clean(iletter, capitalize_first_letter: true)).to eq(iletter) end - end - context "periods at the end" do - + describe "periods at the end" do let(:with_one_period) { "oops." } let(:with_several_periods) { "oops..." } let(:without_period) { "oops" } @@ -93,11 +83,9 @@ RSpec.describe TextCleaner do it "keeps trailing whitespaces when enabled" do expect(TextCleaner.clean(with_several_periods + " ", remove_all_periods_from_the_end: true)).to eq(without_period + " ") end - end - context "extraneous space" do - + describe "extraneous space" do let(:with_space_exclamation) { "oops !" } let(:without_space_exclamation) { "oops!" } let(:with_space_question) { "oops ?" } @@ -117,11 +105,9 @@ RSpec.describe TextCleaner do expect(TextCleaner.clean(with_space_exclamation + " ", remove_extraneous_space: true)).to eq(without_space_exclamation + " ") expect(TextCleaner.clean(with_space_question + " ", remove_extraneous_space: true)).to eq(without_space_question + " ") end - end - context "interior spaces" do - + describe "interior spaces" do let(:spacey_string) { "hello there's weird spaces here." } let(:unspacey_string) { "hello there's weird spaces here." } @@ -132,11 +118,9 @@ RSpec.describe TextCleaner do it "fixes interior spaces when enabled" do expect(TextCleaner.clean(spacey_string, fixes_interior_spaces: true)).to eq(unspacey_string) end - end - context "leading and trailing whitespaces" do - + describe "leading and trailing whitespaces" do let(:spacey_string) { " \t test \n " } let(:unspacey_string) { "test" } @@ -147,11 +131,9 @@ RSpec.describe TextCleaner do it "strips leading and trailing whitespaces when enabled" do expect(TextCleaner.clean(spacey_string, strip_whitespaces: true)).to eq(unspacey_string) end - end - context "title" do - + describe "title" do it "fixes interior spaces" do expect(TextCleaner.clean_title("Hello there")).to eq("Hello there") end @@ -165,8 +147,7 @@ RSpec.describe TextCleaner do expect(TextCleaner.clean_title("Hello​ ​there").length).to eq(11) end - context "title_prettify site setting is enabled" do - + context "when title_prettify site setting is enabled" do before { SiteSetting.title_prettify = true } it "deduplicates !" do @@ -223,7 +204,6 @@ RSpec.describe TextCleaner do expect(TextCleaner.clean_title("istanbul")).to eq("İstanbul") end end - end describe "#normalize_whitespaces" do @@ -242,7 +222,7 @@ RSpec.describe TextCleaner do end end - context "invalid byte sequence" do + describe "invalid byte sequence" do let(:with_invalid_bytes) { "abc\u3042\x81" } let(:without_invalid_bytes) { "abc\u3042" } diff --git a/spec/lib/text_sentinel_spec.rb b/spec/lib/text_sentinel_spec.rb index 510894c47d..78372f9941 100644 --- a/spec/lib/text_sentinel_spec.rb +++ b/spec/lib/text_sentinel_spec.rb @@ -4,13 +4,11 @@ require 'text_sentinel' RSpec.describe TextSentinel do - it "allows utf-8 chars" do expect(TextSentinel.new("йȝîûηыეமிᚉ⠛").text).to eq("йȝîûηыეமிᚉ⠛") end - context "entropy" do - + describe "entropy" do it "returns 0 for an empty string" do expect(TextSentinel.new("").entropy).to eq(0) end @@ -42,10 +40,9 @@ RSpec.describe TextSentinel do it "handles repeated foreign characters" do expect(TextSentinel.new("又一个测试话题" * 3).entropy).to eq(18) end - end - context 'body_sentinel' do + describe 'body_sentinel' do [ 'evil trout is evil', "去年十社會警告", "P.S. Пробирочка очень толковая и весьма умная, так что не обнимайтесь.", @@ -74,8 +71,7 @@ RSpec.describe TextSentinel do end end - context "validity" do - + describe "validity" do let(:valid_string) { "This is a cool topic about Discourse" } it "allows a valid string" do @@ -142,23 +138,19 @@ RSpec.describe TextSentinel do it "allows a long string with colons" do expect(TextSentinel.new("error in org.gradle.internal.graph.CachingDirectedGraphWalker:colon", max_word_length: 30)).to be_valid end - end - context 'title_sentinel' do - + describe 'title_sentinel' do it "uses a sensible min entropy value when min title length is less than title_min_entropy" do SiteSetting.min_topic_title_length = 3 SiteSetting.title_min_entropy = 10 expect(TextSentinel.title_sentinel('Hey')).to be_valid end - end - context 'seems_unpretentious?' do + describe '#seems_unpretentious?' do it 'works with nil title' do expect(TextSentinel.title_sentinel(nil).seems_unpretentious?).to eq(true) end end - end diff --git a/spec/lib/theme_settings_manager_spec.rb b/spec/lib/theme_settings_manager_spec.rb index 999650a4bf..11c1599dce 100644 --- a/spec/lib/theme_settings_manager_spec.rb +++ b/spec/lib/theme_settings_manager_spec.rb @@ -3,7 +3,6 @@ require 'theme_settings_manager' RSpec.describe ThemeSettingsManager do - let!(:theme) { Fabricate(:theme) } let(:theme_settings) do yaml = File.read("#{Rails.root}/spec/fixtures/theme_settings/valid_settings.yaml") @@ -16,7 +15,7 @@ RSpec.describe ThemeSettingsManager do theme_settings.find { |setting| setting.name == name } end - context "Enum" do + describe "Enum" do it "only accepts values from its choices" do enum_setting = find_by_name(:enum_setting) expect { enum_setting.value = "trust level 2" }.to raise_error(Discourse::InvalidParameters) @@ -32,7 +31,7 @@ RSpec.describe ThemeSettingsManager do end end - context "Bool" do + describe "Bool" do it "is either true or false" do bool_setting = find_by_name(:boolean_setting) expect(bool_setting.value).to eq(true) # default @@ -51,7 +50,7 @@ RSpec.describe ThemeSettingsManager do end end - context "Integer" do + describe "Integer" do it "is always an integer" do int_setting = find_by_name(:integer_setting) int_setting.value = 1.6 @@ -86,7 +85,7 @@ RSpec.describe ThemeSettingsManager do end end - context "Float" do + describe "Float" do it "is always a float" do float_setting = find_by_name(:float_setting) float_setting.value = 1.615 @@ -114,7 +113,7 @@ RSpec.describe ThemeSettingsManager do end end - context "String" do + describe "String" do it "can have min or max length" do string_setting = find_by_name(:string_setting_02) expect { string_setting.value = "a" }.to raise_error(Discourse::InvalidParameters) @@ -142,14 +141,14 @@ RSpec.describe ThemeSettingsManager do end end - context "List" do + describe "List" do it "can have a list type" do list_setting = find_by_name(:compact_list_setting) expect(list_setting.list_type).to eq("compact") end end - context "Upload" do + describe "Upload" do let!(:upload) { Fabricate(:upload) } it "saves the upload id" do diff --git a/spec/lib/theme_settings_parser_spec.rb b/spec/lib/theme_settings_parser_spec.rb index d17cad79c6..5590bbf529 100644 --- a/spec/lib/theme_settings_parser_spec.rb +++ b/spec/lib/theme_settings_parser_spec.rb @@ -48,7 +48,7 @@ RSpec.describe ThemeSettingsParser do expect(loader.find_by_name(:enum_setting)[:type]).to eq(types[:enum]) end - context "description locale" do + describe "description locale" do it "favors I18n.locale" do I18n.locale = :ar SiteSetting.default_locale = "en" @@ -72,7 +72,7 @@ RSpec.describe ThemeSettingsParser do end end - context "enum setting" do + describe "enum setting" do it "should never have less than 1 choices" do choices = loader.find_by_name(:enum_setting)[:opts][:choices] expect(choices.class).to eq(Array) @@ -84,7 +84,7 @@ RSpec.describe ThemeSettingsParser do end end - context "list setting" do + describe "list setting" do it "supports list type" do list_type = loader.find_by_name(:compact_list_setting)[:opts][:list_type] expect(list_type).to eq("compact") diff --git a/spec/lib/topic_creator_spec.rb b/spec/lib/topic_creator_spec.rb index cb90c46480..0b448a7cc1 100644 --- a/spec/lib/topic_creator_spec.rb +++ b/spec/lib/topic_creator_spec.rb @@ -18,7 +18,7 @@ RSpec.describe TopicCreator do end describe '#create' do - context 'topic success cases' do + context 'with topic success cases' do before do TopicCreator.any_instance.expects(:save_topic).returns(true) TopicCreator.any_instance.expects(:watch_topic).returns(true) @@ -45,7 +45,7 @@ RSpec.describe TopicCreator do expect(topic.custom_fields["import_id"]).to eq("bar") end - context 'regular user' do + context 'with regular user' do before { SiteSetting.min_trust_to_create_topic = TrustLevel[0] } it "should be possible for a regular user to create a topic" do @@ -81,7 +81,7 @@ RSpec.describe TopicCreator do end end - context 'tags' do + context 'with tags' do fab!(:tag1) { Fabricate(:tag, name: "fun") } fab!(:tag2) { Fabricate(:tag, name: "fun2") } fab!(:tag3) { Fabricate(:tag, name: "fun3") } @@ -96,7 +96,7 @@ RSpec.describe TopicCreator do SiteSetting.min_trust_level_to_tag_topics = 0 end - context 'regular tags' do + context 'with regular tags' do it "user can add tags to topic" do topic = TopicCreator.create(user, Guardian.new(user), valid_attrs.merge(tags: [tag1.name])) expect(topic).to be_valid @@ -123,7 +123,7 @@ RSpec.describe TopicCreator do end end - context 'staff-only tags' do + context 'with staff-only tags' do before do create_staff_only_tags(['alpha']) end @@ -141,7 +141,7 @@ RSpec.describe TopicCreator do end end - context 'minimum_required_tags is present' do + context 'when minimum_required_tags is present' do fab!(:category) { Fabricate(:category, name: "beta", minimum_required_tags: 2) } it "fails for regular user if minimum_required_tags is not satisfied" do @@ -176,7 +176,7 @@ RSpec.describe TopicCreator do end end - context 'required tag group' do + context 'with required tag group' do fab!(:tag_group) { Fabricate(:tag_group, tags: [tag1]) } fab!(:category) { Fabricate(:category, name: "beta", category_required_tag_groups: [CategoryRequiredTagGroup.new(tag_group: tag_group, min_count: 1)]) } @@ -343,7 +343,7 @@ RSpec.describe TopicCreator do ) end - context "and allows other tags" do + context "when allowing other tags" do before { category.update!(allow_global_tags: true) } it "allows topics to use tags that aren't restricted by any category" do @@ -403,9 +403,8 @@ RSpec.describe TopicCreator do end end - context 'personal message' do - - context 'success cases' do + context 'with personal message' do + context 'with success cases' do before do TopicCreator.any_instance.expects(:save_topic).returns(true) TopicCreator.any_instance.expects(:watch_topic).returns(true) @@ -429,7 +428,7 @@ RSpec.describe TopicCreator do end end - context 'failure cases' do + context 'with failure cases' do it "should be rollback the changes when email is invalid" do SiteSetting.manual_polling_enabled = true SiteSetting.reply_by_email_address = "sam+%{reply_key}@sam.com" @@ -452,7 +451,7 @@ RSpec.describe TopicCreator do end end - context 'to emails' do + context 'with to emails' do it 'works for staff' do SiteSetting.min_trust_to_send_email_messages = 'staff' expect(TopicCreator.create(admin, Guardian.new(admin), pm_to_email_valid_attrs)).to be_valid @@ -477,7 +476,7 @@ RSpec.describe TopicCreator do end end - context 'setting timestamps' do + context 'when setting timestamps' do it 'supports Time instances' do freeze_time @@ -506,7 +505,7 @@ RSpec.describe TopicCreator do end end - context 'external_id' do + context 'with external_id' do it 'adds external_id' do topic = TopicCreator.create(user, Guardian.new(user), valid_attrs.merge( external_id: 'external_id' diff --git a/spec/lib/topic_publisher_spec.rb b/spec/lib/topic_publisher_spec.rb index 825acd7de9..fc17d51134 100644 --- a/spec/lib/topic_publisher_spec.rb +++ b/spec/lib/topic_publisher_spec.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true require 'topic_publisher' -RSpec.describe TopicPublisher do - context "shared drafts" do +RSpec.describe TopicPublisher do + describe "shared drafts" do fab!(:shared_drafts_category) { Fabricate(:category) } fab!(:category) { Fabricate(:category) } @@ -11,7 +11,7 @@ RSpec.describe TopicPublisher do SiteSetting.shared_drafts_category = shared_drafts_category.id end - context "publishing" do + context "when publishing" do fab!(:topic) { Fabricate(:topic, category: shared_drafts_category, visible: false) } fab!(:shared_draft) { Fabricate(:shared_draft, topic: topic, category: category) } fab!(:moderator) { Fabricate(:moderator) } @@ -72,7 +72,5 @@ RSpec.describe TopicPublisher do expect(topic.tags).to contain_exactly(tag) end end - end - end diff --git a/spec/lib/topic_query/private_message_lists_spec.rb b/spec/lib/topic_query/private_message_lists_spec.rb index 6c06e1608c..d1c9409b57 100644 --- a/spec/lib/topic_query/private_message_lists_spec.rb +++ b/spec/lib/topic_query/private_message_lists_spec.rb @@ -99,7 +99,7 @@ RSpec.describe TopicQuery::PrivateMessageLists do expect(topics).to eq([]) end - context "Calculating minimum unread count for a topic" do + context "when calculating minimum unread count for a topic" do before do group.update!(publish_read_state: true) group.add(user) diff --git a/spec/lib/topic_query_spec.rb b/spec/lib/topic_query_spec.rb index 9cbb8cc68b..47a5c8a92d 100644 --- a/spec/lib/topic_query_spec.rb +++ b/spec/lib/topic_query_spec.rb @@ -3,7 +3,6 @@ require 'topic_view' RSpec.describe TopicQuery do - # TODO: # This fab! here has impact on all tests. # @@ -20,7 +19,7 @@ RSpec.describe TopicQuery do fab!(:moderator) { Fabricate(:moderator) } fab!(:admin) { Fabricate(:admin) } - context 'secure category' do + describe 'secure category' do it "filters categories out correctly" do category = Fabricate(:category_with_definition) group = Fabricate(:group) @@ -45,12 +44,10 @@ RSpec.describe TopicQuery do group.save expect(TopicQuery.new(user).list_latest.topics.count).to eq(2) - end - end - context "custom filters" do + describe "custom filters" do it "allows custom filters to be applied" do topic1 = Fabricate(:topic) _topic2 = Fabricate(:topic) @@ -66,7 +63,6 @@ RSpec.describe TopicQuery do end describe "#list_topics_by" do - it "allows users to view their own invisible topics" do _topic = Fabricate(:topic, user: user) _invisible_topic = Fabricate(:topic, user: user, visible: false) @@ -159,7 +155,7 @@ RSpec.describe TopicQuery do end end - context 'tracked' do + describe 'tracked' do it "filters tracked topics correctly" do SiteSetting.tagging_enabled = true @@ -228,7 +224,7 @@ RSpec.describe TopicQuery do end end - context 'deleted filter' do + describe 'deleted filter' do it "filters deleted topics correctly" do _topic = Fabricate(:topic, deleted_at: 1.year.ago) @@ -264,7 +260,7 @@ RSpec.describe TopicQuery do end end - context 'category filter' do + describe 'category filter' do let(:category) { Fabricate(:category_with_definition) } let(:diff_category) { Fabricate(:category_with_definition, name: "Different Category") } @@ -283,7 +279,7 @@ RSpec.describe TopicQuery do expect(TopicQuery.new(moderator, category: 'made up slug').list_latest.topics.size).to eq(2) end - context 'subcategories' do + context 'with subcategories' do let!(:subcategory) { Fabricate(:category_with_definition, parent_category_id: category.id) } let(:subsubcategory) { Fabricate(:category_with_definition, parent_category_id: subcategory.id) } @@ -385,7 +381,7 @@ RSpec.describe TopicQuery do end end - context 'tag filter' do + describe 'tag filter' do fab!(:tag) { Fabricate(:tag) } fab!(:other_tag) { Fabricate(:tag) } fab!(:uppercase_tag) { Fabricate(:tag, name: "HeLlO") } @@ -394,7 +390,7 @@ RSpec.describe TopicQuery do SiteSetting.tagging_enabled = true end - context "no category filter" do + context "with no category filter" do fab!(:tagged_topic1) { Fabricate(:topic, tags: [tag]) } fab!(:tagged_topic2) { Fabricate(:topic, tags: [other_tag]) } fab!(:tagged_topic3) { Fabricate(:topic, tags: [tag, other_tag]) } @@ -460,7 +456,7 @@ RSpec.describe TopicQuery do end end - context 'remove_muted_tags' do + context 'when remove_muted_tags is enabled' do fab!(:topic) { Fabricate(:topic, tags: [tag]) } before do @@ -473,7 +469,7 @@ RSpec.describe TopicQuery do end end - context "and categories too" do + context "with categories too" do let(:category1) { Fabricate(:category_with_definition) } let(:category2) { Fabricate(:category_with_definition) } @@ -489,7 +485,7 @@ RSpec.describe TopicQuery do end end - context 'muted categories' do + describe 'muted categories' do it 'is removed from top, new and latest lists' do category = Fabricate(:category_with_definition) topic = Fabricate(:topic, category: category) @@ -521,7 +517,7 @@ RSpec.describe TopicQuery do end end - context 'mute_all_categories_by_default' do + describe 'mute_all_categories_by_default' do fab!(:category) { Fabricate(:category_with_definition) } fab!(:topic) { Fabricate(:topic, category: category) } @@ -559,7 +555,7 @@ RSpec.describe TopicQuery do end end - context 'already seen topics' do + describe 'already seen topics' do it 'is removed from new and visible on latest lists' do category = Fabricate(:category_with_definition) topic = Fabricate(:topic, category: category) @@ -572,7 +568,7 @@ RSpec.describe TopicQuery do end end - context 'muted tags' do + describe 'muted tags' do it 'is removed from new and latest lists' do SiteSetting.tagging_enabled = true SiteSetting.remove_muted_tags_from_latest = 'always' @@ -628,7 +624,7 @@ RSpec.describe TopicQuery do end end - context 'a bunch of topics' do + describe 'a bunch of topics' do fab!(:regular_topic) do Fabricate(:topic, title: 'this is a regular topic', user: creator, @@ -691,7 +687,7 @@ RSpec.describe TopicQuery do let(:topics) { topic_query.list_latest.topics } - context 'list_latest' do + context 'with list_latest' do it "returns the topics in the correct order" do expect(topics.map(&:id)).to eq([pinned_topic, future_topic, closed_topic, archived_topic, regular_topic].map(&:id)) @@ -702,8 +698,7 @@ RSpec.describe TopicQuery do expect(TopicQuery.new(admin).list_latest.topics.include?(invisible_topic)).to eq(true) end - context 'sort_order' do - + context 'with sort_order' do def ids_in_order(order, descending = true) TopicQuery.new(admin, order: order, ascending: descending ? 'false' : 'true').list_latest.topics.map(&:id) end @@ -757,11 +752,8 @@ RSpec.describe TopicQuery do # returns the topics in reverse sheep order if requested" do expect(ids_in_order('sheep', false)).to eq([invisible_topic, regular_topic, closed_topic, pinned_topic, future_topic, archived_topic].map(&:id)) - end - end - end context 'after clearing a pinned topic' do @@ -773,10 +765,9 @@ RSpec.describe TopicQuery do expect(topics).to eq([future_topic, closed_topic, archived_topic, pinned_topic, regular_topic]) end end - end - context 'categorized' do + describe 'categorized' do fab!(:category) { Fabricate(:category_with_definition) } let(:topic_category) { category.topic } fab!(:topic_no_cat) { Fabricate(:topic) } @@ -825,8 +816,7 @@ RSpec.describe TopicQuery do end end - context 'unread / read topics' do - + describe 'unread / read topics' do context 'with no data' do it "has no unread topics" do expect(topic_query.list_unread.topics).to be_blank @@ -868,7 +858,7 @@ RSpec.describe TopicQuery do TopicUser.update_last_read(user, fully_read.id, 1, 1, 0) end - context 'list_unread' do + context 'with list_unread' do it 'lists topics correctly' do _new_topic = Fabricate(:post, user: creator).topic @@ -877,7 +867,7 @@ RSpec.describe TopicQuery do end end - context 'user with auto_track_topics list_unread' do + context 'with user with auto_track_topics list_unread' do before do user.user_option.auto_track_topics_after_msecs = 0 user.user_option.save @@ -887,20 +877,17 @@ RSpec.describe TopicQuery do expect(topic_query.list_unread.topics).to eq([partially_read]) end end - end - end describe '#list_new' do - context 'without a new topic' do it "has no new topics" do expect(topic_query.list_new.topics).to be_blank end end - context 'preload api' do + context 'when preloading api' do it "preloads data correctly" do TopicList.preloaded_custom_fields << "tag" TopicList.preloaded_custom_fields << "age" @@ -925,7 +912,6 @@ RSpec.describe TopicQuery do # if we attempt to access non preloaded fields explode expect { new_topic.custom_fields["boom"] }.to raise_error(StandardError) - end end @@ -944,7 +930,7 @@ RSpec.describe TopicQuery do expect(topic_query.list_new.topics).to eq([]) end - context "muted topics" do + context "with muted topics" do before do new_topic.notify_muted!(user) end @@ -954,7 +940,7 @@ RSpec.describe TopicQuery do expect(topic_query.list_latest.topics).to be_blank end - context 'un-muted' do + context 'when un-muted' do before do new_topic.notify_tracking!(user) end @@ -966,7 +952,6 @@ RSpec.describe TopicQuery do end end end - end describe '#list_posted' do @@ -976,7 +961,7 @@ RSpec.describe TopicQuery do expect(topics).to be_blank end - context 'created topics' do + context 'with created topics' do let!(:created_topic) { create_post(user: user).topic } it "includes the created topic" do @@ -984,7 +969,7 @@ RSpec.describe TopicQuery do end end - context "topic you've posted in" do + context "with topic you've posted in" do let(:other_users_topic) { create_post(user: creator).topic } let!(:your_post) { create_post(user: user, topic: other_users_topic) } @@ -993,15 +978,14 @@ RSpec.describe TopicQuery do end end - context "topic you haven't posted in" do + context "with topic you haven't posted in" do let(:other_users_topic) { create_post(user: creator).topic } it "does not include the topic" do expect(topics).to be_blank end - context "but interacted with" do - + context "with topic you interacted with" do it "is not included if read" do TopicUser.update_last_read(user, other_users_topic.id, 0, 0, 0) @@ -1075,7 +1059,6 @@ RSpec.describe TopicQuery do end describe '#list_related_for' do - let(:user) do Fabricate(:admin) end @@ -1132,7 +1115,7 @@ RSpec.describe TopicQuery do end end - context 'suggested_for' do + describe 'suggested_for' do def clear_cache! Discourse.redis.keys('random_topic_cache*').each { |k| Discourse.redis.del k } end @@ -1150,7 +1133,7 @@ RSpec.describe TopicQuery do end end - context "anonymously browsing with invisible, closed and archived" do + context "when anonymously browsing with invisible, closed and archived" do let!(:topic) { Fabricate(:topic) } let!(:regular_topic) { Fabricate(:post, user: creator).topic } let!(:closed_topic) { Fabricate(:topic, user: creator, closed: true) } @@ -1163,7 +1146,6 @@ RSpec.describe TopicQuery do end context 'when logged in' do - def suggested_for(topic) topic_query.list_suggested_for(topic).topics.map { |t| t.id } end @@ -1180,8 +1162,7 @@ RSpec.describe TopicQuery do expect(suggested_topics).to be_blank end - context 'random suggested' do - + context 'with random suggested' do let!(:new_topic) { Fabricate(:topic, created_at: 2.days.ago) } let!(:old_topic) { Fabricate(:topic, created_at: 3.years.ago) } @@ -1209,7 +1190,6 @@ RSpec.describe TopicQuery do expect(topics.length).to eq(1) expect(topics).not_to include(old_topic) end - end context 'with private messages' do @@ -1254,7 +1234,7 @@ RSpec.describe TopicQuery do another_group.add(user) end - describe 'as user not part of group' do + context 'as user not part of group' do let!(:user) { Fabricate(:user) } it 'should not return topics by the group user' do @@ -1262,7 +1242,7 @@ RSpec.describe TopicQuery do end end - describe 'as user part of group' do + context 'as user part of group' do let!(:user) { group_user } it 'should return the group topics' do @@ -1270,7 +1250,7 @@ RSpec.describe TopicQuery do end end - context "by tag filter" do + context "with tag filter" do let(:tag) { Fabricate(:tag) } let!(:user) { group_user } @@ -1284,7 +1264,6 @@ RSpec.describe TopicQuery do end context 'with some existing topics' do - let!(:old_partially_read) { topic = Fabricate(:post, user: creator).topic Fabricate(:post, user: creator, topic: topic) @@ -1330,7 +1309,6 @@ RSpec.describe TopicQuery do end it "operates correctly" do - # Note, this is a pretty slow integration test # it tests that suggested is returned in the expected order # hence we run suggested_for twice here to save on all the setup @@ -1348,7 +1326,6 @@ RSpec.describe TopicQuery do expect(suggested_for(topic)).to contain_exactly(partially_read.id, old_partially_read.id) end - end end end @@ -1405,7 +1382,7 @@ RSpec.describe TopicQuery do end end - context "shared drafts" do + describe "shared drafts" do fab!(:category) { Fabricate(:category_with_definition) } fab!(:shared_drafts_category) { Fabricate(:category_with_definition) } fab!(:topic) { Fabricate(:topic, category: shared_drafts_category) } @@ -1421,7 +1398,7 @@ RSpec.describe TopicQuery do SiteSetting.shared_drafts_min_trust_level = TrustLevel[3] end - context "destination_category_id" do + context "with destination_category_id" do it "doesn't allow regular users to query destination_category_id" do list = TopicQuery.new(user, destination_category_id: category.id).list_latest expect(list.topics).not_to include(topic) @@ -1451,7 +1428,7 @@ RSpec.describe TopicQuery do end end - context "latest" do + context "with latest" do it "doesn't include shared topics unless filtering by category" do list = TopicQuery.new(moderator).list_latest expect(list.topics).not_to include(topic) @@ -1477,7 +1454,7 @@ RSpec.describe TopicQuery do end end - context "unread" do + context "with unread" do let!(:partially_read) do topic = Fabricate(:topic, category: shared_drafts_category) Fabricate(:post, user: creator, topic: topic).topic diff --git a/spec/lib/topic_view_spec.rb b/spec/lib/topic_view_spec.rb index 030db8dc27..252d40ecc7 100644 --- a/spec/lib/topic_view_spec.rb +++ b/spec/lib/topic_view_spec.rb @@ -13,7 +13,7 @@ RSpec.describe TopicView do let(:topic_view) { TopicView.new(topic.id, evil_trout) } - context "preload" do + describe "preload" do it "allows preloading of data" do preloaded_topic_view = nil preloader = lambda do |view| @@ -51,7 +51,7 @@ RSpec.describe TopicView do expect { TopicView.new(topic.id, admin) }.not_to raise_error end - context "filter options" do + describe "filter options" do fab!(:p0) { Fabricate(:post, topic: topic) } fab!(:p1) { Fabricate(:post, topic: topic, post_type: Post.types[:moderator_action]) } fab!(:p2) { Fabricate(:post, topic: topic, post_type: Post.types[:small_action]) } @@ -70,7 +70,7 @@ RSpec.describe TopicView do end end - context 'custom filters' do + describe 'custom filters' do fab!(:p0) { Fabricate(:post, topic: topic) } fab!(:p1) { Fabricate(:post, topic: topic, wiki: true) } @@ -93,7 +93,7 @@ RSpec.describe TopicView do end end - context "setup_filtered_posts" do + describe "setup_filtered_posts" do describe "filters posts with ignored users" do fab!(:ignored_user) { Fabricate(:ignored_user, user: evil_trout, ignored_user: user) } let!(:post) { Fabricate(:post, topic: topic, user: first_poster) } @@ -110,7 +110,7 @@ RSpec.describe TopicView do expect(tv.next_page).to eq(nil) end - describe "when an ignored user made the original post" do + context "when an ignored user made the original post" do let!(:post) { Fabricate(:post, topic: topic, user: user) } it "filters out ignored user posts only" do @@ -119,7 +119,7 @@ RSpec.describe TopicView do end end - describe "when an anonymous user made a post" do + context "when an anonymous user made a post" do let!(:post4) { Fabricate(:post, topic: topic, user: anonymous) } it "filters out ignored user posts only" do @@ -128,7 +128,7 @@ RSpec.describe TopicView do end end - describe "when an anonymous (non signed-in) user is viewing a Topic" do + context "when an anonymous (non signed-in) user is viewing a Topic" do let!(:post4) { Fabricate(:post, topic: topic, user: anonymous) } it "filters out ignored user posts only" do @@ -137,7 +137,7 @@ RSpec.describe TopicView do end end - describe "when a staff user is ignored" do + context "when a staff user is ignored" do let!(:admin) { Fabricate(:user, admin: true) } let!(:admin_ignored_user) { Fabricate(:ignored_user, user: evil_trout, ignored_user: admin) } let!(:post4) { Fabricate(:post, topic: topic, user: admin) } @@ -150,7 +150,7 @@ RSpec.describe TopicView do end end - context "chunk_size" do + describe "chunk_size" do it "returns `chunk_size` by default" do expect(TopicView.new(topic.id, evil_trout).chunk_size).to eq(TopicView.chunk_size) end @@ -224,7 +224,7 @@ RSpec.describe TopicView do expect { TopicView.new(topic.id, nil) }.to raise_error(Discourse::NotLoggedIn) end - context 'log_check_personal_message is enabled' do + context 'when log_check_personal_message is enabled' do fab!(:group) { Fabricate(:group) } fab!(:private_message) { Fabricate(:private_message_topic, allowed_groups: [group]) } @@ -274,7 +274,7 @@ RSpec.describe TopicView do expect(topic_view.absolute_url).to eq("http://test.localhost/t/#{topic.slug}/#{topic.id}") end - context 'subfolder' do + context 'with subfolder' do it "provides the correct absolute url" do set_subfolder "/forum" expect(topic_view.absolute_url).to eq("http://test.localhost/forum/t/#{topic.slug}/#{topic.id}") @@ -479,7 +479,7 @@ RSpec.describe TopicView do end end - context 'whispers' do + describe 'whispers' do it "handles their visibility properly" do SiteSetting.enable_whispers = true p1 = Fabricate(:post, topic: topic, user: evil_trout) @@ -498,7 +498,6 @@ RSpec.describe TopicView do end describe '#posts' do - # Create the posts in a different order than the sort_order let!(:p5) { Fabricate(:post, topic: topic, user: evil_trout) } let!(:p2) { Fabricate(:post, topic: topic, user: evil_trout) } @@ -700,7 +699,7 @@ RSpec.describe TopicView do end end - context "page_title" do + describe "page_title" do fab!(:tag1) { Fabricate(:tag) } fab!(:tag2) { Fabricate(:tag, topic_count: 2) } fab!(:op_post) { Fabricate(:post, topic: topic) } @@ -710,7 +709,7 @@ RSpec.describe TopicView do subject { TopicView.new(topic.id, evil_trout).page_title } context "when a post number is specified" do - context "admins" do + context "with admins" do it "see post number and username for all posts" do title = TopicView.new(topic.id, admin, post_number: 0).page_title expect(title).to eq(topic.title) @@ -724,7 +723,7 @@ RSpec.describe TopicView do end end - context "regular users" do + context "with regular users" do it "see post number and username for regular posts" do title = TopicView.new(topic.id, evil_trout, post_number: 0).page_title expect(title).to eq(topic.title) @@ -748,20 +747,20 @@ RSpec.describe TopicView do end end - context "uncategorized topic" do - context "topic_page_title_includes_category is false" do + context "with uncategorized topic" do + context "when topic_page_title_includes_category is false" do before { SiteSetting.topic_page_title_includes_category = false } it { is_expected.to eq(topic.title) } end - context "topic_page_title_includes_category is true" do + context "when topic_page_title_includes_category is true" do before { SiteSetting.topic_page_title_includes_category = true } it { is_expected.to eq(topic.title) } - context "tagged topic" do + context "with tagged topic" do before { topic.tags << [tag1, tag2] } - context "tagging enabled" do + context "with tagging enabled" do before { SiteSetting.tagging_enabled = true } it { is_expected.to start_with(topic.title) } @@ -769,7 +768,7 @@ RSpec.describe TopicView do it { is_expected.to end_with(tag2.name) } # tag2 has higher topic count end - context "tagging disabled" do + context "with tagging disabled" do before { SiteSetting.tagging_enabled = false } it { is_expected.to start_with(topic.title) } @@ -780,22 +779,22 @@ RSpec.describe TopicView do end end - context "categorized topic" do + context "with categorized topic" do let(:category) { Fabricate(:category) } before { topic.update(category_id: category.id) } - context "topic_page_title_includes_category is false" do + context "when topic_page_title_includes_category is false" do before { SiteSetting.topic_page_title_includes_category = false } it { is_expected.to eq(topic.title) } end - context "topic_page_title_includes_category is true" do + context "when topic_page_title_includes_category is true" do before { SiteSetting.topic_page_title_includes_category = true } it { is_expected.to start_with(topic.title) } it { is_expected.to end_with(category.name) } - context "tagged topic" do + context "with tagged topic" do before do SiteSetting.tagging_enabled = true topic.tags << [tag1, tag2] diff --git a/spec/lib/trust_level_spec.rb b/spec/lib/trust_level_spec.rb index d89712b198..c64f64f524 100644 --- a/spec/lib/trust_level_spec.rb +++ b/spec/lib/trust_level_spec.rb @@ -2,7 +2,7 @@ RSpec.describe TrustLevel do describe 'levels' do - context "verify enum sequence" do + context "when verifying enum sequence" do before do @levels = TrustLevel.levels end diff --git a/spec/lib/upload_creator_spec.rb b/spec/lib/upload_creator_spec.rb index bd244d2f5a..2838d136bf 100644 --- a/spec/lib/upload_creator_spec.rb +++ b/spec/lib/upload_creator_spec.rb @@ -215,7 +215,7 @@ RSpec.describe UploadCreator do expect(upload.original_filename).to eq('large_and_unoptimized.png') end - context "jpeg image quality settings" do + context "with jpeg image quality settings" do before do SiteSetting.png_to_jpg_quality = 75 SiteSetting.recompress_original_jpg_quality = 40 @@ -247,7 +247,7 @@ RSpec.describe UploadCreator do expect(upload.original_filename).to eq('animated.gif') end - context "png image quality settings" do + context "with png image quality settings" do before do SiteSetting.png_to_jpg_quality = 100 SiteSetting.recompress_original_jpg_quality = 90 @@ -333,7 +333,7 @@ RSpec.describe UploadCreator do end end - context 'uploading to s3' do + context 'when uploading to s3' do let(:filename) { "should_be_jpeg.png" } let(:file) { file_from_fixtures(filename) } let(:pdf_filename) { "small.pdf" } @@ -413,7 +413,7 @@ RSpec.describe UploadCreator do end end - context "secure media functionality" do + context "with secure media functionality" do let(:filename) { "logo.jpg" } let(:file) { file_from_fixtures(filename) } let(:opts) { {} } @@ -513,7 +513,7 @@ RSpec.describe UploadCreator do end end - context 'custom emojis' do + context 'with custom emojis' do let(:animated_filename) { "animated.gif" } let(:animated_file) { file_from_fixtures(animated_filename) } @@ -658,7 +658,7 @@ RSpec.describe UploadCreator do end describe '#should_downsize?' do - context "GIF image" do + context "with GIF image" do let(:gif_file) { file_from_fixtures("animated.gif") } before do diff --git a/spec/lib/upload_recovery_spec.rb b/spec/lib/upload_recovery_spec.rb index dcb3163c66..ec4fb5c27b 100644 --- a/spec/lib/upload_recovery_spec.rb +++ b/spec/lib/upload_recovery_spec.rb @@ -111,7 +111,7 @@ RSpec.describe UploadRecovery do .to eq(File.read(file_from_fixtures("smallest.png"))) end - context 'S3 store' do + describe 'S3 store' do before do setup_s3 stub_s3_store diff --git a/spec/lib/url_helper_spec.rb b/spec/lib/url_helper_spec.rb index bddeca0dbd..343cee9438 100644 --- a/spec/lib/url_helper_spec.rb +++ b/spec/lib/url_helper_spec.rb @@ -1,18 +1,14 @@ # frozen_string_literal: true RSpec.describe UrlHelper do - describe "#relaxed parse" do - it "can handle double #" do url = UrlHelper.relaxed_parse("https://test.com#test#test") expect(url.to_s).to eq("https://test.com#test%23test") end - end describe "#is_local" do - it "is true when the file has been uploaded" do store = stub store.expects(:has_been_uploaded?).returns(true) @@ -42,11 +38,9 @@ RSpec.describe UrlHelper do Discourse.stubs(:store).returns(store) expect(UrlHelper.is_local("/plugins/all.js")).to eq(true) end - end describe "#absolute" do - it "returns an absolute URL for CDN" do begin Rails.configuration.action_controller.asset_host = "//cdn.awesome.com" @@ -74,26 +68,21 @@ RSpec.describe UrlHelper do Rails.configuration.action_controller.stubs(:asset_host).returns("http://my.cdn.com") expect(UrlHelper.absolute("/path/to/file")).to eq("http://my.cdn.com/path/to/file") end - end describe "#absolute_without_cdn" do - it "changes a relative url to an absolute one using base url even when cdn is enabled" do Rails.configuration.action_controller.stubs(:asset_host).returns("http://my.cdn.com") expect(UrlHelper.absolute_without_cdn("/path/to/file")).to eq("http://test.localhost/path/to/file") end - end describe "#schemaless" do - it "removes http schemas only" do expect(UrlHelper.schemaless("http://www.discourse.org")).to eq("//www.discourse.org") expect(UrlHelper.schemaless("https://secure.discourse.org")).to eq("https://secure.discourse.org") expect(UrlHelper.schemaless("ftp://ftp.discourse.org")).to eq("ftp://ftp.discourse.org") end - end describe "#escape_uri" do @@ -185,7 +174,7 @@ RSpec.describe UrlHelper do ) end - context "and secure_media setting is disabled" do + context "when secure_media setting is disabled" do before { SiteSetting.secure_media = false } it "returns the local_cdn_url" do diff --git a/spec/lib/validators/allowed_ip_address_validator_spec.rb b/spec/lib/validators/allowed_ip_address_validator_spec.rb index 37b7ea2ae7..2d02412ee3 100644 --- a/spec/lib/validators/allowed_ip_address_validator_spec.rb +++ b/spec/lib/validators/allowed_ip_address_validator_spec.rb @@ -1,12 +1,11 @@ # frozen_string_literal: true RSpec.describe AllowedIpAddressValidator do - let(:record) { Fabricate.build(:user, trust_level: TrustLevel[0], ip_address: '99.232.23.123') } let(:validator) { described_class.new(attributes: :ip_address) } subject(:validate) { validator.validate_each(record, :ip_address, record.ip_address) } - context "ip address should be blocked" do + context "when ip address should be blocked" do it 'should add an error' do ScreenedIpAddress.stubs(:should_block?).returns(true) validate @@ -15,7 +14,7 @@ RSpec.describe AllowedIpAddressValidator do end end - context "ip address isn't allowed for registration" do + context "when ip address isn't allowed for registration" do it 'should add an error' do SpamHandler.stubs(:should_prevent_registration_from_ip?).returns(true) validate @@ -24,7 +23,7 @@ RSpec.describe AllowedIpAddressValidator do end end - context "ip address should not be blocked" do + context "when ip address should not be blocked" do it "shouldn't add an error" do ScreenedIpAddress.stubs(:should_block?).returns(false) validate @@ -32,7 +31,7 @@ RSpec.describe AllowedIpAddressValidator do end end - context 'ip_address is nil' do + context 'when ip_address is nil' do it "shouldn't add an error" do ScreenedIpAddress.expects(:should_block?).never record.ip_address = nil @@ -40,5 +39,4 @@ RSpec.describe AllowedIpAddressValidator do expect(record.errors[:ip_address]).not_to be_present end end - end diff --git a/spec/lib/validators/email_validator_spec.rb b/spec/lib/validators/email_validator_spec.rb index 459478409e..fc3dd1c561 100644 --- a/spec/lib/validators/email_validator_spec.rb +++ b/spec/lib/validators/email_validator_spec.rb @@ -8,7 +8,7 @@ RSpec.describe EmailValidator do user.errors[:email].present? end - context "blocked email" do + describe "blocked email" do it "doesn't add an error when email doesn't match a blocked email" do expect(blocks?('sam@sam.com')).to eq(false) end @@ -39,7 +39,7 @@ RSpec.describe EmailValidator do end end - context "auto approve email domains" do + describe "auto approve email domains" do it "works as expected" do SiteSetting.auto_approve_email_domains = "example.com" diff --git a/spec/lib/validators/max_username_length_validator_spec.rb b/spec/lib/validators/max_username_length_validator_spec.rb index 257aa77237..edb4af0290 100644 --- a/spec/lib/validators/max_username_length_validator_spec.rb +++ b/spec/lib/validators/max_username_length_validator_spec.rb @@ -10,7 +10,7 @@ RSpec.describe MaxUsernameLengthValidator do expect(validator.error_message).to eq(I18n.t("site_settings.errors.max_username_length_range")) end - context "checks for valid ranges" do + describe "checks for valid ranges" do it "fails for values below the valid range" do expect do SiteSetting.max_username_length = 5 diff --git a/spec/lib/validators/min_username_length_validator_spec.rb b/spec/lib/validators/min_username_length_validator_spec.rb index 16c1879bb3..f181eb3f92 100644 --- a/spec/lib/validators/min_username_length_validator_spec.rb +++ b/spec/lib/validators/min_username_length_validator_spec.rb @@ -9,7 +9,7 @@ RSpec.describe MinUsernameLengthValidator do expect(validator.error_message).to eq(I18n.t("site_settings.errors.min_username_length_range")) end - context "checks for valid ranges" do + describe "checks for valid ranges" do it "fails for values below the valid range" do expect do SiteSetting.min_username_length = 0 diff --git a/spec/lib/validators/password_validator_spec.rb b/spec/lib/validators/password_validator_spec.rb index 8f6c751273..cf04416456 100644 --- a/spec/lib/validators/password_validator_spec.rb +++ b/spec/lib/validators/password_validator_spec.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true RSpec.describe PasswordValidator do - def password_error_message(key) I18n.t("activerecord.errors.models.user.attributes.password.#{key.to_s}") end @@ -9,15 +8,15 @@ RSpec.describe PasswordValidator do let(:validator) { described_class.new(attributes: :password) } subject(:validate) { validator.validate_each(record, :password, @password) } - context "password required" do + describe "password required" do let(:record) { u = Fabricate.build(:user, password: @password); u.password_required!; u } - context "password is not common" do + context "when password is not common" do before do CommonPasswords.stubs(:common_password?).returns(false) end - context "min password length is 8" do + context "when min password length is 8" do before { SiteSetting.min_password_length = 8 } it "doesn't add an error when password is good" do @@ -54,7 +53,7 @@ RSpec.describe PasswordValidator do end end - context "min password length is 12" do + context "when min password length is 12" do before { SiteSetting.min_password_length = 12 } it "adds an error when password length is 11" do @@ -65,7 +64,7 @@ RSpec.describe PasswordValidator do end end - context "password is commonly used" do + context "when password is commonly used" do before do SiteSetting.min_password_length = 8 CommonPasswords.stubs(:common_password?).returns(true) @@ -86,7 +85,7 @@ RSpec.describe PasswordValidator do end end - context "password_unique_characters is 5" do + context "when password_unique_characters is 5" do before do SiteSetting.password_unique_characters = 5 end @@ -155,7 +154,7 @@ RSpec.describe PasswordValidator do end end - context "password not required" do + describe "password not required" do let(:record) { Fabricate.build(:user, password: @password) } it "doesn't add an error if password is not required" do @@ -175,5 +174,4 @@ RSpec.describe PasswordValidator do expect(record.errors[:password]).to be_present end end - end diff --git a/spec/lib/validators/post_validator_spec.rb b/spec/lib/validators/post_validator_spec.rb index 5993b92123..b167130e9a 100644 --- a/spec/lib/validators/post_validator_spec.rb +++ b/spec/lib/validators/post_validator_spec.rb @@ -22,7 +22,7 @@ RSpec.describe PostValidator do end end - describe "when post's topic is a PM between a human and a non human user" do + context "when post's topic is a PM between a human and a non human user" do fab!(:robot) { Fabricate(:user, id: -3) } fab!(:user) { Fabricate(:user) } @@ -43,7 +43,7 @@ RSpec.describe PostValidator do end end - context "stripped_length" do + describe "stripped_length" do it "adds an error for short raw" do post.raw = "abc" validator.stripped_length(post) @@ -102,7 +102,7 @@ RSpec.describe PostValidator do end end - context "too_many_posts" do + describe "too_many_posts" do it "should be invalid when the user has posted too much" do post.user.expects(:posted_too_much_in_topic?).returns(true) validator.max_posts_validator(post) @@ -123,7 +123,7 @@ RSpec.describe PostValidator do end end - context "too_many_mentions" do + describe "too_many_mentions" do before do SiteSetting.newuser_max_mentions_per_post = 2 SiteSetting.max_mentions_per_post = 3 @@ -180,7 +180,7 @@ RSpec.describe PostValidator do end end - context "too_many_embedded_media" do + describe "too_many_embedded_media" do before do SiteSetting.min_trust_to_post_embedded_media = 0 SiteSetting.newuser_max_embedded_media = 2 @@ -223,7 +223,7 @@ RSpec.describe PostValidator do end end - context "invalid post" do + describe "invalid post" do it "should be invalid" do validator.validate(post) expect(post.errors.count).to be > 0 @@ -250,7 +250,7 @@ RSpec.describe PostValidator do Discourse.redis.del(@pm_key) end - context "post is unique" do + context "when post is unique" do let(:new_post) do Fabricate.build(:post, user: user, raw: "unique content", topic: topic) end @@ -268,7 +268,7 @@ RSpec.describe PostValidator do end end - context "post is not unique" do + context "when post is not unique" do def build_post(is_pm:, raw:) Fabricate.build( :post, @@ -314,8 +314,7 @@ RSpec.describe PostValidator do end end - context "force_edit_last_validator" do - + describe "force_edit_last_validator" do fab!(:user) { Fabricate(:user) } fab!(:other_user) { Fabricate(:user) } fab!(:topic) { Fabricate(:topic) } @@ -392,7 +391,7 @@ RSpec.describe PostValidator do end end - context "admin editing a static page" do + describe "admin editing a static page" do before do post.acting_user = build(:admin) SiteSetting.tos_topic_id = post.topic_id @@ -401,9 +400,8 @@ RSpec.describe PostValidator do include_examples "almost no validations" end - context "staged user" do + describe "staged user" do before { post.acting_user = build(:user, staged: true) } include_examples "almost no validations" end - end diff --git a/spec/lib/validators/string_setting_validator_spec.rb b/spec/lib/validators/string_setting_validator_spec.rb index 79024da0fe..3d6b270fb1 100644 --- a/spec/lib/validators/string_setting_validator_spec.rb +++ b/spec/lib/validators/string_setting_validator_spec.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true RSpec.describe StringSettingValidator do - describe '#valid_value?' do shared_examples "for all StringSettingValidator opts" do it "returns true for blank values" do @@ -64,7 +63,7 @@ RSpec.describe StringSettingValidator do end end - context 'combinations of options' do + context 'with combinations of options' do it "min and regex" do v = described_class.new(regex: '^[\w]+$', min: 3) expect(v.valid_value?('chocolate')).to eq(true) @@ -94,7 +93,5 @@ RSpec.describe StringSettingValidator do expect(v.valid_value?('ba')).to eq(false) end end - end - end diff --git a/spec/lib/validators/user_full_name_validator_spec.rb b/spec/lib/validators/user_full_name_validator_spec.rb index 8a9802bb27..c25472fd6b 100644 --- a/spec/lib/validators/user_full_name_validator_spec.rb +++ b/spec/lib/validators/user_full_name_validator_spec.rb @@ -5,7 +5,7 @@ RSpec.describe UserFullNameValidator do subject(:validate) { validator.validate_each(record, :name, @name) } let(:record) { Fabricate.build(:user, name: @name) } - context "name not required" do + context "when name is not required" do before { SiteSetting.full_name_required = false } it "allows no name" do @@ -21,7 +21,7 @@ RSpec.describe UserFullNameValidator do end end - context "name required" do + context "when name is required" do before { SiteSetting.full_name_required = true } it "adds error for nil name" do diff --git a/spec/lib/validators/username_setting_validator_spec.rb b/spec/lib/validators/username_setting_validator_spec.rb index c59105acd3..98c994fd99 100644 --- a/spec/lib/validators/username_setting_validator_spec.rb +++ b/spec/lib/validators/username_setting_validator_spec.rb @@ -18,7 +18,7 @@ RSpec.describe UsernameSettingValidator do expect(validator.valid_value?('no way')).to eq(false) end - context "regex support" do + context "with regex support" do fab!(:darthvader) { Fabricate(:user, username: 'darthvader') } fab!(:luke) { Fabricate(:user, username: 'luke') } diff --git a/spec/lib/version_spec.rb b/spec/lib/version_spec.rb index 726bd3b8e1..a06f67e63e 100644 --- a/spec/lib/version_spec.rb +++ b/spec/lib/version_spec.rb @@ -3,7 +3,7 @@ require 'version' RSpec.describe Discourse::VERSION do - context "has_needed_version?" do + describe ".has_needed_version?" do it "works for major comparisons" do expect(Discourse.has_needed_version?('1.0.0', '1.0.0')).to eq(true) expect(Discourse.has_needed_version?('2.0.0', '1.0.0')).to eq(true) @@ -43,7 +43,7 @@ RSpec.describe Discourse::VERSION do end end - context "find_compatible_resource" do + describe ".find_compatible_resource" do shared_examples "test compatible resource" do it "returns nil when the current version is above all pinned versions" do expect(Discourse.find_compatible_resource(version_list, "2.6.0")).to be_nil @@ -86,7 +86,7 @@ RSpec.describe Discourse::VERSION do include_examples "test compatible resource" end - context "handle a compatible resource out of order" do + context "when handling a compatible resource out of order" do let(:version_list) { <<~YML 2.4.2.beta1: twofourtwobetaone 2.5.0.beta4: twofivebetafour @@ -99,7 +99,7 @@ RSpec.describe Discourse::VERSION do end end - context "find_compatible_git_resource" do + describe ".find_compatible_git_resource" do let!(:git_directory) do path = nil diff --git a/spec/lib/wizard/step_updater_spec.rb b/spec/lib/wizard/step_updater_spec.rb index 429c8e7599..5a0f4ab7df 100644 --- a/spec/lib/wizard/step_updater_spec.rb +++ b/spec/lib/wizard/step_updater_spec.rb @@ -8,7 +8,7 @@ RSpec.describe Wizard::StepUpdater do fab!(:user) { Fabricate(:admin) } let(:wizard) { Wizard::Builder.new(user).build } - context "introduction" do + describe "introduction" do it "updates the introduction step" do locale = SiteSettings::DefaultsProvider::DEFAULT_LOCALE updater = wizard.create_updater('introduction', @@ -42,7 +42,7 @@ RSpec.describe Wizard::StepUpdater do end end - context "privacy" do + describe "privacy" do it "updates to open correctly" do updater = wizard.create_updater('privacy', login_required: false, invite_only: false, must_approve_users: false) updater.update @@ -64,7 +64,7 @@ RSpec.describe Wizard::StepUpdater do end end - context "styling" do + describe "styling" do it "updates fonts" do updater = wizard.create_updater('styling', body_font: 'open_sans', @@ -78,7 +78,7 @@ RSpec.describe Wizard::StepUpdater do expect(SiteSetting.heading_font).to eq('oswald') end - context "colors" do + context "with colors" do context "with an existing color scheme" do fab!(:color_scheme) { Fabricate(:color_scheme, name: 'existing', via_wizard: true) } @@ -122,7 +122,7 @@ RSpec.describe Wizard::StepUpdater do Theme.delete_all end - context 'dark theme' do + context 'with dark theme' do it "creates the theme" do updater = wizard.create_updater('styling', color_scheme: 'Dark', @@ -140,7 +140,7 @@ RSpec.describe Wizard::StepUpdater do end end - context 'light theme' do + context 'with light theme' do it "creates the theme" do updater = wizard.create_updater('styling', color_scheme: ColorScheme::LIGHT_THEME_ID, @@ -184,7 +184,7 @@ RSpec.describe Wizard::StepUpdater do end end - context "auto dark mode" do + context "with auto dark mode" do before do dark_scheme = ColorScheme.where(name: "Dark").first SiteSetting.default_dark_mode_color_scheme_id = dark_scheme.id @@ -215,7 +215,7 @@ RSpec.describe Wizard::StepUpdater do end - context "homepage style" do + context "with homepage style" do it "updates the fields correctly" do SiteSetting.top_menu = "latest|categories|unread|top" updater = wizard.create_updater('styling', @@ -265,7 +265,7 @@ RSpec.describe Wizard::StepUpdater do end end - context "branding" do + describe "branding" do it "updates the fields correctly" do upload = Fabricate(:upload) upload2 = Fabricate(:upload) @@ -285,7 +285,7 @@ RSpec.describe Wizard::StepUpdater do end end - context "corporate" do + describe "corporate" do it "updates the fields properly" do p = Fabricate(:post, raw: 'company_name - governing_law - city_for_disputes template') SiteSetting.tos_topic_id = p.topic_id diff --git a/spec/lib/wizard/wizard_builder_spec.rb b/spec/lib/wizard/wizard_builder_spec.rb index 29fb96adaf..564e578535 100644 --- a/spec/lib/wizard/wizard_builder_spec.rb +++ b/spec/lib/wizard/wizard_builder_spec.rb @@ -32,7 +32,7 @@ RSpec.describe Wizard::Builder do expect(wizard.steps).to be_blank end - context 'privacy step' do + describe 'privacy step' do let(:privacy_step) { wizard.steps.find { |s| s.id == 'privacy' } } it 'should set the right default value for the fields' do @@ -55,7 +55,7 @@ RSpec.describe Wizard::Builder do end end - context 'styling' do + describe 'styling' do let(:styling_step) { wizard.steps.find { |s| s.id == 'styling' } } let(:font_field) { styling_step.fields[1] } fab!(:theme) { Fabricate(:theme) } @@ -65,8 +65,8 @@ RSpec.describe Wizard::Builder do expect(font_field.choices.size).to eq(DiscourseFonts.fonts.size) end - context "colors" do - describe "when the default theme has not been override" do + context "with colors" do + context "when the default theme has not been override" do before do SiteSetting.find_by(name: "default_theme_id").destroy! end @@ -77,7 +77,7 @@ RSpec.describe Wizard::Builder do end end - describe "when the default theme has been override and the color scheme doesn't have a base scheme" do + context "when the default theme has been override and the color scheme doesn't have a base scheme" do let(:color_scheme) { Fabricate(:color_scheme, base_scheme_id: nil) } before do @@ -91,7 +91,7 @@ RSpec.describe Wizard::Builder do end end - describe "when the default theme has been overridden by a theme without a color scheme" do + context "when the default theme has been overridden by a theme without a color scheme" do before do theme.set_default! end @@ -102,7 +102,7 @@ RSpec.describe Wizard::Builder do end end - describe "when the default theme has been overridden by a theme with a color scheme" do + context "when the default theme has been overridden by a theme with a color scheme" do before do theme.update(color_scheme_id: ColorScheme.find_by_name("Dark").id) theme.set_default! @@ -116,7 +116,7 @@ RSpec.describe Wizard::Builder do end end - context 'branding' do + describe 'branding' do let(:branding_step) { wizard.steps.find { |s| s.id == 'branding' } } it 'should set the right default value for the fields' do diff --git a/spec/lib/wizard/wizard_spec.rb b/spec/lib/wizard/wizard_spec.rb index e9b3c8cda7..a493fbfda2 100644 --- a/spec/lib/wizard/wizard_spec.rb +++ b/spec/lib/wizard/wizard_spec.rb @@ -9,7 +9,7 @@ RSpec.describe Wizard do SiteSetting.wizard_enabled = true end - context "defaults" do + describe "defaults" do it "has default values" do wizard = Wizard.new(Fabricate.build(:moderator)) expect(wizard.steps).to be_empty diff --git a/spec/mailers/invite_mailer_spec.rb b/spec/mailers/invite_mailer_spec.rb index 8d2c76640d..bc4e994ffb 100644 --- a/spec/mailers/invite_mailer_spec.rb +++ b/spec/mailers/invite_mailer_spec.rb @@ -1,12 +1,9 @@ # frozen_string_literal: true RSpec.describe InviteMailer do - describe "send_invite" do - - context "invite to site" do - - context "default invite message" do + context "when inviting to site" do + context "with default invite message" do fab!(:invite) { Fabricate(:invite) } let(:invite_mail) { InviteMailer.send_invite(invite) } @@ -35,7 +32,7 @@ RSpec.describe InviteMailer do end end - context "custom invite message" do + context "with custom invite message" do fab!(:invite) { Fabricate( :invite, @@ -43,7 +40,7 @@ RSpec.describe InviteMailer do ) } - context "custom message includes invite link" do + context "when custom message includes invite link" do let(:custom_invite_mail) { InviteMailer.send_invite(invite) } it 'renders the invitee email' do @@ -78,11 +75,11 @@ RSpec.describe InviteMailer do end end - context "invite to topic" do + context "when inviting to topic" do let(:trust_level_2) { build(:user, trust_level: 2) } let(:topic) { Fabricate(:topic, excerpt: "Topic invite support is now available in Discourse!", user: trust_level_2) } - context "default invite message" do + context "with default invite message" do let(:invite) do topic.invite(topic.user, 'name@example.com') Invite.find_by(invited_by_id: topic.user.id) @@ -131,7 +128,7 @@ RSpec.describe InviteMailer do end end - context "custom invite message" do + context "with custom invite message" do let(:invite) do topic.invite( topic.user, @@ -154,5 +151,4 @@ RSpec.describe InviteMailer do end end end - end diff --git a/spec/mailers/rejection_mailer_spec.rb b/spec/mailers/rejection_mailer_spec.rb index cf20ab2caa..279c4c3ee4 100644 --- a/spec/mailers/rejection_mailer_spec.rb +++ b/spec/mailers/rejection_mailer_spec.rb @@ -1,10 +1,8 @@ # frozen_string_literal: true RSpec.describe RejectionMailer do - describe "send_rejection" do - - context 'sends rejection email' do + context 'when sending rejection email' do fab! (:user) { Fabricate(:user) } let (:template_args) { { former_title: "Mail Subject", destination: user.email, site_name: SiteSetting.title } } let (:reject_mail) { RejectionMailer.send_rejection("email_reject_topic_not_found", user.email, template_args) } diff --git a/spec/mailers/user_notifications_spec.rb b/spec/mailers/user_notifications_spec.rb index 755e3ef981..1a7c28097f 100644 --- a/spec/mailers/user_notifications_spec.rb +++ b/spec/mailers/user_notifications_spec.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true RSpec.describe UserNotifications do - let(:user) { Fabricate(:admin) } describe "#get_context_posts" do @@ -50,11 +49,9 @@ RSpec.describe UserNotifications do SiteSetting.private_email = true expect(UserNotifications.get_context_posts(post3, topic_user, user).count).to eq(0) end - end describe ".signup" do - subject { UserNotifications.signup(user) } it "works" do @@ -63,11 +60,9 @@ RSpec.describe UserNotifications do expect(subject.from).to eq([SiteSetting.notification_email]) expect(subject.body).to be_present end - end describe ".forgot_password" do - subject { UserNotifications.forgot_password(user) } it "works" do @@ -141,7 +136,6 @@ RSpec.describe UserNotifications do end describe '.digest' do - subject { UserNotifications.digest(user) } after do @@ -149,7 +143,6 @@ RSpec.describe UserNotifications do end context "without new topics" do - it "doesn't send the email" do expect(subject.to).to be_blank end @@ -169,7 +162,6 @@ RSpec.describe UserNotifications do end context "with new topics" do - let!(:popular_topic) { Fabricate(:topic, user: Fabricate(:coding_horror), created_at: 1.hour.ago) } it "works" do @@ -299,7 +291,6 @@ RSpec.describe UserNotifications do expect(html).to match(' xml:lang="pl-PL"') end end - end describe '.user_replied' do @@ -638,7 +629,7 @@ RSpec.describe UserNotifications do end end - context "one group in pm" do + context "with one group in pm" do before do topic.allowed_groups = [group] end @@ -646,7 +637,7 @@ RSpec.describe UserNotifications do include_examples "includes first group name" end - context "multiple groups in pm" do + context "with multiple groups in pm" do let(:group2) { Fabricate(:group) } before do @@ -656,7 +647,7 @@ RSpec.describe UserNotifications do include_examples "includes first group name" end - context "no groups in pm" do + context "with no groups in pm" do it "includes %{optional_pm} in subject" do expect(mail.subject).to include("[PM] ") end @@ -749,7 +740,7 @@ RSpec.describe UserNotifications do end shared_examples "supports reply by email" do - context "reply_by_email" do + context "with reply_by_email" do it "should have allow_reply_by_email set when that feature is enabled" do expects_build_with(has_entry(:allow_reply_by_email, true)) end @@ -757,7 +748,7 @@ RSpec.describe UserNotifications do end shared_examples "no reply by email" do - context "reply_by_email" do + context "with reply_by_email" do it "doesn't support reply by email" do expects_build_with(Not(has_entry(:allow_reply_by_email, true))) end @@ -765,7 +756,7 @@ RSpec.describe UserNotifications do end shared_examples "respect for private_email" do - context "private_email" do + context "with private_email" do it "doesn't support reply by email" do SiteSetting.private_email = true @@ -789,7 +780,7 @@ RSpec.describe UserNotifications do # The parts of emails that are derived from templates are translated shared_examples "sets user locale" do - context "set locale for translating templates" do + context "with set locale for translating templates" do it "sets the locale" do expects_build_with(has_key(:locale)) end @@ -992,7 +983,7 @@ RSpec.describe UserNotifications do include_examples "sets user locale" end - context "shows the right name in 'From' field" do + context "when showing the right name in 'From' field" do let(:inviter) { Fabricate(:user) } let(:invitee) { Fabricate(:user) } @@ -1043,22 +1034,21 @@ RSpec.describe UserNotifications do end # notification emails derived from templates are translated into the user's locale - shared_context "notification derived from template" do + shared_context "with notification derived from template" do let(:user) { Fabricate(:user, locale: locale) } let(:mail_type) { mail_type } let(:notification) { Fabricate(:notification, user: user) } end describe "notifications from template" do - - context "user locale is allowed" do + context "when user locale is allowed" do before do SiteSetting.allow_user_locale = true end %w(signup signup_after_approval confirm_old_email notify_old_email confirm_new_email forgot_password admin_login account_created).each do |mail_type| - include_examples "notification derived from template" do + include_examples "with notification derived from template" do let(:locale) { "fr" } let(:mail_type) { mail_type } it "sets the locale" do @@ -1068,14 +1058,14 @@ RSpec.describe UserNotifications do end end - context "user locale is not allowed" do + context "when user locale is not allowed" do before do SiteSetting.allow_user_locale = false end %w(signup signup_after_approval notify_old_email confirm_old_email confirm_new_email forgot_password admin_login account_created).each do |mail_type| - include_examples "notification derived from template" do + include_examples "with notification derived from template" do let(:locale) { "fr" } let(:mail_type) { mail_type } it "sets the locale" do @@ -1197,7 +1187,7 @@ RSpec.describe UserNotifications do expect(mail.body).to include("May 25, 2020, 4:00pm") end - context "user doesn't have timezone set" do + context "when user doesn't have timezone set" do before do user.user_option.timezone = nil end @@ -1229,7 +1219,7 @@ RSpec.describe UserNotifications do expect(mail.body).to include("May 25, 2020, 4:00pm") end - context "user doesn't have timezone set" do + context "when user doesn't have timezone set" do before do user.user_option.timezone = nil end diff --git a/spec/mailers/version_mailer_spec.rb b/spec/mailers/version_mailer_spec.rb index a31db7be80..8819df6ee1 100644 --- a/spec/mailers/version_mailer_spec.rb +++ b/spec/mailers/version_mailer_spec.rb @@ -3,7 +3,7 @@ RSpec.describe VersionMailer do subject { VersionMailer.send_notice } - context 'contact_email is blank' do + context 'when contact_email is blank' do before { SiteSetting.contact_email = '' } it "doesn't send the email" do @@ -11,7 +11,7 @@ RSpec.describe VersionMailer do end end - context 'contact_email is set' do + context 'when contact_email is set' do before { SiteSetting.contact_email = 'me@example.com' } it "works" do @@ -20,6 +20,5 @@ RSpec.describe VersionMailer do expect(subject.from).to eq([SiteSetting.notification_email]) expect(subject.body).to be_present end - end end diff --git a/spec/models/associated_group_spec.rb b/spec/models/associated_group_spec.rb index f44485d541..55f0ec6cb5 100644 --- a/spec/models/associated_group_spec.rb +++ b/spec/models/associated_group_spec.rb @@ -20,7 +20,7 @@ RSpec.describe AssociatedGroup do expect(described_class.has_provider?).to eq(true) end - context "cleanup!" do + describe ".cleanup!" do before do associated_group.last_used = 8.days.ago associated_group.save diff --git a/spec/models/badge_spec.rb b/spec/models/badge_spec.rb index cc39d7b9c0..7e1c30ce9f 100644 --- a/spec/models/badge_spec.rb +++ b/spec/models/badge_spec.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true RSpec.describe Badge do - it 'has a valid system attribute for new badges' do expect(Badge.create!(name: "test", badge_type_id: 1).system?).to be false end @@ -140,7 +139,7 @@ RSpec.describe Badge do end end - context "First Quote" do + describe "First Quote" do let(:quoted_post_badge) do Badge.find(Badge::FirstQuote) end @@ -165,12 +164,10 @@ RSpec.describe Badge do user_badge = post2.user.user_badges.find_by(badge_id: quoted_post_badge.id) expect(user_badge.granted_at).to eq_time(post2.created_at) - end end - context "WikiEditor badge" do - + describe "WikiEditor badge" do it "is awarded" do wiki_editor_badge = Badge.find(Badge::WikiEditor) post = Fabricate(:post, wiki: true) @@ -181,11 +178,9 @@ RSpec.describe Badge do expect(UserBadge.where(user_id: post.user.id, badge_id: Badge::WikiEditor).count).to eq(1) end - end - context "PopularLink badge" do - + describe "PopularLink badge" do let(:popular_link_badge) do Badge.find(Badge::PopularLink) end @@ -222,7 +217,6 @@ RSpec.describe Badge do end describe "#seed" do - let(:regular_badge) do Badge.find(Badge::Regular) end diff --git a/spec/models/bookmark_spec.rb b/spec/models/bookmark_spec.rb index 4a75381057..7c89b6a41a 100644 --- a/spec/models/bookmark_spec.rb +++ b/spec/models/bookmark_spec.rb @@ -3,7 +3,7 @@ RSpec.describe Bookmark do fab!(:post) { Fabricate(:post) } - context "validations" do + describe "Validations" do it "does not allow a user to create a bookmark with only one polymorphic column" do user = Fabricate(:user) bm = Bookmark.create(bookmarkable_id: post.id, user: user) diff --git a/spec/models/category_featured_topic_spec.rb b/spec/models/category_featured_topic_spec.rb index 9a90c56275..3d41bbd1c3 100644 --- a/spec/models/category_featured_topic_spec.rb +++ b/spec/models/category_featured_topic_spec.rb @@ -1,11 +1,10 @@ # frozen_string_literal: true RSpec.describe CategoryFeaturedTopic do - it { is_expected.to belong_to :category } it { is_expected.to belong_to :topic } - context 'feature_topics_for' do + describe '.feature_topics_for' do fab!(:user) { Fabricate(:user) } fab!(:category) { Fabricate(:category) } let!(:category_post) { PostCreator.create(user, raw: "I put this post in the category", title: "categorize THIS", category: category.id) } @@ -69,5 +68,4 @@ RSpec.describe CategoryFeaturedTopic do end end - end diff --git a/spec/models/category_group_spec.rb b/spec/models/category_group_spec.rb index 659ebcf6e7..723ac6f098 100644 --- a/spec/models/category_group_spec.rb +++ b/spec/models/category_group_spec.rb @@ -1,9 +1,8 @@ # frozen_string_literal: true RSpec.describe CategoryGroup do - describe '#permission_types' do - context "verify enum sequence" do + context "when verifying enum sequence" do before do @permission_types = CategoryGroup.permission_types end diff --git a/spec/models/category_list_spec.rb b/spec/models/category_list_spec.rb index 127e3420ab..7347508824 100644 --- a/spec/models/category_list_spec.rb +++ b/spec/models/category_list_spec.rb @@ -12,8 +12,7 @@ RSpec.describe CategoryList do fab!(:admin) { Fabricate(:admin) } let(:category_list) { CategoryList.new(Guardian.new(user), include_topics: true) } - context "security" do - + describe "security" do it "properly hide secure categories" do cat = Fabricate(:category_with_definition) Fabricate(:topic, category: cat) @@ -92,7 +91,6 @@ RSpec.describe CategoryList do end context "with a category" do - fab!(:topic_category) { Fabricate(:category_with_definition, num_featured_topics: 2) } context "with a topic in a category" do @@ -130,7 +128,7 @@ RSpec.describe CategoryList do end end - context "notification level" do + context "with notification level" do it "returns 'regular' as default notification level" do category = category_list.categories.find { |c| c.id == topic_category.id } expect(category.notification_level).to eq(NotificationLevels.all[:regular]) @@ -151,7 +149,6 @@ RSpec.describe CategoryList do expect(category.notification_level).to eq(NotificationLevels.all[:regular]) end end - end describe 'category order' do @@ -170,7 +167,7 @@ RSpec.describe CategoryList do uncategorized.save end - context 'fixed_category_positions is enabled' do + context 'when fixed_category_positions is enabled' do before do SiteSetting.fixed_category_positions = true end @@ -194,7 +191,7 @@ RSpec.describe CategoryList do end end - context 'fixed_category_positions is disabled' do + context 'when fixed_category_positions is disabled' do before do SiteSetting.fixed_category_positions = false end @@ -241,7 +238,7 @@ RSpec.describe CategoryList do end end - context 'some categories are muted' do + context 'when some categories are muted' do let!(:cat1) { Fabricate(:category_with_definition) } let!(:muted_cat) { Fabricate(:category_with_definition) } let!(:cat3) { Fabricate(:category_with_definition) } diff --git a/spec/models/category_spec.rb b/spec/models/category_spec.rb index 14e8754d02..942b38180c 100644 --- a/spec/models/category_spec.rb +++ b/spec/models/category_spec.rb @@ -30,7 +30,7 @@ RSpec.describe Category do expect(cats.errors[:name]).to be_present end - context 'associations' do + describe 'Associations' do it 'should delete associated sidebar_section_links when category is destroyed' do category_sidebar_section_link = Fabricate(:category_sidebar_section_link) category_sidebar_section_link_2 = Fabricate(:category_sidebar_section_link, linkable: category_sidebar_section_link.linkable) @@ -289,7 +289,7 @@ RSpec.describe Category do end describe 'non-english characters' do - context 'uses ascii slug generator' do + context 'when using ascii slug generator' do before do SiteSetting.slug_generation_method = 'ascii' @category = Fabricate(:category_with_definition, name: "测试") @@ -302,7 +302,7 @@ RSpec.describe Category do end end - context 'uses none slug generator' do + context 'when using none slug generator' do before do SiteSetting.slug_generation_method = 'none' @category = Fabricate(:category_with_definition, name: "测试") @@ -318,7 +318,7 @@ RSpec.describe Category do end end - context 'uses encoded slug generator' do + context 'when using encoded slug generator' do before do SiteSetting.slug_generation_method = 'encoded' @category = Fabricate(:category_with_definition, name: "测试") diff --git a/spec/models/category_user_spec.rb b/spec/models/category_user_spec.rb index 35a9cb8ff2..5e0a7b9e57 100644 --- a/spec/models/category_user_spec.rb +++ b/spec/models/category_user_spec.rb @@ -98,7 +98,7 @@ RSpec.describe CategoryUser do notification_level: NotificationLevels.all[:regular]).exists?).to eq(true) end - context 'integration' do + describe 'integration' do before do Jobs.run_immediately! NotificationEmailer.enable @@ -268,7 +268,7 @@ RSpec.describe CategoryUser do end describe ".muted_category_ids" do - context "max category nesting 2" do + context "with max category nesting 2" do fab!(:category1) { Fabricate(:category) } fab!(:category2) { Fabricate(:category, parent_category: category1) } fab!(:category3) { Fabricate(:category, parent_category: category1) } @@ -290,7 +290,8 @@ RSpec.describe CategoryUser do expect(CategoryUser.muted_category_ids(user)).to contain_exactly(category3.id) end end - context "max category nesting 3" do + + context "with max category nesting 3" do let(:category1) { Fabricate(:category) } let(:category2) { Fabricate(:category, parent_category: category1) } let(:category3) { Fabricate(:category, parent_category: category2) } diff --git a/spec/models/color_scheme_spec.rb b/spec/models/color_scheme_spec.rb index 156d210742..ae526a5253 100644 --- a/spec/models/color_scheme_spec.rb +++ b/spec/models/color_scheme_spec.rb @@ -64,7 +64,7 @@ RSpec.describe ColorScheme do expect(third.hex).to eq 'F00D33' end - context "hex_for_name without anything enabled" do + context "with hex_for_name without anything enabled" do before do ColorScheme.hex_cache.clear end diff --git a/spec/models/directory_item_spec.rb b/spec/models/directory_item_spec.rb index cd62dd2144..ae46e29e29 100644 --- a/spec/models/directory_item_spec.rb +++ b/spec/models/directory_item_spec.rb @@ -1,9 +1,8 @@ # frozen_string_literal: true RSpec.describe DirectoryItem do - describe '#period_types' do - context "verify enum sequence" do + context "when verifying enum sequence" do before do @period_types = DirectoryItem.period_types end @@ -18,7 +17,7 @@ RSpec.describe DirectoryItem do end end - context 'inactive and silenced users' do + describe 'inactive and silenced users' do it 'removes silenced users correctly' do post = create_post DirectoryItem.refresh_period!(:daily) @@ -47,7 +46,7 @@ RSpec.describe DirectoryItem do end end - context 'refresh' do + describe '.refresh!' do before do freeze_time DateTime.parse('2017-02-02 12:00') UserActionManager.enable @@ -144,7 +143,7 @@ RSpec.describe DirectoryItem do expect(monthly_directory_item.days_visited).to eq(3) end - context 'must approve users' do + context 'when must_approve_users is true' do before do SiteSetting.must_approve_users = true end @@ -155,6 +154,5 @@ RSpec.describe DirectoryItem do expect(DirectoryItem.where(user_id: user.id).count).to eq(0) end end - end end diff --git a/spec/models/discourse_connect_spec.rb b/spec/models/discourse_connect_spec.rb index a383f489ed..fa2de7795e 100644 --- a/spec/models/discourse_connect_spec.rb +++ b/spec/models/discourse_connect_spec.rb @@ -138,7 +138,7 @@ RSpec.describe DiscourseConnect do expect(user.name).to eq("Bob O'Bob") end - context "reviewables" do + describe "reviewables" do let(:sso) do new_discourse_sso.tap do |sso| sso.username = "staged" @@ -639,7 +639,7 @@ RSpec.describe DiscourseConnect do expect(sso.nonce).to_not be_nil end - context 'nonce error' do + describe 'nonce error' do it "generates correct error message when nonce has already been used" do _ , payload = DiscourseConnect.generate_url(secure_session: secure_session).split("?") @@ -672,7 +672,7 @@ RSpec.describe DiscourseConnect do end end - context 'user locale' do + describe 'user locale' do it 'sets default user locale if specified' do SiteSetting.allow_user_locale = true @@ -702,7 +702,7 @@ RSpec.describe DiscourseConnect do end end - context 'trusting emails' do + describe 'trusting emails' do let(:sso) do sso = new_discourse_sso sso.username = "test" @@ -775,7 +775,7 @@ RSpec.describe DiscourseConnect do end - context 'welcome emails' do + describe 'welcome emails' do let(:sso) { sso = new_discourse_sso sso.username = "test" @@ -797,7 +797,7 @@ RSpec.describe DiscourseConnect do end end - context 'setting title for a user' do + describe 'setting title for a user' do let(:sso) { sso = new_discourse_sso sso.username = 'test' @@ -824,7 +824,7 @@ RSpec.describe DiscourseConnect do end end - context 'setting bio for a user' do + describe 'setting bio for a user' do let(:sso) do sso = new_discourse_sso sso.username = "test" diff --git a/spec/models/draft_spec.rb b/spec/models/draft_spec.rb index 751cffbe37..9b83889f67 100644 --- a/spec/models/draft_spec.rb +++ b/spec/models/draft_spec.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true RSpec.describe Draft do - fab!(:user) do Fabricate(:user) end @@ -10,7 +9,7 @@ RSpec.describe Draft do Fabricate(:post) end - context 'system user' do + describe 'system user' do it "can not set drafts" do # fake a sequence DraftSequence.create!(user_id: Discourse.system_user.id, draft_key: "abc", sequence: 10) @@ -26,7 +25,7 @@ RSpec.describe Draft do end end - context 'backup_drafts_to_pm_length' do + describe 'backup_drafts_to_pm_length' do it "correctly backs up drafts to a personal message" do SiteSetting.backup_drafts_to_pm_length = 1 @@ -224,7 +223,7 @@ RSpec.describe Draft do end - context 'key expiry' do + describe 'key expiry' do it 'nukes new topic draft after a topic is created' do Draft.set(user, Draft::NEW_TOPIC, 0, 'my draft') _t = Fabricate(:topic, user: user, advance_draft: true) @@ -295,6 +294,5 @@ RSpec.describe Draft do expect(drafts[0].post_preloaded?).to eq(true) expect(drafts[0].post.id).to eq(post.id) end - end end diff --git a/spec/models/email_change_request_spec.rb b/spec/models/email_change_request_spec.rb index 1e882e3348..c1466c595d 100644 --- a/spec/models/email_change_request_spec.rb +++ b/spec/models/email_change_request_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true RSpec.describe EmailChangeRequest do - context 'validations' do + describe 'Validations' do describe '#new_email' do describe 'when email is invalid' do it 'should not be valid' do diff --git a/spec/models/email_log_spec.rb b/spec/models/email_log_spec.rb index 08ec1b6489..5ef05b26d3 100644 --- a/spec/models/email_log_spec.rb +++ b/spec/models/email_log_spec.rb @@ -1,14 +1,13 @@ # frozen_string_literal: true RSpec.describe EmailLog do - it { is_expected.to belong_to :user } it { is_expected.to validate_presence_of :to_address } it { is_expected.to validate_presence_of :email_type } fab!(:user) { Fabricate(:user) } - context 'unique email per post' do + describe 'unique email per post' do it 'only allows through one email per post' do post = Fabricate(:post) user = post.user @@ -35,7 +34,7 @@ RSpec.describe EmailLog do end end - context 'after_create' do + describe 'after_create' do context 'with user' do it 'updates the last_emailed_at value for the user' do expect { diff --git a/spec/models/email_token_spec.rb b/spec/models/email_token_spec.rb index a7ded830c6..04ebd0e9fc 100644 --- a/spec/models/email_token_spec.rb +++ b/spec/models/email_token_spec.rb @@ -64,7 +64,7 @@ RSpec.describe EmailToken do expect(EmailToken.confirm(email_token.token)).to be_blank end - context 'taken email address' do + context 'with taken email address' do before do @other_user = Fabricate(:coding_horror) email_token.update_attribute :email, @other_user.email @@ -75,15 +75,14 @@ RSpec.describe EmailToken do end end - context 'welcome message' do + context 'with welcome message' do it 'sends a welcome message when the user is activated' do user = EmailToken.confirm(email_token.token) expect(user.send_welcome_message).to eq true end - end - context 'success' do + context 'with success' do let!(:confirmed_user) { EmailToken.confirm(email_token.token) } it "returns the correct user" do @@ -105,7 +104,7 @@ RSpec.describe EmailToken do end end - context 'confirms the token and redeems invite' do + context 'when confirms the token and redeems invite' do before do SiteSetting.must_approve_users = true Jobs.run_immediately! @@ -140,7 +139,7 @@ RSpec.describe EmailToken do end end - context 'does not redeem the invite if token is password_reset' do + context 'when does not redeem the invite if token is password_reset' do before do SiteSetting.must_approve_users = true Jobs.run_immediately! diff --git a/spec/models/group_spec.rb b/spec/models/group_spec.rb index 648de0272e..c9623d3e36 100644 --- a/spec/models/group_spec.rb +++ b/spec/models/group_spec.rb @@ -5,7 +5,7 @@ RSpec.describe Group do let(:user) { Fabricate(:user) } let(:group) { Fabricate(:group) } - context 'validations' do + describe 'Validations' do describe '#grant_trust_level' do describe 'when trust level is not valid' do it 'should not be valid' do @@ -66,7 +66,7 @@ RSpec.describe Group do end describe '#builtin' do - context "verify enum sequence" do + context "when verifying enum sequence" do before do @builtin = Group.builtin end @@ -602,7 +602,7 @@ RSpec.describe Group do end end - context "group management" do + describe "group management" do fab!(:group) { Fabricate(:group) } it "by default has no managers" do @@ -1123,7 +1123,7 @@ RSpec.describe Group do end end - context "Unicode usernames and group names" do + describe "Unicode usernames and group names" do before { SiteSetting.unicode_usernames = true } it "should normalize the name" do diff --git a/spec/models/invite_redeemer_spec.rb b/spec/models/invite_redeemer_spec.rb index 2cdbd4eced..fc4c82244f 100644 --- a/spec/models/invite_redeemer_spec.rb +++ b/spec/models/invite_redeemer_spec.rb @@ -242,7 +242,7 @@ RSpec.describe InviteRedeemer do expect(invite.invited_users.first).to be_present end - context 'invite_link' do + context 'with invite_link' do fab!(:invite_link) { Fabricate(:invite, email: nil, max_redemptions_allowed: 5, expires_at: 1.month.from_now, emailed_status: Invite.emailed_status_types[:not_required]) } let(:invite_redeemer) { InviteRedeemer.new(invite: invite_link, email: 'foo@example.com') } diff --git a/spec/models/invite_spec.rb b/spec/models/invite_spec.rb index 6013de4993..e21b516909 100644 --- a/spec/models/invite_spec.rb +++ b/spec/models/invite_spec.rb @@ -5,7 +5,7 @@ RSpec.describe Invite do let(:xss_email) { "email@test.com" } let(:escaped_email) { "<b onmouseover=alert('wufff!')>email</b><script>alert('test');</script>@test.com" } - context 'validators' do + describe 'Validators' do it { is_expected.to validate_presence_of :invited_by_id } it { is_expected.to rate_limit } @@ -49,7 +49,7 @@ RSpec.describe Invite do end end - context 'before_save' do + describe 'before_save' do it 'regenerates the email token when email is changed' do invite = Fabricate(:invite, email: 'test@example.com') token = invite.email_token @@ -94,7 +94,7 @@ RSpec.describe Invite do ) end - context 'via email' do + context 'with email' do it 'can be created and a job is enqueued to email the invite' do invite = Invite.generate(user, email: 'test@example.com') expect(invite.email).to eq('test@example.com') @@ -116,7 +116,7 @@ RSpec.describe Invite do end end - context 'via link' do + context 'with link' do it 'does not enqueue a job to email the invite' do invite = Invite.generate(user, skip_email: true) expect(invite.emailed_status).to eq(Invite.emailed_status_types[:not_required]) @@ -178,7 +178,7 @@ RSpec.describe Invite do end end - context 'invite to a topic' do + context 'when inviting to a topic' do fab!(:topic) { Fabricate(:topic) } let(:invite) { Invite.generate(topic.user, email: 'test@example.com', topic: topic) } @@ -287,7 +287,7 @@ RSpec.describe Invite do end end - context 'invite to a topic' do + context 'when inviting to a topic' do fab!(:topic) { Fabricate(:private_message_topic) } fab!(:another_topic) { Fabricate(:private_message_topic) } @@ -319,7 +319,7 @@ RSpec.describe Invite do end end - context 'scopes' do + describe 'scopes' do fab!(:inviter) { Fabricate(:user) } fab!(:pending_invite) { Fabricate(:invite, invited_by: inviter, email: 'pending@example.com') } diff --git a/spec/models/notification_spec.rb b/spec/models/notification_spec.rb index d17e71b0ea..d43bcf31be 100644 --- a/spec/models/notification_spec.rb +++ b/spec/models/notification_spec.rb @@ -15,7 +15,7 @@ RSpec.describe Notification do it { is_expected.to belong_to :topic } describe '#types' do - context "verify enum sequence" do + context "when verifying enum sequence" do before do @types = Notification.types end @@ -109,7 +109,6 @@ RSpec.describe Notification do }.not_to change(user.notifications, :count) end end - end describe 'high priority creation' do @@ -131,10 +130,9 @@ RSpec.describe Notification do end describe 'unread counts' do - fab!(:user) { Fabricate(:user) } - context 'a regular notification' do + context 'with a regular notification' do it 'increases unread_notifications' do expect { Fabricate(:notification, user: user); user.reload }.to change(user, :unread_notifications) end @@ -148,7 +146,7 @@ RSpec.describe Notification do end end - context 'a private message' do + context 'with a private message' do it "doesn't increase unread_notifications" do expect { Fabricate(:private_message_notification, user: user); user.reload }.not_to change(user, :unread_notifications) end @@ -166,7 +164,7 @@ RSpec.describe Notification do end end - context 'a bookmark reminder message' do + context 'with a bookmark reminder message' do it "doesn't increase unread_notifications" do expect { Fabricate(:bookmark_reminder_notification, user: user); user.reload }.not_to change(user, :unread_notifications) end @@ -179,7 +177,6 @@ RSpec.describe Notification do expect { Fabricate(:bookmark_reminder_notification, user: user); user.reload }.to change(user, :unread_high_priority_notifications) end end - end describe 'message bus' do @@ -209,7 +206,7 @@ RSpec.describe Notification do partial_user.notifications.create!(notification_type: Notification.types[:mentioned], data: '{}') end - context 'destroy' do + context 'when destroying' do let!(:notification) { Fabricate(:notification) } it 'updates the notification count on destroy' do diff --git a/spec/models/optimized_image_spec.rb b/spec/models/optimized_image_spec.rb index 467be426ad..072e654978 100644 --- a/spec/models/optimized_image_spec.rb +++ b/spec/models/optimized_image_spec.rb @@ -245,8 +245,7 @@ RSpec.describe OptimizedImage do end describe ".create_for" do - - context "versioning" do + context "with versioning" do let(:filename) { 'logo.png' } let(:file) { file_from_fixtures(filename) } @@ -287,7 +286,6 @@ RSpec.describe OptimizedImage do end context "when using an internal store" do - let(:store) { FakeInternalStore.new } before { Discourse.stubs(:store).returns(store) } @@ -297,11 +295,9 @@ RSpec.describe OptimizedImage do OptimizedImage.expects(:resize).returns(false) expect(OptimizedImage.create_for(upload, 100, 200)).to eq(nil) end - end context "when the thumbnail is properly generated" do - before do OptimizedImage.expects(:resize).returns(true) end @@ -329,9 +325,7 @@ RSpec.describe OptimizedImage do oi = OptimizedImage.create_for(upload, 100, 200, format: 'gif') expect(oi.url).to eq("/internally/stored/optimized/image.gif") end - end - end describe "external store" do @@ -350,7 +344,7 @@ RSpec.describe OptimizedImage do end context "when the thumbnail is properly generated" do - context "secure media disabled" do + context "with secure media disabled" do let(:s3_upload) { Fabricate(:upload_s3) } let(:optimized_path) { %r{/optimized/\d+X.*/#{s3_upload.sha1}_2_100x200\.png} } @@ -396,7 +390,6 @@ RSpec.describe OptimizedImage do end end end - end class FakeInternalStore diff --git a/spec/models/post_action_spec.rb b/spec/models/post_action_spec.rb index bd5473bd97..ade7b9c92c 100644 --- a/spec/models/post_action_spec.rb +++ b/spec/models/post_action_spec.rb @@ -20,8 +20,7 @@ RSpec.describe PostAction do expect(pa).not_to be_valid end - context "messaging" do - + describe "messaging" do it "notifies moderators (integration test)" do post = create_post mod = moderator @@ -88,7 +87,7 @@ RSpec.describe PostAction do expect(topic.message_archived?(mod)).to eq(true) end - context "category group moderators" do + context "with category group moderators" do fab!(:group_user) { Fabricate(:group_user) } let(:group) { group_user.group } @@ -109,7 +108,6 @@ RSpec.describe PostAction do expect(readable_by_groups).to include(group.id) end end - end describe "update_counters" do @@ -679,7 +677,7 @@ RSpec.describe PostAction do expect(post.hidden).to eq(false) end - context "topic auto closing" do + context "with topic auto closing" do fab!(:topic) { Fabricate(:topic) } let(:post1) { create_post(topic: topic) } let(:post2) { create_post(topic: topic) } @@ -735,7 +733,7 @@ RSpec.describe PostAction do expect(topic_status_update.status_type).to eq(TopicTimer.types[:open]) end - context "on a staff post" do + context "when on a staff post" do fab!(:staff_user) { Fabricate(:user, moderator: true) } fab!(:topic) { Fabricate(:topic, user: staff_user) } @@ -988,7 +986,7 @@ RSpec.describe PostAction do expect(event).to be_present end - context "resolving flags" do + context "when resolving flags" do let(:result) { PostActionCreator.spam(eviltrout, post) } let(:post_action) { result.post_action } let(:reviewable) { result.reviewable } diff --git a/spec/models/post_action_type_spec.rb b/spec/models/post_action_type_spec.rb index 2eaf9b7425..1fe7429819 100644 --- a/spec/models/post_action_type_spec.rb +++ b/spec/models/post_action_type_spec.rb @@ -1,8 +1,7 @@ # frozen_string_literal: true RSpec.describe PostActionType do - - context "callbacks" do + describe "Callbacks" do describe '#expiry_cache' do it 'should clear the cache on save' do cache = ApplicationSerializer.fragment_cache @@ -21,7 +20,7 @@ RSpec.describe PostActionType do end describe '#types' do - context "verify enum sequence" do + context "when verifying enum sequence" do before do @types = PostActionType.types end diff --git a/spec/models/post_analyzer_spec.rb b/spec/models/post_analyzer_spec.rb index 9f76550a25..fa873cabb2 100644 --- a/spec/models/post_analyzer_spec.rb +++ b/spec/models/post_analyzer_spec.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true RSpec.describe PostAnalyzer do - let(:default_topic_id) { 12 } let(:url) { 'https://twitter.com/evil_trout/status/345954894420787200' } @@ -79,7 +78,7 @@ RSpec.describe PostAnalyzer do end end - context "links" do + describe "links" do let(:raw_no_links) { "hello world my name is evil trout" } let(:raw_one_link_md) { "[jlawr](http://www.imdb.com/name/nm2225369)" } let(:raw_two_links_html) { "disney reddit" } diff --git a/spec/models/post_mover_spec.rb b/spec/models/post_mover_spec.rb index 962be121cd..59ac9a1108 100644 --- a/spec/models/post_mover_spec.rb +++ b/spec/models/post_mover_spec.rb @@ -5,7 +5,7 @@ RSpec.describe PostMover do fab!(:evil_trout) { Fabricate(:evil_trout) } describe '#move_types' do - context "verify enum sequence" do + context "when verifying enum sequence" do before do @move_types = PostMover.move_types end @@ -21,7 +21,7 @@ RSpec.describe PostMover do end describe 'move_posts' do - context 'topics' do + context 'with topics' do before { freeze_time } fab!(:user) { Fabricate(:user, admin: true) } @@ -64,7 +64,7 @@ RSpec.describe PostMover do action_code: "split_topic") end - context 'success' do + context 'with success' do it "correctly handles notifications and bread crumbs" do old_topic = p2.topic @@ -125,8 +125,7 @@ RSpec.describe PostMover do end end - context "errors" do - + context "with errors" do it "raises an error when one of the posts doesn't exist" do non_existent_post_id = Post.maximum(:id)&.next || 1 expect { topic.move_posts(user, [non_existent_post_id], title: "new testing topic name") }.to raise_error(Discourse::InvalidParameters) @@ -143,7 +142,7 @@ RSpec.describe PostMover do end end - context "successfully moved" do + context "when successfully moved" do before do TopicUser.update_last_read(user, topic.id, p4.post_number, p4.post_number, 0) TopicLink.extract_from(p2) @@ -158,7 +157,7 @@ RSpec.describe PostMover do ) end - context "post replies" do + context "with post replies" do describe "when a post with replies is moved" do it "should update post replies correctly" do topic.move_posts( @@ -203,7 +202,7 @@ RSpec.describe PostMover do end end - describe "when only one reply is left behind" do + context "when only one reply is left behind" do it "should update post replies correctly" do p5 = Fabricate( :post, @@ -225,7 +224,7 @@ RSpec.describe PostMover do end end - context "to a new topic" do + context "when moved to a new topic" do it "works correctly" do topic.expects(:add_moderator_post).once new_topic = topic.move_posts(user, [p2.id, p4.id], title: "new testing topic name", category_id: category.id, tags: ["tag1", "tag2"]) @@ -436,7 +435,7 @@ RSpec.describe PostMover do expect(new_topic_user2.bookmarked).to eq(true) end - context "read state and other stats per user" do + context "with read state and other stats per user" do def create_topic_user(user, opts = {}) notification_level = opts.delete(:notification_level) || :regular @@ -535,7 +534,7 @@ RSpec.describe PostMover do end end - context "to an existing topic" do + context "when moved to an existing topic" do fab!(:destination_topic) { Fabricate(:topic, user: another_user) } fab!(:destination_op) { Fabricate(:post, topic: destination_topic, user: another_user, created_at: 1.day.ago) } @@ -710,7 +709,7 @@ RSpec.describe PostMover do expect(Notification.exists?(admin_notification.id)).to eq(true) end - context "post timings" do + context "with post timings" do fab!(:some_user) { Fabricate(:user) } it "successfully moves timings" do @@ -757,7 +756,7 @@ RSpec.describe PostMover do expect(TopicUser.find_by(topic: destination_topic, user: user).liked).to eq(true) end - context "read state and other stats per user" do + context "with read state and other stats per user" do def create_topic_user(user, topic, opts = {}) notification_level = opts.delete(:notification_level) || :regular @@ -913,8 +912,7 @@ RSpec.describe PostMover do end end - context "to a message" do - + context "when moved to a message" do it "works correctly" do topic.expects(:add_moderator_post).once new_topic = topic.move_posts(user, [p2.id, p4.id], title: "new testing topic name", archetype: "private_message") @@ -1032,7 +1030,7 @@ RSpec.describe PostMover do end end - context "moving the first post" do + context "when moving the first post" do it "copies the OP, doesn't delete it" do topic.expects(:add_moderator_post).once new_topic = topic.move_posts(user, [p1.id, p2.id], title: "new testing topic name") @@ -1099,14 +1097,13 @@ RSpec.describe PostMover do end end - context "moving replies" do + context "when moving replies" do include_examples "moves email related stuff" do let!(:old_post) { p3 } end end - context "to an existing topic with a deleted post" do - + context "when moving to an existing topic with a deleted post" do before do topic.expects(:add_moderator_post) end @@ -1142,7 +1139,7 @@ RSpec.describe PostMover do end end - context "to an existing closed topic" do + context "when moving to an existing closed topic" do fab!(:destination_topic) { Fabricate(:topic, closed: true) } it "works correctly for admin" do @@ -1182,7 +1179,7 @@ RSpec.describe PostMover do end end - context 'messages' do + context 'with messages' do fab!(:user) { Fabricate(:user) } fab!(:another_user) { Fabricate(:user) } fab!(:regular_user) { Fabricate(:trust_level_4) } @@ -1208,7 +1205,7 @@ RSpec.describe PostMover do @like = PostActionCreator.like(another_user, p4) end - context 'move to new message' do + context 'when moving to new message' do it "adds post users as topic allowed users" do TopicUser.change(user, personal_message, notification_level: TopicUser.notification_levels[:muted]) TopicUser.change(another_user, personal_message, notification_level: TopicUser.notification_levels[:tracking]) @@ -1271,7 +1268,7 @@ RSpec.describe PostMover do end end - context 'move to existing message' do + context 'when moving to existing message' do it "adds post users as topic allowed users" do personal_message.move_posts(admin, [p2.id, p5.id], destination_topic_id: another_personal_message.id, archetype: "private_message") @@ -1325,7 +1322,7 @@ RSpec.describe PostMover do end end - context 'banner topic' do + context 'with banner topic' do fab!(:regular_user) { Fabricate(:trust_level_4) } fab!(:topic) { Fabricate(:topic) } fab!(:personal_message) { Fabricate(:private_message_topic, user: regular_user) } @@ -1333,7 +1330,7 @@ RSpec.describe PostMover do fab!(:p1) { Fabricate(:post, topic: banner_topic, user: evil_trout) } fab!(:p2) { Fabricate(:post, topic: banner_topic, reply_to_post_number: p1.post_number, user: regular_user) } - context 'move to existing topic' do + context 'when moving to existing topic' do it "allows moving banner topic posts in regular topic" do banner_topic.move_posts(admin, [p2.id], destination_topic_id: topic.id) expect(p2.reload.topic_id).to eq(topic.id) diff --git a/spec/models/post_reply_spec.rb b/spec/models/post_reply_spec.rb index e9ae402c67..b09482a84a 100644 --- a/spec/models/post_reply_spec.rb +++ b/spec/models/post_reply_spec.rb @@ -5,7 +5,7 @@ RSpec.describe PostReply do fab!(:post) { Fabricate(:post, topic: topic) } fab!(:other_post) { Fabricate(:post, topic: topic) } - context "validation" do + describe "Validations" do it "should ensure that the posts belong in the same topic" do expect(PostReply.new(post: post, reply: other_post)).to be_valid diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index e7512813d6..0fffe4dbdc 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -8,7 +8,7 @@ RSpec.describe Post do let(:upload_path) { Discourse.store.upload_path } describe '#hidden_reasons' do - context "verify enum sequence" do + context "when verifying enum sequence" do before do @hidden_reasons = Post.hidden_reasons end @@ -24,7 +24,7 @@ RSpec.describe Post do end describe '#types' do - context "verify enum sequence" do + context "when verifying enum sequence" do before do @types = Post.types end @@ -40,7 +40,7 @@ RSpec.describe Post do end describe '#cook_methods' do - context "verify enum sequence" do + context "when verifying enum sequence" do before do @cook_methods = Post.cook_methods end @@ -97,8 +97,7 @@ RSpec.describe Post do end describe "revisions and deleting/recovery" do - - context 'a post without links' do + context 'with a post without links' do let(:post) { Fabricate(:post, post_args) } before do @@ -122,7 +121,7 @@ RSpec.describe Post do end end - context 'a post with links' do + context 'with a post with links' do let(:post) { Fabricate(:post_with_external_links) } before do post.trash! @@ -138,7 +137,7 @@ RSpec.describe Post do end end - context 'a post with notices' do + context 'with a post with notices' do let(:post) do post = Fabricate(:post, post_args) post.upsert_custom_fields(Post::NOTICE => { type: Post.notices[:returning_user], last_posted_at: 1.day.ago }) @@ -320,13 +319,12 @@ RSpec.describe Post do expect(post_with_two_embedded_media.embedded_media_count).to eq(2) end - context "validation" do - + context "with validation" do before do SiteSetting.newuser_max_embedded_media = 1 end - context 'newuser' do + context 'with newuser' do it "allows a new user to post below the limit" do expect(post_one_image).to be_valid end @@ -353,9 +351,7 @@ RSpec.describe Post do post_two_images.user.trust_level = TrustLevel[1] expect(post_two_images).to be_valid end - end - end describe "maximum attachments" do @@ -372,13 +368,12 @@ RSpec.describe Post do expect(post_two_attachments.attachment_count).to eq(2) end - context "validation" do - + context "with validation" do before do SiteSetting.newuser_max_attachments = 1 end - context 'newuser' do + context 'with newuser' do it "allows a new user to post below the limit" do expect(post_one_attachment).to be_valid end @@ -401,12 +396,10 @@ RSpec.describe Post do post_two_attachments.user.trust_level = TrustLevel[1] expect(post_two_attachments).to be_valid end - end - end - context "links" do + describe "links" do fab!(:newuser) { Fabricate(:user, trust_level: TrustLevel[0]) } let(:no_links) { post_with_body("hello world my name is evil trout", newuser) } let(:one_link) { post_with_body("[jlawr](http://www.imdb.com/name/nm2225369)", newuser) } @@ -446,7 +439,6 @@ RSpec.describe Post do end describe "total host usage" do - it "has none for a regular post" do expect(no_links.total_hosts_usage).to be_blank end @@ -463,11 +455,8 @@ RSpec.describe Post do it "contains the new post's links, PLUS the previous one" do expect(two_links.total_hosts_usage).to eq('disneyland.disney.go.com' => 2, 'reddit.com' => 1) end - end - end - end describe "maximums" do @@ -494,13 +483,12 @@ RSpec.describe Post do expect(post_two_links.link_count).to eq(2) end - context "validation" do - + context "with validation" do before do SiteSetting.newuser_max_links = 1 end - context 'newuser' do + context 'with newuser' do it "returns true when within the amount of links allowed" do expect(post_one_link).to be_valid end @@ -515,7 +503,7 @@ RSpec.describe Post do expect(post_two_links).to be_valid end - context "min_trust_to_post_links" do + context "with min_trust_to_post_links" do it "considers oneboxes links" do SiteSetting.min_trust_to_post_links = 3 post_onebox.user.trust_level = TrustLevel[2] @@ -541,15 +529,11 @@ RSpec.describe Post do expect(post_one_link).to be_valid end end - end - end describe "@mentions" do - - context 'raw_mentions' do - + context 'with raw_mentions' do it "returns an empty array with no matches" do post = Fabricate.build(:post, post_args.merge(raw: "Hello Jake and Finn!")) expect(post.raw_mentions).to eq([]) @@ -591,16 +575,14 @@ RSpec.describe Post do post = Fabricate.build(:post, post_args.merge(raw: "@org-board")) expect(post.raw_mentions).to eq(['org-board']) end - end - context "max mentions" do - + context "with max mentions" do fab!(:newuser) { Fabricate(:user, trust_level: TrustLevel[0]) } let(:post_with_one_mention) { post_with_body("@Jake is the person I'm mentioning", newuser) } let(:post_with_two_mentions) { post_with_body("@Jake @Finn are the people I'm mentioning", newuser) } - context 'new user' do + context 'with new user' do before do SiteSetting.newuser_max_mentions_per_post = 1 SiteSetting.max_mentions_per_post = 5 @@ -615,7 +597,7 @@ RSpec.describe Post do end end - context "not a new user" do + context "when not a new user" do before do SiteSetting.newuser_max_mentions_per_post = 0 SiteSetting.max_mentions_per_post = 1 @@ -631,12 +613,10 @@ RSpec.describe Post do expect(post_with_two_mentions).not_to be_valid end end - end - end - context 'validation' do + describe 'validation' do it 'validates our default post' do expect(Fabricate.build(:post, post_args)).to be_valid end @@ -646,8 +626,7 @@ RSpec.describe Post do end end - context "raw_hash" do - + describe "raw_hash" do let(:raw) { "this is our test post body" } let(:post) { post_with_body(raw) } @@ -673,8 +652,7 @@ RSpec.describe Post do end end - context 'revise' do - + describe 'revise' do let(:post) { Fabricate(:post, post_args) } let(:first_version_at) { post.last_version_at } @@ -684,16 +662,13 @@ RSpec.describe Post do expect(post.revise(post.user, raw: post.raw)).to eq(false) end - describe 'with the same body' do - + context 'with the same body' do it "doesn't change version" do expect { post.revise(post.user, raw: post.raw); post.reload }.not_to change(post, :version) end - end - describe 'grace period editing & edit windows' do - + context 'with grace period editing & edit windows' do before { SiteSetting.editing_grace_period = 1.minute.to_i } it 'works' do @@ -732,10 +707,9 @@ RSpec.describe Post do expect(post.revisions.size).to eq(2) expect(post.last_version_at.to_i).to eq(new_revised_at.to_i) end - end - describe 'rate limiter' do + context 'with rate limiter' do let(:changed_by) { coding_horror } it "triggers a rate limiter" do @@ -744,7 +718,7 @@ RSpec.describe Post do end end - describe 'with a new body' do + context 'with a new body' do let(:changed_by) { coding_horror } let!(:result) { post.revise(changed_by, raw: 'updated body') } @@ -758,8 +732,7 @@ RSpec.describe Post do expect(post.revisions.first.user).to be_present end - context 'second poster posts again quickly' do - + context 'when second poster posts again quickly' do it 'is a grace period edit, because the second poster posted again quickly' do SiteSetting.editing_grace_period = 1.minute.to_i post.revise(changed_by, { raw: 'yet another updated body' }, revised_at: post.updated_at + 10.seconds) @@ -769,11 +742,8 @@ RSpec.describe Post do expect(post.public_version).to eq(2) expect(post.revisions.size).to eq(1) end - end - end - end describe 'before save' do @@ -793,7 +763,6 @@ RSpec.describe Post do end describe 'after save' do - let(:post) { Fabricate(:post, post_args) } it "has correct info set" do @@ -808,8 +777,7 @@ RSpec.describe Post do expect(post.replies).to be_blank end - describe 'extract_quoted_post_numbers' do - + context 'with extract_quoted_post_numbers' do let!(:post) { Fabricate(:post, post_args) } let(:reply) { Fabricate.build(:post, post_args) } @@ -833,8 +801,7 @@ RSpec.describe Post do end end - describe 'a new reply' do - + context 'with a new reply' do fab!(:topic) { Fabricate(:topic) } let(:other_user) { coding_horror } let(:reply_text) { "[quote=\"Evil Trout, post:1\"]\nhello\n[/quote]\nHmmm!" } @@ -870,8 +837,7 @@ RSpec.describe Post do expect(post.reply_count).to eq(1) end - context 'a multi-quote reply' do - + context 'with a multi-quote reply' do let!(:multi_reply) do raw = "[quote=\"Evil Trout, post:1\"]post1 quote[/quote]\nAha!\n[quote=\"Evil Trout, post:2\"]post2 quote[/quote]\nNeat-o" PostCreator.new(other_user, raw: raw, topic_id: topic.id, reply_to_post_number: post.post_number).create @@ -883,12 +849,10 @@ RSpec.describe Post do expect(reply.replies.include?(multi_reply)).to eq(true) end end - end - end - context 'summary' do + describe 'summary' do let!(:p1) { Fabricate(:post, post_args.merge(score: 4, percent_rank: 0.33)) } let!(:p2) { Fabricate(:post, post_args.merge(score: 10, percent_rank: 0.66)) } let!(:p3) { Fabricate(:post, post_args.merge(score: 5, percent_rank: 0.99)) } @@ -901,9 +865,8 @@ RSpec.describe Post do end end - context 'sort_order' do - context 'regular topic' do - + describe 'sort_order' do + context 'with a regular topic' do let!(:p1) { Fabricate(:post, post_args) } let!(:p2) { Fabricate(:post, post_args) } let!(:p3) { Fabricate(:post, post_args) } @@ -914,8 +877,7 @@ RSpec.describe Post do end end - context "reply_history" do - + describe "reply_history" do let!(:p1) { Fabricate(:post, post_args) } let!(:p2) { Fabricate(:post, post_args.merge(reply_to_post_number: p1.post_number)) } let!(:p3) { Fabricate(:post, post_args) } @@ -930,8 +892,7 @@ RSpec.describe Post do end - context "reply_ids" do - + describe "reply_ids" do fab!(:topic) { Fabricate(:topic) } let!(:p1) { Fabricate(:post, topic: topic, post_number: 1) } let!(:p2) { Fabricate(:post, topic: topic, post_number: 2, reply_to_post_number: 1) } @@ -1624,7 +1585,7 @@ RSpec.describe Post do end end - context 'topic updated_at' do + describe 'topic updated_at' do let :topic do create_post.topic end @@ -1657,7 +1618,7 @@ RSpec.describe Post do end end - context "have_uploads" do + describe "have_uploads" do it "should find all posts with the upload" do ids = [] ids << Fabricate(:post, cooked: "A post with upload ").id diff --git a/spec/models/report_spec.rb b/spec/models/report_spec.rb index ab8233c7ea..e68de4c75a 100644 --- a/spec/models/report_spec.rb +++ b/spec/models/report_spec.rb @@ -265,12 +265,12 @@ RSpec.describe Report do expect(report.total).to eq 1 end - context 'no private messages' do + context 'with no private messages' do it 'returns an empty report' do expect(report.data).to be_blank end - context 'some public posts' do + context 'with some public posts' do it 'returns an empty report' do Fabricate(:post, topic: topic, user: user); Fabricate(:post, topic: topic, user: user) expect(report.data).to be_blank @@ -279,7 +279,7 @@ RSpec.describe Report do end end - context 'some private messages' do + context 'with some private messages' do before do Fabricate(:private_message_post, created_at: 25.hours.ago, user: user) Fabricate(:private_message_post, created_at: 1.hour.ago, user: user) @@ -292,7 +292,7 @@ RSpec.describe Report do expect(report.total).to eq 3 end - context 'and some public posts' do + context 'with some public posts' do before do Fabricate(:post, user: user, topic: topic) Fabricate(:post, user: user, topic: topic) @@ -306,7 +306,7 @@ RSpec.describe Report do end end - context 'private message from system user' do + context 'with private message from system user' do before do Fabricate(:private_message_post, created_at: 1.hour.ago, user: Discourse.system_user) end @@ -321,7 +321,7 @@ RSpec.describe Report do describe 'user to user private messages' do let(:report) { Report.find('user_to_user_private_messages') } - context 'private message from system user' do + context 'with private message from system user' do before do Fabricate(:private_message_post, created_at: 1.hour.ago, user: Discourse.system_user) end @@ -626,7 +626,7 @@ RSpec.describe Report do freeze_time(Date.today) end - context "moderators order" do + context "with moderators order" do before do Fabricate(:post, user: sam) Fabricate(:post, user: jeff) @@ -638,7 +638,7 @@ RSpec.describe Report do end end - context "time read" do + context "with time read" do before do sam.user_visits.create(visited_at: 2.days.ago, time_read: 200) sam.user_visits.create(visited_at: 1.day.ago, time_read: 100) @@ -657,7 +657,7 @@ RSpec.describe Report do end end - context "flags" do + context "with flags" do before do flagged_post = Fabricate(:post) result = PostActionCreator.off_topic(jeff, flagged_post) @@ -671,7 +671,7 @@ RSpec.describe Report do end end - context "topics" do + context "with topics" do before do Fabricate(:topic, user: sam) Fabricate(:topic, user: sam) @@ -685,7 +685,7 @@ RSpec.describe Report do expect(report.data[1][:username]).to eq('sam') end - context "private messages" do + context "with private messages" do before do Fabricate(:private_message_topic, user: jeff) end @@ -697,7 +697,7 @@ RSpec.describe Report do end end - context "posts" do + context "with posts" do before do Fabricate(:post, user: sam) Fabricate(:post, user: sam) @@ -711,7 +711,7 @@ RSpec.describe Report do expect(report.data[1][:username]).to eq('sam') end - context "private messages" do + context "with private messages" do before do Fabricate(:private_message_post, user: jeff) end @@ -723,7 +723,7 @@ RSpec.describe Report do end end - context "private messages" do + context "with private messages" do before do Fabricate(:post, user: sam) Fabricate(:post, user: jeff) @@ -739,7 +739,7 @@ RSpec.describe Report do end end - context "revisions" do + context "with revisions" do before do post = Fabricate(:post) post.revise(sam, raw: 'updated body', edit_reason: 'not cool') @@ -750,7 +750,7 @@ RSpec.describe Report do expect(report.data[0][:username]).to eq('sam') end - context "revise own post" do + context "when revising own post" do before do post = Fabricate(:post, user: sam) post.revise(sam, raw: 'updated body') @@ -763,7 +763,7 @@ RSpec.describe Report do end end - context "previous data" do + context "with previous data" do before do Fabricate(:topic, user: sam, created_at: 1.year.ago) end @@ -802,7 +802,7 @@ RSpec.describe Report do include_examples 'category filtering' - context "on subcategories" do + context "with subcategories" do let(:report) { Report.find('flags', filters: { category: c0.id, 'include_subcategories': true }) } include_examples 'category filtering on subcategories' @@ -832,7 +832,7 @@ RSpec.describe Report do include_examples 'category filtering' - context "on subcategories" do + context "with subcategories" do let(:report) { Report.find('topics', filters: { category: c0.id, 'include_subcategories': true }) } include_examples 'category filtering on subcategories' @@ -923,7 +923,7 @@ RSpec.describe Report do include_examples 'category filtering' - context "on subcategories" do + context "with subcategories" do let(:report) { Report.find('posts', filters: { category: c0.id, 'include_subcategories': true }) } include_examples 'category filtering on subcategories' @@ -955,7 +955,7 @@ RSpec.describe Report do include_examples 'category filtering' - context "on subcategories" do + context "with subcategories" do let(:report) { Report.find('topics_with_no_response', filters: { category: c0.id, 'include_subcategories': true }) } include_examples 'category filtering on subcategories' @@ -991,7 +991,7 @@ RSpec.describe Report do include_examples 'category filtering' - context "on subcategories" do + context "with subcategories" do let(:report) { Report.find('likes', filters: { category: c0.id, 'include_subcategories': true }) } include_examples 'category filtering on subcategories' diff --git a/spec/models/reviewable_queued_post_spec.rb b/spec/models/reviewable_queued_post_spec.rb index 6a11e7110b..b745ebf4bb 100644 --- a/spec/models/reviewable_queued_post_spec.rb +++ b/spec/models/reviewable_queued_post_spec.rb @@ -5,11 +5,11 @@ RSpec.describe ReviewableQueuedPost, type: :model do fab!(:category) { Fabricate(:category) } fab!(:moderator) { Fabricate(:moderator) } - context "creating a post" do + describe "creating a post" do let!(:topic) { Fabricate(:topic, category: category) } let(:reviewable) { Fabricate(:reviewable_queued_post, topic: topic) } - context "create" do + context "when creating" do it "triggers queued_post_created" do event = DiscourseEvent.track(:queued_post_created) { reviewable.save! } expect(event).to be_present @@ -33,9 +33,8 @@ RSpec.describe ReviewableQueuedPost, type: :model do end end - context "actions" do - - context "approve_post" do + describe "actions" do + context "with approve_post" do it 'triggers an extensibility event' do event = DiscourseEvent.track(:approved_post) { reviewable.perform(moderator, :approve_post) } expect(event).to be_present @@ -96,7 +95,7 @@ RSpec.describe ReviewableQueuedPost, type: :model do end - context "reject_post" do + context "with reject_post" do it 'triggers an extensibility event' do event = DiscourseEvent.track(:rejected_post) { reviewable.perform(moderator, :reject_post) } expect(event).to be_present @@ -115,7 +114,7 @@ RSpec.describe ReviewableQueuedPost, type: :model do end end - context "delete_user" do + context "with delete_user" do it "deletes the user and rejects the post" do other_reviewable = Fabricate(:reviewable_queued_post, created_by: reviewable.created_by) @@ -132,7 +131,7 @@ RSpec.describe ReviewableQueuedPost, type: :model do end end - context "creating a topic" do + describe "creating a topic" do let(:reviewable) { Fabricate(:reviewable_queued_post_topic, category: category) } before do @@ -141,8 +140,7 @@ RSpec.describe ReviewableQueuedPost, type: :model do SiteSetting.min_trust_level_to_tag_topics = 0 end - context "editing" do - + context "when editing" do it "is editable and returns the fields" do fields = reviewable.editable_for(Guardian.new(moderator)) expect(fields.has?('category_id')).to eq(true) diff --git a/spec/models/reviewable_score_spec.rb b/spec/models/reviewable_score_spec.rb index 09b6d0a6ff..03765b9ead 100644 --- a/spec/models/reviewable_score_spec.rb +++ b/spec/models/reviewable_score_spec.rb @@ -1,8 +1,7 @@ # frozen_string_literal: true RSpec.describe ReviewableScore, type: :model do - - context "transitions" do + describe "transitions" do fab!(:user) { Fabricate(:user, trust_level: 3) } fab!(:post) { Fabricate(:post) } fab!(:moderator) { Fabricate(:moderator) } @@ -156,7 +155,7 @@ RSpec.describe ReviewableScore, type: :model do end describe ".user_flag_score" do - context "a user with no flags" do + context "with a user with no flags" do it "returns 1.0 + trust_level" do expect(ReviewableScore.user_flag_score(Fabricate.build(:user, trust_level: 2))).to eq(3.0) expect(ReviewableScore.user_flag_score(Fabricate.build(:user, trust_level: 3))).to eq(4.0) @@ -168,7 +167,7 @@ RSpec.describe ReviewableScore, type: :model do end end - context "a user with some flags" do + context "with a user with some flags" do fab!(:user) { Fabricate(:user) } let(:user_stat) { user.user_stat } @@ -204,5 +203,4 @@ RSpec.describe ReviewableScore, type: :model do expect(ReviewableScore.calculate_score(user, 2, 3)).to eq(flag_score + 2 + 3) end end - end diff --git a/spec/models/reviewable_spec.rb b/spec/models/reviewable_spec.rb index c404f14ef9..342380bb86 100644 --- a/spec/models/reviewable_spec.rb +++ b/spec/models/reviewable_spec.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true RSpec.describe Reviewable, type: :model do - describe ".create" do fab!(:admin) { Fabricate(:admin) } fab!(:user) { Fabricate(:user) } @@ -136,7 +135,7 @@ RSpec.describe Reviewable, type: :model do expect(Reviewable.list_for(user, status: :pending)).to be_blank end - context 'Reviewing as an admin' do + context 'as an admin' do before { user.update_columns(moderator: false, admin: true) } it 'can filter by the target_created_by_id attribute' do @@ -393,7 +392,7 @@ RSpec.describe Reviewable, type: :model do expect(Reviewable.valid_type?("User")).to eq(false) end - context "events" do + describe "events" do let!(:moderator) { Fabricate(:moderator) } let(:reviewable) { Fabricate(:reviewable) } @@ -411,7 +410,7 @@ RSpec.describe Reviewable, type: :model do end end - context "message bus notifications" do + describe "message bus notifications" do fab!(:moderator) { Fabricate(:moderator) } let(:post) { Fabricate(:post) } @@ -596,7 +595,7 @@ RSpec.describe Reviewable, type: :model do end end - context "priorities" do + describe "priorities" do it "returns 0 for unknown priorities" do expect(Reviewable.min_score_for_priority(:wat)).to eq(0.0) end @@ -624,7 +623,7 @@ RSpec.describe Reviewable, type: :model do end end - context "custom filters" do + describe "custom filters" do after do Reviewable.clear_custom_filters! end @@ -684,7 +683,7 @@ RSpec.describe Reviewable, type: :model do end end - context 'default actions' do + describe 'default actions' do let(:reviewable) { Reviewable.new } let(:actions) { Reviewable::Actions.new(reviewable, Guardian.new) } diff --git a/spec/models/reviewable_user_spec.rb b/spec/models/reviewable_user_spec.rb index ffd345db21..9ec1b72917 100644 --- a/spec/models/reviewable_user_spec.rb +++ b/spec/models/reviewable_user_spec.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true RSpec.describe ReviewableUser, type: :model do - fab!(:moderator) { Fabricate(:moderator) } let(:user) do user = Fabricate(:user) @@ -10,8 +9,9 @@ RSpec.describe ReviewableUser, type: :model do end fab!(:admin) { Fabricate(:admin) } - context "actions_for" do + describe "#actions_for" do fab!(:reviewable) { Fabricate(:reviewable) } + it "returns correct actions in the pending state" do actions = reviewable.actions_for(Guardian.new(moderator)) expect(actions.has?(:approve_user)).to eq(true) @@ -77,9 +77,10 @@ RSpec.describe ReviewableUser, type: :model do end end - context "perform" do + describe "#perform" do fab!(:reviewable) { Fabricate(:reviewable) } - context "approve" do + + context "when approving" do it "allows us to approve a user" do result = reviewable.perform(moderator, :approve_user) expect(result.success?).to eq(true) @@ -185,7 +186,7 @@ RSpec.describe ReviewableUser, type: :model do expect(@reviewable.reviewable_by_moderator).to eq(true) end - context "email jobs" do + context "with email jobs" do it "enqueues a 'signup after approval' email if must_approve_users is true" do expect_enqueued_with(job: :critical_user_email, args: { type: :signup_after_approval }) do @reviewable.perform(admin, :approve_user) @@ -221,5 +222,4 @@ RSpec.describe ReviewableUser, type: :model do expect(event[:params].first).to eq(user) end end - end diff --git a/spec/models/screened_email_spec.rb b/spec/models/screened_email_spec.rb index 4601128a30..11045500e8 100644 --- a/spec/models/screened_email_spec.rb +++ b/spec/models/screened_email_spec.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true RSpec.describe ScreenedEmail do - let(:email) { 'block@spamfromhome.org' } let(:similar_email) { 'bl0ck@spamfromhome.org' } @@ -23,8 +22,7 @@ RSpec.describe ScreenedEmail do end describe '#block' do - context 'email is not being blocked' do - + context 'when email is not being blocked' do it 'creates a new record with default action of :block' do record = ScreenedEmail.block(email) expect(record).not_to be_new_record @@ -40,7 +38,7 @@ RSpec.describe ScreenedEmail do end end - context 'email is already being blocked' do + context 'when email is already being blocked' do let!(:existing) { Fabricate(:screened_email, email: email) } it "doesn't create a new record" do @@ -94,17 +92,16 @@ RSpec.describe ScreenedEmail do end end - context "action_type is :block" do + context "when action_type is :block" do let!(:screened_email) { Fabricate(:screened_email, email: email, action_type: ScreenedEmail.actions[:block]) } it { is_expected.to eq(true) } include_examples "when a ScreenedEmail record matches" end - context "action_type is :do_nothing" do + context "when action_type is :do_nothing" do let!(:screened_email) { Fabricate(:screened_email, email: email, action_type: ScreenedEmail.actions[:do_nothing]) } it { is_expected.to eq(false) } include_examples "when a ScreenedEmail record matches" end end - end diff --git a/spec/models/screened_ip_address_spec.rb b/spec/models/screened_ip_address_spec.rb index 9b2607506e..418ce51d59 100644 --- a/spec/models/screened_ip_address_spec.rb +++ b/spec/models/screened_ip_address_spec.rb @@ -99,7 +99,7 @@ RSpec.describe ScreenedIpAddress do end describe '#watch' do - context 'ip_address is not being watched' do + context 'when ip_address is not being watched' do it 'should create a new record' do record = described_class.watch(ip_address) expect(record).not_to be_new_record @@ -123,7 +123,7 @@ RSpec.describe ScreenedIpAddress do end end - context 'ip_address is already being watched' do + context 'when ip_address is already being watched' do shared_examples 'exact match of ip address' do it 'should not create a new record' do expect { described_class.watch(ip_address_arg) }.to_not change { described_class.count } @@ -134,21 +134,21 @@ RSpec.describe ScreenedIpAddress do end end - context 'using exact match' do + context 'when using exact match' do fab!(:existing) { Fabricate(:screened_ip_address) } let(:ip_address_arg) { existing.ip_address } include_examples 'exact match of ip address' end - context 'using subnet mask 255.255.255.0' do + context 'when using subnet mask 255.255.255.0' do fab!(:existing) { Fabricate(:screened_ip_address, ip_address: '99.232.23.124/24') } - context 'at exact address' do + context 'with exact address' do let(:ip_address_arg) { '99.232.23.124' } include_examples 'exact match of ip address' end - context 'at address in same subnet' do + context 'with address in same subnet' do let(:ip_address_arg) { '99.232.23.135' } include_examples 'exact match of ip address' end @@ -197,7 +197,7 @@ RSpec.describe ScreenedIpAddress do expect(described_class.should_block?('222.234.23.12')).to eq(false) end - context 'IPv4' do + context 'with IPv4' do it 'returns false when when record matches and action is :do_nothing' do Fabricate(:screened_ip_address, ip_address: '111.234.23.11', action_type: described_class.actions[:do_nothing]) expect(described_class.should_block?('111.234.23.11')).to eq(false) @@ -209,7 +209,7 @@ RSpec.describe ScreenedIpAddress do end end - context 'IPv6' do + context 'with IPv6' do it 'returns false when when record matches and action is :do_nothing' do Fabricate(:screened_ip_address, ip_address: '2001:db8::ff00:42:8329', action_type: described_class.actions[:do_nothing]) expect(described_class.should_block?('2001:db8::ff00:42:8329')).to eq(false) @@ -232,7 +232,7 @@ RSpec.describe ScreenedIpAddress do expect(described_class.is_allowed?('222.12.12.12')).to eq(false) end - context 'IPv4' do + context 'with IPv4' do it 'returns true when when record matches and action is :do_nothing' do Fabricate(:screened_ip_address, ip_address: '111.234.23.11', action_type: described_class.actions[:do_nothing]) expect(described_class.is_allowed?('111.234.23.11')).to eq(true) @@ -244,7 +244,7 @@ RSpec.describe ScreenedIpAddress do end end - context 'IPv6' do + context 'with IPv6' do it 'returns true when when record matches and action is :do_nothing' do Fabricate(:screened_ip_address, ip_address: '2001:db8::ff00:42:8329', action_type: described_class.actions[:do_nothing]) expect(described_class.is_allowed?('2001:db8::ff00:42:8329')).to eq(true) @@ -258,13 +258,12 @@ RSpec.describe ScreenedIpAddress do end describe '#block_admin_login?' do - context 'no allow_admin records exist' do - + context 'when no allow_admin records exist' do it "returns false when use_admin_ip_allowlist is false" do expect(described_class.block_admin_login?(Fabricate.build(:user), '123.12.12.12')).to eq(false) end - context "use_admin_ip_allowlist is true" do + context "when use_admin_ip_allowlist is true" do before { SiteSetting.use_admin_ip_allowlist = true } it "returns false when user is nil" do @@ -285,7 +284,7 @@ RSpec.describe ScreenedIpAddress do end end - context 'allow_admin record exists' do + context 'when allow_admin record exists' do before do @permitted_ip_address = '111.234.23.11' Fabricate(:screened_ip_address, ip_address: @permitted_ip_address, action_type: described_class.actions[:allow_admin]) @@ -295,7 +294,7 @@ RSpec.describe ScreenedIpAddress do expect(described_class.block_admin_login?(Fabricate.build(:admin), '123.12.12.12')).to eq(false) end - context "use_admin_ip_allowlist is true" do + context "when use_admin_ip_allowlist is true" do before { SiteSetting.use_admin_ip_allowlist = true } it "returns false when user is nil" do diff --git a/spec/models/screened_url_spec.rb b/spec/models/screened_url_spec.rb index 284fb26076..430b255c12 100644 --- a/spec/models/screened_url_spec.rb +++ b/spec/models/screened_url_spec.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true RSpec.describe ScreenedUrl do - let(:url) { 'http://shopppping.com/bad/drugz' } let(:domain) { 'shopppping.com' } @@ -103,7 +102,7 @@ RSpec.describe ScreenedUrl do end describe '#watch' do - context 'url is not being blocked' do + context 'when url is not being blocked' do it 'creates a new record with default action of :do_nothing' do record = described_class.watch(url, domain) expect(record).not_to be_new_record @@ -117,7 +116,7 @@ RSpec.describe ScreenedUrl do end end - context 'url is already being blocked' do + context 'when url is already being blocked' do let!(:existing) { Fabricate(:screened_url, url: url, domain: domain) } it "doesn't create a new record" do diff --git a/spec/models/search_log_spec.rb b/spec/models/search_log_spec.rb index 1cac6f9ece..773fa56f25 100644 --- a/spec/models/search_log_spec.rb +++ b/spec/models/search_log_spec.rb @@ -1,14 +1,12 @@ # frozen_string_literal: true RSpec.describe SearchLog, type: :model do - after do SearchLog.clear_debounce_cache! end describe ".log" do - - context "invalid arguments" do + context "with invalid arguments" do it "no search type returns error" do status, _ = SearchLog.log( term: 'bounty hunter', @@ -157,7 +155,6 @@ RSpec.describe SearchLog, type: :model do ) expect(action).to eq(:created) end - end end @@ -202,7 +199,7 @@ RSpec.describe SearchLog, type: :model do end end - context "trending" do + describe "trending" do fab!(:user) { Fabricate(:user) } before do SearchLog.log(term: 'ruby', search_type: :header, ip_address: '127.0.0.1') @@ -234,8 +231,7 @@ RSpec.describe SearchLog, type: :model do end end - context "clean_up" do - + describe "clean_up" do it "will remove old logs" do SearchLog.log(term: 'jawa', search_type: :header, ip_address: '127.0.0.1') SearchLog.log(term: 'jedi', search_type: :header, ip_address: '127.0.0.1') @@ -252,7 +248,5 @@ RSpec.describe SearchLog, type: :model do expect(SearchLog.where(term: 'rey').first).to be_present expect(SearchLog.where(term: 'finn').first).to be_present end - end - end diff --git a/spec/models/sidebar_section_link_spec.rb b/spec/models/sidebar_section_link_spec.rb index d4456dc2ab..e497a45b98 100644 --- a/spec/models/sidebar_section_link_spec.rb +++ b/spec/models/sidebar_section_link_spec.rb @@ -3,7 +3,7 @@ RSpec.describe SidebarSectionLink do fab!(:user) { Fabricate(:user) } - context "validations" do + describe "Validations" do it 'is not valid when linkable already exists for the current user' do category_sidebar_section_link = Fabricate(:category_sidebar_section_link, user: user) diff --git a/spec/models/site_setting_spec.rb b/spec/models/site_setting_spec.rb index 762b37fe9f..df2d9a4c58 100644 --- a/spec/models/site_setting_spec.rb +++ b/spec/models/site_setting_spec.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true RSpec.describe SiteSetting do - describe 'topic_title_length' do it 'returns a range of min/max topic title length' do expect(SiteSetting.topic_title_length).to eq( @@ -29,7 +28,6 @@ RSpec.describe SiteSetting do end describe 'in test we do some judo to ensure SiteSetting is always reset between tests' do - it 'is always the correct default' do expect(SiteSetting.contact_email).to eq('') end @@ -81,9 +79,7 @@ RSpec.describe SiteSetting do end describe "min_redirected_to_top_period" do - - context "has_enough_top_topics" do - + context "when has_enough_top_topics" do before do SiteSetting.topics_per_period_in_top_page = 2 SiteSetting.top_page_default_timeframe = 'daily' @@ -98,11 +94,9 @@ RSpec.describe SiteSetting do it "should_return_a_time_period" do expect(SiteSetting.min_redirected_to_top_period(1.days.ago)).to eq(:daily) end - end - context "does_not_have_enough_top_topics" do - + context "when does_not_have_enough_top_topics" do before do SiteSetting.topics_per_period_in_top_page = 20 SiteSetting.top_page_default_timeframe = 'daily' @@ -112,9 +106,7 @@ RSpec.describe SiteSetting do it "should_return_a_time_period" do expect(SiteSetting.min_redirected_to_top_period(1.days.ago)).to eq(nil) end - end - end describe "scheme" do @@ -132,7 +124,7 @@ RSpec.describe SiteSetting do end end - context "shared_drafts_enabled?" do + describe ".shared_drafts_enabled?" do it "returns false by default" do expect(SiteSetting.shared_drafts_enabled?).to eq(false) end @@ -148,7 +140,7 @@ RSpec.describe SiteSetting do end end - context 'deprecated site settings' do + describe 'deprecated site settings' do before do SiteSetting.force_https = true @orig_logger = Rails.logger diff --git a/spec/models/sitemap_spec.rb b/spec/models/sitemap_spec.rb index 23bf57efed..552dd58e64 100644 --- a/spec/models/sitemap_spec.rb +++ b/spec/models/sitemap_spec.rb @@ -109,7 +109,7 @@ RSpec.describe Sitemap do it_behaves_like 'Excludes hidden and restricted topics' end - context 'sitemap for recent topics' do + context 'with sitemap for recent topics' do let(:sitemap) do described_class.new( enabled: true, last_posted_at: 1.minute.ago, name: described_class::RECENT_SITEMAP_NAME @@ -134,7 +134,7 @@ RSpec.describe Sitemap do it_behaves_like 'Excludes hidden and restricted topics' end - context 'news sitemap' do + context 'with news sitemap' do let(:sitemap) do described_class.new( enabled: true, last_posted_at: 1.minute.ago, name: described_class::NEWS_SITEMAP_NAME diff --git a/spec/models/tag_group_spec.rb b/spec/models/tag_group_spec.rb index 2caa05349e..1891acda29 100644 --- a/spec/models/tag_group_spec.rb +++ b/spec/models/tag_group_spec.rb @@ -84,7 +84,7 @@ RSpec.describe TagGroup do include_examples "correct visible tag groups" - context "staff-only tag group restricted to a public category" do + context "with staff-only tag group restricted to a public category" do before do public_category.allowed_tag_groups = [public_tag_group.name, staff_only_tag_group.name] private_category.allowed_tag_groups = [private_tag_group.name, staff_only_tag_group.name] diff --git a/spec/models/tag_spec.rb b/spec/models/tag_spec.rb index b3353d8f4f..4d9be093bc 100644 --- a/spec/models/tag_spec.rb +++ b/spec/models/tag_spec.rb @@ -20,7 +20,7 @@ RSpec.describe Tag do SiteSetting.min_trust_level_to_tag_topics = 0 end - context 'associations' do + describe 'Associations' do it 'should delete associated sidebar_section_links when tag is destroyed' do tag_sidebar_section_link = Fabricate(:tag_sidebar_section_link) tag_sidebar_section_link_2 = Fabricate(:tag_sidebar_section_link, linkable: tag_sidebar_section_link.linkable) @@ -185,7 +185,7 @@ RSpec.describe Tag do end end - context "topic counts" do + describe "topic counts" do it "should exclude private message topics" do topic Fabricate(:private_message_topic, tags: [tag]) @@ -195,7 +195,7 @@ RSpec.describe Tag do end end - context "unused tags scope" do + describe "unused tags scope" do let!(:tags) do [ Fabricate(:tag, name: "used_publically", topic_count: 2, pm_topic_count: 0), Fabricate(:tag, name: "used_privately", topic_count: 0, pm_topic_count: 3), @@ -212,7 +212,7 @@ RSpec.describe Tag do end end - context "full_url" do + describe "full_url" do let(:tag) { Fabricate(:tag, name: "🚀") } it "percent encodes emojis" do @@ -220,7 +220,7 @@ RSpec.describe Tag do end end - context "synonyms" do + describe "synonyms" do let(:synonym) { Fabricate(:tag, target_tag: tag) } it "can be a synonym for another tag" do diff --git a/spec/models/tag_user_spec.rb b/spec/models/tag_user_spec.rb index 53dd65eb63..8d2e1f86fd 100644 --- a/spec/models/tag_user_spec.rb +++ b/spec/models/tag_user_spec.rb @@ -20,7 +20,7 @@ RSpec.describe TagUser do TagUser.notification_levels[:watching] end - context "notification_level_visible" do + describe "notification_level_visible" do let!(:tag1) { Fabricate(:tag) } let!(:tag2) { Fabricate(:tag) } let!(:tag3) { Fabricate(:tag) } @@ -69,7 +69,7 @@ RSpec.describe TagUser do end end - context "change" do + describe "change" do it "watches or tracks on change" do user = Fabricate(:user) tag = Fabricate(:tag) @@ -111,7 +111,7 @@ RSpec.describe TagUser do end end - context "batch_set" do + describe "batch_set" do it "watches and unwatches tags correctly" do user = Fabricate(:user) @@ -160,7 +160,7 @@ RSpec.describe TagUser do end end - context "integration" do + describe "integration" do fab!(:user) { Fabricate(:user) } fab!(:watched_tag) { Fabricate(:tag) } let(:muted_tag) { Fabricate(:tag) } diff --git a/spec/models/theme_field_spec.rb b/spec/models/theme_field_spec.rb index 8b99f55ef2..ce2a1b6220 100644 --- a/spec/models/theme_field_spec.rb +++ b/spec/models/theme_field_spec.rb @@ -402,7 +402,7 @@ HTML end end - context "SVG sprite theme fields" do + describe "SVG sprite theme fields" do let(:upload) { Fabricate(:upload) } let(:theme) { Fabricate(:theme) } let(:theme_field) { ThemeField.create!(theme: theme, target_id: 0, name: SvgSprite.theme_sprite_variable_name, upload: upload, value: "", value_baked: "baked", type_id: ThemeField.types[:theme_upload_var]) } @@ -429,8 +429,7 @@ HTML end end - context 'local js assets' do - + describe 'local js assets' do let :js_content do "// not transpiled; console.log('hello world');" end @@ -515,5 +514,4 @@ HTML expect(theme.scss_variables).not_to include("theme_uploads") end end - end diff --git a/spec/models/theme_spec.rb b/spec/models/theme_spec.rb index 5171121415..2689f613e6 100644 --- a/spec/models/theme_spec.rb +++ b/spec/models/theme_spec.rb @@ -222,7 +222,7 @@ HTML end end - context "plugin api" do + describe "plugin api" do def transpile(html) f = ThemeField.create!(target_id: Theme.targets[:mobile], theme_id: 1, name: "after_header", value: html) f.ensure_baked! @@ -267,7 +267,7 @@ HTML end end - context 'theme upload vars' do + describe 'theme upload vars' do let :image do file_from_fixtures("logo.png") end @@ -298,7 +298,7 @@ HTML end end - context "theme settings" do + describe "theme settings" do it "allows values to be used in scss" do theme.set_field(target: :settings, name: :yaml, value: "background_color: red\nfont_size: 25px") theme.set_field(target: :common, name: :scss, value: 'body {background-color: $background_color; font-size: $font-size}') diff --git a/spec/models/top_topic_spec.rb b/spec/models/top_topic_spec.rb index 27a4620c9a..6542779e29 100644 --- a/spec/models/top_topic_spec.rb +++ b/spec/models/top_topic_spec.rb @@ -1,9 +1,8 @@ # frozen_string_literal: true RSpec.describe TopTopic do - describe '#sorted_periods' do - context "verify enum sequence" do + context "when verifying enum sequence" do before do @sorted_periods = TopTopic.sorted_periods end @@ -20,8 +19,7 @@ RSpec.describe TopTopic do it { is_expected.to belong_to :topic } - context "refresh!" do - + describe ".refresh!" do fab!(:t1) { Fabricate(:topic) } fab!(:t2) { Fabricate(:topic) } @@ -30,7 +28,6 @@ RSpec.describe TopTopic do end context "after calculating" do - before do TopTopic.refresh! end @@ -42,7 +39,6 @@ RSpec.describe TopTopic do end describe "#compute_top_score_for" do - fab!(:user) { Fabricate(:user) } fab!(:coding_horror) { Fabricate(:coding_horror) } @@ -139,7 +135,6 @@ RSpec.describe TopTopic do expect(top_topics.where(topic_id: topic_1.id).pluck_first(:yearly_score)).to eq(27) expect(top_topics.where(topic_id: topic_2.id).pluck_first(:yearly_score)).to be_within(0.0000000001).of(18.301029995664) expect(top_topics.where(topic_id: topic_3.id).pluck_first(:yearly_score)).to be_within(0.0000000001).of(10.602059991328) - end end end diff --git a/spec/models/topic_converter_spec.rb b/spec/models/topic_converter_spec.rb index a8cdf0cbb2..084d50f0d1 100644 --- a/spec/models/topic_converter_spec.rb +++ b/spec/models/topic_converter_spec.rb @@ -1,8 +1,7 @@ # frozen_string_literal: true RSpec.describe TopicConverter do - - context 'convert_to_public_topic' do + describe 'convert_to_public_topic' do fab!(:admin) { Fabricate(:admin) } fab!(:author) { Fabricate(:user) } fab!(:category) { Fabricate(:category, topic_count: 1) } @@ -14,7 +13,7 @@ RSpec.describe TopicConverter do Category.find(SiteSetting.uncategorized_category_id) end - context 'success' do + context 'with success' do it "converts private message to regular topic" do SiteSetting.allow_uncategorized_topics = true topic = nil @@ -44,7 +43,7 @@ RSpec.describe TopicConverter do expect(topic.category_id).to eq(SiteSetting.uncategorized_category_id) end - describe 'when uncategorized category is not allowed' do + context 'when uncategorized category is not allowed' do before do SiteSetting.allow_uncategorized_topics = false category.update!(read_restricted: false) @@ -65,7 +64,7 @@ RSpec.describe TopicConverter do end end - describe 'when a custom category_id is given' do + context 'when a custom category_id is given' do it 'should convert private message into the right category' do topic = TopicConverter.new(first_post.topic, admin).convert_to_public_topic(category.id) @@ -118,14 +117,14 @@ RSpec.describe TopicConverter do end end - context 'convert_to_private_message' do + describe 'convert_to_private_message' do fab!(:admin) { Fabricate(:admin) } fab!(:author) { Fabricate(:user) } fab!(:category) { Fabricate(:category) } fab!(:topic) { Fabricate(:topic, user: author, category_id: category.id) } fab!(:post) { Fabricate(:post, topic: topic, user: topic.user) } - context 'success' do + context 'with success' do it "converts regular topic to private message" do private_message = topic.convert_to_private_message(post.user) expect(private_message).to be_valid @@ -207,7 +206,7 @@ RSpec.describe TopicConverter do end end - context 'topic has replies' do + context 'when topic has replies' do before do @replied_user = Fabricate(:coding_horror) create_post(topic: topic, user: @replied_user) @@ -234,7 +233,7 @@ RSpec.describe TopicConverter do end end - context 'user_profiles with newly converted PM as featured topic' do + context 'with user_profiles with newly converted PM as featured topic' do it "sets all matching user_profile featured topic ids to nil" do author.user_profile.update(featured_topic: topic) topic.convert_to_private_message(admin) @@ -242,6 +241,5 @@ RSpec.describe TopicConverter do expect(author.user_profile.reload.featured_topic).to eq(nil) end end - end end diff --git a/spec/models/topic_embed_spec.rb b/spec/models/topic_embed_spec.rb index a112a126ff..bedfb02978 100644 --- a/spec/models/topic_embed_spec.rb +++ b/spec/models/topic_embed_spec.rb @@ -9,7 +9,6 @@ RSpec.describe TopicEmbed do it { is_expected.to validate_presence_of :embed_url } describe '.import' do - fab!(:user) { Fabricate(:user) } let(:title) { "How to turn a fish from good to evil in 30 seconds" } let(:url) { 'http://eviltrout.com/123' } @@ -23,7 +22,7 @@ RSpec.describe TopicEmbed do expect(TopicEmbed.count).to eq(0) end - context 'creation of a post' do + context 'when creating a post' do let!(:post) { TopicEmbed.import(user, url, title, contents) } let(:topic_embed) { TopicEmbed.find_by(post: post) } @@ -128,7 +127,7 @@ RSpec.describe TopicEmbed do end end - context "post creation supports markdown rendering" do + context "when post creation supports markdown rendering" do before do SiteSetting.embed_support_markdown = true end @@ -215,7 +214,7 @@ RSpec.describe TopicEmbed do end end - context 'post with allowed classes "foo" and "emoji"' do + context 'with post with allowed classes "foo" and "emoji"' do fab!(:user) { Fabricate(:user) } let(:url) { 'http://eviltrout.com/123' } let(:contents) { "my normal size emoji

Hi

" } @@ -247,7 +246,7 @@ RSpec.describe TopicEmbed do end end - context 'post with author metadata' do + context 'with post with author metadata' do fab!(:user) { Fabricate(:user, username: 'eviltrout') } let(:url) { 'http://eviltrout.com/321' } let(:contents) { 'rich and morty' } @@ -263,7 +262,7 @@ RSpec.describe TopicEmbed do end end - context 'post with no allowed classes' do + context 'with post with no allowed classes' do fab!(:user) { Fabricate(:user) } let(:url) { 'http://eviltrout.com/123' } let(:contents) { "my normal size emoji

Hi

" } @@ -291,7 +290,7 @@ RSpec.describe TopicEmbed do end end - context "non-ascii URL" do + context "with non-ascii URL" do let(:url) { 'http://eviltrout.com/test/ماهی' } let(:contents) { "سلاماین یک پاراگراف آزمون است." } @@ -305,7 +304,7 @@ RSpec.describe TopicEmbed do end end - context "encoded URL" do + context "with encoded URL" do let(:url) { 'http://example.com/hello%20world' } let(:contents) { "Hello World!" } @@ -319,7 +318,7 @@ RSpec.describe TopicEmbed do end end - context "non-http URL" do + context "with non-http URL" do it "throws an error" do url = '/test.txt' @@ -327,7 +326,7 @@ RSpec.describe TopicEmbed do end end - context "emails" do + context "with emails" do let(:url) { 'http://example.com/foo' } let(:contents) { '

URL encoded @ symbol

normal mailto link

' } @@ -343,7 +342,7 @@ RSpec.describe TopicEmbed do end end - context "malformed href" do + context "with malformed href" do let(:url) { 'http://example.com/foo' } let(:contents) { '

Baz

' } @@ -356,7 +355,7 @@ RSpec.describe TopicEmbed do end end - context 'canonical links' do + context 'with canonical links' do let(:url) { 'http://eviltrout.com/123?asd' } let(:canonical_url) { 'http://eviltrout.com/123' } let(:content) { "" } diff --git a/spec/models/topic_link_click_spec.rb b/spec/models/topic_link_click_spec.rb index 4d3fc35cd5..4f43fc456d 100644 --- a/spec/models/topic_link_click_spec.rb +++ b/spec/models/topic_link_click_spec.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true RSpec.describe TopicLinkClick do - it { is_expected.to belong_to :topic_link } it { is_expected.to belong_to :user } it { is_expected.to validate_presence_of :topic_link_id } @@ -10,7 +9,7 @@ RSpec.describe TopicLinkClick do URI.parse('http://test.host') end - context 'topic_links' do + describe 'topic_links' do before do @topic = Fabricate(:topic) @post = Fabricate(:post_with_external_links, user: @topic.user, topic: @topic) @@ -22,7 +21,7 @@ RSpec.describe TopicLinkClick do expect(@topic_link.clicks).to eq(0) end - context 'create' do + describe '.create' do before do TopicLinkClick.create(topic_link: @topic_link, ip_address: '192.168.1.1') end @@ -37,10 +36,8 @@ RSpec.describe TopicLinkClick do end end - context 'create_from' do - + describe '.create_from' do it "works correctly" do - # returns nil to prevent exploits click = TopicLinkClick.create_from(url: "http://url-that-doesnt-exist.com", post_id: @post.id, ip: '127.0.0.1') expect(click).to eq(nil) @@ -93,7 +90,7 @@ RSpec.describe TopicLinkClick do end - context "relative urls" do + context "with relative urls" do let(:host) { URI.parse(Discourse.base_url).host } it 'returns the url' do @@ -113,8 +110,7 @@ RSpec.describe TopicLinkClick do expect(redirect).to eq(url) end - context "cdn links" do - + context "with cdn links" do before do Rails.configuration.action_controller.asset_host = "https://cdn.discourse.org/stuff" end @@ -161,8 +157,7 @@ RSpec.describe TopicLinkClick do end - context "s3 cdns" do - + context "with s3 cdns" do it "works with s3 urls" do setup_s3 SiteSetting.s3_cdn_url = "https://discourse-s3-cdn.global.ssl.fastly.net" @@ -236,7 +231,7 @@ RSpec.describe TopicLinkClick do end end - context 'same base URL with different query' do + context 'with same base URL with different query' do it 'are handled differently' do post = Fabricate(:post, raw: <<~RAW) no query param: http://example.com/a @@ -282,11 +277,7 @@ RSpec.describe TopicLinkClick do expect(@click.topic_link).to eq(@topic_link) expect(@url).to eq(@topic_link.url) end - end - end - end - end diff --git a/spec/models/topic_link_spec.rb b/spec/models/topic_link_spec.rb index e95c78a31f..19f94bad35 100644 --- a/spec/models/topic_link_spec.rb +++ b/spec/models/topic_link_spec.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true RSpec.describe TopicLink do - it { is_expected.to validate_presence_of :url } def test_uri @@ -74,11 +73,9 @@ RSpec.describe TopicLink do expect(new_ids).to contain_exactly(*old_ids) end - end describe 'internal links' do - it "extracts onebox" do other_topic = Fabricate(:topic, user: user) Fabricate(:post, topic: other_topic, user: user, raw: "some content for the first post") @@ -99,8 +96,7 @@ RSpec.describe TopicLink do expect(link.url).to eq(url) end - context 'topic link' do - + context 'with topic link' do fab!(:other_topic) do Fabricate(:topic, user: user) end @@ -111,7 +107,6 @@ RSpec.describe TopicLink do end it 'works' do - # ensure other_topic has a post post @@ -237,7 +232,7 @@ RSpec.describe TopicLink do end end - context "link to a user on discourse" do + context "with link to a user on discourse" do let(:post) { Fabricate(:post, topic: topic, user: user, raw: "user") } before do @@ -249,7 +244,7 @@ RSpec.describe TopicLink do end end - context "link to a discourse resource like a FAQ" do + context "with link to a discourse resource like a FAQ" do let(:post) { Fabricate(:post, topic: topic, user: user, raw: "faq link here") } before do TopicLink.extract_from(post) @@ -260,7 +255,7 @@ RSpec.describe TopicLink do end end - context "mention links" do + context "with mention links" do let(:post) { Fabricate(:post, topic: topic, user: user, raw: "Hey #{user.username_lower}") } before do @@ -272,7 +267,7 @@ RSpec.describe TopicLink do end end - context "email address" do + context "with email address" do it "does not extract a link" do post = Fabricate(:post, topic: topic, user: user, raw: "Valid email: foo@bar.com\n\nInvalid email: rfc822;name@domain.com") TopicLink.extract_from(post) @@ -280,7 +275,7 @@ RSpec.describe TopicLink do end end - context "mail link" do + context "with mail link" do let(:post) { Fabricate(:post, topic: topic, user: user, raw: "[email]bar@example.com[/email]") } it 'does not extract a link' do @@ -289,7 +284,7 @@ RSpec.describe TopicLink do end end - context "quote links" do + context "with quote links" do it "sets quote correctly" do linked_post = Fabricate(:post, topic: topic, user: user, raw: "my test post") quoting_post = Fabricate(:post, raw: "[quote=\"#{user.username}, post: #{linked_post.post_number}, topic: #{topic.id}\"]\nquote\n[/quote]") @@ -302,7 +297,7 @@ RSpec.describe TopicLink do end end - context "link to a local attachments" do + context "with link to a local attachments" do let(:post) { Fabricate(:post, topic: topic, user: user, raw: 'ruby.rb') } it "extracts the link" do @@ -322,7 +317,7 @@ RSpec.describe TopicLink do end - context "link to an attachments uploaded on S3" do + context "with link to an attachments uploaded on S3" do let(:post) { Fabricate(:post, topic: topic, user: user, raw: 'ruby.rb') } it "extracts the link" do @@ -519,5 +514,4 @@ RSpec.describe TopicLink do expect { TopicLink.extract_from(post) }.to_not raise_error end end - end diff --git a/spec/models/topic_list_spec.rb b/spec/models/topic_list_spec.rb index 18dfb84a2f..89401996d1 100644 --- a/spec/models/topic_list_spec.rb +++ b/spec/models/topic_list_spec.rb @@ -28,7 +28,7 @@ RSpec.describe TopicList do end end - context "preload" do + describe "preload" do it "allows preloading of data" do preloaded_topic = false preloader = lambda do |topics, topic_list| diff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rb index 8107438612..b21761e952 100644 --- a/spec/models/topic_spec.rb +++ b/spec/models/topic_spec.rb @@ -14,7 +14,7 @@ RSpec.describe Topic do fab!(:group) { Fabricate(:group) } fab!(:trust_level_2) { Fabricate(:user, trust_level: SiteSetting.min_trust_level_to_allow_invite) } - context 'validations' do + describe 'Validations' do let(:topic) { Fabricate.build(:topic) } describe "#featured_link" do @@ -160,7 +160,6 @@ RSpec.describe Topic do end end end - end it { is_expected.to rate_limit } @@ -210,8 +209,8 @@ RSpec.describe Topic do end end - context 'slug' do - context 'encoded generator' do + describe 'slug' do + context 'with encoded generator' do before { SiteSetting.slug_generation_method = 'encoded' } context 'with ascii letters' do @@ -247,7 +246,7 @@ RSpec.describe Topic do end end - context 'none generator' do + context 'with none generator' do let!(:title) { "熱帶風暴畫眉" } let!(:slug) { "topic" } let!(:topic) { Fabricate.build(:topic, title: title) } @@ -286,7 +285,7 @@ RSpec.describe Topic do end end - context 'slug computed hooks' do + describe 'slug computed hooks' do before do invert_slug = ->(topic, slug, title) { slug.reverse } Topic.slug_computed_callbacks << invert_slug @@ -318,7 +317,7 @@ RSpec.describe Topic do end end - context "updating a title to be shorter" do + describe "updating a title to be shorter" do let!(:topic) { Fabricate(:topic) } it "doesn't update it to be shorter due to cleaning using TextCleaner" do @@ -327,7 +326,7 @@ RSpec.describe Topic do end end - context 'private message title' do + describe 'private message title' do before do SiteSetting.min_topic_title_length = 15 SiteSetting.min_personal_message_title_length = 3 @@ -344,7 +343,7 @@ RSpec.describe Topic do end end - context 'admin topic title' do + describe 'admin topic title' do it 'allows really short titles' do pm = Fabricate.build(:private_message_topic, user: admin, title: 'a') expect(pm).to be_valid @@ -356,7 +355,7 @@ RSpec.describe Topic do end end - context 'topic title uniqueness' do + describe 'topic title uniqueness' do fab!(:category1) { Fabricate(:category) } fab!(:category2) { Fabricate(:category) } @@ -428,11 +427,9 @@ RSpec.describe Topic do expect(new_topic_different_cat.errors[:title]).to include(I18n.t("errors.messages.too_short", count: 134)) end end - end - context 'html in title' do - + describe 'html in title' do def build_topic_with_title(title) build(:topic, title: title).tap { |t| t.valid? } end @@ -472,14 +469,14 @@ RSpec.describe Topic do expect(topic_script.fancy_title).not_to include("