Commit ecda32ea authored by Dylan Griffith's avatar Dylan Griffith Committed by Bob Van Landuyt

Extract Clusters::BuildService

parent 01dc3c96
......@@ -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
......
# 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
# 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
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