2018-11-06 07:13:33 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe ClusterAncestorsFinder, '#execute' do
|
|
|
|
let(:group) { create(:group) }
|
|
|
|
let(:project) { create(:project, group: group) }
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
let!(:project_cluster) do
|
2019-04-17 22:45:31 -04:00
|
|
|
create(:cluster, :provided_by_user, :project, projects: [project])
|
2018-11-06 07:13:33 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
let!(:group_cluster) do
|
2019-04-17 22:45:31 -04:00
|
|
|
create(:cluster, :provided_by_user, :group, groups: [group])
|
|
|
|
end
|
|
|
|
|
|
|
|
let!(:instance_cluster) do
|
|
|
|
create(:cluster, :provided_by_user, :instance)
|
2018-11-06 07:13:33 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
subject { described_class.new(clusterable, user).execute }
|
|
|
|
|
|
|
|
context 'for a project' do
|
|
|
|
let(:clusterable) { project }
|
|
|
|
|
2018-12-06 13:47:41 -05:00
|
|
|
before do
|
|
|
|
project.add_maintainer(user)
|
|
|
|
end
|
|
|
|
|
2018-11-06 07:13:33 -05:00
|
|
|
it 'returns the project clusters followed by group clusters' do
|
2019-04-17 22:45:31 -04:00
|
|
|
is_expected.to eq([project_cluster, group_cluster, instance_cluster])
|
2018-11-06 07:13:33 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'nested groups', :nested_groups do
|
|
|
|
let(:group) { create(:group, parent: parent_group) }
|
|
|
|
let(:parent_group) { create(:group) }
|
|
|
|
|
|
|
|
let!(:parent_group_cluster) do
|
2019-04-17 22:45:31 -04:00
|
|
|
create(:cluster, :provided_by_user, :group, groups: [parent_group])
|
2018-11-06 07:13:33 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the project clusters followed by group clusters ordered ascending the hierarchy' do
|
2019-04-17 22:45:31 -04:00
|
|
|
is_expected.to eq([project_cluster, group_cluster, parent_group_cluster, instance_cluster])
|
2018-11-06 07:13:33 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-12-06 13:47:41 -05:00
|
|
|
context 'user cannot read clusters for clusterable' do
|
|
|
|
let(:clusterable) { project }
|
|
|
|
|
|
|
|
it 'returns nothing' do
|
|
|
|
is_expected.to be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-11-06 07:13:33 -05:00
|
|
|
context 'for a group' do
|
|
|
|
let(:clusterable) { group }
|
|
|
|
|
2018-12-06 13:47:41 -05:00
|
|
|
before do
|
|
|
|
group.add_maintainer(user)
|
|
|
|
end
|
|
|
|
|
2018-11-06 07:13:33 -05:00
|
|
|
it 'returns the list of group clusters' do
|
2019-04-17 22:45:31 -04:00
|
|
|
is_expected.to eq([group_cluster, instance_cluster])
|
2018-11-06 07:13:33 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'nested groups', :nested_groups do
|
|
|
|
let(:group) { create(:group, parent: parent_group) }
|
|
|
|
let(:parent_group) { create(:group) }
|
|
|
|
|
|
|
|
let!(:parent_group_cluster) do
|
2019-04-17 22:45:31 -04:00
|
|
|
create(:cluster, :provided_by_user, :group, groups: [parent_group])
|
2018-11-06 07:13:33 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the list of group clusters ordered ascending the hierarchy' do
|
2019-04-17 22:45:31 -04:00
|
|
|
is_expected.to eq([group_cluster, parent_group_cluster, instance_cluster])
|
2018-11-06 07:13:33 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-04-17 22:45:31 -04:00
|
|
|
|
|
|
|
context 'for an instance' do
|
|
|
|
let(:clusterable) { Clusters::Instance.new }
|
|
|
|
let(:user) { create(:admin) }
|
|
|
|
|
|
|
|
it 'returns the list of instance clusters' do
|
|
|
|
is_expected.to eq([instance_cluster])
|
|
|
|
end
|
|
|
|
end
|
2018-11-06 07:13:33 -05:00
|
|
|
end
|