Commit 04263b9f authored by Matija Čupić's avatar Matija Čupić

Add GroupVariableSerializer for Ci::GroupVariable

parent 9be519c1
......@@ -8,7 +8,7 @@ module Groups
variables = @group.variables
.map { |variable| variable.present(current_user: current_user) }
render status: :ok, json: { variables: variables }
render status: :ok, json: { variables: GroupVariableSerializer.new.represent(variables) }
end
end
end
......@@ -20,7 +20,7 @@ module Groups
variables = @group.variables
.map { |variable| variable.present(current_user: current_user) }
return render status: :ok, json: { variables: variables }
return render status: :ok, json: { variables: GroupVariableSerializer.new.represent(variables) }
end
render status: :bad_request, json: @group.errors.full_messages
......
class GroupVariableEntity < Grape::Entity
expose :id
expose :key
expose :value
expose :protected?, as: :protected
end
class GroupVariableSerializer < BaseSerializer
entity GroupVariableEntity
end
......@@ -19,7 +19,7 @@ describe Groups::VariablesController do
it 'renders the ci_group_variable as json' do
subject
expect(response.body).to include(variable.to_json)
expect(response).to match_response_schema('variable')
end
end
......@@ -82,7 +82,7 @@ describe Groups::VariablesController do
it 'has all variables in response' do
subject
expect(response.body).to include(group.variables.reload.to_json)
expect(response).to match_response_schema('variable')
end
end
......@@ -111,7 +111,7 @@ describe Groups::VariablesController do
it 'has all variables in response' do
subject
expect(response.body).to include(group.variables.reload.to_json)
expect(json_response['variables'].count).to eq(0)
end
end
end
......
require 'spec_helper'
describe GroupVariableEntity do
let(:variable) { create(:ci_group_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