summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPawel Chojnacki <pawel@chojnacki.ws>2017-04-24 22:34:36 +0200
committerPawel Chojnacki <pawel@chojnacki.ws>2017-04-24 22:34:36 +0200
commit33f7c40f3f7d2b342dcaa839b7cd56599a573c65 (patch)
tree96bcf4f5018b5f5c91b082767129fe503c8a7ac3
parente057ad975c6ced8c9565fc8329db16b1ababcef8 (diff)
downloadgitlab-ce-33f7c40f3f7d2b342dcaa839b7cd56599a573c65.tar.gz
use represent_concise instead of separate entity
-rw-r--r--app/controllers/projects/deployments_controller.rb2
-rw-r--r--app/serializers/deployment_entity.rb12
-rw-r--r--app/serializers/deployment_entity_detailed.rb15
-rw-r--r--app/serializers/deployment_serializer.rb5
-rw-r--r--spec/serializers/deployment_entity_detailed_spec.rb26
5 files changed, 18 insertions, 42 deletions
diff --git a/app/controllers/projects/deployments_controller.rb b/app/controllers/projects/deployments_controller.rb
index 79e59fc1326..c319671456d 100644
--- a/app/controllers/projects/deployments_controller.rb
+++ b/app/controllers/projects/deployments_controller.rb
@@ -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
diff --git a/app/serializers/deployment_entity.rb b/app/serializers/deployment_entity.rb
index a8d6d80faad..8b3de1bed0f 100644
--- a/app/serializers/deployment_entity.rb
+++ b/app/serializers/deployment_entity.rb
@@ -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
diff --git a/app/serializers/deployment_entity_detailed.rb b/app/serializers/deployment_entity_detailed.rb
deleted file mode 100644
index 63df61dd51b..00000000000
--- a/app/serializers/deployment_entity_detailed.rb
+++ /dev/null
@@ -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
diff --git a/app/serializers/deployment_serializer.rb b/app/serializers/deployment_serializer.rb
index 4b4bf6cd526..cba5c3f311f 100644
--- a/app/serializers/deployment_serializer.rb
+++ b/app/serializers/deployment_serializer.rb
@@ -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
diff --git a/spec/serializers/deployment_entity_detailed_spec.rb b/spec/serializers/deployment_entity_detailed_spec.rb
deleted file mode 100644
index d28e3fa0665..00000000000
--- a/spec/serializers/deployment_entity_detailed_spec.rb
+++ /dev/null
@@ -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