2019-12-04 20:38:33 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Gitlab::Database::ObsoleteIgnoredColumns do
|
2020-06-23 00:09:42 +05:30
|
|
|
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))
|
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
# Used a fixed date to prevent tests failing across date boundaries
|
2020-06-23 00:09:42 +05:30
|
|
|
stub_const('REMOVE_DATE', Date.new(2019, 12, 16))
|
2020-01-01 13:55:28 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
Testing.module_eval do
|
|
|
|
Testing::MyBase.class_eval do
|
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
SomeAbstract.class_eval do
|
|
|
|
include IgnorableColumns
|
2020-01-01 13:55:28 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
self.abstract_class = true
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
self.table_name = 'projects'
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
ignore_column :unused, remove_after: '2019-01-01', remove_with: '12.0'
|
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
Testing::B.class_eval do
|
|
|
|
include IgnorableColumns
|
2020-01-01 13:55:28 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
self.table_name = 'issues'
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
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
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
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
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
Testing::C.class_eval do
|
|
|
|
self.table_name = 'users'
|
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
subject { described_class.new(Testing::MyBase) }
|
|
|
|
|
|
|
|
describe '#execute' do
|
|
|
|
it 'returns a list of class names and columns pairs' do
|
2021-01-03 14:25:43 +05:30
|
|
|
travel_to(REMOVE_DATE) do
|
2020-01-01 13:55:28 +05:30
|
|
|
expect(subject.execute).to eq([
|
|
|
|
['Testing::A', {
|
|
|
|
'unused' => IgnorableColumns::ColumnIgnore.new(Date.parse('2019-01-01'), '12.0'),
|
|
|
|
'also_unused' => IgnorableColumns::ColumnIgnore.new(Date.parse('2019-02-01'), '12.1')
|
|
|
|
}],
|
|
|
|
['Testing::B', {
|
|
|
|
'other' => IgnorableColumns::ColumnIgnore.new(Date.parse('2019-01-01'), '12.0')
|
|
|
|
}]
|
|
|
|
])
|
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|