summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPawel Chojnacki <pawel@chojnacki.ws>2017-03-28 14:56:30 +0200
committerPawel Chojnacki <pawel@chojnacki.ws>2017-03-28 14:56:30 +0200
commitd3e794e26f806fe491269a74e76c39669433c0fe (patch)
treee094ecabf28df0007325a524980a0c0b22a840cb
parent73203873438d666427228ffdbfe835ea4ffddaa6 (diff)
downloadgitlab-ce-d3e794e26f806fe491269a74e76c39669433c0fe.tar.gz
Optionally filter by deployment time
-rw-r--r--app/controllers/projects/deployments_controller.rb8
-rw-r--r--spec/controllers/projects/deployments_controller_spec.rb2
2 files changed, 6 insertions, 4 deletions
diff --git a/app/controllers/projects/deployments_controller.rb b/app/controllers/projects/deployments_controller.rb
index ed0f802dbd9..a8a6f09d9df 100644
--- a/app/controllers/projects/deployments_controller.rb
+++ b/app/controllers/projects/deployments_controller.rb
@@ -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
diff --git a/spec/controllers/projects/deployments_controller_spec.rb b/spec/controllers/projects/deployments_controller_spec.rb
index b0d543177cc..7b7f16e14da 100644
--- a/spec/controllers/projects/deployments_controller_spec.rb
+++ b/spec/controllers/projects/deployments_controller_spec.rb
@@ -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