Commit ef78f67f authored by Stan Hu's avatar Stan Hu

Add a spec for rate limiting pipeline schedules

parent 54f13b1e
......@@ -45,7 +45,7 @@ class Projects::PipelineSchedulesController < Projects::ApplicationController
limiter = ::Gitlab::ActionRateLimiter.new(action: 'play_pipeline_schedule')
if limiter.throttled?(throttle_key, 1)
flash[:notice] = 'You cannot play this scheduled pipeline at the moment. Please wait a minute.'
flash[:alert] = 'You cannot play this scheduled pipeline at the moment. Please wait a minute.'
return redirect_to pipeline_schedules_path(@project)
end
......@@ -53,7 +53,7 @@ class Projects::PipelineSchedulesController < Projects::ApplicationController
flash[:notice] =
if job_id
"Successfully scheduled a pipeline to run. Go to the <a href=\"#{project_pipelines_path(@project)}\">Pipelines page</a> for details".html_safe
"Successfully scheduled a pipeline to run. Go to the <a href=\"#{project_pipelines_path(@project)}\">Pipelines page</a> for details.".html_safe
else
'Unable to schedule a pipeline to run immediately'
end
......
......@@ -385,6 +385,16 @@ describe Projects::PipelineSchedulesController do
expect(flash[:notice]).to start_with 'Successfully scheduled a pipeline to run'
expect(response).to have_gitlab_http_status(302)
end
it 'prevents users from scheduling the same pipeline repeatedly' do
2.times do
post :play, namespace_id: project.namespace.to_param, project_id: project, id: pipeline_schedule.id
end
expect(flash.to_a.size).to eq(2)
expect(flash[:alert]).to eq 'You cannot play this scheduled pipeline at the moment. Please wait a minute.'
expect(response).to have_gitlab_http_status(302)
end
end
context 'when a developer attempts to schedule a protected ref' do
......
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