diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-01 06:06:11 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-01 06:06:11 +0000 |
commit | 864475536355651a9f7caa5b1606aa5640424ec3 (patch) | |
tree | 1dc80c96ddf3f9049c4a163b4c49f052a9b1a4ad /spec | |
parent | 7ddd5846999029916b2b6d8560b5b0f02ec0f6ea (diff) | |
download | gitlab-ce-864475536355651a9f7caa5b1606aa5640424ec3.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/lib/gitlab/database/obsolete_ignored_columns_spec.rb | 21 | ||||
-rw-r--r-- | spec/models/concerns/ignorable_columns_spec.rb | 88 | ||||
-rw-r--r-- | spec/rubocop/cop/ignored_columns_spec.rb | 22 |
3 files changed, 126 insertions, 5 deletions
diff --git a/spec/lib/gitlab/database/obsolete_ignored_columns_spec.rb b/spec/lib/gitlab/database/obsolete_ignored_columns_spec.rb index 6d38f7f1b95..b3826666b18 100644 --- a/spec/lib/gitlab/database/obsolete_ignored_columns_spec.rb +++ b/spec/lib/gitlab/database/obsolete_ignored_columns_spec.rb @@ -8,21 +8,27 @@ describe Gitlab::Database::ObsoleteIgnoredColumns do end class SomeAbstract < MyBase + include IgnorableColumns + self.abstract_class = true self.table_name = 'projects' - self.ignored_columns += %i[unused] + ignore_column :unused, remove_after: '2019-01-01', remove_with: '12.0' end class B < MyBase + include IgnorableColumns + self.table_name = 'issues' - self.ignored_columns += %i[id other] + 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' end class A < SomeAbstract - self.ignored_columns += %i[id also_unused] + 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' end class C < MyBase @@ -35,8 +41,13 @@ describe Gitlab::Database::ObsoleteIgnoredColumns do describe '#execute' do it 'returns a list of class names and columns pairs' do expect(subject.execute).to eq([ - ['Testing::A', %w(unused also_unused)], - ['Testing::B', %w(other)] + ['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 diff --git a/spec/models/concerns/ignorable_columns_spec.rb b/spec/models/concerns/ignorable_columns_spec.rb new file mode 100644 index 00000000000..55efa1b5fda --- /dev/null +++ b/spec/models/concerns/ignorable_columns_spec.rb @@ -0,0 +1,88 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe IgnorableColumns do + let(:record_class) do + Class.new(ApplicationRecord) do + include IgnorableColumns + end + end + + subject { record_class } + + it 'adds columns to ignored_columns' do + expect do + subject.ignore_columns(:name, :created_at, remove_after: '2019-12-01', remove_with: '12.6') + end.to change { subject.ignored_columns }.from([]).to(%w(name created_at)) + end + + it 'adds columns to ignored_columns (array version)' do + expect do + subject.ignore_columns(%i[name created_at], remove_after: '2019-12-01', remove_with: '12.6') + end.to change { subject.ignored_columns }.from([]).to(%w(name created_at)) + end + + it 'requires remove_after attribute to be set' do + expect { subject.ignore_columns(:name, remove_after: nil, remove_with: 12.6) }.to raise_error(ArgumentError, /Please indicate/) + end + + it 'requires remove_after attribute to be set' do + expect { subject.ignore_columns(:name, remove_after: "not a date", remove_with: 12.6) }.to raise_error(ArgumentError, /Please indicate/) + end + + it 'requires remove_with attribute to be set' do + expect { subject.ignore_columns(:name, remove_after: '2019-12-01', remove_with: nil) }.to raise_error(ArgumentError, /Please indicate/) + end + + describe '.ignored_columns_details' do + shared_examples_for 'storing removal information' do + it 'storing removal information' do + subject.ignore_column(columns, remove_after: '2019-12-01', remove_with: '12.6') + + [columns].flatten.each do |column| + expect(subject.ignored_columns_details[column].remove_after).to eq(Date.parse('2019-12-01')) + expect(subject.ignored_columns_details[column].remove_with).to eq('12.6') + end + end + end + + context 'with single column' do + let(:columns) { :name } + it_behaves_like 'storing removal information' + end + + context 'with array column' do + let(:columns) { %i[name created_at] } + it_behaves_like 'storing removal information' + end + + it 'defaults to empty Hash' do + expect(subject.ignored_columns_details).to eq({}) + end + end + + describe IgnorableColumns::ColumnIgnore do + subject { described_class.new(remove_after, remove_with) } + + let(:remove_with) { double } + + describe '#safe_to_remove?' do + context 'after remove_after date has passed' do + let(:remove_after) { Date.parse('2019-01-10') } + + it 'returns true (safe to remove)' do + expect(subject.safe_to_remove?).to be_truthy + end + end + + context 'before remove_after date has passed' do + let(:remove_after) { Date.today } + + it 'returns false (not safe to remove)' do + expect(subject.safe_to_remove?).to be_falsey + end + end + end + end +end diff --git a/spec/rubocop/cop/ignored_columns_spec.rb b/spec/rubocop/cop/ignored_columns_spec.rb new file mode 100644 index 00000000000..64437765018 --- /dev/null +++ b/spec/rubocop/cop/ignored_columns_spec.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +require 'spec_helper' +require 'rubocop' +require 'rubocop/rspec/support' +require_relative '../../../rubocop/cop/ignored_columns' + +describe RuboCop::Cop::IgnoredColumns do + include CopHelper + + subject(:cop) { described_class.new } + + it 'flags the use of destroy_all with a local variable receiver' do + inspect_source(<<~RUBY) + class Foo < ApplicationRecord + self.ignored_columns += %i[id] + end + RUBY + + expect(cop.offenses.size).to eq(1) + end +end |