diff options
-rw-r--r-- | app/controllers/clusters/clusters_controller.rb | 27 | ||||
-rw-r--r-- | app/services/clusters/build_service.rb | 21 | ||||
-rw-r--r-- | spec/services/clusters/build_service_spec.rb | 25 |
3 files changed, 52 insertions, 21 deletions
diff --git a/app/controllers/clusters/clusters_controller.rb b/app/controllers/clusters/clusters_controller.rb index cb6f49e608c..9aa8b758539 100644 --- a/app/controllers/clusters/clusters_controller.rb +++ b/app/controllers/clusters/clusters_controller.rb @@ -181,30 +181,15 @@ class Clusters::ClustersController < Clusters::BaseController end def gcp_cluster - @gcp_cluster = new_cluster do |cluster| - cluster.build_provider_gcp - end + cluster = Clusters::BuildService.new(clusterable.subject).execute + cluster.build_provider_gcp + @gcp_cluster = cluster.present(current_user: current_user) end def user_cluster - @user_cluster = new_cluster do |cluster| - cluster.build_platform_kubernetes - end - end - - def new_cluster - ::Clusters::Cluster.new.tap do |cluster| - yield cluster - - case clusterable.subject - when ::Project - cluster.cluster_type = :project_type - when ::Group - cluster.cluster_type = :group_type - else - raise NotImplementedError - end - end.present(current_user: current_user) + cluster = Clusters::BuildService.new(clusterable.subject).execute + cluster.build_platform_kubernetes + @user_cluster = cluster.present(current_user: current_user) end def validate_gcp_token diff --git a/app/services/clusters/build_service.rb b/app/services/clusters/build_service.rb new file mode 100644 index 00000000000..8de73831164 --- /dev/null +++ b/app/services/clusters/build_service.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true +module Clusters + class BuildService + def initialize(subject) + @subject = subject + end + + def execute + ::Clusters::Cluster.new.tap do |cluster| + case @subject + when ::Project + cluster.cluster_type = :project_type + when ::Group + cluster.cluster_type = :group_type + else + raise NotImplementedError + end + end + end + end +end diff --git a/spec/services/clusters/build_service_spec.rb b/spec/services/clusters/build_service_spec.rb new file mode 100644 index 00000000000..da0cb42b3a1 --- /dev/null +++ b/spec/services/clusters/build_service_spec.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Clusters::BuildService do + describe '#execute' do + subject { described_class.new(cluster_subject).execute } + + describe 'when cluster subject is a project' do + let(:cluster_subject) { build(:project) } + + it 'sets the cluster_type to project_type' do + is_expected.to be_project_type + end + end + + describe 'when cluster subject is a group' do + let(:cluster_subject) { build(:group) } + + it 'sets the cluster_type to group_type' do + is_expected.to be_group_type + end + end + end +end |