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