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
dd85269a
Commit
dd85269a
authored
Jul 16, 2019
by
Ash McKenzie
Committed by
Alex Buijs
Aug 15, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow UsageData.count to use count_by:
parent
ad3ee493
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
2 deletions
+8
-2
lib/gitlab/usage_data.rb
lib/gitlab/usage_data.rb
+2
-2
spec/lib/gitlab/usage_data_spec.rb
spec/lib/gitlab/usage_data_spec.rb
+6
-0
No files found.
lib/gitlab/usage_data.rb
View file @
dd85269a
...
...
@@ -190,8 +190,8 @@ module Gitlab
{}
# augmented in EE
end
def
count
(
relation
,
fallback:
-
1
)
relation
.
count
def
count
(
relation
,
count_by:
nil
,
fallback:
-
1
)
count_by
?
relation
.
count
(
count_by
)
:
relation
.
count
rescue
ActiveRecord
::
StatementInvalid
fallback
end
...
...
spec/lib/gitlab/usage_data_spec.rb
View file @
dd85269a
...
...
@@ -271,6 +271,12 @@ describe Gitlab::UsageData do
expect
(
described_class
.
count
(
relation
)).
to
eq
(
1
)
end
it
'returns the count for count_by when provided'
do
allow
(
relation
).
to
receive
(
:count
).
with
(
:creator_id
).
and_return
(
2
)
expect
(
described_class
.
count
(
relation
,
count_by: :creator_id
)).
to
eq
(
2
)
end
it
'returns the fallback value when counting fails'
do
allow
(
relation
).
to
receive
(
:count
).
and_raise
(
ActiveRecord
::
StatementInvalid
.
new
(
''
))
...
...
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