Commit 73203873 authored by Pawel Chojnacki's avatar Pawel Chojnacki

Use DeploymentSerializer to create deployment json

parent 601f50c6
......@@ -2,8 +2,9 @@ class Projects::DeploymentsController < Projects::ApplicationController
before_action :authorize_read_deployment!
def index
serializer = DeploymentSerializer.new(user: @current_user)
deployments = environment.deployments.where('created_at > ?', 8.hours.ago)
.map { |d| d.slice(:id, :iid, :created_at, :sha, :ref, :tag) }
.map { |d| serializer.represent(d) }
render json: { deployments: deployments }
end
......
......@@ -18,6 +18,7 @@ class DeploymentEntity < Grape::Entity
end
end
expose :created_at
expose :tag
expose :last?
expose :user, using: UserEntity
......
class DeploymentSerializer < BaseSerializer
entity DeploymentEntity
end
......@@ -28,19 +28,16 @@ describe Projects::DeploymentsController do
end
it 'returns a list with deployments information' do
deployment = create(:deployment, environment: environment)
create(:deployment, environment: environment)
get :index, environment_params
expect(response).to be_ok
deployments = json_response['deployments']
deployment_info = deployments.first.with_indifferent_access
created_at = deployment_info.delete(:created_at).to_time.utc
expect(deployments.count).to eq(1)
expect(deployment_info).to include(:id, :iid, :sha, :ref, :tag)
expect(deployment).to have_attributes(deployment_info)
expect(deployment.created_at).to be_within(1.second).of(created_at)
expect(deployment_info).to include(:id, :iid, :sha, :ref, :tag, :created_at)
end
end
......
......@@ -24,4 +24,8 @@ describe DeploymentEntity do
expect(subject[:ref][:name]).to eq 'master'
expect(subject[:ref][:ref_path]).not_to be_empty
end
it 'exposes creation date' do
expect(subject).to include(:created_at)
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