Commit f7d44fd1 authored by Tiger's avatar Tiger

Clarify wide/small table rubocop definitions

parent 4e12f87c
......@@ -37,7 +37,7 @@ module RuboCop
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)
......
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
......
......@@ -14,7 +14,7 @@ RSpec.describe RuboCop::Cop::Migration::SaferBooleanColumn, type: :rubocop do
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 @@ RSpec.describe RuboCop::Cop::Migration::SaferBooleanColumn, type: :rubocop do
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 @@ RSpec.describe RuboCop::Cop::Migration::SaferBooleanColumn, type: :rubocop do
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
......
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