Commit edb55604 authored by Jan Provaznik's avatar Jan Provaznik

Merge branch 'rc/fix_leaky_constants' into 'master'

Fix leaky rspec constants

See merge request gitlab-org/gitlab!27630
parents ff127fcd 21443630
......@@ -331,8 +331,21 @@ RSpec/LeakyConstantDeclaration:
Enabled: true
Exclude:
- 'spec/**/*.rb'
- 'ee/spec/**/*.rb'
- 'qa/spec/**/*.rb'
- 'ee/spec/lib/gitlab/geo/log_cursor/logger_spec.rb'
- 'ee/spec/lib/gitlab/geo/log_helpers_spec.rb'
- 'ee/spec/lib/gitlab/geo/replicator_spec.rb'
- 'ee/spec/mailers/emails/service_desk_spec.rb'
- 'ee/spec/migrations/remove_creations_in_gitlab_subscription_histories_spec.rb'
- 'ee/spec/migrations/set_resolved_state_on_vulnerabilities_spec.rb'
- 'ee/spec/models/repository_spec.rb'
- 'ee/spec/presenters/security/vulnerable_project_presenter_spec.rb'
- 'ee/spec/serializers/vulnerable_project_entity_spec.rb'
- 'ee/spec/services/clusters/applications/check_upgrade_progress_service_spec.rb'
- 'ee/spec/services/dashboard/projects/list_service_spec.rb'
- 'ee/spec/services/metrics/dashboard/clone_dashboard_service_spec.rb'
- 'ee/spec/support/shared_contexts/epic_aggregate_constants.rb'
- 'ee/spec/workers/elastic_namespace_rollout_worker_spec.rb'
RSpec/EmptyLineAfterHook:
Enabled: false
......
......@@ -5,11 +5,15 @@ require 'spec_helper'
describe OperationsController do
include Rails.application.routes.url_helpers
PUBLIC = Gitlab::VisibilityLevel::PUBLIC
PRIVATE = Gitlab::VisibilityLevel::PRIVATE
let(:user) { create(:user) }
before do
stub_const('PUBLIC', Gitlab::VisibilityLevel::PUBLIC)
stub_const('PRIVATE', Gitlab::VisibilityLevel::PRIVATE)
stub_licensed_features(operations_dashboard: true)
sign_in(user)
end
shared_examples 'unlicensed' do |http_method, action|
before do
stub_licensed_features(operations_dashboard: false)
......@@ -22,11 +26,6 @@ describe OperationsController do
end
end
before do
stub_licensed_features(operations_dashboard: true)
sign_in(user)
end
describe 'GET #index' do
it_behaves_like 'unlicensed', :get, :index
......
......@@ -14,6 +14,7 @@ describe 'GlobalSearch', :elastic do
before do
stub_ee_application_setting(elasticsearch_search: true, elasticsearch_indexing: true)
stub_const('POSSIBLE_FEATURES', %i(issues merge_requests wiki_blobs blobs commits).freeze)
project.add_developer(member)
project.add_developer(external_member)
......@@ -166,8 +167,6 @@ describe 'GlobalSearch', :elastic do
expect_items_to_be_found(user, except: :all)
end
POSSIBLE_FEATURES = %i(issues merge_requests wiki_blobs blobs commits).freeze
def expect_items_to_be_found(user, only: nil, except: nil)
arr = if only
[only].flatten.compact
......
......@@ -9,6 +9,8 @@ describe "Admin sends notification", :js, :sidekiq_might_not_need_inline do
let(:user) { create(:user) }
before do
stub_const('NOTIFICATION_TEXT', 'Your project has been moved.')
group.add_developer(user)
sign_in(admin)
......@@ -20,7 +22,6 @@ describe "Admin sends notification", :js, :sidekiq_might_not_need_inline do
it "sends notification" do
perform_enqueued_jobs do
NOTIFICATION_TEXT = "Your project has been moved.".freeze
body = find(:xpath, "//body")
page.within("form#new-admin-email") do
......
......@@ -7,14 +7,14 @@ describe "Admin unsubscribes from notification" do
let_it_be(:urlsafe_email) { Base64.urlsafe_encode64(user.email) }
before do
stub_const('NOTIFICATION_TEXT', 'You have been unsubscribed from receiving GitLab administrator notifications.')
sign_in(user)
visit(unsubscribe_path(urlsafe_email))
end
it "unsubscribes from notifications" do
NOTIFICATION_TEXT = "You have been unsubscribed from receiving GitLab administrator notifications.".freeze
perform_enqueued_jobs do
click_button("Unsubscribe")
end
......
......@@ -3,19 +3,9 @@
require 'spec_helper'
describe Security::PipelineVulnerabilitiesFinder do
class NoDeduplicationMergeReportsService
def initialize(*source_reports)
@source_reports = source_reports
end
def execute
@source_reports.last
end
end
def disable_deduplication
allow(::Security::MergeReportsService).to receive(:new) do |*args|
NoDeduplicationMergeReportsService.new(*args)
instance_double('NoDeduplicationMergeReportsService', execute: args.last)
end
end
......
......@@ -5,8 +5,6 @@ require 'spec_helper'
describe Mutations::DesignManagement::Delete do
include DesignManagementTestHelpers
Errors = Gitlab::Graphql::Errors
let(:issue) { create(:issue) }
let(:current_designs) { issue.designs.current }
let(:user) { issue.author }
......@@ -18,6 +16,10 @@ describe Mutations::DesignManagement::Delete do
let(:mutation) { described_class.new(object: nil, context: { current_user: user }, field: nil) }
before do
stub_const('Errors', Gitlab::Graphql::Errors, transfer_nested_constants: true)
end
def run_mutation
mutation = described_class.new(object: nil, context: { current_user: user }, field: nil)
mutation.resolve(project_path: project.full_path, iid: issue.iid, filenames: filenames)
......@@ -28,7 +30,7 @@ describe Mutations::DesignManagement::Delete do
{ errors: [], version: DesignManagement::Version.for_issue(issue).ordered.first }
end
shared_examples "failures" do |error: Errors::ResourceNotAvailable|
shared_examples "failures" do |error: Gitlab::Graphql::Errors::ResourceNotAvailable|
it "raises #{error.name}" do
expect { run_mutation }.to raise_error(error)
end
......@@ -63,7 +65,7 @@ describe Mutations::DesignManagement::Delete do
end
it 'fails with an argument error' do
expect { run_mutation }.to raise_error(Errors::ArgumentError)
expect { run_mutation }.to raise_error(Gitlab::Graphql::Errors::ArgumentError)
end
end
......
......@@ -8,11 +8,15 @@ describe CsvBuilder do
let(:subject) { described_class.new(fake_relation, 'Q & A' => :question, 'Reversed' => -> (o) { o.question.to_s.reverse }) }
let(:csv_data) { subject.render }
class FakeRelation < Array
before do
stub_const('FakeRelation', Array)
FakeRelation.class_eval do
def find_each(&block)
each(&block)
end
end
end
it 'generates a csv' do
expect(csv_data.scan(/(,|\n)/).join).to include ",\n,"
......
......@@ -5,31 +5,7 @@ require 'spec_helper'
describe Gitlab::Geo::CronManager, :geo do
include ::EE::GeoHelpers
def job(name)
Sidekiq::Cron::Job.find(name)
end
subject(:manager) { described_class.new }
describe '#execute' do
let_it_be(:primary) { create(:geo_node, :primary) }
let_it_be(:secondary) { create(:geo_node) }
def init_cron_job(job_name, class_name)
job = Sidekiq::Cron::Job.new(
name: job_name,
cron: '0 * * * *',
class: class_name
)
job.enable!
end
def count_enabled
JOBS.count { |job_name| job(job_name).enabled? }
end
JOBS = %w[
jobs = %w[
ldap_test
repository_check_worker
geo_repository_verification_primary_batch_worker
......@@ -42,13 +18,15 @@ describe Gitlab::Geo::CronManager, :geo do
geo_migrated_local_files_clean_up_worker
].freeze
before(:all) do
JOBS.each { |name| init_cron_job(name, name.camelize) }
def job(name)
Sidekiq::Cron::Job.find(name)
end
after(:all) do
JOBS.each { |name| job(name)&.destroy }
end
subject(:manager) { described_class.new }
describe '#execute' do
let_it_be(:primary) { create(:geo_node, :primary) }
let_it_be(:secondary) { create(:geo_node) }
let(:common_jobs) { [job('geo_metrics_update_worker'), job('repository_check_worker')] }
let(:ldap_test_job) { job('ldap_test') }
......@@ -64,6 +42,28 @@ describe Gitlab::Geo::CronManager, :geo do
]
end
before(:all) do
jobs.each { |name| init_cron_job(name, name.camelize) }
end
after(:all) do
jobs.each { |name| job(name)&.destroy }
end
def init_cron_job(job_name, class_name)
job = Sidekiq::Cron::Job.new(
name: job_name,
cron: '0 * * * *',
class: class_name
)
job.enable!
end
def count_enabled(jobs)
jobs.count { |job_name| job(job_name).enabled? }
end
context 'on a Geo primary' do
before do
stub_current_geo_node(primary)
......@@ -91,7 +91,7 @@ describe Gitlab::Geo::CronManager, :geo do
it 'does not change current job configuration' do
allow(Geo).to receive(:connected?).and_return(false)
expect { manager.execute }.not_to change { count_enabled }
expect { manager.execute }.not_to change { count_enabled(jobs) }
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment