Add ClusterPresenter. Fix Static Analysys.

This commit is contained in:
Shinya Maeda 2017-10-06 02:45:15 +09:00
parent d27b113b49
commit 6712762b9d
6 changed files with 56 additions and 13 deletions

View file

@ -81,7 +81,7 @@ class Projects::ClustersController < Projects::ApplicationController
private private
def cluster def cluster
@cluster ||= project.cluster @cluster ||= project.cluster.present(current_user: current_user)
end end
def create_params def create_params

View file

@ -1,6 +1,7 @@
module Gcp module Gcp
class Cluster < ActiveRecord::Base class Cluster < ActiveRecord::Base
extend Gitlab::Gcp::Model extend Gitlab::Gcp::Model
include Presentable
belongs_to :project, inverse_of: :cluster belongs_to :project, inverse_of: :cluster
belongs_to :user belongs_to :user

View file

@ -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

View file

@ -37,7 +37,7 @@
%label %label
= s_('ClusterIntegration|Google container engine') = s_('ClusterIntegration|Google container engine')
%p %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 } = s_('ClusterIntegration|Manage your cluster by visiting %{link_gke}').html_safe % { link_gke: link_gke }
.hidden.js-cluster-error.alert.alert-danger{ role: 'alert' } .hidden.js-cluster-error.alert.alert-danger{ role: 'alert' }

View file

@ -100,8 +100,7 @@ describe Projects::ClustersController do
describe 'POST create' do describe 'POST create' do
subject do subject do
post :create, params.merge( post :create, params.merge(namespace_id: project.namespace,
namespace_id: project.namespace,
project_id: project) project_id: project)
end end
@ -121,7 +120,7 @@ describe Projects::ClustersController do
{ {
cluster: { cluster: {
gcp_cluster_name: 'new-cluster', gcp_cluster_name: 'new-cluster',
gcp_project_id: '111', gcp_project_id: '111'
} }
} }
end end
@ -221,8 +220,7 @@ describe Projects::ClustersController do
let(:params) { {} } let(:params) { {} }
subject do subject do
put :update, params.merge( put :update, params.merge(namespace_id: project.namespace,
namespace_id: project.namespace,
project_id: project, project_id: project,
id: cluster) id: cluster)
end end

View file

@ -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