use represent_concise instead of separate entity
This commit is contained in:
parent
e057ad975c
commit
33f7c40f3f
5 changed files with 18 additions and 42 deletions
|
@ -7,7 +7,7 @@ class Projects::DeploymentsController < Projects::ApplicationController
|
|||
deployments = deployments.where('created_at > ?', params[:after].to_time) if params[:after]&.to_time
|
||||
|
||||
render json: { deployments: DeploymentSerializer.new(user: @current_user, project: project)
|
||||
.represent(deployments) }
|
||||
.represent_concise(deployments) }
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -9,9 +9,21 @@ class DeploymentEntity < Grape::Entity
|
|||
expose :name do |deployment|
|
||||
deployment.ref
|
||||
end
|
||||
|
||||
expose :ref_path do |deployment|
|
||||
namespace_project_tree_path(
|
||||
deployment.project.namespace,
|
||||
deployment.project,
|
||||
id: deployment.ref)
|
||||
end
|
||||
end
|
||||
|
||||
expose :created_at
|
||||
expose :tag
|
||||
expose :last?
|
||||
|
||||
expose :user, using: UserEntity
|
||||
expose :commit, using: CommitEntity
|
||||
expose :deployable, using: BuildEntity
|
||||
expose :manual_actions, using: BuildEntity
|
||||
end
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
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
|
|
@ -1,3 +1,8 @@
|
|||
class DeploymentSerializer < BaseSerializer
|
||||
entity DeploymentEntity
|
||||
|
||||
def represent_concise(resource, opts = {})
|
||||
opts[:only] = [:iid, :id, :sha, :created_at, :tag, :last?, :id, ref: [:name]]
|
||||
represent(resource, opts)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
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
|
Loading…
Reference in a new issue