diff --git a/spec/lib/gitlab/database/obsolete_ignored_columns_spec.rb b/spec/lib/gitlab/database/obsolete_ignored_columns_spec.rb index b3826666b18524f78f1178d1e7148995fb1f5d07..0f68201a153b7d68b8363c0101bca7757ade9e45 100644 --- a/spec/lib/gitlab/database/obsolete_ignored_columns_spec.rb +++ b/spec/lib/gitlab/database/obsolete_ignored_columns_spec.rb @@ -4,6 +4,9 @@ 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 @@ class B < MyBase 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,15 +43,17 @@ class C < MyBase describe '#execute' do it 'returns a list of class names and columns pairs' do - 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') - }] - ]) + Timecop.freeze(Testing::REMOVE_DATE) do + 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 end end end