Commit 19f942a9 authored by Rajendra Kadam's avatar Rajendra Kadam Committed by Peter Leitzen

Fix leaky constant in migration helpers and ignored cols spec

parent 11271ac4
......@@ -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,14 +3,22 @@
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
Testing.module_eval do
Testing::MyBase.class_eval do
end
class SomeAbstract < MyBase
SomeAbstract.class_eval do
include IgnorableColumns
self.abstract_class = true
......@@ -20,7 +28,7 @@ describe Gitlab::Database::ObsoleteIgnoredColumns do
ignore_column :unused, remove_after: '2019-01-01', remove_with: '12.0'
end
class B < MyBase
Testing::B.class_eval do
include IgnorableColumns
self.table_name = 'issues'
......@@ -29,21 +37,22 @@ describe Gitlab::Database::ObsoleteIgnoredColumns do
ignore_column :not_used_but_still_ignored, remove_after: REMOVE_DATE.to_s, remove_with: '12.1'
end
class A < SomeAbstract
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
Testing::C.class_eval do
self.table_name = 'users'
end
end
end
subject { described_class.new(Testing::MyBase) }
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