1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe ClusterablePresenter do
include Gitlab::Routing.url_helpers
describe '.fabricate' do
let(:project) { create(:project) }
subject { described_class.fabricate(project) }
it 'creates an object from a descendant presenter' do
expect(subject).to be_kind_of(ProjectClusterablePresenter)
end
end
shared_examples 'appropriate member permissions' do
context 'with a developer' do
before do
clusterable.add_developer(user)
end
it { is_expected.to be_falsy }
end
context 'with a maintainer' do
before do
clusterable.add_maintainer(user)
end
it { is_expected.to be_truthy }
end
end
describe '#can_create_cluster?' do
let(:user) { create(:user) }
subject { described_class.new(clusterable).can_create_cluster? }
before do
allow(clusterable).to receive(:current_user).and_return(user)
end
context 'when clusterable is a group' do
let(:clusterable) { create(:group) }
it_behaves_like 'appropriate member permissions'
end
context 'when clusterable is a project' do
let(:clusterable) { create(:project, :repository) }
it_behaves_like 'appropriate member permissions'
end
end
describe '#can_add_cluster?' do
let(:user) { create(:user) }
subject { described_class.new(clusterable).can_add_cluster? }
before do
clusterable.add_maintainer(user)
allow(clusterable).to receive(:current_user).and_return(user)
end
context 'when clusterable is a group' do
let(:clusterable) { create(:group) }
it_behaves_like 'appropriate member permissions'
end
context 'when clusterable is a project' do
let(:clusterable) { create(:project, :repository) }
it_behaves_like 'appropriate member permissions'
end
end
describe '#can_admin_cluster?' do
let(:user) { create(:user) }
subject { described_class.new(clusterable).can_admin_cluster? }
before do
clusterable.add_maintainer(user)
allow(clusterable).to receive(:current_user).and_return(user)
end
context 'when clusterable is a group' do
let(:clusterable) { create(:group) }
it_behaves_like 'appropriate member permissions'
end
context 'when clusterable is a project' do
let(:clusterable) { create(:project, :repository) }
it_behaves_like 'appropriate member permissions'
end
end
describe '#environments_cluster_path' do
subject { described_class.new(clusterable).environments_cluster_path(cluster) }
let(:clusterable) { create(:group) }
let(:cluster) { create(:cluster_for_group, groups: [clusterable]) }
it { is_expected.to be_nil }
end
describe '#index_path' do
let(:clusterable) { create(:group) }
context 'without options' do
subject { described_class.new(clusterable).index_path }
it { is_expected.to eq(group_clusters_path(clusterable)) }
end
context 'with options' do
subject { described_class.new(clusterable).index_path(format: :json) }
it { is_expected.to eq(group_clusters_path(clusterable, format: :json)) }
end
end
end
|