From f7d44fd131ae5639f9473f25cdb1a40ef17df8ef Mon Sep 17 00:00:00 2001 From: Tiger <twatson@gitlab.com> Date: Mon, 31 Aug 2020 07:51:26 +1000 Subject: [PATCH] Clarify wide/small table rubocop definitions --- rubocop/cop/migration/safer_boolean_column.rb | 2 +- rubocop/migration_helpers.rb | 7 +++---- spec/rubocop/cop/migration/safer_boolean_column_spec.rb | 8 ++++---- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/rubocop/cop/migration/safer_boolean_column.rb b/rubocop/cop/migration/safer_boolean_column.rb index 25aaf42d00ede6..22d5d37a83dcb8 100644 --- a/rubocop/cop/migration/safer_boolean_column.rb +++ b/rubocop/cop/migration/safer_boolean_column.rb @@ -37,7 +37,7 @@ def on_send(node) table, _, type = matched.to_a.take(3).map(&:children).map(&:first) opts = matched[3] - return unless WHITELISTED_TABLES.include?(table) && type == :boolean + return unless SMALL_TABLES.include?(table) && type == :boolean no_default = no_default?(opts) nulls_allowed = nulls_allowed?(opts) diff --git a/rubocop/migration_helpers.rb b/rubocop/migration_helpers.rb index 355450bbf57d0e..7c0ab441c282a8 100644 --- a/rubocop/migration_helpers.rb +++ b/rubocop/migration_helpers.rb @@ -1,14 +1,13 @@ module RuboCop # Module containing helper methods for writing migration cops. module MigrationHelpers - WHITELISTED_TABLES = %i[ + # Tables with permanently small number of records + SMALL_TABLES = %i[ application_settings plan_limits ].freeze - # Blacklisted tables due to: - # - number of columns (> 50 on GitLab.com as of 03/2020) - # - number of records + # Tables with large number of columns (> 50 on GitLab.com as of 03/2020) WIDE_TABLES = %i[ users projects diff --git a/spec/rubocop/cop/migration/safer_boolean_column_spec.rb b/spec/rubocop/cop/migration/safer_boolean_column_spec.rb index 013f2edc5e9dfa..72b817fde12816 100644 --- a/spec/rubocop/cop/migration/safer_boolean_column_spec.rb +++ b/spec/rubocop/cop/migration/safer_boolean_column_spec.rb @@ -14,7 +14,7 @@ allow(cop).to receive(:in_migration?).and_return(true) end - described_class::WHITELISTED_TABLES.each do |table| + described_class::SMALL_TABLES.each do |table| context "for the #{table} table" do sources_and_offense = [ ["add_column :#{table}, :column, :boolean, default: true", 'should disallow nulls'], @@ -59,14 +59,14 @@ end end - it 'registers no offense for tables not listed in WHITELISTED_TABLES' do + it 'registers no offense for tables not listed in SMALL_TABLES' do inspect_source("add_column :large_table, :column, :boolean") expect(cop.offenses).to be_empty end it 'registers no offense for non-boolean columns' do - table = described_class::WHITELISTED_TABLES.sample + table = described_class::SMALL_TABLES.sample inspect_source("add_column :#{table}, :column, :string") expect(cop.offenses).to be_empty @@ -75,7 +75,7 @@ context 'outside of migration' do it 'registers no offense' do - table = described_class::WHITELISTED_TABLES.sample + table = described_class::SMALL_TABLES.sample inspect_source("add_column :#{table}, :column, :boolean") expect(cop.offenses).to be_empty -- GitLab