DEV: Automatically require 'rails_helper' in all specs (#16077)

It's very easy to forget to add `require 'rails_helper'` at the top of every core/plugin spec file, and omissions can cause some very confusing/sporadic errors.

By setting this flag in `.rspec`, we can remove the need for `require 'rails_helper'` entirely.
This commit is contained in:
David Taylor 2022-03-01 17:50:50 +00:00 committed by GitHub
parent 9415ec91a1
commit c9dab6fd08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
815 changed files with 1 additions and 1487 deletions

1
.rspec
View File

@ -1 +1,2 @@
--colour
--require 'rails_helper'

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe "Local Dates" do
before do
freeze_time DateTime.parse('2018-11-10 12:00')

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
def generate_html(text, opts = {})
output = "<p><span"
output += " data-date=\"#{opts[:date]}\"" if opts[:date]

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe Post do
before do

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe DiscourseNarrativeBot::AdvancedUserNarrative do
fab!(:narrative_bot) { ::DiscourseNarrativeBot::Base.new }
fab!(:discobot_user) { narrative_bot.discobot_user }

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe DiscourseNarrativeBot::NewUserNarrative do
fab!(:welcome_topic) { Fabricate(:topic, title: 'Welcome to Discourse') }
fab!(:narrative_bot) { ::DiscourseNarrativeBot::Base.new }

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe DiscourseNarrativeBot::Store do
describe '.set' do
it 'should set the right value in the plugin store' do

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe DiscourseNarrativeBot::TrackSelector do
let(:user) { Fabricate(:user) }
let(:narrative_bot) { ::DiscourseNarrativeBot::Base.new }

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Jobs::DiscourseNarrativeBot::GrantBadges do
let(:user) { Fabricate(:user) }
let(:other_user) { Fabricate(:user) }

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe Jobs::DiscourseNarrativeBot::RemapOldBotImages do
context "when bot's post contains an old link" do
let!(:post) do

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Jobs::SendDefaultWelcomeMessage do
let(:user) { Fabricate(:user) }

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe DiscourseNarrativeBot::CertificateGenerator do
let(:user) { Fabricate(:user) }
let(:avatar_url) { 'http://test.localhost/cdn/avatar.png' }

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe "Discobot Certificate" do
let(:user) { Fabricate(:user, name: 'Jeff Atwood') }

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe "Discobot welcome post" do
let(:user) { Fabricate(:user) }

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe User do
let(:user) { Fabricate(:user) }
let(:profile_page_url) { "#{Discourse.base_url}/users/#{user.username}" }

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe "discourse-presence" do
describe 'PresenceChannel configuration' do
fab!(:user) { Fabricate(:user) }

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe DiscoursePoll::Poll do
fab!(:user) { Fabricate(:user) }
fab!(:user_2) { Fabricate(:user) }

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe DiscoursePoll::PollsUpdater do
def update(post, polls)

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe PrettyText do
def n(html)

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe ::DiscoursePoll::Poll do
describe ".transform_for_user_field_override" do
it "Transforms UserField name if a matching CustomUserField is present" do

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
def serialize_option(option, user)
PollOptionSerializer.new(
option,

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe 'SiteSetting.styleguide_admin_only' do
before do
SiteSetting.styleguide_enabled = true

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe 'Styleguide assets' do
before do
SiteSetting.styleguide_enabled = true

View File

@ -1,8 +1,6 @@
# coding: utf-8
# frozen_string_literal: true
require 'rails_helper'
describe ApplicationHelper do
describe "preload_script" do

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe TopicsHelper do
describe "#categories_breadcrumb" do

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe UserNotificationsHelper do
let(:upload_path) { Discourse.store.upload_path }

View File

@ -1,6 +1,5 @@
# frozen_string_literal: true
require "rails_helper"
require "import_export"
describe ImportExport::CategoryExporter do

View File

@ -1,6 +1,5 @@
# frozen_string_literal: true
require "rails_helper"
require "import_export/category_structure_exporter"
describe ImportExport::CategoryStructureExporter do

View File

@ -1,6 +1,5 @@
# frozen_string_literal: true
require "rails_helper"
require "import_export/group_exporter"
describe ImportExport::GroupExporter do

View File

@ -1,6 +1,5 @@
# frozen_string_literal: true
require "rails_helper"
require "import_export"
describe ImportExport::Importer do

View File

@ -1,6 +1,5 @@
# frozen_string_literal: true
require "rails_helper"
require "import_export"
describe ImportExport::TopicExporter do

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe 'Setting changes' do
describe '#must_approve_users' do
before { SiteSetting.must_approve_users = false }

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe 'api keys' do
let(:user) { Fabricate(:user) }
let(:api_key) { ApiKey.create!(user_id: user.id, created_by_id: Discourse.system_user) }

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe "auto reject reviewable users" do
context "reviewable users" do
fab!(:old_user) { Fabricate(:reviewable, created_at: 80.days.ago) }

View File

@ -1,8 +1,6 @@
# encoding: UTF-8
# frozen_string_literal: true
require 'rails_helper'
describe "category tag restrictions" do
def filter_allowed_tags(opts = {})

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe 'content security policy integration' do
it "adds the csp headers correctly" do

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require "rails_helper"
describe EmailStyle do
context "ERB evaluation" do

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require "rails_helper"
describe PostAction do
it "triggers the 'flag_reviewed' event when there was at least one flag" do

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe Group do
let(:group) do
Fabricate(

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe 'invalid requests', type: :request do
before do
@orig_logger = Rails.logger

View File

@ -1,8 +1,6 @@
# encoding: UTF-8
# frozen_string_literal: true
require 'rails_helper'
describe 'invite only' do
describe '#create invite only' do

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe 'message bus integration' do
it "allows anonymous requests to the messagebus" do

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe 'multisite', type: [:multisite, :request] do
it "works" do
get "http://test.localhost/session/csrf.json"

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe 'multisite', type: [:multisite, :request] do
it "should always allow /srv/status through" do
get "http://unknown.com/srv/status"

View File

@ -1,8 +1,6 @@
# encoding: UTF-8
# frozen_string_literal: true
require 'rails_helper'
describe 'rate limiter integration' do
before do

View File

@ -1,8 +1,6 @@
# encoding: UTF-8
# frozen_string_literal: true
require 'rails_helper'
describe "spammers on same IP" do
let(:ip_address) { '182.189.119.174' }

View File

@ -1,8 +1,6 @@
# encoding: UTF-8
# frozen_string_literal: true
require 'rails_helper'
describe "spam rules for users" do
describe 'auto-silence users based on flagging' do

View File

@ -1,8 +1,6 @@
# encoding: UTF-8
# frozen_string_literal: true
require 'rails_helper'
describe Topic do
let(:job_klass) { Jobs::CloseTopic }

View File

@ -1,6 +1,4 @@
# frozen_string_literal: true
require 'rails_helper'
describe "Topic Thumbnails" do
before do
SiteSetting.create_thumbnails = true

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe WatchedWord do
fab!(:tl2_user) { Fabricate(:user, trust_level: TrustLevel[2]) }
fab!(:admin) { Fabricate(:admin) }

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require "rails_helper"
def list_files(base_dir, pattern = '*')
Dir[File.join("#{base_dir}", pattern)]
end

View File

@ -1,6 +1,4 @@
# frozen_string_literal: true
require 'rails_helper'
describe "CommonMark" do
it 'passes spec' do

View File

@ -1,6 +1,5 @@
# frozen_string_literal: true
require "rails_helper"
require "i18n/duplicate_key_finder"
def extract_locale(path)

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require "rails_helper"
describe "constants match ruby" do
let(:ctx) { MiniRacer::Context.new }

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require "rails_helper"
describe 'Oj' do
it "is enabled" do
classes = Set.new

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require "rails_helper"
describe ::Jobs::Onceoff do
it "can run all once off jobs without errors" do
# Load all once offs

View File

@ -1,6 +1,5 @@
# frozen_string_literal: true
require "rails_helper"
require "i18n/duplicate_key_finder"
describe "site setting integrity checks" do

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe Jobs::AboutStats do
it 'caches the stats' do
begin

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe Jobs::ActivationReminderEmails do
before { Jobs.run_immediately! }

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Jobs::AutoExpireUserApiKeys do
fab!(:key1) { Fabricate(:readonly_user_api_key) }
fab!(:key2) { Fabricate(:readonly_user_api_key) }

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe Jobs::AutoQueueHandler do
subject { Jobs::AutoQueueHandler.new.execute({}) }

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe Jobs::AutomaticGroupMembership do
it "raises an error when the group id is missing" do

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Jobs::BookmarkReminderNotifications do
subject { described_class.new }

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe Jobs::BulkGrantTrustLevel do
it "raises an error when trust_level is missing" do

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe Jobs::BulkInvite do
describe '#execute' do
fab!(:user) { Fabricate(:user) }

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe Jobs::BumpTopic do
fab!(:admin) { Fabricate(:admin) }
fab!(:user) { Fabricate(:user) }

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe Jobs::CleanDismissedTopicUsers do
fab!(:user) { Fabricate(:user, created_at: 1.days.ago, previous_visit_at: 1.days.ago) }
fab!(:topic) { Fabricate(:topic, created_at: 5.hours.ago) }

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe Jobs::CleanUpAssociatedAccounts do
subject { Jobs::CleanUpAssociatedAccounts.new.execute({}) }

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe Jobs::CleanUpCrawlerStats do
subject { Jobs::CleanUpCrawlerStats.new.execute({}) }

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe Jobs::CleanUpEmailChangeRequests do
it "deletes records older than 1 month" do
very_old = Fabricate(:email_change_request, updated_at: 32.days.ago)

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe Jobs::CleanUpEmailLogs do
fab!(:email_log) { Fabricate(:email_log, created_at: 2.years.ago) }
fab!(:email_log2) { Fabricate(:email_log, created_at: 2.weeks.ago) }

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Jobs::CleanUpInactiveUsers do
it "should clean up new users that have been inactive" do
SiteSetting.clean_up_inactive_users_after_days = 0

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Jobs::CleanUpPostReplyKeys do
it 'removes old post_reply_keys' do
freeze_time

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Jobs::CleanUpUnusedStagedUsers do
fab!(:staged_user) { Fabricate(:user, staged: true) }

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe Jobs::CleanUpUploads do
def fabricate_upload(attributes = {})

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Jobs::CleanUpUserExportTopics do
fab!(:user) { Fabricate(:user) }

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe Jobs::CleanupImapSyncLog do
let(:job_class) { Jobs::CleanupImapSyncLog.new }

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe Jobs::CloseTopic do
fab!(:admin) { Fabricate(:admin) }

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe Jobs::CorrectMissingDualstackUrls do
it 'corrects the urls' do
setup_s3

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe Jobs::CrawlTopicLink do
let(:job) { Jobs::CrawlTopicLink.new }

View File

@ -1,6 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
require 'jobs/regular/create_linked_topic'
describe Jobs::CreateLinkedTopic do

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe Jobs::CreateMissingAvatars do
it "runs correctly without crashing" do
Jobs::CreateMissingAvatars.new.execute(nil)

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe Jobs::CreateRecentPostSearchIndexes do
subject { described_class.new }

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe Jobs::CreateUserReviewable do
let(:user) { Fabricate(:user) }

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe ::Jobs::DashboardStats do
let(:group_message) { GroupMessage.new(Group[:admins].name, :dashboard_problems, limit_once_per: 7.days.to_i) }

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe Jobs::DeleteReplies do
fab!(:admin) { Fabricate(:admin) }

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe Jobs::DeleteTopic do
fab!(:admin) { Fabricate(:admin) }

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe Jobs::DisableBootstrapMode do
context '.execute' do

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Jobs::DownloadAvatarFromUrl do
fab!(:user) { Fabricate(:user) }

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Jobs::DownloadBackupEmail do
fab!(:user) { Fabricate(:admin) }

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Jobs::DownloadProfileBackgroundFromUrl do
fab!(:user) { Fabricate(:user) }

View File

@ -1,6 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
require 'excon'
describe Jobs::EmitWebHookEvent do

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe Jobs::EnableBootstrapMode do
context '.execute' do

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe Jobs::EnqueueDigestEmails do
describe '#target_users' do

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe Jobs::EnqueueSuspectUsers do
before { SiteSetting.approve_suspect_users = true }

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Jobs::EnsureS3UploadsExistence do
context "S3 inventory enabled" do
before do

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe Jobs::ExportCsvFile do
context '#execute' do

View File

@ -1,6 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
require 'csv'
describe Jobs::ExportUserArchive do

View File

@ -1,6 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
require 'jobs/regular/process_post'
describe Jobs::FeatureTopicUsers do

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Jobs::FixOutOfSyncUserUploadedAvatar do
it 'should fix out of sync user uploaded avatars' do
user_with_custom_upload = Fabricate(:user)

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