Commit d0754e4d authored by Stan Hu's avatar Stan Hu

Fix date-dependent test failure in obsolete_ignored_columns_spec.rb

If `spec/lib/gitlab/database/obsolete_ignored_columns_spec.rb` is loaded
before a date boundary and execute after the boundary has crossed, the
test will fail with an extra column because `Date.today` has advanced.
To fix this problem, we fix the dates used in the test.
parent a99ffb52
......@@ -4,6 +4,9 @@ require 'spec_helper'
describe Gitlab::Database::ObsoleteIgnoredColumns do
module Testing
# Used a fixed date to prevent tests failing across date boundaries
REMOVE_DATE = Date.new(2019, 12, 16)
class MyBase < ApplicationRecord
end
......@@ -23,12 +26,12 @@ describe Gitlab::Database::ObsoleteIgnoredColumns do
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: Date.today.to_s, remove_with: '12.1'
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: Date.today.to_s, 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
......@@ -40,6 +43,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
expect(subject.execute).to eq([
['Testing::A', {
'unused' => IgnorableColumns::ColumnIgnore.new(Date.parse('2019-01-01'), '12.0'),
......@@ -51,4 +55,5 @@ describe Gitlab::Database::ObsoleteIgnoredColumns do
])
end
end
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