summaryrefslogtreecommitdiff
path: root/spec/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'spec/helpers')
-rw-r--r--spec/helpers/admin/user_actions_helper_spec.rb41
-rw-r--r--spec/helpers/analytics/unique_visits_helper_spec.rb34
-rw-r--r--spec/helpers/application_settings_helper_spec.rb20
-rw-r--r--spec/helpers/blob_helper_spec.rb16
-rw-r--r--spec/helpers/ci/pipeline_editor_helper_spec.rb36
-rw-r--r--spec/helpers/ci/runners_helper_spec.rb16
-rw-r--r--spec/helpers/clusters_helper_spec.rb7
-rw-r--r--spec/helpers/commits_helper_spec.rb9
-rw-r--r--spec/helpers/diff_helper_spec.rb25
-rw-r--r--spec/helpers/emails_helper_spec.rb8
-rw-r--r--spec/helpers/environments_helper_spec.rb14
-rw-r--r--spec/helpers/gitlab_routing_helper_spec.rb17
-rw-r--r--spec/helpers/integrations_helper_spec.rb (renamed from spec/helpers/services_helper_spec.rb)28
-rw-r--r--spec/helpers/issues_helper_spec.rb3
-rw-r--r--spec/helpers/namespaces_helper_spec.rb20
-rw-r--r--spec/helpers/nav/new_dropdown_helper_spec.rb27
-rw-r--r--spec/helpers/nav/top_nav_helper_spec.rb13
-rw-r--r--spec/helpers/operations_helper_spec.rb24
-rw-r--r--spec/helpers/packages_helper_spec.rb4
-rw-r--r--spec/helpers/projects/alert_management_helper_spec.rb14
-rw-r--r--spec/helpers/projects_helper_spec.rb33
-rw-r--r--spec/helpers/registrations_helper_spec.rb24
-rw-r--r--spec/helpers/releases_helper_spec.rb50
-rw-r--r--spec/helpers/sessions_helper_spec.rb36
-rw-r--r--spec/helpers/user_callouts_helper_spec.rb12
-rw-r--r--spec/helpers/users_helper_spec.rb50
26 files changed, 380 insertions, 201 deletions
diff --git a/spec/helpers/admin/user_actions_helper_spec.rb b/spec/helpers/admin/user_actions_helper_spec.rb
index 7ccd9a4fe3e..d945b13cad6 100644
--- a/spec/helpers/admin/user_actions_helper_spec.rb
+++ b/spec/helpers/admin/user_actions_helper_spec.rb
@@ -29,13 +29,13 @@ RSpec.describe Admin::UserActionsHelper do
context 'the user is a standard user' do
let_it_be(:user) { create(:user) }
- it { is_expected.to contain_exactly("edit", "block", "deactivate", "delete", "delete_with_contributions") }
+ it { is_expected.to contain_exactly("edit", "block", "ban", "deactivate", "delete", "delete_with_contributions") }
end
context 'the user is an admin user' do
let_it_be(:user) { create(:user, :admin) }
- it { is_expected.to contain_exactly("edit", "block", "deactivate", "delete", "delete_with_contributions") }
+ it { is_expected.to contain_exactly("edit", "block", "ban", "deactivate", "delete", "delete_with_contributions") }
end
context 'the user is blocked by LDAP' do
@@ -59,7 +59,7 @@ RSpec.describe Admin::UserActionsHelper do
context 'the user is deactivated' do
let_it_be(:user) { create(:user, :deactivated) }
- it { is_expected.to contain_exactly("edit", "block", "activate", "delete", "delete_with_contributions") }
+ it { is_expected.to contain_exactly("edit", "block", "ban", "activate", "delete", "delete_with_contributions") }
end
context 'the user is locked' do
@@ -73,6 +73,7 @@ RSpec.describe Admin::UserActionsHelper do
is_expected.to contain_exactly(
"edit",
"block",
+ "ban",
"deactivate",
"unlock",
"delete",
@@ -81,6 +82,12 @@ RSpec.describe Admin::UserActionsHelper do
}
end
+ context 'the user is banned' do
+ let_it_be(:user) { create(:user, :banned) }
+
+ it { is_expected.to contain_exactly("edit", "unban", "delete", "delete_with_contributions") }
+ end
+
context 'the current_user does not have permission to delete the user' do
let_it_be(:user) { build(:user) }
@@ -88,7 +95,7 @@ RSpec.describe Admin::UserActionsHelper do
allow(helper).to receive(:can?).with(current_user, :destroy_user, user).and_return(false)
end
- it { is_expected.to contain_exactly("edit", "block", "deactivate") }
+ it { is_expected.to contain_exactly("edit", "block", "ban", "deactivate") }
end
context 'the user is a sole owner of a group' do
@@ -99,7 +106,31 @@ RSpec.describe Admin::UserActionsHelper do
group.add_owner(user)
end
- it { is_expected.to contain_exactly("edit", "block", "deactivate") }
+ it { is_expected.to contain_exactly("edit", "block", "ban", "deactivate") }
+ end
+
+ context 'the user is a bot' do
+ let_it_be(:user) { create(:user, :bot) }
+
+ it { is_expected.to match_array([]) }
+ end
+
+ context 'when `ban_user_feature_flag` is disabled' do
+ before do
+ stub_feature_flags(ban_user_feature_flag: false)
+ end
+
+ context 'the user is a standard user' do
+ let_it_be(:user) { create(:user) }
+
+ it { is_expected.not_to include("ban") }
+ end
+
+ context 'the user is banned' do
+ let_it_be(:user) { create(:user, :banned) }
+
+ it { is_expected.not_to include("unban") }
+ end
end
end
end
diff --git a/spec/helpers/analytics/unique_visits_helper_spec.rb b/spec/helpers/analytics/unique_visits_helper_spec.rb
deleted file mode 100644
index b4b370c169d..00000000000
--- a/spec/helpers/analytics/unique_visits_helper_spec.rb
+++ /dev/null
@@ -1,34 +0,0 @@
-# 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) }
-
- 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/application_settings_helper_spec.rb b/spec/helpers/application_settings_helper_spec.rb
index 4c62b3e12c1..90bfb2e72e6 100644
--- a/spec/helpers/application_settings_helper_spec.rb
+++ b/spec/helpers/application_settings_helper_spec.rb
@@ -178,6 +178,26 @@ RSpec.describe ApplicationSettingsHelper do
end
end
+ describe '.valid_runner_registrars' do
+ subject { helper.valid_runner_registrars }
+
+ context 'when only admins are permitted to register runners' do
+ before do
+ stub_application_setting(valid_runner_registrars: [])
+ end
+
+ it { is_expected.to eq [] }
+ end
+
+ context 'when group and project users are permitted to register runners' do
+ before do
+ stub_application_setting(valid_runner_registrars: ApplicationSetting::VALID_RUNNER_REGISTRAR_TYPES)
+ end
+
+ it { is_expected.to eq ApplicationSetting::VALID_RUNNER_REGISTRAR_TYPES }
+ end
+ end
+
describe '.signup_enabled?' do
subject { helper.signup_enabled? }
diff --git a/spec/helpers/blob_helper_spec.rb b/spec/helpers/blob_helper_spec.rb
index 885569574a4..c48d609836d 100644
--- a/spec/helpers/blob_helper_spec.rb
+++ b/spec/helpers/blob_helper_spec.rb
@@ -67,8 +67,8 @@ RSpec.describe BlobHelper do
it 'passes on primary tracking attributes' do
parsed_link = Capybara.string(link).find_link('Edit')
- expect(parsed_link[:'data-track-event']).to eq("click_edit")
- expect(parsed_link[:'data-track-label']).to eq("Edit")
+ expect(parsed_link[:'data-track-action']).to eq("click_edit")
+ expect(parsed_link[:'data-track-label']).to eq("edit")
expect(parsed_link[:'data-track-property']).to eq(nil)
end
end
@@ -85,8 +85,8 @@ RSpec.describe BlobHelper do
it 'passes on secondary tracking attributes' do
parsed_link = Capybara.string(link).find_link('Edit')
- expect(parsed_link[:'data-track-event']).to eq("click_edit")
- expect(parsed_link[:'data-track-label']).to eq("Edit")
+ expect(parsed_link[:'data-track-action']).to eq("click_edit")
+ expect(parsed_link[:'data-track-label']).to eq("edit")
expect(parsed_link[:'data-track-property']).to eq("secondary")
end
end
@@ -332,8 +332,8 @@ RSpec.describe BlobHelper do
it 'passes on secondary tracking attributes' do
parsed_link = Capybara.string(link).find_link('Web IDE')
- expect(parsed_link[:'data-track-event']).to eq("click_edit_ide")
- expect(parsed_link[:'data-track-label']).to eq("Web IDE")
+ expect(parsed_link[:'data-track-action']).to eq("click_edit_ide")
+ expect(parsed_link[:'data-track-label']).to eq("web_ide")
expect(parsed_link[:'data-track-property']).to eq("secondary")
end
end
@@ -350,8 +350,8 @@ RSpec.describe BlobHelper do
it 'passes on primary tracking attributes' do
parsed_link = Capybara.string(link).find_link('Web IDE')
- expect(parsed_link[:'data-track-event']).to eq("click_edit_ide")
- expect(parsed_link[:'data-track-label']).to eq("Web IDE")
+ expect(parsed_link[:'data-track-action']).to eq("click_edit_ide")
+ expect(parsed_link[:'data-track-label']).to eq("web_ide")
expect(parsed_link[:'data-track-property']).to eq(nil)
end
end
diff --git a/spec/helpers/ci/pipeline_editor_helper_spec.rb b/spec/helpers/ci/pipeline_editor_helper_spec.rb
index 2287718db5a..3ce4657282e 100644
--- a/spec/helpers/ci/pipeline_editor_helper_spec.rb
+++ b/spec/helpers/ci/pipeline_editor_helper_spec.rb
@@ -40,12 +40,12 @@ RSpec.describe Ci::PipelineEditorHelper do
it 'returns pipeline editor data' do
expect(pipeline_editor_data).to eq({
"ci-config-path": project.ci_config_path_or_default,
- "ci-examples-help-page-path" => help_page_path('ci/examples/README'),
- "ci-help-page-path" => help_page_path('ci/README'),
+ "ci-examples-help-page-path" => help_page_path('ci/examples/index'),
+ "ci-help-page-path" => help_page_path('ci/index'),
"commit-sha" => project.commit.sha,
- "default-branch" => project.default_branch,
+ "default-branch" => project.default_branch_or_main,
"empty-state-illustration-path" => 'foo',
- "initial-branch-name": nil,
+ "initial-branch-name" => nil,
"lint-help-page-path" => help_page_path('ci/lint', anchor: 'validate-basic-logic-and-syntax'),
"needs-help-page-path" => help_page_path('ci/yaml/README', anchor: 'needs'),
"new-merge-request-path" => '/mock/project/-/merge_requests/new',
@@ -54,7 +54,7 @@ RSpec.describe Ci::PipelineEditorHelper do
"project-path" => project.path,
"project-full-path" => project.full_path,
"project-namespace" => project.namespace.full_path,
- "runner-help-page-path" => help_page_path('ci/runners/README'),
+ "runner-help-page-path" => help_page_path('ci/runners/index'),
"total-branches" => project.repository.branches.length,
"yml-help-page-path" => help_page_path('ci/yaml/README')
})
@@ -67,12 +67,12 @@ RSpec.describe Ci::PipelineEditorHelper do
it 'returns pipeline editor data' do
expect(pipeline_editor_data).to eq({
"ci-config-path": project.ci_config_path_or_default,
- "ci-examples-help-page-path" => help_page_path('ci/examples/README'),
- "ci-help-page-path" => help_page_path('ci/README'),
+ "ci-examples-help-page-path" => help_page_path('ci/examples/index'),
+ "ci-help-page-path" => help_page_path('ci/index'),
"commit-sha" => '',
- "default-branch" => project.default_branch,
+ "default-branch" => project.default_branch_or_main,
"empty-state-illustration-path" => 'foo',
- "initial-branch-name": nil,
+ "initial-branch-name" => nil,
"lint-help-page-path" => help_page_path('ci/lint', anchor: 'validate-basic-logic-and-syntax'),
"needs-help-page-path" => help_page_path('ci/yaml/README', anchor: 'needs'),
"new-merge-request-path" => '/mock/project/-/merge_requests/new',
@@ -81,11 +81,27 @@ RSpec.describe Ci::PipelineEditorHelper do
"project-path" => project.path,
"project-full-path" => project.full_path,
"project-namespace" => project.namespace.full_path,
- "runner-help-page-path" => help_page_path('ci/runners/README'),
+ "runner-help-page-path" => help_page_path('ci/runners/index'),
"total-branches" => 0,
"yml-help-page-path" => help_page_path('ci/yaml/README')
})
end
end
+
+ context 'with a non-default branch name' do
+ let(:user) { create(:user) }
+
+ before do
+ create_commit('Message', project, user, 'feature')
+ controller.params[:branch_name] = 'feature'
+ end
+
+ it 'returns correct values' do
+ latest_feature_sha = project.repository.commit('feature').sha
+
+ expect(pipeline_editor_data['initial-branch-name']).to eq('feature')
+ expect(pipeline_editor_data['commit-sha']).to eq(latest_feature_sha)
+ end
+ end
end
end
diff --git a/spec/helpers/ci/runners_helper_spec.rb b/spec/helpers/ci/runners_helper_spec.rb
index 94d4d620de9..40927d44e24 100644
--- a/spec/helpers/ci/runners_helper_spec.rb
+++ b/spec/helpers/ci/runners_helper_spec.rb
@@ -3,6 +3,12 @@
require 'spec_helper'
RSpec.describe Ci::RunnersHelper do
+ let_it_be(:user, refind: true) { create(:user) }
+
+ before do
+ allow(helper).to receive(:current_user).and_return(user)
+ end
+
describe '#runner_status_icon', :clean_gitlab_redis_cache do
it "returns - not contacted yet" do
runner = create(:ci_runner)
@@ -90,28 +96,28 @@ RSpec.describe Ci::RunnersHelper do
context 'when project has runners' do
it 'returns the correct value for is_enabled' do
- data = toggle_shared_runners_settings_data(project_with_runners)
+ data = helper.toggle_shared_runners_settings_data(project_with_runners)
expect(data[:is_enabled]).to eq("true")
end
end
context 'when project does not have runners' do
it 'returns the correct value for is_enabled' do
- data = toggle_shared_runners_settings_data(project_without_runners)
+ data = helper.toggle_shared_runners_settings_data(project_without_runners)
expect(data[:is_enabled]).to eq("false")
end
end
context 'for all projects' do
it 'returns the update path for toggling the shared runners setting' do
- data = toggle_shared_runners_settings_data(project_with_runners)
+ data = helper.toggle_shared_runners_settings_data(project_with_runners)
expect(data[:update_path]).to eq(toggle_shared_runners_project_runners_path(project_with_runners))
end
it 'returns false for is_disabled_and_unoverridable when project has no group' do
project = create(:project)
- data = toggle_shared_runners_settings_data(project)
+ data = helper.toggle_shared_runners_settings_data(project)
expect(data[:is_disabled_and_unoverridable]).to eq("false")
end
@@ -129,7 +135,7 @@ RSpec.describe Ci::RunnersHelper do
project = create(:project, group: group)
allow(group).to receive(:shared_runners_setting).and_return(shared_runners_setting)
- data = toggle_shared_runners_settings_data(project)
+ data = helper.toggle_shared_runners_settings_data(project)
expect(data[:is_disabled_and_unoverridable]).to eq(is_disabled_and_unoverridable)
end
end
diff --git a/spec/helpers/clusters_helper_spec.rb b/spec/helpers/clusters_helper_spec.rb
index 8c738141063..f64afa1ed71 100644
--- a/spec/helpers/clusters_helper_spec.rb
+++ b/spec/helpers/clusters_helper_spec.rb
@@ -75,6 +75,13 @@ RSpec.describe ClustersHelper do
it 'displays project path' do
expect(subject[:project_path]).to eq(project.full_path)
end
+
+ it 'generates docs urls' do
+ expect(subject[:agent_docs_url]).to eq(help_page_path('user/clusters/agent/index'))
+ expect(subject[:install_docs_url]).to eq(help_page_path('administration/clusters/kas'))
+ expect(subject[:get_started_docs_url]).to eq(help_page_path('user/clusters/agent/index', anchor: 'define-a-configuration-repository'))
+ expect(subject[:integration_docs_url]).to eq(help_page_path('user/clusters/agent/index', anchor: 'get-started-with-gitops-and-the-gitlab-agent'))
+ end
end
describe '#js_clusters_list_data' do
diff --git a/spec/helpers/commits_helper_spec.rb b/spec/helpers/commits_helper_spec.rb
index 4e94636ba45..34445d26258 100644
--- a/spec/helpers/commits_helper_spec.rb
+++ b/spec/helpers/commits_helper_spec.rb
@@ -321,4 +321,13 @@ RSpec.describe CommitsHelper do
it { is_expected.to include(pipeline.cache_key) }
end
end
+
+ describe "#commit_path_template" do
+ let(:project) { build(:project) }
+ let(:expected_path) { "/#{project.full_path}/-/commit/$COMMIT_SHA" }
+
+ subject { helper.commit_path_template(project) }
+
+ it { is_expected.to eq(expected_path) }
+ end
end
diff --git a/spec/helpers/diff_helper_spec.rb b/spec/helpers/diff_helper_spec.rb
index dfea1020c52..29708f10de4 100644
--- a/spec/helpers/diff_helper_spec.rb
+++ b/spec/helpers/diff_helper_spec.rb
@@ -293,23 +293,22 @@ RSpec.describe DiffHelper do
describe '#render_overflow_warning?' do
using RSpec::Parameterized::TableSyntax
- let(:diffs_collection) { instance_double(Gitlab::Diff::FileCollection::MergeRequestDiff, raw_diff_files: diff_files) }
+ let(:diffs_collection) { instance_double(Gitlab::Diff::FileCollection::MergeRequestDiff, raw_diff_files: diff_files, overflow?: false) }
let(:diff_files) { Gitlab::Git::DiffCollection.new(files) }
let(:safe_file) { { too_large: false, diff: '' } }
let(:large_file) { { too_large: true, diff: '' } }
let(:files) { [safe_file, safe_file] }
- before do
- allow(diff_files).to receive(:overflow?).and_return(false)
- allow(diff_files).to receive(:overflow_max_bytes?).and_return(false)
- allow(diff_files).to receive(:overflow_max_files?).and_return(false)
- allow(diff_files).to receive(:overflow_max_lines?).and_return(false)
- allow(diff_files).to receive(:collapsed_safe_bytes?).and_return(false)
- allow(diff_files).to receive(:collapsed_safe_files?).and_return(false)
- allow(diff_files).to receive(:collapsed_safe_lines?).and_return(false)
- end
-
context 'when no limits are hit' do
+ before do
+ allow(diff_files).to receive(:overflow_max_bytes?).and_return(false)
+ allow(diff_files).to receive(:overflow_max_files?).and_return(false)
+ allow(diff_files).to receive(:overflow_max_lines?).and_return(false)
+ allow(diff_files).to receive(:collapsed_safe_bytes?).and_return(false)
+ allow(diff_files).to receive(:collapsed_safe_files?).and_return(false)
+ allow(diff_files).to receive(:collapsed_safe_lines?).and_return(false)
+ end
+
it 'returns false and does not log any overflow events' do
expect(Gitlab::Metrics).not_to receive(:add_event).with(:diffs_overflow_collection_limits)
expect(Gitlab::Metrics).not_to receive(:add_event).with(:diffs_overflow_single_file_limits)
@@ -343,7 +342,7 @@ RSpec.describe DiffHelper do
context 'when the file collection has an overflow' do
before do
- allow(diff_files).to receive(:overflow?).and_return(true)
+ allow(diffs_collection).to receive(:overflow?).and_return(true)
end
it 'returns true and only logs all the correct collection overflow event' do
@@ -405,7 +404,7 @@ RSpec.describe DiffHelper do
it "returns a valid URL" do
allow(helper).to receive(:safe_params).and_return(params)
- expect(subject).to match(/foo\/bar\/-\/commit\/#{commit.sha}\/diff_for_path/)
+ expect(subject).to match(%r{foo/bar/-/commit/#{commit.sha}/diff_for_path})
end
end
diff --git a/spec/helpers/emails_helper_spec.rb b/spec/helpers/emails_helper_spec.rb
index 58ed5901d45..956c19f54d1 100644
--- a/spec/helpers/emails_helper_spec.rb
+++ b/spec/helpers/emails_helper_spec.rb
@@ -238,16 +238,16 @@ RSpec.describe EmailsHelper do
it 'returns the default header logo' do
create :appearance, header_logo: nil
- expect(header_logo).to eq(
- %{<img alt="GitLab" src="/images/mailers/gitlab_header_logo.gif" width="55" height="50" />}
+ expect(header_logo).to match(
+ %r{<img alt="GitLab" src="/images/mailers/gitlab_header_logo\.(?:gif|png)" width="\d+" height="\d+" />}
)
end
end
context 'there is no brand item' do
it 'returns the default header logo' do
- expect(header_logo).to eq(
- %{<img alt="GitLab" src="/images/mailers/gitlab_header_logo.gif" width="55" height="50" />}
+ expect(header_logo).to match(
+ %r{<img alt="GitLab" src="/images/mailers/gitlab_header_logo\.(?:gif|png)" width="\d+" height="\d+" />}
)
end
end
diff --git a/spec/helpers/environments_helper_spec.rb b/spec/helpers/environments_helper_spec.rb
index 96869fcc777..22867a5b652 100644
--- a/spec/helpers/environments_helper_spec.rb
+++ b/spec/helpers/environments_helper_spec.rb
@@ -122,7 +122,7 @@ RSpec.describe EnvironmentsHelper do
end
context 'has_managed_prometheus' do
- context 'without prometheus service' do
+ context 'without prometheus integration' do
it "doesn't have managed prometheus" do
expect(metrics_data).to include(
'has_managed_prometheus' => 'false'
@@ -130,12 +130,12 @@ RSpec.describe EnvironmentsHelper do
end
end
- context 'with prometheus service' do
- let_it_be(:prometheus_service) { create(:prometheus_service, project: project) }
+ context 'with prometheus integration' do
+ let_it_be(:prometheus_integration) { create(:prometheus_integration, project: project) }
- context 'when manual prometheus service is active' do
+ context 'when manual prometheus integration is active' do
it "doesn't have managed prometheus" do
- prometheus_service.update!(manual_configuration: true)
+ prometheus_integration.update!(manual_configuration: true)
expect(metrics_data).to include(
'has_managed_prometheus' => 'false'
@@ -143,9 +143,9 @@ RSpec.describe EnvironmentsHelper do
end
end
- context 'when prometheus service is inactive' do
+ context 'when prometheus integration is inactive' do
it "doesn't have managed prometheus" do
- prometheus_service.update!(manual_configuration: false)
+ prometheus_integration.update!(manual_configuration: false)
expect(metrics_data).to include(
'has_managed_prometheus' => 'false'
diff --git a/spec/helpers/gitlab_routing_helper_spec.rb b/spec/helpers/gitlab_routing_helper_spec.rb
index 40faf994ad2..a3f2b8fafa0 100644
--- a/spec/helpers/gitlab_routing_helper_spec.rb
+++ b/spec/helpers/gitlab_routing_helper_spec.rb
@@ -239,8 +239,9 @@ RSpec.describe GitlabRoutingHelper do
let(:blob) { snippet.blobs.first }
let(:ref) { 'snippet-test-ref' }
let(:args) { {} }
+ let(:path) { blob.path }
- subject { gitlab_raw_snippet_blob_url(snippet, blob.path, ref, **args) }
+ subject { gitlab_raw_snippet_blob_url(snippet, path, ref, **args) }
it_behaves_like 'snippet blob raw url'
@@ -248,7 +249,7 @@ RSpec.describe GitlabRoutingHelper do
let(:args) { { inline: true } }
let(:snippet) { personal_snippet }
- it { expect(subject).to eq("http://test.host/-/snippets/#{snippet.id}/raw/#{ref}/#{blob.path}?inline=true") }
+ it { expect(subject).to eq("http://test.host/-/snippets/#{snippet.id}/raw/#{ref}/#{path}?inline=true") }
end
context 'without a ref' do
@@ -257,7 +258,17 @@ RSpec.describe GitlabRoutingHelper do
let(:expected_ref) { snippet.repository.root_ref }
it 'uses the root ref' do
- expect(subject).to eq("http://test.host/-/snippets/#{snippet.id}/raw/#{expected_ref}/#{blob.path}")
+ expect(subject).to eq("http://test.host/-/snippets/#{snippet.id}/raw/#{expected_ref}/#{path}")
+ end
+
+ context 'when snippet does not have a repository' do
+ let(:snippet) { create(:personal_snippet) }
+ let(:path) { 'example' }
+ let(:expected_ref) { Gitlab::DefaultBranch.value }
+
+ it 'uses the instance deafult branch' do
+ expect(subject).to eq("http://test.host/-/snippets/#{snippet.id}/raw/#{expected_ref}/#{path}")
+ end
end
end
end
diff --git a/spec/helpers/services_helper_spec.rb b/spec/helpers/integrations_helper_spec.rb
index 6dd872225ba..8e652d2f150 100644
--- a/spec/helpers/services_helper_spec.rb
+++ b/spec/helpers/integrations_helper_spec.rb
@@ -2,7 +2,23 @@
require 'spec_helper'
-RSpec.describe ServicesHelper do
+RSpec.describe IntegrationsHelper do
+ describe '#integration_event_description' do
+ subject(:description) { helper.integration_event_description(integration, 'merge_request_events') }
+
+ context 'when integration is Jira' do
+ let(:integration) { Integrations::Jira.new }
+
+ it { is_expected.to include('Jira') }
+ end
+
+ context 'when integration is Team City' do
+ let(:integration) { Integrations::Teamcity.new }
+
+ it { is_expected.to include('TeamCity') }
+ end
+ end
+
describe '#integration_form_data' do
let(:fields) do
[
@@ -36,8 +52,8 @@ RSpec.describe ServicesHelper do
subject { helper.integration_form_data(integration) }
- context 'Slack service' do
- let(:integration) { build(:slack_service) }
+ context 'with Slack integration' do
+ let(:integration) { build(:integrations_slack) }
it { is_expected.to include(*fields) }
it { is_expected.not_to include(*jira_fields) }
@@ -48,14 +64,14 @@ RSpec.describe ServicesHelper do
end
context 'Jira service' do
- let(:integration) { build(:jira_service) }
+ let(:integration) { build(:jira_integration) }
it { is_expected.to include(*fields, *jira_fields) }
end
end
describe '#scoped_reset_integration_path' do
- let(:integration) { build_stubbed(:jira_service) }
+ let(:integration) { build_stubbed(:jira_integration) }
let(:group) { nil }
subject { helper.scoped_reset_integration_path(integration, group: group) }
@@ -75,7 +91,7 @@ RSpec.describe ServicesHelper do
end
context 'when a new integration is not persisted' do
- let_it_be(:integration) { build(:jira_service) }
+ let_it_be(:integration) { build(:jira_integration) }
it 'returns an empty string' do
is_expected.to eq('')
diff --git a/spec/helpers/issues_helper_spec.rb b/spec/helpers/issues_helper_spec.rb
index a8a227c8ec4..96aba312ba3 100644
--- a/spec/helpers/issues_helper_spec.rb
+++ b/spec/helpers/issues_helper_spec.rb
@@ -294,7 +294,6 @@ RSpec.describe IssuesHelper do
expected = {
autocomplete_award_emojis_path: autocomplete_award_emojis_path,
- autocomplete_users_path: autocomplete_users_path(active: true, current_user: true, project_id: project.id, format: :json),
calendar_path: '#',
can_bulk_update: 'true',
can_edit: 'true',
@@ -313,8 +312,6 @@ RSpec.describe IssuesHelper do
max_attachment_size: number_to_human_size(Gitlab::CurrentSettings.max_attachment_size.megabytes),
new_issue_path: new_project_issue_path(project, issue: { milestone_id: finder.milestones.first.id }),
project_import_jira_path: project_import_jira_path(project),
- project_labels_path: project_labels_path(project, include_ancestor_groups: true, format: :json),
- project_milestones_path: project_milestones_path(project, format: :json),
project_path: project.full_path,
quick_actions_help_path: help_page_path('user/project/quick_actions'),
reset_path: new_issuable_address_project_path(project, issuable_type: 'issue'),
diff --git a/spec/helpers/namespaces_helper_spec.rb b/spec/helpers/namespaces_helper_spec.rb
index a8a918cbc74..68bc19cb429 100644
--- a/spec/helpers/namespaces_helper_spec.rb
+++ b/spec/helpers/namespaces_helper_spec.rb
@@ -195,26 +195,6 @@ RSpec.describe NamespacesHelper do
end
end
- describe '#cascading_namespace_settings_enabled?' do
- subject { helper.cascading_namespace_settings_enabled? }
-
- context 'when `cascading_namespace_settings` feature flag is enabled' do
- it 'returns `true`' do
- expect(subject).to be(true)
- end
- end
-
- context 'when `cascading_namespace_settings` feature flag is disabled' do
- before do
- stub_feature_flags(cascading_namespace_settings: false)
- end
-
- it 'returns `false`' do
- expect(subject).to be(false)
- end
- end
- end
-
describe '#cascading_namespace_settings_popover_data' do
attribute = :delayed_project_removal
diff --git a/spec/helpers/nav/new_dropdown_helper_spec.rb b/spec/helpers/nav/new_dropdown_helper_spec.rb
index dd860ce3180..e3d9bc5b174 100644
--- a/spec/helpers/nav/new_dropdown_helper_spec.rb
+++ b/spec/helpers/nav/new_dropdown_helper_spec.rb
@@ -13,7 +13,6 @@ RSpec.describe Nav::NewDropdownHelper do
let(:with_can_create_project) { false }
let(:with_can_create_group) { false }
let(:with_can_create_snippet) { false }
- let(:with_new_repo_experiment) { :control }
let(:with_invite_members_experiment) { false }
let(:with_invite_members_experiment_enabled) { false }
@@ -29,7 +28,6 @@ RSpec.describe Nav::NewDropdownHelper do
end
before do
- stub_experiments(new_repo: with_new_repo_experiment)
allow(::Gitlab::Experimentation).to receive(:active?).with(:invite_members_new_dropdown) { with_invite_members_experiment }
allow(helper).to receive(:experiment_enabled?).with(:invite_members_new_dropdown) { with_invite_members_experiment_enabled }
allow(helper).to receive(:tracking_label) { 'test_tracking_label' }
@@ -43,19 +41,6 @@ RSpec.describe Nav::NewDropdownHelper do
allow(user).to receive(:can?).with(:create_snippet) { with_can_create_snippet }
end
- shared_examples 'new repo experiment shared example' do |title|
- let(:with_new_repo_experiment) { :candidate }
-
- it 'has experiment project title' do
- expect(subject[:menu_sections]).to match(
- expected_menu_section(
- title: title,
- menu_item: a_hash_including(title: 'New project/repository')
- )
- )
- end
- end
-
shared_examples 'invite member link shared example' do
it 'shows invite member link' do
expect(subject[:menu_sections]).to eq(
@@ -117,15 +102,13 @@ RSpec.describe Nav::NewDropdownHelper do
title: 'GitLab',
menu_item: ::Gitlab::Nav::TopNavMenuItem.build(
id: 'general_new_project',
- title: 'New project',
+ title: 'New project/repository',
href: '/projects/new',
- data: { track_experiment: 'new_repo', track_event: 'click_link_new_project', track_label: 'plus_menu_dropdown', qa_selector: 'global_new_project_link' }
+ data: { track_event: 'click_link_new_project', track_label: 'plus_menu_dropdown', qa_selector: 'global_new_project_link' }
)
)
)
end
-
- it_behaves_like 'new repo experiment shared example', 'GitLab'
end
context 'when can create group' do
@@ -193,15 +176,13 @@ RSpec.describe Nav::NewDropdownHelper do
title: 'This group',
menu_item: ::Gitlab::Nav::TopNavMenuItem.build(
id: 'new_project',
- title: 'New project',
+ title: 'New project/repository',
href: "/projects/new?namespace_id=#{group.id}",
- data: { track_experiment: 'new_repo', track_event: 'click_link_new_project_group', track_label: 'plus_menu_dropdown' }
+ data: { track_event: 'click_link_new_project_group', track_label: 'plus_menu_dropdown' }
)
)
)
end
-
- it_behaves_like 'new repo experiment shared example', 'This group'
end
context 'when can create subgroup' do
diff --git a/spec/helpers/nav/top_nav_helper_spec.rb b/spec/helpers/nav/top_nav_helper_spec.rb
index d87c751c62f..4d6da258536 100644
--- a/spec/helpers/nav/top_nav_helper_spec.rb
+++ b/spec/helpers/nav/top_nav_helper_spec.rb
@@ -143,7 +143,6 @@ RSpec.describe Nav::TopNavHelper do
css_class: 'qa-projects-dropdown',
data: {
track_event: 'click_dropdown',
- track_experiment: 'new_repo',
track_label: 'projects_dropdown'
},
icon: 'project',
@@ -539,10 +538,18 @@ RSpec.describe Nav::TopNavHelper do
end
context 'with new' do
- let(:with_new_view_model) { { id: 'test-new-view-model' } }
+ let(:with_new_view_model) { { menu_sections: [{ id: 'test-new-view-model' }] } }
it 'has new subview' do
- expect(subject[:views][:new]).to eq({ id: 'test-new-view-model' })
+ expect(subject[:views][:new]).to eq(with_new_view_model)
+ end
+ end
+
+ context 'with new and no menu_sections' do
+ let(:with_new_view_model) { { menu_sections: [] } }
+
+ it 'has new subview' do
+ expect(subject[:views][:new]).to be_nil
end
end
end
diff --git a/spec/helpers/operations_helper_spec.rb b/spec/helpers/operations_helper_spec.rb
index e1bd477bc75..1864f9fad15 100644
--- a/spec/helpers/operations_helper_spec.rb
+++ b/spec/helpers/operations_helper_spec.rb
@@ -20,19 +20,19 @@ RSpec.describe OperationsHelper do
allow(helper).to receive(:can?).with(user, :admin_operations, project) { true }
end
- context 'initial service configuration' do
- let_it_be(:prometheus_service) { PrometheusService.new(project: project) }
+ context 'initial integration configuration' do
+ let_it_be(:prometheus_integration) { ::Integrations::Prometheus.new(project: project) }
before do
- allow(project).to receive(:find_or_initialize_service).and_call_original
- allow(project).to receive(:find_or_initialize_service).with('prometheus').and_return(prometheus_service)
+ allow(project).to receive(:find_or_initialize_integration).and_call_original
+ allow(project).to receive(:find_or_initialize_integration).with('prometheus').and_return(prometheus_integration)
end
it 'returns the correct values' do
expect(subject).to eq(
'alerts_setup_url' => help_page_path('operations/incident_management/integrations.md', anchor: 'configuration'),
'alerts_usage_url' => project_alert_management_index_path(project),
- 'prometheus_form_path' => project_service_path(project, prometheus_service),
+ 'prometheus_form_path' => project_service_path(project, prometheus_integration),
'prometheus_reset_key_path' => reset_alerting_token_project_settings_operations_path(project),
'prometheus_authorization_key' => nil,
'prometheus_api_url' => nil,
@@ -53,15 +53,15 @@ RSpec.describe OperationsHelper do
end
context 'with external Prometheus configured' do
- let_it_be(:prometheus_service, reload: true) do
- create(:prometheus_service, project: project)
+ let_it_be(:prometheus_integration, reload: true) do
+ create(:prometheus_integration, 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
+ 'prometheus_api_url' => prometheus_integration.api_url
)
end
end
@@ -71,7 +71,7 @@ RSpec.describe OperationsHelper do
it 'returns the correct values' do
expect(subject).to include(
'prometheus_activated' => 'false',
- 'prometheus_api_url' => prometheus_service.api_url
+ 'prometheus_api_url' => prometheus_integration.api_url
)
end
end
@@ -79,11 +79,11 @@ RSpec.describe OperationsHelper do
let(:cluster_managed) { false }
before do
- allow(prometheus_service)
+ allow(prometheus_integration)
.to receive(:prometheus_available?)
.and_return(cluster_managed)
- prometheus_service.update!(manual_configuration: false)
+ prometheus_integration.update!(manual_configuration: false)
end
include_examples 'Prometheus is disabled'
@@ -101,7 +101,7 @@ RSpec.describe OperationsHelper do
it 'returns the correct values' do
expect(subject).to include(
'prometheus_authorization_key' => project_alerting_setting.token,
- 'prometheus_api_url' => prometheus_service.api_url
+ 'prometheus_api_url' => prometheus_integration.api_url
)
end
end
diff --git a/spec/helpers/packages_helper_spec.rb b/spec/helpers/packages_helper_spec.rb
index 93d32cb8418..8b3c8411fbd 100644
--- a/spec/helpers/packages_helper_spec.rb
+++ b/spec/helpers/packages_helper_spec.rb
@@ -66,6 +66,7 @@ RSpec.describe PackagesHelper do
end
describe '#show_cleanup_policy_on_alert' do
+ let_it_be(:user) { create(:user) }
let_it_be_with_reload(:container_repository) { create(:container_repository) }
subject { helper.show_cleanup_policy_on_alert(project.reload) }
@@ -203,9 +204,10 @@ RSpec.describe PackagesHelper do
with_them do
before do
+ allow(helper).to receive(:current_user).and_return(user)
allow(Gitlab).to receive(:com?).and_return(com)
stub_config(registry: { enabled: config_registry })
- allow(project).to receive(:container_registry_enabled).and_return(project_registry)
+ allow(project).to receive(:feature_available?).with(:container_registry, user).and_return(project_registry)
stub_application_setting(container_expiration_policies_enable_historic_entries: historic_entries)
stub_feature_flags(container_expiration_policies_historic_entry: false)
stub_feature_flags(container_expiration_policies_historic_entry: project) if historic_entry
diff --git a/spec/helpers/projects/alert_management_helper_spec.rb b/spec/helpers/projects/alert_management_helper_spec.rb
index 9895d06f93a..2450f7838b3 100644
--- a/spec/helpers/projects/alert_management_helper_spec.rb
+++ b/spec/helpers/projects/alert_management_helper_spec.rb
@@ -41,12 +41,12 @@ RSpec.describe Projects::AlertManagementHelper do
end
end
- context 'with prometheus service' do
- let_it_be(:prometheus_service) { create(:prometheus_service, project: project) }
+ context 'with prometheus integration' do
+ let_it_be(:prometheus_integration) { create(:prometheus_integration, project: project) }
- context 'when manual prometheus service is active' do
+ context 'when manual prometheus integration is active' do
it "enables alert management and doesn't show managed prometheus" do
- prometheus_service.update!(manual_configuration: true)
+ prometheus_integration.update!(manual_configuration: true)
expect(data).to include(
'alert-management-enabled' => 'true'
@@ -69,9 +69,9 @@ RSpec.describe Projects::AlertManagementHelper do
end
end
- context 'when prometheus service is inactive' do
+ context 'when prometheus integration is inactive' do
it 'disables alert management and hides managed prometheus' do
- prometheus_service.update!(manual_configuration: false)
+ prometheus_integration.update!(manual_configuration: false)
expect(data).to include(
'alert-management-enabled' => 'false'
@@ -83,7 +83,7 @@ RSpec.describe Projects::AlertManagementHelper do
end
end
- context 'without prometheus service' do
+ context 'without prometheus integration' do
it "doesn't have managed prometheus" do
expect(data).to include(
'has-managed-prometheus' => 'false'
diff --git a/spec/helpers/projects_helper_spec.rb b/spec/helpers/projects_helper_spec.rb
index 1804a9a99cf..75e80f5edbc 100644
--- a/spec/helpers/projects_helper_spec.rb
+++ b/spec/helpers/projects_helper_spec.rb
@@ -138,7 +138,7 @@ RSpec.describe ProjectsHelper do
end
end
- describe "#project_list_cache_key", :clean_gitlab_redis_shared_state do
+ describe "#project_list_cache_key", :clean_gitlab_redis_cache do
let(:project) { project_with_repo }
before do
@@ -876,6 +876,37 @@ RSpec.describe ProjectsHelper do
end
end
+ describe '#show_terraform_banner?' do
+ let_it_be(:ruby) { create(:programming_language, name: 'Ruby') }
+ let_it_be(:hcl) { create(:programming_language, name: 'HCL') }
+
+ subject { helper.show_terraform_banner?(project) }
+
+ before do
+ create(:repository_language, project: project, programming_language: language, share: 1)
+ end
+
+ context 'the project does not contain terraform files' do
+ let(:language) { ruby }
+
+ it { is_expected.to be_falsey }
+ end
+
+ context 'the project contains terraform files' do
+ let(:language) { hcl }
+
+ it { is_expected.to be_truthy }
+
+ context 'the project already has a terraform state' do
+ before do
+ create(:terraform_state, project: project)
+ end
+
+ it { is_expected.to be_falsey }
+ end
+ end
+ end
+
describe '#project_title' do
subject { helper.project_title(project) }
diff --git a/spec/helpers/registrations_helper_spec.rb b/spec/helpers/registrations_helper_spec.rb
index fa647548b3c..b2f9a794cb3 100644
--- a/spec/helpers/registrations_helper_spec.rb
+++ b/spec/helpers/registrations_helper_spec.rb
@@ -3,30 +3,6 @@
require 'spec_helper'
RSpec.describe RegistrationsHelper do
- using RSpec::Parameterized::TableSyntax
-
- describe '#social_signin_enabled?' do
- before do
- allow(::Gitlab).to receive(:dev_env_or_com?).and_return(com)
- allow(view).to receive(:omniauth_enabled?).and_return(omniauth_enabled)
- allow(view).to receive(:button_based_providers_enabled?).and_return(button_based_providers_enabled)
- allow(view).to receive(:devise_mapping).and_return(double(omniauthable?: omniauthable))
- end
-
- subject { helper.social_signin_enabled? }
-
- where com: [true, false],
- omniauth_enabled: [true, false],
- omniauthable: [true, false],
- button_based_providers_enabled: [true, false]
-
- with_them do
- let(:result) { com && omniauth_enabled && button_based_providers_enabled && omniauthable }
-
- it { is_expected.to eq(result) }
- end
- end
-
describe '#signup_username_data_attributes' do
it 'has expected attributes' do
expect(helper.signup_username_data_attributes.keys).to include(:min_length, :min_length_message, :max_length, :max_length_message, :qa_selector)
diff --git a/spec/helpers/releases_helper_spec.rb b/spec/helpers/releases_helper_spec.rb
index e6bf91ceef6..69f66dc6488 100644
--- a/spec/helpers/releases_helper_spec.rb
+++ b/spec/helpers/releases_helper_spec.rb
@@ -5,7 +5,7 @@ require 'spec_helper'
RSpec.describe ReleasesHelper do
describe '#illustration' do
it 'returns the correct image path' do
- expect(helper.illustration).to match(/illustrations\/releases-(\w+)\.svg/)
+ expect(helper.illustration).to match(%r{illustrations/releases-(\w+)\.svg})
end
end
@@ -48,16 +48,6 @@ RSpec.describe ReleasesHelper do
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
@@ -107,4 +97,42 @@ RSpec.describe ReleasesHelper do
end
end
end
+
+ describe 'startup queries' do
+ describe 'use_startup_query_for_index_page?' do
+ it 'allows startup queries for non-paginated requests' do
+ allow(helper).to receive(:params).and_return({ unrelated_query_param: 'value' })
+
+ expect(helper.use_startup_query_for_index_page?).to be(true)
+ end
+
+ it 'disallows startup queries for requests paginated with a "before" cursor' do
+ allow(helper).to receive(:params).and_return({ unrelated_query_param: 'value', before: 'cursor' })
+
+ expect(helper.use_startup_query_for_index_page?).to be(false)
+ end
+
+ it 'disallows startup queries for requests paginated with an "after" cursor' do
+ allow(helper).to receive(:params).and_return({ unrelated_query_param: 'value', after: 'cursor' })
+
+ expect(helper.use_startup_query_for_index_page?).to be(false)
+ end
+ end
+
+ describe '#index_page_startup_query_variables' do
+ let_it_be(:project) { build(:project, namespace: create(:group)) }
+
+ before do
+ helper.instance_variable_set(:@project, project)
+ end
+
+ it 'returns the correct GraphQL variables for the startup query' do
+ expect(helper.index_page_startup_query_variables).to eq({
+ fullPath: project.full_path,
+ sort: 'RELEASED_AT_DESC',
+ first: 1
+ })
+ end
+ end
+ end
end
diff --git a/spec/helpers/sessions_helper_spec.rb b/spec/helpers/sessions_helper_spec.rb
index 027943aecee..816e43669bd 100644
--- a/spec/helpers/sessions_helper_spec.rb
+++ b/spec/helpers/sessions_helper_spec.rb
@@ -3,6 +3,42 @@
require 'spec_helper'
RSpec.describe SessionsHelper do
+ describe '#recently_confirmed_com?' do
+ subject { helper.recently_confirmed_com? }
+
+ context 'when on .com' do
+ before do
+ allow(Gitlab).to receive(:dev_env_or_com?).and_return(true)
+ end
+
+ it 'when flash notice is empty it is false' do
+ flash[:notice] = nil
+ expect(subject).to be false
+ end
+
+ it 'when flash notice is anything it is false' do
+ flash[:notice] = 'hooray!'
+ expect(subject).to be false
+ end
+
+ it 'when flash notice is devise confirmed message it is true' do
+ flash[:notice] = t(:confirmed, scope: [:devise, :confirmations])
+ expect(subject).to be true
+ end
+ end
+
+ context 'when not on .com' do
+ before do
+ allow(Gitlab).to receive(:dev_env_or_com?).and_return(false)
+ end
+
+ it 'when flash notice is devise confirmed message it is false' do
+ flash[:notice] = t(:confirmed, scope: [:devise, :confirmations])
+ expect(subject).to be false
+ end
+ end
+ end
+
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/user_callouts_helper_spec.rb b/spec/helpers/user_callouts_helper_spec.rb
index f68da45bb9a..90333cb0ad5 100644
--- a/spec/helpers/user_callouts_helper_spec.rb
+++ b/spec/helpers/user_callouts_helper_spec.rb
@@ -97,7 +97,17 @@ RSpec.describe UserCalloutsHelper do
allow(helper).to receive(:user_dismissed?).with(described_class::CUSTOMIZE_HOMEPAGE) { false }
end
- it { is_expected.to be true }
+ context 'when user is on the default dashboard' do
+ it { is_expected.to be true }
+ end
+
+ context 'when user is not on the default dashboard' do
+ before do
+ user.dashboard = 'stars'
+ end
+
+ it { is_expected.to be false }
+ end
end
context 'when user dismissed' do
diff --git a/spec/helpers/users_helper_spec.rb b/spec/helpers/users_helper_spec.rb
index 862fd58df04..480b1e2a0de 100644
--- a/spec/helpers/users_helper_spec.rb
+++ b/spec/helpers/users_helper_spec.rb
@@ -364,4 +364,54 @@ RSpec.describe UsersHelper do
expect(data[:paths]).to match_schema('entities/admin_users_data_attributes_paths')
end
end
+
+ describe '#confirm_user_data' do
+ confirm_admin_user_path = '/admin/users/root/confirm'
+
+ before do
+ allow(helper).to receive(:confirm_admin_user_path).with(user).and_return(confirm_admin_user_path)
+ end
+
+ subject(:confirm_user_data) { helper.confirm_user_data(user) }
+
+ it 'sets `path` key correctly' do
+ expect(confirm_user_data[:path]).to eq(confirm_admin_user_path)
+ end
+
+ it 'sets `modal_attributes` key to valid json' do
+ expect(confirm_user_data[:modal_attributes]).to be_valid_json
+ end
+
+ context 'when `user.unconfirmed_email` is set' do
+ let(:user) { create(:user, unconfirmed_email: 'foo@bar.com') }
+
+ it 'sets `modal_attributes.messageHtml` correctly' do
+ expect(Gitlab::Json.parse(confirm_user_data[:modal_attributes])['messageHtml']).to eq('This user has an unconfirmed email address (foo@bar.com). You may force a confirmation.')
+ end
+ end
+
+ context 'when `user.unconfirmed_email` is not set' do
+ it 'sets `modal_attributes.messageHtml` correctly' do
+ expect(Gitlab::Json.parse(confirm_user_data[:modal_attributes])['messageHtml']).to eq('This user has an unconfirmed email address. You may force a confirmation.')
+ end
+ end
+ end
+
+ describe '#admin_user_actions_data_attributes' do
+ subject(:data) { helper.admin_user_actions_data_attributes(user) }
+
+ before do
+ allow(helper).to receive(:current_user).and_return(user)
+ allow(Admin::UserEntity).to receive(:represent).and_call_original
+ end
+
+ it 'user matches the serialized json' do
+ expect(data[:user]).to be_valid_json
+ expect(Admin::UserEntity).to have_received(:represent).with(user, hash_including({ current_user: user }))
+ end
+
+ it 'paths matches the schema' do
+ expect(data[:paths]).to match_schema('entities/admin_users_data_attributes_paths')
+ end
+ end
end