Commit 88e0da4f authored by Jan Provaznik's avatar Jan Provaznik

Merge branch 'rc/fix_leaky_constants_2' into 'master'

Fixes for RSpec/LeakyConstantDeclaration

See merge request gitlab-org/gitlab!27956
parents 5524a083 68c6fea8
......@@ -328,13 +328,6 @@ RSpec/LeakyConstantDeclaration:
Exclude:
- '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'
......
......@@ -3,13 +3,12 @@
require 'spec_helper'
describe Gitlab::Geo::LogCursor::Logger, :geo do
class LoggerSpec; end
subject(:logger) { described_class.new(LoggerSpec) }
let(:data) { { pid: 111, class: 'LoggerSpec', host: 'localhost', message: 'Test' } }
before do
stub_const('LoggerSpec', Class.new)
stub_const("#{described_class.name}::PID", 111)
end
......
......@@ -3,11 +3,15 @@
require 'spec_helper'
describe Gitlab::Geo::LogHelpers do
class FakeLogHelpersConsumer
include Gitlab::Geo::LogHelpers
before do
stub_const('FakeLogHelpersConsumer', Class.new)
def execute
log_error('Test message')
FakeLogHelpersConsumer.class_eval do
include Gitlab::Geo::LogHelpers
def execute
log_error('Test message')
end
end
end
......
......@@ -4,14 +4,18 @@ require 'spec_helper'
describe Gitlab::Geo::Replicator do
context 'with defined events' do
class DummyReplicator < Gitlab::Geo::Replicator
event :test
event :another_test
before do
stub_const('DummyReplicator', Class.new(Gitlab::Geo::Replicator))
protected
DummyReplicator.class_eval do
event :test
event :another_test
def publish_test(other:)
true
protected
def publish_test(other:)
true
end
end
end
......@@ -36,15 +40,19 @@ describe Gitlab::Geo::Replicator do
end
context 'model DSL' do
class DummyModel
include ActiveModel::Model
before do
stub_const('DummyModel', Class.new)
def self.after_create_commit(*args)
end
DummyModel.class_eval do
include ActiveModel::Model
include Gitlab::Geo::ReplicableModel
def self.after_create_commit(*args)
end
with_replicator DummyReplicator
include Gitlab::Geo::ReplicableModel
with_replicator DummyReplicator
end
end
subject { DummyModel.new }
......
......@@ -15,39 +15,43 @@ describe Emails::ServiceDesk do
let_it_be(:issue) { create(:issue, project: project) }
let(:template) { double(content: template_content) }
class ServiceEmailClass < ApplicationMailer
include GitlabRoutingHelper
include EmailsHelper
include Emails::ServiceDesk
before do
stub_const('ServiceEmailClass', Class.new(ApplicationMailer))
helper GitlabRoutingHelper
helper EmailsHelper
ServiceEmailClass.class_eval do
include GitlabRoutingHelper
include EmailsHelper
include Emails::ServiceDesk
append_view_path Rails.root.join('ee', 'app', 'views', 'notify')
helper GitlabRoutingHelper
helper EmailsHelper
# this method is implemented in Notify class, we don't need to test it
def reply_key
'test-key'
end
append_view_path Rails.root.join('ee', 'app', 'views', 'notify')
# this method is implemented in Notify class, we don't need to test it
def sender(author_id, params = {})
author_id
end
# this method is implemented in Notify class, we don't need to test it
def reply_key
'test-key'
end
# this method is implemented in Notify class
#
# We do not need to test the Notify method, it is already tested in notify_spec
def mail_new_thread(issue, options)
# we need to rewrite this in order to look up templates in the correct directory
self.class.mailer_name = 'notify'
# this method is implemented in Notify class, we don't need to test it
def sender(author_id, params = {})
author_id
end
# this method is implemented in Notify class
#
# We do not need to test the Notify method, it is already tested in notify_spec
def mail_new_thread(issue, options)
# we need to rewrite this in order to look up templates in the correct directory
self.class.mailer_name = 'notify'
# this is needed for default layout
@unsubscribe_url = 'http://unsubscribe.example.com'
# this is needed for default layout
@unsubscribe_url = 'http://unsubscribe.example.com'
mail(options)
mail(options)
end
alias_method :mail_answer_thread, :mail_new_thread
end
alias_method :mail_answer_thread, :mail_new_thread
end
shared_examples 'handle template content' do |template_key|
......
......@@ -4,9 +4,11 @@ require 'spec_helper'
require Rails.root.join('db', 'post_migrate', '20200113151354_remove_creations_in_gitlab_subscription_histories.rb')
describe RemoveCreationsInGitlabSubscriptionHistories do
GITLAB_SUBSCRIPTION_CREATED = 0
GITLAB_SUBSCRIPTION_UPDATED = 1
GITLAB_SUBSCRIPTION_DESTROYED = 2
before do
stub_const('GITLAB_SUBSCRIPTION_CREATED', 0)
stub_const('GITLAB_SUBSCRIPTION_UPDATED', 1)
stub_const('GITLAB_SUBSCRIPTION_DESTROYED', 2)
end
let(:gitlab_subscriptions) { table(:gitlab_subscriptions) }
let(:gitlab_subscription_histories) { table(:gitlab_subscription_histories) }
......
......@@ -4,8 +4,6 @@ require 'spec_helper'
require Rails.root.join('db', 'post_migrate', '20191114173624_set_resolved_state_on_vulnerabilities.rb')
describe SetResolvedStateOnVulnerabilities do
PACK_FORMAT = 'H*'
let(:confidence_levels) do
{ undefined: 0, ignore: 1, unknown: 2, experimental: 3, low: 4, medium: 5, high: 6, confirmed: 7 }
end
......@@ -47,6 +45,8 @@ describe SetResolvedStateOnVulnerabilities do
end
before do
stub_const('PACK_FORMAT', 'H*')
author = users.create!(id: 1, email: 'author@example.com', projects_limit: 10)
closer = users.create!(id: closer_id, email: 'closer@example.com', projects_limit: 10)
namespace = namespaces.create!(id: 1, name: 'namespace_1', path: 'namespace_1', owner_id: author.id)
......
......@@ -7,7 +7,9 @@ describe Repository do
include ::EE::GeoHelpers
include GitHelpers
TestBlob = Struct.new(:path)
before do
stub_const('TestBlob', Struct.new(:path))
end
let_it_be(:primary_node) { create(:geo_node, :primary) }
let_it_be(:secondary_node) { create(:geo_node) }
......
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