Commit 33f7c40f authored by Pawel Chojnacki's avatar Pawel Chojnacki

use represent_concise instead of separate entity

parent e057ad97
...@@ -7,7 +7,7 @@ class Projects::DeploymentsController < Projects::ApplicationController ...@@ -7,7 +7,7 @@ class Projects::DeploymentsController < Projects::ApplicationController
deployments = deployments.where('created_at > ?', params[:after].to_time) if params[:after]&.to_time deployments = deployments.where('created_at > ?', params[:after].to_time) if params[:after]&.to_time
render json: { deployments: DeploymentSerializer.new(user: @current_user, project: project) render json: { deployments: DeploymentSerializer.new(user: @current_user, project: project)
.represent(deployments) } .represent_concise(deployments) }
end end
private private
......
...@@ -9,9 +9,21 @@ class DeploymentEntity < Grape::Entity ...@@ -9,9 +9,21 @@ class DeploymentEntity < Grape::Entity
expose :name do |deployment| expose :name do |deployment|
deployment.ref deployment.ref
end end
expose :ref_path do |deployment|
namespace_project_tree_path(
deployment.project.namespace,
deployment.project,
id: deployment.ref)
end
end end
expose :created_at expose :created_at
expose :tag expose :tag
expose :last? expose :last?
expose :user, using: UserEntity
expose :commit, using: CommitEntity
expose :deployable, using: BuildEntity
expose :manual_actions, using: BuildEntity
end end
class DeploymentEntityDetailed < DeploymentEntity
expose :ref do
expose :ref_path do |deployment|
namespace_project_tree_path(
deployment.project.namespace,
deployment.project,
id: deployment.ref)
end
end
expose :user, using: UserEntity
expose :commit, using: CommitEntity
expose :deployable, using: BuildEntity
expose :manual_actions, using: BuildEntity
end
class DeploymentSerializer < BaseSerializer class DeploymentSerializer < BaseSerializer
entity DeploymentEntity entity DeploymentEntity
def represent_concise(resource, opts = {})
opts[:only] = [:iid, :id, :sha, :created_at, :tag, :last?, :id, ref: [:name]]
represent(resource, opts)
end
end end
require 'spec_helper'
describe DeploymentEntityDetailed do
let(:user) { create(:user) }
let(:request) { double('request') }
let(:deployment) { create(:deployment) }
let(:entity) { described_class.new(deployment, request: request) }
subject { entity.as_json }
before do
allow(request).to receive(:user).and_return(user)
end
it 'exposes internal deployment id' do
expect(subject).to include(:iid)
end
it 'exposes nested information about branch' 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