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
16f21dcc
Commit
16f21dcc
authored
May 18, 2020
by
Justin Ho
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use public_send instead of send
Add more specs to cover values of help and choices
parent
1106bdff
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
28 deletions
+64
-28
app/serializers/service_field_entity.rb
app/serializers/service_field_entity.rb
+2
-3
spec/serializers/service_field_entity_spec.rb
spec/serializers/service_field_entity_spec.rb
+62
-25
No files found.
app/serializers/service_field_entity.rb
View file @
16f21dcc
...
...
@@ -6,7 +6,8 @@ class ServiceFieldEntity < Grape::Entity
expose
:type
,
:name
,
:title
,
:placeholder
,
:required
,
:choices
,
:help
expose
:value
do
|
field
|
value
=
service
.
send
(
field
[
:name
])
# rubocop:disable GitlabSecurity/PublicSend
value
=
service
.
public_send
(
field
[
:name
])
# rubocop:disable GitlabSecurity/PublicSend
if
field
[
:type
]
==
'password'
&&
value
.
present?
'true'
else
...
...
@@ -16,8 +17,6 @@ class ServiceFieldEntity < Grape::Entity
private
alias_method
:field
,
:object
def
service
request
.
service
end
...
...
spec/serializers/service_field_entity_spec.rb
View file @
16f21dcc
...
...
@@ -3,7 +3,6 @@
require
'spec_helper'
describe
ServiceFieldEntity
do
let
(
:service
)
{
create
(
:jira_service
)
}
let
(
:request
)
{
double
(
'request'
)
}
subject
{
described_class
.
new
(
field
,
request:
request
,
service:
service
).
as_json
}
...
...
@@ -13,33 +12,71 @@ describe ServiceFieldEntity do
end
describe
'#as_json'
do
context
'field with type text'
do
let
(
:field
)
{
service
.
global_fields
.
find
{
|
field
|
field
[
:name
]
==
'username'
}
}
it
'exposes correct attributes'
do
expect
(
subject
[
:type
]).
to
eq
(
'text'
)
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
eq
(
nil
)
expect
(
subject
[
:help
]).
to
eq
(
nil
)
expect
(
subject
[
:value
]).
to
eq
(
'jira_username'
)
context
'Jira Service'
do
let
(
:service
)
{
create
(
:jira_service
)
}
context
'field with type text'
do
let
(
:field
)
{
service
.
global_fields
.
find
{
|
field
|
field
[
:name
]
==
'username'
}
}
it
'exposes correct attributes'
do
expect
(
subject
[
:type
]).
to
eq
(
'text'
)
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
context
'field with type password'
do
let
(
:field
)
{
service
.
global_fields
.
find
{
|
field
|
field
[
:name
]
==
'password'
}
}
it
'exposes correct attributes but hides password'
do
expect
(
subject
[
:type
]).
to
eq
(
'password'
)
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
context
'field with type password'
do
let
(
:field
)
{
service
.
global_fields
.
find
{
|
field
|
field
[
:name
]
==
'password'
}
}
it
'exposes correct attributes but hides password'
do
expect
(
subject
[
:type
]).
to
eq
(
'password'
)
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
eq
(
nil
)
expect
(
subject
[
:help
]).
to
eq
(
nil
)
expect
(
subject
[
:value
]).
to
eq
(
'true'
)
context
'EmailsOnPush Service'
do
let
(
:service
)
{
create
(
:emails_on_push_service
)
}
context
'field with type checkbox'
do
let
(
:field
)
{
service
.
global_fields
.
find
{
|
field
|
field
[
:name
]
==
'send_from_committer_email'
}
}
it
'exposes correct attributes'
do
expect
(
subject
[
:type
]).
to
eq
(
'checkbox'
)
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
[
:value
]).
to
eq
(
true
)
end
end
context
'field with type select'
do
let
(
:field
)
{
service
.
global_fields
.
find
{
|
field
|
field
[
:name
]
==
'branches_to_be_notified'
}
}
it
'exposes correct attributes'
do
expect
(
subject
[
:type
]).
to
eq
(
'select'
)
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
...
...
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