Commit dcf9fd4e authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch 'pl-spec-groups-helper-perf' into 'master'

Improve performance of groups helper spec

See merge request gitlab-org/gitlab!57234
parents b5a86dd6 c4c80ec4
......@@ -5,33 +5,31 @@ require 'spec_helper'
RSpec.describe GroupsHelper do
include ApplicationHelper
describe 'group_icon_url' do
describe '#group_icon_url' do
it 'returns an url for the avatar' do
avatar_file_path = File.join('spec', 'fixtures', 'banana_sample.gif')
group = create(:group, :with_avatar)
group = create(:group)
group.avatar = fixture_file_upload(avatar_file_path)
group.save!
expect(group_icon_url(group.path).to_s)
.to match(group.avatar.url)
expect(group_icon_url(group.path).to_s).to match(group.avatar.url)
end
it 'gives default avatar_icon when no avatar is present' do
group = create(:group)
group = build_stubbed(:group)
expect(group_icon_url(group.path)).to match_asset_path('group_avatar.png')
end
end
describe 'group_dependency_proxy_url' do
describe '#group_dependency_proxy_url' do
it 'converts uppercase letters to lowercase' do
group = create(:group, path: 'GroupWithUPPERcaseLetters')
group = build_stubbed(:group, path: 'GroupWithUPPERcaseLetters')
expect(group_dependency_proxy_url(group)).to end_with("/groupwithuppercaseletters#{DependencyProxy::URL_SUFFIX}")
end
end
describe 'group_lfs_status' do
let(:group) { create(:group) }
let!(:project) { create(:project, namespace_id: group.id) }
describe '#group_lfs_status' do
let_it_be_with_reload(:group) { create(:group) }
let_it_be_with_reload(:project) { create(:project, namespace_id: group.id) }
before do
allow(Gitlab.config.lfs).to receive(:enabled).and_return(true)
......@@ -54,9 +52,7 @@ RSpec.describe GroupsHelper do
end
context 'more than one project in group' do
before do
create(:project, namespace_id: group.id)
end
let_it_be_with_reload(:another_project) { create(:project, namespace_id: group.id) }
context 'LFS enabled in group' do
before do
......@@ -92,7 +88,7 @@ RSpec.describe GroupsHelper do
end
end
describe 'group_title' do
describe '#group_title' do
let_it_be(:group) { create(:group) }
let_it_be(:nested_group) { create(:group, parent: group) }
let_it_be(:deep_nested_group) { create(:group, parent: nested_group) }
......@@ -115,14 +111,14 @@ RSpec.describe GroupsHelper do
end
end
# rubocop:disable Layout/SpaceBeforeComma
describe '#share_with_group_lock_help_text' do
let!(:root_group) { create(:group) }
let!(:subgroup) { create(:group, parent: root_group) }
let!(:sub_subgroup) { create(:group, parent: subgroup) }
let(:root_owner) { create(:user) }
let(:sub_owner) { create(:user) }
let(:sub_sub_owner) { create(:user) }
let_it_be_with_reload(:root_group) { create(:group) }
let_it_be_with_reload(:subgroup) { create(:group, parent: root_group) }
let_it_be_with_reload(:sub_subgroup) { create(:group, parent: subgroup) }
let_it_be(:root_owner) { create(:user) }
let_it_be(:sub_owner) { create(:user) }
let_it_be(:sub_sub_owner) { create(:user) }
let(:possible_help_texts) do
{
default_help: "This setting will be applied to all subgroups unless overridden by a group owner",
......@@ -149,6 +145,13 @@ RSpec.describe GroupsHelper do
subject { helper.share_with_group_lock_help_text(sub_subgroup) }
before_all do
root_group.add_owner(root_owner)
subgroup.add_owner(sub_owner)
sub_subgroup.add_owner(sub_sub_owner)
end
# rubocop:disable Layout/SpaceBeforeComma
where(:root_share_with_group_locked, :subgroup_share_with_group_locked, :sub_subgroup_share_with_group_locked, :current_user, :help_text, :linked_ancestor) do
[
[false , false , false , :root_owner , :default_help , nil],
......@@ -177,13 +180,10 @@ RSpec.describe GroupsHelper do
[true , true , true , :sub_sub_owner , :ancestor_locked_so_ask_the_owner , :root_group]
]
end
# rubocop:enable Layout/SpaceBeforeComma
with_them do
before do
root_group.add_owner(root_owner)
subgroup.add_owner(sub_owner)
sub_subgroup.add_owner(sub_sub_owner)
root_group.update_column(:share_with_group_lock, true) if root_share_with_group_locked
subgroup.update_column(:share_with_group_lock, true) if subgroup_share_with_group_locked
sub_subgroup.update_column(:share_with_group_lock, true) if sub_subgroup_share_with_group_locked
......@@ -212,8 +212,8 @@ RSpec.describe GroupsHelper do
end
describe '#group_container_registry_nav' do
let(:group) { create(:group, :public) }
let(:user) { create(:user) }
let_it_be(:group) { create(:group, :public) }
let_it_be(:user) { create(:user) }
before do
stub_container_registry_config(enabled: true)
......@@ -248,8 +248,8 @@ RSpec.describe GroupsHelper do
end
describe '#group_sidebar_links' do
let(:group) { create(:group, :public) }
let(:user) { create(:user) }
let_it_be(:group) { create(:group, :public) }
let_it_be(:user) { create(:user) }
before do
group.add_owner(user)
......@@ -287,10 +287,10 @@ RSpec.describe GroupsHelper do
end
end
describe 'parent_group_options' do
let(:current_user) { create(:user) }
let(:group) { create(:group, name: 'group') }
let(:group2) { create(:group, name: 'group2') }
describe '#parent_group_options' do
let_it_be(:current_user) { create(:user) }
let_it_be(:group) { create(:group, name: 'group') }
let_it_be(:group2) { create(:group, name: 'group2') }
before do
group.add_owner(current_user)
......@@ -321,9 +321,9 @@ RSpec.describe GroupsHelper do
end
describe '#can_disable_group_emails?' do
let(:current_user) { create(:user) }
let(:group) { create(:group, name: 'group') }
let(:subgroup) { create(:group, name: 'subgroup', parent: group) }
let_it_be(:current_user) { create(:user) }
let_it_be(:group) { create(:group, name: 'group') }
let_it_be(:subgroup) { create(:group, name: 'subgroup', parent: group) }
before do
allow(helper).to receive(:current_user) { current_user }
......@@ -361,8 +361,8 @@ RSpec.describe GroupsHelper do
end
describe '#can_update_default_branch_protection?' do
let(:current_user) { create(:user) }
let(:group) { create(:group) }
let_it_be(:current_user) { create(:user) }
let_it_be(:group) { create(:group) }
subject { helper.can_update_default_branch_protection?(group) }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment