debian-mirror-gitlab/spec/helpers/namespaces_helper_spec.rb

136 lines
4.3 KiB
Ruby
Raw Normal View History

2019-12-21 20:55:43 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
require 'spec_helper'
2023-07-09 08:55:56 +05:30
RSpec.describe NamespacesHelper, feature_category: :subgroups do
2017-08-17 22:00:37 +05:30
let!(:admin) { create(:admin) }
2019-07-07 11:18:12 +05:30
let!(:admin_project_creation_level) { nil }
let!(:admin_group) do
2023-06-20 00:43:36 +05:30
create(:group, :private, project_creation_level: admin_project_creation_level)
2019-07-07 11:18:12 +05:30
end
2020-10-24 23:57:45 +05:30
2017-08-17 22:00:37 +05:30
let!(:user) { create(:user) }
2019-07-07 11:18:12 +05:30
let!(:user_project_creation_level) { nil }
let!(:user_group) do
2023-06-20 00:43:36 +05:30
create(:group, :private, project_creation_level: user_project_creation_level)
2019-07-07 11:18:12 +05:30
end
2020-10-24 23:57:45 +05:30
2019-07-07 11:18:12 +05:30
let!(:subgroup1) do
2023-06-20 00:43:36 +05:30
create(:group, :private, parent: admin_group, project_creation_level: nil)
2019-07-07 11:18:12 +05:30
end
2020-10-24 23:57:45 +05:30
2019-07-07 11:18:12 +05:30
let!(:subgroup2) do
2023-06-20 00:43:36 +05:30
create(
:group,
:private,
parent: admin_group,
project_creation_level: ::Gitlab::Access::DEVELOPER_MAINTAINER_PROJECT_ACCESS
)
2019-07-07 11:18:12 +05:30
end
2020-10-24 23:57:45 +05:30
2019-07-07 11:18:12 +05:30
let!(:subgroup3) do
2023-06-20 00:43:36 +05:30
create(
:group,
:private,
parent: admin_group,
project_creation_level: ::Gitlab::Access::MAINTAINER_PROJECT_ACCESS
)
2019-07-07 11:18:12 +05:30
end
2017-08-17 22:00:37 +05:30
before do
admin_group.add_owner(admin)
user_group.add_owner(user)
end
2021-04-29 21:17:54 +05:30
describe '#cascading_namespace_settings_popover_data' do
attribute = :delayed_project_removal
subject do
helper.cascading_namespace_settings_popover_data(
attribute,
subgroup1,
-> (locked_ancestor) { edit_group_path(locked_ancestor, anchor: 'js-permissions-settings') }
)
end
context 'when locked by an application setting' do
before do
allow(subgroup1.namespace_settings).to receive("#{attribute}_locked_by_application_setting?").and_return(true)
allow(subgroup1.namespace_settings).to receive("#{attribute}_locked_by_ancestor?").and_return(false)
end
it 'returns expected hash' do
expect(subject).to match({
popover_data: {
locked_by_application_setting: true,
locked_by_ancestor: false
}.to_json,
testid: 'cascading-settings-lock-icon'
})
end
end
context 'when locked by an ancestor namespace' do
before do
allow(subgroup1.namespace_settings).to receive("#{attribute}_locked_by_application_setting?").and_return(false)
allow(subgroup1.namespace_settings).to receive("#{attribute}_locked_by_ancestor?").and_return(true)
allow(subgroup1.namespace_settings).to receive("#{attribute}_locked_ancestor").and_return(admin_group.namespace_settings)
end
it 'returns expected hash' do
expect(subject).to match({
popover_data: {
locked_by_application_setting: false,
locked_by_ancestor: true,
ancestor_namespace: {
full_name: admin_group.full_name,
path: edit_group_path(admin_group, anchor: 'js-permissions-settings')
}
}.to_json,
testid: 'cascading-settings-lock-icon'
})
end
end
end
2021-06-08 01:23:25 +05:30
describe '#cascading_namespace_setting_locked?' do
let(:attribute) { :delayed_project_removal }
context 'when `group` argument is `nil`' do
it 'returns `false`' do
expect(helper.cascading_namespace_setting_locked?(attribute, nil)).to eq(false)
end
end
context 'when `*_locked?` method does not exist' do
it 'returns `false`' do
expect(helper.cascading_namespace_setting_locked?(:attribute_that_does_not_exist, admin_group)).to eq(false)
end
end
context 'when `*_locked?` method does exist' do
before do
allow(admin_group.namespace_settings).to receive(:delayed_project_removal_locked?).and_return(true)
end
it 'calls corresponding `*_locked?` method' do
helper.cascading_namespace_setting_locked?(attribute, admin_group, include_self: true)
expect(admin_group.namespace_settings).to have_received(:delayed_project_removal_locked?).with(include_self: true)
end
end
end
2022-06-21 17:19:12 +05:30
2023-07-09 08:55:56 +05:30
describe '#pipeline_usage_app_data', unless: Gitlab.ee?, feature_category: :consumables_cost_management do
2022-06-21 17:19:12 +05:30
it 'returns a hash with necessary data for the frontend' do
2022-07-16 23:28:13 +05:30
expect(helper.pipeline_usage_app_data(user_group)).to eql({
2022-06-21 17:19:12 +05:30
namespace_actual_plan_name: user_group.actual_plan_name,
namespace_path: user_group.full_path,
namespace_id: user_group.id,
2022-07-16 23:28:13 +05:30
user_namespace: user_group.user_namespace?.to_s,
2022-06-21 17:19:12 +05:30
page_size: Kaminari.config.default_per_page
})
end
end
2017-08-17 22:00:37 +05:30
end