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
Boxiang Sun
gitlab-ce
Commits
9be519c1
Commit
9be519c1
authored
Jan 30, 2018
by
Matija Čupić
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add VariableSerializer for Ci::Variable
parent
b48d8c8a
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
35 additions
and
5 deletions
+35
-5
app/controllers/projects/variables_controller.rb
app/controllers/projects/variables_controller.rb
+2
-2
app/serializers/variable_entity.rb
app/serializers/variable_entity.rb
+7
-0
app/serializers/variable_serializer.rb
app/serializers/variable_serializer.rb
+3
-0
spec/controllers/projects/variables_controller_spec.rb
spec/controllers/projects/variables_controller_spec.rb
+3
-3
spec/fixtures/api/schemas/variable.json
spec/fixtures/api/schemas/variable.json
+6
-0
spec/serializers/variable_entity_spec.rb
spec/serializers/variable_entity_spec.rb
+14
-0
No files found.
app/controllers/projects/variables_controller.rb
View file @
9be519c1
...
...
@@ -7,7 +7,7 @@ class Projects::VariablesController < Projects::ApplicationController
variables
=
@project
.
variables
.
map
{
|
variable
|
variable
.
present
(
current_user:
current_user
)
}
render
status: :ok
,
json:
{
variables:
variables
}
render
status: :ok
,
json:
{
variables:
VariableSerializer
.
new
.
represent
(
variables
)
}
end
end
end
...
...
@@ -19,7 +19,7 @@ class Projects::VariablesController < Projects::ApplicationController
variables
=
@project
.
variables
.
map
{
|
variable
|
variable
.
present
(
current_user:
current_user
)
}
return
render
status: :ok
,
json:
{
variables:
variables
}
return
render
status: :ok
,
json:
{
variables:
VariableSerializer
.
new
.
represent
(
variables
)
}
end
render
status: :bad_request
,
json:
@project
.
errors
.
full_messages
...
...
app/serializers/variable_entity.rb
0 → 100644
View file @
9be519c1
class
VariableEntity
<
Grape
::
Entity
expose
:id
expose
:key
expose
:value
expose
:protected?
,
as: :protected
end
app/serializers/variable_serializer.rb
0 → 100644
View file @
9be519c1
class
VariableSerializer
<
BaseSerializer
entity
VariableEntity
end
spec/controllers/projects/variables_controller_spec.rb
View file @
9be519c1
...
...
@@ -24,7 +24,7 @@ describe Projects::VariablesController do
it
'renders the ci_variable as json'
do
subject
expect
(
response
.
body
).
to
include
(
variable
.
to_json
)
expect
(
response
).
to
match_response_schema
(
'variable'
)
end
end
...
...
@@ -91,7 +91,7 @@ describe Projects::VariablesController do
it
'has all variables in response'
do
subject
expect
(
response
.
body
).
to
include
(
project
.
variables
.
reload
.
to_json
)
expect
(
response
).
to
match_response_schema
(
'variable'
)
end
end
...
...
@@ -120,7 +120,7 @@ describe Projects::VariablesController do
it
'has all variables in response'
do
subject
expect
(
response
.
body
).
to
include
(
project
.
variables
.
reload
.
to_json
)
expect
(
json_response
[
'variables'
].
count
).
to
eq
(
0
)
end
end
end
...
...
spec/fixtures/api/schemas/variable.json
0 → 100644
View file @
9be519c1
{
"id"
:
"string"
,
"key"
:
"string"
,
"value"
:
"string"
,
"protected"
:
"boolean"
}
spec/serializers/variable_entity_spec.rb
0 → 100644
View file @
9be519c1
require
'spec_helper'
describe
VariableEntity
do
let
(
:variable
)
{
create
(
:ci_variable
)
}
let
(
:entity
)
{
described_class
.
new
(
variable
)
}
describe
'#as_json'
do
subject
{
entity
.
as_json
}
it
'contains required fields'
do
expect
(
subject
).
to
include
(
:id
,
:key
,
:value
,
:protected
)
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