Commit 6712762b authored by Shinya Maeda's avatar Shinya Maeda

Add ClusterPresenter. Fix Static Analysys.

parent d27b113b
......@@ -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
......
module Gcp
class Cluster < ActiveRecord::Base
extend Gitlab::Gcp::Model
include Presentable
belongs_to :project, inverse_of: :cluster
belongs_to :user
......
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
......@@ -117,12 +116,12 @@ describe Projects::ClustersController do
end
context 'when all required parameters are set' do
let(:params) do
let(:params) do
{
cluster: {
gcp_cluster_name: 'new-cluster',
gcp_project_id: '111',
}
gcp_project_id: '111'
}
}
end
......@@ -140,7 +139,7 @@ describe Projects::ClustersController do
context 'when not all required parameters are set' do
render_views
let(:params) do
let(:params) do
{
cluster: {
project_namespace: 'some namespace'
......@@ -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
......
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
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