Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
2b5f4e40
Commit
2b5f4e40
authored
May 27, 2020
by
Justin Ho
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract some logic to helpers and refactor specs
As suggested in code review
parent
e99efc34
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
72 additions
and
35 deletions
+72
-35
app/helpers/services_helper.rb
app/helpers/services_helper.rb
+18
-0
app/views/shared/_service_settings.html.haml
app/views/shared/_service_settings.html.haml
+2
-4
spec/serializers/service_field_entity_spec.rb
spec/serializers/service_field_entity_spec.rb
+52
-31
No files found.
app/helpers/services_helper.rb
View file @
2b5f4e40
...
@@ -98,6 +98,24 @@ module ServicesHelper
...
@@ -98,6 +98,24 @@ module ServicesHelper
end
end
end
end
def
trigger_events_for_service
return
[]
unless
Feature
.
enabled?
(
:integration_form_refactor
,
@project
)
ServiceEventSerializer
.
new
(
service:
@service
).
represent
(
@service
.
configurable_events
).
to_json
end
def
fields_for_service
return
[]
unless
Feature
.
enabled?
(
:integration_form_refactor
,
@project
)
ServiceFieldSerializer
.
new
(
service:
@service
).
represent
(
@service
.
global_fields
).
to_json
end
def
show_service_trigger_events
return
false
if
@service
.
is_a?
(
JiraService
)
||
Feature
.
enabled?
(
:integration_form_refactor
,
@project
)
@service
.
configurable_events
.
present?
end
extend
self
extend
self
end
end
...
...
app/views/shared/_service_settings.html.haml
View file @
2b5f4e40
=
form_errors
(
@service
)
=
form_errors
(
@service
)
-
trigger_events
=
Feature
.
enabled?
(
:integration_form_refactor
,
@project
)
?
ServiceEventSerializer
.
new
(
service:
@service
).
represent
(
@service
.
configurable_events
).
to_json
:
[]
-
fields
=
Feature
.
enabled?
(
:integration_form_refactor
,
@project
)
?
ServiceFieldSerializer
.
new
(
service:
@service
).
represent
(
@service
.
global_fields
).
to_json
:
[]
-
if
lookup_context
.
template_exists?
(
'help'
,
"projects/services/
#{
@service
.
to_param
}
"
,
true
)
-
if
lookup_context
.
template_exists?
(
'help'
,
"projects/services/
#{
@service
.
to_param
}
"
,
true
)
=
render
"projects/services/
#{
@service
.
to_param
}
/help"
,
subject:
@service
=
render
"projects/services/
#{
@service
.
to_param
}
/help"
,
subject:
@service
...
@@ -11,9 +9,9 @@
...
@@ -11,9 +9,9 @@
.service-settings
.service-settings
.js-vue-integration-settings
{
data:
{
show_active:
@service
.
show_active_box?
.
to_s
,
activated:
(
@service
.
active
||
@service
.
new_record?
).
to_s
,
type:
@service
.
to_param
,
merge_request_events:
@service
.
merge_requests_events
.
to_s
,
.js-vue-integration-settings
{
data:
{
show_active:
@service
.
show_active_box?
.
to_s
,
activated:
(
@service
.
active
||
@service
.
new_record?
).
to_s
,
type:
@service
.
to_param
,
merge_request_events:
@service
.
merge_requests_events
.
to_s
,
commit_events:
@service
.
commit_events
.
to_s
,
enable_comments:
@service
.
comment_on_event_enabled
.
to_s
,
comment_detail:
@service
.
comment_detail
,
trigger_events:
trigger_events
,
fields:
fields
}
}
commit_events:
@service
.
commit_events
.
to_s
,
enable_comments:
@service
.
comment_on_event_enabled
.
to_s
,
comment_detail:
@service
.
comment_detail
,
trigger_events:
trigger_events
_for_service
,
fields:
fields_for_service
}
}
-
if
@service
.
configurable_events
.
present?
&&
!
@service
.
is_a?
(
JiraService
)
&&
Feature
.
disabled?
(
:integration_form_refactor
,
@project
)
-
if
show_service_trigger_events
.form-group.row
.form-group.row
%label
.col-form-label.col-sm-2
=
_
(
'Trigger'
)
%label
.col-form-label.col-sm-2
=
_
(
'Trigger'
)
...
...
spec/serializers/service_field_entity_spec.rb
View file @
2b5f4e40
...
@@ -17,31 +17,42 @@ describe ServiceFieldEntity do
...
@@ -17,31 +17,42 @@ describe ServiceFieldEntity do
context
'field with type text'
do
context
'field with type text'
do
let
(
:field
)
{
service
.
global_fields
.
find
{
|
field
|
field
[
:name
]
==
'username'
}
}
let
(
:field
)
{
service
.
global_fields
.
find
{
|
field
|
field
[
:name
]
==
'username'
}
}
let
(
:expected_hash
)
do
{
type:
'text'
,
name:
'username'
,
title:
'Username or Email'
,
placeholder:
'Use a username for server version and an email for cloud version'
,
required:
true
,
choices:
nil
,
help:
nil
,
value:
'jira_username'
}
end
it
'exposes correct attributes'
do
it
'exposes correct attributes'
do
expect
(
subject
[
:type
]).
to
eq
(
'text'
)
is_expected
.
to
eq
(
expected_hash
)
expect
(
subject
[
:name
]).
to
eq
(
'username'
)
expect
(
subject
[
:title
]).
to
eq
(
'Username or Email'
)
expect
(
subject
[
:placeholder
]).
to
eq
(
'Use a username for server version and an email for cloud version'
)
expect
(
subject
[
:required
]).
to
eq
(
true
)
expect
(
subject
[
:choices
]).
to
be_nil
expect
(
subject
[
:help
]).
to
be_nil
expect
(
subject
[
:value
]).
to
eq
(
'jira_username'
)
end
end
end
end
context
'field with type password'
do
context
'field with type password'
do
let
(
:field
)
{
service
.
global_fields
.
find
{
|
field
|
field
[
:name
]
==
'password'
}
}
let
(
:field
)
{
service
.
global_fields
.
find
{
|
field
|
field
[
:name
]
==
'password'
}
}
let
(
:expected_hash
)
do
{
type:
'password'
,
name:
'password'
,
title:
'Password or API token'
,
placeholder:
'Use a password for server version and an API token for cloud version'
,
required:
true
,
choices:
nil
,
help:
nil
,
value:
'true'
}
end
it
'exposes correct attributes but hides password'
do
it
'exposes correct attributes but hides password'
do
expect
(
subject
[
:type
]).
to
eq
(
'password'
)
is_expected
.
to
eq
(
expected_hash
)
expect
(
subject
[
:name
]).
to
eq
(
'password'
)
expect
(
subject
[
:title
]).
to
eq
(
'Password or API token'
)
expect
(
subject
[
:placeholder
]).
to
eq
(
'Use a password for server version and an API token for cloud version'
)
expect
(
subject
[
:required
]).
to
eq
(
true
)
expect
(
subject
[
:choices
]).
to
be_nil
expect
(
subject
[
:help
]).
to
be_nil
expect
(
subject
[
:value
]).
to
eq
(
'true'
)
end
end
end
end
end
end
...
@@ -51,31 +62,41 @@ describe ServiceFieldEntity do
...
@@ -51,31 +62,41 @@ describe ServiceFieldEntity do
context
'field with type checkbox'
do
context
'field with type checkbox'
do
let
(
:field
)
{
service
.
global_fields
.
find
{
|
field
|
field
[
:name
]
==
'send_from_committer_email'
}
}
let
(
:field
)
{
service
.
global_fields
.
find
{
|
field
|
field
[
:name
]
==
'send_from_committer_email'
}
}
let
(
:expected_hash
)
do
{
type:
'checkbox'
,
name:
'send_from_committer_email'
,
title:
'Send from committer'
,
placeholder:
nil
,
required:
nil
,
choices:
nil
,
value:
true
}
end
it
'exposes correct attributes'
do
it
'exposes correct attributes'
do
expect
(
subject
[
:type
]).
to
eq
(
'checkbox'
)
is_expected
.
to
include
(
expected_hash
)
expect
(
subject
[
:name
]).
to
eq
(
'send_from_committer_email'
)
expect
(
subject
[
:title
]).
to
eq
(
'Send from committer'
)
expect
(
subject
[
:placeholder
]).
to
be_nil
expect
(
subject
[
:required
]).
to
be_nil
expect
(
subject
[
:choices
]).
to
be_nil
expect
(
subject
[
:help
]).
to
include
(
"Send notifications from the committer's email address if the domain is part of the domain GitLab is running on"
)
expect
(
subject
[
:help
]).
to
include
(
"Send notifications from the committer's email address if the domain is part of the domain GitLab is running on"
)
expect
(
subject
[
:value
]).
to
eq
(
true
)
end
end
end
end
context
'field with type select'
do
context
'field with type select'
do
let
(
:field
)
{
service
.
global_fields
.
find
{
|
field
|
field
[
:name
]
==
'branches_to_be_notified'
}
}
let
(
:field
)
{
service
.
global_fields
.
find
{
|
field
|
field
[
:name
]
==
'branches_to_be_notified'
}
}
let
(
:expected_hash
)
do
{
type:
'select'
,
name:
'branches_to_be_notified'
,
title:
nil
,
placeholder:
nil
,
required:
nil
,
choices:
[[
'All branches'
,
'all'
],
[
'Default branch'
,
'default'
],
[
'Protected branches'
,
'protected'
],
[
'Default branch and protected branches'
,
'default_and_protected'
]],
help:
nil
,
value:
nil
}
end
it
'exposes correct attributes'
do
it
'exposes correct attributes'
do
expect
(
subject
[
:type
]).
to
eq
(
'select'
)
is_expected
.
to
eq
(
expected_hash
)
expect
(
subject
[
:name
]).
to
eq
(
'branches_to_be_notified'
)
expect
(
subject
[
:title
]).
to
be_nil
expect
(
subject
[
:placeholder
]).
to
be_nil
expect
(
subject
[
:required
]).
to
be_nil
expect
(
subject
[
:choices
]).
to
eq
([[
'All branches'
,
'all'
],
[
'Default branch'
,
'default'
],
[
'Protected branches'
,
'protected'
],
[
'Default branch and protected branches'
,
'default_and_protected'
]])
expect
(
subject
[
:help
]).
to
be_nil
expect
(
subject
[
:value
]).
to
be_nil
end
end
end
end
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment