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
14ecaff4
Commit
14ecaff4
authored
Nov 01, 2019
by
Pavel Shutsin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Restyle productivity analytics spec
parent
7cf73994
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
69 deletions
+26
-69
ee/app/models/productivity_analytics.rb
ee/app/models/productivity_analytics.rb
+1
-1
ee/spec/models/productivity_analytics_spec.rb
ee/spec/models/productivity_analytics_spec.rb
+25
-68
No files found.
ee/app/models/productivity_analytics.rb
View file @
14ecaff4
...
...
@@ -73,6 +73,6 @@ class ProductivityAnalytics
end
def
default_sorting
{
id: :desc
}
{
id: :desc
}
end
end
ee/spec/models/productivity_analytics_spec.rb
View file @
14ecaff4
...
...
@@ -4,7 +4,7 @@ require 'spec_helper'
describe
ProductivityAnalytics
do
describe
'metrics data'
do
subjec
t
(
:analytics
)
{
described_class
.
new
(
merge_requests:
finder_mrs
,
sort:
custom_sort
)
}
le
t
(
:analytics
)
{
described_class
.
new
(
merge_requests:
finder_mrs
,
sort:
custom_sort
)
}
let
(
:finder_mrs
)
{
ProductivityAnalyticsFinder
.
new
(
create
(
:admin
),
finder_options
).
execute
}
let
(
:finder_options
)
{
{
state:
'merged'
}
}
...
...
@@ -127,86 +127,43 @@ describe ProductivityAnalytics do
end
describe
'#histogram_data'
do
subject
{
analytics
.
histogram_data
(
type:
metric
)
}
context
'days_to_merge metric'
do
let
(
:metric
)
{
'days_to_merge'
}
it
'returns aggregated data per days to merge from MR creation date'
do
expect
(
subject
).
to
eq
(
3
=>
2
,
14
=>
1
,
30
=>
1
)
end
end
context
'time_to_first_comment metric'
do
let
(
:metric
)
{
'time_to_first_comment'
}
it
'returns aggregated data per hours from MR creation to first comment'
do
expect
(
subject
).
to
eq
(
0
=>
3
,
24
=>
1
)
end
end
context
'time_to_last_commit metric'
do
let
(
:metric
)
{
'time_to_last_commit'
}
it
'returns aggregated data per hours from first comment to last commit'
do
expect
(
subject
).
to
eq
(
13
*
24
=>
1
,
29
*
24
=>
1
,
2
*
24
=>
2
)
end
end
context
'time_to_merge metric'
do
let
(
:metric
)
{
'time_to_merge'
}
it
'returns aggregated data per hours from last commit to merge'
do
expect
(
subject
).
to
eq
(
24
=>
3
,
0
=>
1
)
end
end
context
'commits_count metric'
do
let
(
:metric
)
{
'commits_count'
}
it
'returns aggregated data per number of commits'
do
expect
(
subject
).
to
eq
(
1
=>
2
,
5
=>
1
,
20
=>
1
)
end
end
context
'loc_per_commit metric'
do
let
(
:metric
)
{
'loc_per_commit'
}
it
'returns aggregated data per number of LoC/commits_count'
do
expect
(
subject
).
to
eq
(
15
=>
1
,
16
=>
1
,
14
=>
1
,
5
=>
1
)
end
subject
(
:histogram_data
)
{
analytics
.
histogram_data
(
type:
metric
)
}
using
RSpec
::
Parameterized
::
TableSyntax
where
(
:metric
,
:expected_result
)
do
'days_to_merge'
|
{
3
=>
2
,
14
=>
1
,
30
=>
1
}
'time_to_first_comment'
|
{
0
=>
3
,
24
=>
1
}
'time_to_last_commit'
|
{
13
*
24
=>
1
,
29
*
24
=>
1
,
2
*
24
=>
2
}
'time_to_merge'
|
{
24
=>
3
,
0
=>
1
}
'commits_count'
|
{
1
=>
2
,
5
=>
1
,
20
=>
1
}
'loc_per_commit'
|
{
15
=>
1
,
16
=>
1
,
14
=>
1
,
5
=>
1
}
'files_touched'
|
{
15
=>
1
,
3
=>
2
,
1
=>
1
}
'something_invalid'
|
nil
end
context
'files_touched metric'
do
let
(
:metric
)
{
'files_touched'
}
it
'returns aggregated data per number of modified files'
do
expect
(
subject
).
to
eq
(
15
=>
1
,
3
=>
2
,
1
=>
1
)
with_them
do
it
'calculates correctly'
do
expect
(
analytics
.
histogram_data
(
type:
metric
)).
to
eq
(
expected_result
)
end
end
context
'for invalid metric'
do
let
(
:metric
)
{
'something_invalid'
}
it
{
is_expected
.
to
eq
nil
}
end
context
'for multiple labeled mrs'
do
let
(
:finder_options
)
{
super
().
merge
(
label_name:
[
label_a
.
title
,
label_b
.
title
])
}
let
(
:metric
)
{
'days_to_merge'
}
it
'returns aggregated data'
do
expect
(
subject
).
to
eq
(
3
=>
2
,
30
=>
1
)
expect
(
analytics
.
histogram_data
(
type:
'days_to_merge'
)
).
to
eq
(
3
=>
2
,
30
=>
1
)
end
end
end
# Test coverage depends on #histogram_data tests. We want to avoid duplication here, so test only for 1 metric.
describe
'#scatterplot_data'
do
subject
{
analytics
.
scatterplot_data
(
type:
'days_to_merge'
)
}
subject
(
:scatterplot_data
)
{
analytics
.
scatterplot_data
(
type:
'days_to_merge'
)
}
it
'returns metric values for each MR'
do
expect
(
s
ubject
).
to
match
(
expect
(
s
catterplot_data
).
to
match
(
short_mr
.
id
=>
{
metric:
3
,
merged_at:
be_like_time
(
short_mr
.
merged_at
)
},
short_mr_2
.
id
=>
{
metric:
3
,
merged_at:
be_like_time
(
short_mr_2
.
merged_at
)
},
medium_mr
.
id
=>
{
metric:
14
,
merged_at:
be_like_time
(
medium_mr
.
merged_at
)
},
...
...
@@ -216,7 +173,7 @@ describe ProductivityAnalytics do
end
describe
'#merge_requests_extended'
do
subject
{
analytics
.
merge_requests_extended
}
subject
(
:merge_requests
)
{
analytics
.
merge_requests_extended
}
it
'returns MRs data with all the metrics calculated'
do
expected_data
=
{
...
...
@@ -227,7 +184,7 @@ describe ProductivityAnalytics do
}
expected_data
.
each
do
|
mr_id
,
expected_attributes
|
expect
(
subject
.
detect
{
|
mr
|
mr
.
id
==
mr_id
}.
attributes
).
to
include
(
expected_attributes
)
expect
(
merge_requests
.
detect
{
|
mr
|
mr
.
id
==
mr_id
}.
attributes
).
to
include
(
expected_attributes
)
end
end
...
...
@@ -235,14 +192,14 @@ describe ProductivityAnalytics do
let
(
:custom_sort
)
{
'loc_per_commit_asc'
}
it
'reorders MRs according to custom sorting'
do
expect
(
subject
).
to
eq
[
short_mr_2
,
short_mr
,
long_mr
,
medium_mr
]
expect
(
merge_requests
).
to
eq
[
short_mr_2
,
short_mr
,
long_mr
,
medium_mr
]
end
context
'with unknown sorting'
do
let
(
:custom_sort
)
{
'weird_stuff'
}
it
'sorts by id desc'
do
expect
(
subject
).
to
eq
[
short_mr_2
,
short_mr
,
medium_mr
,
long_mr
]
expect
(
merge_requests
).
to
eq
[
short_mr_2
,
short_mr
,
medium_mr
,
long_mr
]
end
end
end
...
...
@@ -258,7 +215,7 @@ describe ProductivityAnalytics do
}
expected_data
.
each
do
|
mr_id
,
expected_attributes
|
expect
(
subject
.
detect
{
|
mr
|
mr
.
id
==
mr_id
}.
attributes
).
to
include
(
expected_attributes
)
expect
(
merge_requests
.
detect
{
|
mr
|
mr
.
id
==
mr_id
}.
attributes
).
to
include
(
expected_attributes
)
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