Commit 03081a03 authored by Peter Leitzen's avatar Peter Leitzen

Merge branch 'leaky-constant-fix-33' into 'master'

Fix leaky constant in relation factory spec

See merge request gitlab-org/gitlab!32129
parents 2d7ba6f0 be1647f5
...@@ -353,7 +353,6 @@ RSpec/LeakyConstantDeclaration: ...@@ -353,7 +353,6 @@ RSpec/LeakyConstantDeclaration:
- 'spec/lib/gitlab/config/entry/simplifiable_spec.rb' - 'spec/lib/gitlab/config/entry/simplifiable_spec.rb'
- 'spec/lib/gitlab/git/diff_collection_spec.rb' - 'spec/lib/gitlab/git/diff_collection_spec.rb'
- 'spec/lib/gitlab/import_export/import_test_coverage_spec.rb' - 'spec/lib/gitlab/import_export/import_test_coverage_spec.rb'
- 'spec/lib/gitlab/import_export/project/relation_factory_spec.rb'
- 'spec/lib/gitlab/quick_actions/dsl_spec.rb' - 'spec/lib/gitlab/quick_actions/dsl_spec.rb'
- 'spec/lib/marginalia_spec.rb' - 'spec/lib/marginalia_spec.rb'
- 'spec/mailers/notify_spec.rb' - 'spec/mailers/notify_spec.rb'
......
---
title: Fix leaky constant issue in relation factory spec
merge_request: 32129
author: Rajendra Kadam
type: fixed
...@@ -18,6 +18,22 @@ describe Gitlab::ImportExport::Project::RelationFactory do ...@@ -18,6 +18,22 @@ describe Gitlab::ImportExport::Project::RelationFactory do
excluded_keys: excluded_keys) excluded_keys: excluded_keys)
end end
before do
# Mocks an ActiveRecordish object with the dodgy columns
stub_const('FooModel', Class.new)
FooModel.class_eval do
include ActiveModel::Model
def initialize(params = {})
params.each { |key, value| send("#{key}=", value) }
end
def values
instance_variables.map { |ivar| instance_variable_get(ivar) }
end
end
end
context 'hook object' do context 'hook object' do
let(:relation_sym) { :hooks } let(:relation_sym) { :hooks }
let(:id) { 999 } let(:id) { 999 }
...@@ -83,19 +99,6 @@ describe Gitlab::ImportExport::Project::RelationFactory do ...@@ -83,19 +99,6 @@ describe Gitlab::ImportExport::Project::RelationFactory do
end end
end end
# Mocks an ActiveRecordish object with the dodgy columns
class FooModel
include ActiveModel::Model
def initialize(params = {})
params.each { |key, value| send("#{key}=", value) }
end
def values
instance_variables.map { |ivar| instance_variable_get(ivar) }
end
end
context 'merge_request object' do context 'merge_request object' do
let(:relation_sym) { :merge_requests } let(:relation_sym) { :merge_requests }
...@@ -208,11 +211,12 @@ describe Gitlab::ImportExport::Project::RelationFactory do ...@@ -208,11 +211,12 @@ describe Gitlab::ImportExport::Project::RelationFactory do
} }
end end
class HazardousFooModel < FooModel before do
stub_const('HazardousFooModel', Class.new(FooModel))
HazardousFooModel.class_eval do
attr_accessor :service_id, :moved_to_id, :namespace_id, :ci_id, :random_project_id, :random_id, :milestone_id, :project_id attr_accessor :service_id, :moved_to_id, :namespace_id, :ci_id, :random_project_id, :random_id, :milestone_id, :project_id
end end
before do
allow(HazardousFooModel).to receive(:reflect_on_association).and_return(nil) allow(HazardousFooModel).to receive(:reflect_on_association).and_return(nil)
end end
...@@ -246,11 +250,12 @@ describe Gitlab::ImportExport::Project::RelationFactory do ...@@ -246,11 +250,12 @@ describe Gitlab::ImportExport::Project::RelationFactory do
Gitlab::ImportExport::Project::RelationFactory::PROJECT_REFERENCES.map { |ref| { ref => 99 } }.inject(:merge) Gitlab::ImportExport::Project::RelationFactory::PROJECT_REFERENCES.map { |ref| { ref => 99 } }.inject(:merge)
end end
class ProjectFooModel < FooModel before do
stub_const('ProjectFooModel', Class.new(FooModel))
ProjectFooModel.class_eval do
attr_accessor(*Gitlab::ImportExport::Project::RelationFactory::PROJECT_REFERENCES) attr_accessor(*Gitlab::ImportExport::Project::RelationFactory::PROJECT_REFERENCES)
end end
before do
allow(ProjectFooModel).to receive(:reflect_on_association).and_return(nil) allow(ProjectFooModel).to receive(:reflect_on_association).and_return(nil)
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