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
c2745ad6
Commit
c2745ad6
authored
Oct 02, 2020
by
Peter Leitzen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
RuboCop: Allow `add_foreign_key` within `with_lock_retries`
parent
1343456a
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
4 deletions
+26
-4
rubocop/cop/migration/add_concurrent_foreign_key.rb
rubocop/cop/migration/add_concurrent_foreign_key.rb
+16
-4
spec/rubocop/cop/migration/add_concurrent_foreign_key_spec.rb
.../rubocop/cop/migration/add_concurrent_foreign_key_spec.rb
+10
-0
No files found.
rubocop/cop/migration/add_concurrent_foreign_key.rb
View file @
c2745ad6
...
...
@@ -14,15 +14,21 @@ module RuboCop
(false)
PATTERN
def_node_matcher
:with_lock_retries?
,
<<~
PATTERN
(:send nil? :with_lock_retries)
PATTERN
def
on_send
(
node
)
return
unless
in_migration?
(
node
)
name
=
node
.
children
[
1
]
if
name
==
:add_foreign_key
&&
!
not_valid_fk?
(
node
)
return
unless
name
==
:add_foreign_key
return
if
in_with_lock_retries?
(
node
)
return
if
not_valid_fk?
(
node
)
add_offense
(
node
,
location: :selector
)
end
end
def
method_name
(
node
)
node
.
children
.
first
...
...
@@ -33,6 +39,12 @@ module RuboCop
pair
.
children
[
0
].
children
[
0
]
==
:validate
&&
false_node?
(
pair
.
children
[
1
])
end
end
def
in_with_lock_retries?
(
node
)
node
.
each_ancestor
(
:block
).
any?
do
|
parent
|
with_lock_retries?
(
parent
.
to_a
.
first
)
end
end
end
end
end
...
...
spec/rubocop/cop/migration/add_concurrent_foreign_key_spec.rb
View file @
c2745ad6
...
...
@@ -36,5 +36,15 @@ RSpec.describe RuboCop::Cop::Migration::AddConcurrentForeignKey, type: :rubocop
expect
(
cop
.
offenses
).
to
be_empty
end
it
'does not register an offense when `add_foreign_key` is within `with_lock_retries`'
do
inspect_source
<<~
RUBY
with_lock_retries do
add_foreign_key :key, :projects, column: :project_id, on_delete: :cascade
end
RUBY
expect
(
cop
.
offenses
).
to
be_empty
end
end
end
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