Add ClusterPresenter. Fix Static Analysys.
This commit is contained in:
parent
d27b113b49
commit
6712762b9d
|
@ -81,7 +81,7 @@ class Projects::ClustersController < Projects::ApplicationController
|
|||
private
|
||||
|
||||
def cluster
|
||||
@cluster ||= project.cluster
|
||||
@cluster ||= project.cluster.present(current_user: current_user)
|
||||
end
|
||||
|
||||
def create_params
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
module Gcp
|
||||
class Cluster < ActiveRecord::Base
|
||||
extend Gitlab::Gcp::Model
|
||||
include Presentable
|
||||
|
||||
belongs_to :project, inverse_of: :cluster
|
||||
belongs_to :user
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
module Gcp
|
||||
class ClusterPresenter < Gitlab::View::Presenter::Delegated
|
||||
presents :cluster
|
||||
|
||||
def gke_cluster_url
|
||||
"https://console.cloud.google.com/kubernetes/clusters/details/#{gcp_cluster_zone}/#{gcp_cluster_name}"
|
||||
end
|
||||
end
|
||||
end
|
|
@ -37,7 +37,7 @@
|
|||
%label
|
||||
= s_('ClusterIntegration|Google container engine')
|
||||
%p
|
||||
- link_gke = link_to(s_('ClusterIntegration|Google Container Engine'), '', target: '_blank', rel: 'noopener noreferrer')
|
||||
- link_gke = link_to(s_('ClusterIntegration|Google Container Engine'), @cluster.gke_cluster_url, target: '_blank', rel: 'noopener noreferrer')
|
||||
= s_('ClusterIntegration|Manage your cluster by visiting %{link_gke}').html_safe % { link_gke: link_gke }
|
||||
|
||||
.hidden.js-cluster-error.alert.alert-danger{ role: 'alert' }
|
||||
|
|
|
@ -100,9 +100,8 @@ describe Projects::ClustersController do
|
|||
|
||||
describe 'POST create' do
|
||||
subject do
|
||||
post :create, params.merge(
|
||||
namespace_id: project.namespace,
|
||||
project_id: project)
|
||||
post :create, params.merge(namespace_id: project.namespace,
|
||||
project_id: project)
|
||||
end
|
||||
|
||||
context 'when not logged' do
|
||||
|
@ -121,7 +120,7 @@ describe Projects::ClustersController do
|
|||
{
|
||||
cluster: {
|
||||
gcp_cluster_name: 'new-cluster',
|
||||
gcp_project_id: '111',
|
||||
gcp_project_id: '111'
|
||||
}
|
||||
}
|
||||
end
|
||||
|
@ -221,10 +220,9 @@ describe Projects::ClustersController do
|
|||
let(:params) { {} }
|
||||
|
||||
subject do
|
||||
put :update, params.merge(
|
||||
namespace_id: project.namespace,
|
||||
project_id: project,
|
||||
id: cluster)
|
||||
put :update, params.merge(namespace_id: project.namespace,
|
||||
project_id: project,
|
||||
id: cluster)
|
||||
end
|
||||
|
||||
context 'when logged as master' do
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Gcp::ClusterPresenter do
|
||||
let(:project) { create(:project) }
|
||||
let(:cluster) { create(:gcp_cluster, project: project) }
|
||||
|
||||
subject(:presenter) do
|
||||
described_class.new(cluster)
|
||||
end
|
||||
|
||||
it 'inherits from Gitlab::View::Presenter::Delegated' do
|
||||
expect(described_class.superclass).to eq(Gitlab::View::Presenter::Delegated)
|
||||
end
|
||||
|
||||
describe '#initialize' do
|
||||
it 'takes a cluster and optional params' do
|
||||
expect { presenter }.not_to raise_error
|
||||
end
|
||||
|
||||
it 'exposes cluster' do
|
||||
expect(presenter.cluster).to eq(cluster)
|
||||
end
|
||||
|
||||
it 'forwards missing methods to cluster' do
|
||||
expect(presenter.gcp_cluster_zone).to eq(cluster.gcp_cluster_zone)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#gke_cluster_url' do
|
||||
subject { described_class.new(cluster).gke_cluster_url }
|
||||
|
||||
it { is_expected.to include(cluster.gcp_cluster_zone) }
|
||||
it { is_expected.to include(cluster.gcp_cluster_name) }
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue