Commit fcedb845 authored by Peter Leitzen's avatar Peter Leitzen

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

Fix leaky constant in migration helpers and ignored cols spec

See merge request gitlab-org/gitlab!32170
parents a81bba38 19f942a9
...@@ -351,9 +351,6 @@ RSpec/LeakyConstantDeclaration: ...@@ -351,9 +351,6 @@ RSpec/LeakyConstantDeclaration:
- 'spec/db/schema_spec.rb' - 'spec/db/schema_spec.rb'
- 'spec/lib/feature_spec.rb' - 'spec/lib/feature_spec.rb'
- 'spec/lib/gitlab/config/entry/simplifiable_spec.rb' - 'spec/lib/gitlab/config/entry/simplifiable_spec.rb'
- 'spec/lib/gitlab/database/migration_helpers_spec.rb'
- 'spec/lib/gitlab/database/obsolete_ignored_columns_spec.rb'
- 'spec/lib/gitlab/database/with_lock_retries_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/import_export/project/relation_factory_spec.rb'
......
---
title: Fix leaky constant issue in migration helpers, with lock retries and ignored cols spec
merge_request: 32170
author: Rajendra Kadam
type: fixed
...@@ -3,39 +3,48 @@ ...@@ -3,39 +3,48 @@
require 'spec_helper' require 'spec_helper'
describe Gitlab::Database::ObsoleteIgnoredColumns do describe Gitlab::Database::ObsoleteIgnoredColumns do
module Testing before do
stub_const('Testing', Module.new)
stub_const('Testing::MyBase', Class.new(ActiveRecord::Base))
stub_const('SomeAbstract', Class.new(Testing::MyBase))
stub_const('Testing::B', Class.new(Testing::MyBase))
stub_const('Testing::A', Class.new(SomeAbstract))
stub_const('Testing::C', Class.new(Testing::MyBase))
# Used a fixed date to prevent tests failing across date boundaries # Used a fixed date to prevent tests failing across date boundaries
REMOVE_DATE = Date.new(2019, 12, 16) stub_const('REMOVE_DATE', Date.new(2019, 12, 16))
class MyBase < ApplicationRecord Testing.module_eval do
end Testing::MyBase.class_eval do
end
class SomeAbstract < MyBase SomeAbstract.class_eval do
include IgnorableColumns include IgnorableColumns
self.abstract_class = true self.abstract_class = true
self.table_name = 'projects' self.table_name = 'projects'
ignore_column :unused, remove_after: '2019-01-01', remove_with: '12.0' ignore_column :unused, remove_after: '2019-01-01', remove_with: '12.0'
end end
class B < MyBase Testing::B.class_eval do
include IgnorableColumns include IgnorableColumns
self.table_name = 'issues' self.table_name = 'issues'
ignore_column :id, :other, remove_after: '2019-01-01', remove_with: '12.0' ignore_column :id, :other, remove_after: '2019-01-01', remove_with: '12.0'
ignore_column :not_used_but_still_ignored, remove_after: REMOVE_DATE.to_s, remove_with: '12.1' ignore_column :not_used_but_still_ignored, remove_after: REMOVE_DATE.to_s, remove_with: '12.1'
end end
class A < SomeAbstract Testing::A.class_eval do
ignore_column :also_unused, remove_after: '2019-02-01', remove_with: '12.1' ignore_column :also_unused, remove_after: '2019-02-01', remove_with: '12.1'
ignore_column :not_used_but_still_ignored, remove_after: REMOVE_DATE.to_s, remove_with: '12.1' ignore_column :not_used_but_still_ignored, remove_after: REMOVE_DATE.to_s, remove_with: '12.1'
end end
class C < MyBase Testing::C.class_eval do
self.table_name = 'users' self.table_name = 'users'
end
end end
end end
...@@ -43,7 +52,7 @@ describe Gitlab::Database::ObsoleteIgnoredColumns do ...@@ -43,7 +52,7 @@ describe Gitlab::Database::ObsoleteIgnoredColumns do
describe '#execute' do describe '#execute' do
it 'returns a list of class names and columns pairs' do it 'returns a list of class names and columns pairs' do
Timecop.freeze(Testing::REMOVE_DATE) do Timecop.freeze(REMOVE_DATE) do
expect(subject.execute).to eq([ expect(subject.execute).to eq([
['Testing::A', { ['Testing::A', {
'unused' => IgnorableColumns::ColumnIgnore.new(Date.parse('2019-01-01'), '12.0'), 'unused' => IgnorableColumns::ColumnIgnore.new(Date.parse('2019-01-01'), '12.0'),
......
...@@ -35,9 +35,6 @@ describe Gitlab::Database::WithLockRetries do ...@@ -35,9 +35,6 @@ describe Gitlab::Database::WithLockRetries do
end end
context 'when lock retry is enabled' do context 'when lock retry is enabled' do
class ActiveRecordSecond < ActiveRecord::Base
end
let(:lock_fiber) do let(:lock_fiber) do
Fiber.new do Fiber.new do
# Initiating a second DB connection for the lock # Initiating a second DB connection for the lock
...@@ -52,6 +49,8 @@ describe Gitlab::Database::WithLockRetries do ...@@ -52,6 +49,8 @@ describe Gitlab::Database::WithLockRetries do
end end
before do before do
stub_const('ActiveRecordSecond', Class.new(ActiveRecord::Base))
lock_fiber.resume # start the transaction and lock the table lock_fiber.resume # start the transaction and lock the table
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