Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
f7d44fd1
Commit
f7d44fd1
authored
Aug 31, 2020
by
Tiger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clarify wide/small table rubocop definitions
parent
4e12f87c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
8 additions
and
9 deletions
+8
-9
rubocop/cop/migration/safer_boolean_column.rb
rubocop/cop/migration/safer_boolean_column.rb
+1
-1
rubocop/migration_helpers.rb
rubocop/migration_helpers.rb
+3
-4
spec/rubocop/cop/migration/safer_boolean_column_spec.rb
spec/rubocop/cop/migration/safer_boolean_column_spec.rb
+4
-4
No files found.
rubocop/cop/migration/safer_boolean_column.rb
View file @
f7d44fd1
...
...
@@ -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
)
...
...
rubocop/migration_helpers.rb
View file @
f7d44fd1
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
...
...
spec/rubocop/cop/migration/safer_boolean_column_spec.rb
View file @
f7d44fd1
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment