summaryrefslogtreecommitdiff
path: root/spec/helpers
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-07-20 12:26:25 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-07-20 12:26:25 +0000
commita09983ae35713f5a2bbb100981116d31ce99826e (patch)
tree2ee2af7bd104d57086db360a7e6d8c9d5d43667a /spec/helpers
parent18c5ab32b738c0b6ecb4d0df3994000482f34bd8 (diff)
downloadgitlab-ce-a09983ae35713f5a2bbb100981116d31ce99826e.tar.gz
Add latest changes from gitlab-org/gitlab@13-2-stable-ee
Diffstat (limited to 'spec/helpers')
-rw-r--r--spec/helpers/access_tokens_helper_spec.rb2
-rw-r--r--spec/helpers/analytics/unique_visits_helper_spec.rb56
-rw-r--r--spec/helpers/appearances_helper_spec.rb2
-rw-r--r--spec/helpers/application_helper_spec.rb12
-rw-r--r--spec/helpers/application_settings_helper_spec.rb2
-rw-r--r--spec/helpers/auth_helper_spec.rb2
-rw-r--r--spec/helpers/auto_devops_helper_spec.rb8
-rw-r--r--spec/helpers/avatars_helper_spec.rb2
-rw-r--r--spec/helpers/award_emoji_helper_spec.rb2
-rw-r--r--spec/helpers/blame_helper_spec.rb2
-rw-r--r--spec/helpers/blob_helper_spec.rb10
-rw-r--r--spec/helpers/boards_helper_spec.rb2
-rw-r--r--spec/helpers/broadcast_messages_helper_spec.rb2
-rw-r--r--spec/helpers/button_helper_spec.rb2
-rw-r--r--spec/helpers/calendar_helper_spec.rb2
-rw-r--r--spec/helpers/ci/builds_helper_spec.rb111
-rw-r--r--spec/helpers/ci/pipeline_schedules_helper_spec.rb24
-rw-r--r--spec/helpers/ci/runners_helper_spec.rb (renamed from spec/helpers/runners_helper_spec.rb)2
-rw-r--r--spec/helpers/ci/status_helper_spec.rb (renamed from spec/helpers/ci_status_helper_spec.rb)2
-rw-r--r--spec/helpers/clusters_helper_spec.rb26
-rw-r--r--spec/helpers/commits_helper_spec.rb16
-rw-r--r--spec/helpers/components_helper_spec.rb2
-rw-r--r--spec/helpers/container_expiration_policies_helper_spec.rb2
-rw-r--r--spec/helpers/cookies_helper_spec.rb42
-rw-r--r--spec/helpers/dashboard_helper_spec.rb2
-rw-r--r--spec/helpers/defer_script_tag_helper_spec.rb2
-rw-r--r--spec/helpers/diff_helper_spec.rb16
-rw-r--r--spec/helpers/emails_helper_spec.rb2
-rw-r--r--spec/helpers/emoji_helper_spec.rb2
-rw-r--r--spec/helpers/environment_helper_spec.rb2
-rw-r--r--spec/helpers/environments_helper_spec.rb59
-rw-r--r--spec/helpers/events_helper_spec.rb103
-rw-r--r--spec/helpers/explore_helper_spec.rb2
-rw-r--r--spec/helpers/export_helper_spec.rb2
-rw-r--r--spec/helpers/external_link_helper_spec.rb2
-rw-r--r--spec/helpers/form_helper_spec.rb2
-rw-r--r--spec/helpers/git_helper_spec.rb2
-rw-r--r--spec/helpers/gitlab_routing_helper_spec.rb49
-rw-r--r--spec/helpers/graph_helper_spec.rb2
-rw-r--r--spec/helpers/groups/group_members_helper_spec.rb2
-rw-r--r--spec/helpers/groups_helper_spec.rb2
-rw-r--r--spec/helpers/hooks_helper_spec.rb2
-rw-r--r--spec/helpers/icons_helper_spec.rb32
-rw-r--r--spec/helpers/import_helper_spec.rb2
-rw-r--r--spec/helpers/instance_configuration_helper_spec.rb2
-rw-r--r--spec/helpers/issuables_helper_spec.rb26
-rw-r--r--spec/helpers/issues_helper_spec.rb26
-rw-r--r--spec/helpers/labels_helper_spec.rb2
-rw-r--r--spec/helpers/markup_helper_spec.rb2
-rw-r--r--spec/helpers/members_helper_spec.rb2
-rw-r--r--spec/helpers/merge_requests_helper_spec.rb2
-rw-r--r--spec/helpers/namespaces_helper_spec.rb94
-rw-r--r--spec/helpers/nav_helper_spec.rb2
-rw-r--r--spec/helpers/notes_helper_spec.rb2
-rw-r--r--spec/helpers/notifications_helper_spec.rb2
-rw-r--r--spec/helpers/notify_helper_spec.rb33
-rw-r--r--spec/helpers/onboarding_experiment_helper_spec.rb38
-rw-r--r--spec/helpers/operations_helper_spec.rb160
-rw-r--r--spec/helpers/page_layout_helper_spec.rb2
-rw-r--r--spec/helpers/pagination_helper_spec.rb2
-rw-r--r--spec/helpers/preferences_helper_spec.rb9
-rw-r--r--spec/helpers/profiles_helper_spec.rb2
-rw-r--r--spec/helpers/projects/alert_management_helper_spec.rb33
-rw-r--r--spec/helpers/projects/error_tracking_helper_spec.rb2
-rw-r--r--spec/helpers/projects_helper_spec.rb47
-rw-r--r--spec/helpers/recaptcha_experiment_helper_spec.rb2
-rw-r--r--spec/helpers/releases_helper_spec.rb37
-rw-r--r--spec/helpers/rss_helper_spec.rb2
-rw-r--r--spec/helpers/search_helper_spec.rb95
-rw-r--r--spec/helpers/services_helper_spec.rb27
-rw-r--r--spec/helpers/sessions_helper_spec.rb2
-rw-r--r--spec/helpers/sidekiq_helper_spec.rb2
-rw-r--r--spec/helpers/snippets_helper_spec.rb2
-rw-r--r--spec/helpers/sorting_helper_spec.rb2
-rw-r--r--spec/helpers/sourcegraph_helper_spec.rb2
-rw-r--r--spec/helpers/storage_helper_spec.rb7
-rw-r--r--spec/helpers/submodule_helper_spec.rb2
-rw-r--r--spec/helpers/subscribable_banner_helper_spec.rb2
-rw-r--r--spec/helpers/tab_helper_spec.rb2
-rw-r--r--spec/helpers/time_helper_spec.rb2
-rw-r--r--spec/helpers/timeboxes_helper_spec.rb2
-rw-r--r--spec/helpers/timeboxes_routing_helper_spec.rb2
-rw-r--r--spec/helpers/todos_helper_spec.rb81
-rw-r--r--spec/helpers/tracking_helper_spec.rb2
-rw-r--r--spec/helpers/tree_helper_spec.rb56
-rw-r--r--spec/helpers/user_callouts_helper_spec.rb6
-rw-r--r--spec/helpers/users_helper_spec.rb2
-rw-r--r--spec/helpers/version_check_helper_spec.rb2
-rw-r--r--spec/helpers/visibility_level_helper_spec.rb2
-rw-r--r--spec/helpers/wiki_helper_spec.rb54
-rw-r--r--spec/helpers/x509_helper_spec.rb2
91 files changed, 1250 insertions, 263 deletions
diff --git a/spec/helpers/access_tokens_helper_spec.rb b/spec/helpers/access_tokens_helper_spec.rb
index 1d246d3f236..28041203447 100644
--- a/spec/helpers/access_tokens_helper_spec.rb
+++ b/spec/helpers/access_tokens_helper_spec.rb
@@ -2,7 +2,7 @@
require "spec_helper"
-describe AccessTokensHelper do
+RSpec.describe AccessTokensHelper do
describe "#scope_description" do
using RSpec::Parameterized::TableSyntax
diff --git a/spec/helpers/analytics/unique_visits_helper_spec.rb b/spec/helpers/analytics/unique_visits_helper_spec.rb
new file mode 100644
index 00000000000..ff9769078c4
--- /dev/null
+++ b/spec/helpers/analytics/unique_visits_helper_spec.rb
@@ -0,0 +1,56 @@
+# frozen_string_literal: true
+
+require "spec_helper"
+
+RSpec.describe Analytics::UniqueVisitsHelper do
+ include Devise::Test::ControllerHelpers
+
+ describe '#track_visit' do
+ let(:target_id) { 'p_analytics_valuestream' }
+ let(:current_user) { create(:user) }
+
+ before do
+ stub_feature_flags(track_unique_visits: true)
+ end
+
+ it 'does not track visits if feature flag disabled' do
+ stub_feature_flags(track_unique_visits: false)
+ sign_in(current_user)
+
+ expect_any_instance_of(Gitlab::Analytics::UniqueVisits).not_to receive(:track_visit)
+
+ helper.track_visit(target_id)
+ end
+
+ it 'does not track visits if usage ping is disabled' do
+ sign_in(current_user)
+ expect(Gitlab::CurrentSettings).to receive(:usage_ping_enabled?).and_return(false)
+
+ expect_any_instance_of(Gitlab::Analytics::UniqueVisits).not_to receive(:track_visit)
+
+ helper.track_visit(target_id)
+ end
+
+ it 'does not track visit if user is not logged in' do
+ expect_any_instance_of(Gitlab::Analytics::UniqueVisits).not_to receive(:track_visit)
+
+ helper.track_visit(target_id)
+ end
+
+ it 'tracks visit if user is logged in' do
+ sign_in(current_user)
+
+ expect_any_instance_of(Gitlab::Analytics::UniqueVisits).to receive(:track_visit)
+
+ helper.track_visit(target_id)
+ end
+
+ it 'tracks visit if user is not logged in, but has the cookie already' do
+ helper.request.cookies[:visitor_id] = { value: SecureRandom.uuid, expires: 24.months }
+
+ expect_any_instance_of(Gitlab::Analytics::UniqueVisits).to receive(:track_visit)
+
+ helper.track_visit(target_id)
+ end
+ end
+end
diff --git a/spec/helpers/appearances_helper_spec.rb b/spec/helpers/appearances_helper_spec.rb
index ed3e31b3c53..179c69b2a67 100644
--- a/spec/helpers/appearances_helper_spec.rb
+++ b/spec/helpers/appearances_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe AppearancesHelper do
+RSpec.describe AppearancesHelper do
before do
user = create(:user)
allow(helper).to receive(:current_user).and_return(user)
diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb
index 75377356445..08107b841d7 100644
--- a/spec/helpers/application_helper_spec.rb
+++ b/spec/helpers/application_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe ApplicationHelper do
+RSpec.describe ApplicationHelper do
describe 'current_controller?' do
before do
stub_controller_name('foo')
@@ -209,6 +209,16 @@ describe ApplicationHelper do
end
end
+ describe '#page_startup_api_calls' do
+ it 'returns map containing JS Page Startup Calls' do
+ helper.add_page_startup_api_call("testURL")
+
+ startup_calls = helper.page_startup_api_calls
+
+ expect(startup_calls["testURL"]).to eq({})
+ end
+ end
+
describe '#autocomplete_data_sources' do
let(:project) { create(:project) }
let(:noteable_type) { Issue }
diff --git a/spec/helpers/application_settings_helper_spec.rb b/spec/helpers/application_settings_helper_spec.rb
index 3fb754f1090..c5fd88ada8f 100644
--- a/spec/helpers/application_settings_helper_spec.rb
+++ b/spec/helpers/application_settings_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe ApplicationSettingsHelper do
+RSpec.describe ApplicationSettingsHelper do
context 'when all protocols in use' do
before do
stub_application_setting(enabled_git_access_protocol: '')
diff --git a/spec/helpers/auth_helper_spec.rb b/spec/helpers/auth_helper_spec.rb
index 23f3449d9a7..1e843ee221b 100644
--- a/spec/helpers/auth_helper_spec.rb
+++ b/spec/helpers/auth_helper_spec.rb
@@ -2,7 +2,7 @@
require "spec_helper"
-describe AuthHelper do
+RSpec.describe AuthHelper do
describe "button_based_providers" do
it 'returns all enabled providers from devise' do
allow(helper).to receive(:auth_providers) { [:twitter, :github] }
diff --git a/spec/helpers/auto_devops_helper_spec.rb b/spec/helpers/auto_devops_helper_spec.rb
index e0fecb0c159..ad705dc5a7b 100644
--- a/spec/helpers/auto_devops_helper_spec.rb
+++ b/spec/helpers/auto_devops_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe AutoDevopsHelper do
+RSpec.describe AutoDevopsHelper do
let_it_be(:project, reload: true) { create(:project) }
let_it_be(:user) { create(:user) }
@@ -93,6 +93,12 @@ describe AutoDevopsHelper do
end
end
+ describe '#auto_devops_settings_path' do
+ it 'returns auto devops settings path' do
+ expect(helper.auto_devops_settings_path(project)).to eql(project_settings_ci_cd_path(project, anchor: 'autodevops-settings'))
+ end
+ end
+
describe '#badge_for_auto_devops_scope' do
subject { helper.badge_for_auto_devops_scope(receiver) }
diff --git a/spec/helpers/avatars_helper_spec.rb b/spec/helpers/avatars_helper_spec.rb
index 2a030742cb9..9e18ab34c1f 100644
--- a/spec/helpers/avatars_helper_spec.rb
+++ b/spec/helpers/avatars_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe AvatarsHelper do
+RSpec.describe AvatarsHelper do
include UploadHelpers
let(:user) { create(:user) }
diff --git a/spec/helpers/award_emoji_helper_spec.rb b/spec/helpers/award_emoji_helper_spec.rb
index 3dee466a80c..51e0a1b9721 100644
--- a/spec/helpers/award_emoji_helper_spec.rb
+++ b/spec/helpers/award_emoji_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe AwardEmojiHelper do
+RSpec.describe AwardEmojiHelper do
describe '.toggle_award_url' do
subject { helper.toggle_award_url(awardable) }
diff --git a/spec/helpers/blame_helper_spec.rb b/spec/helpers/blame_helper_spec.rb
index 8b5de040508..6371c2b63ce 100644
--- a/spec/helpers/blame_helper_spec.rb
+++ b/spec/helpers/blame_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe BlameHelper do
+RSpec.describe BlameHelper do
describe '#get_age_map_start_date' do
let(:dates) do
[Time.zone.local(2014, 3, 17, 0, 0, 0),
diff --git a/spec/helpers/blob_helper_spec.rb b/spec/helpers/blob_helper_spec.rb
index 2631c219222..fe975aa7723 100644
--- a/spec/helpers/blob_helper_spec.rb
+++ b/spec/helpers/blob_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe BlobHelper do
+RSpec.describe BlobHelper do
include TreeHelper
describe '#highlight' do
@@ -53,20 +53,12 @@ describe BlobHelper do
end
it 'returns a link with the proper route' do
- stub_feature_flags(web_ide_default: false)
link = helper.edit_blob_button(project, 'master', 'README.md')
expect(Capybara.string(link).find_link('Edit')[:href]).to eq("/#{project.full_path}/-/edit/master/README.md")
end
- it 'returns a link with a Web IDE route' do
- link = helper.edit_blob_button(project, 'master', 'README.md')
-
- expect(Capybara.string(link).find_link('Edit')[:href]).to eq("/-/ide/project/#{project.full_path}/edit/master/-/README.md")
- end
-
it 'returns a link with the passed link_opts on the expected route' do
- stub_feature_flags(web_ide_default: false)
link = helper.edit_blob_button(project, 'master', 'README.md', link_opts: { mr_id: 10 })
expect(Capybara.string(link).find_link('Edit')[:href]).to eq("/#{project.full_path}/-/edit/master/README.md?mr_id=10")
diff --git a/spec/helpers/boards_helper_spec.rb b/spec/helpers/boards_helper_spec.rb
index cb9be9d5fb4..a805b96a8cc 100644
--- a/spec/helpers/boards_helper_spec.rb
+++ b/spec/helpers/boards_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe BoardsHelper do
+RSpec.describe BoardsHelper do
let_it_be(:project) { create(:project) }
describe '#build_issue_link_base' do
diff --git a/spec/helpers/broadcast_messages_helper_spec.rb b/spec/helpers/broadcast_messages_helper_spec.rb
index 58cc03a9446..21fde35954e 100644
--- a/spec/helpers/broadcast_messages_helper_spec.rb
+++ b/spec/helpers/broadcast_messages_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe BroadcastMessagesHelper do
+RSpec.describe BroadcastMessagesHelper do
describe 'current_broadcast_notification_message' do
subject { helper.current_broadcast_notification_message }
diff --git a/spec/helpers/button_helper_spec.rb b/spec/helpers/button_helper_spec.rb
index cf8887f9731..6a5cb73281e 100644
--- a/spec/helpers/button_helper_spec.rb
+++ b/spec/helpers/button_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe ButtonHelper do
+RSpec.describe ButtonHelper do
describe 'http_clone_button' do
let(:user) { create(:user) }
let(:project) { build_stubbed(:project) }
diff --git a/spec/helpers/calendar_helper_spec.rb b/spec/helpers/calendar_helper_spec.rb
index 8dba6815e8d..ceed4191ef4 100644
--- a/spec/helpers/calendar_helper_spec.rb
+++ b/spec/helpers/calendar_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe CalendarHelper do
+RSpec.describe CalendarHelper do
describe '#calendar_url_options' do
context 'when signed in' do
it "includes the current_user's feed_token" do
diff --git a/spec/helpers/ci/builds_helper_spec.rb b/spec/helpers/ci/builds_helper_spec.rb
new file mode 100644
index 00000000000..143d96cf632
--- /dev/null
+++ b/spec/helpers/ci/builds_helper_spec.rb
@@ -0,0 +1,111 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Ci::BuildsHelper do
+ describe '#build_summary' do
+ subject { helper.build_summary(build, skip: skip) }
+
+ context 'when build has no trace' do
+ let(:build) { instance_double(Ci::Build, has_trace?: false) }
+
+ context 'when skip is false' do
+ let(:skip) { false }
+
+ it 'returns no job log' do
+ expect(subject).to eq('No job log')
+ end
+ end
+
+ context 'when skip is true' do
+ let(:skip) { true }
+
+ it 'returns no job log' do
+ expect(subject).to eq('No job log')
+ end
+ end
+ end
+
+ context 'when build has trace' do
+ let(:build) { create(:ci_build, :trace_live) }
+
+ context 'when skip is true' do
+ let(:skip) { true }
+
+ it 'returns link to logs' do
+ expect(subject).to include('View job log')
+ expect(subject).to include(pipeline_job_url(build.pipeline, build))
+ end
+ end
+
+ context 'when skip is false' do
+ let(:skip) { false }
+
+ it 'returns log lines' do
+ expect(subject).to include(build.trace.html(last_lines: 10).html_safe)
+ end
+ end
+ end
+ end
+
+ describe '#sidebar_build_class' do
+ using RSpec::Parameterized::TableSyntax
+
+ where(:build_id, :current_build_id, :retried, :expected_result) do
+ 1 | 1 | true | 'active retried'
+ 1 | 1 | false | 'active'
+ 1 | 2 | false | ''
+ 1 | 2 | true | 'retried'
+ end
+
+ let(:build) { instance_double(Ci::Build, retried?: retried, id: build_id) }
+ let(:current_build) { instance_double(Ci::Build, retried?: true, id: current_build_id ) }
+
+ subject { helper.sidebar_build_class(build, current_build) }
+
+ with_them do
+ it 'builds sidebar html class' do
+ expect(subject).to eq(expected_result)
+ end
+ end
+ end
+
+ describe '#javascript_build_options' do
+ subject { helper.javascript_build_options }
+
+ it 'returns build options' do
+ project = assign_project
+ ci_build = assign_build
+
+ expect(subject).to eq({
+ page_path: project_job_path(project, ci_build),
+ build_status: ci_build.status,
+ build_stage: ci_build.stage,
+ log_state: ''
+ })
+ end
+ end
+
+ describe '#build_failed_issue_options' do
+ subject { helper.build_failed_issue_options }
+
+ it 'returns failed title and description' do
+ project = assign_project
+ ci_build = assign_build
+
+ expect(subject).to eq(title: "Job Failed \##{ci_build.id}", description: project_job_url(project, ci_build))
+ end
+ end
+
+ def assign_project
+ build(:project).tap do |project|
+ assign(:project, project)
+ end
+ end
+
+ def assign_build
+ create(:ci_build).tap do |ci_build|
+ assign(:build, ci_build)
+ end
+ end
+end
diff --git a/spec/helpers/ci/pipeline_schedules_helper_spec.rb b/spec/helpers/ci/pipeline_schedules_helper_spec.rb
new file mode 100644
index 00000000000..2a81c2a44a0
--- /dev/null
+++ b/spec/helpers/ci/pipeline_schedules_helper_spec.rb
@@ -0,0 +1,24 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Ci::PipelineSchedulesHelper, :aggregate_failures do
+ describe '#timezone_data' do
+ subject { helper.timezone_data }
+
+ it 'matches schema' do
+ expect(subject).not_to be_empty
+ subject.each_with_index do |timzone_hash, i|
+ expect(timzone_hash.keys).to contain_exactly(:name, :offset, :identifier), "Failed at index #{i}"
+ end
+ end
+
+ it 'formats for display' do
+ first_timezone = ActiveSupport::TimeZone.all[0]
+
+ expect(subject[0][:name]).to eq(first_timezone.name)
+ expect(subject[0][:offset]).to eq(first_timezone.now.utc_offset)
+ expect(subject[0][:identifier]).to eq(first_timezone.tzinfo.identifier)
+ end
+ end
+end
diff --git a/spec/helpers/runners_helper_spec.rb b/spec/helpers/ci/runners_helper_spec.rb
index 042714d002e..a006933a2a5 100644
--- a/spec/helpers/runners_helper_spec.rb
+++ b/spec/helpers/ci/runners_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe RunnersHelper do
+RSpec.describe Ci::RunnersHelper do
it "returns - not contacted yet" do
runner = FactoryBot.build :ci_runner
expect(runner_status_icon(runner)).to include("not connected yet")
diff --git a/spec/helpers/ci_status_helper_spec.rb b/spec/helpers/ci/status_helper_spec.rb
index 80be119b069..12a6acb1ecc 100644
--- a/spec/helpers/ci_status_helper_spec.rb
+++ b/spec/helpers/ci/status_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe CiStatusHelper do
+RSpec.describe Ci::StatusHelper do
include IconsHelper
let(:success_commit) { double("Ci::Pipeline", status: 'success') }
diff --git a/spec/helpers/clusters_helper_spec.rb b/spec/helpers/clusters_helper_spec.rb
index c41d4f0ede7..dff83005c89 100644
--- a/spec/helpers/clusters_helper_spec.rb
+++ b/spec/helpers/clusters_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe ClustersHelper do
+RSpec.describe ClustersHelper do
describe '#has_rbac_enabled?' do
context 'when kubernetes platform has been created' do
let(:platform_kubernetes) { build_stubbed(:cluster_platform_kubernetes) }
@@ -60,18 +60,24 @@ describe ClustersHelper do
end
describe '#js_clusters_list_data' do
- it 'displays endpoint path and images' do
- js_data = helper.js_clusters_list_data('/path')
+ subject { helper.js_clusters_list_data('/path') }
- expect(js_data[:endpoint]).to eq('/path')
+ it 'displays endpoint path' do
+ expect(subject[:endpoint]).to eq('/path')
+ end
+
+ it 'generates svg image data', :aggregate_failures do
+ expect(subject.dig(:img_tags, :aws, :path)).to match(%r(/illustrations/logos/amazon_eks|svg))
+ expect(subject.dig(:img_tags, :default, :path)).to match(%r(/illustrations/logos/kubernetes|svg))
+ expect(subject.dig(:img_tags, :gcp, :path)).to match(%r(/illustrations/logos/google_gke|svg))
- expect(js_data.dig(:img_tags, :aws, :path)).to match(%r(/illustrations/logos/amazon_eks|svg))
- expect(js_data.dig(:img_tags, :default, :path)).to match(%r(/illustrations/logos/kubernetes|svg))
- expect(js_data.dig(:img_tags, :gcp, :path)).to match(%r(/illustrations/logos/google_gke|svg))
+ expect(subject.dig(:img_tags, :aws, :text)).to eq('Amazon EKS')
+ expect(subject.dig(:img_tags, :default, :text)).to eq('Kubernetes Cluster')
+ expect(subject.dig(:img_tags, :gcp, :text)).to eq('Google GKE')
+ end
- expect(js_data.dig(:img_tags, :aws, :text)).to eq('Amazon EKS')
- expect(js_data.dig(:img_tags, :default, :text)).to eq('Kubernetes Cluster')
- expect(js_data.dig(:img_tags, :gcp, :text)).to eq('Google GKE')
+ it 'displays and ancestor_help_path' do
+ expect(subject[:ancestor_help_path]).to eq('/help/user/group/clusters/index#cluster-precedence')
end
end
diff --git a/spec/helpers/commits_helper_spec.rb b/spec/helpers/commits_helper_spec.rb
index e036e97f745..cc318a21fc9 100644
--- a/spec/helpers/commits_helper_spec.rb
+++ b/spec/helpers/commits_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe CommitsHelper do
+RSpec.describe CommitsHelper do
describe 'commit_author_link' do
it 'escapes the author email' do
commit = double(
@@ -51,6 +51,20 @@ describe CommitsHelper do
end
end
+ describe '#view_file_button' do
+ let(:project) { build(:project) }
+ let(:path) { 'path/to/file' }
+ let(:sha) { '1234567890' }
+
+ subject do
+ helper.view_file_button(sha, path, project)
+ end
+
+ it 'links to project files' do
+ expect(subject).to have_link('1234567', href: helper.project_blob_path(project, "#{sha}/#{path}"))
+ end
+ end
+
describe '#view_on_environment_button' do
let(:project) { create(:project) }
let(:environment) { create(:environment, external_url: 'http://example.com') }
diff --git a/spec/helpers/components_helper_spec.rb b/spec/helpers/components_helper_spec.rb
index 703bee0ca92..4fa6d27993f 100644
--- a/spec/helpers/components_helper_spec.rb
+++ b/spec/helpers/components_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe ComponentsHelper do
+RSpec.describe ComponentsHelper do
describe '#gitlab_workhorse_version' do
context 'without a Gitlab-Workhorse header' do
it 'shows the version from Gitlab::Workhorse.version' do
diff --git a/spec/helpers/container_expiration_policies_helper_spec.rb b/spec/helpers/container_expiration_policies_helper_spec.rb
index 6dcbadd89cb..b2a03f8d90f 100644
--- a/spec/helpers/container_expiration_policies_helper_spec.rb
+++ b/spec/helpers/container_expiration_policies_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe ContainerExpirationPoliciesHelper do
+RSpec.describe ContainerExpirationPoliciesHelper do
describe '#keep_n_options' do
it 'returns keep_n options formatted for dropdown usage' do
expected_result = [
diff --git a/spec/helpers/cookies_helper_spec.rb b/spec/helpers/cookies_helper_spec.rb
new file mode 100644
index 00000000000..c73e7d64987
--- /dev/null
+++ b/spec/helpers/cookies_helper_spec.rb
@@ -0,0 +1,42 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe CookiesHelper do
+ describe '#set_secure_cookie' do
+ it 'creates an encrypted cookie with expected attributes' do
+ stub_config_setting(https: true)
+ expiration = 1.month.from_now
+ key = :secure_cookie
+ value = 'secure value'
+
+ expect_next_instance_of(ActionDispatch::Cookies::EncryptedKeyRotatingCookieJar) do |instance|
+ expect(instance).to receive(:[]=).with(key, httponly: true, secure: true, expires: expiration, value: value)
+ end
+
+ helper.set_secure_cookie(key, value, httponly: true, expires: expiration, type: CookiesHelper::COOKIE_TYPE_ENCRYPTED)
+ end
+
+ it 'creates a permanent cookie with expected attributes' do
+ key = :permanent_cookie
+ value = 'permanent value'
+
+ expect_next_instance_of(ActionDispatch::Cookies::PermanentCookieJar) do |instance|
+ expect(instance).to receive(:[]=).with(key, httponly: false, secure: false, expires: nil, value: value)
+ end
+
+ helper.set_secure_cookie(key, value, type: CookiesHelper::COOKIE_TYPE_PERMANENT)
+ end
+
+ it 'creates a regular cookie with expected attributes' do
+ key = :regular_cookie
+ value = 'regular value'
+
+ expect_next_instance_of(ActionDispatch::Cookies::CookieJar) do |instance|
+ expect(instance).to receive(:[]=).with(key, httponly: false, secure: false, expires: nil, value: value)
+ end
+
+ helper.set_secure_cookie(key, value)
+ end
+ end
+end
diff --git a/spec/helpers/dashboard_helper_spec.rb b/spec/helpers/dashboard_helper_spec.rb
index 8a4ea33ac7c..65182dcb729 100644
--- a/spec/helpers/dashboard_helper_spec.rb
+++ b/spec/helpers/dashboard_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe DashboardHelper do
+RSpec.describe DashboardHelper do
let(:user) { build(:user) }
before do
diff --git a/spec/helpers/defer_script_tag_helper_spec.rb b/spec/helpers/defer_script_tag_helper_spec.rb
index 440904188ca..14317e353ab 100644
--- a/spec/helpers/defer_script_tag_helper_spec.rb
+++ b/spec/helpers/defer_script_tag_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe DeferScriptTagHelper do
+RSpec.describe DeferScriptTagHelper do
describe 'script tag' do
script_url = 'test.js'
diff --git a/spec/helpers/diff_helper_spec.rb b/spec/helpers/diff_helper_spec.rb
index 63aa41bbad5..ef1f0940074 100644
--- a/spec/helpers/diff_helper_spec.rb
+++ b/spec/helpers/diff_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe DiffHelper do
+RSpec.describe DiffHelper do
include RepoHelpers
let(:project) { create(:project, :repository) }
@@ -303,6 +303,20 @@ describe DiffHelper do
end
end
+ describe '#diff_file_html_data' do
+ let(:project) { build(:project) }
+ let(:path) { 'path/to/file' }
+ let(:sha) { '1234567890' }
+
+ subject do
+ helper.diff_file_html_data(project, path, sha)
+ end
+
+ it 'returns data for project files' do
+ expect(subject).to include(blob_diff_path: helper.project_blob_diff_path(project, "#{sha}/#{path}"))
+ end
+ end
+
describe '#diff_file_path_text' do
it 'returns full path by default' do
expect(diff_file_path_text(diff_file)).to eq(diff_file.new_path)
diff --git a/spec/helpers/emails_helper_spec.rb b/spec/helpers/emails_helper_spec.rb
index 0ff9080ef94..bc5fe05ab52 100644
--- a/spec/helpers/emails_helper_spec.rb
+++ b/spec/helpers/emails_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe EmailsHelper do
+RSpec.describe EmailsHelper do
describe 'closure_reason_text' do
context 'when given a MergeRequest' do
let(:merge_request) { create(:merge_request) }
diff --git a/spec/helpers/emoji_helper_spec.rb b/spec/helpers/emoji_helper_spec.rb
index 1b73e956f7a..15e4ce03960 100644
--- a/spec/helpers/emoji_helper_spec.rb
+++ b/spec/helpers/emoji_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe EmojiHelper do
+RSpec.describe EmojiHelper do
describe '#emoji_icon' do
let(:options) { {} }
let(:emoji_text) { 'rocket' }
diff --git a/spec/helpers/environment_helper_spec.rb b/spec/helpers/environment_helper_spec.rb
index 53953d72b06..8c542ca01f4 100644
--- a/spec/helpers/environment_helper_spec.rb
+++ b/spec/helpers/environment_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe EnvironmentHelper do
+RSpec.describe EnvironmentHelper do
describe '#render_deployment_status' do
context 'when using a manual deployment' do
it 'renders a span tag' do
diff --git a/spec/helpers/environments_helper_spec.rb b/spec/helpers/environments_helper_spec.rb
index 48104dfc5a6..90d6096654e 100644
--- a/spec/helpers/environments_helper_spec.rb
+++ b/spec/helpers/environments_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe EnvironmentsHelper do
+RSpec.describe EnvironmentsHelper do
let_it_be(:user) { create(:user) }
let_it_be(:project, reload: true) { create(:project, :repository) }
let_it_be(:environment) { create(:environment, project: project) }
@@ -23,6 +23,7 @@ describe EnvironmentsHelper do
'metrics-dashboard-base-path' => environment_metrics_path(environment),
'current-environment-name' => environment.name,
'documentation-path' => help_page_path('administration/monitoring/prometheus/index.md'),
+ 'add-dashboard-documentation-path' => help_page_path('user/project/integrations/prometheus.md', anchor: 'adding-a-new-dashboard-to-your-project'),
'empty-getting-started-svg-path' => match_asset_path('/assets/illustrations/monitoring/getting_started.svg'),
'empty-loading-svg-path' => match_asset_path('/assets/illustrations/monitoring/loading.svg'),
'empty-no-data-svg-path' => match_asset_path('/assets/illustrations/monitoring/no_data.svg'),
@@ -41,10 +42,26 @@ describe EnvironmentsHelper do
'custom-metrics-available' => 'true',
'alerts-endpoint' => project_prometheus_alerts_path(project, environment_id: environment.id, format: :json),
'prometheus-alerts-available' => 'true',
- 'custom-dashboard-base-path' => Metrics::Dashboard::CustomDashboardService::DASHBOARD_ROOT
+ 'custom-dashboard-base-path' => Metrics::Dashboard::CustomDashboardService::DASHBOARD_ROOT,
+ 'operations-settings-path' => project_settings_operations_path(project),
+ 'can-access-operations-settings' => 'true'
)
end
+ context 'without admin_operations permission' do
+ before do
+ allow(helper).to receive(:can?)
+ .with(user, :admin_operations, project)
+ .and_return(false)
+ end
+
+ specify do
+ expect(metrics_data).to include(
+ 'can-access-operations-settings' => 'false'
+ )
+ end
+ end
+
context 'without read_prometheus_alerts permission' do
before do
allow(helper).to receive(:can?)
@@ -78,6 +95,30 @@ describe EnvironmentsHelper do
it { is_expected.to include('environment-state' => 'stopped') }
end
+
+ context 'when request is from project scoped metrics path' do
+ let(:request) { double('request', path: path) }
+
+ before do
+ allow(helper).to receive(:request).and_return(request)
+ end
+
+ context '/:namespace/:project/-/metrics' do
+ let(:path) { project_metrics_dashboard_path(project) }
+
+ it 'uses correct path for metrics-dashboard-base-path' do
+ expect(metrics_data['metrics-dashboard-base-path']).to eq(project_metrics_dashboard_path(project))
+ end
+ end
+
+ context '/:namespace/:project/-/metrics/some_custom_dashboard.yml' do
+ let(:path) { "#{project_metrics_dashboard_path(project)}/some_custom_dashboard.yml" }
+
+ it 'uses correct path for metrics-dashboard-base-path' do
+ expect(metrics_data['metrics-dashboard-base-path']).to eq(project_metrics_dashboard_path(project))
+ end
+ end
+ end
end
describe '#custom_metrics_available?' do
@@ -97,4 +138,18 @@ describe EnvironmentsHelper do
expect(subject).to eq(true)
end
end
+
+ describe '#environment_logs_data' do
+ it 'returns logs data' do
+ expected_data = {
+ "environment-name": environment.name,
+ "environments-path": project_environments_path(project, format: :json),
+ "environment-id": environment.id,
+ "cluster-applications-documentation-path" => help_page_path('user/clusters/applications.md', anchor: 'elastic-stack'),
+ "clusters-path": project_clusters_path(project, format: :json)
+ }
+
+ expect(helper.environment_logs_data(project, environment)).to eq(expected_data)
+ end
+ end
end
diff --git a/spec/helpers/events_helper_spec.rb b/spec/helpers/events_helper_spec.rb
index 6f24308757d..4ca31405c1e 100644
--- a/spec/helpers/events_helper_spec.rb
+++ b/spec/helpers/events_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe EventsHelper do
+RSpec.describe EventsHelper do
include Gitlab::Routing
describe '#event_commit_title' do
@@ -174,8 +174,8 @@ describe EventsHelper do
url = helper.event_wiki_page_target_url(event)
title = event.target_title
html = [
- "<span class=\"event-target-type append-right-4\">wiki page</span>",
- "<a title=\"#{title}\" class=\"has-tooltip event-target-link append-right-4\" href=\"#{url}\">",
+ "<span class=\"event-target-type gl-mr-2\">wiki page</span>",
+ "<a title=\"#{title}\" class=\"has-tooltip event-target-link gl-mr-2\" href=\"#{url}\">",
title,
"</a>"
].join
@@ -227,4 +227,101 @@ describe EventsHelper do
end
end
end
+
+ describe '#event_filter_visible' do
+ include DesignManagementTestHelpers
+
+ let_it_be(:project) { create(:project) }
+ let_it_be(:current_user) { create(:user) }
+
+ subject { helper.event_filter_visible(key) }
+
+ before do
+ enable_design_management
+ project.add_reporter(current_user)
+ allow(helper).to receive(:current_user).and_return(current_user)
+ end
+
+ def disable_read_design_activity(object)
+ allow(Ability).to receive(:allowed?)
+ .with(current_user, :read_design_activity, eq(object))
+ .and_return(false)
+ end
+
+ context 'for :designs' do
+ let(:key) { :designs }
+
+ context 'there is no relevant instance variable' do
+ it { is_expected.to be(true) }
+ end
+
+ context 'a project has been assigned' do
+ before do
+ assign(:project, project)
+ end
+
+ it { is_expected.to be(true) }
+
+ context 'the current user cannot read design activity' do
+ before do
+ disable_read_design_activity(project)
+ end
+
+ it { is_expected.to be(false) }
+ end
+ end
+
+ context 'projects have been assigned' do
+ before do
+ assign(:projects, Project.where(id: project.id))
+ end
+
+ it { is_expected.to be(true) }
+
+ context 'the collection is empty' do
+ before do
+ assign(:projects, Project.none)
+ end
+
+ it { is_expected.to be(false) }
+ end
+
+ context 'the current user cannot read design activity' do
+ before do
+ disable_read_design_activity(project)
+ end
+
+ it { is_expected.to be(false) }
+ end
+ end
+
+ context 'a group has been assigned' do
+ let_it_be(:group) { create(:group) }
+
+ before do
+ assign(:group, group)
+ end
+
+ context 'there are no projects in the group' do
+ it { is_expected.to be(false) }
+ end
+
+ context 'the group has at least one project' do
+ before do
+ create(:project_group_link, project: project, group: group)
+ end
+
+ it { is_expected.to be(true) }
+
+ context 'the current user cannot read design activity' do
+ before do
+ disable_read_design_activity(group)
+ end
+
+ it { is_expected.to be(false) }
+ end
+ end
+ end
+ end
+ end
end
diff --git a/spec/helpers/explore_helper_spec.rb b/spec/helpers/explore_helper_spec.rb
index 1a6af3be055..d843a9d3ce5 100644
--- a/spec/helpers/explore_helper_spec.rb
+++ b/spec/helpers/explore_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe ExploreHelper do
+RSpec.describe ExploreHelper do
let(:user) { build(:user) }
before do
diff --git a/spec/helpers/export_helper_spec.rb b/spec/helpers/export_helper_spec.rb
index 3fbda441b5d..7ab9560ca6a 100644
--- a/spec/helpers/export_helper_spec.rb
+++ b/spec/helpers/export_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe ExportHelper do
+RSpec.describe ExportHelper do
describe '#project_export_descriptions' do
it 'includes design management' do
expect(project_export_descriptions).to include('Design Management files and data')
diff --git a/spec/helpers/external_link_helper_spec.rb b/spec/helpers/external_link_helper_spec.rb
index 7fc4ef18731..b1a1884d887 100644
--- a/spec/helpers/external_link_helper_spec.rb
+++ b/spec/helpers/external_link_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe ExternalLinkHelper do
+RSpec.describe ExternalLinkHelper do
include IconsHelper
it 'returns external link with icon' do
diff --git a/spec/helpers/form_helper_spec.rb b/spec/helpers/form_helper_spec.rb
index 6698d8970e7..79c96e65a0e 100644
--- a/spec/helpers/form_helper_spec.rb
+++ b/spec/helpers/form_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe FormHelper do
+RSpec.describe FormHelper do
describe 'form_errors' do
it 'returns nil when model has no errors' do
model = double(errors: [])
diff --git a/spec/helpers/git_helper_spec.rb b/spec/helpers/git_helper_spec.rb
index 6dfd8d2cc76..0dd9eecb7f0 100644
--- a/spec/helpers/git_helper_spec.rb
+++ b/spec/helpers/git_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe GitHelper do
+RSpec.describe GitHelper do
describe '#short_sha' do
let(:short_sha) { helper.short_sha('d4e043f6c20749a3ab3f4b8e23f2a8979f4b9100') }
diff --git a/spec/helpers/gitlab_routing_helper_spec.rb b/spec/helpers/gitlab_routing_helper_spec.rb
index 4def04f4284..bd48fc7cee2 100644
--- a/spec/helpers/gitlab_routing_helper_spec.rb
+++ b/spec/helpers/gitlab_routing_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe GitlabRoutingHelper do
+RSpec.describe GitlabRoutingHelper do
let(:project) { build_stubbed(:project) }
let(:group) { build_stubbed(:group) }
@@ -147,8 +147,8 @@ describe GitlabRoutingHelper do
end
context 'snippets' do
- let_it_be(:personal_snippet) { create(:personal_snippet) }
- let_it_be(:project_snippet) { create(:project_snippet) }
+ let_it_be(:personal_snippet) { create(:personal_snippet, :repository) }
+ let_it_be(:project_snippet) { create(:project_snippet, :repository) }
let_it_be(:note) { create(:note_on_personal_snippet, noteable: personal_snippet) }
describe '#gitlab_snippet_path' do
@@ -181,6 +181,23 @@ describe GitlabRoutingHelper do
end
end
+ describe '#gitlab_raw_snippet_blob_path' do
+ let(:ref) { 'test-ref' }
+
+ it_behaves_like 'snippet blob raw path' do
+ subject { gitlab_raw_snippet_blob_path(blob, ref) }
+ end
+
+ context 'without a ref' do
+ let(:blob) { personal_snippet.blobs.first }
+ let(:ref) { blob.repository.root_ref }
+
+ it 'uses the root ref' do
+ expect(gitlab_raw_snippet_blob_path(blob)).to eq("/-/snippets/#{personal_snippet.id}/raw/#{ref}/#{blob.path}")
+ end
+ end
+ end
+
describe '#gitlab_raw_snippet_url' do
it 'returns the raw personal snippet url' do
expect(gitlab_raw_snippet_url(personal_snippet)).to eq("http://test.host/snippets/#{personal_snippet.id}/raw")
@@ -191,6 +208,32 @@ describe GitlabRoutingHelper do
end
end
+ describe '#gitlab_raw_snippet_blob_url' do
+ let(:blob) { snippet.blobs.first }
+ let(:ref) { 'snippet-test-ref' }
+
+ context 'for a PersonalSnippet' do
+ let(:snippet) { personal_snippet }
+
+ it { expect(gitlab_raw_snippet_blob_url(snippet, blob.path, ref)).to eq("http://test.host/-/snippets/#{snippet.id}/raw/#{ref}/#{blob.path}") }
+ end
+
+ context 'for a ProjectSnippet' do
+ let(:snippet) { project_snippet }
+
+ it { expect(gitlab_raw_snippet_blob_url(snippet, blob.path, ref)).to eq("http://test.host/#{snippet.project.full_path}/-/snippets/#{snippet.id}/raw/#{ref}/#{blob.path}") }
+ end
+
+ context 'without a ref' do
+ let(:snippet) { personal_snippet }
+ let(:ref) { snippet.repository.root_ref }
+
+ it 'uses the root ref' do
+ expect(gitlab_raw_snippet_blob_url(snippet, blob.path)).to eq("http://test.host/-/snippets/#{snippet.id}/raw/#{ref}/#{blob.path}")
+ end
+ end
+ end
+
describe '#gitlab_snippet_notes_path' do
it 'returns the notes path for the personal snippet' do
expect(gitlab_snippet_notes_path(personal_snippet)).to eq("/snippets/#{personal_snippet.id}/notes")
diff --git a/spec/helpers/graph_helper_spec.rb b/spec/helpers/graph_helper_spec.rb
index dc389c09e60..3c7e4f970c3 100644
--- a/spec/helpers/graph_helper_spec.rb
+++ b/spec/helpers/graph_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe GraphHelper do
+RSpec.describe GraphHelper do
describe '#get_refs' do
let(:project) { create(:project, :repository) }
let(:commit) { project.commit("master") }
diff --git a/spec/helpers/groups/group_members_helper_spec.rb b/spec/helpers/groups/group_members_helper_spec.rb
index 898c330c498..90792331d9b 100644
--- a/spec/helpers/groups/group_members_helper_spec.rb
+++ b/spec/helpers/groups/group_members_helper_spec.rb
@@ -2,7 +2,7 @@
require "spec_helper"
-describe Groups::GroupMembersHelper do
+RSpec.describe Groups::GroupMembersHelper do
describe '.group_member_select_options' do
let(:group) { create(:group) }
diff --git a/spec/helpers/groups_helper_spec.rb b/spec/helpers/groups_helper_spec.rb
index 5be247c5b49..a739c16f3b1 100644
--- a/spec/helpers/groups_helper_spec.rb
+++ b/spec/helpers/groups_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe GroupsHelper do
+RSpec.describe GroupsHelper do
include ApplicationHelper
describe 'group_icon_url' do
diff --git a/spec/helpers/hooks_helper_spec.rb b/spec/helpers/hooks_helper_spec.rb
index 4352089c1c0..92e082c4974 100644
--- a/spec/helpers/hooks_helper_spec.rb
+++ b/spec/helpers/hooks_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe HooksHelper do
+RSpec.describe HooksHelper do
let(:project) { create(:project) }
let(:project_hook) { create(:project_hook, project: project) }
let(:system_hook) { create(:system_hook) }
diff --git a/spec/helpers/icons_helper_spec.rb b/spec/helpers/icons_helper_spec.rb
index 5c26db028b7..c47bba42ae2 100644
--- a/spec/helpers/icons_helper_spec.rb
+++ b/spec/helpers/icons_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe IconsHelper do
+RSpec.describe IconsHelper do
let(:icons_path) { ActionController::Base.helpers.image_path("icons.svg") }
describe 'icon' do
@@ -22,8 +22,13 @@ describe IconsHelper do
describe 'sprite_icon_path' do
it 'returns relative path' do
- expect(sprite_icon_path)
- .to eq icons_path
+ expect(sprite_icon_path).to eq(icons_path)
+ end
+
+ it 'only calls image_path once when called multiple times' do
+ expect(ActionController::Base.helpers).to receive(:image_path).once.and_call_original
+
+ 2.times { sprite_icon_path }
end
context 'when an asset_host is set in the config it will return an absolute local URL' do
@@ -235,4 +240,25 @@ describe IconsHelper do
.to eq("<span class=\"gl-snippet-icon gl-snippet-icon-download\"></span>")
end
end
+
+ describe 'loading_icon' do
+ it 'returns span with gl-spinner class and default configuration' do
+ expect(loading_icon.to_s)
+ .to eq '<span class="gl-spinner gl-spinner-orange gl-spinner-sm" aria-label="Loading"></span>'
+ end
+
+ context 'when css_class is provided' do
+ it 'appends css_class to gl-spinner element' do
+ expect(loading_icon(css_class: 'gl-mr-2').to_s)
+ .to eq '<span class="gl-spinner gl-spinner-orange gl-spinner-sm gl-mr-2" aria-label="Loading"></span>'
+ end
+ end
+
+ context 'when container is true' do
+ it 'creates a container that has the gl-spinner-container class selector' do
+ expect(loading_icon(container: true).to_s)
+ .to eq '<div class="gl-spinner-container"><span class="gl-spinner gl-spinner-orange gl-spinner-sm" aria-label="Loading"></span></div>'
+ end
+ end
+ end
end
diff --git a/spec/helpers/import_helper_spec.rb b/spec/helpers/import_helper_spec.rb
index a6b283e49dc..18cbbdfd804 100644
--- a/spec/helpers/import_helper_spec.rb
+++ b/spec/helpers/import_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe ImportHelper do
+RSpec.describe ImportHelper do
describe '#sanitize_project_name' do
it 'removes leading tildes' do
expect(helper.sanitize_project_name('~~root')).to eq('root')
diff --git a/spec/helpers/instance_configuration_helper_spec.rb b/spec/helpers/instance_configuration_helper_spec.rb
index 31a6c7bc839..1ba06b97088 100644
--- a/spec/helpers/instance_configuration_helper_spec.rb
+++ b/spec/helpers/instance_configuration_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe InstanceConfigurationHelper do
+RSpec.describe InstanceConfigurationHelper do
describe '#instance_configuration_cell_html' do
describe 'if not block is passed' do
it 'returns the parameter if present' do
diff --git a/spec/helpers/issuables_helper_spec.rb b/spec/helpers/issuables_helper_spec.rb
index 38ad11846d2..4c93a8387a9 100644
--- a/spec/helpers/issuables_helper_spec.rb
+++ b/spec/helpers/issuables_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe IssuablesHelper do
+RSpec.describe IssuablesHelper do
let(:label) { build_stubbed(:label) }
let(:label2) { build_stubbed(:label) }
@@ -303,4 +303,28 @@ describe IssuablesHelper do
end
end
end
+
+ describe '#issuable_squash_option?' do
+ using RSpec::Parameterized::TableSyntax
+
+ where(:issuable_persisted, :squash, :squash_enabled_by_default, :expectation) do
+ true | true | true | true
+ true | false | true | false
+ false | false | false | false
+ false | false | true | true
+ false | true | false | false
+ false | true | true | true
+ end
+
+ with_them do
+ it 'returns the correct value' do
+ project = double(
+ squash_enabled_by_default?: squash_enabled_by_default
+ )
+ issuable = double(persisted?: issuable_persisted, squash: squash)
+
+ expect(helper.issuable_squash_option?(issuable, project)).to eq(expectation)
+ end
+ end
+ end
end
diff --git a/spec/helpers/issues_helper_spec.rb b/spec/helpers/issues_helper_spec.rb
index 3ef6745958c..f2757f0e3ed 100644
--- a/spec/helpers/issues_helper_spec.rb
+++ b/spec/helpers/issues_helper_spec.rb
@@ -2,7 +2,7 @@
require "spec_helper"
-describe IssuesHelper do
+RSpec.describe IssuesHelper do
let(:project) { create(:project) }
let(:issue) { create :issue, project: project }
let(:ext_project) { create :redmine_project }
@@ -209,4 +209,28 @@ describe IssuesHelper do
it_behaves_like 'does not display link'
end
end
+
+ describe '#show_moved_service_desk_issue_warning?' do
+ let(:project1) { create(:project, service_desk_enabled: true) }
+ let(:project2) { create(:project, service_desk_enabled: true) }
+ let!(:old_issue) { create(:issue, author: User.support_bot, project: project1) }
+ let!(:new_issue) { create(:issue, author: User.support_bot, project: project2) }
+
+ before do
+ allow(Gitlab::IncomingEmail).to receive(:enabled?) { true }
+ allow(Gitlab::IncomingEmail).to receive(:supports_wildcard?) { true }
+
+ old_issue.update(moved_to: new_issue)
+ end
+
+ it 'is true when moved issue project has service desk disabled' do
+ project2.update!(service_desk_enabled: false)
+
+ expect(helper.show_moved_service_desk_issue_warning?(new_issue)).to be(true)
+ end
+
+ it 'is false when moved issue project has service desk enabled' do
+ expect(helper.show_moved_service_desk_issue_warning?(new_issue)).to be(false)
+ end
+ end
end
diff --git a/spec/helpers/labels_helper_spec.rb b/spec/helpers/labels_helper_spec.rb
index ec70041d51f..77e1d10354c 100644
--- a/spec/helpers/labels_helper_spec.rb
+++ b/spec/helpers/labels_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe LabelsHelper do
+RSpec.describe LabelsHelper do
describe '#show_label_issuables_link?' do
shared_examples 'a valid response to show_label_issuables_link?' do |issuables_type, when_enabled = true, when_disabled = false|
context "when asking for a #{issuables_type} link" do
diff --git a/spec/helpers/markup_helper_spec.rb b/spec/helpers/markup_helper_spec.rb
index 1fc79a9762a..302ab0cc137 100644
--- a/spec/helpers/markup_helper_spec.rb
+++ b/spec/helpers/markup_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe MarkupHelper do
+RSpec.describe MarkupHelper do
let_it_be(:project) { create(:project, :repository) }
let_it_be(:user) do
user = create(:user, username: 'gfm')
diff --git a/spec/helpers/members_helper_spec.rb b/spec/helpers/members_helper_spec.rb
index 946ffcddae7..99e8696e960 100644
--- a/spec/helpers/members_helper_spec.rb
+++ b/spec/helpers/members_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe MembersHelper do
+RSpec.describe MembersHelper do
describe '#remove_member_message' do
let(:requester) { create(:user) }
let(:project) { create(:project, :public) }
diff --git a/spec/helpers/merge_requests_helper_spec.rb b/spec/helpers/merge_requests_helper_spec.rb
index 8db8c37038e..fcb9efa39d5 100644
--- a/spec/helpers/merge_requests_helper_spec.rb
+++ b/spec/helpers/merge_requests_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe MergeRequestsHelper do
+RSpec.describe MergeRequestsHelper do
include ActionView::Helpers::UrlHelper
include ProjectForksHelper
diff --git a/spec/helpers/namespaces_helper_spec.rb b/spec/helpers/namespaces_helper_spec.rb
index ebce296d7c2..1313a5c9352 100644
--- a/spec/helpers/namespaces_helper_spec.rb
+++ b/spec/helpers/namespaces_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe NamespacesHelper do
+RSpec.describe NamespacesHelper do
let!(:admin) { create(:admin) }
let!(:admin_project_creation_level) { nil }
let!(:admin_group) do
@@ -174,96 +174,4 @@ describe NamespacesHelper do
end
end
end
-
- describe '#namespace_storage_alert' do
- subject { helper.namespace_storage_alert(namespace) }
-
- let(:namespace) { build(:namespace) }
-
- let(:payload) do
- {
- alert_level: :info,
- usage_message: "Usage",
- explanation_message: "Explanation",
- root_namespace: namespace
- }
- end
-
- before do
- allow(helper).to receive(:current_user).and_return(admin)
- allow_next_instance_of(Namespaces::CheckStorageSizeService, namespace, admin) do |check_storage_size_service|
- expect(check_storage_size_service).to receive(:execute).and_return(ServiceResponse.success(payload: payload))
- end
- end
-
- context 'when payload is not empty and no cookie is set' do
- it { is_expected.to eq(payload) }
- end
-
- context 'when there is no current_user' do
- before do
- allow(helper).to receive(:current_user).and_return(nil)
- end
-
- it { is_expected.to eq({}) }
- end
-
- context 'when payload is empty' do
- let(:payload) { {} }
-
- it { is_expected.to eq({}) }
- end
-
- context 'when cookie is set' do
- before do
- helper.request.cookies["hide_storage_limit_alert_#{namespace.id}_info"] = 'true'
- end
-
- it { is_expected.to eq({}) }
- end
-
- context 'when payload is empty and cookie is set' do
- let(:payload) { {} }
-
- before do
- helper.request.cookies["hide_storage_limit_alert_#{namespace.id}_info"] = 'true'
- end
-
- it { is_expected.to eq({}) }
- end
- end
-
- describe '#namespace_storage_alert_style' do
- using RSpec::Parameterized::TableSyntax
-
- subject { helper.namespace_storage_alert_style(alert_level) }
-
- where(:alert_level, :result) do
- :info | 'info'
- :warning | 'warning'
- :error | 'danger'
- :alert | 'danger'
- end
-
- with_them do
- it { is_expected.to eq(result) }
- end
- end
-
- describe '#namespace_storage_alert_icon' do
- using RSpec::Parameterized::TableSyntax
-
- subject { helper.namespace_storage_alert_icon(alert_level) }
-
- where(:alert_level, :result) do
- :info | 'information-o'
- :warning | 'warning'
- :error | 'error'
- :alert | 'error'
- end
-
- with_them do
- it { is_expected.to eq(result) }
- end
- end
end
diff --git a/spec/helpers/nav_helper_spec.rb b/spec/helpers/nav_helper_spec.rb
index ac1c6c62433..b1c9485e5a1 100644
--- a/spec/helpers/nav_helper_spec.rb
+++ b/spec/helpers/nav_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe NavHelper, :do_not_mock_admin_mode do
+RSpec.describe NavHelper, :do_not_mock_admin_mode do
describe '#header_links' do
include_context 'custom session'
diff --git a/spec/helpers/notes_helper_spec.rb b/spec/helpers/notes_helper_spec.rb
index 543a9081779..f29f947ba46 100644
--- a/spec/helpers/notes_helper_spec.rb
+++ b/spec/helpers/notes_helper_spec.rb
@@ -2,7 +2,7 @@
require "spec_helper"
-describe NotesHelper do
+RSpec.describe NotesHelper do
include RepoHelpers
let(:owner) { create(:owner) }
diff --git a/spec/helpers/notifications_helper_spec.rb b/spec/helpers/notifications_helper_spec.rb
index d8dcce203fe..319c85c19f9 100644
--- a/spec/helpers/notifications_helper_spec.rb
+++ b/spec/helpers/notifications_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe NotificationsHelper do
+RSpec.describe NotificationsHelper do
describe 'notification_icon' do
it { expect(notification_icon(:disabled)).to match('class="fa fa-microphone-slash fa-fw"') }
it { expect(notification_icon(:owner_disabled)).to match('class="fa fa-microphone-slash fa-fw"') }
diff --git a/spec/helpers/notify_helper_spec.rb b/spec/helpers/notify_helper_spec.rb
new file mode 100644
index 00000000000..9c9d745cb53
--- /dev/null
+++ b/spec/helpers/notify_helper_spec.rb
@@ -0,0 +1,33 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe NotifyHelper do
+ include ActionView::Helpers::UrlHelper
+
+ describe 'merge_request_reference_link' do
+ let(:project) { create(:project) }
+ let(:merge_request) { create(:merge_request, source_project: project) }
+
+ it 'returns link to merge request with the text reference' do
+ url = "http://test.host/#{project.full_path}/-/merge_requests/#{merge_request.iid}"
+
+ expect(merge_request_reference_link(merge_request)).to eq(reference_link(merge_request, url))
+ end
+ end
+
+ describe 'issue_reference_link' do
+ let(:project) { create(:project) }
+ let(:issue) { create(:issue, project: project) }
+
+ it 'returns link to issue with the text reference' do
+ url = "http://test.host/#{project.full_path}/-/issues/#{issue.iid}"
+
+ expect(issue_reference_link(issue)).to eq(reference_link(issue, url))
+ end
+ end
+
+ def reference_link(entity, url)
+ "<a href=\"#{url}\">#{entity.to_reference}</a>"
+ end
+end
diff --git a/spec/helpers/onboarding_experiment_helper_spec.rb b/spec/helpers/onboarding_experiment_helper_spec.rb
deleted file mode 100644
index cada91bff3c..00000000000
--- a/spec/helpers/onboarding_experiment_helper_spec.rb
+++ /dev/null
@@ -1,38 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-
-describe OnboardingExperimentHelper, type: :helper do
- describe '.allow_access_to_onboarding?' do
- context "when we're not gitlab.com or dev env" do
- it 'returns false' do
- allow(::Gitlab).to receive(:dev_env_or_com?).and_return(false)
-
- expect(helper.allow_access_to_onboarding?).to be(false)
- end
- end
-
- context "when we're gitlab.com or dev env" do
- before do
- allow(::Gitlab).to receive(:dev_env_or_com?).and_return(true)
- end
-
- context 'and the :user_onboarding feature is not enabled' do
- it 'returns false' do
- stub_feature_flags(user_onboarding: false)
-
- expect(helper.allow_access_to_onboarding?).to be(false)
- end
- end
-
- context 'and the :user_onboarding feature is enabled' do
- it 'returns true' do
- stub_feature_flags(user_onboarding: true)
- allow(helper).to receive(:current_user).and_return(create(:user))
-
- expect(helper.allow_access_to_onboarding?).to be(true)
- end
- end
- end
- end
-end
diff --git a/spec/helpers/operations_helper_spec.rb b/spec/helpers/operations_helper_spec.rb
new file mode 100644
index 00000000000..73deb2249bc
--- /dev/null
+++ b/spec/helpers/operations_helper_spec.rb
@@ -0,0 +1,160 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe OperationsHelper do
+ include Gitlab::Routing
+
+ let_it_be(:user) { create(:user) }
+ let_it_be(:project, reload: true) { create(:project) }
+
+ before do
+ helper.instance_variable_set(:@project, project)
+ allow(helper).to receive(:current_user) { user }
+ end
+
+ describe '#alerts_settings_data' do
+ subject { helper.alerts_settings_data }
+
+ before do
+ allow(helper).to receive(:can?).with(user, :admin_operations, project) { true }
+ end
+
+ context 'initial service configuration' do
+ let_it_be(:alerts_service) { AlertsService.new(project: project) }
+ let_it_be(:prometheus_service) { PrometheusService.new(project: project) }
+
+ before do
+ allow(project).to receive(:find_or_initialize_service).with('alerts').and_return(alerts_service)
+ allow(project).to receive(:find_or_initialize_service).with('prometheus').and_return(prometheus_service)
+ end
+
+ it 'returns the correct values' do
+ expect(subject).to eq(
+ 'activated' => 'false',
+ 'url' => alerts_service.url,
+ 'authorization_key' => nil,
+ 'form_path' => project_service_path(project, alerts_service),
+ 'alerts_setup_url' => help_page_path('user/project/integrations/generic_alerts.md', anchor: 'setting-up-generic-alerts'),
+ 'alerts_usage_url' => project_alert_management_index_path(project),
+ 'prometheus_form_path' => project_service_path(project, prometheus_service),
+ 'prometheus_reset_key_path' => reset_alerting_token_project_settings_operations_path(project),
+ 'prometheus_authorization_key' => nil,
+ 'prometheus_api_url' => nil,
+ 'prometheus_activated' => 'false',
+ 'prometheus_url' => notify_project_prometheus_alerts_url(project, format: :json),
+ 'disabled' => 'false'
+ )
+ end
+ end
+
+ context 'with external Prometheus configured' do
+ let_it_be(:prometheus_service, reload: true) do
+ create(:prometheus_service, project: project)
+ end
+
+ context 'with external Prometheus enabled' do
+ it 'returns the correct values' do
+ expect(subject).to include(
+ 'prometheus_activated' => 'true',
+ 'prometheus_api_url' => prometheus_service.api_url
+ )
+ end
+ end
+
+ context 'with external Prometheus disabled' do
+ shared_examples 'Prometheus is disabled' do
+ it 'returns the correct values' do
+ expect(subject).to include(
+ 'prometheus_activated' => 'false',
+ 'prometheus_api_url' => prometheus_service.api_url
+ )
+ end
+ end
+
+ let(:cluster_managed) { false }
+
+ before do
+ allow(prometheus_service)
+ .to receive(:prometheus_available?)
+ .and_return(cluster_managed)
+
+ prometheus_service.update!(manual_configuration: false)
+ end
+
+ include_examples 'Prometheus is disabled'
+
+ context 'when cluster managed' do
+ let(:cluster_managed) { true }
+
+ include_examples 'Prometheus is disabled'
+ end
+ end
+
+ context 'with project alert setting' do
+ let_it_be(:project_alerting_setting) { create(:project_alerting_setting, project: project) }
+
+ it 'returns the correct values' do
+ expect(subject).to include(
+ 'prometheus_authorization_key' => project_alerting_setting.token,
+ 'prometheus_api_url' => prometheus_service.api_url
+ )
+ end
+ end
+ end
+
+ context 'with generic alerts service configured' do
+ let_it_be(:alerts_service) { create(:alerts_service, project: project) }
+
+ context 'with generic alerts enabled' do
+ it 'returns the correct values' do
+ expect(subject).to include(
+ 'activated' => 'true',
+ 'authorization_key' => alerts_service.token,
+ 'url' => alerts_service.url
+ )
+ end
+ end
+
+ context 'with generic alerts disabled' do
+ before do
+ alerts_service.update!(active: false)
+ end
+
+ it 'returns the correct values' do
+ expect(subject).to include(
+ 'activated' => 'false',
+ 'authorization_key' => alerts_service.token
+ )
+ end
+ end
+ end
+ end
+
+ describe '#operations_settings_data' do
+ let_it_be(:operations_settings) do
+ create(
+ :project_incident_management_setting,
+ project: project,
+ issue_template_key: 'template-key',
+ pagerduty_active: true
+ )
+ end
+
+ subject { helper.operations_settings_data }
+
+ it 'returns the correct set of data' do
+ is_expected.to eq(
+ operations_settings_endpoint: project_settings_operations_path(project),
+ templates: '[]',
+ create_issue: 'false',
+ issue_template_key: 'template-key',
+ send_email: 'false',
+ pagerduty_active: 'true',
+ pagerduty_token: operations_settings.pagerduty_token,
+ pagerduty_webhook_url: project_incidents_pagerduty_url(project, token: operations_settings.pagerduty_token),
+ pagerduty_reset_key_path: reset_pagerduty_token_project_settings_operations_path(project)
+ )
+ end
+ end
+end
diff --git a/spec/helpers/page_layout_helper_spec.rb b/spec/helpers/page_layout_helper_spec.rb
index 55f743ac683..e8a5c4613fe 100644
--- a/spec/helpers/page_layout_helper_spec.rb
+++ b/spec/helpers/page_layout_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe PageLayoutHelper do
+RSpec.describe PageLayoutHelper do
describe 'page_description' do
it 'defaults to nil' do
expect(helper.page_description).to eq nil
diff --git a/spec/helpers/pagination_helper_spec.rb b/spec/helpers/pagination_helper_spec.rb
index 9fb51249edc..4cd6b6f3922 100644
--- a/spec/helpers/pagination_helper_spec.rb
+++ b/spec/helpers/pagination_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe PaginationHelper do
+RSpec.describe PaginationHelper do
describe '#paginate_collection' do
let(:collection) { User.all.page(1) }
diff --git a/spec/helpers/preferences_helper_spec.rb b/spec/helpers/preferences_helper_spec.rb
index 7969cfd97b5..be0ad5e1a3f 100644
--- a/spec/helpers/preferences_helper_spec.rb
+++ b/spec/helpers/preferences_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe PreferencesHelper do
+RSpec.describe PreferencesHelper do
describe '#dashboard_choices' do
let(:user) { build(:user) }
@@ -120,13 +120,6 @@ describe PreferencesHelper do
end
end
- describe '#language_choices' do
- it 'returns an array of all available languages' do
- expect(helper.language_choices).to be_an(Array)
- expect(helper.language_choices.map(&:first)).to eq(Gitlab::I18n::AVAILABLE_LANGUAGES.values.sort)
- end
- end
-
def stub_user(messages = {})
if messages.empty?
allow(helper).to receive(:current_user).and_return(nil)
diff --git a/spec/helpers/profiles_helper_spec.rb b/spec/helpers/profiles_helper_spec.rb
index fc282eee26d..4a8ba2b7113 100644
--- a/spec/helpers/profiles_helper_spec.rb
+++ b/spec/helpers/profiles_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe ProfilesHelper do
+RSpec.describe ProfilesHelper do
describe '#commit_email_select_options' do
it 'returns an array with private commit email along with all the verified emails' do
user = create(:user)
diff --git a/spec/helpers/projects/alert_management_helper_spec.rb b/spec/helpers/projects/alert_management_helper_spec.rb
index 49b64b316e7..859c08b194a 100644
--- a/spec/helpers/projects/alert_management_helper_spec.rb
+++ b/spec/helpers/projects/alert_management_helper_spec.rb
@@ -2,23 +2,24 @@
require 'spec_helper'
-describe Projects::AlertManagementHelper do
+RSpec.describe Projects::AlertManagementHelper do
include Gitlab::Routing.url_helpers
let_it_be(:project, reload: true) { create(:project) }
let_it_be(:current_user) { create(:user) }
- let_it_be(:project_path) { project.full_path }
+ let(:project_path) { project.full_path }
+ let(:project_id) { project.id }
describe '#alert_management_data' do
let(:user_can_enable_alert_management) { true }
- let(:setting_path) { edit_project_service_path(project, AlertsService) }
+ let(:setting_path) { project_settings_operations_path(project, anchor: 'js-alert-management-settings') }
subject(:data) { helper.alert_management_data(current_user, project) }
before do
allow(helper)
.to receive(:can?)
- .with(current_user, :admin_project, project)
+ .with(current_user, :admin_operations, project)
.and_return(user_can_enable_alert_management)
end
@@ -27,6 +28,7 @@ describe Projects::AlertManagementHelper do
expect(helper.alert_management_data(current_user, project)).to match(
'project-path' => project_path,
'enable-alert-management-path' => setting_path,
+ 'populating-alerts-help-url' => 'http://test.host/help/user/project/operations/alert_management.html#enable-alert-management',
'empty-alert-svg-path' => match_asset_path('/assets/illustrations/alert-management-empty-state.svg'),
'user-can-enable-alert-management' => 'true',
'alert-management-enabled' => 'false'
@@ -56,6 +58,28 @@ describe Projects::AlertManagementHelper do
end
end
+ context 'with prometheus service' do
+ let_it_be(:prometheus_service) { create(:prometheus_service, project: project) }
+
+ context 'when prometheus service is active' do
+ it 'enables alert management' do
+ expect(data).to include(
+ 'alert-management-enabled' => 'true'
+ )
+ end
+ end
+
+ context 'when prometheus service is inactive' do
+ it 'disables alert management' do
+ prometheus_service.update!(manual_configuration: false)
+
+ expect(data).to include(
+ 'alert-management-enabled' => 'false'
+ )
+ end
+ end
+ end
+
context 'when user does not have requisite enablement permissions' do
let(:user_can_enable_alert_management) { false }
@@ -75,6 +99,7 @@ describe Projects::AlertManagementHelper do
expect(helper.alert_management_detail_data(project, alert_id)).to eq(
'alert-id' => alert_id,
'project-path' => project_path,
+ 'project-id' => project_id,
'project-issues-path' => issues_path
)
end
diff --git a/spec/helpers/projects/error_tracking_helper_spec.rb b/spec/helpers/projects/error_tracking_helper_spec.rb
index 008d749a002..882031a9c86 100644
--- a/spec/helpers/projects/error_tracking_helper_spec.rb
+++ b/spec/helpers/projects/error_tracking_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::ErrorTrackingHelper do
+RSpec.describe Projects::ErrorTrackingHelper do
include Gitlab::Routing.url_helpers
let_it_be(:project, reload: true) { create(:project) }
diff --git a/spec/helpers/projects_helper_spec.rb b/spec/helpers/projects_helper_spec.rb
index 4e072f02ae0..a3d0673f1b3 100644
--- a/spec/helpers/projects_helper_spec.rb
+++ b/spec/helpers/projects_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe ProjectsHelper do
+RSpec.describe ProjectsHelper do
include ProjectForksHelper
let_it_be(:project) { create(:project) }
@@ -444,8 +444,8 @@ describe ProjectsHelper do
end
describe '#get_project_nav_tabs' do
+ let_it_be(:user) { create(:user) }
let(:project) { create(:project) }
- let(:user) { create(:user) }
before do
allow(helper).to receive(:can?) { true }
@@ -501,6 +501,20 @@ describe ProjectsHelper do
is_expected.not_to include(:external_wiki)
end
end
+
+ context 'when project has confluence enabled' do
+ before do
+ allow(project).to receive(:has_confluence?).and_return(true)
+ end
+
+ it { is_expected.to include(:confluence) }
+ it { is_expected.not_to include(:wiki) }
+ end
+
+ context 'when project does not have confluence enabled' do
+ it { is_expected.not_to include(:confluence) }
+ it { is_expected.to include(:wiki) }
+ end
end
describe '#can_view_operations_tab?' do
@@ -977,19 +991,32 @@ describe ProjectsHelper do
end
end
- describe '#project_license_name(project)' do
+ describe '#project_license_name(project)', :request_store do
let_it_be(:project) { create(:project) }
let_it_be(:repository) { project.repository }
subject { project_license_name(project) }
+ def license_name
+ project_license_name(project)
+ end
+
context 'gitaly is working appropriately' do
- it 'returns the license name' do
- license = Licensee::License.new('mit')
- allow(repository).to receive(:license).and_return(license)
+ let(:license) { Licensee::License.new('mit') }
+ before do
+ expect(repository).to receive(:license).and_return(license)
+ end
+
+ it 'returns the license name' do
expect(subject).to eq(license.name)
end
+
+ it 'memoizes the value' do
+ expect do
+ 2.times { expect(license_name).to eq(license.name) }
+ end.to change { Gitlab::GitalyClient.get_request_count }.by_at_most(1)
+ end
end
context 'gitaly is unreachable' do
@@ -1003,10 +1030,16 @@ describe ProjectsHelper do
subject
end
+
+ it 'memoizes the nil value' do
+ expect do
+ 2.times { expect(license_name).to be_nil }
+ end.to change { Gitlab::GitalyClient.get_request_count }.by_at_most(1)
+ end
end
before do
- allow(repository).to receive(:license).and_raise(exception)
+ expect(repository).to receive(:license).and_raise(exception)
end
context "Gitlab::Git::CommandError" do
diff --git a/spec/helpers/recaptcha_experiment_helper_spec.rb b/spec/helpers/recaptcha_experiment_helper_spec.rb
index a5b233e28a0..e677164c950 100644
--- a/spec/helpers/recaptcha_experiment_helper_spec.rb
+++ b/spec/helpers/recaptcha_experiment_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe RecaptchaExperimentHelper, type: :helper do
+RSpec.describe RecaptchaExperimentHelper, type: :helper do
let(:session) { {} }
before do
diff --git a/spec/helpers/releases_helper_spec.rb b/spec/helpers/releases_helper_spec.rb
index de4086e48db..82fc799f9b0 100644
--- a/spec/helpers/releases_helper_spec.rb
+++ b/spec/helpers/releases_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe ReleasesHelper do
+RSpec.describe ReleasesHelper do
describe '#illustration' do
it 'returns the correct image path' do
expect(helper.illustration).to match(/illustrations\/releases-(\w+)\.svg/)
@@ -22,6 +22,7 @@ describe ReleasesHelper do
let(:can_user_create_release) { false }
let(:common_keys) { [:project_id, :illustration_path, :documentation_path] }
+ # rubocop: disable CodeReuse/ActiveRecord
before do
helper.instance_variable_set(:@project, project)
helper.instance_variable_set(:@release, release)
@@ -30,6 +31,7 @@ describe ReleasesHelper do
.with(user, :create_release, project)
.and_return(can_user_create_release)
end
+ # rubocop: enable CodeReuse/ActiveRecord
describe '#data_for_releases_page' do
it 'includes the required data for displaying release blocks' do
@@ -41,7 +43,20 @@ describe ReleasesHelper do
it 'includes new_release_path' do
expect(helper.data_for_releases_page.keys).to contain_exactly(*common_keys, :new_release_path)
- expect(helper.data_for_releases_page[:new_release_path]).to eq(new_project_tag_path(project))
+ end
+
+ it 'points new_release_path to the "New Release" page' do
+ expect(helper.data_for_releases_page[:new_release_path]).to eq(new_project_release_path(project))
+ end
+
+ context 'when the "new_release_page" feature flag is disabled' do
+ before do
+ stub_feature_flags(new_release_page: false)
+ end
+
+ it 'points new_release_path to the "New Tag" page' do
+ expect(helper.data_for_releases_page[:new_release_path]).to eq(new_project_tag_path(project))
+ end
end
end
end
@@ -57,7 +72,23 @@ describe ReleasesHelper do
release_assets_docs_path
manage_milestones_path
new_milestone_path)
- expect(helper.data_for_edit_release_page.keys).to eq(keys)
+
+ expect(helper.data_for_edit_release_page.keys).to match_array(keys)
+ end
+ end
+
+ describe '#data_for_new_release_page' do
+ it 'has the needed data to display the "new release" page' do
+ keys = %i(project_id
+ markdown_preview_path
+ markdown_docs_path
+ update_release_api_docs_path
+ release_assets_docs_path
+ manage_milestones_path
+ new_milestone_path
+ default_branch)
+
+ expect(helper.data_for_new_release_page.keys).to match_array(keys)
end
end
end
diff --git a/spec/helpers/rss_helper_spec.rb b/spec/helpers/rss_helper_spec.rb
index 657f5fb42bc..c7eb33dc6f7 100644
--- a/spec/helpers/rss_helper_spec.rb
+++ b/spec/helpers/rss_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe RssHelper do
+RSpec.describe RssHelper do
describe '#rss_url_options' do
context 'when signed in' do
it "includes the current_user's feed_token" do
diff --git a/spec/helpers/search_helper_spec.rb b/spec/helpers/search_helper_spec.rb
index b209ed869bf..699232e67b1 100644
--- a/spec/helpers/search_helper_spec.rb
+++ b/spec/helpers/search_helper_spec.rb
@@ -2,12 +2,105 @@
require 'spec_helper'
-describe SearchHelper do
+RSpec.describe SearchHelper do
# Override simple_sanitize for our testing purposes
def simple_sanitize(str)
str
end
+ describe 'search_autocomplete_opts' do
+ context "with no current user" do
+ before do
+ allow(self).to receive(:current_user).and_return(nil)
+ end
+
+ it "returns nil" do
+ expect(search_autocomplete_opts("q")).to be_nil
+ end
+ end
+
+ context "with a standard user" do
+ let(:user) { create(:user) }
+
+ before do
+ allow(self).to receive(:current_user).and_return(user)
+ end
+
+ it "includes Help sections" do
+ expect(search_autocomplete_opts("hel").size).to eq(9)
+ end
+
+ it "includes default sections" do
+ expect(search_autocomplete_opts("dash").size).to eq(1)
+ end
+
+ it "does not include admin sections" do
+ expect(search_autocomplete_opts("admin").size).to eq(0)
+ end
+
+ it "does not allow regular expression in search term" do
+ expect(search_autocomplete_opts("(webhooks|api)").size).to eq(0)
+ end
+
+ it "includes the user's groups" do
+ create(:group).add_owner(user)
+ expect(search_autocomplete_opts("gro").size).to eq(1)
+ end
+
+ it "includes nested group" do
+ create(:group, :nested, name: 'foo').add_owner(user)
+ expect(search_autocomplete_opts('foo').size).to eq(1)
+ end
+
+ it "includes the user's projects" do
+ project = create(:project, namespace: create(:namespace, owner: user))
+ expect(search_autocomplete_opts(project.name).size).to eq(1)
+ end
+
+ it "includes the required project attrs" do
+ project = create(:project, namespace: create(:namespace, owner: user))
+ result = search_autocomplete_opts(project.name).first
+
+ expect(result.keys).to match_array(%i[category id value label url avatar_url])
+ end
+
+ it "includes the required group attrs" do
+ create(:group).add_owner(user)
+ result = search_autocomplete_opts("gro").first
+
+ expect(result.keys).to match_array(%i[category id label url avatar_url])
+ end
+
+ it "does not include the public group" do
+ group = create(:group)
+ expect(search_autocomplete_opts(group.name).size).to eq(0)
+ end
+
+ context "with a current project" do
+ before do
+ @project = create(:project, :repository)
+ end
+
+ it "includes project-specific sections" do
+ expect(search_autocomplete_opts("Files").size).to eq(1)
+ expect(search_autocomplete_opts("Commits").size).to eq(1)
+ end
+ end
+ end
+
+ context 'with an admin user' do
+ let(:admin) { create(:admin) }
+
+ before do
+ allow(self).to receive(:current_user).and_return(admin)
+ end
+
+ it "includes admin sections" do
+ expect(search_autocomplete_opts("admin").size).to eq(1)
+ end
+ end
+ end
+
describe 'search_entries_info' do
using RSpec::Parameterized::TableSyntax
diff --git a/spec/helpers/services_helper_spec.rb b/spec/helpers/services_helper_spec.rb
index edc14f86a50..10d6ec7b6a7 100644
--- a/spec/helpers/services_helper_spec.rb
+++ b/spec/helpers/services_helper_spec.rb
@@ -2,14 +2,33 @@
require 'spec_helper'
-describe ServicesHelper do
+RSpec.describe ServicesHelper do
describe 'event_action_title' do
it { expect(event_action_title('comment')).to eq 'Comment' }
it { expect(event_action_title('something')).to eq 'Something' }
end
- describe 'event_action_description' do
- it { expect(event_action_description('comment')).to eq 'Comment will be posted on each event' }
- it { expect(event_action_description('something')).to eq nil }
+ describe '#integration_form_data' do
+ 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
+ )
+ end
+ end
end
end
diff --git a/spec/helpers/sessions_helper_spec.rb b/spec/helpers/sessions_helper_spec.rb
index 647771ace92..027943aecee 100644
--- a/spec/helpers/sessions_helper_spec.rb
+++ b/spec/helpers/sessions_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe SessionsHelper do
+RSpec.describe SessionsHelper do
describe '#unconfirmed_email?' do
it 'returns true when the flash alert contains a devise failure unconfirmed message' do
flash[:alert] = t(:unconfirmed, scope: [:devise, :failure])
diff --git a/spec/helpers/sidekiq_helper_spec.rb b/spec/helpers/sidekiq_helper_spec.rb
index 86e52419f9c..6a0a92bafd8 100644
--- a/spec/helpers/sidekiq_helper_spec.rb
+++ b/spec/helpers/sidekiq_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe SidekiqHelper do
+RSpec.describe SidekiqHelper do
describe 'parse_sidekiq_ps' do
it 'parses line with time' do
line = '55137 10,0 2,1 S+ 2:30pm sidekiq 4.1.4 gitlab [0 of 25 busy] '
diff --git a/spec/helpers/snippets_helper_spec.rb b/spec/helpers/snippets_helper_spec.rb
index 6fdf4f5cfb4..8fc54f17e71 100644
--- a/spec/helpers/snippets_helper_spec.rb
+++ b/spec/helpers/snippets_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe SnippetsHelper do
+RSpec.describe SnippetsHelper do
include Gitlab::Routing
include IconsHelper
diff --git a/spec/helpers/sorting_helper_spec.rb b/spec/helpers/sorting_helper_spec.rb
index 5397a47b3dd..6c52016139b 100644
--- a/spec/helpers/sorting_helper_spec.rb
+++ b/spec/helpers/sorting_helper_spec.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
require 'spec_helper'
-describe SortingHelper do
+RSpec.describe SortingHelper do
include ApplicationHelper
include IconsHelper
include ExploreHelper
diff --git a/spec/helpers/sourcegraph_helper_spec.rb b/spec/helpers/sourcegraph_helper_spec.rb
index 3e8486a5632..6a95c8e4a43 100644
--- a/spec/helpers/sourcegraph_helper_spec.rb
+++ b/spec/helpers/sourcegraph_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe SourcegraphHelper do
+RSpec.describe SourcegraphHelper do
describe '#sourcegraph_url_message' do
let(:sourcegraph_url) { 'http://sourcegraph.example.com' }
diff --git a/spec/helpers/storage_helper_spec.rb b/spec/helpers/storage_helper_spec.rb
index 577e6e5caf0..eca42c8ce06 100644
--- a/spec/helpers/storage_helper_spec.rb
+++ b/spec/helpers/storage_helper_spec.rb
@@ -2,7 +2,7 @@
require "spec_helper"
-describe StorageHelper do
+RSpec.describe StorageHelper do
describe "#storage_counter" do
it "formats bytes to one decimal place" do
expect(helper.storage_counter(1.23.megabytes)).to eq("1.2 MB")
@@ -30,10 +30,11 @@ describe StorageHelper do
repository_size: 10.kilobytes,
wiki_size: 10.bytes,
lfs_objects_size: 20.gigabytes,
- build_artifacts_size: 30.megabytes))
+ build_artifacts_size: 30.megabytes,
+ snippets_size: 40.megabytes))
end
- let(:message) { 'Repository: 10 KB / Wikis: 10 Bytes / Build Artifacts: 30 MB / LFS: 20 GB' }
+ let(:message) { 'Repository: 10 KB / Wikis: 10 Bytes / Build Artifacts: 30 MB / LFS: 20 GB / Snippets: 40 MB' }
it 'works on ProjectStatistics' do
expect(helper.storage_counters_details(project.statistics)).to eq(message)
diff --git a/spec/helpers/submodule_helper_spec.rb b/spec/helpers/submodule_helper_spec.rb
index db0836c8550..426bca2ced2 100644
--- a/spec/helpers/submodule_helper_spec.rb
+++ b/spec/helpers/submodule_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe SubmoduleHelper do
+RSpec.describe SubmoduleHelper do
include RepoHelpers
let(:submodule_item) { double(id: 'hash', path: 'rack') }
diff --git a/spec/helpers/subscribable_banner_helper_spec.rb b/spec/helpers/subscribable_banner_helper_spec.rb
index 75f2e32d7d8..3f9ea989fb0 100644
--- a/spec/helpers/subscribable_banner_helper_spec.rb
+++ b/spec/helpers/subscribable_banner_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe SubscribableBannerHelper do
+RSpec.describe SubscribableBannerHelper do
describe '#display_subscription_banner!' do
it 'is over-written in EE' do
expect { helper.display_subscription_banner! }.not_to raise_error
diff --git a/spec/helpers/tab_helper_spec.rb b/spec/helpers/tab_helper_spec.rb
index 3a3935a2130..f89d0ac0f5a 100644
--- a/spec/helpers/tab_helper_spec.rb
+++ b/spec/helpers/tab_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe TabHelper do
+RSpec.describe TabHelper do
include ApplicationHelper
describe 'nav_link' do
diff --git a/spec/helpers/time_helper_spec.rb b/spec/helpers/time_helper_spec.rb
index 858d6d341f4..6663a5c81c8 100644
--- a/spec/helpers/time_helper_spec.rb
+++ b/spec/helpers/time_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe TimeHelper do
+RSpec.describe TimeHelper do
describe "#time_interval_in_words" do
it "returns minutes and seconds" do
intervals_in_words = {
diff --git a/spec/helpers/timeboxes_helper_spec.rb b/spec/helpers/timeboxes_helper_spec.rb
index 6fe738914ce..94e997f7a65 100644
--- a/spec/helpers/timeboxes_helper_spec.rb
+++ b/spec/helpers/timeboxes_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe TimeboxesHelper do
+RSpec.describe TimeboxesHelper do
describe '#milestones_filter_dropdown_path' do
let(:project) { create(:project) }
let(:project2) { create(:project) }
diff --git a/spec/helpers/timeboxes_routing_helper_spec.rb b/spec/helpers/timeboxes_routing_helper_spec.rb
index 1b0eb2c0ad2..952194b6704 100644
--- a/spec/helpers/timeboxes_routing_helper_spec.rb
+++ b/spec/helpers/timeboxes_routing_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe TimeboxesRoutingHelper do
+RSpec.describe TimeboxesRoutingHelper do
let(:project) { build_stubbed(:project) }
let(:group) { build_stubbed(:group) }
diff --git a/spec/helpers/todos_helper_spec.rb b/spec/helpers/todos_helper_spec.rb
index 0811c2af891..6b658a475b1 100644
--- a/spec/helpers/todos_helper_spec.rb
+++ b/spec/helpers/todos_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe TodosHelper do
+RSpec.describe TodosHelper do
let_it_be(:user) { create(:user) }
let_it_be(:author) { create(:user) }
let_it_be(:issue) { create(:issue, title: 'Issue 1') }
@@ -163,4 +163,83 @@ describe TodosHelper do
expect(design_option).to include(text: 'Design')
end
end
+
+ describe '#todo_target_state_pill' do
+ subject { helper.todo_target_state_pill(todo) }
+
+ shared_examples 'a rendered state pill' do |attr|
+ it 'returns expected html' do
+ aggregate_failures do
+ expect(subject).to have_css(".status-box-#{attr[:type]}-#{attr[:state].dasherize}")
+ expect(subject).to have_content(attr[:state].capitalize)
+ end
+ end
+ end
+
+ shared_examples 'no state pill' do
+ specify { expect(subject).to eq(nil) }
+ end
+
+ context 'merge request todo' do
+ let(:todo) { create(:todo, target: create(:merge_request)) }
+
+ it_behaves_like 'no state pill'
+
+ context 'merged MR' do
+ before do
+ todo.target.update!(state: 'merged')
+ end
+
+ it_behaves_like 'a rendered state pill', type: 'mr', state: 'merged'
+ end
+ end
+
+ context 'issue todo' do
+ let(:todo) { create(:todo, target: issue) }
+
+ it_behaves_like 'no state pill'
+
+ context 'closed issue' do
+ before do
+ todo.target.update!(state: 'closed')
+ end
+
+ it_behaves_like 'a rendered state pill', type: 'issue', state: 'closed'
+ end
+ end
+
+ context 'alert todo' do
+ let(:todo) { alert_todo }
+
+ it_behaves_like 'no state pill'
+
+ context 'resolved alert' do
+ before do
+ todo.target.resolve!
+ end
+
+ it_behaves_like 'a rendered state pill', type: 'alert', state: 'resolved'
+ end
+ end
+ end
+
+ describe '#todo_author_display?' do
+ using RSpec::Parameterized::TableSyntax
+
+ subject { helper.todo_author_display?(alert_todo) }
+
+ where(:action, :result) do
+ Todo::BUILD_FAILED | false
+ Todo::UNMERGEABLE | false
+ Todo::ASSIGNED | true
+ end
+
+ with_them do
+ before do
+ alert_todo.action = action
+ end
+
+ it { is_expected.to eq(result) }
+ end
+ end
end
diff --git a/spec/helpers/tracking_helper_spec.rb b/spec/helpers/tracking_helper_spec.rb
index b0c98be4130..47b344cfc25 100644
--- a/spec/helpers/tracking_helper_spec.rb
+++ b/spec/helpers/tracking_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe TrackingHelper do
+RSpec.describe TrackingHelper do
describe '#tracking_attrs' do
using RSpec::Parameterized::TableSyntax
diff --git a/spec/helpers/tree_helper_spec.rb b/spec/helpers/tree_helper_spec.rb
index c7cdb4ae45c..307479744ef 100644
--- a/spec/helpers/tree_helper_spec.rb
+++ b/spec/helpers/tree_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe TreeHelper do
+RSpec.describe TreeHelper do
let(:project) { create(:project, :repository) }
let(:repository) { project.repository }
let(:sha) { 'c1c67abbaf91f624347bb3ae96eabe3a1b742478' }
@@ -154,4 +154,58 @@ describe TreeHelper do
expect(helper.commit_in_single_accessible_branch).to include(escaped_branch_name)
end
end
+
+ describe '#vue_file_list_data' do
+ before do
+ allow(helper).to receive(:current_user).and_return(nil)
+ end
+
+ it 'returns a list of attributes related to the project' do
+ expect(helper.vue_file_list_data(project, sha)).to include(
+ can_push_code: nil,
+ fork_path: nil,
+ escaped_ref: sha,
+ ref: sha,
+ project_path: project.full_path,
+ project_short_path: project.path,
+ full_name: project.name_with_namespace
+ )
+ end
+
+ context 'user does not have write access but a personal fork exists' do
+ include ProjectForksHelper
+
+ let_it_be(:user) { create(:user) }
+ let!(:forked_project) { create(:project, :repository, namespace: user.namespace) }
+
+ before do
+ project.add_guest(user)
+ fork_project(project, nil, target_project: forked_project)
+
+ allow(helper).to receive(:current_user).and_return(user)
+ end
+
+ it 'includes fork_path too' do
+ expect(helper.vue_file_list_data(project, sha)).to include(
+ fork_path: forked_project.full_path
+ )
+ end
+ end
+
+ context 'user has write access' do
+ let_it_be(:user) { create(:user) }
+
+ before do
+ project.add_developer(user)
+
+ allow(helper).to receive(:current_user).and_return(user)
+ end
+
+ it 'includes can_push_code: true' do
+ expect(helper.vue_file_list_data(project, sha)).to include(
+ can_push_code: "true"
+ )
+ end
+ end
+ end
end
diff --git a/spec/helpers/user_callouts_helper_spec.rb b/spec/helpers/user_callouts_helper_spec.rb
index b123b11d278..60238053aa2 100644
--- a/spec/helpers/user_callouts_helper_spec.rb
+++ b/spec/helpers/user_callouts_helper_spec.rb
@@ -2,15 +2,15 @@
require "spec_helper"
-describe UserCalloutsHelper do
- let(:user) { create(:user) }
+RSpec.describe UserCalloutsHelper do
+ let_it_be(:user) { create(:user) }
before do
allow(helper).to receive(:current_user).and_return(user)
end
describe '.show_gke_cluster_integration_callout?' do
- let(:project) { create(:project) }
+ let_it_be(:project) { create(:project) }
subject { helper.show_gke_cluster_integration_callout?(project) }
diff --git a/spec/helpers/users_helper_spec.rb b/spec/helpers/users_helper_spec.rb
index e3e599007a4..8dfdb23c64b 100644
--- a/spec/helpers/users_helper_spec.rb
+++ b/spec/helpers/users_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe UsersHelper do
+RSpec.describe UsersHelper do
include TermsHelper
let(:user) { create(:user) }
diff --git a/spec/helpers/version_check_helper_spec.rb b/spec/helpers/version_check_helper_spec.rb
index 421ff21bfdb..6d849d0720e 100644
--- a/spec/helpers/version_check_helper_spec.rb
+++ b/spec/helpers/version_check_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe VersionCheckHelper do
+RSpec.describe VersionCheckHelper do
describe '#version_status_badge' do
it 'returns nil if not dev environment and not enabled' do
stub_rails_env('development')
diff --git a/spec/helpers/visibility_level_helper_spec.rb b/spec/helpers/visibility_level_helper_spec.rb
index 3b4d82c65ac..9cbace3cfd0 100644
--- a/spec/helpers/visibility_level_helper_spec.rb
+++ b/spec/helpers/visibility_level_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe VisibilityLevelHelper do
+RSpec.describe VisibilityLevelHelper do
include ProjectForksHelper
let(:project) { build(:project) }
diff --git a/spec/helpers/wiki_helper_spec.rb b/spec/helpers/wiki_helper_spec.rb
index 4b53823aaed..040368b5ebd 100644
--- a/spec/helpers/wiki_helper_spec.rb
+++ b/spec/helpers/wiki_helper_spec.rb
@@ -2,7 +2,39 @@
require 'spec_helper'
-describe WikiHelper do
+RSpec.describe WikiHelper do
+ describe '#wiki_page_title' do
+ let_it_be(:page) { create(:wiki_page) }
+
+ it 'sets the title for the show action' do
+ expect(helper).to receive(:breadcrumb_title).with(page.human_title)
+ expect(helper).to receive(:wiki_breadcrumb_dropdown_links).with(page.slug)
+ expect(helper).to receive(:page_title).with(page.human_title, 'Wiki')
+ expect(helper).to receive(:add_to_breadcrumbs).with('Wiki', helper.wiki_path(page.wiki))
+
+ helper.wiki_page_title(page)
+ end
+
+ it 'sets the title for a custom action' do
+ expect(helper).to receive(:breadcrumb_title).with(page.human_title)
+ expect(helper).to receive(:wiki_breadcrumb_dropdown_links).with(page.slug)
+ expect(helper).to receive(:page_title).with('Edit', page.human_title, 'Wiki')
+ expect(helper).to receive(:add_to_breadcrumbs).with('Wiki', helper.wiki_path(page.wiki))
+
+ helper.wiki_page_title(page, 'Edit')
+ end
+
+ it 'sets the title for an unsaved page' do
+ expect(page).to receive(:persisted?).and_return(false)
+ expect(helper).not_to receive(:breadcrumb_title)
+ expect(helper).not_to receive(:wiki_breadcrumb_dropdown_links)
+ expect(helper).to receive(:page_title).with('Wiki')
+ expect(helper).to receive(:add_to_breadcrumbs).with('Wiki', helper.wiki_path(page.wiki))
+
+ helper.wiki_page_title(page)
+ end
+ end
+
describe '#breadcrumb' do
context 'when the page is at the root level' do
it 'returns the capitalized page name' do
@@ -72,4 +104,24 @@ describe WikiHelper do
expect(helper.wiki_sort_title('unknown')).to eq('Title')
end
end
+
+ describe '#wiki_page_tracking_context' do
+ let_it_be(:page) { create(:wiki_page, title: 'path/to/page 💩', content: '💩', format: :markdown) }
+
+ subject { helper.wiki_page_tracking_context(page) }
+
+ it 'returns the tracking context' do
+ expect(subject).to eq(
+ 'wiki-format' => :markdown,
+ 'wiki-title-size' => 9,
+ 'wiki-content-size' => 4,
+ 'wiki-directory-nest-level' => 2
+ )
+ end
+
+ it 'returns a nest level of zero for toplevel files' do
+ expect(page).to receive(:path).and_return('page')
+ expect(subject).to include('wiki-directory-nest-level' => 0)
+ end
+ end
end
diff --git a/spec/helpers/x509_helper_spec.rb b/spec/helpers/x509_helper_spec.rb
index db3f6158195..4e3e8c8d3f6 100644
--- a/spec/helpers/x509_helper_spec.rb
+++ b/spec/helpers/x509_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe X509Helper do
+RSpec.describe X509Helper do
describe '#x509_subject' do
let(:search_uppercase) { %w[CN OU O] }
let(:search_lowercase) { %w[cn ou o] }