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
dc9b9abe
Commit
dc9b9abe
authored
Apr 08, 2021
by
Rajendra Kadam
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add specs for min/max in utils
parent
17f4f482
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
6 deletions
+25
-6
lib/gitlab/utils/usage_data.rb
lib/gitlab/utils/usage_data.rb
+7
-6
spec/lib/gitlab/utils/usage_data_spec.rb
spec/lib/gitlab/utils/usage_data_spec.rb
+18
-0
No files found.
lib/gitlab/utils/usage_data.rb
View file @
dc9b9abe
...
...
@@ -36,6 +36,7 @@
module
Gitlab
module
Utils
module
UsageData
include
Gitlab
::
Utils
::
StrongMemoize
extend
self
FALLBACK
=
-
1
...
...
@@ -209,17 +210,17 @@ module Gitlab
Gitlab
::
UsageDataCounters
::
HLLRedisCounter
.
track_event
(
event_name
.
to_s
,
values:
values
)
end
def
maximum_id
(
relation
)
key
=
:"
#{
relation
.
name
.
downcase
}
_maximum_id"
def
maximum_id
(
model
)
key
=
:"
#{
model
.
name
.
downcase
}
_maximum_id"
strong_memoize
(
key
)
do
relation
.
maximum
(
:id
)
model
.
maximum
(
:id
)
end
end
def
minimum_id
(
relation
)
key
=
:"
#{
relation
.
name
.
downcase
}
_minimum_id"
def
minimum_id
(
model
)
key
=
:"
#{
model
.
name
.
downcase
}
_minimum_id"
strong_memoize
(
key
)
do
relation
.
minimum
(
:id
)
model
.
minimum
(
:id
)
end
end
...
...
spec/lib/gitlab/utils/usage_data_spec.rb
View file @
dc9b9abe
...
...
@@ -479,4 +479,22 @@ RSpec.describe Gitlab::Utils::UsageData do
expect
{
described_class
.
track_usage_event
(
unknown_event
,
value
)
}.
to
raise_error
(
Gitlab
::
UsageDataCounters
::
HLLRedisCounter
::
UnknownEvent
)
end
end
describe
'min/max'
do
let
(
:model
)
{
double
(
:relation
)
}
it
'returns min from the model'
do
allow
(
model
).
to
receive
(
:minimum
).
and_return
(
2
)
allow
(
model
).
to
receive
(
:name
).
and_return
(
'sample_min_model'
)
expect
(
described_class
.
minimum_id
(
model
)).
to
eq
(
2
)
end
it
'returns max from the model'
do
allow
(
model
).
to
receive
(
:maximum
).
and_return
(
100
)
allow
(
model
).
to
receive
(
:name
).
and_return
(
'sample_max_model'
)
expect
(
described_class
.
maximum_id
(
model
)).
to
eq
(
100
)
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