Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
heptapod
heptapod
Commits
5ed6ccd27d6c
Commit
5ed6ccd2
authored
Sep 28, 2015
by
Kamil Trzcinski
Browse files
Fix tests
parent
6e18ba78ae88
Changes
11
Hide whitespace changes
Inline
Side-by-side
app/models/ci/build.rb
View file @
5ed6ccd2
...
...
@@ -186,7 +186,7 @@
end
def
project_id
commit
.
gl_
project
.
gitlab_
id
commit
.
project
.
id
end
def
project_name
...
...
app/models/ci/commit.rb
View file @
5ed6ccd2
...
...
@@ -37,8 +37,15 @@
end
def
project
@project
||=
gl_project
.
gitlab_ci_project
@project
||=
gl_project
.
create_gitlab_ci_project
unless
@project
gl_project
.
ensure_ci_project
@project
=
gl_project
.
gitlab_ci_project
end
@project
end
def
project_id
project
.
id
end
def
last_build
...
...
@@ -116,14 +123,14 @@
builds_attrs
=
config_processor
.
builds_for_stage_and_ref
(
stage
,
ref
,
tag
)
builds_attrs
.
map
do
|
build_attrs
|
builds
.
create!
({
name:
build_attrs
[
:name
],
commands:
build_attrs
[
:script
],
tag_list:
build_attrs
[
:tags
],
options:
build_attrs
[
:options
],
allow_failure:
build_attrs
[
:allow_failure
],
stage:
build_attrs
[
:stage
],
trigger_request:
trigger_request
,
})
name:
build_attrs
[
:name
],
commands:
build_attrs
[
:script
],
tag_list:
build_attrs
[
:tags
],
options:
build_attrs
[
:options
],
allow_failure:
build_attrs
[
:allow_failure
],
stage:
build_attrs
[
:stage
],
trigger_request:
trigger_request
,
})
end
end
...
...
app/models/project.rb
View file @
5ed6ccd2
...
...
@@ -748,6 +748,12 @@
gitlab_ci_project
.
commits
.
find_by
(
sha:
sha
)
if
gitlab_ci?
end
def
ensure_ci_project
unless
gitlab_ci_project
create_gitlab_ci_project
end
end
def
enable_ci
(
user
)
# Enable service
service
=
gitlab_ci_service
||
create_gitlab_ci_service
...
...
spec/models/ci/commit_spec.rb
View file @
5ed6ccd2
...
...
@@ -18,7 +18,9 @@
require
'spec_helper'
describe
Ci
::
Commit
do
let
(
:commit
)
{
FactoryGirl
.
create
:ci_commit
}
let
(
:commit_with_project
)
{
FactoryGirl
.
create
:ci_commit
}
let
(
:project
)
{
FactoryGirl
.
create
:ci_project
}
let
(
:gl_project
)
{
FactoryGirl
.
create
:empty_project
,
gitlab_ci_project:
project
}
let
(
:commit
)
{
FactoryGirl
.
create
:ci_commit
,
gl_project:
gl_project
}
let
(
:commit_with_project
)
{
FactoryGirl
.
create
:ci_commit
,
gl_project:
gl_project
}
let
(
:config_processor
)
{
Ci
::
GitlabCiYamlProcessor
.
new
(
gitlab_ci_yaml
)
}
...
...
@@ -23,6 +25,6 @@
let
(
:config_processor
)
{
Ci
::
GitlabCiYamlProcessor
.
new
(
gitlab_ci_yaml
)
}
it
{
is_expected
.
to
belong_to
(
:project
)
}
it
{
is_expected
.
to
belong_to
(
:
gl_
project
)
}
it
{
is_expected
.
to
have_many
(
:builds
)
}
it
{
is_expected
.
to
validate_presence_of
:before_sha
}
it
{
is_expected
.
to
validate_presence_of
:sha
}
...
...
@@ -87,7 +89,7 @@
email_add_pusher:
false
,
email_recipients:
'rec1 rec2'
gl_project
=
FactoryGirl
.
create
:empty_project
,
gitlab_ci_project:
project
commit
=
FactoryGirl
.
create
:ci_commit
,
project:
gl_project
commit
=
FactoryGirl
.
create
:ci_commit
,
gl_
project:
gl_project
expect
(
commit
.
project_recipients
).
to
eq
([
'rec1'
,
'rec2'
])
end
...
...
@@ -96,7 +98,7 @@
email_add_pusher:
true
,
email_recipients:
'rec1 rec1 rec2'
gl_project
=
FactoryGirl
.
create
:empty_project
,
gitlab_ci_project:
project
commit
=
FactoryGirl
.
create
:ci_commit
,
project:
gl_project
commit
=
FactoryGirl
.
create
:ci_commit
,
gl_
project:
gl_project
expected
=
'rec2'
allow
(
commit
).
to
receive
(
:push_data
)
{
{
user_email:
expected
}
}
expect
(
commit
.
project_recipients
).
to
eq
([
'rec1'
,
'rec2'
])
...
...
spec/models/ci/project_services/hip_chat_message_spec.rb
View file @
5ed6ccd2
...
...
@@ -3,6 +3,4 @@
describe
Ci
::
HipChatMessage
do
subject
{
Ci
::
HipChatMessage
.
new
(
build
)
}
let
(
:project
)
{
FactoryGirl
.
create
(
:ci_project
)
}
context
"One build"
do
...
...
@@ -8,5 +6,5 @@
context
"One build"
do
let
(
:commit
)
{
FactoryGirl
.
create
(
:ci_commit_with_one_job
,
project:
project
)
}
let
(
:commit
)
{
FactoryGirl
.
create
(
:ci_commit_with_one_job
)
}
let
(
:build
)
do
commit
.
create_builds
...
...
@@ -37,7 +35,7 @@
end
context
"Several builds"
do
let
(
:commit
)
{
FactoryGirl
.
create
(
:ci_commit_with_two_jobs
,
project:
project
)
}
let
(
:commit
)
{
FactoryGirl
.
create
(
:ci_commit_with_two_jobs
)
}
let
(
:build
)
do
commit
.
builds
.
first
...
...
spec/models/ci/project_services/hip_chat_service_spec.rb
View file @
5ed6ccd2
...
...
@@ -39,8 +39,8 @@
before
do
allow
(
service
).
to
receive_messages
(
project:
project
,
project_id:
project
.
id
,
project:
commit
.
project
,
project_id:
commit
.
project
_
id
,
notify_only_broken_builds:
false
,
hipchat_room:
123
,
hipchat_token:
'a1b2c3d4e5f6'
...
...
spec/models/ci/project_services/slack_message_spec.rb
View file @
5ed6ccd2
...
...
@@ -3,6 +3,4 @@
describe
Ci
::
SlackMessage
do
subject
{
Ci
::
SlackMessage
.
new
(
commit
)
}
let
(
:project
)
{
FactoryGirl
.
create
:ci_project
}
context
"One build"
do
...
...
@@ -8,5 +6,5 @@
context
"One build"
do
let
(
:commit
)
{
FactoryGirl
.
create
(
:ci_commit_with_one_job
,
project:
project
)
}
let
(
:commit
)
{
FactoryGirl
.
create
(
:ci_commit_with_one_job
)
}
let
(
:build
)
do
commit
.
create_builds
...
...
@@ -43,7 +41,7 @@
end
context
"Several builds"
do
let
(
:commit
)
{
FactoryGirl
.
create
(
:ci_commit_with_two_jobs
,
project:
project
)
}
let
(
:commit
)
{
FactoryGirl
.
create
(
:ci_commit_with_two_jobs
)
}
context
'when all matrix builds succeeded'
do
let
(
:color
)
{
'good'
}
...
...
spec/models/ci/project_services/slack_service_spec.rb
View file @
5ed6ccd2
...
...
@@ -38,8 +38,8 @@
before
do
allow
(
slack
).
to
receive_messages
(
project:
project
,
project_id:
project
.
id
,
project:
commit
.
project
,
project_id:
commit
.
project
_
id
,
webhook:
webhook_url
,
notify_only_broken_builds:
notify_only_broken_builds
)
...
...
spec/models/ci/project_spec.rb
View file @
5ed6ccd2
...
...
@@ -28,5 +28,7 @@
require
'spec_helper'
describe
Ci
::
Project
do
let
(
:gl_project
)
{
FactoryGirl
.
create
:empty_project
,
gitlab_ci_project:
project
}
let
(
:gl_project
)
{
}
subject
{
FactoryGirl
.
build
:ci_project
}
...
...
@@ -31,6 +33,12 @@
subject
{
FactoryGirl
.
build
:ci_project
}
it
{
is_expected
.
to
have_many
(
:commits
)
}
it
{
is_expected
.
to
have_many
(
:runner_projects
)
}
it
{
is_expected
.
to
have_many
(
:runners
)
}
it
{
is_expected
.
to
have_many
(
:web_hooks
)
}
it
{
is_expected
.
to
have_many
(
:events
)
}
it
{
is_expected
.
to
have_many
(
:variables
)
}
it
{
is_expected
.
to
have_many
(
:triggers
)
}
it
{
is_expected
.
to
have_many
(
:services
)
}
it
{
is_expected
.
to
validate_presence_of
:name
}
it
{
is_expected
.
to
validate_presence_of
:timeout
}
...
...
@@ -50,7 +58,10 @@
describe
"ordered_by_last_commit_date"
do
it
"returns ordered projects"
do
newest_project
=
FactoryGirl
.
create
:ci_project
oldest_project
=
FactoryGirl
.
create
:ci_project
project_without_commits
=
FactoryGirl
.
create
:ci_project
newest_project
=
FactoryGirl
.
create
:empty_project
newest_project
.
ensure_ci_project
oldest_project
=
FactoryGirl
.
create
:empty_project
oldest_project
.
ensure_ci_project
project_without_commits
=
FactoryGirl
.
create
:empty_project
project_without_commits
.
ensure_ci_project
...
...
@@ -56,4 +67,4 @@
FactoryGirl
.
create
:ci_commit
,
committed_at:
1
.
hour
.
ago
,
project:
newest_project
FactoryGirl
.
create
:ci_commit
,
committed_at:
2
.
hour
.
ago
,
project:
oldest_project
FactoryGirl
.
create
:ci_commit
,
committed_at:
1
.
hour
.
ago
,
gl_
project:
newest_project
FactoryGirl
.
create
:ci_commit
,
committed_at:
2
.
hour
.
ago
,
gl_
project:
oldest_project
...
...
@@ -59,6 +70,6 @@
expect
(
Ci
::
Project
.
ordered_by_last_commit_date
).
to
eq
([
newest_project
,
oldest
_project
,
project_without_commits
])
expect
(
Ci
::
Project
.
ordered_by_last_commit_date
).
to
eq
([
newest_project
.
gitlab_ci_project
,
oldest_project
.
gitlab_ci
_project
,
project_without_commits
.
gitlab_ci_project
])
end
end
describe
'ordered commits'
do
...
...
@@ -61,7 +72,7 @@
end
end
describe
'ordered commits'
do
let
(
:project
)
{
FactoryGirl
.
create
:
ci
_project
}
let
(
:project
)
{
FactoryGirl
.
create
:
empty
_project
}
it
'returns ordered list of commits'
do
...
...
@@ -66,8 +77,8 @@
it
'returns ordered list of commits'
do
commit1
=
FactoryGirl
.
create
:ci_commit
,
committed_at:
1
.
hour
.
ago
,
project:
project
commit2
=
FactoryGirl
.
create
:ci_commit
,
committed_at:
2
.
hour
.
ago
,
project:
project
expect
(
project
.
commits
).
to
eq
([
commit2
,
commit1
])
commit1
=
FactoryGirl
.
create
:ci_commit
,
committed_at:
1
.
hour
.
ago
,
gl_
project:
project
commit2
=
FactoryGirl
.
create
:ci_commit
,
committed_at:
2
.
hour
.
ago
,
gl_
project:
project
expect
(
project
.
commits
).
to
eq
([
commit2
.
project
,
commit1
.
project
])
end
it
'returns commits ordered by committed_at and id, with nulls last'
do
...
...
@@ -71,12 +82,12 @@
end
it
'returns commits ordered by committed_at and id, with nulls last'
do
commit1
=
FactoryGirl
.
create
:ci_commit
,
committed_at:
1
.
hour
.
ago
,
project:
project
commit2
=
FactoryGirl
.
create
:ci_commit
,
committed_at:
nil
,
project:
project
commit3
=
FactoryGirl
.
create
:ci_commit
,
committed_at:
2
.
hour
.
ago
,
project:
project
commit4
=
FactoryGirl
.
create
:ci_commit
,
committed_at:
nil
,
project:
project
expect
(
project
.
commits
).
to
eq
([
commit2
,
commit4
,
commit3
,
commit1
])
commit1
=
FactoryGirl
.
create
:ci_commit
,
committed_at:
1
.
hour
.
ago
,
gl_
project:
project
commit2
=
FactoryGirl
.
create
:ci_commit
,
committed_at:
nil
,
gl_
project:
project
commit3
=
FactoryGirl
.
create
:ci_commit
,
committed_at:
2
.
hour
.
ago
,
gl_
project:
project
commit4
=
FactoryGirl
.
create
:ci_commit
,
committed_at:
nil
,
gl_
project:
project
expect
(
project
.
commits
).
to
eq
([
commit2
.
project
,
commit4
.
project
,
commit3
.
project
,
commit1
.
project
])
end
end
context
:valid_project
do
...
...
@@ -79,9 +90,7 @@
end
end
context
:valid_project
do
let
(
:project
)
{
FactoryGirl
.
create
:ci_project
}
let
(
:gl_project
)
{
FactoryGirl
.
create
(
:empty_project
,
gitlab_ci_project:
project
)
}
let
(
:commit
)
{
FactoryGirl
.
create
(
:ci_commit
,
gl_project:
gl_project
)
}
let
(
:commit
)
{
FactoryGirl
.
create
(
:ci_commit
)
}
context
:project_with_commit_and_builds
do
...
...
@@ -86,5 +95,7 @@
context
:project_with_commit_and_builds
do
let
(
:project
)
{
commit
.
project
}
before
do
FactoryGirl
.
create
(
:ci_build
,
commit:
commit
)
end
...
...
spec/models/ci/service_spec.rb
View file @
5ed6ccd2
...
...
@@ -34,7 +34,7 @@
before
do
allow
(
@service
).
to
receive_messages
(
project:
project
project:
commit
.
project
)
build
@testable
=
@service
.
can_test?
...
...
spec/services/ci/register_build_service_spec.rb
View file @
5ed6ccd2
...
...
@@ -3,7 +3,9 @@
module
Ci
describe
RegisterBuildService
do
let!
(
:service
)
{
RegisterBuildService
.
new
}
let!
(
:commit
)
{
FactoryGirl
.
create
:ci_commit
}
let!
(
:project
)
{
FactoryGirl
.
create
:ci_project
}
let!
(
:gl_project
)
{
FactoryGirl
.
create
:empty_project
,
gitlab_ci_project:
project
}
let!
(
:commit
)
{
FactoryGirl
.
create
:ci_commit
,
gl_project:
gl_project
}
let!
(
:pending_build
)
{
FactoryGirl
.
create
:ci_build
,
commit:
commit
}
let!
(
:shared_runner
)
{
FactoryGirl
.
create
(
:ci_runner
,
is_shared:
true
)
}
let!
(
:specific_runner
)
{
FactoryGirl
.
create
(
:ci_runner
,
is_shared:
false
)
}
...
...
Write
Preview
Supports
Markdown
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