summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThong Kuah <tkuah@gitlab.com>2018-10-15 16:37:51 +1300
committerThong Kuah <tkuah@gitlab.com>2018-11-01 18:38:36 +1300
commit5b3c096c9e0c9e8e7e1cb35c1b9e347995b948f5 (patch)
treef0e4934cd4bbf59d670ff8911e64d94602907259
parent5a953741820b78492333e1543062a5c222694d8c (diff)
downloadgitlab-ce-5b3c096c9e0c9e8e7e1cb35c1b9e347995b948f5.tar.gz
Convert clusters to use a top-level controller
In preparation so that we can create both cluster attached to project and cluster attached to group. - Move ClustersController to top level - Move Clusters::ApplicationsController to top-level too - Creates a Clusters::BaseController to share common functions - Do not rely on @project ivar. Anything could set the ivar. - Fix Vue page components due to new data-page value Because of the controller change we have gone from `projects:clusters:new` to `clusters:new`, so we need to update the file location of the page components. There is somewhere a function that will convert data-page to a file location. On that note, projects/clusters/gcp/new/, translate to Projects::Clusters::Gcp#new doesn't exist so replace that with clusters/create_gcp/ and clusters/create_user/
-rw-r--r--app/assets/javascripts/pages/clusters/create_gcp/index.js (renamed from app/assets/javascripts/pages/projects/clusters/gcp/new/index.js)2
-rw-r--r--app/assets/javascripts/pages/clusters/create_user/index.js7
-rw-r--r--app/assets/javascripts/pages/clusters/destroy/index.js (renamed from app/assets/javascripts/pages/projects/clusters/destroy/index.js)0
-rw-r--r--app/assets/javascripts/pages/clusters/index/index.js (renamed from app/assets/javascripts/pages/projects/clusters/index/index.js)0
-rw-r--r--app/assets/javascripts/pages/clusters/new/index.js7
-rw-r--r--app/assets/javascripts/pages/clusters/show/index.js (renamed from app/assets/javascripts/pages/projects/clusters/show/index.js)0
-rw-r--r--app/assets/javascripts/pages/clusters/update/index.js (renamed from app/assets/javascripts/pages/projects/clusters/update/index.js)0
-rw-r--r--app/assets/javascripts/pages/projects/index.js14
-rw-r--r--app/controllers/clusters/applications_controller.rb (renamed from app/controllers/projects/clusters/applications_controller.rb)3
-rw-r--r--app/controllers/clusters/base_controller.rb42
-rw-r--r--app/controllers/clusters_controller.rb (renamed from app/controllers/projects/clusters_controller.rb)16
-rw-r--r--app/helpers/clusters_helper.rb2
-rw-r--r--app/views/clusters/_advanced_settings.html.haml (renamed from app/views/projects/clusters/_advanced_settings.html.haml)0
-rw-r--r--app/views/clusters/_banner.html.haml (renamed from app/views/projects/clusters/_banner.html.haml)0
-rw-r--r--app/views/clusters/_cluster.html.haml (renamed from app/views/projects/clusters/_cluster.html.haml)0
-rw-r--r--app/views/clusters/_empty_state.html.haml (renamed from app/views/projects/clusters/_empty_state.html.haml)0
-rw-r--r--app/views/clusters/_gcp_signup_offer_banner.html.haml (renamed from app/views/projects/clusters/_gcp_signup_offer_banner.html.haml)0
-rw-r--r--app/views/clusters/_integration_form.html.haml (renamed from app/views/projects/clusters/_integration_form.html.haml)0
-rw-r--r--app/views/clusters/_sidebar.html.haml (renamed from app/views/projects/clusters/_sidebar.html.haml)0
-rw-r--r--app/views/clusters/gcp/_form.html.haml (renamed from app/views/projects/clusters/gcp/_form.html.haml)0
-rw-r--r--app/views/clusters/gcp/_header.html.haml (renamed from app/views/projects/clusters/gcp/_header.html.haml)0
-rw-r--r--app/views/clusters/gcp/_show.html.haml (renamed from app/views/projects/clusters/gcp/_show.html.haml)0
-rw-r--r--app/views/clusters/index.html.haml (renamed from app/views/projects/clusters/index.html.haml)0
-rw-r--r--app/views/clusters/new.html.haml (renamed from app/views/projects/clusters/new.html.haml)8
-rw-r--r--app/views/clusters/show.html.haml (renamed from app/views/projects/clusters/show.html.haml)4
-rw-r--r--app/views/clusters/user/_form.html.haml (renamed from app/views/projects/clusters/user/_form.html.haml)0
-rw-r--r--app/views/clusters/user/_header.html.haml (renamed from app/views/projects/clusters/user/_header.html.haml)0
-rw-r--r--app/views/clusters/user/_show.html.haml (renamed from app/views/projects/clusters/user/_show.html.haml)0
-rw-r--r--changelogs/unreleased/top_level_clusters_controller.yml6
-rw-r--r--config/routes.rb17
-rw-r--r--config/routes/project.rb15
-rw-r--r--qa/qa/page/project/operations/kubernetes/add.rb2
-rw-r--r--qa/qa/page/project/operations/kubernetes/add_existing.rb2
-rw-r--r--qa/qa/page/project/operations/kubernetes/index.rb2
-rw-r--r--spec/controllers/clusters/applications_controller_spec.rb (renamed from spec/controllers/projects/clusters/applications_controller_spec.rb)4
-rw-r--r--spec/controllers/clusters_controller_spec.rb (renamed from spec/controllers/projects/clusters_controller_spec.rb)37
-rw-r--r--spec/features/projects/clusters/gcp_spec.rb6
-rw-r--r--spec/features/projects/clusters/user_spec.rb2
38 files changed, 136 insertions, 62 deletions
diff --git a/app/assets/javascripts/pages/projects/clusters/gcp/new/index.js b/app/assets/javascripts/pages/clusters/create_gcp/index.js
index d4f34e32a48..e7c8cc4ab5f 100644
--- a/app/assets/javascripts/pages/projects/clusters/gcp/new/index.js
+++ b/app/assets/javascripts/pages/clusters/create_gcp/index.js
@@ -1,5 +1,7 @@
+import initDismissableCallout from '~/dismissable_callout';
import initGkeDropdowns from '~/projects/gke_cluster_dropdowns';
document.addEventListener('DOMContentLoaded', () => {
+ initDismissableCallout('.gcp-signup-offer');
initGkeDropdowns();
});
diff --git a/app/assets/javascripts/pages/clusters/create_user/index.js b/app/assets/javascripts/pages/clusters/create_user/index.js
new file mode 100644
index 00000000000..e7c8cc4ab5f
--- /dev/null
+++ b/app/assets/javascripts/pages/clusters/create_user/index.js
@@ -0,0 +1,7 @@
+import initDismissableCallout from '~/dismissable_callout';
+import initGkeDropdowns from '~/projects/gke_cluster_dropdowns';
+
+document.addEventListener('DOMContentLoaded', () => {
+ initDismissableCallout('.gcp-signup-offer');
+ initGkeDropdowns();
+});
diff --git a/app/assets/javascripts/pages/projects/clusters/destroy/index.js b/app/assets/javascripts/pages/clusters/destroy/index.js
index 8001d2dd1da..8001d2dd1da 100644
--- a/app/assets/javascripts/pages/projects/clusters/destroy/index.js
+++ b/app/assets/javascripts/pages/clusters/destroy/index.js
diff --git a/app/assets/javascripts/pages/projects/clusters/index/index.js b/app/assets/javascripts/pages/clusters/index/index.js
index e4b8baede58..e4b8baede58 100644
--- a/app/assets/javascripts/pages/projects/clusters/index/index.js
+++ b/app/assets/javascripts/pages/clusters/index/index.js
diff --git a/app/assets/javascripts/pages/clusters/new/index.js b/app/assets/javascripts/pages/clusters/new/index.js
new file mode 100644
index 00000000000..e7c8cc4ab5f
--- /dev/null
+++ b/app/assets/javascripts/pages/clusters/new/index.js
@@ -0,0 +1,7 @@
+import initDismissableCallout from '~/dismissable_callout';
+import initGkeDropdowns from '~/projects/gke_cluster_dropdowns';
+
+document.addEventListener('DOMContentLoaded', () => {
+ initDismissableCallout('.gcp-signup-offer');
+ initGkeDropdowns();
+});
diff --git a/app/assets/javascripts/pages/projects/clusters/show/index.js b/app/assets/javascripts/pages/clusters/show/index.js
index 8001d2dd1da..8001d2dd1da 100644
--- a/app/assets/javascripts/pages/projects/clusters/show/index.js
+++ b/app/assets/javascripts/pages/clusters/show/index.js
diff --git a/app/assets/javascripts/pages/projects/clusters/update/index.js b/app/assets/javascripts/pages/clusters/update/index.js
index 8001d2dd1da..8001d2dd1da 100644
--- a/app/assets/javascripts/pages/projects/clusters/update/index.js
+++ b/app/assets/javascripts/pages/clusters/update/index.js
diff --git a/app/assets/javascripts/pages/projects/index.js b/app/assets/javascripts/pages/projects/index.js
index 5659e13981a..8e0af018b61 100644
--- a/app/assets/javascripts/pages/projects/index.js
+++ b/app/assets/javascripts/pages/projects/index.js
@@ -1,21 +1,7 @@
-import initDismissableCallout from '~/dismissable_callout';
-import initGkeDropdowns from '~/projects/gke_cluster_dropdowns';
import Project from './project';
import ShortcutsNavigation from '../../behaviors/shortcuts/shortcuts_navigation';
document.addEventListener('DOMContentLoaded', () => {
- const { page } = document.body.dataset;
- const newClusterViews = [
- 'projects:clusters:new',
- 'projects:clusters:create_gcp',
- 'projects:clusters:create_user',
- ];
-
- if (newClusterViews.indexOf(page) > -1) {
- initDismissableCallout('.gcp-signup-offer');
- initGkeDropdowns();
- }
-
new Project(); // eslint-disable-line no-new
new ShortcutsNavigation(); // eslint-disable-line no-new
});
diff --git a/app/controllers/projects/clusters/applications_controller.rb b/app/controllers/clusters/applications_controller.rb
index bcea96bce94..a5ac5fe3f8e 100644
--- a/app/controllers/projects/clusters/applications_controller.rb
+++ b/app/controllers/clusters/applications_controller.rb
@@ -1,8 +1,7 @@
# frozen_string_literal: true
-class Projects::Clusters::ApplicationsController < Projects::ApplicationController
+class Clusters::ApplicationsController < Clusters::BaseController
before_action :cluster
- before_action :authorize_read_cluster!
before_action :authorize_create_cluster!, only: [:create]
def create
diff --git a/app/controllers/clusters/base_controller.rb b/app/controllers/clusters/base_controller.rb
new file mode 100644
index 00000000000..2804b236d17
--- /dev/null
+++ b/app/controllers/clusters/base_controller.rb
@@ -0,0 +1,42 @@
+# frozen_string_literal: true
+
+class Clusters::BaseController < ApplicationController
+ include RoutableActions
+
+ skip_before_action :authenticate_user!
+ before_action :require_project_id
+ before_action :project, if: :project_type?
+ before_action :repository, if: :project_type?
+ before_action :authorize_read_cluster!
+
+ private
+
+ # We can extend to `#group_type?` in the future
+ def require_project_id
+ not_found unless project_type?
+ end
+
+ def project
+ @project ||= find_routable!(Project, File.join(params[:namespace_id], params[:project_id]))
+ end
+
+ def repository
+ @repository ||= project.repository
+ end
+
+ def authorize_read_cluster!
+ access_denied! unless can?(current_user, :read_cluster, clusterable)
+ end
+
+ def authorize_create_cluster!
+ access_denied! unless can?(current_user, :create_cluster, clusterable)
+ end
+
+ def clusterable
+ project if project_type?
+ end
+
+ def project_type?
+ params[:project_id].present?
+ end
+end
diff --git a/app/controllers/projects/clusters_controller.rb b/app/controllers/clusters_controller.rb
index 62adc66fb09..5cf4e44c4ed 100644
--- a/app/controllers/projects/clusters_controller.rb
+++ b/app/controllers/clusters_controller.rb
@@ -1,8 +1,7 @@
# frozen_string_literal: true
-class Projects::ClustersController < Projects::ApplicationController
+class ClustersController < Clusters::BaseController
before_action :cluster, except: [:index, :new, :create_gcp, :create_user]
- before_action :authorize_read_cluster!
before_action :generate_gcp_authorize_url, only: [:new]
before_action :validate_gcp_token, only: [:new]
before_action :gcp_cluster, only: [:new]
@@ -11,6 +10,9 @@ class Projects::ClustersController < Projects::ApplicationController
before_action :authorize_update_cluster!, only: [:update]
before_action :authorize_admin_cluster!, only: [:destroy]
before_action :update_applications_status, only: [:status]
+
+ layout :determine_layout
+
helper_method :token_in_session
STATUS_POLLING_INTERVAL = 10_000
@@ -29,7 +31,7 @@ class Projects::ClustersController < Projects::ApplicationController
Gitlab::PollingInterval.set_header(response, interval: STATUS_POLLING_INTERVAL)
render json: ClusterSerializer
- .new(project: @project, current_user: @current_user)
+ .new(project: project, current_user: @current_user)
.represent_status(@cluster)
end
end
@@ -105,6 +107,12 @@ class Projects::ClustersController < Projects::ApplicationController
private
+ def determine_layout
+ if project_type?
+ 'project'
+ end
+ end
+
def cluster
@cluster ||= project.clusters.find(params[:id])
.present(current_user: current_user)
@@ -169,7 +177,7 @@ class Projects::ClustersController < Projects::ApplicationController
end
def generate_gcp_authorize_url
- state = generate_session_key_redirect(new_project_cluster_path(@project).to_s)
+ state = generate_session_key_redirect(new_project_cluster_path(project).to_s)
@authorize_url = GoogleApi::CloudPlatform::Client.new(
nil, callback_google_api_auth_url,
diff --git a/app/helpers/clusters_helper.rb b/app/helpers/clusters_helper.rb
index 19eb763e1de..21ee95a6f20 100644
--- a/app/helpers/clusters_helper.rb
+++ b/app/helpers/clusters_helper.rb
@@ -10,7 +10,7 @@ module ClustersHelper
return unless show_gcp_signup_offer?
content_tag :section, class: 'no-animate expanded' do
- render 'projects/clusters/gcp_signup_offer_banner'
+ render 'clusters/gcp_signup_offer_banner'
end
end
end
diff --git a/app/views/projects/clusters/_advanced_settings.html.haml b/app/views/clusters/_advanced_settings.html.haml
index 243e8cd9ba0..243e8cd9ba0 100644
--- a/app/views/projects/clusters/_advanced_settings.html.haml
+++ b/app/views/clusters/_advanced_settings.html.haml
diff --git a/app/views/projects/clusters/_banner.html.haml b/app/views/clusters/_banner.html.haml
index 73cfea0ef92..73cfea0ef92 100644
--- a/app/views/projects/clusters/_banner.html.haml
+++ b/app/views/clusters/_banner.html.haml
diff --git a/app/views/projects/clusters/_cluster.html.haml b/app/views/clusters/_cluster.html.haml
index 2d7f7c6b1fb..2d7f7c6b1fb 100644
--- a/app/views/projects/clusters/_cluster.html.haml
+++ b/app/views/clusters/_cluster.html.haml
diff --git a/app/views/projects/clusters/_empty_state.html.haml b/app/views/clusters/_empty_state.html.haml
index b8a3556a206..b8a3556a206 100644
--- a/app/views/projects/clusters/_empty_state.html.haml
+++ b/app/views/clusters/_empty_state.html.haml
diff --git a/app/views/projects/clusters/_gcp_signup_offer_banner.html.haml b/app/views/clusters/_gcp_signup_offer_banner.html.haml
index 73b11d509d3..73b11d509d3 100644
--- a/app/views/projects/clusters/_gcp_signup_offer_banner.html.haml
+++ b/app/views/clusters/_gcp_signup_offer_banner.html.haml
diff --git a/app/views/projects/clusters/_integration_form.html.haml b/app/views/clusters/_integration_form.html.haml
index d0a553e3414..d0a553e3414 100644
--- a/app/views/projects/clusters/_integration_form.html.haml
+++ b/app/views/clusters/_integration_form.html.haml
diff --git a/app/views/projects/clusters/_sidebar.html.haml b/app/views/clusters/_sidebar.html.haml
index 3d10348212f..3d10348212f 100644
--- a/app/views/projects/clusters/_sidebar.html.haml
+++ b/app/views/clusters/_sidebar.html.haml
diff --git a/app/views/projects/clusters/gcp/_form.html.haml b/app/views/clusters/gcp/_form.html.haml
index 171ceeceb68..171ceeceb68 100644
--- a/app/views/projects/clusters/gcp/_form.html.haml
+++ b/app/views/clusters/gcp/_form.html.haml
diff --git a/app/views/projects/clusters/gcp/_header.html.haml b/app/views/clusters/gcp/_header.html.haml
index a2ad3cd64df..a2ad3cd64df 100644
--- a/app/views/projects/clusters/gcp/_header.html.haml
+++ b/app/views/clusters/gcp/_header.html.haml
diff --git a/app/views/projects/clusters/gcp/_show.html.haml b/app/views/clusters/gcp/_show.html.haml
index 779c9c245c1..779c9c245c1 100644
--- a/app/views/projects/clusters/gcp/_show.html.haml
+++ b/app/views/clusters/gcp/_show.html.haml
diff --git a/app/views/projects/clusters/index.html.haml b/app/views/clusters/index.html.haml
index a55de84b5cd..a55de84b5cd 100644
--- a/app/views/projects/clusters/index.html.haml
+++ b/app/views/clusters/index.html.haml
diff --git a/app/views/projects/clusters/new.html.haml b/app/views/clusters/new.html.haml
index a38003f5750..57cdbcd2d38 100644
--- a/app/views/projects/clusters/new.html.haml
+++ b/app/views/clusters/new.html.haml
@@ -19,9 +19,9 @@
.tab-content.gitlab-tab-content
.tab-pane{ id: 'create-gcp-cluster-pane', class: active_when(active_tab == 'gcp'), role: 'tabpanel' }
- = render 'projects/clusters/gcp/header'
+ = render 'clusters/gcp/header'
- if @valid_gcp_token
- = render 'projects/clusters/gcp/form'
+ = render 'clusters/gcp/form'
- elsif @authorize_url
.signin-with-google
= link_to(image_tag('auth_buttons/signin_with_google.png', width: '191px'), @authorize_url)
@@ -32,5 +32,5 @@
= s_('Google authentication is not %{link_to_documentation}. Ask your GitLab administrator if you want to use this service.').html_safe % { link_to_documentation: link }
.tab-pane{ id: 'add-user-cluster-pane', class: active_when(active_tab == 'user'), role: 'tabpanel' }
- = render 'projects/clusters/user/header'
- = render 'projects/clusters/user/form'
+ = render 'clusters/user/header'
+ = render 'clusters/user/form'
diff --git a/app/views/projects/clusters/show.html.haml b/app/views/clusters/show.html.haml
index eddd3613c5f..14416303827 100644
--- a/app/views/projects/clusters/show.html.haml
+++ b/app/views/clusters/show.html.haml
@@ -38,9 +38,9 @@
%p= s_('ClusterIntegration|See and edit the details for your Kubernetes cluster')
.settings-content
- if @cluster.managed?
- = render 'projects/clusters/gcp/show'
+ = render 'clusters/gcp/show'
- else
- = render 'projects/clusters/user/show'
+ = render 'clusters/user/show'
%section.settings.no-animate#js-cluster-advanced-settings{ class: ('expanded' if expanded) }
.settings-header
diff --git a/app/views/projects/clusters/user/_form.html.haml b/app/views/clusters/user/_form.html.haml
index 54a6e685bb0..54a6e685bb0 100644
--- a/app/views/projects/clusters/user/_form.html.haml
+++ b/app/views/clusters/user/_form.html.haml
diff --git a/app/views/projects/clusters/user/_header.html.haml b/app/views/clusters/user/_header.html.haml
index 749177fa6c1..749177fa6c1 100644
--- a/app/views/projects/clusters/user/_header.html.haml
+++ b/app/views/clusters/user/_header.html.haml
diff --git a/app/views/projects/clusters/user/_show.html.haml b/app/views/clusters/user/_show.html.haml
index 5b57f7ceb7d..5b57f7ceb7d 100644
--- a/app/views/projects/clusters/user/_show.html.haml
+++ b/app/views/clusters/user/_show.html.haml
diff --git a/changelogs/unreleased/top_level_clusters_controller.yml b/changelogs/unreleased/top_level_clusters_controller.yml
new file mode 100644
index 00000000000..1fe1d048de4
--- /dev/null
+++ b/changelogs/unreleased/top_level_clusters_controller.yml
@@ -0,0 +1,6 @@
+---
+title: Change to top level controller for clusters so that we can use it for project
+ clusters (now) and group clusters (later)
+merge_request: 22438
+author:
+type: other
diff --git a/config/routes.rb b/config/routes.rb
index 37c7f98ec98..cfb81cabfe4 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -84,6 +84,23 @@ Rails.application.routes.draw do
draw :instance_statistics
end
+ concern :clusterable do
+ resources :clusters, except: [:edit, :create], controller: '/clusters' do
+ collection do
+ post :create_gcp
+ post :create_user
+ end
+
+ member do
+ get :status, format: :json
+
+ scope :applications do
+ post '/:application', to: '/clusters/applications#create', as: :install_applications
+ end
+ end
+ end
+ end
+
draw :api
draw :sidekiq
draw :help
diff --git a/config/routes/project.rb b/config/routes/project.rb
index 73c46f72168..387d2363552 100644
--- a/config/routes/project.rb
+++ b/config/routes/project.rb
@@ -206,20 +206,7 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
end
end
- resources :clusters, except: [:edit, :create] do
- collection do
- post :create_gcp
- post :create_user
- end
-
- member do
- get :status, format: :json
-
- scope :applications do
- post '/:application', to: 'clusters/applications#create', as: :install_applications
- end
- end
- end
+ concerns :clusterable
resources :environments, except: [:destroy] do
member do
diff --git a/qa/qa/page/project/operations/kubernetes/add.rb b/qa/qa/page/project/operations/kubernetes/add.rb
index 18c16ca6db7..0128fbefebd 100644
--- a/qa/qa/page/project/operations/kubernetes/add.rb
+++ b/qa/qa/page/project/operations/kubernetes/add.rb
@@ -4,7 +4,7 @@ module QA
module Operations
module Kubernetes
class Add < Page::Base
- view 'app/views/projects/clusters/new.html.haml' do
+ view 'app/views/clusters/new.html.haml' do
element :add_existing_cluster_button, "Add existing cluster" # rubocop:disable QA/ElementWithPattern
end
diff --git a/qa/qa/page/project/operations/kubernetes/add_existing.rb b/qa/qa/page/project/operations/kubernetes/add_existing.rb
index f8e026b4405..c2fa920641d 100644
--- a/qa/qa/page/project/operations/kubernetes/add_existing.rb
+++ b/qa/qa/page/project/operations/kubernetes/add_existing.rb
@@ -4,7 +4,7 @@ module QA
module Operations
module Kubernetes
class AddExisting < Page::Base
- view 'app/views/projects/clusters/user/_form.html.haml' do
+ view 'app/views/clusters/user/_form.html.haml' do
element :cluster_name, 'text_field :name' # rubocop:disable QA/ElementWithPattern
element :api_url, 'text_field :api_url' # rubocop:disable QA/ElementWithPattern
element :ca_certificate, 'text_area :ca_cert' # rubocop:disable QA/ElementWithPattern
diff --git a/qa/qa/page/project/operations/kubernetes/index.rb b/qa/qa/page/project/operations/kubernetes/index.rb
index 312b459ac89..13197c5fae4 100644
--- a/qa/qa/page/project/operations/kubernetes/index.rb
+++ b/qa/qa/page/project/operations/kubernetes/index.rb
@@ -4,7 +4,7 @@ module QA
module Operations
module Kubernetes
class Index < Page::Base
- view 'app/views/projects/clusters/_empty_state.html.haml' do
+ view 'app/views/clusters/_empty_state.html.haml' do
element :add_kubernetes_cluster_button, "link_to s_('ClusterIntegration|Add Kubernetes cluster')" # rubocop:disable QA/ElementWithPattern
end
diff --git a/spec/controllers/projects/clusters/applications_controller_spec.rb b/spec/controllers/clusters/applications_controller_spec.rb
index 9e17e392d3d..12846795f3e 100644
--- a/spec/controllers/projects/clusters/applications_controller_spec.rb
+++ b/spec/controllers/clusters/applications_controller_spec.rb
@@ -1,6 +1,8 @@
+# frozen_string_literal: true
+
require 'spec_helper'
-describe Projects::Clusters::ApplicationsController do
+describe Clusters::ApplicationsController do
include AccessMatchersForController
def current_application
diff --git a/spec/controllers/projects/clusters_controller_spec.rb b/spec/controllers/clusters_controller_spec.rb
index 9201332c5c8..459157e4ad1 100644
--- a/spec/controllers/projects/clusters_controller_spec.rb
+++ b/spec/controllers/clusters_controller_spec.rb
@@ -1,6 +1,8 @@
+# frozen_string_literal: true
+
require 'spec_helper'
-describe Projects::ClustersController do
+describe ClustersController do
include AccessMatchersForController
include GoogleApi::CloudPlatformHelpers
@@ -218,9 +220,9 @@ describe Projects::ClustersController do
describe 'security' do
before do
allow_any_instance_of(described_class)
- .to receive(:token_in_session).and_return('token')
+ .to receive(:token_in_session).and_return('token')
allow_any_instance_of(described_class)
- .to receive(:expires_at_in_session).and_return(1.hour.since.to_i.to_s)
+ .to receive(:expires_at_in_session).and_return(1.hour.since.to_i.to_s)
allow_any_instance_of(GoogleApi::CloudPlatform::Client)
.to receive(:projects_zones_clusters_create) do
OpenStruct.new(
@@ -322,10 +324,11 @@ describe Projects::ClustersController do
let(:cluster) { create(:cluster, :providing_by_gcp, projects: [project]) }
def go
- get :status, namespace_id: project.namespace,
- project_id: project,
- id: cluster,
- format: :json
+ get :status,
+ namespace_id: project.namespace,
+ project_id: project,
+ id: cluster,
+ format: :json
end
describe 'functionality' do
@@ -359,9 +362,10 @@ describe Projects::ClustersController do
let(:cluster) { create(:cluster, :provided_by_gcp, projects: [project]) }
def go
- get :show, namespace_id: project.namespace,
- project_id: project,
- id: cluster
+ get :show,
+ namespace_id: project.namespace,
+ project_id: project,
+ id: cluster
end
describe 'functionality' do
@@ -530,9 +534,10 @@ describe Projects::ClustersController do
let!(:cluster) { create(:cluster, :provided_by_gcp, :production_environment, projects: [project]) }
def go
- delete :destroy, namespace_id: project.namespace,
- project_id: project,
- id: cluster
+ delete :destroy,
+ namespace_id: project.namespace,
+ project_id: project,
+ id: cluster
end
describe 'functionality' do
@@ -591,4 +596,10 @@ describe Projects::ClustersController do
it { expect { go }.to be_denied_for(:external) }
end
end
+
+ context 'no project_id param' do
+ it 'does not respond to any action without project_id param' do
+ expect { get :index }.to raise_error(ActionController::UrlGenerationError)
+ end
+ end
end
diff --git a/spec/features/projects/clusters/gcp_spec.rb b/spec/features/projects/clusters/gcp_spec.rb
index 8b92b9fc869..e9f230b2be0 100644
--- a/spec/features/projects/clusters/gcp_spec.rb
+++ b/spec/features/projects/clusters/gcp_spec.rb
@@ -9,16 +9,16 @@ describe 'Gcp Cluster', :js do
before do
project.add_maintainer(user)
gitlab_sign_in(user)
- allow(Projects::ClustersController).to receive(:STATUS_POLLING_INTERVAL) { 100 }
+ allow(ClustersController).to receive(:STATUS_POLLING_INTERVAL) { 100 }
end
context 'when user has signed with Google' do
let(:project_id) { 'test-project-1234' }
before do
- allow_any_instance_of(Projects::ClustersController)
+ allow_any_instance_of(ClustersController)
.to receive(:token_in_session).and_return('token')
- allow_any_instance_of(Projects::ClustersController)
+ allow_any_instance_of(ClustersController)
.to receive(:expires_at_in_session).and_return(1.hour.since.to_i.to_s)
end
diff --git a/spec/features/projects/clusters/user_spec.rb b/spec/features/projects/clusters/user_spec.rb
index 9ae1dba60b5..b8bc7f490a6 100644
--- a/spec/features/projects/clusters/user_spec.rb
+++ b/spec/features/projects/clusters/user_spec.rb
@@ -9,7 +9,7 @@ describe 'User Cluster', :js do
before do
project.add_maintainer(user)
gitlab_sign_in(user)
- allow(Projects::ClustersController).to receive(:STATUS_POLLING_INTERVAL) { 100 }
+ allow(ClustersController).to receive(:STATUS_POLLING_INTERVAL) { 100 }
end
context 'when user does not have a cluster and visits cluster index page' do