Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
ef340f6e
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ef340f6e
编写于
4月 21, 2016
作者:
R
Rémy Coutable
提交者:
Robert Speicher
4月 25, 2016
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Ensure URL in all Service subclasses are valid
Signed-off-by:
N
Rémy Coutable
<
remy@rymai.me
>
上级
b79c5c40
变更
26
隐藏空白更改
内联
并排
Showing
26 changed file
with
525 addition
and
228 deletion
+525
-228
app/helpers/issues_helper.rb
app/helpers/issues_helper.rb
+33
-15
app/models/project_services/buildkite_service.rb
app/models/project_services/buildkite_service.rb
+2
-2
app/models/project_services/issue_tracker_service.rb
app/models/project_services/issue_tracker_service.rb
+1
-1
app/models/project_services/jira_service.rb
app/models/project_services/jira_service.rb
+2
-0
app/models/project_services/slack_service.rb
app/models/project_services/slack_service.rb
+1
-1
spec/helpers/issues_helper_spec.rb
spec/helpers/issues_helper_spec.rb
+36
-0
spec/models/project_services/bamboo_service_spec.rb
spec/models/project_services/bamboo_service_spec.rb
+30
-65
spec/models/project_services/buildkite_service_spec.rb
spec/models/project_services/buildkite_service_spec.rb
+17
-0
spec/models/project_services/builds_email_service_spec.rb
spec/models/project_services/builds_email_service_spec.rb
+38
-43
spec/models/project_services/campfire_service_spec.rb
spec/models/project_services/campfire_service_spec.rb
+42
-0
spec/models/project_services/custom_issue_tracker_service_spec.rb
...els/project_services/custom_issue_tracker_service_spec.rb
+49
-0
spec/models/project_services/drone_ci_service_spec.rb
spec/models/project_services/drone_ci_service_spec.rb
+3
-10
spec/models/project_services/emails_on_push_service_spec.rb
spec/models/project_services/emails_on_push_service_spec.rb
+17
-0
spec/models/project_services/external_wiki_service_spec.rb
spec/models/project_services/external_wiki_service_spec.rb
+11
-6
spec/models/project_services/flowdock_service_spec.rb
spec/models/project_services/flowdock_service_spec.rb
+14
-0
spec/models/project_services/gemnasium_service_spec.rb
spec/models/project_services/gemnasium_service_spec.rb
+16
-0
spec/models/project_services/gitlab_issue_tracker_service_spec.rb
...els/project_services/gitlab_issue_tracker_service_spec.rb
+14
-0
spec/models/project_services/hipchat_service_spec.rb
spec/models/project_services/hipchat_service_spec.rb
+14
-0
spec/models/project_services/irker_service_spec.rb
spec/models/project_services/irker_service_spec.rb
+8
-6
spec/models/project_services/jira_service_spec.rb
spec/models/project_services/jira_service_spec.rb
+25
-1
spec/models/project_services/pivotaltracker_service_spec.rb
spec/models/project_services/pivotaltracker_service_spec.rb
+42
-0
spec/models/project_services/pushover_service_spec.rb
spec/models/project_services/pushover_service_spec.rb
+13
-7
spec/models/project_services/redmine_service_spec.rb
spec/models/project_services/redmine_service_spec.rb
+49
-0
spec/models/project_services/slack_service_spec.rb
spec/models/project_services/slack_service_spec.rb
+11
-6
spec/models/project_services/teamcity_service_spec.rb
spec/models/project_services/teamcity_service_spec.rb
+30
-65
spec/support/issue_tracker_service_shared_example.rb
spec/support/issue_tracker_service_shared_example.rb
+7
-0
未找到文件。
app/helpers/issues_helper.rb
浏览文件 @
ef340f6e
...
...
@@ -16,31 +16,49 @@ module IssuesHelper
def
url_for_project_issues
(
project
=
@project
,
options
=
{})
return
''
if
project
.
nil?
if
options
[
:only_path
]
project
.
issues_tracker
.
project_path
else
project
.
issues_tracker
.
project_url
end
url
=
if
options
[
:only_path
]
project
.
issues_tracker
.
project_path
else
project
.
issues_tracker
.
project_url
end
# Ensure we return a valid URL to prevent possible XSS.
URI
.
parse
(
url
).
to_s
rescue
URI
::
InvalidURIError
''
end
def
url_for_new_issue
(
project
=
@project
,
options
=
{})
return
''
if
project
.
nil?
if
options
[
:only_path
]
project
.
issues_tracker
.
new_issue_path
else
project
.
issues_tracker
.
new_issue_url
end
url
=
if
options
[
:only_path
]
project
.
issues_tracker
.
new_issue_path
else
project
.
issues_tracker
.
new_issue_url
end
# Ensure we return a valid URL to prevent possible XSS.
URI
.
parse
(
url
).
to_s
rescue
URI
::
InvalidURIError
''
end
def
url_for_issue
(
issue_iid
,
project
=
@project
,
options
=
{})
return
''
if
project
.
nil?
if
options
[
:only_path
]
project
.
issues_tracker
.
issue_path
(
issue_iid
)
else
project
.
issues_tracker
.
issue_url
(
issue_iid
)
end
url
=
if
options
[
:only_path
]
project
.
issues_tracker
.
issue_path
(
issue_iid
)
else
project
.
issues_tracker
.
issue_url
(
issue_iid
)
end
# Ensure we return a valid URL to prevent possible XSS.
URI
.
parse
(
url
).
to_s
rescue
URI
::
InvalidURIError
''
end
def
bulk_update_milestone_options
...
...
app/models/project_services/buildkite_service.rb
浏览文件 @
ef340f6e
...
...
@@ -26,7 +26,7 @@ class BuildkiteService < CiService
prop_accessor
:project_url
,
:token
,
:enable_ssl_verification
validates
:project_url
,
presence:
true
,
if: :activated?
validates
:project_url
,
presence:
true
,
url:
true
,
if: :activated?
validates
:token
,
presence:
true
,
if: :activated?
after_save
:compose_service_hook
,
if: :activated?
...
...
@@ -91,7 +91,7 @@ class BuildkiteService < CiService
{
type:
'text'
,
name:
'project_url'
,
placeholder:
"
#{
ENDPOINT
}
/example/project"
},
{
type:
'checkbox'
,
name:
'enable_ssl_verification'
,
title:
"Enable SSL verification"
}
...
...
app/models/project_services/issue_tracker_service.rb
浏览文件 @
ef340f6e
...
...
@@ -21,7 +21,7 @@
class
IssueTrackerService
<
Service
validates
:project_url
,
:issues_url
,
:new_issue_url
,
presence:
true
,
if: :activated?
validates
:project_url
,
:issues_url
,
:new_issue_url
,
presence:
true
,
url:
true
,
if: :activated?
default_value_for
:category
,
'issue_tracker'
...
...
app/models/project_services/jira_service.rb
浏览文件 @
ef340f6e
...
...
@@ -28,6 +28,8 @@ class JiraService < IssueTrackerService
prop_accessor
:username
,
:password
,
:api_url
,
:jira_issue_transition_id
,
:title
,
:description
,
:project_url
,
:issues_url
,
:new_issue_url
validates
:api_url
,
presence:
true
,
url:
true
,
if: :activated?
before_validation
:set_api_url
,
:set_jira_issue_transition_id
before_update
:reset_password
...
...
app/models/project_services/slack_service.rb
浏览文件 @
ef340f6e
...
...
@@ -22,7 +22,7 @@
class
SlackService
<
Service
prop_accessor
:webhook
,
:username
,
:channel
boolean_accessor
:notify_only_broken_builds
validates
:webhook
,
presence:
true
,
if: :activated?
validates
:webhook
,
presence:
true
,
url:
true
,
if: :activated?
def
initialize_properties
if
properties
.
nil?
...
...
spec/helpers/issues_helper_spec.rb
浏览文件 @
ef340f6e
...
...
@@ -30,6 +30,18 @@ describe IssuesHelper do
expect
(
url_for_project_issues
).
to
eq
""
end
it
'returns an empty string if project_url is invalid'
do
expect
(
project
).
to
receive_message_chain
(
'issues_tracker.project_url'
)
{
'javascript:alert("foo");'
}
expect
(
url_for_project_issues
(
project
)).
to
eq
''
end
it
'returns an empty string if project_path is invalid'
do
expect
(
project
).
to
receive_message_chain
(
'issues_tracker.project_path'
)
{
'javascript:alert("foo");'
}
expect
(
url_for_project_issues
(
project
,
only_path:
true
)).
to
eq
''
end
describe
"when external tracker was enabled and then config removed"
do
before
do
@project
=
ext_project
...
...
@@ -68,6 +80,18 @@ describe IssuesHelper do
expect
(
url_for_issue
(
issue
.
iid
)).
to
eq
""
end
it
'returns an empty string if issue_url is invalid'
do
expect
(
project
).
to
receive_message_chain
(
'issues_tracker.issue_url'
)
{
'javascript:alert("foo");'
}
expect
(
url_for_issue
(
issue
.
iid
,
project
)).
to
eq
''
end
it
'returns an empty string if issue_path is invalid'
do
expect
(
project
).
to
receive_message_chain
(
'issues_tracker.issue_path'
)
{
'javascript:alert("foo");'
}
expect
(
url_for_issue
(
issue
.
iid
,
project
,
only_path:
true
)).
to
eq
''
end
describe
"when external tracker was enabled and then config removed"
do
before
do
@project
=
ext_project
...
...
@@ -105,6 +129,18 @@ describe IssuesHelper do
expect
(
url_for_new_issue
).
to
eq
""
end
it
'returns an empty string if issue_url is invalid'
do
expect
(
project
).
to
receive_message_chain
(
'issues_tracker.new_issue_url'
)
{
'javascript:alert("foo");'
}
expect
(
url_for_new_issue
(
project
)).
to
eq
''
end
it
'returns an empty string if issue_path is invalid'
do
expect
(
project
).
to
receive_message_chain
(
'issues_tracker.new_issue_path'
)
{
'javascript:alert("foo");'
}
expect
(
url_for_new_issue
(
project
,
only_path:
true
)).
to
eq
''
end
describe
"when external tracker was enabled and then config removed"
do
before
do
@project
=
ext_project
...
...
spec/models/project_services/bamboo_service_spec.rb
浏览文件 @
ef340f6e
...
...
@@ -27,86 +27,51 @@ describe BambooService, models: true do
end
describe
'Validations'
do
describe
'#bamboo_url'
do
it
'does not validate the presence of bamboo_url if service is not active'
do
bamboo_service
=
service
bamboo_service
.
active
=
false
expect
(
bamboo_service
).
not_to
validate_presence_of
(
:bamboo_url
)
end
it
'validates the presence of bamboo_url if service is active'
do
bamboo_service
=
service
bamboo_service
.
active
=
true
expect
(
bamboo_service
).
to
validate_presence_of
(
:bamboo_url
)
end
end
subject
{
service
}
describe
'#build_key'
do
it
'does not validate the presence of build_key if service is not active'
do
bamboo_service
=
service
bamboo_service
.
active
=
false
context
'when service is active'
do
before
{
subject
.
active
=
true
}
expect
(
bamboo_service
).
not_to
validate_presence_of
(
:build_key
)
end
it
{
is_expected
.
to
validate_presence_of
(
:build_key
)
}
it
{
is_expected
.
to
validate_presence_of
(
:bamboo_url
)
}
it_behaves_like
'issue tracker service URL attribute'
,
:bamboo_url
it
'validates the presence of build_key if service is activ
e'
do
bamboo_service
=
service
bamboo_service
.
active
=
true
describe
'#usernam
e'
do
it
'does not validate the presence of username if password is nil'
do
subject
.
password
=
nil
expect
(
bamboo_service
).
to
validate_presence_of
(
:build_key
)
end
end
expect
(
subject
).
not_to
validate_presence_of
(
:username
)
end
describe
'#username'
do
it
'does not validate the presence of username if service is not active'
do
bamboo_service
=
service
bamboo_service
.
active
=
false
it
'validates the presence of username if password is present'
do
subject
.
password
=
'secret'
expect
(
bamboo_service
).
not_to
validate_presence_of
(
:username
)
expect
(
subject
).
to
validate_presence_of
(
:username
)
end
end
it
'does not validate the presence of username if username is nil'
do
bamboo_service
=
service
bamboo_service
.
active
=
true
bamboo_service
.
password
=
nil
describe
'#password'
do
it
'does not validate the presence of password if username is nil'
do
subject
.
username
=
nil
expect
(
bamboo_service
).
not_to
validate_presence_of
(
:username
)
end
expect
(
subject
).
not_to
validate_presence_of
(
:password
)
end
it
'validates the presence of username if service is active and username is present'
do
bamboo_service
=
service
bamboo_service
.
active
=
true
bamboo_service
.
password
=
'secret'
it
'validates the presence of password if username is present'
do
subject
.
username
=
'john'
expect
(
bamboo_service
).
to
validate_presence_of
(
:username
)
expect
(
subject
).
to
validate_presence_of
(
:password
)
end
end
end
describe
'#password'
do
it
'does not validate the presence of password if service is not active'
do
bamboo_service
=
service
bamboo_service
.
active
=
false
expect
(
bamboo_service
).
not_to
validate_presence_of
(
:password
)
end
it
'does not validate the presence of password if username is nil'
do
bamboo_service
=
service
bamboo_service
.
active
=
true
bamboo_service
.
username
=
nil
expect
(
bamboo_service
).
not_to
validate_presence_of
(
:password
)
end
it
'validates the presence of password if service is active and username is present'
do
bamboo_service
=
service
bamboo_service
.
active
=
true
bamboo_service
.
username
=
'john'
context
'when service is inactive'
do
before
{
subject
.
active
=
false
}
expect
(
bamboo_service
).
to
validate_presence_of
(
:password
)
end
it
{
is_expected
.
not_to
validate_presence_of
(
:build_key
)
}
it
{
is_expected
.
not_to
validate_presence_of
(
:bamboo_url
)
}
it
{
is_expected
.
not_to
validate_presence_of
(
:username
)
}
it
{
is_expected
.
not_to
validate_presence_of
(
:password
)
}
end
end
...
...
spec/models/project_services/buildkite_service_spec.rb
浏览文件 @
ef340f6e
...
...
@@ -26,6 +26,23 @@ describe BuildkiteService, models: true do
it
{
is_expected
.
to
have_one
:service_hook
}
end
describe
'Validations'
do
context
'when service is active'
do
before
{
subject
.
active
=
true
}
it
{
is_expected
.
to
validate_presence_of
(
:project_url
)
}
it
{
is_expected
.
to
validate_presence_of
(
:token
)
}
it_behaves_like
'issue tracker service URL attribute'
,
:project_url
end
context
'when service is inactive'
do
before
{
subject
.
active
=
false
}
it
{
is_expected
.
not_to
validate_presence_of
(
:project_url
)
}
it
{
is_expected
.
not_to
validate_presence_of
(
:token
)
}
end
end
describe
'commits methods'
do
before
do
@project
=
Project
.
new
...
...
spec/models/project_services/builds_email_service_spec.rb
浏览文件 @
ef340f6e
require
'spec_helper'
describe
BuildsEmailService
do
let
(
:build
)
{
create
(
:ci_build
)
}
let
(
:data
)
{
Gitlab
::
BuildDataBuilder
.
build
(
build
)
}
let!
(
:project
)
{
create
(
:project
,
:public
,
ci_id:
1
)
}
let
(
:service
)
{
described_class
.
new
(
project:
project
,
active:
true
)
}
let
(
:data
)
{
Gitlab
::
BuildDataBuilder
.
build
(
create
(
:ci_build
))
}
describe
'Validations'
do
context
'when service is active'
do
before
{
subject
.
active
=
true
}
it
{
is_expected
.
to
validate_presence_of
(
:recipients
)
}
context
'when pusher is added'
do
before
{
subject
.
add_pusher
=
true
}
it
{
is_expected
.
not_to
validate_presence_of
(
:recipients
)
}
end
end
context
'when service is inactive'
do
before
{
subject
.
active
=
false
}
it
{
is_expected
.
not_to
validate_presence_of
(
:recipients
)
}
end
end
describe
'#execute'
do
it
'sends email'
do
s
ervice
.
recipients
=
'test@gitlab.com'
s
ubject
.
recipients
=
'test@gitlab.com'
data
[
:build_status
]
=
'failed'
expect
(
BuildEmailWorker
).
to
receive
(
:perform_async
)
service
.
execute
(
data
)
subject
.
execute
(
data
)
end
it
'does not send email with succeeded build and notify_only_broken_builds on'
do
expect
(
s
ervice
).
to
receive
(
:notify_only_broken_builds
).
and_return
(
true
)
expect
(
s
ubject
).
to
receive
(
:notify_only_broken_builds
).
and_return
(
true
)
data
[
:build_status
]
=
'success'
expect
(
BuildEmailWorker
).
not_to
receive
(
:perform_async
)
service
.
execute
(
data
)
subject
.
execute
(
data
)
end
it
'does not send email with failed build and build_allow_failure is true'
do
data
[
:build_status
]
=
'failed'
data
[
:build_allow_failure
]
=
true
expect
(
BuildEmailWorker
).
not_to
receive
(
:perform_async
)
service
.
execute
(
data
)
subject
.
execute
(
data
)
end
it
'does not send email with unknown build status'
do
data
[
:build_status
]
=
'foo'
expect
(
BuildEmailWorker
).
not_to
receive
(
:perform_async
)
service
.
execute
(
data
)
end
it
'does not send email when recipients list is empty'
do
service
.
recipients
=
' ,, '
data
[
:build_status
]
=
'failed'
expect
(
BuildEmailWorker
).
not_to
receive
(
:perform_async
)
service
.
execute
(
data
)
end
end
describe
'validations'
do
context
'when pusher is not added'
do
before
{
service
.
add_pusher
=
false
}
it
'does not allow empty recipient input'
do
service
.
recipients
=
''
expect
(
service
.
valid?
).
to
be
false
end
it
'does allow non-empty recipient input'
do
service
.
recipients
=
'test@example.com'
expect
(
service
.
valid?
).
to
be
true
end
subject
.
execute
(
data
)
end
context
'when pusher is added'
do
before
{
service
.
add_pusher
=
true
}
it
'does not send email when recipients list is empty'
do
subject
.
recipients
=
' ,, '
data
[
:build_status
]
=
'failed'
it
'does allow empty recipient input'
do
service
.
recipients
=
''
expect
(
service
.
valid?
).
to
be
true
end
expect
(
BuildEmailWorker
).
not_to
receive
(
:perform_async
)
it
'does allow non-empty recipient input'
do
service
.
recipients
=
'test@example.com'
expect
(
service
.
valid?
).
to
be
true
end
subject
.
execute
(
data
)
end
end
end
spec/models/project_services/campfire_service_spec.rb
0 → 100644
浏览文件 @
ef340f6e
# == Schema Information
#
# Table name: services
#
# id :integer not null, primary key
# type :string(255)
# title :string(255)
# project_id :integer
# created_at :datetime
# updated_at :datetime
# active :boolean default(FALSE), not null
# properties :text
# template :boolean default(FALSE)
# push_events :boolean default(TRUE)
# issues_events :boolean default(TRUE)
# merge_requests_events :boolean default(TRUE)
# tag_push_events :boolean default(TRUE)
# note_events :boolean default(TRUE), not null
#
require
'spec_helper'
describe
CampfireService
,
models:
true
do
describe
'Associations'
do
it
{
is_expected
.
to
belong_to
:project
}
it
{
is_expected
.
to
have_one
:service_hook
}
end
describe
'Validations'
do
context
'when service is active'
do
before
{
subject
.
active
=
true
}
it
{
is_expected
.
to
validate_presence_of
(
:token
)
}
end
context
'when service is inactive'
do
before
{
subject
.
active
=
false
}
it
{
is_expected
.
not_to
validate_presence_of
(
:token
)
}
end
end
end
spec/models/project_services/custom_issue_tracker_service_spec.rb
0 → 100644
浏览文件 @
ef340f6e
# == Schema Information
#
# Table name: services
#
# id :integer not null, primary key
# type :string(255)
# title :string(255)
# project_id :integer
# created_at :datetime
# updated_at :datetime
# active :boolean default(FALSE), not null
# properties :text
# template :boolean default(FALSE)
# push_events :boolean default(TRUE)
# issues_events :boolean default(TRUE)
# merge_requests_events :boolean default(TRUE)
# tag_push_events :boolean default(TRUE)
# note_events :boolean default(TRUE), not null
#
require
'spec_helper'
describe
CustomIssueTrackerService
,
models:
true
do
describe
'Associations'
do
it
{
is_expected
.
to
belong_to
:project
}
it
{
is_expected
.
to
have_one
:service_hook
}
end
describe
'Validations'
do
context
'when service is active'
do
before
{
subject
.
active
=
true
}
it
{
is_expected
.
to
validate_presence_of
(
:project_url
)
}
it
{
is_expected
.
to
validate_presence_of
(
:issues_url
)
}
it
{
is_expected
.
to
validate_presence_of
(
:new_issue_url
)
}
it_behaves_like
'issue tracker service URL attribute'
,
:project_url
it_behaves_like
'issue tracker service URL attribute'
,
:issues_url
it_behaves_like
'issue tracker service URL attribute'
,
:new_issue_url
end
context
'when service is inactive'
do
before
{
subject
.
active
=
false
}
it
{
is_expected
.
not_to
validate_presence_of
(
:project_url
)
}
it
{
is_expected
.
not_to
validate_presence_of
(
:issues_url
)
}
it
{
is_expected
.
not_to
validate_presence_of
(
:new_issue_url
)
}
end
end
end
spec/models/project_services/drone_ci_service_spec.rb
浏览文件 @
ef340f6e
...
...
@@ -28,25 +28,18 @@ describe DroneCiService, models: true do
describe
'validations'
do
context
'active'
do
before
{
allow
(
subject
).
to
receive
(
:activated?
).
and_return
(
true
)
}
before
{
subject
.
active
=
true
}
it
{
is_expected
.
to
validate_presence_of
(
:token
)
}
it
{
is_expected
.
to
validate_presence_of
(
:drone_url
)
}
it
{
is_expected
.
to
allow_value
(
'ewf9843kdnfdfs89234n'
).
for
(
:token
)
}
it
{
is_expected
.
to
allow_value
(
'http://ci.example.com'
).
for
(
:drone_url
)
}
it
{
is_expected
.
not_to
allow_value
(
'this is not url'
).
for
(
:drone_url
)
}
it
{
is_expected
.
not_to
allow_value
(
'http//noturl'
).
for
(
:drone_url
)
}
it
{
is_expected
.
not_to
allow_value
(
'ftp://ci.example.com'
).
for
(
:drone_url
)
}
it_behaves_like
'issue tracker service URL attribute'
,
:drone_url
end
context
'inactive'
do
before
{
allow
(
subject
).
to
receive
(
:activated?
).
and_return
(
false
)
}
before
{
subject
.
active
=
false
}
it
{
is_expected
.
not_to
validate_presence_of
(
:token
)
}
it
{
is_expected
.
not_to
validate_presence_of
(
:drone_url
)
}
it
{
is_expected
.
to
allow_value
(
'ewf9843kdnfdfs89234n'
).
for
(
:token
)
}
it
{
is_expected
.
to
allow_value
(
'http://drone.example.com'
).
for
(
:drone_url
)
}
it
{
is_expected
.
to
allow_value
(
'ftp://drone.example.com'
).
for
(
:drone_url
)
}
end
end
...
...
spec/models/project_services/emails_on_push_service_spec.rb
0 → 100644
浏览文件 @
ef340f6e
require
'spec_helper'
describe
EmailsOnPushService
do
describe
'Validations'
do
context
'when service is active'
do
before
{
subject
.
active
=
true
}
it
{
is_expected
.
to
validate_presence_of
(
:recipients
)
}
end
context
'when service is inactive'
do
before
{
subject
.
active
=
false
}
it
{
is_expected
.
not_to
validate_presence_of
(
:recipients
)
}
end
end
end
spec/models/external_wiki_service_spec.rb
→
spec/models/
project_services/
external_wiki_service_spec.rb
浏览文件 @
ef340f6e
...
...
@@ -28,13 +28,18 @@ describe ExternalWikiService, models: true do
it
{
should
have_one
:service_hook
}
end
describe
"Validations"
do
context
"active"
do
before
do
subject
.
active
=
true
end
describe
'Validations'
do
context
'when service is active'
do
before
{
subject
.
active
=
true
}
it
{
is_expected
.
to
validate_presence_of
(
:external_wiki_url
)
}
it_behaves_like
'issue tracker service URL attribute'
,
:external_wiki_url
end
context
'when service is inactive'
do
before
{
subject
.
active
=
false
}
it
{
should
validate_presence_of
:external_wiki_url
}
it
{
is_expected
.
not_to
validate_presence_of
(
:external_wiki_url
)
}
end
end
...
...
spec/models/project_services/flowdock_service_spec.rb
浏览文件 @
ef340f6e
...
...
@@ -26,6 +26,20 @@ describe FlowdockService, models: true do
it
{
is_expected
.
to
have_one
:service_hook
}
end
describe
'Validations'
do
context
'when service is active'
do
before
{
subject
.
active
=
true
}
it
{
is_expected
.
to
validate_presence_of
(
:token
)
}
end
context
'when service is inactive'
do
before
{
subject
.
active
=
false
}
it
{
is_expected
.
not_to
validate_presence_of
(
:token
)
}
end
end
describe
"Execute"
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
)
}
...
...
spec/models/project_services/gemnasium_service_spec.rb
浏览文件 @
ef340f6e
...
...
@@ -26,6 +26,22 @@ describe GemnasiumService, models: true do
it
{
is_expected
.
to
have_one
:service_hook
}
end
describe
'Validations'
do
context
'when service is active'
do
before
{
subject
.
active
=
true
}
it
{
is_expected
.
to
validate_presence_of
(
:token
)
}
it
{
is_expected
.
to
validate_presence_of
(
:api_key
)
}
end
context
'when service is inactive'
do
before
{
subject
.
active
=
false
}
it
{
is_expected
.
not_to
validate_presence_of
(
:token
)
}
it
{
is_expected
.
not_to
validate_presence_of
(
:api_key
)
}
end
end
describe
"Execute"
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
)
}
...
...
spec/models/project_services/gitlab_issue_tracker_service_spec.rb
浏览文件 @
ef340f6e
...
...
@@ -26,6 +26,20 @@ describe GitlabIssueTrackerService, models: true do
it
{
is_expected
.
to
have_one
:service_hook
}
end
describe
'Validations'
do
context
'when service is active'
do
subject
{
described_class
.
new
(
project:
create
(
:project
),
active:
true
)
}
it
{
is_expected
.
to
validate_presence_of
(
:issues_url
)
}
it_behaves_like
'issue tracker service URL attribute'
,
:issues_url
end
context
'when service is inactive'
do
subject
{
described_class
.
new
(
project:
create
(
:project
),
active:
false
)
}
it
{
is_expected
.
not_to
validate_presence_of
(
:issues_url
)
}
end
end
describe
'project and issue urls'
do
let
(
:project
)
{
create
(
:project
)
}
...
...
spec/models/project_services/hipchat_service_spec.rb
浏览文件 @
ef340f6e
...
...
@@ -26,6 +26,20 @@ describe HipchatService, models: true do
it
{
is_expected
.
to
have_one
:service_hook
}
end
describe
'Validations'
do
context
'when service is active'
do
before
{
subject
.
active
=
true
}
it
{
is_expected
.
to
validate_presence_of
(
:token
)
}
end
context
'when service is inactive'
do
before
{
subject
.
active
=
false
}
it
{
is_expected
.
not_to
validate_presence_of
(
:token
)
}
end
end
describe
"Execute"
do
let
(
:hipchat
)
{
HipchatService
.
new
}
let
(
:user
)
{
create
(
:user
,
username:
'username'
)
}
...
...
spec/models/project_services/irker_service_spec.rb
浏览文件 @
ef340f6e
...
...
@@ -29,14 +29,16 @@ describe IrkerService, models: true do
end
describe
'Validations'
do
before
do
subject
.
active
=
true
subject
.
properties
[
'recipients'
]
=
_recipients
context
'when service is active'
do
before
{
subject
.
active
=
true
}
it
{
is_expected
.
to
validate_presence_of
(
:recipients
)
}
end
context
'active'
do
let
(
:_recipients
)
{
nil
}
it
{
should
validate_presence_of
:recipients
}
context
'when service is inactive'
do
before
{
subject
.
active
=
false
}
it
{
is_expected
.
not_to
validate_presence_of
(
:recipients
)
}
end
end
...
...
spec/models/project_services/jira_service_spec.rb
浏览文件 @
ef340f6e
...
...
@@ -26,6 +26,30 @@ describe JiraService, models: true do
it
{
is_expected
.
to
have_one
:service_hook
}
end
describe
'Validations'
do
context
'when service is active'
do
before
{
subject
.
active
=
true
}
it
{
is_expected
.
to
validate_presence_of
(
:api_url
)
}
it
{
is_expected
.
to
validate_presence_of
(
:project_url
)
}
it
{
is_expected
.
to
validate_presence_of
(
:issues_url
)
}
it
{
is_expected
.
to
validate_presence_of
(
:new_issue_url
)
}
it_behaves_like
'issue tracker service URL attribute'
,
:api_url
it_behaves_like
'issue tracker service URL attribute'
,
:project_url
it_behaves_like
'issue tracker service URL attribute'
,
:issues_url
it_behaves_like
'issue tracker service URL attribute'
,
:new_issue_url
end
context
'when service is inactive'
do
before
{
subject
.
active
=
false
}
it
{
is_expected
.
not_to
validate_presence_of
(
:api_url
)
}
it
{
is_expected
.
not_to
validate_presence_of
(
:project_url
)
}
it
{
is_expected
.
not_to
validate_presence_of
(
:issues_url
)
}
it
{
is_expected
.
not_to
validate_presence_of
(
:new_issue_url
)
}
end
end
describe
"Execute"
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
)
}
...
...
@@ -72,7 +96,7 @@ describe JiraService, models: true do
context
"when a password was previously set"
do
before
do
@jira_service
=
JiraService
.
create
(
@jira_service
=
JiraService
.
create
!
(
project:
create
(
:project
),
properties:
{
api_url:
'http://jira.example.com/rest/api/2'
,
...
...
spec/models/project_services/pivotaltracker_service_spec.rb
0 → 100644
浏览文件 @
ef340f6e
# == Schema Information
#
# Table name: services
#
# id :integer not null, primary key
# type :string(255)
# title :string(255)
# project_id :integer
# created_at :datetime
# updated_at :datetime
# active :boolean default(FALSE), not null
# properties :text
# template :boolean default(FALSE)
# push_events :boolean default(TRUE)
# issues_events :boolean default(TRUE)
# merge_requests_events :boolean default(TRUE)
# tag_push_events :boolean default(TRUE)
# note_events :boolean default(TRUE), not null
#
require
'spec_helper'
describe
PivotaltrackerService
,
models:
true
do
describe
'Associations'
do
it
{
is_expected
.
to
belong_to
:project
}
it
{
is_expected
.
to
have_one
:service_hook
}
end
describe
'Validations'
do
context
'when service is active'
do
before
{
subject
.
active
=
true
}
it
{
is_expected
.
to
validate_presence_of
(
:token
)
}
end
context
'when service is inactive'
do
before
{
subject
.
active
=
false
}
it
{
is_expected
.
not_to
validate_presence_of
(
:token
)
}
end
end
end
spec/models/project_services/pushover_service_spec.rb
浏览文件 @
ef340f6e
...
...
@@ -27,14 +27,20 @@ describe PushoverService, models: true do
end
describe
'Validations'
do
context
'active'
do
before
do
subject
.
active
=
true
end
context
'when service is active'
do
before
{
subject
.
active
=
true
}
it
{
is_expected
.
to
validate_presence_of
:api_key
}
it
{
is_expected
.
to
validate_presence_of
:user_key
}
it
{
is_expected
.
to
validate_presence_of
:priority
}
it
{
is_expected
.
to
validate_presence_of
(
:api_key
)
}
it
{
is_expected
.
to
validate_presence_of
(
:user_key
)
}
it
{
is_expected
.
to
validate_presence_of
(
:priority
)
}
end
context
'when service is inactive'
do
before
{
subject
.
active
=
false
}
it
{
is_expected
.
not_to
validate_presence_of
(
:api_key
)
}
it
{
is_expected
.
not_to
validate_presence_of
(
:user_key
)
}
it
{
is_expected
.
not_to
validate_presence_of
(
:priority
)
}
end
end
...
...
spec/models/project_services/redmine_service_spec.rb
0 → 100644
浏览文件 @
ef340f6e
# == Schema Information
#
# Table name: services
#
# id :integer not null, primary key
# type :string(255)
# title :string(255)
# project_id :integer
# created_at :datetime
# updated_at :datetime
# active :boolean default(FALSE), not null
# properties :text
# template :boolean default(FALSE)
# push_events :boolean default(TRUE)
# issues_events :boolean default(TRUE)
# merge_requests_events :boolean default(TRUE)
# tag_push_events :boolean default(TRUE)
# note_events :boolean default(TRUE), not null
#
require
'spec_helper'
describe
RedmineService
,
models:
true
do
describe
'Associations'
do
it
{
is_expected
.
to
belong_to
:project
}
it
{
is_expected
.
to
have_one
:service_hook
}
end
describe
'Validations'
do
context
'when service is active'
do
before
{
subject
.
active
=
true
}
it
{
is_expected
.
to
validate_presence_of
(
:project_url
)
}
it
{
is_expected
.
to
validate_presence_of
(
:issues_url
)
}
it
{
is_expected
.
to
validate_presence_of
(
:new_issue_url
)
}
it_behaves_like
'issue tracker service URL attribute'
,
:project_url
it_behaves_like
'issue tracker service URL attribute'
,
:issues_url
it_behaves_like
'issue tracker service URL attribute'
,
:new_issue_url
end
context
'when service is inactive'
do
before
{
subject
.
active
=
false
}
it
{
is_expected
.
not_to
validate_presence_of
(
:project_url
)
}
it
{
is_expected
.
not_to
validate_presence_of
(
:issues_url
)
}
it
{
is_expected
.
not_to
validate_presence_of
(
:new_issue_url
)
}
end
end
end
spec/models/project_services/slack_service_spec.rb
浏览文件 @
ef340f6e
...
...
@@ -26,13 +26,18 @@ describe SlackService, models: true do
it
{
is_expected
.
to
have_one
:service_hook
}
end
describe
"Validations"
do
context
"active"
do
before
do
subject
.
active
=
true
end
describe
'Validations'
do
context
'when service is active'
do
before
{
subject
.
active
=
true
}
it
{
is_expected
.
to
validate_presence_of
:webhook
}
it
{
is_expected
.
to
validate_presence_of
(
:webhook
)
}
it_behaves_like
'issue tracker service URL attribute'
,
:webhook
end
context
'when service is inactive'
do
before
{
subject
.
active
=
false
}
it
{
is_expected
.
not_to
validate_presence_of
(
:webhook
)
}
end
end
...
...
spec/models/project_services/teamcity_service_spec.rb
浏览文件 @
ef340f6e
...
...
@@ -27,86 +27,51 @@ describe TeamcityService, models: true do
end
describe
'Validations'
do
describe
'#teamcity_url'
do
it
'does not validate the presence of teamcity_url if service is not active'
do
teamcity_service
=
service
teamcity_service
.
active
=
false
expect
(
teamcity_service
).
not_to
validate_presence_of
(
:teamcity_url
)
end
it
'validates the presence of teamcity_url if service is active'
do
teamcity_service
=
service
teamcity_service
.
active
=
true
expect
(
teamcity_service
).
to
validate_presence_of
(
:teamcity_url
)
end
end
subject
{
service
}
describe
'#build_type'
do
it
'does not validate the presence of build_type if service is not active'
do
teamcity_service
=
service
teamcity_service
.
active
=
false
context
'when service is active'
do
before
{
subject
.
active
=
true
}
expect
(
teamcity_service
).
not_to
validate_presence_of
(
:build_type
)
end
it
{
is_expected
.
to
validate_presence_of
(
:build_type
)
}
it
{
is_expected
.
to
validate_presence_of
(
:teamcity_url
)
}
it_behaves_like
'issue tracker service URL attribute'
,
:teamcity_url
it
'validates the presence of build_type if service is activ
e'
do
teamcity_service
=
service
teamcity_service
.
active
=
true
describe
'#usernam
e'
do
it
'does not validate the presence of username if password is nil'
do
subject
.
password
=
nil
expect
(
teamcity_service
).
to
validate_presence_of
(
:build_type
)
end
end
expect
(
subject
).
not_to
validate_presence_of
(
:username
)
end
describe
'#username'
do
it
'does not validate the presence of username if service is not active'
do
teamcity_service
=
service
teamcity_service
.
active
=
false
it
'validates the presence of username if password is present'
do
subject
.
password
=
'secret'
expect
(
teamcity_service
).
not_to
validate_presence_of
(
:username
)
expect
(
subject
).
to
validate_presence_of
(
:username
)
end
end
it
'does not validate the presence of username if username is nil'
do
teamcity_service
=
service
teamcity_service
.
active
=
true
teamcity_service
.
password
=
nil
describe
'#password'
do
it
'does not validate the presence of password if username is nil'
do
subject
.
username
=
nil
expect
(
teamcity_service
).
not_to
validate_presence_of
(
:username
)
end
expect
(
subject
).
not_to
validate_presence_of
(
:password
)
end
it
'validates the presence of username if service is active and username is present'
do
teamcity_service
=
service
teamcity_service
.
active
=
true
teamcity_service
.
password
=
'secret'
it
'validates the presence of password if username is present'
do
subject
.
username
=
'john'
expect
(
teamcity_service
).
to
validate_presence_of
(
:username
)
expect
(
subject
).
to
validate_presence_of
(
:password
)
end
end
end
describe
'#password'
do
it
'does not validate the presence of password if service is not active'
do
teamcity_service
=
service
teamcity_service
.
active
=
false
expect
(
teamcity_service
).
not_to
validate_presence_of
(
:password
)
end
it
'does not validate the presence of password if username is nil'
do
teamcity_service
=
service
teamcity_service
.
active
=
true
teamcity_service
.
username
=
nil
expect
(
teamcity_service
).
not_to
validate_presence_of
(
:password
)
end
it
'validates the presence of password if service is active and username is present'
do
teamcity_service
=
service
teamcity_service
.
active
=
true
teamcity_service
.
username
=
'john'
context
'when service is inactive'
do
before
{
subject
.
active
=
false
}
expect
(
teamcity_service
).
to
validate_presence_of
(
:password
)
end
it
{
is_expected
.
not_to
validate_presence_of
(
:build_type
)
}
it
{
is_expected
.
not_to
validate_presence_of
(
:teamcity_url
)
}
it
{
is_expected
.
not_to
validate_presence_of
(
:username
)
}
it
{
is_expected
.
not_to
validate_presence_of
(
:password
)
}
end
end
...
...
spec/support/issue_tracker_service_shared_example.rb
0 → 100644
浏览文件 @
ef340f6e
RSpec
.
shared_examples
'issue tracker service URL attribute'
do
|
url_attr
|
it
{
is_expected
.
to
allow_value
(
'https://example.com'
).
for
(
url_attr
)
}
it
{
is_expected
.
not_to
allow_value
(
'example.com'
).
for
(
url_attr
)
}
it
{
is_expected
.
not_to
allow_value
(
'ftp://example.com'
).
for
(
url_attr
)
}
it
{
is_expected
.
not_to
allow_value
(
'herp-and-derp'
).
for
(
url_attr
)
}
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录