BigW Consortium Gitlab

Add VariableSerializer for Ci::Variable

parent b48d8c8a
......@@ -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
......
class VariableEntity < Grape::Entity
expose :id
expose :key
expose :value
expose :protected?, as: :protected
end
class VariableSerializer < BaseSerializer
entity VariableEntity
end
......@@ -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
......
{
"id": "string",
"key": "string",
"value": "string",
"protected": "boolean"
}
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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment