2017-10-05 13:45:15 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-10-30 12:09:39 -04:00
|
|
|
describe Clusters::ClusterPresenter do
|
|
|
|
let(:cluster) { create(:cluster, :provided_by_gcp) }
|
2017-10-05 13:45:15 -04:00
|
|
|
|
|
|
|
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
|
2017-10-30 12:09:39 -04:00
|
|
|
expect(presenter.status).to eq(cluster.status)
|
2017-10-05 13:45:15 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#gke_cluster_url' do
|
|
|
|
subject { described_class.new(cluster).gke_cluster_url }
|
|
|
|
|
2017-10-30 12:09:39 -04:00
|
|
|
it { is_expected.to include(cluster.provider.zone) }
|
|
|
|
it { is_expected.to include(cluster.name) }
|
2017-10-05 13:45:15 -04:00
|
|
|
end
|
2017-12-05 11:09:04 -05:00
|
|
|
|
|
|
|
describe '#can_toggle_cluster' do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(cluster).to receive(:current_user).and_return(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
subject { described_class.new(cluster).can_toggle_cluster? }
|
|
|
|
|
|
|
|
context 'when user can update' do
|
|
|
|
before do
|
|
|
|
allow_any_instance_of(described_class).to receive(:can?).with(user, :update_cluster, cluster).and_return(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when cluster is created' do
|
|
|
|
before do
|
|
|
|
allow(cluster).to receive(:created?).and_return(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to eq(true) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when cluster is not created' do
|
|
|
|
before do
|
|
|
|
allow(cluster).to receive(:created?).and_return(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to eq(false) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user can not update' do
|
|
|
|
before do
|
|
|
|
allow_any_instance_of(described_class).to receive(:can?).with(user, :update_cluster, cluster).and_return(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to eq(false) }
|
|
|
|
end
|
|
|
|
end
|
2017-10-05 13:45:15 -04:00
|
|
|
end
|