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
0f748605
Commit
0f748605
authored
Sep 02, 2016
by
Timothy Andrew
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for the `plan` cycle analytics phase.
Clean up the `issue` tests as well
parent
0910868d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
188 additions
and
63 deletions
+188
-63
spec/models/cycle_analytics/issue_spec.rb
spec/models/cycle_analytics/issue_spec.rb
+57
-63
spec/models/cycle_analytics/plan_spec.rb
spec/models/cycle_analytics/plan_spec.rb
+131
-0
No files found.
spec/models/cycle_analytics/issue_spec.rb
View file @
0f748605
...
@@ -5,33 +5,28 @@ describe 'CycleAnalytics#issue', models: true do
...
@@ -5,33 +5,28 @@ describe 'CycleAnalytics#issue', models: true do
let
(
:from_date
)
{
10
.
days
.
ago
}
let
(
:from_date
)
{
10
.
days
.
ago
}
subject
{
CycleAnalytics
.
new
(
project
,
from:
from_date
)
}
subject
{
CycleAnalytics
.
new
(
project
,
from:
from_date
)
}
context
"when calculating the median of times between:
context
"when a milestone is added to the issue"
do
start: issue created_at
it
"calculates the median of available durations (between issue creation and milestone addition)"
do
end: milestone first added to issue
time_differences
=
Array
.
new
(
5
)
do
OR
start_time
=
Time
.
now
list-label first added to issue
end_time
=
rand
(
1
..
10
).
days
.
from_now
"
do
context
"when a milestone is added to the issue"
do
it
"calculates the median of available durations"
do
start_and_end_times
=
Array
.
new
(
5
)
do
start_time
=
Time
.
now
end_time
=
rand
(
1
..
10
).
days
.
from_now
milestone
=
create
(
:milestone
,
project:
project
)
issue
=
Timecop
.
freeze
(
start_time
)
{
create
(
:issue
,
project:
project
)
}
Timecop
.
freeze
(
end_time
)
{
issue
.
update
(
milestone:
milestone
)
}
[
start_time
,
end_time
]
milestone
=
create
(
:milestone
,
project:
project
)
end
issue
=
Timecop
.
freeze
(
start_time
)
{
create
(
:issue
,
project:
project
)
}
Timecop
.
freeze
(
end_time
)
{
issue
.
update
(
milestone:
milestone
)
}
median_start_time
,
median_end_time
=
start_and_end_times
[
2
]
end_time
-
start_time
expect
(
subject
.
issue
).
to
eq
(
median_end_time
-
median_start_time
)
end
end
median_time_difference
=
time_differences
.
sort
[
2
]
expect
(
subject
.
issue
).
to
eq
(
median_time_difference
)
end
end
end
context
"when a label is added to the issue"
do
context
"when a label is added to the issue"
do
it
"calculates the median of available durations when the label is a list-label"
do
context
"when the label is a list-label"
do
start_and_end_times
=
Array
.
new
(
5
)
do
it
"calculates the median of available durations (between issue creation and label addition)"
do
time_differences
=
Array
.
new
(
5
)
do
start_time
=
Time
.
now
start_time
=
Time
.
now
end_time
=
rand
(
1
..
10
).
days
.
from_now
end_time
=
rand
(
1
..
10
).
days
.
from_now
...
@@ -39,61 +34,60 @@ describe 'CycleAnalytics#issue', models: true do
...
@@ -39,61 +34,60 @@ describe 'CycleAnalytics#issue', models: true do
issue
=
Timecop
.
freeze
(
start_time
)
{
create
(
:issue
,
project:
project
)
}
issue
=
Timecop
.
freeze
(
start_time
)
{
create
(
:issue
,
project:
project
)
}
Timecop
.
freeze
(
end_time
)
{
issue
.
update
(
label_ids:
[
list_label
.
id
])
}
Timecop
.
freeze
(
end_time
)
{
issue
.
update
(
label_ids:
[
list_label
.
id
])
}
[
start_time
,
end_time
]
end_time
-
start_time
end
end
median_
start_time
,
median_end_time
=
start_and_end_times
[
2
]
median_
time_difference
=
time_differences
.
sort
[
2
]
expect
(
subject
.
issue
).
to
eq
(
median_
end_time
-
median_start_tim
e
)
expect
(
subject
.
issue
).
to
eq
(
median_
time_differenc
e
)
end
end
end
it
"does not make a calculation for regular labels"
do
it
"does not make a calculation for regular labels"
do
5
.
times
do
5
.
times
do
regular_label
=
create
(
:label
)
regular_label
=
create
(
:label
)
issue
=
create
(
:issue
,
project:
project
)
issue
=
create
(
:issue
,
project:
project
)
issue
.
update
(
label_ids:
[
regular_label
.
id
])
issue
.
update
(
label_ids:
[
regular_label
.
id
])
end
expect
(
subject
.
issue
).
to
be_nil
end
end
expect
(
subject
.
issue
).
to
be_nil
end
end
end
context
"when a milestone and list-label are both added to the issue"
do
context
"when a milestone and list-label are both added to the issue"
do
it
"uses the time the milestone was added as the 'end time'
"
do
it
"calculates the median of available durations (between issue creation and milestone addition)
"
do
start_time
=
Time
.
now
start_time
=
Time
.
now
milestone_add_time
=
rand
(
1
..
10
).
days
.
from_now
milestone_add_time
=
rand
(
1
..
10
).
days
.
from_now
list_label_add_time
=
rand
(
1
..
10
).
days
.
from_now
list_label_add_time
=
rand
(
1
..
10
).
days
.
from_now
milestone
=
create
(
:milestone
,
project:
project
)
milestone
=
create
(
:milestone
,
project:
project
)
list_label
=
create
(
:label
,
lists:
[
create
(
:list
)])
list_label
=
create
(
:label
,
lists:
[
create
(
:list
)])
issue
=
Timecop
.
freeze
(
start_time
)
{
create
(
:issue
,
project:
project
)
}
issue
=
Timecop
.
freeze
(
start_time
)
{
create
(
:issue
,
project:
project
)
}
Timecop
.
freeze
(
milestone_add_time
)
{
issue
.
update
(
milestone:
milestone
)
}
Timecop
.
freeze
(
milestone_add_time
)
{
issue
.
update
(
milestone:
milestone
)
}
Timecop
.
freeze
(
list_label_add_time
)
{
issue
.
update
(
label_ids:
[
list_label
.
id
])
}
Timecop
.
freeze
(
list_label_add_time
)
{
issue
.
update
(
label_ids:
[
list_label
.
id
])
}
expect
(
subject
.
issue
).
to
eq
(
milestone_add_time
-
start_time
)
end
expect
(
subject
.
issue
).
to
eq
(
milestone_add_time
-
start_time
)
end
it
"does not include issues from other projects"
do
it
"does not include issues from other projects"
do
milestone
=
create
(
:milestone
,
project:
project
)
milestone
=
create
(
:milestone
,
project:
project
)
list_label
=
create
(
:label
,
lists:
[
create
(
:list
)])
list_label
=
create
(
:label
,
lists:
[
create
(
:list
)])
issue
=
create
(
:issue
)
issue
=
create
(
:issue
)
issue
.
update
(
milestone:
milestone
)
issue
.
update
(
milestone:
milestone
)
issue
.
update
(
label_ids:
[
list_label
.
id
])
issue
.
update
(
label_ids:
[
list_label
.
id
])
expect
(
subject
.
issue
).
to
be_nil
expect
(
subject
.
issue
).
to
be_nil
end
end
it
"excludes issues created before the 'from' date"
do
it
"excludes issues created before the 'from' date"
do
before_from_date
=
from_date
-
5
.
days
before_from_date
=
from_date
-
5
.
days
milestone
=
create
(
:milestone
,
project:
project
)
milestone
=
create
(
:milestone
,
project:
project
)
list_label
=
create
(
:label
,
lists:
[
create
(
:list
)])
list_label
=
create
(
:label
,
lists:
[
create
(
:list
)])
issue
=
Timecop
.
freeze
(
before_from_date
)
{
create
(
:issue
,
project:
project
)}
issue
=
Timecop
.
freeze
(
before_from_date
)
{
create
(
:issue
,
project:
project
)}
issue
.
update
(
milestone:
milestone
)
issue
.
update
(
milestone:
milestone
)
issue
.
update
(
label_ids:
[
list_label
.
id
])
issue
.
update
(
label_ids:
[
list_label
.
id
])
expect
(
subject
.
issue
).
to
be_nil
expect
(
subject
.
issue
).
to
be_nil
end
end
end
end
end
end
end
spec/models/cycle_analytics/plan_spec.rb
0 → 100644
View file @
0f748605
require
'spec_helper'
describe
'CycleAnalytics#plan'
,
feature:
true
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:from_date
)
{
10
.
days
.
ago
}
let
(
:user
)
{
create
(
:user
,
:admin
)
}
subject
{
CycleAnalytics
.
new
(
project
,
from:
from_date
)
}
def
create_commit_referencing_issue
(
issue
,
time:
Time
.
now
)
sha
=
Timecop
.
freeze
(
time
)
{
project
.
repository
.
commit_file
(
user
,
FFaker
::
Product
.
brand
,
"content"
,
"Commit for #
#{
issue
.
iid
}
"
,
"master"
,
false
)
}
commit
=
project
.
repository
.
commit
(
sha
)
commit
.
create_cross_references!
end
context
"when a milestone is added to the issue"
do
context
"when the issue is mentioned in a commit"
do
it
"calculates the median of available durations between the two"
do
time_differences
=
Array
.
new
(
5
)
do
start_time
=
Time
.
now
end_time
=
rand
(
1
..
10
).
days
.
from_now
milestone
=
create
(
:milestone
,
project:
project
)
issue
=
create
(
:issue
,
project:
project
)
Timecop
.
freeze
(
start_time
)
{
issue
.
update
(
milestone:
milestone
)
}
create_commit_referencing_issue
(
issue
,
time:
end_time
)
end_time
-
start_time
end
median_time_difference
=
time_differences
.
sort
[
2
]
# Use `be_within` to account for time lost between Rails invoking CLI git
# and the commit being created, which Timecop can't freeze.
expect
(
subject
.
plan
).
to
be_within
(
2
).
of
(
median_time_difference
)
end
end
end
context
"when a label is added to the issue"
do
context
"when the issue is mentioned in a commit"
do
context
"when the label is a list-label"
do
it
"calculates the median of available durations between the two"
do
time_differences
=
Array
.
new
(
5
)
do
start_time
=
Time
.
now
end_time
=
rand
(
1
..
10
).
days
.
from_now
issue
=
create
(
:issue
,
project:
project
)
list_label
=
create
(
:label
,
lists:
[
create
(
:list
)])
Timecop
.
freeze
(
start_time
)
{
issue
.
update
(
label_ids:
[
list_label
.
id
])
}
create_commit_referencing_issue
(
issue
,
time:
end_time
)
end_time
-
start_time
end
median_time_difference
=
time_differences
.
sort
[
2
]
# Use `be_within` to account for time lost between Rails invoking CLI git
# and the commit being created, which Timecop can't freeze.
expect
(
subject
.
plan
).
to
be_within
(
2
).
of
(
median_time_difference
)
end
end
it
"does not make a calculation for regular labels"
do
5
.
times
do
regular_label
=
create
(
:label
)
issue
=
create
(
:issue
,
project:
project
)
issue
.
update
(
label_ids:
[
regular_label
.
id
])
create_commit_referencing_issue
(
issue
)
end
expect
(
subject
.
plan
).
to
be_nil
end
end
end
context
"when a milestone and list-label are both added to the issue"
do
context
"when the issue is mentioned in a commit"
do
it
"calculates the median of available durations between the two (using milestone addition as the 'start_time')"
do
time_differences
=
Array
.
new
(
5
)
do
label_addition_time
=
Time
.
now
milestone_addition_time
=
rand
(
2
..
12
).
hours
.
from_now
end_time
=
rand
(
1
..
10
).
days
.
from_now
issue
=
create
(
:issue
,
project:
project
)
milestone
=
create
(
:milestone
,
project:
project
)
list_label
=
create
(
:label
,
lists:
[
create
(
:list
)])
Timecop
.
freeze
(
label_addition_time
)
{
issue
.
update
(
label_ids:
[
list_label
.
id
])
}
Timecop
.
freeze
(
milestone_addition_time
)
{
issue
.
update
(
milestone:
milestone
)
}
create_commit_referencing_issue
(
issue
,
time:
end_time
)
end_time
-
milestone_addition_time
end
median_time_difference
=
time_differences
.
sort
[
2
]
# Use `be_within` to account for time lost between Rails invoking CLI git
# and the commit being created, which Timecop can't freeze.
expect
(
subject
.
plan
).
to
be_within
(
2
).
of
(
median_time_difference
)
end
it
"does not include issues from other projects"
do
other_project
=
create
(
:project
)
list_label
=
create
(
:label
,
lists:
[
create
(
:list
)])
issue
=
create
(
:issue
,
project:
other_project
)
issue
.
update
(
milestone:
create
(
:milestone
))
issue
.
update
(
label_ids:
[
list_label
.
id
])
create_commit_referencing_issue
(
issue
)
expect
(
subject
.
issue
).
to
be_nil
end
it
"excludes issues created before the 'from' date"
do
before_from_date
=
from_date
-
5
.
days
milestone
=
create
(
:milestone
,
project:
project
)
list_label
=
create
(
:label
,
lists:
[
create
(
:list
)])
issue
=
Timecop
.
freeze
(
before_from_date
)
{
create
(
:issue
,
project:
project
)}
issue
.
update
(
milestone:
milestone
)
issue
.
update
(
label_ids:
[
list_label
.
id
])
create_commit_referencing_issue
(
issue
)
expect
(
subject
.
issue
).
to
be_nil
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