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:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-03-16 21:18:33 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-03-16 21:18:33 +0300
commitf64a639bcfa1fc2bc89ca7db268f594306edfd7c (patch)
treea2c3c2ebcc3b45e596949db485d6ed18ffaacfa1 /spec/helpers
parentbfbc3e0d6583ea1a91f627528bedc3d65ba4b10f (diff)
Add latest changes from gitlab-org/gitlab@13-10-stable-eev13.10.0-rc40
Diffstat (limited to 'spec/helpers')
-rw-r--r--spec/helpers/application_settings_helper_spec.rb15
-rw-r--r--spec/helpers/auth_helper_spec.rb8
-rw-r--r--spec/helpers/avatars_helper_spec.rb65
-rw-r--r--spec/helpers/boards_helper_spec.rb81
-rw-r--r--spec/helpers/ci/pipeline_editor_helper_spec.rb7
-rw-r--r--spec/helpers/commits_helper_spec.rb21
-rw-r--r--spec/helpers/gitlab_routing_helper_spec.rb10
-rw-r--r--spec/helpers/groups_helper_spec.rb22
-rw-r--r--spec/helpers/ide_helper_spec.rb47
-rw-r--r--spec/helpers/invite_members_helper_spec.rb25
-rw-r--r--spec/helpers/issuables_description_templates_helper_spec.rb104
-rw-r--r--spec/helpers/learn_gitlab_helper_spec.rb6
-rw-r--r--spec/helpers/merge_requests_helper_spec.rb53
-rw-r--r--spec/helpers/namespaces_helper_spec.rb36
-rw-r--r--spec/helpers/notifications_helper_spec.rb16
-rw-r--r--spec/helpers/preferences_helper_spec.rb1
-rw-r--r--spec/helpers/projects/project_members_helper_spec.rb4
-rw-r--r--spec/helpers/projects/security/configuration_helper_spec.rb13
-rw-r--r--spec/helpers/projects_helper_spec.rb26
-rw-r--r--spec/helpers/search_helper_spec.rb5
-rw-r--r--spec/helpers/services_helper_spec.rb46
-rw-r--r--spec/helpers/stat_anchors_helper_spec.rb18
-rw-r--r--spec/helpers/timeboxes_helper_spec.rb9
-rw-r--r--spec/helpers/visibility_level_helper_spec.rb16
24 files changed, 452 insertions, 202 deletions
diff --git a/spec/helpers/application_settings_helper_spec.rb b/spec/helpers/application_settings_helper_spec.rb
index 2cd01451e0d..c74ee3ce0ec 100644
--- a/spec/helpers/application_settings_helper_spec.rb
+++ b/spec/helpers/application_settings_helper_spec.rb
@@ -130,20 +130,15 @@ RSpec.describe ApplicationSettingsHelper do
before do
helper.instance_variable_set(:@application_setting, application_setting)
stub_storage_settings({ 'default': {}, 'storage_1': {}, 'storage_2': {} })
- allow(ApplicationSetting).to receive(:repository_storages_weighted_attributes).and_return(
- [:repository_storages_weighted_default,
- :repository_storages_weighted_storage_1,
- :repository_storages_weighted_storage_2])
-
stub_application_setting(repository_storages_weighted: { 'default' => 100, 'storage_1' => 50, 'storage_2' => nil })
end
it 'returns storages correctly' do
- expect(helper.storage_weights).to eq([
- { name: :repository_storages_weighted_default, label: 'default', value: 100 },
- { name: :repository_storages_weighted_storage_1, label: 'storage_1', value: 50 },
- { name: :repository_storages_weighted_storage_2, label: 'storage_2', value: 0 }
- ])
+ expect(helper.storage_weights).to eq(OpenStruct.new(
+ default: 100,
+ storage_1: 50,
+ storage_2: 0
+ ))
end
end
diff --git a/spec/helpers/auth_helper_spec.rb b/spec/helpers/auth_helper_spec.rb
index b5d70af1336..beffa4cf60e 100644
--- a/spec/helpers/auth_helper_spec.rb
+++ b/spec/helpers/auth_helper_spec.rb
@@ -99,19 +99,19 @@ RSpec.describe AuthHelper do
end
end
- describe 'experiment_enabled_button_based_providers' do
+ describe 'trial_enabled_button_based_providers' do
it 'returns the intersection set of github & google_oauth2 with enabled providers' do
allow(helper).to receive(:enabled_button_based_providers) { %w(twitter github google_oauth2) }
- expect(helper.experiment_enabled_button_based_providers).to eq(%w(github google_oauth2))
+ expect(helper.trial_enabled_button_based_providers).to eq(%w(github google_oauth2))
allow(helper).to receive(:enabled_button_based_providers) { %w(google_oauth2 bitbucket) }
- expect(helper.experiment_enabled_button_based_providers).to eq(%w(google_oauth2))
+ expect(helper.trial_enabled_button_based_providers).to eq(%w(google_oauth2))
allow(helper).to receive(:enabled_button_based_providers) { %w(bitbucket) }
- expect(helper.experiment_enabled_button_based_providers).to be_empty
+ expect(helper.trial_enabled_button_based_providers).to be_empty
end
end
diff --git a/spec/helpers/avatars_helper_spec.rb b/spec/helpers/avatars_helper_spec.rb
index 9e18ab34c1f..7fcd5ae880a 100644
--- a/spec/helpers/avatars_helper_spec.rb
+++ b/spec/helpers/avatars_helper_spec.rb
@@ -5,7 +5,7 @@ require 'spec_helper'
RSpec.describe AvatarsHelper do
include UploadHelpers
- let(:user) { create(:user) }
+ let_it_be(:user) { create(:user) }
describe '#project_icon & #group_icon' do
shared_examples 'resource with a default avatar' do |source_type|
@@ -89,33 +89,60 @@ RSpec.describe AvatarsHelper do
end
end
- describe '#avatar_icon_for_email' do
+ describe '#avatar_icon_for_email', :clean_gitlab_redis_cache do
let(:user) { create(:user, avatar: File.open(uploaded_image_temp_path)) }
- context 'using an email' do
- context 'when there is a matching user' do
- it 'returns a relative URL for the avatar' do
- expect(helper.avatar_icon_for_email(user.email).to_s)
- .to eq(user.avatar.url)
+ subject { helper.avatar_icon_for_email(user.email).to_s }
+
+ shared_examples "returns avatar for email" do
+ context 'using an email' do
+ context 'when there is a matching user' do
+ it 'returns a relative URL for the avatar' do
+ expect(subject).to eq(user.avatar.url)
+ end
end
- end
- context 'when no user exists for the email' do
- it 'calls gravatar_icon' do
- expect(helper).to receive(:gravatar_icon).with('foo@example.com', 20, 2)
+ context 'when no user exists for the email' do
+ it 'calls gravatar_icon' do
+ expect(helper).to receive(:gravatar_icon).with('foo@example.com', 20, 2)
- helper.avatar_icon_for_email('foo@example.com', 20, 2)
+ helper.avatar_icon_for_email('foo@example.com', 20, 2)
+ end
end
- end
- context 'without an email passed' do
- it 'calls gravatar_icon' do
- expect(helper).to receive(:gravatar_icon).with(nil, 20, 2)
+ context 'without an email passed' do
+ it 'calls gravatar_icon' do
+ expect(helper).to receive(:gravatar_icon).with(nil, 20, 2)
+ expect(User).not_to receive(:find_by_any_email)
- helper.avatar_icon_for_email(nil, 20, 2)
+ helper.avatar_icon_for_email(nil, 20, 2)
+ end
end
end
end
+
+ context "when :avatar_cache_for_email flag is enabled" do
+ before do
+ stub_feature_flags(avatar_cache_for_email: true)
+ end
+
+ it_behaves_like "returns avatar for email"
+
+ it "caches the request" do
+ expect(User).to receive(:find_by_any_email).once.and_call_original
+
+ expect(helper.avatar_icon_for_email(user.email).to_s).to eq(user.avatar.url)
+ expect(helper.avatar_icon_for_email(user.email).to_s).to eq(user.avatar.url)
+ end
+ end
+
+ context "when :avatar_cache_for_email flag is disabled" do
+ before do
+ stub_feature_flags(avatar_cache_for_email: false)
+ end
+
+ it_behaves_like "returns avatar for email"
+ end
end
describe '#avatar_icon_for_user' do
@@ -346,7 +373,7 @@ RSpec.describe AvatarsHelper do
is_expected.to eq tag(
:img,
alt: "#{options[:user_name]}'s avatar",
- src: avatar_icon_for_email(options[:user_email], 16),
+ src: helper.avatar_icon_for_email(options[:user_email], 16),
data: { container: 'body' },
class: "avatar s16 has-tooltip",
title: options[:user_name]
@@ -379,7 +406,7 @@ RSpec.describe AvatarsHelper do
is_expected.to eq tag(
:img,
alt: "#{user_with_avatar.username}'s avatar",
- src: avatar_icon_for_email(user_with_avatar.email, 16, only_path: false),
+ src: helper.avatar_icon_for_email(user_with_avatar.email, 16, only_path: false),
data: { container: 'body' },
class: "avatar s16 has-tooltip",
title: user_with_avatar.username
diff --git a/spec/helpers/boards_helper_spec.rb b/spec/helpers/boards_helper_spec.rb
index b85ebec5545..b00ee19cea2 100644
--- a/spec/helpers/boards_helper_spec.rb
+++ b/spec/helpers/boards_helper_spec.rb
@@ -3,52 +3,71 @@
require 'spec_helper'
RSpec.describe BoardsHelper do
- let_it_be(:project) { create(:project) }
+ let_it_be(:user) { create(:user) }
+ let_it_be(:base_group) { create(:group, path: 'base') }
+ let_it_be(:project) { create(:project, group: base_group) }
+ let_it_be(:project_board) { create(:board, project: project) }
+ let_it_be(:group_board) { create(:board, group: base_group) }
describe '#build_issue_link_base' do
context 'project board' do
it 'returns correct path for project board' do
- @project = project
- @board = create(:board, project: @project)
+ assign(:project, project)
+ assign(:board, project_board)
- expect(build_issue_link_base).to eq("/#{@project.namespace.path}/#{@project.path}/-/issues")
+ expect(helper.build_issue_link_base).to eq("/#{project.namespace.path}/#{project.path}/-/issues")
end
end
context 'group board' do
- let(:base_group) { create(:group, path: 'base') }
-
it 'returns correct path for base group' do
- @board = create(:board, group: base_group)
+ assign(:board, group_board)
- expect(build_issue_link_base).to eq('/base/:project_path/issues')
+ expect(helper.build_issue_link_base).to eq('/base/:project_path/issues')
end
it 'returns correct path for subgroup' do
subgroup = create(:group, parent: base_group, path: 'sub')
- @board = create(:board, group: subgroup)
+ assign(:board, create(:board, group: subgroup))
- expect(build_issue_link_base).to eq('/base/sub/:project_path/issues')
+ expect(helper.build_issue_link_base).to eq('/base/sub/:project_path/issues')
end
end
end
- describe '#board_data' do
- let_it_be(:user) { create(:user) }
- let_it_be(:board) { create(:board, project: project) }
+ describe '#board_base_url' do
+ context 'when project board' do
+ it 'generates the correct url' do
+ assign(:board, group_board)
+ assign(:group, base_group)
+
+ expect(helper.board_base_url).to eq "http://test.host/groups/#{base_group.full_path}/-/boards"
+ end
+ end
+
+ context 'when project board' do
+ it 'generates the correct url' do
+ assign(:board, project_board)
+ assign(:project, project)
+
+ expect(helper.board_base_url).to eq "/#{project.full_path}/-/boards"
+ end
+ end
+ end
+ describe '#board_data' do
context 'project_board' do
before do
assign(:project, project)
- assign(:board, board)
+ assign(:board, project_board)
allow(helper).to receive(:current_user) { user }
- allow(helper).to receive(:can?).with(user, :create_non_backlog_issues, board).and_return(true)
- allow(helper).to receive(:can?).with(user, :admin_issue, board).and_return(true)
+ allow(helper).to receive(:can?).with(user, :create_non_backlog_issues, project_board).and_return(true)
+ allow(helper).to receive(:can?).with(user, :admin_issue, project_board).and_return(true)
end
it 'returns a board_lists_path as lists_endpoint' do
- expect(helper.board_data[:lists_endpoint]).to eq(board_lists_path(board))
+ expect(helper.board_data[:lists_endpoint]).to eq(board_lists_path(project_board))
end
it 'returns board type as parent' do
@@ -63,28 +82,33 @@ RSpec.describe BoardsHelper do
expect(helper.board_data[:labels_fetch_path]).to eq("/#{project.full_path}/-/labels.json?include_ancestor_groups=true")
expect(helper.board_data[:labels_manage_path]).to eq("/#{project.full_path}/-/labels")
end
+
+ it 'returns the group id of a project' do
+ expect(helper.board_data[:group_id]).to eq(project.group.id)
+ end
end
context 'group board' do
- let_it_be(:group) { create(:group, path: 'base') }
- let_it_be(:board) { create(:board, group: group) }
-
before do
- assign(:group, group)
- assign(:board, board)
+ assign(:group, base_group)
+ assign(:board, group_board)
allow(helper).to receive(:current_user) { user }
- allow(helper).to receive(:can?).with(user, :create_non_backlog_issues, board).and_return(true)
- allow(helper).to receive(:can?).with(user, :admin_issue, board).and_return(true)
+ allow(helper).to receive(:can?).with(user, :create_non_backlog_issues, group_board).and_return(true)
+ allow(helper).to receive(:can?).with(user, :admin_issue, group_board).and_return(true)
end
it 'returns correct path for base group' do
- expect(helper.build_issue_link_base).to eq('/base/:project_path/issues')
+ expect(helper.build_issue_link_base).to eq("/#{base_group.full_path}/:project_path/issues")
end
it 'returns required label endpoints' do
- expect(helper.board_data[:labels_fetch_path]).to eq("/groups/base/-/labels.json?include_ancestor_groups=true&only_group_labels=true")
- expect(helper.board_data[:labels_manage_path]).to eq("/groups/base/-/labels")
+ expect(helper.board_data[:labels_fetch_path]).to eq("/groups/#{base_group.full_path}/-/labels.json?include_ancestor_groups=true&only_group_labels=true")
+ expect(helper.board_data[:labels_manage_path]).to eq("/groups/#{base_group.full_path}/-/labels")
+ end
+
+ it 'returns the group id' do
+ expect(helper.board_data[:group_id]).to eq(base_group.id)
end
end
end
@@ -93,8 +117,7 @@ RSpec.describe BoardsHelper do
let(:board_json) { helper.current_board_json }
it 'can serialise with a basic set of attributes' do
- board = create(:board, project: project)
- assign(:board, board)
+ assign(:board, project_board)
expect(board_json).to match_schema('current-board')
end
diff --git a/spec/helpers/ci/pipeline_editor_helper_spec.rb b/spec/helpers/ci/pipeline_editor_helper_spec.rb
index 8f38d3b1439..7686983eb0f 100644
--- a/spec/helpers/ci/pipeline_editor_helper_spec.rb
+++ b/spec/helpers/ci/pipeline_editor_helper_spec.rb
@@ -19,12 +19,5 @@ RSpec.describe Ci::PipelineEditorHelper do
expect(subject).to be false
end
-
- it 'user can not view editor if feature is disabled' do
- allow(helper).to receive(:can_collaborate_with_project?).and_return(true)
- stub_feature_flags(ci_pipeline_editor_page: false)
-
- expect(subject).to be false
- end
end
end
diff --git a/spec/helpers/commits_helper_spec.rb b/spec/helpers/commits_helper_spec.rb
index 2f5f4c4596b..397751b07af 100644
--- a/spec/helpers/commits_helper_spec.rb
+++ b/spec/helpers/commits_helper_spec.rb
@@ -3,6 +3,8 @@
require 'spec_helper'
RSpec.describe CommitsHelper do
+ include ProjectForksHelper
+
describe '#revert_commit_link' do
context 'when current_user exists' do
before do
@@ -238,15 +240,22 @@ RSpec.describe CommitsHelper do
expect(subject).to be_a(Gitlab::Git::DiffCollection)
end
end
+ end
- context "feature flag is disabled" do
- let(:paginate) { true }
+ describe '#cherry_pick_projects_data' do
+ let(:project) { create(:project, :repository) }
+ let(:user) { create(:user, maintainer_projects: [project]) }
+ let!(:forked_project) { fork_project(project, user, { namespace: user.namespace, repository: true }) }
- it "returns a standard DiffCollection" do
- stub_feature_flags(paginate_commit_view: false)
+ before do
+ allow(helper).to receive(:current_user).and_return(user)
+ end
- expect(subject).to be_a(Gitlab::Git::DiffCollection)
- end
+ it 'returns data for cherry picking into a project' do
+ expect(helper.cherry_pick_projects_data(project)).to match_array([
+ { id: project.id.to_s, name: project.full_path, refsUrl: refs_project_path(project) },
+ { id: forked_project.id.to_s, name: forked_project.full_path, refsUrl: refs_project_path(forked_project) }
+ ])
end
end
end
diff --git a/spec/helpers/gitlab_routing_helper_spec.rb b/spec/helpers/gitlab_routing_helper_spec.rb
index f23ffcee35d..0df04d2a8a7 100644
--- a/spec/helpers/gitlab_routing_helper_spec.rb
+++ b/spec/helpers/gitlab_routing_helper_spec.rb
@@ -332,4 +332,14 @@ RSpec.describe GitlabRoutingHelper do
end
end
end
+
+ context 'GraphQL ETag paths' do
+ context 'with pipelines' do
+ let(:pipeline) { double(id: 5) }
+
+ it 'returns an ETag path for pipelines' do
+ expect(graphql_etag_pipeline_path(pipeline)).to eq('/api/graphql:pipelines/id/5')
+ end
+ end
+ end
end
diff --git a/spec/helpers/groups_helper_spec.rb b/spec/helpers/groups_helper_spec.rb
index 61aaa618c45..0d2af464902 100644
--- a/spec/helpers/groups_helper_spec.rb
+++ b/spec/helpers/groups_helper_spec.rb
@@ -18,11 +18,17 @@ RSpec.describe GroupsHelper do
it 'gives default avatar_icon when no avatar is present' do
group = create(:group)
- group.save!
expect(group_icon_url(group.path)).to match_asset_path('group_avatar.png')
end
end
+ describe 'group_dependency_proxy_url' do
+ it 'converts uppercase letters to lowercase' do
+ group = create(: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) }
@@ -454,18 +460,12 @@ RSpec.describe GroupsHelper do
allow(helper).to receive(:current_user) { current_user }
end
- context 'when cached_sidebar_open_issues_count feature flag is enabled' do
- before do
- stub_feature_flags(cached_sidebar_open_issues_count: true)
+ it 'returns count value from cache' do
+ allow_next_instance_of(count_service) do |service|
+ allow(service).to receive(:count).and_return(2500)
end
- it 'returns count value from cache' do
- allow_next_instance_of(count_service) do |service|
- allow(service).to receive(:count).and_return(2500)
- end
-
- expect(helper.group_open_issues_count(group)).to eq('2.5k')
- end
+ expect(helper.group_open_issues_count(group)).to eq('2.5k')
end
context 'when cached_sidebar_open_issues_count feature flag is disabled' do
diff --git a/spec/helpers/ide_helper_spec.rb b/spec/helpers/ide_helper_spec.rb
new file mode 100644
index 00000000000..db30446fa95
--- /dev/null
+++ b/spec/helpers/ide_helper_spec.rb
@@ -0,0 +1,47 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe IdeHelper do
+ describe '#ide_data' do
+ let_it_be(:project) { create(:project) }
+
+ before do
+ allow(helper).to receive(:current_user).and_return(project.creator)
+ end
+
+ context 'when instance vars are not set' do
+ it 'returns instance data in the hash as nil' do
+ expect(helper.ide_data)
+ .to include(
+ 'branch-name' => nil,
+ 'file-path' => nil,
+ 'merge-request' => nil,
+ 'forked-project' => nil,
+ 'project' => nil
+ )
+ end
+ end
+
+ context 'when instance vars are set' do
+ it 'returns instance data in the hash' do
+ self.instance_variable_set(:@branch, 'master')
+ self.instance_variable_set(:@path, 'foo/bar')
+ self.instance_variable_set(:@merge_request, '1')
+ self.instance_variable_set(:@forked_project, project)
+ self.instance_variable_set(:@project, project)
+
+ serialized_project = API::Entities::Project.represent(project).to_json
+
+ expect(helper.ide_data)
+ .to include(
+ 'branch-name' => 'master',
+ 'file-path' => 'foo/bar',
+ 'merge-request' => '1',
+ 'forked-project' => serialized_project,
+ 'project' => serialized_project
+ )
+ end
+ end
+ end
+end
diff --git a/spec/helpers/invite_members_helper_spec.rb b/spec/helpers/invite_members_helper_spec.rb
index 576021b37b3..62bd953cce8 100644
--- a/spec/helpers/invite_members_helper_spec.rb
+++ b/spec/helpers/invite_members_helper_spec.rb
@@ -11,6 +11,21 @@ RSpec.describe InviteMembersHelper do
helper.extend(Gitlab::Experimentation::ControllerConcern)
end
+ describe '#show_invite_members_track_event' do
+ it 'shows values when can directly invite members' do
+ allow(helper).to receive(:directly_invite_members?).and_return(true)
+
+ expect(helper.show_invite_members_track_event).to eq 'show_invite_members'
+ end
+
+ it 'shows values when can indirectly invite members' do
+ allow(helper).to receive(:directly_invite_members?).and_return(false)
+ allow(helper).to receive(:indirectly_invite_members?).and_return(true)
+
+ expect(helper.show_invite_members_track_event).to eq 'show_invite_members_version_b'
+ end
+ end
+
context 'with project' do
before do
assign(:project, project)
@@ -56,15 +71,7 @@ RSpec.describe InviteMembersHelper do
allow(helper).to receive(:current_user) { owner }
end
- it 'returns false' do
- allow(helper).to receive(:experiment_enabled?).with(:invite_members_version_a) { false }
-
- expect(helper.directly_invite_members?).to eq false
- end
-
it 'returns true' do
- allow(helper).to receive(:experiment_enabled?).with(:invite_members_version_a) { true }
-
expect(helper.directly_invite_members?).to eq true
end
end
@@ -75,8 +82,6 @@ RSpec.describe InviteMembersHelper do
end
it 'returns false' do
- allow(helper).to receive(:experiment_enabled?).with(:invite_members_version_a) { true }
-
expect(helper.directly_invite_members?).to eq false
end
end
diff --git a/spec/helpers/issuables_description_templates_helper_spec.rb b/spec/helpers/issuables_description_templates_helper_spec.rb
index 42643b755f8..e8961ccb535 100644
--- a/spec/helpers/issuables_description_templates_helper_spec.rb
+++ b/spec/helpers/issuables_description_templates_helper_spec.rb
@@ -13,22 +13,33 @@ RSpec.describe IssuablesDescriptionTemplatesHelper, :clean_gitlab_redis_cache do
let_it_be(:group_member) { create(:group_member, :developer, group: parent_group, user: user) }
let_it_be(:project_member) { create(:project_member, :developer, user: user, project: project) }
- it 'returns empty hash when template type does not exist' do
- expect(helper.issuable_templates(build(:project), 'non-existent-template-type')).to eq([])
+ context 'when feature flag disabled' do
+ before do
+ stub_feature_flags(inherited_issuable_templates: false)
+ end
+
+ it 'returns empty array when template type does not exist' do
+ expect(helper.issuable_templates(project, 'non-existent-template-type')).to eq([])
+ end
end
- context 'with cached issuable templates' do
+ context 'when feature flag enabled' do
before do
- allow(Gitlab::Template::IssueTemplate).to receive(:template_names).and_return({})
- allow(Gitlab::Template::MergeRequestTemplate).to receive(:template_names).and_return({})
+ stub_feature_flags(inherited_issuable_templates: true)
+ end
- helper.issuable_templates(project, 'issues')
- helper.issuable_templates(project, 'merge_request')
+ it 'returns empty hash when template type does not exist' do
+ expect(helper.issuable_templates(build(:project), 'non-existent-template-type')).to eq({})
end
+ end
+ context 'with cached issuable templates' do
it 'does not call TemplateFinder' do
- expect(Gitlab::Template::IssueTemplate).not_to receive(:template_names)
- expect(Gitlab::Template::MergeRequestTemplate).not_to receive(:template_names)
+ expect(Gitlab::Template::IssueTemplate).to receive(:template_names).once.and_call_original
+ expect(Gitlab::Template::MergeRequestTemplate).to receive(:template_names).once.and_call_original
+
+ helper.issuable_templates(project, 'issues')
+ helper.issuable_templates(project, 'merge_request')
helper.issuable_templates(project, 'issues')
helper.issuable_templates(project, 'merge_request')
end
@@ -63,29 +74,78 @@ RSpec.describe IssuablesDescriptionTemplatesHelper, :clean_gitlab_redis_cache do
end
describe '#issuable_templates_names' do
- let(:project) { double(Project, id: 21) }
-
- let(:templates) do
- [
- { name: "another_issue_template", id: "another_issue_template", project_id: project.id },
- { name: "custom_issue_template", id: "custom_issue_template", project_id: project.id }
- ]
- end
+ let_it_be(:project) { build(:project) }
- it 'returns project templates only' do
+ before do
allow(helper).to receive(:ref_project).and_return(project)
allow(helper).to receive(:issuable_templates).and_return(templates)
+ end
+
+ context 'when feature flag disabled' do
+ let(:templates) do
+ [
+ { name: "another_issue_template", id: "another_issue_template", project_id: project.id },
+ { name: "custom_issue_template", id: "custom_issue_template", project_id: project.id }
+ ]
+ end
- expect(helper.issuable_templates_names(Issue.new)).to eq(%w[another_issue_template custom_issue_template])
+ before do
+ stub_feature_flags(inherited_issuable_templates: false)
+ end
+
+ it 'returns project templates only' do
+ expect(helper.issuable_templates_names(Issue.new)).to eq(%w[another_issue_template custom_issue_template])
+ end
+ end
+
+ context 'when feature flag enabled' do
+ before do
+ stub_feature_flags(inherited_issuable_templates: true)
+ end
+
+ context 'with matching project templates' do
+ let(:templates) do
+ {
+ "" => [
+ { name: "another_issue_template", id: "another_issue_template", project_id: project.id },
+ { name: "custom_issue_template", id: "custom_issue_template", project_id: project.id }
+ ],
+ "Instance" => [
+ { name: "first_issue_issue_template", id: "first_issue_issue_template", project_id: non_existing_record_id },
+ { name: "second_instance_issue_template", id: "second_instance_issue_template", project_id: non_existing_record_id }
+ ]
+ }
+ end
+
+ it 'returns project templates only' do
+ expect(helper.issuable_templates_names(Issue.new)).to eq(%w[another_issue_template custom_issue_template])
+ end
+ end
+
+ context 'without matching project templates' do
+ let(:templates) do
+ {
+ "Project Templates" => [
+ { name: "another_issue_template", id: "another_issue_template", project_id: non_existing_record_id },
+ { name: "custom_issue_template", id: "custom_issue_template", project_id: non_existing_record_id }
+ ],
+ "Instance" => [
+ { name: "first_issue_issue_template", id: "first_issue_issue_template", project_id: non_existing_record_id },
+ { name: "second_instance_issue_template", id: "second_instance_issue_template", project_id: non_existing_record_id }
+ ]
+ }
+ end
+
+ it 'returns empty array' do
+ expect(helper.issuable_templates_names(Issue.new)).to eq([])
+ end
+ end
end
context 'when there are not templates in the project' do
let(:templates) { {} }
it 'returns empty array' do
- allow(helper).to receive(:ref_project).and_return(project)
- allow(helper).to receive(:issuable_templates).and_return(templates)
-
expect(helper.issuable_templates_names(Issue.new)).to eq([])
end
end
diff --git a/spec/helpers/learn_gitlab_helper_spec.rb b/spec/helpers/learn_gitlab_helper_spec.rb
index f789eb9d940..6cee8a9191c 100644
--- a/spec/helpers/learn_gitlab_helper_spec.rb
+++ b/spec/helpers/learn_gitlab_helper_spec.rb
@@ -41,11 +41,13 @@ RSpec.describe LearnGitlabHelper do
it 'sets correct path and completion status' do
expect(onboarding_actions_data[:git_write]).to eq({
url: project_issue_url(project, LearnGitlabHelper::ACTION_ISSUE_IDS[:git_write]),
- completed: true
+ completed: true,
+ svg: helper.image_path("learn_gitlab/git_write.svg")
})
expect(onboarding_actions_data[:pipeline_created]).to eq({
url: project_issue_url(project, LearnGitlabHelper::ACTION_ISSUE_IDS[:pipeline_created]),
- completed: false
+ completed: false,
+ svg: helper.image_path("learn_gitlab/pipeline_created.svg")
})
end
end
diff --git a/spec/helpers/merge_requests_helper_spec.rb b/spec/helpers/merge_requests_helper_spec.rb
index fce4d560b2f..3cf855229bb 100644
--- a/spec/helpers/merge_requests_helper_spec.rb
+++ b/spec/helpers/merge_requests_helper_spec.rb
@@ -90,4 +90,57 @@ RSpec.describe MergeRequestsHelper do
)
end
end
+
+ describe '#reviewers_label' do
+ let(:merge_request) { build_stubbed(:merge_request) }
+ let(:reviewer1) { build_stubbed(:user, name: 'Jane Doe') }
+ let(:reviewer2) { build_stubbed(:user, name: 'John Doe') }
+
+ before do
+ allow(merge_request).to receive(:reviewers).and_return(reviewers)
+ end
+
+ context 'when multiple reviewers exist' do
+ let(:reviewers) { [reviewer1, reviewer2] }
+
+ it 'returns reviewer label with reviewer names' do
+ expect(helper.reviewers_label(merge_request)).to eq("Reviewers: Jane Doe and John Doe")
+ end
+
+ it 'returns reviewer label only with include_value: false' do
+ expect(helper.reviewers_label(merge_request, include_value: false)).to eq("Reviewers")
+ end
+
+ context 'when the name contains a URL' do
+ let(:reviewers) { [build_stubbed(:user, name: 'www.gitlab.com')] }
+
+ it 'returns sanitized name' do
+ expect(helper.reviewers_label(merge_request)).to eq("Reviewer: www_gitlab_com")
+ end
+ end
+ end
+
+ context 'when one reviewer exists' do
+ let(:reviewers) { [reviewer1] }
+
+ it 'returns reviewer label with no names' do
+ expect(helper.reviewers_label(merge_request)).to eq("Reviewer: Jane Doe")
+ end
+
+ it 'returns reviewer label only with include_value: false' do
+ expect(helper.reviewers_label(merge_request, include_value: false)).to eq("Reviewer")
+ end
+ end
+
+ context 'when no reviewers exist' do
+ let(:reviewers) { [] }
+
+ it 'returns reviewer label with no names' do
+ expect(helper.reviewers_label(merge_request)).to eq("Reviewers: ")
+ end
+ it 'returns reviewer label only with include_value: false' do
+ expect(helper.reviewers_label(merge_request, include_value: false)).to eq("Reviewers")
+ end
+ end
+ end
end
diff --git a/spec/helpers/namespaces_helper_spec.rb b/spec/helpers/namespaces_helper_spec.rb
index 1636ba6ef42..b436f4ab0c9 100644
--- a/spec/helpers/namespaces_helper_spec.rb
+++ b/spec/helpers/namespaces_helper_spec.rb
@@ -46,13 +46,26 @@ RSpec.describe NamespacesHelper do
end
describe '#namespaces_options' do
- it 'returns groups without being a member for admin' do
- allow(helper).to receive(:current_user).and_return(admin)
+ context 'when admin mode is enabled', :enable_admin_mode do
+ it 'returns groups without being a member for admin' do
+ allow(helper).to receive(:current_user).and_return(admin)
- options = helper.namespaces_options(user_group.id, display_path: true, extra_group: user_group.id)
+ options = helper.namespaces_options(user_group.id, display_path: true, extra_group: user_group.id)
- expect(options).to include(admin_group.name)
- expect(options).to include(user_group.name)
+ expect(options).to include(admin_group.name)
+ expect(options).to include(user_group.name)
+ end
+ end
+
+ context 'when admin mode is disabled' do
+ it 'returns only allowed namespaces for admin' do
+ allow(helper).to receive(:current_user).and_return(admin)
+
+ options = helper.namespaces_options(user_group.id, display_path: true, extra_group: user_group.id)
+
+ expect(options).to include(admin_group.name)
+ expect(options).not_to include(user_group.name)
+ end
end
it 'returns only allowed namespaces for user' do
@@ -74,13 +87,16 @@ RSpec.describe NamespacesHelper do
expect(options).to include(admin_group.name)
end
- it 'selects existing group' do
- allow(helper).to receive(:current_user).and_return(admin)
+ context 'when admin mode is disabled' do
+ it 'selects existing group' do
+ allow(helper).to receive(:current_user).and_return(admin)
+ user_group.add_owner(admin)
- options = helper.namespaces_options(:extra_group, display_path: true, extra_group: user_group)
+ options = helper.namespaces_options(:extra_group, display_path: true, extra_group: user_group)
- expect(options).to include("selected=\"selected\" value=\"#{user_group.id}\"")
- expect(options).to include(admin_group.name)
+ expect(options).to include("selected=\"selected\" value=\"#{user_group.id}\"")
+ expect(options).to include(admin_group.name)
+ end
end
it 'selects the new group by default' do
diff --git a/spec/helpers/notifications_helper_spec.rb b/spec/helpers/notifications_helper_spec.rb
index 555cffba614..a5338659659 100644
--- a/spec/helpers/notifications_helper_spec.rb
+++ b/spec/helpers/notifications_helper_spec.rb
@@ -19,22 +19,6 @@ RSpec.describe NotificationsHelper do
it { expect(notification_title(:global)).to match('Global') }
end
- describe '#notification_event_name' do
- context 'for success_pipeline' do
- it 'returns the custom name' do
- expect(FastGettext).to receive(:cached_find).with('NotificationEvent|Successful pipeline')
- expect(notification_event_name(:success_pipeline)).to eq('Successful pipeline')
- end
- end
-
- context 'for everything else' do
- it 'returns a humanized name' do
- expect(FastGettext).to receive(:cached_find).with('NotificationEvent|Failed pipeline')
- expect(notification_event_name(:failed_pipeline)).to eq('Failed pipeline')
- end
- end
- end
-
describe '#notification_icon_level' do
let(:user) { create(:user) }
let(:global_setting) { user.global_notification_setting }
diff --git a/spec/helpers/preferences_helper_spec.rb b/spec/helpers/preferences_helper_spec.rb
index be0ad5e1a3f..e5420fb6729 100644
--- a/spec/helpers/preferences_helper_spec.rb
+++ b/spec/helpers/preferences_helper_spec.rb
@@ -29,6 +29,7 @@ RSpec.describe PreferencesHelper do
['Starred Projects', 'stars'],
["Your Projects' Activity", 'project_activity'],
["Starred Projects' Activity", 'starred_project_activity'],
+ ["Followed Users' Activity", 'followed_user_activity'],
["Your Groups", 'groups'],
["Your To-Do List", 'todos'],
["Assigned Issues", 'issues'],
diff --git a/spec/helpers/projects/project_members_helper_spec.rb b/spec/helpers/projects/project_members_helper_spec.rb
index 5e0b4df7f7f..1a55840a58a 100644
--- a/spec/helpers/projects/project_members_helper_spec.rb
+++ b/spec/helpers/projects/project_members_helper_spec.rb
@@ -166,7 +166,7 @@ RSpec.describe Projects::ProjectMembersHelper do
members: helper.project_members_data_json(project, present_members(project_members)),
member_path: '/foo-bar/-/project_members/:id',
source_id: project.id,
- can_manage_members: true
+ can_manage_members: 'true'
})
end
end
@@ -193,7 +193,7 @@ RSpec.describe Projects::ProjectMembersHelper do
members: helper.project_group_links_data_json(project_group_links),
member_path: '/foo-bar/-/group_links/:id',
source_id: project.id,
- can_manage_members: true
+ can_manage_members: 'true'
})
end
end
diff --git a/spec/helpers/projects/security/configuration_helper_spec.rb b/spec/helpers/projects/security/configuration_helper_spec.rb
new file mode 100644
index 00000000000..c5049bd87f0
--- /dev/null
+++ b/spec/helpers/projects/security/configuration_helper_spec.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Projects::Security::ConfigurationHelper do
+ let(:current_user) { create(:user) }
+
+ describe 'security_upgrade_path' do
+ subject { security_upgrade_path }
+
+ it { is_expected.to eq('https://about.gitlab.com/pricing/') }
+ end
+end
diff --git a/spec/helpers/projects_helper_spec.rb b/spec/helpers/projects_helper_spec.rb
index 303e3c78153..e6cd11a4d70 100644
--- a/spec/helpers/projects_helper_spec.rb
+++ b/spec/helpers/projects_helper_spec.rb
@@ -401,40 +401,20 @@ RSpec.describe ProjectsHelper do
context 'Security & Compliance tabs' do
before do
- stub_feature_flags(secure_security_and_compliance_configuration_page_on_ce: feature_flag_enabled)
allow(helper).to receive(:can?).with(user, :read_security_configuration, project).and_return(can_read_security_configuration)
end
context 'when user cannot read security configuration' do
let(:can_read_security_configuration) { false }
- context 'when feature flag is disabled' do
- let(:feature_flag_enabled) { false }
-
- it { is_expected.not_to include(:security_configuration) }
- end
-
- context 'when feature flag is enabled' do
- let(:feature_flag_enabled) { true }
-
- it { is_expected.not_to include(:security_configuration) }
- end
+ it { is_expected.not_to include(:security_configuration) }
end
context 'when user can read security configuration' do
let(:can_read_security_configuration) { true }
+ let(:feature_flag_enabled) { true }
- context 'when feature flag is disabled' do
- let(:feature_flag_enabled) { false }
-
- it { is_expected.not_to include(:security_configuration) }
- end
-
- context 'when feature flag is enabled' do
- let(:feature_flag_enabled) { true }
-
- it { is_expected.to include(:security_configuration) }
- end
+ it { is_expected.to include(:security_configuration) }
end
end
diff --git a/spec/helpers/search_helper_spec.rb b/spec/helpers/search_helper_spec.rb
index a977f2c88c6..13d3a80bd13 100644
--- a/spec/helpers/search_helper_spec.rb
+++ b/spec/helpers/search_helper_spec.rb
@@ -534,10 +534,11 @@ RSpec.describe SearchHelper do
where(:description, :expected) do
'test' | '<span class="gl-text-gray-900 gl-font-weight-bold">test</span>'
- '<span style="color: blue;">this test should not be blue</span>' | '<span>this <span class="gl-text-gray-900 gl-font-weight-bold">test</span> should not be blue</span>'
+ '<span style="color: blue;">this test should not be blue</span>' | 'this <span class="gl-text-gray-900 gl-font-weight-bold">test</span> should not be blue'
'<a href="#" onclick="alert(\'XSS\')">Click Me test</a>' | '<a href="#">Click Me <span class="gl-text-gray-900 gl-font-weight-bold">test</span></a>'
'<script type="text/javascript">alert(\'Another XSS\');</script> test' | ' <span class="gl-text-gray-900 gl-font-weight-bold">test</span>'
'Lorem test ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec.' | 'Lorem <span class="gl-text-gray-900 gl-font-weight-bold">test</span> ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Don...'
+ '<img src="https://random.foo.com/test.png" width="128" height="128" />some image' | 'some image'
end
with_them do
@@ -580,7 +581,7 @@ RSpec.describe SearchHelper do
describe '#issuable_state_to_badge_class' do
context 'with merge request' do
it 'returns correct badge based on status' do
- expect(issuable_state_to_badge_class(build(:merge_request, :merged))).to eq(:primary)
+ expect(issuable_state_to_badge_class(build(:merge_request, :merged))).to eq(:info)
expect(issuable_state_to_badge_class(build(:merge_request, :closed))).to eq(:danger)
expect(issuable_state_to_badge_class(build(:merge_request, :opened))).to eq(:success)
end
diff --git a/spec/helpers/services_helper_spec.rb b/spec/helpers/services_helper_spec.rb
index 534f33d9b5a..1726a8362a7 100644
--- a/spec/helpers/services_helper_spec.rb
+++ b/spec/helpers/services_helper_spec.rb
@@ -4,27 +4,35 @@ require 'spec_helper'
RSpec.describe ServicesHelper do
describe '#integration_form_data' do
+ let(:fields) do
+ [
+ :id,
+ :show_active,
+ :activated,
+ :type,
+ :merge_request_events,
+ :commit_events,
+ :enable_comments,
+ :comment_detail,
+ :learn_more_path,
+ :trigger_events,
+ :fields,
+ :inherit_from_id,
+ :integration_level,
+ :editable,
+ :cancel_path,
+ :can_test,
+ :test_path,
+ :reset_path
+ ]
+ end
+
subject { helper.integration_form_data(integration) }
- context 'Jira service' do
- let(:integration) { build(:jira_service) }
-
- it 'includes Jira specific fields' do
- is_expected.to include(
- :id,
- :show_active,
- :activated,
- :type,
- :merge_request_events,
- :commit_events,
- :enable_comments,
- :comment_detail,
- :trigger_events,
- :fields,
- :inherit_from_id,
- :integration_level
- )
- end
+ context 'Slack service' do
+ let(:integration) { build(:slack_service) }
+
+ it { is_expected.to include(*fields) }
specify do
expect(subject[:reset_path]).to eq(helper.scoped_reset_integration_path(integration))
diff --git a/spec/helpers/stat_anchors_helper_spec.rb b/spec/helpers/stat_anchors_helper_spec.rb
index 0615baac3cb..f3830bf4172 100644
--- a/spec/helpers/stat_anchors_helper_spec.rb
+++ b/spec/helpers/stat_anchors_helper_spec.rb
@@ -18,7 +18,7 @@ RSpec.describe StatAnchorsHelper do
context 'when anchor is not a link' do
context 'when class_modifier is set' do
- let(:anchor) { anchor_klass.new(false, nil, nil, 'default') }
+ let(:anchor) { anchor_klass.new(false, nil, nil, 'btn-default') }
it 'returns the proper attributes' do
expect(subject[:class]).to include('gl-button btn btn-default')
@@ -49,5 +49,21 @@ RSpec.describe StatAnchorsHelper do
expect(subject[:itemprop]).to eq true
end
end
+
+ context 'when data is not set' do
+ let(:anchor) { anchor_klass.new(false, nil, nil, nil, nil, nil, nil) }
+
+ it 'returns the data attributes' do
+ expect(subject[:data]).to be_nil
+ end
+ end
+
+ context 'when itemprop is set' do
+ let(:anchor) { anchor_klass.new(false, nil, nil, nil, nil, nil, { 'toggle' => 'modal' }) }
+
+ it 'returns the data attributes' do
+ expect(subject[:data]).to eq({ 'toggle' => 'modal' })
+ end
+ end
end
end
diff --git a/spec/helpers/timeboxes_helper_spec.rb b/spec/helpers/timeboxes_helper_spec.rb
index 94e997f7a65..9cbed7668ac 100644
--- a/spec/helpers/timeboxes_helper_spec.rb
+++ b/spec/helpers/timeboxes_helper_spec.rb
@@ -58,15 +58,6 @@ RSpec.describe TimeboxesHelper do
it { expect(result_for(start_date: yesterday)).to eq("started on #{yesterday_formatted}") }
it { expect(result_for(start_date: yesterday, due_date: tomorrow)).to eq("#{yesterday_formatted}–#{tomorrow_formatted}") }
end
-
- context 'iteration' do
- # Iterations always have start and due dates, so only A-B format is expected
- it 'formats properly' do
- iteration = build(:iteration, start_date: yesterday, due_date: tomorrow)
-
- expect(timebox_date_range(iteration)).to eq("#{yesterday_formatted}–#{tomorrow_formatted}")
- end
- end
end
describe '#milestone_counts' do
diff --git a/spec/helpers/visibility_level_helper_spec.rb b/spec/helpers/visibility_level_helper_spec.rb
index 10e0815918f..2aac0cae0c6 100644
--- a/spec/helpers/visibility_level_helper_spec.rb
+++ b/spec/helpers/visibility_level_helper_spec.rb
@@ -33,6 +33,22 @@ RSpec.describe VisibilityLevelHelper do
end
end
+ describe 'visibility_level_label' do
+ using RSpec::Parameterized::TableSyntax
+
+ where(:level_value, :level_name) do
+ Gitlab::VisibilityLevel::PRIVATE | 'Private'
+ Gitlab::VisibilityLevel::INTERNAL | 'Internal'
+ Gitlab::VisibilityLevel::PUBLIC | 'Public'
+ end
+
+ with_them do
+ it 'returns the name of the visibility level' do
+ expect(visibility_level_label(level_value)).to eq(level_name)
+ end
+ end
+ end
+
describe 'visibility_level_description' do
context 'used with a Project' do
let(:descriptions) do