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
067a5422
Commit
067a5422
authored
Mar 05, 2020
by
Pavel Shutsin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor analytics metric refresh specs
Introduce new shared example block to DRY specs code
parent
da12adf9
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
74 additions
and
117 deletions
+74
-117
ee/spec/lib/analytics/refresh_approvals_data_spec.rb
ee/spec/lib/analytics/refresh_approvals_data_spec.rb
+3
-48
ee/spec/lib/analytics/refresh_comments_data_spec.rb
ee/spec/lib/analytics/refresh_comments_data_spec.rb
+23
-69
ee/spec/support/shared_examples/lib/analytics/common_merge_request_metrics_refresh_shared_examples.rb
...s/common_merge_request_metrics_refresh_shared_examples.rb
+48
-0
No files found.
ee/spec/lib/analytics/refresh_approvals_data_spec.rb
View file @
067a5422
...
@@ -5,56 +5,11 @@ require 'spec_helper'
...
@@ -5,56 +5,11 @@ require 'spec_helper'
describe
Analytics
::
RefreshApprovalsData
do
describe
Analytics
::
RefreshApprovalsData
do
subject
{
described_class
.
new
(
merge_request
)
}
subject
{
described_class
.
new
(
merge_request
)
}
let!
(
:approval
)
{
create
(
:approval
)
}
let
(
:merge_request
)
{
create
:merge_request
}
let
(
:merge_request
)
{
approval
.
merge_request
}
describe
'#execute'
do
describe
'#execute'
do
it
'updates mr first_approved_at metric'
do
let
(
:calculated_value
)
{
2
.
days
.
ago
.
beginning_of_day
}
expect
do
subject
.
execute
merge_request
.
metrics
.
reload
end
.
to
change
{
merge_request
.
metrics
.
first_approved_at
}.
from
(
nil
).
to
(
be_like_time
(
approval
.
created_at
))
end
context
'when first_approved_at is already present'
do
include_examples
'common merge request metric refresh for'
,
:first_approved_at
before
do
merge_request
.
metrics
.
update
(
first_approved_at:
3
.
days
.
ago
.
beginning_of_day
)
end
it
'does not change mr first_approved_at metric'
do
expect
do
subject
.
execute
merge_request
.
metrics
.
reload
end
.
not_to
change
{
merge_request
.
metrics
.
first_approved_at
}
end
it
'updates mr first_approved_at metric if forced'
do
expect
do
subject
.
execute
(
force:
true
)
merge_request
.
metrics
.
reload
end
.
to
change
{
merge_request
.
metrics
.
first_approved_at
}.
to
(
be_like_time
(
approval
.
created_at
))
end
end
context
'when no merge request metric is present'
do
before
do
merge_request
.
metrics
.
destroy
merge_request
.
reload
end
it
'creates one'
do
expect
{
subject
.
execute
}
.
to
change
{
merge_request
.
metrics
&
.
first_approved_at
}.
from
(
nil
).
to
(
be_like_time
(
approval
.
created_at
))
end
end
end
describe
'#execute_async'
do
it
'schedules async execution'
do
expect
(
Analytics
::
CodeReviewMetricsWorker
)
.
to
receive
(
:perform_async
).
with
(
described_class
.
name
,
merge_request
.
id
,
force:
true
)
subject
.
execute_async
(
force:
true
)
end
end
end
end
end
ee/spec/lib/analytics/refresh_comments_data_spec.rb
View file @
067a5422
...
@@ -3,63 +3,28 @@
...
@@ -3,63 +3,28 @@
require
'spec_helper'
require
'spec_helper'
describe
Analytics
::
RefreshCommentsData
do
describe
Analytics
::
RefreshCommentsData
do
subject
{
described_class
.
for_note
(
note
)
}
describe
'.for_note'
do
describe
'.for_note'
do
subject
{
described_class
.
for_note
(
note
)
}
context
'for non-commit, non-mr note'
do
context
'for non-commit, non-mr note'
do
let
(
:note
)
{
create
(
:note
,
:on_issue
)
}
let
(
:note
)
{
create
(
:note
,
:on_issue
)
}
it
{
is_expected
.
to
be_nil
}
it
{
is_expected
.
to
be_nil
}
end
end
end
describe
'#execute'
do
context
'for MR note'
do
context
'when note is for a merge request'
do
let
(
:note
)
{
create
(
:note
,
:on_merge_request
)
}
let
(
:noteable
)
{
create
(
:merge_request
)
}
let
(
:note
)
{
create
(
:note
,
:on_merge_request
,
noteable:
noteable
,
project:
noteable
.
project
,
author:
create
(
:user
))
}
it
'updates mr first_comment_at metric'
do
expect
do
subject
.
execute
noteable
.
metrics
.
reload
end
.
to
change
{
noteable
.
metrics
.
first_comment_at
}.
from
(
nil
).
to
(
be_like_time
(
note
.
created_at
))
end
context
'when no merge request metric is present'
do
before
do
noteable
.
metrics
.
destroy
noteable
.
reload
end
it
'creates a new metric and updates the first_comment_at
'
do
it
'returns refresh comments instance for note MR
'
do
subject
.
execute
expected_mock
=
instance_double
(
described_class
)
expect
(
noteable
.
metrics
.
reload
.
first_comment_at
).
to
(
be_like_time
(
note
.
created_at
))
allow
(
described_class
).
to
receive
(
:new
).
with
(
note
.
noteable
).
and_return
(
expected_mock
)
end
end
context
'and first_comment_at is already filled'
do
expect
(
subject
).
to
eq
expected_mock
before
do
noteable
.
metrics
.
update
(
first_comment_at:
3
.
days
.
ago
.
beginning_of_day
)
end
it
'does not change mr first_comment_at metric'
do
expect
do
subject
.
execute
noteable
.
metrics
.
reload
end
.
not_to
change
{
noteable
.
metrics
.
first_comment_at
}
end
it
'updates mr first_comment_at metric if forced'
do
expect
do
subject
.
execute
(
force:
true
)
noteable
.
metrics
.
reload
end
.
to
change
{
noteable
.
metrics
.
first_comment_at
}.
to
(
be_like_time
(
note
.
created_at
))
end
end
end
end
end
context
'
when noteable is a commit
'
do
context
'
for commit note
'
do
let
(
:note
)
{
create
(
:diff_note_on_commit
,
author:
create
(
:user
))
}
let
(
:note
)
{
create
(
:diff_note_on_commit
,
author:
create
(
:user
))
}
let!
(
:merge_request
)
{
create
:merge_request
,
source_project:
note
.
project
}
let!
(
:merge_request
)
{
create
:merge_request
,
source_project:
note
.
project
}
...
@@ -67,33 +32,22 @@ describe Analytics::RefreshCommentsData do
...
@@ -67,33 +32,22 @@ describe Analytics::RefreshCommentsData do
allow
(
note
.
noteable
).
to
receive
(
:merge_requests
).
and_return
(
note
.
project
.
merge_requests
)
allow
(
note
.
noteable
).
to
receive
(
:merge_requests
).
and_return
(
note
.
project
.
merge_requests
)
end
end
it
'updates mr first_comment_at metric'
do
it
'returns refresh comments instance for commit MR'
do
expect
do
expected_mock
=
instance_double
(
described_class
)
subject
.
execute
merge_request
.
metrics
.
reload
allow
(
described_class
).
to
receive
(
:new
).
with
(
merge_request
).
and_return
(
expected_mock
)
end
.
to
change
{
merge_request
.
metrics
.
first_comment_at
}.
from
(
nil
).
to
(
be_like_time
(
note
.
created_at
))
end
context
'and first_comment_at is already filled'
do
expect
(
subject
).
to
eq
expected_mock
let!
(
:merge_request
)
do
create
:merge_request
,
:with_productivity_metrics
,
source_project:
note
.
project
,
metrics_data:
{
first_comment_at:
3
.
days
.
ago
.
beginning_of_day
}
end
it
'does not change mr first_comment_at metric'
do
expect
do
subject
.
execute
merge_request
.
metrics
.
reload
end
.
not_to
change
{
merge_request
.
metrics
.
first_comment_at
}
end
it
'updates mr first_comment_at metric if forced'
do
expect
do
subject
.
execute
(
force:
true
)
merge_request
.
metrics
.
reload
end
.
to
change
{
merge_request
.
metrics
.
first_comment_at
}.
to
(
be_like_time
(
note
.
created_at
))
end
end
end
end
end
end
end
describe
'#execute'
do
subject
{
described_class
.
new
(
merge_request
)
}
let
(
:merge_request
)
{
create
:merge_request
}
let
(
:calculated_value
)
{
2
.
days
.
ago
.
beginning_of_day
}
include_examples
'common merge request metric refresh for'
,
:first_comment_at
end
end
end
ee/spec/support/shared_examples/lib/analytics/common_merge_request_metrics_refresh_shared_examples.rb
0 → 100644
View file @
067a5422
# frozen_string_literal: true
RSpec
.
shared_examples
'common merge request metric refresh for'
do
|
metric_name
|
before
do
allow_next_instance_of
(
Analytics
::
MergeRequestMetricsCalculator
,
merge_request
)
do
|
instance
|
allow
(
instance
).
to
receive
(
metric_name
).
and_return
(
calculated_value
)
end
end
it
"updates
#{
metric_name
}
"
do
expect
do
subject
.
execute
merge_request
.
metrics
.
reload
end
.
to
change
{
merge_request
.
metrics
[
metric_name
]
}.
from
(
nil
).
to
(
calculated_value
)
end
context
"when
#{
metric_name
}
is already present"
do
before
do
merge_request
.
metrics
.
update
(
metric_name
=>
calculated_value
-
10
)
end
it
"does not change
#{
metric_name
}
"
do
expect
do
subject
.
execute
merge_request
.
metrics
.
reload
end
.
not_to
change
{
merge_request
.
metrics
[
metric_name
]
}
end
it
"updates
#{
metric_name
}
if forced"
do
expect
do
subject
.
execute
(
force:
true
)
merge_request
.
metrics
.
reload
end
.
to
change
{
merge_request
.
metrics
[
metric_name
]
}.
to
(
calculated_value
)
end
end
context
'when no merge request metric is present'
do
before
do
merge_request
.
metrics
.
destroy
merge_request
.
reload
end
it
'creates one'
do
expect
{
subject
.
execute
}
.
to
change
{
merge_request
.
metrics
&&
merge_request
.
metrics
[
metric_name
]
}.
from
(
nil
).
to
(
calculated_value
)
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