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:
- 'spec/db/schema_spec.rb'
- 'spec/lib/feature_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/import_export/import_test_coverage_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 @@
require 'spec_helper'
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
REMOVE_DATE = Date.new(2019, 12, 16)
stub_const('REMOVE_DATE', Date.new(2019, 12, 16))
class MyBase < ApplicationRecord
end
Testing.module_eval do
Testing::MyBase.class_eval do
end
class SomeAbstract < MyBase
include IgnorableColumns
SomeAbstract.class_eval do
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'
end
ignore_column :unused, remove_after: '2019-01-01', remove_with: '12.0'
end
class B < MyBase
include IgnorableColumns
Testing::B.class_eval do
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 :not_used_but_still_ignored, remove_after: REMOVE_DATE.to_s, remove_with: '12.1'
end
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'
end
class A < SomeAbstract
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'
end
Testing::A.class_eval do
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'
end
class C < MyBase
self.table_name = 'users'
Testing::C.class_eval do
self.table_name = 'users'
end
end
end
......@@ -43,7 +52,7 @@ describe Gitlab::Database::ObsoleteIgnoredColumns do
describe '#execute' 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([
['Testing::A', {
'unused' => IgnorableColumns::ColumnIgnore.new(Date.parse('2019-01-01'), '12.0'),
......
......@@ -35,9 +35,6 @@ describe Gitlab::Database::WithLockRetries do
end
context 'when lock retry is enabled' do
class ActiveRecordSecond < ActiveRecord::Base
end
let(:lock_fiber) do
Fiber.new do
# Initiating a second DB connection for the lock
......@@ -52,6 +49,8 @@ describe Gitlab::Database::WithLockRetries do
end
before do
stub_const('ActiveRecordSecond', Class.new(ActiveRecord::Base))
lock_fiber.resume # start the transaction and lock the table
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