Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/helpers/groups_helper_spec.rb')
-rw-r--r--spec/helpers/groups_helper_spec.rb285
1 files changed, 172 insertions, 113 deletions
diff --git a/spec/helpers/groups_helper_spec.rb b/spec/helpers/groups_helper_spec.rb
index d588120bb98..ad6852f63df 100644
--- a/spec/helpers/groups_helper_spec.rb
+++ b/spec/helpers/groups_helper_spec.rb
@@ -96,9 +96,31 @@ RSpec.describe GroupsHelper do
subject { helper.group_title(very_deep_nested_group) }
- it 'outputs the groups in the correct order' do
- expect(subject)
- .to match(%r{<li style="text-indent: 16px;"><a.*>#{deep_nested_group.name}.*</li>.*<a.*>#{very_deep_nested_group.name}</a>}m)
+ context 'traversal queries' do
+ shared_examples 'correct ancestor order' do
+ it 'outputs the groups in the correct order' do
+ expect(subject)
+ .to match(%r{<li style="text-indent: 16px;"><a.*>#{deep_nested_group.name}.*</li>.*<a.*>#{very_deep_nested_group.name}</a>}m)
+ end
+ end
+
+ context 'recursive' do
+ before do
+ stub_feature_flags(use_traversal_ids: false)
+ end
+
+ include_examples 'correct ancestor order'
+ end
+
+ context 'linear' do
+ before do
+ stub_feature_flags(use_traversal_ids: true)
+
+ very_deep_nested_group.reload # make sure traversal_ids are reloaded
+ end
+
+ include_examples 'correct ancestor order'
+ end
end
it 'enqueues the elements in the breadcrumb schema list' do
@@ -122,101 +144,121 @@ RSpec.describe GroupsHelper do
end
describe '#share_with_group_lock_help_text' do
- 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",
- ancestor_locked_but_you_can_override: %r{This setting is applied on <a .+>.+</a>\. You can override the setting or .+},
- ancestor_locked_so_ask_the_owner: /This setting is applied on .+\. To share projects in this group with another group, ask the owner to override the setting or remove the share with group lock from .+/,
- ancestor_locked_and_has_been_overridden: /This setting is applied on .+ and has been overridden on this subgroup/
- }
- end
-
- let(:possible_linked_ancestors) do
- {
- root_group: root_group,
- subgroup: subgroup
- }
- end
-
- let(:users) do
- {
- root_owner: root_owner,
- sub_owner: sub_owner,
- sub_sub_owner: sub_sub_owner
- }
- end
-
- 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],
- [false , false , false , :sub_owner , :default_help , nil],
- [false , false , false , :sub_sub_owner , :default_help , nil],
- [false , false , true , :root_owner , :default_help , nil],
- [false , false , true , :sub_owner , :default_help , nil],
- [false , false , true , :sub_sub_owner , :default_help , nil],
- [false , true , false , :root_owner , :ancestor_locked_and_has_been_overridden , :subgroup],
- [false , true , false , :sub_owner , :ancestor_locked_and_has_been_overridden , :subgroup],
- [false , true , false , :sub_sub_owner , :ancestor_locked_and_has_been_overridden , :subgroup],
- [false , true , true , :root_owner , :ancestor_locked_but_you_can_override , :subgroup],
- [false , true , true , :sub_owner , :ancestor_locked_but_you_can_override , :subgroup],
- [false , true , true , :sub_sub_owner , :ancestor_locked_so_ask_the_owner , :subgroup],
- [true , false , false , :root_owner , :default_help , nil],
- [true , false , false , :sub_owner , :default_help , nil],
- [true , false , false , :sub_sub_owner , :default_help , nil],
- [true , false , true , :root_owner , :default_help , nil],
- [true , false , true , :sub_owner , :default_help , nil],
- [true , false , true , :sub_sub_owner , :default_help , nil],
- [true , true , false , :root_owner , :ancestor_locked_and_has_been_overridden , :root_group],
- [true , true , false , :sub_owner , :ancestor_locked_and_has_been_overridden , :root_group],
- [true , true , false , :sub_sub_owner , :ancestor_locked_and_has_been_overridden , :root_group],
- [true , true , true , :root_owner , :ancestor_locked_but_you_can_override , :root_group],
- [true , true , true , :sub_owner , :ancestor_locked_so_ask_the_owner , :root_group],
- [true , true , true , :sub_sub_owner , :ancestor_locked_so_ask_the_owner , :root_group]
- ]
- end
- # rubocop:enable Layout/SpaceBeforeComma
+ context 'traversal queries' do
+ 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",
+ ancestor_locked_but_you_can_override: %r{This setting is applied on <a .+>.+</a>\. You can override the setting or .+},
+ ancestor_locked_so_ask_the_owner: /This setting is applied on .+\. To share projects in this group with another group, ask the owner to override the setting or remove the share with group lock from .+/,
+ ancestor_locked_and_has_been_overridden: /This setting is applied on .+ and has been overridden on this subgroup/
+ }
+ end
- with_them do
- before do
- 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
-
- allow(helper).to receive(:current_user).and_return(users[current_user])
- allow(helper).to receive(:can?)
- .with(users[current_user], :change_share_with_group_lock, subgroup)
- .and_return(Ability.allowed?(users[current_user], :change_share_with_group_lock, subgroup))
-
- ancestor = possible_linked_ancestors[linked_ancestor]
- if ancestor
- allow(helper).to receive(:can?)
- .with(users[current_user], :read_group, ancestor)
- .and_return(Ability.allowed?(users[current_user], :read_group, ancestor))
- allow(helper).to receive(:can?)
- .with(users[current_user], :admin_group, ancestor)
- .and_return(Ability.allowed?(users[current_user], :admin_group, ancestor))
+ let(:possible_linked_ancestors) do
+ {
+ root_group: root_group,
+ subgroup: subgroup
+ }
+ end
+
+ let(:users) do
+ {
+ root_owner: root_owner,
+ sub_owner: sub_owner,
+ sub_sub_owner: sub_sub_owner
+ }
+ end
+
+ 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
+
+ shared_examples 'correct ancestor order' do
+ # 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],
+ [false , false , false , :sub_owner , :default_help , nil],
+ [false , false , false , :sub_sub_owner , :default_help , nil],
+ [false , false , true , :root_owner , :default_help , nil],
+ [false , false , true , :sub_owner , :default_help , nil],
+ [false , false , true , :sub_sub_owner , :default_help , nil],
+ [false , true , false , :root_owner , :ancestor_locked_and_has_been_overridden , :subgroup],
+ [false , true , false , :sub_owner , :ancestor_locked_and_has_been_overridden , :subgroup],
+ [false , true , false , :sub_sub_owner , :ancestor_locked_and_has_been_overridden , :subgroup],
+ [false , true , true , :root_owner , :ancestor_locked_but_you_can_override , :subgroup],
+ [false , true , true , :sub_owner , :ancestor_locked_but_you_can_override , :subgroup],
+ [false , true , true , :sub_sub_owner , :ancestor_locked_so_ask_the_owner , :subgroup],
+ [true , false , false , :root_owner , :default_help , nil],
+ [true , false , false , :sub_owner , :default_help , nil],
+ [true , false , false , :sub_sub_owner , :default_help , nil],
+ [true , false , true , :root_owner , :default_help , nil],
+ [true , false , true , :sub_owner , :default_help , nil],
+ [true , false , true , :sub_sub_owner , :default_help , nil],
+ [true , true , false , :root_owner , :ancestor_locked_and_has_been_overridden , :root_group],
+ [true , true , false , :sub_owner , :ancestor_locked_and_has_been_overridden , :root_group],
+ [true , true , false , :sub_sub_owner , :ancestor_locked_and_has_been_overridden , :root_group],
+ [true , true , true , :root_owner , :ancestor_locked_but_you_can_override , :root_group],
+ [true , true , true , :sub_owner , :ancestor_locked_so_ask_the_owner , :root_group],
+ [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.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
+
+ allow(helper).to receive(:current_user).and_return(users[current_user])
+ allow(helper).to receive(:can?)
+ .with(users[current_user], :change_share_with_group_lock, subgroup)
+ .and_return(Ability.allowed?(users[current_user], :change_share_with_group_lock, subgroup))
+
+ ancestor = possible_linked_ancestors[linked_ancestor]
+ if ancestor
+ allow(helper).to receive(:can?)
+ .with(users[current_user], :read_group, ancestor)
+ .and_return(Ability.allowed?(users[current_user], :read_group, ancestor))
+ allow(helper).to receive(:can?)
+ .with(users[current_user], :admin_group, ancestor)
+ .and_return(Ability.allowed?(users[current_user], :admin_group, ancestor))
+ end
+ end
+
+ it 'has the correct help text with correct ancestor links' do
+ expect(subject).to match(possible_help_texts[help_text])
+ expect(subject).to match(possible_linked_ancestors[linked_ancestor].name) unless help_text == :default_help
+ end
end
end
- it 'has the correct help text with correct ancestor links' do
- expect(subject).to match(possible_help_texts[help_text])
- expect(subject).to match(possible_linked_ancestors[linked_ancestor].name) unless help_text == :default_help
+ context 'recursive' do
+ before do
+ stub_feature_flags(use_traversal_ids: false)
+ end
+
+ include_examples 'correct ancestor order'
+ end
+
+ context 'linear' do
+ before do
+ stub_feature_flags(use_traversal_ids: true)
+ end
+
+ include_examples 'correct ancestor order'
end
end
end
@@ -420,42 +462,59 @@ RSpec.describe GroupsHelper do
describe '#show_invite_banner?' do
let_it_be(:current_user) { create(:user) }
let_it_be_with_refind(:group) { create(:group) }
+ let_it_be(:subgroup) { create(:group, parent: group) }
let_it_be(:users) { [current_user, create(:user)] }
- subject { helper.show_invite_banner?(group) }
-
before do
allow(helper).to receive(:current_user) { current_user }
allow(helper).to receive(:can?).with(current_user, :admin_group, group).and_return(can_admin_group)
- stub_feature_flags(invite_your_teammates_banner_a: feature_enabled_flag)
+ allow(helper).to receive(:can?).with(current_user, :admin_group, subgroup).and_return(can_admin_group)
users.take(group_members_count).each { |user| group.add_guest(user) }
end
using RSpec::Parameterized::TableSyntax
- where(:feature_enabled_flag, :can_admin_group, :group_members_count, :expected_result) do
- true | true | 1 | true
- true | false | 1 | false
- false | true | 1 | false
- false | false | 1 | false
- true | true | 2 | false
- true | false | 2 | false
- false | true | 2 | false
- false | false | 2 | false
+ where(:can_admin_group, :group_members_count, :expected_result) do
+ true | 1 | true
+ false | 1 | false
+ true | 2 | false
+ false | 2 | false
end
with_them do
- context 'when the group was just created' do
- before do
- flash[:notice] = "Group #{group.name} was successfully created"
+ context 'for a parent group' do
+ subject { helper.show_invite_banner?(group) }
+
+ context 'when the group was just created' do
+ before do
+ flash[:notice] = "Group #{group.name} was successfully created"
+ end
+
+ it { is_expected.to be_falsey }
end
- it { is_expected.to be_falsey }
+ context 'when no flash message' do
+ it 'returns the expected result' do
+ expect(subject).to eq(expected_result)
+ end
+ end
end
- context 'when no flash message' do
- it 'returns the expected result' do
- expect(subject).to eq(expected_result)
+ context 'for a subgroup' do
+ subject { helper.show_invite_banner?(subgroup) }
+
+ context 'when the subgroup was just created' do
+ before do
+ flash[:notice] = "Group #{subgroup.name} was successfully created"
+ end
+
+ it { is_expected.to be_falsey }
+ end
+
+ context 'when no flash message' do
+ it 'returns the expected result' do
+ expect(subject).to eq(expected_result)
+ end
end
end
end