Use DeploymentSerializer to create deployment json
This commit is contained in:
		
							parent
							
								
									601f50c642
								
							
						
					
					
						commit
						7320387343
					
				| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,3 @@
 | 
			
		|||
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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue