diff options
Diffstat (limited to 'spec/controllers/projects/pipeline_schedules_controller_spec.rb')
-rw-r--r-- | spec/controllers/projects/pipeline_schedules_controller_spec.rb | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/spec/controllers/projects/pipeline_schedules_controller_spec.rb b/spec/controllers/projects/pipeline_schedules_controller_spec.rb index 6d810fdcd51..e4d87daa8d7 100644 --- a/spec/controllers/projects/pipeline_schedules_controller_spec.rb +++ b/spec/controllers/projects/pipeline_schedules_controller_spec.rb @@ -6,8 +6,8 @@ RSpec.describe Projects::PipelineSchedulesController, feature_category: :continu include AccessMatchersForController let_it_be(:user) { create(:user) } - let_it_be(:project) { create(:project, :public, :repository) } - let_it_be(:pipeline_schedule) { create(:ci_pipeline_schedule, project: project) } + let_it_be_with_reload(:project) { create(:project, :public, :repository) } + let_it_be_with_reload(:pipeline_schedule) { create(:ci_pipeline_schedule, project: project) } before do project.add_developer(user) @@ -137,6 +137,20 @@ RSpec.describe Projects::PipelineSchedulesController, feature_category: :continu expect(v.variable_type).to eq("file") end end + + context 'when the user is not allowed to create a pipeline schedule with variables' do + before do + project.update!(restrict_user_defined_variables: true) + end + + it 'does not create a new schedule' do + expect { go } + .to not_change { Ci::PipelineSchedule.count } + .and not_change { Ci::PipelineScheduleVariable.count } + + expect(response).to have_gitlab_http_status(:ok) + end + end end context 'when variables_attributes has two variables and duplicated' do @@ -149,8 +163,8 @@ RSpec.describe Projects::PipelineSchedulesController, feature_category: :continu it 'returns an error that the keys of variable are duplicated' do expect { go } - .to change { Ci::PipelineSchedule.count }.by(0) - .and change { Ci::PipelineScheduleVariable.count }.by(0) + .to not_change { Ci::PipelineSchedule.count } + .and not_change { Ci::PipelineScheduleVariable.count } expect(assigns(:schedule).errors['variables']).not_to be_empty end @@ -213,6 +227,22 @@ RSpec.describe Projects::PipelineSchedulesController, feature_category: :continu expect(pipeline_schedule.variables.last.key).to eq('AAA') expect(pipeline_schedule.variables.last.value).to eq('AAA123') end + + context 'when the user is not allowed to update pipeline schedule variables' do + before do + project.update!(restrict_user_defined_variables: true) + end + + it 'does not update the schedule' do + expect { go } + .to not_change { Ci::PipelineScheduleVariable.count } + + expect(response).to have_gitlab_http_status(:ok) + + pipeline_schedule.reload + expect(pipeline_schedule.variables).to be_empty + end + end end context 'when params include two duplicated variables' do |