diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-30 15:07:51 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-30 15:07:51 +0000 |
commit | 4e9acbfba3682c552b3de707c535e6257ef41054 (patch) | |
tree | 8b1fd5f89ad3f1be68d8944815b13bb7d498e4a6 /spec/rubocop | |
parent | 506d6dcd7c787ba71a8a53102f3d4fdb6adcfa5e (diff) | |
download | gitlab-ce-4e9acbfba3682c552b3de707c535e6257ef41054.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/rubocop')
-rw-r--r-- | spec/rubocop/cop/migration/add_columns_to_wide_tables_spec.rb | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/spec/rubocop/cop/migration/add_columns_to_wide_tables_spec.rb b/spec/rubocop/cop/migration/add_columns_to_wide_tables_spec.rb new file mode 100644 index 00000000000..f0c64740e63 --- /dev/null +++ b/spec/rubocop/cop/migration/add_columns_to_wide_tables_spec.rb @@ -0,0 +1,92 @@ +# frozen_string_literal: true + +require 'spec_helper' +require 'rubocop' + +require_relative '../../../../rubocop/cop/migration/add_columns_to_wide_tables' + +describe RuboCop::Cop::Migration::AddColumnsToWideTables do + include CopHelper + + let(:cop) { described_class.new } + + context 'outside of a migration' do + it 'does not register any offenses' do + expect_no_offenses(<<~RUBY) + def up + add_column(:users, :another_column, :string) + end + RUBY + end + end + + context 'in a migration' do + before do + allow(cop).to receive(:in_migration?).and_return(true) + end + + context 'with wide tables' do + it 'registers an offense when adding a column to a wide table' do + offense = '`projects` is a wide table with several columns, addig more should be avoided unless absolutely necessary. Consider storing the column in a different table or creating a new one.' + + expect_offense(<<~RUBY) + def up + add_column(:projects, :another_column, :integer) + ^^^^^^^^^^ #{offense} + end + RUBY + end + + it 'registers an offense when adding a column with default to a wide table' do + offense = '`users` is a wide table with several columns, addig more should be avoided unless absolutely necessary. Consider storing the column in a different table or creating a new one.' + + expect_offense(<<~RUBY) + def up + add_column_with_default(:users, :another_column, :boolean, default: false) + ^^^^^^^^^^^^^^^^^^^^^^^ #{offense} + end + RUBY + end + + it 'registers an offense when adding a reference' do + offense = '`ci_builds` is a wide table with several columns, addig more should be avoided unless absolutely necessary. Consider storing the column in a different table or creating a new one.' + + expect_offense(<<~RUBY) + def up + add_reference(:ci_builds, :issue, :boolean, index: true) + ^^^^^^^^^^^^^ #{offense} + end + RUBY + end + + it 'registers an offense when adding timestamps' do + offense = '`projects` is a wide table with several columns, addig more should be avoided unless absolutely necessary. Consider storing the column in a different table or creating a new one.' + + expect_offense(<<~RUBY) + def up + add_timestamps_with_timezone(:projects, null: false) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{offense} + end + RUBY + end + + it 'register no offense when using other method' do + expect_no_offenses(<<~RUBY) + def up + add_concurrent_index(:projects, :new_index) + end + RUBY + end + end + + context 'with a regular table' do + it 'registers no offense for notes' do + expect_no_offenses(<<~RUBY) + def up + add_column(:notes, :another_column, :boolean) + end + RUBY + end + end + end +end |