From 909c277e56e2773bab8368b6fdd3871a4c9c53f3 Mon Sep 17 00:00:00 2001 From: Tomasz Maczukin Date: Thu, 22 Mar 2018 15:31:41 +0100 Subject: Move leftovers from pipelines_settings_controller to settings/ci_cd_controller --- .../projects/pipelines_settings_controller.rb | 37 ----- app/controllers/projects/refs_controller.rb | 2 +- .../projects/settings/ci_cd_controller.rb | 50 ++++++- .../projects/pipelines_settings/_badge.html.haml | 32 ---- .../projects/pipelines_settings/_show.html.haml | 160 -------------------- app/views/projects/settings/ci_cd/_badge.html.haml | 32 ++++ app/views/projects/settings/ci_cd/_form.html.haml | 161 +++++++++++++++++++++ app/views/projects/settings/ci_cd/show.html.haml | 5 +- config/routes/project.rb | 2 +- .../projects/pipelines_settings_controller_spec.rb | 79 +--------- .../projects/settings/ci_cd_controller_spec.rb | 84 ++++++++++- spec/features/projects/badges/list_spec.rb | 2 +- .../pipelines_settings/_show.html.haml_spec.rb | 62 -------- .../settings/ci_cd/_form.html.haml_spec.rb | 62 ++++++++ 14 files changed, 392 insertions(+), 378 deletions(-) delete mode 100644 app/views/projects/pipelines_settings/_badge.html.haml delete mode 100644 app/views/projects/pipelines_settings/_show.html.haml create mode 100644 app/views/projects/settings/ci_cd/_badge.html.haml create mode 100644 app/views/projects/settings/ci_cd/_form.html.haml delete mode 100644 spec/views/projects/pipelines_settings/_show.html.haml_spec.rb create mode 100644 spec/views/projects/settings/ci_cd/_form.html.haml_spec.rb diff --git a/app/controllers/projects/pipelines_settings_controller.rb b/app/controllers/projects/pipelines_settings_controller.rb index dc12b76e2b0..73c613b26f3 100644 --- a/app/controllers/projects/pipelines_settings_controller.rb +++ b/app/controllers/projects/pipelines_settings_controller.rb @@ -4,41 +4,4 @@ class Projects::PipelinesSettingsController < Projects::ApplicationController def show redirect_to project_settings_ci_cd_path(@project, params: params) end - - def update - Projects::UpdateService.new(project, current_user, update_params).tap do |service| - if service.execute - flash[:notice] = "Pipelines settings for '#{@project.name}' were successfully updated." - - run_autodevops_pipeline(service) - - redirect_to project_settings_ci_cd_path(@project) - else - render 'show' - end - end - end - - private - - def run_autodevops_pipeline(service) - return unless service.run_auto_devops_pipeline? - - if @project.empty_repo? - flash[:warning] = "This repository is currently empty. A new Auto DevOps pipeline will be created after a new file has been pushed to a branch." - return - end - - CreatePipelineWorker.perform_async(project.id, current_user.id, project.default_branch, :web, ignore_skip_ci: true, save_on_errors: false) - flash[:success] = "A new Auto DevOps pipeline has been created, go to Pipelines page for details".html_safe - end - - def update_params - params.require(:project).permit( - :runners_token, :builds_enabled, :build_allow_git_fetch, - :build_timeout_human_readable, :build_coverage_regex, :public_builds, - :auto_cancel_pending_pipelines, :ci_config_path, - auto_devops_attributes: [:id, :domain, :enabled] - ) - end end diff --git a/app/controllers/projects/refs_controller.rb b/app/controllers/projects/refs_controller.rb index 2376f469213..48a09e1ddb8 100644 --- a/app/controllers/projects/refs_controller.rb +++ b/app/controllers/projects/refs_controller.rb @@ -25,7 +25,7 @@ class Projects::RefsController < Projects::ApplicationController when "graphs_commits" commits_project_graph_path(@project, @id) when "badges" - project_pipelines_settings_path(@project, ref: @id) + project_settings_ci_cd_path(@project, ref: @id) else project_commits_path(@project, @id) end diff --git a/app/controllers/projects/settings/ci_cd_controller.rb b/app/controllers/projects/settings/ci_cd_controller.rb index 96125b549b7..d80ef8113aa 100644 --- a/app/controllers/projects/settings/ci_cd_controller.rb +++ b/app/controllers/projects/settings/ci_cd_controller.rb @@ -2,13 +2,24 @@ module Projects module Settings class CiCdController < Projects::ApplicationController before_action :authorize_admin_pipeline! + before_action :define_variables def show - define_runners_variables - define_secret_variables - define_triggers_variables - define_badges_variables - define_auto_devops_variables + end + + def update + Projects::UpdateService.new(project, current_user, update_params).tap do |service| + result = service.execute + if result[:status] == :success + flash[:notice] = "Pipelines settings for '#{@project.name}' were successfully updated." + + run_autodevops_pipeline(service) + + redirect_to project_settings_ci_cd_path(@project) + else + render 'show' + end + end end def reset_cache @@ -25,6 +36,35 @@ module Projects private + def update_params + params.require(:project).permit( + :runners_token, :builds_enabled, :build_allow_git_fetch, + :build_timeout_human_readable, :build_coverage_regex, :public_builds, + :auto_cancel_pending_pipelines, :ci_config_path, + auto_devops_attributes: [:id, :domain, :enabled] + ) + end + + def run_autodevops_pipeline(service) + return unless service.run_auto_devops_pipeline? + + if @project.empty_repo? + flash[:warning] = "This repository is currently empty. A new Auto DevOps pipeline will be created after a new file has been pushed to a branch." + return + end + + CreatePipelineWorker.perform_async(project.id, current_user.id, project.default_branch, :web, ignore_skip_ci: true, save_on_errors: false) + flash[:success] = "A new Auto DevOps pipeline has been created, go to Pipelines page for details".html_safe + end + + def define_variables + define_runners_variables + define_secret_variables + define_triggers_variables + define_badges_variables + define_auto_devops_variables + end + def define_runners_variables @project_runners = @project.runners.ordered @assignable_runners = current_user.ci_authorized_runners diff --git a/app/views/projects/pipelines_settings/_badge.html.haml b/app/views/projects/pipelines_settings/_badge.html.haml deleted file mode 100644 index e8028059487..00000000000 --- a/app/views/projects/pipelines_settings/_badge.html.haml +++ /dev/null @@ -1,32 +0,0 @@ -%div{ class: badge.title.gsub(' ', '-') } - .col-lg-12 - %h4 - = badge.title.capitalize - .panel.panel-default - .panel-heading - %b - = badge.title.capitalize - · - = badge.to_html - .pull-right - = render 'shared/ref_switcher', destination: 'badges', align_right: true - .panel-body - .row - .col-md-2.text-center - Markdown - .col-md-10.code.js-syntax-highlight - = highlight('.md', badge.to_markdown) - .row - %hr - .row - .col-md-2.text-center - HTML - .col-md-10.code.js-syntax-highlight - = highlight('.html', badge.to_html) - .row - %hr - .row - .col-md-2.text-center - AsciiDoc - .col-md-10.code.js-syntax-highlight - = highlight('.adoc', badge.to_asciidoc) diff --git a/app/views/projects/pipelines_settings/_show.html.haml b/app/views/projects/pipelines_settings/_show.html.haml deleted file mode 100644 index 845fa088ec0..00000000000 --- a/app/views/projects/pipelines_settings/_show.html.haml +++ /dev/null @@ -1,160 +0,0 @@ -.row.prepend-top-default - .col-lg-12 - = form_for @project, url: project_pipelines_settings_path(@project) do |f| - %fieldset.builds-feature - .form-group - %h5 Auto DevOps (Beta) - %p - Auto DevOps will automatically build, test, and deploy your application based on a predefined Continuous Integration and Delivery configuration. - = link_to 'Learn more about Auto DevOps', help_page_path('topics/autodevops/index.md') - - message = auto_devops_warning_message(@project) - - if message - %p.settings-message.text-center - = message.html_safe - = f.fields_for :auto_devops_attributes, @auto_devops do |form| - .radio - = form.label :enabled_true do - = form.radio_button :enabled, 'true' - %strong Enable Auto DevOps - %br - %span.descr - The Auto DevOps pipeline configuration will be used when there is no .gitlab-ci.yml in the project. - - .radio - = form.label :enabled_false do - = form.radio_button :enabled, 'false' - %strong Disable Auto DevOps - %br - %span.descr - An explicit .gitlab-ci.yml needs to be specified before you can begin using Continuous Integration and Delivery. - - .radio - = form.label :enabled_ do - = form.radio_button :enabled, '' - %strong Instance default (#{Gitlab::CurrentSettings.auto_devops_enabled? ? 'enabled' : 'disabled'}) - %br - %span.descr - Follow the instance default to either have Auto DevOps enabled or disabled when there is no project specific .gitlab-ci.yml. - %p - You need to specify a domain if you want to use Auto Review Apps and Auto Deploy stages. - = form.text_field :domain, class: 'form-control', placeholder: 'domain.com' - - %hr - .form-group.append-bottom-default.js-secret-runner-token - = f.label :runners_token, "Runner token", class: 'label-light' - .form-control.js-secret-value-placeholder - = '*' * 20 - = f.text_field :runners_token, class: "form-control hide js-secret-value", placeholder: 'xEeFCaDAB89' - %p.help-block The secure token used by the Runner to checkout the project - %button.btn.btn-info.prepend-top-10.js-secret-value-reveal-button{ type: 'button', data: { secret_reveal_status: 'false' } } - = _('Reveal value') - - %hr - .form-group - %h5.prepend-top-0 - Git strategy for pipelines - %p - Choose between clone or fetch to get the recent application code - = link_to icon('question-circle'), help_page_path('user/project/pipelines/settings', anchor: 'git-strategy'), target: '_blank' - .radio - = f.label :build_allow_git_fetch_false do - = f.radio_button :build_allow_git_fetch, 'false' - %strong git clone - %br - %span.descr - Slower but makes sure the project workspace is pristine as it clones the repository from scratch for every job - .radio - = f.label :build_allow_git_fetch_true do - = f.radio_button :build_allow_git_fetch, 'true' - %strong git fetch - %br - %span.descr - Faster as it re-uses the project workspace (falling back to clone if it doesn't exist) - - %hr - .form-group - = f.label :build_timeout_human_readable, 'Timeout', class: 'label-light' - = f.text_field :build_timeout_human_readable, class: 'form-control' - %p.help-block - Per job. If a job passes this threshold, it will be marked as failed - = link_to icon('question-circle'), help_page_path('user/project/pipelines/settings', anchor: 'timeout'), target: '_blank' - - %hr - .form-group - = f.label :ci_config_path, 'Custom CI config path', class: 'label-light' - = f.text_field :ci_config_path, class: 'form-control', placeholder: '.gitlab-ci.yml' - %p.help-block - The path to CI config file. Defaults to .gitlab-ci.yml - = link_to icon('question-circle'), help_page_path('user/project/pipelines/settings', anchor: 'custom-ci-config-path'), target: '_blank' - - %hr - .form-group - .checkbox - = f.label :public_builds do - = f.check_box :public_builds - %strong Public pipelines - .help-block - Allow public access to pipelines and job details, including output logs and artifacts - = link_to icon('question-circle'), help_page_path('user/project/pipelines/settings', anchor: 'visibility-of-pipelines'), target: '_blank' - .bs-callout.bs-callout-info - %p If enabled: - %ul - %li - For public projects, anyone can view pipelines and access job details (output logs and artifacts) - %li - For internal projects, any logged in user can view pipelines and access job details (output logs and artifacts) - %li - For private projects, any member (guest or higher) can view pipelines and access job details (output logs and artifacts) - %p - If disabled, the access level will depend on the user's - permissions in the project. - - %hr - .form-group - .checkbox - = f.label :auto_cancel_pending_pipelines do - = f.check_box :auto_cancel_pending_pipelines, {}, 'enabled', 'disabled' - %strong Auto-cancel redundant, pending pipelines - .help-block - New pipelines will cancel older, pending pipelines on the same branch - = link_to icon('question-circle'), help_page_path('user/project/pipelines/settings', anchor: 'auto-cancel-pending-pipelines'), target: '_blank' - - %hr - .form-group - = f.label :build_coverage_regex, "Test coverage parsing", class: 'label-light' - .input-group - %span.input-group-addon / - = f.text_field :build_coverage_regex, class: 'form-control', placeholder: 'Regular expression' - %span.input-group-addon / - %p.help-block - A regular expression that will be used to find the test coverage - output in the job trace. Leave blank to disable - = link_to icon('question-circle'), help_page_path('user/project/pipelines/settings', anchor: 'test-coverage-parsing'), target: '_blank' - .bs-callout.bs-callout-info - %p Below are examples of regex for existing tools: - %ul - %li - Simplecov (Ruby) - - %code \(\d+.\d+\%\) covered - %li - pytest-cov (Python) - - %code \d+\%\s*$ - %li - phpunit --coverage-text --colors=never (PHP) - - %code ^\s*Lines:\s*\d+.\d+\% - %li - gcovr (C/C++) - - %code ^TOTAL.*\s+(\d+\%)$ - %li - tap --coverage-report=text-summary (NodeJS) - - %code ^Statements\s*:\s*([^%]+) - %li - excoveralls (Elixir) - - %code \[TOTAL\]\s+(\d+\.\d+)% - - = f.submit 'Save changes', class: "btn btn-save" - -%hr - -.row.prepend-top-default - = render partial: 'projects/pipelines_settings/badge', collection: @badges diff --git a/app/views/projects/settings/ci_cd/_badge.html.haml b/app/views/projects/settings/ci_cd/_badge.html.haml new file mode 100644 index 00000000000..e8028059487 --- /dev/null +++ b/app/views/projects/settings/ci_cd/_badge.html.haml @@ -0,0 +1,32 @@ +%div{ class: badge.title.gsub(' ', '-') } + .col-lg-12 + %h4 + = badge.title.capitalize + .panel.panel-default + .panel-heading + %b + = badge.title.capitalize + · + = badge.to_html + .pull-right + = render 'shared/ref_switcher', destination: 'badges', align_right: true + .panel-body + .row + .col-md-2.text-center + Markdown + .col-md-10.code.js-syntax-highlight + = highlight('.md', badge.to_markdown) + .row + %hr + .row + .col-md-2.text-center + HTML + .col-md-10.code.js-syntax-highlight + = highlight('.html', badge.to_html) + .row + %hr + .row + .col-md-2.text-center + AsciiDoc + .col-md-10.code.js-syntax-highlight + = highlight('.adoc', badge.to_asciidoc) diff --git a/app/views/projects/settings/ci_cd/_form.html.haml b/app/views/projects/settings/ci_cd/_form.html.haml new file mode 100644 index 00000000000..a976ad12cff --- /dev/null +++ b/app/views/projects/settings/ci_cd/_form.html.haml @@ -0,0 +1,161 @@ +.row.prepend-top-default + .col-lg-12 + = form_for @project, url: project_settings_ci_cd_path(@project) do |f| + = form_errors(@project) + %fieldset.builds-feature + .form-group + %h5 Auto DevOps (Beta) + %p + Auto DevOps will automatically build, test, and deploy your application based on a predefined Continuous Integration and Delivery configuration. + = link_to 'Learn more about Auto DevOps', help_page_path('topics/autodevops/index.md') + - message = auto_devops_warning_message(@project) + - if message + %p.settings-message.text-center + = message.html_safe + = f.fields_for :auto_devops_attributes, @auto_devops do |form| + .radio + = form.label :enabled_true do + = form.radio_button :enabled, 'true' + %strong Enable Auto DevOps + %br + %span.descr + The Auto DevOps pipeline configuration will be used when there is no .gitlab-ci.yml in the project. + + .radio + = form.label :enabled_false do + = form.radio_button :enabled, 'false' + %strong Disable Auto DevOps + %br + %span.descr + An explicit .gitlab-ci.yml needs to be specified before you can begin using Continuous Integration and Delivery. + + .radio + = form.label :enabled_ do + = form.radio_button :enabled, '' + %strong Instance default (#{Gitlab::CurrentSettings.auto_devops_enabled? ? 'enabled' : 'disabled'}) + %br + %span.descr + Follow the instance default to either have Auto DevOps enabled or disabled when there is no project specific .gitlab-ci.yml. + %p + You need to specify a domain if you want to use Auto Review Apps and Auto Deploy stages. + = form.text_field :domain, class: 'form-control', placeholder: 'domain.com' + + %hr + .form-group.append-bottom-default.js-secret-runner-token + = f.label :runners_token, "Runner token", class: 'label-light' + .form-control.js-secret-value-placeholder + = '*' * 20 + = f.text_field :runners_token, class: "form-control hide js-secret-value", placeholder: 'xEeFCaDAB89' + %p.help-block The secure token used by the Runner to checkout the project + %button.btn.btn-info.prepend-top-10.js-secret-value-reveal-button{ type: 'button', data: { secret_reveal_status: 'false' } } + = _('Reveal value') + + %hr + .form-group + %h5.prepend-top-0 + Git strategy for pipelines + %p + Choose between clone or fetch to get the recent application code + = link_to icon('question-circle'), help_page_path('user/project/pipelines/settings', anchor: 'git-strategy'), target: '_blank' + .radio + = f.label :build_allow_git_fetch_false do + = f.radio_button :build_allow_git_fetch, 'false' + %strong git clone + %br + %span.descr + Slower but makes sure the project workspace is pristine as it clones the repository from scratch for every job + .radio + = f.label :build_allow_git_fetch_true do + = f.radio_button :build_allow_git_fetch, 'true' + %strong git fetch + %br + %span.descr + Faster as it re-uses the project workspace (falling back to clone if it doesn't exist) + + %hr + .form-group + = f.label :build_timeout_human_readable, 'Timeout', class: 'label-light' + = f.text_field :build_timeout_human_readable, class: 'form-control' + %p.help-block + Per job. If a job passes this threshold, it will be marked as failed + = link_to icon('question-circle'), help_page_path('user/project/pipelines/settings', anchor: 'timeout'), target: '_blank' + + %hr + .form-group + = f.label :ci_config_path, 'Custom CI config path', class: 'label-light' + = f.text_field :ci_config_path, class: 'form-control', placeholder: '.gitlab-ci.yml' + %p.help-block + The path to CI config file. Defaults to .gitlab-ci.yml + = link_to icon('question-circle'), help_page_path('user/project/pipelines/settings', anchor: 'custom-ci-config-path'), target: '_blank' + + %hr + .form-group + .checkbox + = f.label :public_builds do + = f.check_box :public_builds + %strong Public pipelines + .help-block + Allow public access to pipelines and job details, including output logs and artifacts + = link_to icon('question-circle'), help_page_path('user/project/pipelines/settings', anchor: 'visibility-of-pipelines'), target: '_blank' + .bs-callout.bs-callout-info + %p If enabled: + %ul + %li + For public projects, anyone can view pipelines and access job details (output logs and artifacts) + %li + For internal projects, any logged in user can view pipelines and access job details (output logs and artifacts) + %li + For private projects, any member (guest or higher) can view pipelines and access job details (output logs and artifacts) + %p + If disabled, the access level will depend on the user's + permissions in the project. + + %hr + .form-group + .checkbox + = f.label :auto_cancel_pending_pipelines do + = f.check_box :auto_cancel_pending_pipelines, {}, 'enabled', 'disabled' + %strong Auto-cancel redundant, pending pipelines + .help-block + New pipelines will cancel older, pending pipelines on the same branch + = link_to icon('question-circle'), help_page_path('user/project/pipelines/settings', anchor: 'auto-cancel-pending-pipelines'), target: '_blank' + + %hr + .form-group + = f.label :build_coverage_regex, "Test coverage parsing", class: 'label-light' + .input-group + %span.input-group-addon / + = f.text_field :build_coverage_regex, class: 'form-control', placeholder: 'Regular expression' + %span.input-group-addon / + %p.help-block + A regular expression that will be used to find the test coverage + output in the job trace. Leave blank to disable + = link_to icon('question-circle'), help_page_path('user/project/pipelines/settings', anchor: 'test-coverage-parsing'), target: '_blank' + .bs-callout.bs-callout-info + %p Below are examples of regex for existing tools: + %ul + %li + Simplecov (Ruby) - + %code \(\d+.\d+\%\) covered + %li + pytest-cov (Python) - + %code \d+\%\s*$ + %li + phpunit --coverage-text --colors=never (PHP) - + %code ^\s*Lines:\s*\d+.\d+\% + %li + gcovr (C/C++) - + %code ^TOTAL.*\s+(\d+\%)$ + %li + tap --coverage-report=text-summary (NodeJS) - + %code ^Statements\s*:\s*([^%]+) + %li + excoveralls (Elixir) - + %code \[TOTAL\]\s+(\d+\.\d+)% + + = f.submit 'Save changes', class: "btn btn-save" + +%hr + +.row.prepend-top-default + = render partial: 'badge', collection: @badges diff --git a/app/views/projects/settings/ci_cd/show.html.haml b/app/views/projects/settings/ci_cd/show.html.haml index d65341dbd40..09268c9943b 100644 --- a/app/views/projects/settings/ci_cd/show.html.haml +++ b/app/views/projects/settings/ci_cd/show.html.haml @@ -3,8 +3,9 @@ - page_title "CI / CD" - expanded = Rails.env.test? +- general_expanded = @project.errors.empty? ? expanded : true -%section.settings#js-general-pipeline-settings.no-animate{ class: ('expanded' if expanded) } +%section.settings#js-general-pipeline-settings.no-animate{ class: ('expanded' if general_expanded) } .settings-header %h4 General pipelines settings @@ -13,7 +14,7 @@ %p Update your CI/CD configuration, like job timeout or Auto DevOps. .settings-content - = render 'projects/pipelines_settings/show' + = render 'form' %section.settings.no-animate{ class: ('expanded' if expanded) } .settings-header diff --git a/config/routes/project.rb b/config/routes/project.rb index 48ba8ef06f9..0f2ea1c01d1 100644 --- a/config/routes/project.rb +++ b/config/routes/project.rb @@ -420,7 +420,7 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do end namespace :settings do get :members, to: redirect("%{namespace_id}/%{project_id}/project_members") - resource :ci_cd, only: [:show], controller: 'ci_cd' do + resource :ci_cd, only: [:show, :update], controller: 'ci_cd' do post :reset_cache end resource :integrations, only: [:show] diff --git a/spec/controllers/projects/pipelines_settings_controller_spec.rb b/spec/controllers/projects/pipelines_settings_controller_spec.rb index 913b9bd804a..694896b6bcf 100644 --- a/spec/controllers/projects/pipelines_settings_controller_spec.rb +++ b/spec/controllers/projects/pipelines_settings_controller_spec.rb @@ -11,82 +11,11 @@ describe Projects::PipelinesSettingsController do sign_in(user) end - describe 'PATCH update' do - subject do - patch :update, - namespace_id: project.namespace.to_param, - project_id: project, - project: { - auto_devops_attributes: params - } - end - - context 'when updating the auto_devops settings' do - let(:params) { { enabled: '', domain: 'mepmep.md' } } - - it 'redirects to the settings page' do - subject - - expect(response).to have_gitlab_http_status(302) - expect(flash[:notice]).to eq("Pipelines settings for '#{project.name}' were successfully updated.") - end - - context 'following the instance default' do - let(:params) { { enabled: '' } } - - it 'allows enabled to be set to nil' do - subject - project_auto_devops.reload - - expect(project_auto_devops.enabled).to be_nil - end - end - - context 'when run_auto_devops_pipeline is true' do - before do - expect_any_instance_of(Projects::UpdateService).to receive(:run_auto_devops_pipeline?).and_return(true) - end - - context 'when the project repository is empty' do - it 'sets a warning flash' do - expect(subject).to set_flash[:warning] - end - - it 'does not queue a CreatePipelineWorker' do - expect(CreatePipelineWorker).not_to receive(:perform_async).with(project.id, user.id, project.default_branch, :web, any_args) - - subject - end - end - - context 'when the project repository is not empty' do - let(:project) { create(:project, :repository) } - - it 'sets a success flash' do - allow(CreatePipelineWorker).to receive(:perform_async).with(project.id, user.id, project.default_branch, :web, any_args) - - expect(subject).to set_flash[:success] - end - - it 'queues a CreatePipelineWorker' do - expect(CreatePipelineWorker).to receive(:perform_async).with(project.id, user.id, project.default_branch, :web, any_args) - - subject - end - end - end - - context 'when run_auto_devops_pipeline is not true' do - before do - expect_any_instance_of(Projects::UpdateService).to receive(:run_auto_devops_pipeline?).and_return(false) - end - - it 'does not queue a CreatePipelineWorker' do - expect(CreatePipelineWorker).not_to receive(:perform_async).with(project.id, user.id, :web, any_args) + describe 'GET show' do + it 'redirects with 302 status code' do + get :show, namespace_id: project.namespace, project_id: project - subject - end - end + expect(response).to have_gitlab_http_status(302) end end end diff --git a/spec/controllers/projects/settings/ci_cd_controller_spec.rb b/spec/controllers/projects/settings/ci_cd_controller_spec.rb index 293e76798ae..330bd760040 100644 --- a/spec/controllers/projects/settings/ci_cd_controller_spec.rb +++ b/spec/controllers/projects/settings/ci_cd_controller_spec.rb @@ -1,8 +1,9 @@ require('spec_helper') describe Projects::Settings::CiCdController do - let(:project) { create(:project, :public, :access_requestable) } - let(:user) { create(:user) } + set(:user) { create(:user) } + set(:project_auto_devops) { create(:project_auto_devops) } + let(:project) { project_auto_devops.project } before do project.add_master(user) @@ -55,4 +56,83 @@ describe Projects::Settings::CiCdController do end end end + + describe 'PATCH update' do + subject do + patch :update, + namespace_id: project.namespace.to_param, + project_id: project, + project: { + auto_devops_attributes: params + } + end + + context 'when updating the auto_devops settings' do + let(:params) { { enabled: '', domain: 'mepmep.md' } } + + it 'redirects to the settings page' do + subject + + expect(response).to have_gitlab_http_status(302) + expect(flash[:notice]).to eq("Pipelines settings for '#{project.name}' were successfully updated.") + end + + context 'following the instance default' do + let(:params) { { enabled: '' } } + + it 'allows enabled to be set to nil' do + subject + project_auto_devops.reload + + expect(project_auto_devops.enabled).to be_nil + end + end + + context 'when run_auto_devops_pipeline is true' do + before do + expect_any_instance_of(Projects::UpdateService).to receive(:run_auto_devops_pipeline?).and_return(true) + end + + context 'when the project repository is empty' do + it 'sets a warning flash' do + expect(subject).to set_flash[:warning] + end + + it 'does not queue a CreatePipelineWorker' do + expect(CreatePipelineWorker).not_to receive(:perform_async).with(project.id, user.id, project.default_branch, :web, any_args) + + subject + end + end + + context 'when the project repository is not empty' do + let(:project) { create(:project, :repository) } + + it 'sets a success flash' do + allow(CreatePipelineWorker).to receive(:perform_async).with(project.id, user.id, project.default_branch, :web, any_args) + + expect(subject).to set_flash[:success] + end + + it 'queues a CreatePipelineWorker' do + expect(CreatePipelineWorker).to receive(:perform_async).with(project.id, user.id, project.default_branch, :web, any_args) + + subject + end + end + end + + context 'when run_auto_devops_pipeline is not true' do + before do + expect_any_instance_of(Projects::UpdateService).to receive(:run_auto_devops_pipeline?).and_return(false) + end + + it 'does not queue a CreatePipelineWorker' do + expect(CreatePipelineWorker).not_to receive(:perform_async).with(project.id, user.id, :web, any_args) + + subject + end + end + end + end end diff --git a/spec/features/projects/badges/list_spec.rb b/spec/features/projects/badges/list_spec.rb index c705e479690..0abef4bc447 100644 --- a/spec/features/projects/badges/list_spec.rb +++ b/spec/features/projects/badges/list_spec.rb @@ -6,7 +6,7 @@ feature 'list of badges' do project = create(:project, :repository) project.add_master(user) sign_in(user) - visit project_pipelines_settings_path(project) + visit project_settings_ci_cd_path(project) end scenario 'user wants to see build status badge' do diff --git a/spec/views/projects/pipelines_settings/_show.html.haml_spec.rb b/spec/views/projects/pipelines_settings/_show.html.haml_spec.rb deleted file mode 100644 index 7b300150874..00000000000 --- a/spec/views/projects/pipelines_settings/_show.html.haml_spec.rb +++ /dev/null @@ -1,62 +0,0 @@ -require 'spec_helper' - -describe 'projects/pipelines_settings/_show' do - let(:project) { create(:project, :repository) } - - before do - assign :project, project - end - - context 'when kubernetes is not active' do - context 'when auto devops domain is not defined' do - it 'shows warning message' do - render - - expect(rendered).to have_css('.settings-message') - expect(rendered).to have_text('Auto Review Apps and Auto Deploy need a domain name and a') - expect(rendered).to have_link('Kubernetes cluster') - end - end - - context 'when auto devops domain is defined' do - before do - project.build_auto_devops(domain: 'example.com') - end - - it 'shows warning message' do - render - - expect(rendered).to have_css('.settings-message') - expect(rendered).to have_text('Auto Review Apps and Auto Deploy need a') - expect(rendered).to have_link('Kubernetes cluster') - end - end - end - - context 'when kubernetes is active' do - before do - create(:kubernetes_service, project: project) - end - - context 'when auto devops domain is not defined' do - it 'shows warning message' do - render - - expect(rendered).to have_css('.settings-message') - expect(rendered).to have_text('Auto Review Apps and Auto Deploy need a domain name to work correctly.') - end - end - - context 'when auto devops domain is defined' do - before do - project.build_auto_devops(domain: 'example.com') - end - - it 'does not show warning message' do - render - - expect(rendered).not_to have_css('.settings-message') - end - end - end -end diff --git a/spec/views/projects/settings/ci_cd/_form.html.haml_spec.rb b/spec/views/projects/settings/ci_cd/_form.html.haml_spec.rb new file mode 100644 index 00000000000..be9a4d9c57c --- /dev/null +++ b/spec/views/projects/settings/ci_cd/_form.html.haml_spec.rb @@ -0,0 +1,62 @@ +require 'spec_helper' + +describe 'projects/settings/ci_cd/_form' do + let(:project) { create(:project, :repository) } + + before do + assign :project, project + end + + context 'when kubernetes is not active' do + context 'when auto devops domain is not defined' do + it 'shows warning message' do + render + + expect(rendered).to have_css('.settings-message') + expect(rendered).to have_text('Auto Review Apps and Auto Deploy need a domain name and a') + expect(rendered).to have_link('Kubernetes cluster') + end + end + + context 'when auto devops domain is defined' do + before do + project.build_auto_devops(domain: 'example.com') + end + + it 'shows warning message' do + render + + expect(rendered).to have_css('.settings-message') + expect(rendered).to have_text('Auto Review Apps and Auto Deploy need a') + expect(rendered).to have_link('Kubernetes cluster') + end + end + end + + context 'when kubernetes is active' do + before do + create(:kubernetes_service, project: project) + end + + context 'when auto devops domain is not defined' do + it 'shows warning message' do + render + + expect(rendered).to have_css('.settings-message') + expect(rendered).to have_text('Auto Review Apps and Auto Deploy need a domain name to work correctly.') + end + end + + context 'when auto devops domain is defined' do + before do + project.build_auto_devops(domain: 'example.com') + end + + it 'does not show warning message' do + render + + expect(rendered).not_to have_css('.settings-message') + end + end + end +end -- cgit v1.2.1