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' ...@@ -4,6 +4,9 @@ require 'spec_helper'
describe Gitlab::Database::ObsoleteIgnoredColumns do describe Gitlab::Database::ObsoleteIgnoredColumns do
module Testing module Testing
# Used a fixed date to prevent tests failing across date boundaries
REMOVE_DATE = Date.new(2019, 12, 16)
class MyBase < ApplicationRecord class MyBase < ApplicationRecord
end end
...@@ -23,12 +26,12 @@ describe Gitlab::Database::ObsoleteIgnoredColumns do ...@@ -23,12 +26,12 @@ describe Gitlab::Database::ObsoleteIgnoredColumns do
self.table_name = 'issues' self.table_name = 'issues'
ignore_column :id, :other, remove_after: '2019-01-01', remove_with: '12.0' 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 end
class A < SomeAbstract class A < SomeAbstract
ignore_column :also_unused, remove_after: '2019-02-01', remove_with: '12.1' 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 end
class C < MyBase class C < MyBase
...@@ -40,6 +43,7 @@ describe Gitlab::Database::ObsoleteIgnoredColumns do ...@@ -40,6 +43,7 @@ describe Gitlab::Database::ObsoleteIgnoredColumns do
describe '#execute' do describe '#execute' do
it 'returns a list of class names and columns pairs' do it 'returns a list of class names and columns pairs' do
Timecop.freeze(Testing::REMOVE_DATE) do
expect(subject.execute).to eq([ expect(subject.execute).to eq([
['Testing::A', { ['Testing::A', {
'unused' => IgnorableColumns::ColumnIgnore.new(Date.parse('2019-01-01'), '12.0'), 'unused' => IgnorableColumns::ColumnIgnore.new(Date.parse('2019-01-01'), '12.0'),
...@@ -51,4 +55,5 @@ describe Gitlab::Database::ObsoleteIgnoredColumns do ...@@ -51,4 +55,5 @@ describe Gitlab::Database::ObsoleteIgnoredColumns do
]) ])
end end
end 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