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
Kazuhiko Shiozaki
gitlab-ce
Commits
59c3a323
Commit
59c3a323
authored
Sep 10, 2015
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix commit specs
parent
10b3c85e
Changes
18
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
254 additions
and
250 deletions
+254
-250
app/models/ci/trigger.rb
app/models/ci/trigger.rb
+2
-2
spec/factories/ci/builds.rb
spec/factories/ci/builds.rb
+1
-1
spec/factories/ci/trigger_requests.rb
spec/factories/ci/trigger_requests.rb
+1
-1
spec/models/ci/build_spec.rb
spec/models/ci/build_spec.rb
+45
-45
spec/models/ci/commit_spec.rb
spec/models/ci/commit_spec.rb
+60
-56
spec/models/ci/mail_service_spec.rb
spec/models/ci/mail_service_spec.rb
+18
-18
spec/models/ci/network_spec.rb
spec/models/ci/network_spec.rb
+13
-13
spec/models/ci/project_services/hip_chat_message_spec.rb
spec/models/ci/project_services/hip_chat_message_spec.rb
+4
-4
spec/models/ci/project_services/hip_chat_service_spec.rb
spec/models/ci/project_services/hip_chat_service_spec.rb
+3
-3
spec/models/ci/project_services/slack_message_spec.rb
spec/models/ci/project_services/slack_message_spec.rb
+22
-22
spec/models/ci/project_services/slack_service_spec.rb
spec/models/ci/project_services/slack_service_spec.rb
+4
-4
spec/models/ci/project_spec.rb
spec/models/ci/project_spec.rb
+43
-43
spec/models/ci/runner_spec.rb
spec/models/ci/runner_spec.rb
+5
-5
spec/models/ci/service_spec.rb
spec/models/ci/service_spec.rb
+3
-3
spec/models/ci/trigger_spec.rb
spec/models/ci/trigger_spec.rb
+2
-2
spec/models/ci/user_spec.rb
spec/models/ci/user_spec.rb
+9
-9
spec/models/ci/variable_spec.rb
spec/models/ci/variable_spec.rb
+4
-4
spec/models/ci/web_hook_spec.rb
spec/models/ci/web_hook_spec.rb
+15
-15
No files found.
app/models/ci/trigger.rb
View file @
59c3a323
...
...
@@ -13,10 +13,10 @@
module
Ci
class
Trigger
<
ActiveRecord
::
Base
extend
Ci
::
Model
acts_as_paranoid
belongs_to
:project
,
class_name:
'Ci::
Trigger
'
belongs_to
:project
,
class_name:
'Ci::
Project
'
has_many
:trigger_requests
,
dependent: :destroy
,
class_name:
'Ci::TriggerRequest'
validates_presence_of
:token
...
...
spec/factories/ci/builds.rb
View file @
59c3a323
...
...
@@ -37,7 +37,7 @@ FactoryGirl.define do
}
end
factory
:not_started_build
do
factory
:
ci_
not_started_build
do
started_at
nil
finished_at
nil
end
...
...
spec/factories/ci/trigger_requests.rb
View file @
59c3a323
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl
.
define
do
factory
:ci_trigger_request
do
factory
:ci_trigger_request
,
class:
Ci
::
TriggerRequest
do
factory
:ci_trigger_request_with_variables
do
variables
do
{
...
...
spec/models/ci/build_spec.rb
View file @
59c3a323
...
...
@@ -30,14 +30,14 @@ describe Ci::Build do
let
(
:commit
)
{
FactoryGirl
.
create
:ci_commit
,
project:
project
}
let
(
:build
)
{
FactoryGirl
.
create
:ci_build
,
commit:
commit
}
it
{
should
belong_to
(
:commit
)
}
it
{
should
validate_presence_of
:status
}
it
{
is_expected
.
to
belong_to
(
:commit
)
}
it
{
is_expected
.
to
validate_presence_of
:status
}
it
{
should
respond_to
:success?
}
it
{
should
respond_to
:failed?
}
it
{
should
respond_to
:running?
}
it
{
should
respond_to
:pending?
}
it
{
should
respond_to
:trace_html
}
it
{
is_expected
.
to
respond_to
:success?
}
it
{
is_expected
.
to
respond_to
:failed?
}
it
{
is_expected
.
to
respond_to
:running?
}
it
{
is_expected
.
to
respond_to
:pending?
}
it
{
is_expected
.
to
respond_to
:trace_html
}
describe
:first_pending
do
let
(
:first
)
{
FactoryGirl
.
create
:ci_build
,
commit:
commit
,
status:
'pending'
,
created_at:
Date
.
yesterday
}
...
...
@@ -45,8 +45,8 @@ describe Ci::Build do
before
{
first
;
second
}
subject
{
Ci
::
Build
.
first_pending
}
it
{
should
be_a
(
Ci
::
Build
)
}
it
(
'returns with the first pending build'
)
{
should
eq
(
first
)
}
it
{
is_expected
.
to
be_a
(
Ci
::
Build
)
}
it
(
'returns with the first pending build'
)
{
is_expected
.
to
eq
(
first
)
}
end
describe
:create_from
do
...
...
@@ -69,14 +69,14 @@ describe Ci::Build do
context
'without started_at'
do
before
{
build
.
started_at
=
nil
}
it
{
should
be_falsey
}
it
{
is_expected
.
to
be_falsey
}
end
%w(running success failed)
.
each
do
|
status
|
context
"if build status is
#{
status
}
"
do
before
{
build
.
status
=
status
}
it
{
should
be_truthy
}
it
{
is_expected
.
to
be_truthy
}
end
end
...
...
@@ -84,7 +84,7 @@ describe Ci::Build do
context
"if build status is
#{
status
}
"
do
before
{
build
.
status
=
status
}
it
{
should
be_falsey
}
it
{
is_expected
.
to
be_falsey
}
end
end
end
...
...
@@ -96,7 +96,7 @@ describe Ci::Build do
context
"if build.status is
#{
state
}
"
do
before
{
build
.
status
=
state
}
it
{
should
be_truthy
}
it
{
is_expected
.
to
be_truthy
}
end
end
...
...
@@ -104,7 +104,7 @@ describe Ci::Build do
context
"if build.status is
#{
state
}
"
do
before
{
build
.
status
=
state
}
it
{
should
be_falsey
}
it
{
is_expected
.
to
be_falsey
}
end
end
end
...
...
@@ -116,7 +116,7 @@ describe Ci::Build do
context
"if build.status is
#{
state
}
"
do
before
{
build
.
status
=
state
}
it
{
should
be_truthy
}
it
{
is_expected
.
to
be_truthy
}
end
end
...
...
@@ -124,7 +124,7 @@ describe Ci::Build do
context
"if build.status is
#{
state
}
"
do
before
{
build
.
status
=
state
}
it
{
should
be_falsey
}
it
{
is_expected
.
to
be_falsey
}
end
end
end
...
...
@@ -138,13 +138,13 @@ describe Ci::Build do
context
'and build.status is success'
do
before
{
build
.
status
=
'success'
}
it
{
should
be_falsey
}
it
{
is_expected
.
to
be_falsey
}
end
context
'and build.status is failed'
do
before
{
build
.
status
=
'failed'
}
it
{
should
be_falsey
}
it
{
is_expected
.
to
be_falsey
}
end
end
...
...
@@ -154,13 +154,13 @@ describe Ci::Build do
context
'and build.status is success'
do
before
{
build
.
status
=
'success'
}
it
{
should
be_falsey
}
it
{
is_expected
.
to
be_falsey
}
end
context
'and build.status is failed'
do
before
{
build
.
status
=
'failed'
}
it
{
should
be_truthy
}
it
{
is_expected
.
to
be_truthy
}
end
end
end
...
...
@@ -168,27 +168,27 @@ describe Ci::Build do
describe
:trace
do
subject
{
build
.
trace_html
}
it
{
should
be_empty
}
it
{
is_expected
.
to
be_empty
}
context
'if build.trace contains text'
do
let
(
:text
)
{
'example output'
}
before
{
build
.
trace
=
text
}
it
{
should
include
(
text
)
}
it
{
should
have_at_least
(
text
.
length
).
items
}
it
{
is_expected
.
to
include
(
text
)
}
it
{
is_expected
.
to
have_at_least
(
text
.
length
).
items
}
end
end
describe
:timeout
do
subject
{
build
.
timeout
}
it
{
should
eq
(
commit
.
project
.
timeout
)
}
it
{
is_expected
.
to
eq
(
commit
.
project
.
timeout
)
}
end
describe
:duration
do
subject
{
build
.
duration
}
it
{
should
eq
(
120.0
)
}
it
{
is_expected
.
to
eq
(
120.0
)
}
context
'if the building process has not started yet'
do
before
do
...
...
@@ -196,7 +196,7 @@ describe Ci::Build do
build
.
finished_at
=
nil
end
it
{
should
be_nil
}
it
{
is_expected
.
to
be_nil
}
end
context
'if the building process has started'
do
...
...
@@ -205,8 +205,8 @@ describe Ci::Build do
build
.
finished_at
=
nil
end
it
{
should
be_a
(
Float
)
}
it
{
should
>
0.0
}
it
{
is_expected
.
to
be_a
(
Float
)
}
it
{
is_expected
.
to
be
>
0.0
}
end
end
...
...
@@ -221,86 +221,86 @@ describe Ci::Build do
}
subject
{
build
.
options
}
it
{
should
eq
(
options
)
}
it
{
is_expected
.
to
eq
(
options
)
}
end
describe
:ref
do
subject
{
build
.
ref
}
it
{
should
eq
(
commit
.
ref
)
}
it
{
is_expected
.
to
eq
(
commit
.
ref
)
}
end
describe
:sha
do
subject
{
build
.
sha
}
it
{
should
eq
(
commit
.
sha
)
}
it
{
is_expected
.
to
eq
(
commit
.
sha
)
}
end
describe
:short_sha
do
subject
{
build
.
short_sha
}
it
{
should
eq
(
commit
.
short_sha
)
}
it
{
is_expected
.
to
eq
(
commit
.
short_sha
)
}
end
describe
:before_sha
do
subject
{
build
.
before_sha
}
it
{
should
eq
(
commit
.
before_sha
)
}
it
{
is_expected
.
to
eq
(
commit
.
before_sha
)
}
end
describe
:allow_git_fetch
do
subject
{
build
.
allow_git_fetch
}
it
{
should
eq
(
project
.
allow_git_fetch
)
}
it
{
is_expected
.
to
eq
(
project
.
allow_git_fetch
)
}
end
describe
:project
do
subject
{
build
.
project
}
it
{
should
eq
(
commit
.
project
)
}
it
{
is_expected
.
to
eq
(
commit
.
project
)
}
end
describe
:project_id
do
subject
{
build
.
project_id
}
it
{
should
eq
(
commit
.
project_id
)
}
it
{
is_expected
.
to
eq
(
commit
.
project_id
)
}
end
describe
:project_name
do
subject
{
build
.
project_name
}
it
{
should
eq
(
project
.
name
)
}
it
{
is_expected
.
to
eq
(
project
.
name
)
}
end
describe
:repo_url
do
subject
{
build
.
repo_url
}
it
{
should
eq
(
project
.
repo_url_with_auth
)
}
it
{
is_expected
.
to
eq
(
project
.
repo_url_with_auth
)
}
end
describe
:extract_coverage
do
context
'valid content & regex'
do
subject
{
build
.
extract_coverage
(
'Coverage 1033 / 1051 LOC (98.29%) covered'
,
'\(\d+.\d+\%\) covered'
)
}
it
{
should
eq
(
98.29
)
}
it
{
is_expected
.
to
eq
(
98.29
)
}
end
context
'valid content & bad regex'
do
subject
{
build
.
extract_coverage
(
'Coverage 1033 / 1051 LOC (98.29%) covered'
,
'very covered'
)
}
it
{
should
be_nil
}
it
{
is_expected
.
to
be_nil
}
end
context
'no coverage content & regex'
do
subject
{
build
.
extract_coverage
(
'No coverage for today :sad:'
,
'\(\d+.\d+\%\) covered'
)
}
it
{
should
be_nil
}
it
{
is_expected
.
to
be_nil
}
end
context
'multiple results in content & regex'
do
subject
{
build
.
extract_coverage
(
' (98.39%) covered. (98.29%) covered'
,
'\(\d+.\d+\%\) covered'
)
}
it
{
should
eq
(
98.29
)
}
it
{
is_expected
.
to
eq
(
98.29
)
}
end
end
...
...
@@ -314,7 +314,7 @@ describe Ci::Build do
]
}
it
{
should
eq
(
variables
)
}
it
{
is_expected
.
to
eq
(
variables
)
}
context
'and secure variables'
do
let
(
:secure_variables
)
{
...
...
@@ -327,7 +327,7 @@ describe Ci::Build do
build
.
project
.
variables
<<
Ci
::
Variable
.
new
(
key:
'SECRET_KEY'
,
value:
'secret_value'
)
end
it
{
should
eq
(
variables
+
secure_variables
)
}
it
{
is_expected
.
to
eq
(
variables
+
secure_variables
)
}
context
'and trigger variables'
do
let
(
:trigger
)
{
FactoryGirl
.
create
:ci_trigger
,
project:
project
}
...
...
@@ -342,7 +342,7 @@ describe Ci::Build do
build
.
trigger_request
=
trigger_request
end
it
{
should
eq
(
variables
+
secure_variables
+
trigger_variables
)
}
it
{
is_expected
.
to
eq
(
variables
+
secure_variables
+
trigger_variables
)
}
end
end
end
...
...
spec/models/ci/commit_spec.rb
View file @
59c3a323
...
...
@@ -21,18 +21,18 @@ describe Ci::Commit do
let
(
:project
)
{
FactoryGirl
.
create
:ci_project
}
let
(
:commit
)
{
FactoryGirl
.
create
:ci_commit
,
project:
project
}
let
(
:commit_with_project
)
{
FactoryGirl
.
create
:ci_commit
,
project:
project
}
let
(
:config_processor
)
{
GitlabCiYamlProcessor
.
new
(
gitlab_ci_yaml
)
}
let
(
:config_processor
)
{
Ci
::
GitlabCiYamlProcessor
.
new
(
gitlab_ci_yaml
)
}
it
{
should
belong_to
(
:project
)
}
it
{
should
have_many
(
:builds
)
}
it
{
should
validate_presence_of
:before_sha
}
it
{
should
validate_presence_of
:sha
}
it
{
should
validate_presence_of
:ref
}
it
{
should
validate_presence_of
:push_data
}
it
{
is_expected
.
to
belong_to
(
: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
}
it
{
is_expected
.
to
validate_presence_of
:ref
}
it
{
is_expected
.
to
validate_presence_of
:push_data
}
it
{
should
respond_to
:git_author_name
}
it
{
should
respond_to
:git_author_email
}
it
{
should
respond_to
:short_sha
}
it
{
is_expected
.
to
respond_to
:git_author_name
}
it
{
is_expected
.
to
respond_to
:git_author_email
}
it
{
is_expected
.
to
respond_to
:short_sha
}
describe
:last_build
do
subject
{
commit
.
last_build
}
...
...
@@ -41,8 +41,8 @@ describe Ci::Commit do
@second
=
FactoryGirl
.
create
:ci_build
,
commit:
commit
end
it
{
should
be_a
(
Ci
::
Build
)
}
it
(
'returns with the most recently created build'
)
{
should
eq
(
@second
)
}
it
{
is_expected
.
to
be_a
(
Ci
::
Build
)
}
it
(
'returns with the most recently created build'
)
{
is_expected
.
to
eq
(
@second
)
}
end
describe
:retry
do
...
...
@@ -67,8 +67,8 @@ describe Ci::Commit do
email_recipients:
''
commit
=
FactoryGirl
.
create
:ci_commit
,
project:
project
expected
=
'commit_pusher_email'
commit
.
stub
(
:push_data
)
{
{
user_email:
expected
}
}
commit
.
project_recipients
.
should
==
[
expected
]
allow
(
commit
).
to
receive
(
:push_data
)
{
{
user_email:
expected
}
}
expect
(
commit
.
project_recipients
).
to
eq
([
expected
])
end
it
'should return commit_pusher_email and additional recipients'
do
...
...
@@ -77,8 +77,8 @@ describe Ci::Commit do
email_recipients:
'rec1 rec2'
commit
=
FactoryGirl
.
create
:ci_commit
,
project:
project
expected
=
'commit_pusher_email'
commit
.
stub
(
:push_data
)
{
{
user_email:
expected
}
}
commit
.
project_recipients
.
should
==
[
'rec1'
,
'rec2'
,
expected
]
allow
(
commit
).
to
receive
(
:push_data
)
{
{
user_email:
expected
}
}
expect
(
commit
.
project_recipients
).
to
eq
([
'rec1'
,
'rec2'
,
expected
])
end
it
'should return recipients'
do
...
...
@@ -86,7 +86,7 @@ describe Ci::Commit do
email_add_pusher:
false
,
email_recipients:
'rec1 rec2'
commit
=
FactoryGirl
.
create
:ci_commit
,
project:
project
commit
.
project_recipients
.
should
==
[
'rec1'
,
'rec2'
]
expect
(
commit
.
project_recipients
).
to
eq
([
'rec1'
,
'rec2'
])
end
it
'should return unique recipients only'
do
...
...
@@ -95,8 +95,8 @@ describe Ci::Commit do
email_recipients:
'rec1 rec1 rec2'
commit
=
FactoryGirl
.
create
:ci_commit
,
project:
project
expected
=
'rec2'
commit
.
stub
(
:push_data
)
{
{
user_email:
expected
}
}
commit
.
project_recipients
.
should
==
[
'rec1'
,
'rec2'
]
allow
(
commit
).
to
receive
(
:push_data
)
{
{
user_email:
expected
}
}
expect
(
commit
.
project_recipients
).
to
eq
([
'rec1'
,
'rec2'
])
end
end
end
...
...
@@ -108,7 +108,7 @@ describe Ci::Commit do
commit
.
valid_commit_sha
end
it
(
'commit errors should not be empty'
)
{
commit
.
errors
.
should_not
be_empty
}
it
(
'commit errors should not be empty'
)
{
expect
(
commit
.
errors
).
not_to
be_empty
}
end
end
...
...
@@ -116,55 +116,59 @@ describe Ci::Commit do
subject
{
commit_with_project
.
compare?
}
context
'if commit.before_sha are not nil'
do
it
{
should
be_true
}
it
{
is_expected
.
to
be_truthy
}
end
end
describe
:short_sha
do
subject
{
commit
.
short_before_sha
}
it
{
should
have
(
8
).
items
}
it
{
commit
.
before_sha
.
should
start_with
(
subject
)
}
it
'has 8 items'
do
expect
(
subject
.
size
).
to
eq
(
8
)
end
it
{
expect
(
commit
.
before_sha
).
to
start_with
(
subject
)
}
end
describe
:short_sha
do
subject
{
commit
.
short_sha
}
it
{
should
have
(
8
).
items
}
it
{
commit
.
sha
.
should
start_with
(
subject
)
}
it
'has 8 items'
do
expect
(
subject
.
size
).
to
eq
(
8
)
end
it
{
expect
(
commit
.
sha
).
to
start_with
(
subject
)
}
end
describe
:create_next_builds
do
before
do
commit
.
stub
(
:config_processor
).
and_return
(
config_processor
)
allow
(
commit
).
to
receive
(
:config_processor
).
and_return
(
config_processor
)
end
it
"creates builds for next type"
do
commit
.
create_builds
.
should
be_true
expect
(
commit
.
create_builds
).
to
be_truthy
commit
.
builds
.
reload
commit
.
builds
.
size
.
should
==
2
expect
(
commit
.
builds
.
size
).
to
eq
(
2
)
commit
.
create_next_builds
(
nil
).
should
be_true
expect
(
commit
.
create_next_builds
(
nil
)).
to
be_truthy
commit
.
builds
.
reload
commit
.
builds
.
size
.
should
==
4
expect
(
commit
.
builds
.
size
).
to
eq
(
4
)
commit
.
create_next_builds
(
nil
).
should
be_true
expect
(
commit
.
create_next_builds
(
nil
)).
to
be_truthy
commit
.
builds
.
reload
commit
.
builds
.
size
.
should
==
5
expect
(
commit
.
builds
.
size
).
to
eq
(
5
)
commit
.
create_next_builds
(
nil
).
should
be_false
expect
(
commit
.
create_next_builds
(
nil
)).
to
be_falsey
end
end
describe
:create_builds
do
before
do
commit
.
stub
(
:config_processor
).
and_return
(
config_processor
)
allow
(
commit
).
to
receive
(
:config_processor
).
and_return
(
config_processor
)
end
it
'creates builds'
do
commit
.
create_builds
.
should
be_true
expect
(
commit
.
create_builds
).
to
be_truthy
commit
.
builds
.
reload
commit
.
builds
.
size
.
should
==
2
expect
(
commit
.
builds
.
size
).
to
eq
(
2
)
end
context
'for build triggers'
do
...
...
@@ -172,29 +176,29 @@ describe Ci::Commit do
let
(
:trigger_request
)
{
FactoryGirl
.
create
:ci_trigger_request
,
commit:
commit
,
trigger:
trigger
}
it
'creates builds'
do
commit
.
create_builds
(
trigger_request
).
should
be_true
expect
(
commit
.
create_builds
(
trigger_request
)).
to
be_truthy
commit
.
builds
.
reload
commit
.
builds
.
size
.
should
==
2
expect
(
commit
.
builds
.
size
).
to
eq
(
2
)
end
it
'rebuilds commit'
do
commit
.
create_builds
.
should
be_true
expect
(
commit
.
create_builds
).
to
be_truthy
commit
.
builds
.
reload
commit
.
builds
.
size
.
should
==
2
expect
(
commit
.
builds
.
size
).
to
eq
(
2
)
commit
.
create_builds
(
trigger_request
).
should
be_true
expect
(
commit
.
create_builds
(
trigger_request
)).
to
be_truthy
commit
.
builds
.
reload
commit
.
builds
.
size
.
should
==
4
expect
(
commit
.
builds
.
size
).
to
eq
(
4
)
end
it
'creates next builds'
do
commit
.
create_builds
(
trigger_request
).
should
be_true
expect
(
commit
.
create_builds
(
trigger_request
)).
to
be_truthy
commit
.
builds
.
reload
commit
.
builds
.
size
.
should
==
2
expect
(
commit
.
builds
.
size
).
to
eq
(
2
)
commit
.
create_next_builds
(
trigger_request
).
should
be_true
expect
(
commit
.
create_next_builds
(
trigger_request
)).
to
be_truthy
commit
.
builds
.
reload
commit
.
builds
.
size
.
should
==
4
expect
(
commit
.
builds
.
size
).
to
eq
(
4
)
end
context
'for [ci skip]'
do
...
...
@@ -204,11 +208,11 @@ describe Ci::Commit do
end
it
'rebuilds commit'
do
commit
.
status
.
should
==
'skipped'
commit
.
create_builds
(
trigger_request
).
should
be_true
expect
(
commit
.
status
).
to
eq
(
'skipped'
)
expect
(
commit
.
create_builds
(
trigger_request
)).
to
be_truthy
commit
.
builds
.
reload
commit
.
builds
.
size
.
should
==
2
commit
.
status
.
should
==
'pending'
expect
(
commit
.
builds
.
size
).
to
eq
(
2
)
expect
(
commit
.
status
).
to
eq
(
'pending'
)
end
end
end
...
...
@@ -222,13 +226,13 @@ describe Ci::Commit do
build
=
FactoryGirl
.
create
:ci_build
,
commit:
commit
,
finished_at:
Time
.
now
-
60
build1
=
FactoryGirl
.
create
:ci_build
,
commit:
commit
,
finished_at:
Time
.
now
-
120
commit
.
finished_at
.
to_i
.
should
==
build
.
finished_at
.
to_i
expect
(
commit
.
finished_at
.
to_i
).
to
eq
(
build
.
finished_at
.
to_i
)
end
it
"returns nil if there is no finished build"
do
build
=
FactoryGirl
.
create
:ci_not_started_build
,
commit:
commit
commit
.
finished_at
.
should
be_nil
expect
(
commit
.
finished_at
).
to
be_nil
end
end
...
...
@@ -239,26 +243,26 @@ describe Ci::Commit do
it
"calculates average when there are two builds with coverage"
do
FactoryGirl
.
create
:ci_build
,
name:
"rspec"
,
coverage:
30
,
commit:
commit
FactoryGirl
.
create
:ci_build
,
name:
"rubocop"
,
coverage:
40
,
commit:
commit
commit
.
coverage
.
should
==
"35.00"
expect
(
commit
.
coverage
).
to
eq
(
"35.00"
)
end
it
"calculates average when there are two builds with coverage and one with nil"
do
FactoryGirl
.
create
:ci_build
,
name:
"rspec"
,
coverage:
30
,
commit:
commit
FactoryGirl
.
create
:ci_build
,
name:
"rubocop"
,
coverage:
40
,
commit:
commit
FactoryGirl
.
create
:ci_build
,
commit:
commit
commit
.
coverage
.
should
==
"35.00"
expect
(
commit
.
coverage
).
to
eq
(
"35.00"
)
end
it
"calculates average when there are two builds with coverage and one is retried"
do
FactoryGirl
.
create
:ci_build
,
name:
"rspec"
,
coverage:
30
,
commit:
commit
FactoryGirl
.
create
:ci_build
,
name:
"rubocop"
,
coverage:
30
,
commit:
commit
FactoryGirl
.
create
:ci_build
,
name:
"rubocop"
,
coverage:
40
,
commit:
commit
commit
.
coverage
.
should
==
"35.00"
expect
(
commit
.
coverage
).
to
eq
(
"35.00"
)
end
it
"calculates average when there is one build without coverage"
do
FactoryGirl
.
create
:ci_build
,
commit:
commit
commit
.
coverage
.
should
be_nil
expect
(
commit
.
coverage
).
to
be_nil
end
end
end
spec/models/ci/mail_service_spec.rb
View file @
59c3a323
...
...
@@ -16,7 +16,7 @@ require 'spec_helper'
describe
Ci
::
MailService
do
describe
"Associations"
do
it
{
should
belong_to
:project
}
it
{
is_expected
.
to
belong_to
:project
}
end
describe
"Validations"
do
...
...
@@ -36,7 +36,7 @@ describe Ci::MailService do
let
(
:build
)
{
FactoryGirl
.
create
(
:ci_build
,
status: :failed
,
commit:
commit
)
}
before
do
mail
.
stub
(
allow
(
mail
).
to
receive_messages
(
project:
project
)
end
...
...
@@ -47,8 +47,8 @@ describe Ci::MailService do
end
def
should_email
(
email
)
Notify
.
should_
receive
(
:build_fail_email
).
with
(
build
.
id
,
email
)
Notify
.
should_not_
receive
(
:build_success_email
).
with
(
build
.
id
,
email
)
expect
(
Notify
).
to
receive
(
:build_fail_email
).
with
(
build
.
id
,
email
)
expect
(
Notify
).
not_to
receive
(
:build_success_email
).
with
(
build
.
id
,
email
)
end
end
...
...
@@ -58,7 +58,7 @@ describe Ci::MailService do
let
(
:build
)
{
FactoryGirl
.
create
(
:ci_build
,
status: :success
,
commit:
commit
)
}
before
do
mail
.
stub
(
allow
(
mail
).
to
receive_messages
(
project:
project
)
end
...
...
@@ -69,8 +69,8 @@ describe Ci::MailService do
end
def
should_email
(
email
)
Notify
.
should_
receive
(
:build_success_email
).
with
(
build
.
id
,
email
)
Notify
.
should_not_
receive
(
:build_fail_email
).
with
(
build
.
id
,
email
)
expect
(
Notify
).
to
receive
(
:build_success_email
).
with
(
build
.
id
,
email
)
expect
(
Notify
).
not_to
receive
(
:build_fail_email
).
with
(
build
.
id
,
email
)
end
end
...
...
@@ -85,7 +85,7 @@ describe Ci::MailService do
let
(
:build
)
{
FactoryGirl
.
create
(
:ci_build
,
status: :success
,
commit:
commit
)
}
before
do
mail
.
stub
(
allow
(
mail
).
to
receive_messages
(
project:
project
)
end
...
...
@@ -97,8 +97,8 @@ describe Ci::MailService do
end
def
should_email
(
email
)
Notify
.
should_
receive
(
:build_success_email
).
with
(
build
.
id
,
email
)
Notify
.
should_not_
receive
(
:build_fail_email
).
with
(
build
.
id
,
email
)
expect
(
Notify
).
to
receive
(
:build_success_email
).
with
(
build
.
id
,
email
)
expect
(
Notify
).
not_to
receive
(
:build_fail_email
).
with
(
build
.
id
,
email
)
end
end
...
...
@@ -113,7 +113,7 @@ describe Ci::MailService do
let
(
:build
)
{
FactoryGirl
.
create
(
:ci_build
,
status: :success
,
commit:
commit
)
}
before
do
mail
.
stub
(
allow
(
mail
).
to
receive_messages
(
project:
project
)
end
...
...
@@ -125,8 +125,8 @@ describe Ci::MailService do
end
def
should_email
(
email
)
Notify
.
should_not_
receive
(
:build_success_email
).
with
(
build
.
id
,
email
)
Notify
.
should_not_
receive
(
:build_fail_email
).
with
(
build
.
id
,
email
)
expect
(
Notify
).
not_to
receive
(
:build_success_email
).
with
(
build
.
id
,
email
)
expect
(
Notify
).
not_to
receive
(
:build_fail_email
).
with
(
build
.
id
,
email
)
end
end
...
...
@@ -141,14 +141,14 @@ describe Ci::MailService do
let
(
:build
)
{
FactoryGirl
.
create
(
:ci_build
,
status: :success
,
commit:
commit
)
}
before
do
mail
.
stub
(
allow
(
mail
).
to
receive_messages
(
project:
project
)
build
end
it
do
mail
.
can_test?
.
should
==
true
expect
(
mail
.
can_test?
).
to
eq
(
true
)
end
end
...
...
@@ -163,7 +163,7 @@ describe Ci::MailService do
let
(
:build
)
{
FactoryGirl
.
create
(
:ci_build
,
status: :failed
,
commit:
commit
)
}
before
do
mail
.
stub
(
allow
(
mail
).
to
receive_messages
(
project:
project
)
end
...
...
@@ -176,8 +176,8 @@ describe Ci::MailService do
end
def
should_email
(
email
)
Notify
.
should_not_
receive
(
:build_success_email
).
with
(
build
.
id
,
email
)
Notify
.
should_not_
receive
(
:build_fail_email
).
with
(
build
.
id
,
email
)
expect
(
Notify
).
not_to
receive
(
:build_success_email
).
with
(
build
.
id
,
email
)
expect
(
Notify
).
not_to
receive
(
:build_fail_email
).
with
(
build
.
id
,
email
)
end
end
end
...
...
spec/models/ci/network_spec.rb
View file @
59c3a323
...
...
@@ -9,21 +9,21 @@ describe Network do
context
'on success'
do
before
do
response
=
double
response
.
stub
(
:code
)
{
200
}
network
.
class
.
stub
(
:put
)
{
response
}
allow
(
response
).
to
receive
(
:code
)
{
200
}
allow
(
network
.
class
).
to
receive
(
:put
)
{
response
}
end
it
{
should
be_true
}
it
{
is_expected
.
to
be_truthy
}
end
context
'on failure'
do
before
do
response
=
double
response
.
stub
(
:code
)
{
404
}
network
.
class
.
stub
(
:put
)
{
response
}
allow
(
response
).
to
receive
(
:code
)
{
404
}
allow
(
network
.
class
).
to
receive
(
:put
)
{
response
}
end
it
{
should
be_nil
}
it
{
is_expected
.
to
be_nil
}
end
end
...
...
@@ -34,21 +34,21 @@ describe Network do
context
'on success'
do
let
(
:parsed_response
)
{
'parsed'
}
before
do
response
.
stub
(
:code
)
{
200
}
response
.
stub
(
:parsed_response
)
{
parsed_response
}
network
.
class
.
stub
(
:delete
)
{
response
}
allow
(
response
).
to
receive
(
:code
)
{
200
}
allow
(
response
).
to
receive
(
:parsed_response
)
{
parsed_response
}
allow
(
network
.
class
).
to
receive
(
:delete
)
{
response
}
end
it
{
should
equal
(
parsed_response
)
}
it
{
is_expected
.
to
equal
(
parsed_response
)
}
end
context
'on failure'
do
before
do
response
.
stub
(
:code
)
{
404
}
network
.
class
.
stub
(
:delete
)
{
response
}
allow
(
response
).
to
receive
(
:code
)
{
404
}
allow
(
network
.
class
).
to
receive
(
:delete
)
{
response
}
end
it
{
should
be_nil
}
it
{
is_expected
.
to
be_nil
}
end
end
end
spec/models/ci/project_services/hip_chat_message_spec.rb
View file @
59c3a323
...
...
@@ -18,7 +18,7 @@ describe Ci::HipChatMessage do
build
.
update
(
status:
"success"
)
expect
(
subject
.
status_color
).
to
eq
'green'
expect
(
subject
.
notify?
).
to
be_false
expect
(
subject
.
notify?
).
to
be_false
y
expect
(
subject
.
to_s
).
to
match
(
/Build '[^']+' #\d+/
)
expect
(
subject
.
to_s
).
to
match
(
/Successful in \d+ second\(s\)\./
)
end
...
...
@@ -29,7 +29,7 @@ describe Ci::HipChatMessage do
build
.
update
(
status:
"failed"
)
expect
(
subject
.
status_color
).
to
eq
'red'
expect
(
subject
.
notify?
).
to
be_tru
e
expect
(
subject
.
notify?
).
to
be_tru
thy
expect
(
subject
.
to_s
).
to
match
(
/Build '[^']+' #\d+/
)
expect
(
subject
.
to_s
).
to
match
(
/Failed in \d+ second\(s\)\./
)
end
...
...
@@ -50,7 +50,7 @@ describe Ci::HipChatMessage do
commit
.
reload
expect
(
subject
.
status_color
).
to
eq
'green'
expect
(
subject
.
notify?
).
to
be_false
expect
(
subject
.
notify?
).
to
be_false
y
expect
(
subject
.
to_s
).
to
match
(
/Commit #\d+/
)
expect
(
subject
.
to_s
).
to
match
(
/Successful in \d+ second\(s\)\./
)
end
...
...
@@ -65,7 +65,7 @@ describe Ci::HipChatMessage do
second_build
.
update
(
status:
"failed"
)
expect
(
subject
.
status_color
).
to
eq
'red'
expect
(
subject
.
notify?
).
to
be_tru
e
expect
(
subject
.
notify?
).
to
be_tru
thy
expect
(
subject
.
to_s
).
to
match
(
/Commit #\d+/
)
expect
(
subject
.
to_s
).
to
match
(
/Failed in \d+ second\(s\)\./
)
end
...
...
spec/models/ci/project_services/hip_chat_service_spec.rb
View file @
59c3a323
...
...
@@ -24,8 +24,8 @@ describe Ci::HipChatService do
subject
.
active
=
true
end
it
{
should
validate_presence_of
:hipchat_room
}
it
{
should
validate_presence_of
:hipchat_token
}
it
{
is_expected
.
to
validate_presence_of
:hipchat_room
}
it
{
is_expected
.
to
validate_presence_of
:hipchat_token
}
end
end
...
...
@@ -39,7 +39,7 @@ describe Ci::HipChatService do
let
(
:api_url
)
{
'https://api.hipchat.com/v2/room/123/notification?auth_token=a1b2c3d4e5f6'
}
before
do
service
.
stub
(
allow
(
service
).
to
receive_messages
(
project:
project
,
project_id:
project
.
id
,
notify_only_broken_builds:
false
,
...
...
spec/models/ci/project_services/slack_message_spec.rb
View file @
59c3a323
...
...
@@ -19,11 +19,11 @@ describe Ci::SlackMessage do
it
'returns a message with succeeded build'
do
build
.
update
(
status:
"success"
)
subject
.
color
.
should
==
color
subject
.
fallback
.
should
include
(
'Build'
)
subject
.
fallback
.
should
include
(
"
\#
#{
build
.
id
}
"
)
subject
.
fallback
.
should
include
(
'succeeded'
)
subject
.
attachments
.
first
[
:fields
].
should
be_empty
expect
(
subject
.
color
).
to
eq
(
color
)
expect
(
subject
.
fallback
).
to
include
(
'Build'
)
expect
(
subject
.
fallback
).
to
include
(
"
\#
#{
build
.
id
}
"
)
expect
(
subject
.
fallback
).
to
include
(
'succeeded'
)
expect
(
subject
.
attachments
.
first
[
:fields
]).
to
be_empty
end
end
...
...
@@ -33,11 +33,11 @@ describe Ci::SlackMessage do
it
'returns a message with failed build'
do
build
.
update
(
status:
"failed"
)
subject
.
color
.
should
==
color
subject
.
fallback
.
should
include
(
'Build'
)
subject
.
fallback
.
should
include
(
"
\#
#{
build
.
id
}
"
)
subject
.
fallback
.
should
include
(
'failed'
)
subject
.
attachments
.
first
[
:fields
].
should
be_empty
expect
(
subject
.
color
).
to
eq
(
color
)
expect
(
subject
.
fallback
).
to
include
(
'Build'
)
expect
(
subject
.
fallback
).
to
include
(
"
\#
#{
build
.
id
}
"
)
expect
(
subject
.
fallback
).
to
include
(
'failed'
)
expect
(
subject
.
attachments
.
first
[
:fields
]).
to
be_empty
end
end
end
...
...
@@ -53,11 +53,11 @@ describe Ci::SlackMessage do
commit
.
builds
.
update_all
(
status:
"success"
)
commit
.
reload
subject
.
color
.
should
==
color
subject
.
fallback
.
should
include
(
'Commit'
)
subject
.
fallback
.
should
include
(
"
\#
#{
commit
.
id
}
"
)
subject
.
fallback
.
should
include
(
'succeeded'
)
subject
.
attachments
.
first
[
:fields
].
should
be_empty
expect
(
subject
.
color
).
to
eq
(
color
)
expect
(
subject
.
fallback
).
to
include
(
'Commit'
)
expect
(
subject
.
fallback
).
to
include
(
"
\#
#{
commit
.
id
}
"
)
expect
(
subject
.
fallback
).
to
include
(
'succeeded'
)
expect
(
subject
.
attachments
.
first
[
:fields
]).
to
be_empty
end
end
...
...
@@ -71,13 +71,13 @@ describe Ci::SlackMessage do
first_build
.
update
(
status:
"success"
)
second_build
.
update
(
status:
"failed"
)
subject
.
color
.
should
==
color
subject
.
fallback
.
should
include
(
'Commit'
)
subject
.
fallback
.
should
include
(
"
\#
#{
commit
.
id
}
"
)
subject
.
fallback
.
should
include
(
'failed'
)
subject
.
attachments
.
first
[
:fields
].
size
.
should
==
1
subject
.
attachments
.
first
[
:fields
].
first
[
:title
].
should
==
second_build
.
name
subject
.
attachments
.
first
[
:fields
].
first
[
:value
].
should
include
(
"
\#
#{
second_build
.
id
}
"
)
expect
(
subject
.
color
).
to
eq
(
color
)
expect
(
subject
.
fallback
).
to
include
(
'Commit'
)
expect
(
subject
.
fallback
).
to
include
(
"
\#
#{
commit
.
id
}
"
)
expect
(
subject
.
fallback
).
to
include
(
'failed'
)
expect
(
subject
.
attachments
.
first
[
:fields
].
size
).
to
eq
(
1
)
expect
(
subject
.
attachments
.
first
[
:fields
].
first
[
:title
]).
to
eq
(
second_build
.
name
)
expect
(
subject
.
attachments
.
first
[
:fields
].
first
[
:value
]).
to
include
(
"
\#
#{
second_build
.
id
}
"
)
end
end
end
...
...
spec/models/ci/project_services/slack_service_spec.rb
View file @
59c3a323
...
...
@@ -16,7 +16,7 @@ require 'spec_helper'
describe
Ci
::
SlackService
do
describe
"Associations"
do
it
{
should
belong_to
:project
}
it
{
is_expected
.
to
belong_to
:project
}
end
describe
"Validations"
do
...
...
@@ -25,7 +25,7 @@ describe Ci::SlackService do
subject
.
active
=
true
end
it
{
should
validate_presence_of
:webhook
}
it
{
is_expected
.
to
validate_presence_of
:webhook
}
end
end
...
...
@@ -38,7 +38,7 @@ describe Ci::SlackService do
let
(
:notify_only_broken_builds
)
{
false
}
before
do
slack
.
stub
(
allow
(
slack
).
to
receive_messages
(
project:
project
,
project_id:
project
.
id
,
webhook:
webhook_url
,
...
...
@@ -52,7 +52,7 @@ describe Ci::SlackService do
slack
.
execute
(
build
)
SlackNotifierWorker
.
drain
WebMock
.
should
have_requested
(
:post
,
webhook_url
).
once
expect
(
WebMock
).
to
have_requested
(
:post
,
webhook_url
).
once
end
end
end
spec/models/ci/project_spec.rb
View file @
59c3a323
...
...
@@ -30,21 +30,21 @@ require 'spec_helper'
describe
Project
do
subject
{
FactoryGirl
.
build
:ci_project
}
it
{
should
have_many
(
:commits
)
}
it
{
is_expected
.
to
have_many
(
:commits
)
}
it
{
should
validate_presence_of
:name
}
it
{
should
validate_presence_of
:timeout
}
it
{
should
validate_presence_of
:default_ref
}
it
{
is_expected
.
to
validate_presence_of
:name
}
it
{
is_expected
.
to
validate_presence_of
:timeout
}
it
{
is_expected
.
to
validate_presence_of
:default_ref
}
describe
'before_validation'
do
it
'should set an random token if none provided'
do
project
=
FactoryGirl
.
create
:ci_project_without_token
project
.
token
.
should_not
==
""
expect
(
project
.
token
).
not_to
eq
(
""
)
end
it
'should not set an random toke if one provided'
do
project
=
FactoryGirl
.
create
:ci_project
project
.
token
.
should
==
"iPWx6WM4lhHNedGfBpPJNP"
expect
(
project
.
token
).
to
eq
(
"iPWx6WM4lhHNedGfBpPJNP"
)
end
end
...
...
@@ -57,7 +57,7 @@ describe Project do
FactoryGirl
.
create
:ci_commit
,
committed_at:
1
.
hour
.
ago
,
project:
newest_project
FactoryGirl
.
create
:ci_commit
,
committed_at:
2
.
hour
.
ago
,
project:
oldest_project
Project
.
ordered_by_last_commit_date
.
should
==
[
newest_project
,
oldest_project
,
project_without_commits
]
expect
(
Project
.
ordered_by_last_commit_date
).
to
eq
([
newest_project
,
oldest_project
,
project_without_commits
])
end
end
...
...
@@ -70,56 +70,56 @@ describe Project do
FactoryGirl
.
create
(
:ci_build
,
commit:
commit
)
end
it
{
project
.
status
.
should
==
'pending'
}
it
{
project
.
last_commit
.
should
be_kind_of
(
Commit
)
}
it
{
project
.
human_status
.
should
==
'pending'
}
it
{
expect
(
project
.
status
).
to
eq
(
'pending'
)
}
it
{
expect
(
project
.
last_commit
).
to
be_kind_of
(
Commit
)
}
it
{
expect
(
project
.
human_status
).
to
eq
(
'pending'
)
}
end
end
describe
'#email_notification?'
do
it
do
project
=
FactoryGirl
.
create
:ci_project
,
email_add_pusher:
true
project
.
email_notification?
.
should
==
true
expect
(
project
.
email_notification?
).
to
eq
(
true
)
end
it
do
project
=
FactoryGirl
.
create
:ci_project
,
email_add_pusher:
false
,
email_recipients:
'test tesft'
project
.
email_notification?
.
should
==
true
expect
(
project
.
email_notification?
).
to
eq
(
true
)
end
it
do
project
=
FactoryGirl
.
create
:ci_project
,
email_add_pusher:
false
,
email_recipients:
''
project
.
email_notification?
.
should
==
false
expect
(
project
.
email_notification?
).
to
eq
(
false
)
end
end
describe
'#broken_or_success?'
do
it
{
project
=
FactoryGirl
.
create
:ci_project
,
email_add_pusher:
true
project
.
stub
(
:broken?
).
and_return
(
true
)
project
.
stub
(
:success?
).
and_return
(
true
)
project
.
broken_or_success?
.
should
==
true
allow
(
project
).
to
receive
(
:broken?
).
and_return
(
true
)
allow
(
project
).
to
receive
(
:success?
).
and_return
(
true
)
expect
(
project
.
broken_or_success?
).
to
eq
(
true
)
}
it
{
project
=
FactoryGirl
.
create
:ci_project
,
email_add_pusher:
true
project
.
stub
(
:broken?
).
and_return
(
true
)
project
.
stub
(
:success?
).
and_return
(
false
)
project
.
broken_or_success?
.
should
==
true
allow
(
project
).
to
receive
(
:broken?
).
and_return
(
true
)
allow
(
project
).
to
receive
(
:success?
).
and_return
(
false
)
expect
(
project
.
broken_or_success?
).
to
eq
(
true
)
}
it
{
project
=
FactoryGirl
.
create
:ci_project
,
email_add_pusher:
true
project
.
stub
(
:broken?
).
and_return
(
false
)
project
.
stub
(
:success?
).
and_return
(
true
)
project
.
broken_or_success?
.
should
==
true
allow
(
project
).
to
receive
(
:broken?
).
and_return
(
false
)
allow
(
project
).
to
receive
(
:success?
).
and_return
(
true
)
expect
(
project
.
broken_or_success?
).
to
eq
(
true
)
}
it
{
project
=
FactoryGirl
.
create
:ci_project
,
email_add_pusher:
true
project
.
stub
(
:broken?
).
and_return
(
false
)
project
.
stub
(
:success?
).
and_return
(
false
)
project
.
broken_or_success?
.
should
==
false
allow
(
project
).
to
receive
(
:broken?
).
and_return
(
false
)
allow
(
project
).
to
receive
(
:success?
).
and_return
(
false
)
expect
(
project
.
broken_or_success?
).
to
eq
(
false
)
}
end
...
...
@@ -128,14 +128,14 @@ describe Project do
let
(
:parsed_project
)
{
Project
.
parse
(
project_dump
)
}
it
{
parsed_project
.
should
be_valid
}
it
{
parsed_project
.
should
be_kind_of
(
Project
)
}
it
{
parsed_project
.
name
.
should
eq
(
"GitLab / api.gitlab.org"
)
}
it
{
parsed_project
.
gitlab_id
.
should
eq
(
189
)
}
it
{
parsed_project
.
gitlab_url
.
should
eq
(
"http://demo.gitlab.com/gitlab/api-gitlab-org"
)
}
it
{
expect
(
parsed_project
).
to
be_valid
}
it
{
expect
(
parsed_project
).
to
be_kind_of
(
Project
)
}
it
{
expect
(
parsed_project
.
name
).
to
eq
(
"GitLab / api.gitlab.org"
)
}
it
{
expect
(
parsed_project
.
gitlab_id
).
to
eq
(
189
)
}
it
{
expect
(
parsed_project
.
gitlab_url
).
to
eq
(
"http://demo.gitlab.com/gitlab/api-gitlab-org"
)
}
it
"parses plain hash"
do
Project
.
parse
(
project_dump
).
name
.
should
eq
(
"GitLab / api.gitlab.org"
)
expect
(
Project
.
parse
(
project_dump
).
name
).
to
eq
(
"GitLab / api.gitlab.org"
)
end
end
...
...
@@ -143,43 +143,43 @@ describe Project do
let
(
:project
)
{
FactoryGirl
.
create
:ci_project
}
subject
{
project
.
repo_url_with_auth
}
it
{
should
be_a
(
String
)
}
it
{
should
end_with
(
".git"
)
}
it
{
should
start_with
(
project
.
gitlab_url
[
0
..
6
])
}
it
{
should
include
(
project
.
token
)
}
it
{
should
include
(
'gitlab-ci-token'
)
}
it
{
should
include
(
project
.
gitlab_url
[
7
..-
1
])
}
it
{
is_expected
.
to
be_a
(
String
)
}
it
{
is_expected
.
to
end_with
(
".git"
)
}
it
{
is_expected
.
to
start_with
(
project
.
gitlab_url
[
0
..
6
])
}
it
{
is_expected
.
to
include
(
project
.
token
)
}
it
{
is_expected
.
to
include
(
'gitlab-ci-token'
)
}
it
{
is_expected
.
to
include
(
project
.
gitlab_url
[
7
..-
1
])
}
end
describe
:search
do
let!
(
:project
)
{
FactoryGirl
.
create
(
:ci_project
,
name:
"foo"
)
}
it
{
Project
.
search
(
'fo'
).
should
include
(
project
)
}
it
{
Project
.
search
(
'bar'
).
should
be_empty
}
it
{
expect
(
Project
.
search
(
'fo'
)).
to
include
(
project
)
}
it
{
expect
(
Project
.
search
(
'bar'
)).
to
be_empty
}
end
describe
:any_runners
do
it
"there are no runners available"
do
project
=
FactoryGirl
.
create
(
:ci_project
)
project
.
any_runners?
.
should
be_false
expect
(
project
.
any_runners?
).
to
be_falsey
end
it
"there is a specific runner"
do
project
=
FactoryGirl
.
create
(
:ci_project
)
project
.
runners
<<
FactoryGirl
.
create
(
:ci_specific_runner
)
project
.
any_runners?
.
should
be_true
expect
(
project
.
any_runners?
).
to
be_truthy
end
it
"there is a shared runner"
do
project
=
FactoryGirl
.
create
(
:ci_project
,
shared_runners_enabled:
true
)
FactoryGirl
.
create
(
:ci_shared_runner
)
project
.
any_runners?
.
should
be_true
expect
(
project
.
any_runners?
).
to
be_truthy
end
it
"there is a shared runner, but they are prohibited to use"
do
project
=
FactoryGirl
.
create
(
:ci_project
)
FactoryGirl
.
create
(
:ci_shared_runner
)
project
.
any_runners?
.
should
be_false
expect
(
project
.
any_runners?
).
to
be_falsey
end
end
end
spec/models/ci/runner_spec.rb
View file @
59c3a323
...
...
@@ -43,9 +43,9 @@ describe Ci::Runner do
before
{
shared_runner
.
assign_to
(
project
)
}
it
{
shared_runner
.
should
be_specific
}
it
{
shared_runner
.
projects
.
should
==
[
project
]
}
it
{
shared_runner
.
only_for?
(
project
).
should
be_true
}
it
{
expect
(
shared_runner
).
to
be_specific
}
it
{
expect
(
shared_runner
.
projects
).
to
eq
([
project
])
}
it
{
expect
(
shared_runner
.
only_for?
(
project
)).
to
be_truthy
}
end
describe
"belongs_to_one_project?"
do
...
...
@@ -56,7 +56,7 @@ describe Ci::Runner do
project
.
runners
<<
runner
project1
.
runners
<<
runner
runner
.
belongs_to_one_project?
.
should
be_false
expect
(
runner
.
belongs_to_one_project?
).
to
be_falsey
end
it
"returns true"
do
...
...
@@ -64,7 +64,7 @@ describe Ci::Runner do
project
=
FactoryGirl
.
create
(
:ci_project
)
project
.
runners
<<
runner
runner
.
belongs_to_one_project?
.
should
be_true
expect
(
runner
.
belongs_to_one_project?
).
to
be_truthy
end
end
end
spec/models/ci/service_spec.rb
View file @
59c3a323
...
...
@@ -17,7 +17,7 @@ require 'spec_helper'
describe
Ci
::
Service
do
describe
"Associations"
do
it
{
should
belong_to
:project
}
it
{
is_expected
.
to
belong_to
:project
}
end
describe
"Mass assignment"
do
...
...
@@ -34,7 +34,7 @@ describe Ci::Service do
let
(
:build
)
{
FactoryGirl
.
create
:ci_build
,
commit:
commit
}
before
do
@service
.
stub
(
allow
(
@service
).
to
receive_messages
(
project:
project
)
build
...
...
@@ -42,7 +42,7 @@ describe Ci::Service do
end
describe
:can_test
do
it
{
@testable
.
should
==
true
}
it
{
expect
(
@testable
).
to
eq
(
true
)
}
end
end
end
...
...
spec/models/ci/trigger_spec.rb
View file @
59c3a323
...
...
@@ -6,12 +6,12 @@ describe Ci::Trigger do
describe
'before_validation'
do
it
'should set an random token if none provided'
do
trigger
=
FactoryGirl
.
create
:ci_trigger_without_token
,
project:
project
trigger
.
token
.
should_not
be_nil
expect
(
trigger
.
token
).
not_to
be_nil
end
it
'should not set an random token if one provided'
do
trigger
=
FactoryGirl
.
create
:ci_trigger
,
project:
project
trigger
.
token
.
should
==
'token'
expect
(
trigger
.
token
).
to
eq
(
'token'
)
end
end
end
spec/models/ci/user_spec.rb
View file @
59c3a323
...
...
@@ -10,19 +10,19 @@ describe Ci::User do
FactoryGirl
.
create
:ci_project
,
gitlab_id:
2
gitlab_project
=
OpenStruct
.
new
({
id:
1
})
gitlab_project1
=
OpenStruct
.
new
({
id:
2
})
User
.
any_instance
.
stub
(
:gitlab_projects
).
and_return
([
gitlab_project
,
gitlab_project1
])
allow_any_instance_of
(
User
).
to
receive
(
:gitlab_projects
).
and_return
([
gitlab_project
,
gitlab_project1
])
end
it
"returns projects"
do
User
.
any_instance
.
stub
(
:can_manage_project?
).
and_return
(
true
)
allow_any_instance_of
(
User
).
to
receive
(
:can_manage_project?
).
and_return
(
true
)
user
.
authorized_projects
.
count
.
should
==
2
expect
(
user
.
authorized_projects
.
count
).
to
eq
(
2
)
end
it
"empty list if user miss manage permission"
do
User
.
any_instance
.
stub
(
:can_manage_project?
).
and_return
(
false
)
allow_any_instance_of
(
User
).
to
receive
(
:can_manage_project?
).
and_return
(
false
)
user
.
authorized_projects
.
count
.
should
==
0
expect
(
user
.
authorized_projects
.
count
).
to
eq
(
0
)
end
end
...
...
@@ -32,8 +32,8 @@ describe Ci::User do
project1
=
FactoryGirl
.
create
:ci_project
,
gitlab_id:
2
gitlab_project
=
OpenStruct
.
new
({
id:
1
})
gitlab_project1
=
OpenStruct
.
new
({
id:
2
})
User
.
any_instance
.
stub
(
:gitlab_projects
).
and_return
([
gitlab_project
,
gitlab_project1
])
User
.
any_instance
.
stub
(
:can_manage_project?
).
and_return
(
true
)
allow_any_instance_of
(
User
).
to
receive
(
:gitlab_projects
).
and_return
([
gitlab_project
,
gitlab_project1
])
allow_any_instance_of
(
User
).
to
receive
(
:can_manage_project?
).
and_return
(
true
)
user
=
User
.
new
({})
runner
=
FactoryGirl
.
create
:ci_specific_runner
...
...
@@ -43,8 +43,8 @@ describe Ci::User do
project
.
runners
<<
runner
project1
.
runners
<<
runner1
user
.
authorized_runners
.
should
include
(
runner
,
runner1
)
user
.
authorized_runners
.
should_not
include
(
runner2
)
expect
(
user
.
authorized_runners
).
to
include
(
runner
,
runner1
)
expect
(
user
.
authorized_runners
).
not_to
include
(
runner2
)
end
end
end
spec/models/ci/variable_spec.rb
View file @
59c3a323
...
...
@@ -14,7 +14,7 @@
require
'spec_helper'
describe
Ci
::
Variable
do
subject
{
Variable
.
new
}
subject
{
Ci
::
Variable
.
new
}
let
(
:secret_value
)
{
'secret'
}
...
...
@@ -24,15 +24,15 @@ describe Ci::Variable do
describe
:value
do
it
'stores the encrypted value'
do
subject
.
encrypted_value
.
should_not
be_nil
expect
(
subject
.
encrypted_value
).
not_to
be_nil
end
it
'stores an iv for value'
do
subject
.
encrypted_value_iv
.
should_not
be_nil
expect
(
subject
.
encrypted_value_iv
).
not_to
be_nil
end
it
'stores a salt for value'
do
subject
.
encrypted_value_salt
.
should_not
be_nil
expect
(
subject
.
encrypted_value_salt
).
not_to
be_nil
end
it
'fails to decrypt if iv is incorrect'
do
...
...
spec/models/ci/web_hook_spec.rb
View file @
59c3a323
...
...
@@ -13,22 +13,22 @@ require 'spec_helper'
describe
Ci
::
WebHook
do
describe
"Associations"
do
it
{
should
belong_to
:project
}
it
{
is_expected
.
to
belong_to
:project
}
end
describe
"Validations"
do
it
{
should
validate_presence_of
(
:url
)
}
it
{
is_expected
.
to
validate_presence_of
(
:url
)
}
context
"url format"
do
it
{
should
allow_value
(
"http://example.com"
).
for
(
:url
)
}
it
{
should
allow_value
(
"https://excample.com"
).
for
(
:url
)
}
it
{
should
allow_value
(
"http://test.com/api"
).
for
(
:url
)
}
it
{
should
allow_value
(
"http://test.com/api?key=abc"
).
for
(
:url
)
}
it
{
should
allow_value
(
"http://test.com/api?key=abc&type=def"
).
for
(
:url
)
}
it
{
is_expected
.
to
allow_value
(
"http://example.com"
).
for
(
:url
)
}
it
{
is_expected
.
to
allow_value
(
"https://excample.com"
).
for
(
:url
)
}
it
{
is_expected
.
to
allow_value
(
"http://test.com/api"
).
for
(
:url
)
}
it
{
is_expected
.
to
allow_value
(
"http://test.com/api?key=abc"
).
for
(
:url
)
}
it
{
is_expected
.
to
allow_value
(
"http://test.com/api?key=abc&type=def"
).
for
(
:url
)
}
it
{
should_not
allow_value
(
"example.com"
).
for
(
:url
)
}
it
{
should_not
allow_value
(
"ftp://example.com"
).
for
(
:url
)
}
it
{
should_not
allow_value
(
"herp-and-derp"
).
for
(
:url
)
}
it
{
is_expected
.
not_to
allow_value
(
"example.com"
).
for
(
:url
)
}
it
{
is_expected
.
not_to
allow_value
(
"ftp://example.com"
).
for
(
:url
)
}
it
{
is_expected
.
not_to
allow_value
(
"herp-and-derp"
).
for
(
:url
)
}
end
end
...
...
@@ -43,22 +43,22 @@ describe Ci::WebHook do
it
"POSTs to the web hook URL"
do
@web_hook
.
execute
(
@data
)
WebMock
.
should
have_requested
(
:post
,
@web_hook
.
url
).
once
expect
(
WebMock
).
to
have_requested
(
:post
,
@web_hook
.
url
).
once
end
it
"POSTs the data as JSON"
do
json
=
@data
.
to_json
@web_hook
.
execute
(
@data
)
WebMock
.
should
have_requested
(
:post
,
@web_hook
.
url
).
with
(
body:
json
).
once
expect
(
WebMock
).
to
have_requested
(
:post
,
@web_hook
.
url
).
with
(
body:
json
).
once
end
it
"catches exceptions"
do
WebHook
.
should_
receive
(
:post
).
and_raise
(
"Some HTTP Post error"
)
expect
(
WebHook
).
to
receive
(
:post
).
and_raise
(
"Some HTTP Post error"
)
lambda
{
expect
{
@web_hook
.
execute
(
@data
)
}.
should
raise_error
}.
to
raise_error
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