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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
204419e9
Commit
204419e9
authored
Sep 20, 2016
by
Timothy Andrew
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test the `CycleAnalytics::Summary` model.
parent
461b3995
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
83 additions
and
6 deletions
+83
-6
app/models/cycle_analytics/summary.rb
app/models/cycle_analytics/summary.rb
+5
-2
spec/factories/deployments.rb
spec/factories/deployments.rb
+2
-1
spec/models/cycle_analytics/summary_spec.rb
spec/models/cycle_analytics/summary_spec.rb
+53
-0
spec/support/cycle_analytics_helpers.rb
spec/support/cycle_analytics_helpers.rb
+23
-3
No files found.
app/models/cycle_analytics/summary.rb
View file @
204419e9
...
@@ -11,11 +11,14 @@ class CycleAnalytics
...
@@ -11,11 +11,14 @@ class CycleAnalytics
def
commits
def
commits
repository
=
@project
.
repository
.
raw_repository
repository
=
@project
.
repository
.
raw_repository
repository
.
log
(
ref:
@project
.
default_branch
,
after:
@from
).
count
if
@project
.
default_branch
repository
.
log
(
ref:
@project
.
default_branch
,
after:
@from
).
count
end
end
end
def
deploys
def
deploys
@project
.
deployments
.
count
@project
.
deployments
.
where
(
"created_at > ?"
,
@from
).
count
end
end
end
end
end
end
spec/factories/deployments.rb
View file @
204419e9
...
@@ -3,11 +3,12 @@ FactoryGirl.define do
...
@@ -3,11 +3,12 @@ FactoryGirl.define do
sha
'97de212e80737a608d939f648d959671fb0a0142'
sha
'97de212e80737a608d939f648d959671fb0a0142'
ref
'master'
ref
'master'
tag
false
tag
false
project
nil
environment
factory: :environment
environment
factory: :environment
after
(
:build
)
do
|
deployment
,
evaluator
|
after
(
:build
)
do
|
deployment
,
evaluator
|
deployment
.
project
=
deployment
.
environment
.
project
deployment
.
project
||
=
deployment
.
environment
.
project
end
end
end
end
end
end
spec/models/cycle_analytics/summary_spec.rb
0 → 100644
View file @
204419e9
require
'spec_helper'
describe
CycleAnalytics
::
Summary
,
models:
true
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:from
)
{
Time
.
now
}
let
(
:user
)
{
create
(
:user
,
:admin
)
}
subject
{
described_class
.
new
(
project
,
from:
from
)
}
describe
"#new_issues"
do
it
"finds the number of issues created after the 'from date'"
do
Timecop
.
freeze
(
5
.
days
.
ago
)
{
create
(
:issue
,
project:
project
)
}
Timecop
.
freeze
(
5
.
days
.
from_now
)
{
create
(
:issue
,
project:
project
)
}
expect
(
subject
.
new_issues
).
to
eq
(
1
)
end
it
"doesn't find issues from other projects"
do
Timecop
.
freeze
(
5
.
days
.
from_now
)
{
create
(
:issue
,
project:
create
(
:project
))
}
expect
(
subject
.
new_issues
).
to
eq
(
0
)
end
end
describe
"#commits"
do
it
"finds the number of commits created after the 'from date'"
do
Timecop
.
freeze
(
5
.
days
.
ago
)
{
create_commit
(
"Test message"
,
project
,
user
,
'master'
)
}
Timecop
.
freeze
(
5
.
days
.
from_now
)
{
create_commit
(
"Test message"
,
project
,
user
,
'master'
)
}
expect
(
subject
.
commits
).
to
eq
(
1
)
end
it
"doesn't find commits from other projects"
do
Timecop
.
freeze
(
5
.
days
.
from_now
)
{
create_commit
(
"Test message"
,
create
(
:project
),
user
,
'master'
)
}
expect
(
subject
.
commits
).
to
eq
(
0
)
end
end
describe
"#deploys"
do
it
"finds the number of deploys made created after the 'from date'"
do
Timecop
.
freeze
(
5
.
days
.
ago
)
{
create
(
:deployment
,
project:
project
)
}
Timecop
.
freeze
(
5
.
days
.
from_now
)
{
create
(
:deployment
,
project:
project
)
}
expect
(
subject
.
deploys
).
to
eq
(
1
)
end
it
"doesn't find commits from other projects"
do
Timecop
.
freeze
(
5
.
days
.
from_now
)
{
create
(
:deployment
,
project:
create
(
:project
))
}
expect
(
subject
.
deploys
).
to
eq
(
0
)
end
end
end
spec/support/cycle_analytics_helpers.rb
View file @
204419e9
module
CycleAnalyticsHelpers
module
CycleAnalyticsHelpers
def
create_commit_referencing_issue
(
issue
)
def
create_commit_referencing_issue
(
issue
)
sha
=
project
.
repository
.
commit_file
(
user
,
random_git_name
,
"content"
,
"Commit for #
#{
issue
.
iid
}
"
,
"master"
,
false
)
branch_name
=
random_git_name
commit
=
project
.
repository
.
commit
(
sha
)
project
.
repository
.
add_branch
(
user
,
branch_name
,
'master'
)
commit
.
create_cross_references!
(
user
)
create_commit
(
"Commit for #
#{
issue
.
iid
}
"
,
issue
.
project
,
user
,
branch_name
)
end
def
create_commit
(
message
,
project
,
user
,
branch_name
)
filename
=
random_git_name
options
=
{
committer:
project
.
repository
.
user_to_committer
(
user
),
author:
project
.
repository
.
user_to_committer
(
user
),
commit:
{
message:
message
,
branch:
branch_name
,
update_ref:
true
},
file:
{
content:
"content"
,
path:
filename
,
update:
false
}
}
commit_sha
=
Gitlab
::
Git
::
Blob
.
commit
(
project
.
repository
,
options
)
project
.
repository
.
commit
(
commit_sha
)
GitPushService
.
new
(
project
,
user
,
oldrev:
project
.
repository
.
commit
(
branch_name
).
sha
,
newrev:
commit_sha
,
ref:
'refs/heads/master'
).
execute
end
end
def
create_merge_request_closing_issue
(
issue
,
message:
nil
)
def
create_merge_request_closing_issue
(
issue
,
message:
nil
)
...
...
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