Commit d3e794e2 authored by Pawel Chojnacki's avatar Pawel Chojnacki

Optionally filter by deployment time

parent 73203873
......@@ -2,9 +2,11 @@ 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| serializer.represent(d) }
serializer = DeploymentSerializer.new(user: @current_user, project: project)
deployments = environment.deployments.reorder(created_at: :desc)
deployments = deployments.where('created_at > ?', params[:after].to_time) if params[:after]&.to_time
deployments = deployments.map { |deployment| serializer.represent(deployment) }
render json: { deployments: deployments }
end
......
......@@ -20,7 +20,7 @@ describe Projects::DeploymentsController do
create(:deployment, environment: environment, created_at: 7.hours.ago)
create(:deployment, environment: environment)
get :index, environment_params
get :index, environment_params(:after => 8.hours.ago)
expect(response).to be_ok
......
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