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
17d1c421
Commit
17d1c421
authored
May 20, 2021
by
Piotr Skorupa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix cop specs
parent
2537619a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
76 additions
and
29 deletions
+76
-29
rubocop/cop/usage_data/histogram_with_large_table.rb
rubocop/cop/usage_data/histogram_with_large_table.rb
+6
-10
spec/rubocop/cop/usage_data/histogram_with_large_table_spec.rb
...rubocop/cop/usage_data/histogram_with_large_table_spec.rb
+70
-19
No files found.
rubocop/cop/usage_data/histogram_with_large_table.rb
View file @
17d1c421
...
...
@@ -17,19 +17,15 @@ module RuboCop
# Match one level const as Issue, Gitlab
def_node_matcher
:one_level_node
,
<<~
PATTERN
(send nil? :histogram
(send
(const {nil? cbase} $...)
$...)
`(const {nil? cbase} $...)
$...)
PATTERN
# Match two level const as ::Clusters::Cluster, ::Ci::Pipeline
def_node_matcher
:two_level_node
,
<<~
PATTERN
(send nil? :histogram
(send
(const
(const {nil? cbase} $...)
$...)
`(const
(const {nil? cbase} $...)
$...)
$...)
PATTERN
...
...
@@ -40,10 +36,10 @@ module RuboCop
return
unless
Array
(
one_level_matches
).
any?
||
Array
(
two_level_matches
).
any?
if
one_level_matches
class_name
=
one_level_matches
[
0
].
first
else
if
two_level_matches
class_name
=
"
#{
two_level_matches
[
0
].
first
}
::
#{
two_level_matches
[
1
].
first
}
"
.
to_sym
else
class_name
=
one_level_matches
[
0
].
first
end
if
large_table?
(
class_name
)
...
...
spec/rubocop/cop/usage_data/histogram_with_large_table_spec.rb
View file @
17d1c421
...
...
@@ -5,8 +5,8 @@ require 'fast_spec_helper'
require_relative
'../../../../rubocop/cop/usage_data/histogram_with_large_table'
RSpec
.
describe
RuboCop
::
Cop
::
UsageData
::
HistogramWithLargeTable
do
let
(
:high_traffic_models
)
{
%
i
[Issue Ci::Build]
}
let
(
:msg
)
{
'
Use one of the count, distinct_count methods for counting
on'
}
let
(
:high_traffic_models
)
{
%
w
[Issue Ci::Build]
}
let
(
:msg
)
{
'
Avoid histogram method
on'
}
let
(
:config
)
do
RuboCop
::
Config
.
new
(
'UsageData/HistogramWithLargeTable'
=>
{
...
...
@@ -17,28 +17,79 @@ RSpec.describe RuboCop::Cop::UsageData::HistogramWithLargeTable do
subject
(
:cop
)
{
described_class
.
new
(
config
)
}
context
'with large tables'
do
context
'when calling histogram(Issue)'
do
it
'does not register an offense'
do
expect_no_offenses
(
'count(Issue, :project_id, buckets: 1..100)'
)
context
'with one-level constants'
do
context
'when calling histogram(Issue)'
do
it
'registers an offense'
do
expect_offense
(
<<~
CODE
)
histogram(Issue, :project_id, buckets: 1..100)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#{
msg
}
Issue
CODE
end
end
context
'when calling histogram(::Issue)'
do
it
'registers an offense'
do
expect_offense
(
<<~
CODE
)
histogram(::Issue, :project_id, buckets: 1..100)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#{
msg
}
Issue
CODE
end
end
end
context
'when calling histogram(::Ci::Build)'
do
it
'does not register an offense'
do
expect_offense
(
<<~
CODE
)
histogram(::Ci::Build.active, buckets: 1..100)
^^^^^^^^^
#{
msg
}
Ci::Build
CODE
context
'when calling histogram(Issue.closed)'
do
it
'registers an offense'
do
expect_offense
(
<<~
CODE
)
histogram(Issue.closed, :project_id, buckets: 1..100)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#{
msg
}
Issue
CODE
end
end
context
'when calling histogram(::Issue.closed)'
do
it
'registers an offense'
do
expect_offense
(
<<~
CODE
)
histogram(::Issue.closed, :project_id, buckets: 1..100)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#{
msg
}
Issue
CODE
end
end
end
context
'when calling histogram(Ci::Build.active)'
do
it
'does not register an offense'
do
expect_no_offenses
(
'hist(Ci::Build.active, :project_id, buckets: 1..100)'
)
expect_offense
(
<<~
CODE
)
histogram(Ci::Build.active)
^^^^^^^^^
#{
msg
}
Ci::Build
CODE
context
'with two-level constants'
do
context
'when calling histogram(::Ci::Build)'
do
it
'registers an offense'
do
expect_offense
(
<<~
CODE
)
histogram(::Ci::Build, buckets: 1..100)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#{
msg
}
Ci::Build
CODE
end
end
context
'when calling histogram(::Ci::Build.active)'
do
it
'registers an offense'
do
expect_offense
(
<<~
CODE
)
histogram(::Ci::Build.active, buckets: 1..100)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#{
msg
}
Ci::Build
CODE
end
end
context
'when calling histogram(Ci::Build)'
do
it
'registers an offense'
do
expect_offense
(
<<~
CODE
)
histogram(Ci::Build, buckets: 1..100)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#{
msg
}
Ci::Build
CODE
end
end
context
'when calling histogram(Ci::Build.active)'
do
it
'registers an offense'
do
expect_offense
(
<<~
CODE
)
histogram(Ci::Build.active, buckets: 1..100)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#{
msg
}
Ci::Build
CODE
end
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