diff options
Diffstat (limited to 'spec/helpers')
26 files changed, 471 insertions, 262 deletions
diff --git a/spec/helpers/admin/components_helper_spec.rb b/spec/helpers/admin/components_helper_spec.rb new file mode 100644 index 00000000000..bb590d003ad --- /dev/null +++ b/spec/helpers/admin/components_helper_spec.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +require "spec_helper" + +RSpec.describe Admin::ComponentsHelper, feature_category: :database do + describe '#database_versions' do + let(:expected_version) { '12.13' } + let(:expected_hash) do + main = { + main: { adapter_name: 'PostgreSQL', version: expected_version } + } + main[:ci] = { adapter_name: 'PostgreSQL', version: expected_version } if Gitlab::Database.has_config?(:ci) + main[:geo] = { adapter_name: 'PostgreSQL', version: expected_version } if Gitlab::Database.has_config?(:geo) + + main + end + + subject { helper.database_versions } + + before do + allow_next_instance_of(Gitlab::Database::Reflection) do |reflection| + allow(reflection).to receive(:version).and_return(expected_version) + end + end + + it 'returns expected database data' do + expect(subject).to eq(expected_hash) + end + end +end diff --git a/spec/helpers/appearances_helper_spec.rb b/spec/helpers/appearances_helper_spec.rb index b3afd350397..8673353996e 100644 --- a/spec/helpers/appearances_helper_spec.rb +++ b/spec/helpers/appearances_helper_spec.rb @@ -10,6 +10,20 @@ RSpec.describe AppearancesHelper do allow(helper).to receive(:current_user).and_return(user) end + describe '#appearance_short_name' do + it 'returns the default value' do + create(:appearance) + + expect(helper.appearance_short_name).to match('GitLab') + end + + it 'returns the customized value' do + create(:appearance, pwa_short_name: 'Short') + + expect(helper.appearance_short_name).to match('Short') + end + end + describe '.current_appearance' do it 'memoizes empty appearance' do expect(Appearance).to receive(:current).once diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index 3384f9fea05..a8514c373db 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -163,6 +163,13 @@ RSpec.describe ApplicationHelper do expect(timeago_element.attr('class')).to eq 'js-short-timeago' expect(timeago_element.next_element).to eq nil end + + it 'returns blank if time is nil' do + el = helper.time_ago_with_tooltip(nil) + + expect(el).to eq('') + expect(el.html_safe).to eq('') + end end describe '#active_when' do @@ -221,28 +228,43 @@ RSpec.describe ApplicationHelper do end describe '#instance_review_permitted?' do - let_it_be(:non_admin_user) { create :user } - let_it_be(:admin_user) { create :user, :admin } + shared_examples 'returns expected result depending on instance setting' do |instance_setting, expected_result| + before do + allow(::Gitlab::CurrentSettings).to receive(:instance_review_permitted?).and_return(instance_setting) + allow(helper).to receive(:current_user).and_return(current_user) + end - before do - allow(::Gitlab::CurrentSettings).to receive(:instance_review_permitted?).and_return(app_setting) - allow(helper).to receive(:current_user).and_return(current_user) + it { is_expected.to be(expected_result) } end subject { helper.instance_review_permitted? } - where(app_setting: [true, false], is_admin: [true, false, nil]) + context 'as admin' do + let_it_be(:current_user) { build(:user, :admin) } - with_them do - let(:current_user) do - if is_admin.nil? - nil - else - is_admin ? admin_user : non_admin_user + context 'when admin mode setting is disabled', :do_not_mock_admin_mode_setting do + it_behaves_like 'returns expected result depending on instance setting', true, true + it_behaves_like 'returns expected result depending on instance setting', false, false + end + + context 'when admin mode setting is enabled' do + context 'when in admin mode', :enable_admin_mode do + it_behaves_like 'returns expected result depending on instance setting', true, true + it_behaves_like 'returns expected result depending on instance setting', false, false + end + + context 'when not in admin mode' do + it_behaves_like 'returns expected result depending on instance setting', true, false + it_behaves_like 'returns expected result depending on instance setting', false, false end end + end + + context 'as normal user' do + let_it_be(:current_user) { build(:user) } - it { is_expected.to be(app_setting && is_admin) } + it_behaves_like 'returns expected result depending on instance setting', true, false + it_behaves_like 'returns expected result depending on instance setting', false, false end end @@ -597,16 +619,6 @@ RSpec.describe ApplicationHelper do it 'returns nil' do expect(helper.dispensable_render).to be_nil end - - context 'when the feature flag is disabled' do - before do - stub_feature_flags(dispensable_render: false) - end - - it 'raises an error' do - expect { helper.dispensable_render }.to raise_error(StandardError) - end - end end end @@ -651,16 +663,6 @@ RSpec.describe ApplicationHelper do it 'returns nil' do expect(helper.dispensable_render_if_exists).to be_nil end - - context 'when the feature flag is disabled' do - before do - stub_feature_flags(dispensable_render: false) - end - - it 'raises an error' do - expect { helper.dispensable_render_if_exists }.to raise_error(StandardError) - end - end end end diff --git a/spec/helpers/button_helper_spec.rb b/spec/helpers/button_helper_spec.rb index a7f65aa3134..8a5669867bf 100644 --- a/spec/helpers/button_helper_spec.rb +++ b/spec/helpers/button_helper_spec.rb @@ -165,6 +165,7 @@ RSpec.describe ButtonHelper do context 'when no `text` attribute is not provided' do it 'shows copy to clipboard button with default configuration and no text set to copy' do expect(element.attr('class')).to eq('btn btn-clipboard gl-button btn-default-tertiary btn-icon btn-sm') + expect(element.attr('title')).to eq('Copy') expect(element.attr('type')).to eq('button') expect(element.attr('aria-label')).to eq('Copy') expect(element.attr('aria-live')).to eq('polite') diff --git a/spec/helpers/ci/runners_helper_spec.rb b/spec/helpers/ci/runners_helper_spec.rb index 1b1edde8faf..6d14abd6574 100644 --- a/spec/helpers/ci/runners_helper_spec.rb +++ b/spec/helpers/ci/runners_helper_spec.rb @@ -103,7 +103,7 @@ RSpec.describe Ci::RunnersHelper do { runner_enabled_value: Namespace::SR_ENABLED, runner_disabled_value: Namespace::SR_DISABLED_AND_UNOVERRIDABLE, - runner_allow_override_value: Namespace::SR_DISABLED_WITH_OVERRIDE + runner_allow_override_value: Namespace::SR_DISABLED_AND_OVERRIDABLE } end @@ -197,7 +197,7 @@ RSpec.describe Ci::RunnersHelper do where(:shared_runners_setting, :is_disabled_and_unoverridable) do :shared_runners_enabled | "false" - :disabled_with_override | "false" + :disabled_and_overridable | "false" :disabled_and_unoverridable | "true" end diff --git a/spec/helpers/emails_helper_spec.rb b/spec/helpers/emails_helper_spec.rb index 04653d9ff03..1f7400983da 100644 --- a/spec/helpers/emails_helper_spec.rb +++ b/spec/helpers/emails_helper_spec.rb @@ -385,7 +385,7 @@ RSpec.describe EmailsHelper do context 'with no html tag' do let(:expected_output) do - 'Reviewer changed to John' + 'John was added as a reviewer.<br>' end it 'returns the expected output' do @@ -395,7 +395,7 @@ RSpec.describe EmailsHelper do context 'with <strong> tag' do let(:expected_output) do - 'Reviewer changed to <strong>John</strong>' + '<strong>John</strong> was added as a reviewer.<br>' end it 'returns the expected output' do @@ -410,7 +410,7 @@ RSpec.describe EmailsHelper do context 'with no html tag' do let(:expected_output) do - 'Reviewer changed from John and Mary to Ted' + 'Ted was added as a reviewer.<br>John and Mary were removed from reviewers.' end it 'returns the expected output' do @@ -420,7 +420,7 @@ RSpec.describe EmailsHelper do context 'with <strong> tag' do let(:expected_output) do - 'Reviewer changed from <strong>John and Mary</strong> to <strong>Ted</strong>' + '<strong>Ted</strong> was added as a reviewer.<br><strong>John and Mary</strong> were removed from reviewers.' end it 'returns the expected output' do @@ -435,7 +435,7 @@ RSpec.describe EmailsHelper do context 'with no html tag' do let(:expected_output) do - 'Reviewer changed from John and Mary to Unassigned' + 'All reviewers were removed.' end it 'returns the expected output' do @@ -445,7 +445,7 @@ RSpec.describe EmailsHelper do context 'with <strong> tag' do let(:expected_output) do - 'Reviewer changed from <strong>John and Mary</strong> to <strong>Unassigned</strong>' + 'All reviewers were removed.' end it 'returns the expected output' do @@ -460,7 +460,7 @@ RSpec.describe EmailsHelper do let(:fishy_user) { build(:user, name: "<script>alert('hi')</script>") } let(:expected_output) do - 'Reviewer changed to <strong><script>alert('hi')</script></strong>' + '<strong><script>alert('hi')</script></strong> was added as a reviewer.<br>' end it 'escapes the html tag' do @@ -476,7 +476,7 @@ RSpec.describe EmailsHelper do let(:fishy_user) { build(:user, name: "example.com") } let(:expected_output) do - 'Reviewer changed to example_com' + 'example_com was added as a reviewer.<br>' end it "sanitizes user's name" do diff --git a/spec/helpers/feature_flags_helper_spec.rb b/spec/helpers/feature_flags_helper_spec.rb index 228459277ca..786454c6c4d 100644 --- a/spec/helpers/feature_flags_helper_spec.rb +++ b/spec/helpers/feature_flags_helper_spec.rb @@ -38,7 +38,7 @@ RSpec.describe FeatureFlagsHelper do feature_flags_path: "/#{project.full_path}/-/feature_flags", environments_endpoint: "/#{project.full_path}/-/environments/search.json", strategy_type_docs_page_path: "/help/operations/feature_flags#feature-flag-strategies", - environments_scope_docs_path: "/help/ci/environments/index.md#scope-environments-with-specs") + environments_scope_docs_path: "/help/ci/environments/index.md#limit-the-environment-scope-of-a-cicd-variable") end end end diff --git a/spec/helpers/form_helper_spec.rb b/spec/helpers/form_helper_spec.rb index 1797b0e32cd..7c8c59be409 100644 --- a/spec/helpers/form_helper_spec.rb +++ b/spec/helpers/form_helper_spec.rb @@ -162,6 +162,24 @@ RSpec.describe FormHelper do end end + it 'renders custom messages without the attribute name prefix' do + model = double(errors: errors_stub('Error 1')) + model.errors.add(:name, 'is already taken') + model.errors.add(:code_name, 'This code name is not allowed') + + allow(model.class).to receive(:human_attribute_name) do |attribute| + attribute.to_s.capitalize + end + + errors = helper.form_errors(model, custom_message: [:code_name]) + + aggregate_failures do + expect(errors).to include('<li>Error 1</li>') + expect(errors).to include('<li>Name is already taken</li>') + expect(errors).to include('<li>This code name is not allowed</li>') + end + end + it 'renders help page links' do stubbed_errors = ActiveModel::Errors.new(double).tap do |errors| errors.add(:base, 'No text.', help_page_url: 'http://localhost/doc/user/index.html') diff --git a/spec/helpers/groups/group_members_helper_spec.rb b/spec/helpers/groups/group_members_helper_spec.rb index 4d1280533dd..a9c6822e2c1 100644 --- a/spec/helpers/groups/group_members_helper_spec.rb +++ b/spec/helpers/groups/group_members_helper_spec.rb @@ -55,7 +55,9 @@ RSpec.describe Groups::GroupMembersHelper do expected = { source_id: shared_group.id, can_manage_members: true, - can_manage_access_requests: true + can_manage_access_requests: true, + group_name: shared_group.name, + group_path: shared_group.full_path } expect(subject).to include(expected) diff --git a/spec/helpers/groups/observability_helper_spec.rb b/spec/helpers/groups/observability_helper_spec.rb index 6d0a8631f78..ee33a853f9c 100644 --- a/spec/helpers/groups/observability_helper_spec.rb +++ b/spec/helpers/groups/observability_helper_spec.rb @@ -22,6 +22,11 @@ RSpec.describe Groups::ObservabilityHelper do allow(helper).to receive(:params).and_return({ action: 'explore' }) expect(helper.observability_iframe_src(group)).to eq("#{observability_url}/-/#{group.id}/explore") end + + it 'returns the iframe src for action: datasources' do + allow(helper).to receive(:params).and_return({ action: 'datasources' }) + expect(helper.observability_iframe_src(group)).to eq("#{observability_url}/-/#{group.id}/datasources") + end end context 'if observability_path exists in params' do @@ -65,6 +70,11 @@ RSpec.describe Groups::ObservabilityHelper do allow(helper).to receive(:params).and_return({ action: 'explore' }) expect(helper.observability_iframe_src(group)).to eq("#{observability_url}/explore") end + + it 'returns the iframe src without group.id for action: datasources' do + allow(helper).to receive(:params).and_return({ action: 'datasources' }) + expect(helper.observability_iframe_src(group)).to eq("#{observability_url}/datasources") + end end end @@ -76,12 +86,17 @@ RSpec.describe Groups::ObservabilityHelper do it 'returns the title for action: manage' do allow(helper).to receive(:params).and_return({ action: 'manage' }) - expect(helper.observability_page_title).to eq("Manage Dashboards") + expect(helper.observability_page_title).to eq("Manage dashboards") end it 'returns the title for action: explore' do allow(helper).to receive(:params).and_return({ action: 'explore' }) - expect(helper.observability_page_title).to eq("Explore") + expect(helper.observability_page_title).to eq("Explore telemetry data") + end + + it 'returns the title for action: datasources' do + allow(helper).to receive(:params).and_return({ action: 'datasources' }) + expect(helper.observability_page_title).to eq("Data sources") end it 'returns the default title for unknown action' do diff --git a/spec/helpers/import_helper_spec.rb b/spec/helpers/import_helper_spec.rb index 18cbbdfd804..7a5a69ea5b5 100644 --- a/spec/helpers/import_helper_spec.rb +++ b/spec/helpers/import_helper_spec.rb @@ -49,4 +49,20 @@ RSpec.describe ImportHelper do expect(helper.provider_project_link_url(host_url, full_path)).to match('http://provider.com/repo/path') end end + + describe '#import_configure_github_admin_message' do + subject { helper.import_configure_github_admin_message } + + it 'returns note for admin' do + allow(helper).to receive(:current_user) { instance_double('User', can_admin_all_resources?: true) } + + is_expected.to have_text('Note: As an administrator') + end + + it 'returns note for other user' do + allow(helper).to receive(:current_user) { instance_double('User', can_admin_all_resources?: false) } + + is_expected.to have_text('Note: Consider asking your GitLab administrator') + end + end end diff --git a/spec/helpers/issuables_helper_spec.rb b/spec/helpers/issuables_helper_spec.rb index 15b57a4c9eb..f2e3e401766 100644 --- a/spec/helpers/issuables_helper_spec.rb +++ b/spec/helpers/issuables_helper_spec.rb @@ -112,19 +112,7 @@ RSpec.describe IssuablesHelper do context 'when assigned issues count is over 100' do let_it_be(:issues) { create_list(:issue, 101, project: project, assignees: [user]) } - before do - stub_feature_flags(limit_assigned_issues_count: false) - end - - it { is_expected.to eq 101 } - - context 'when FF limit_assigned_issues_count is enabled' do - before do - stub_feature_flags(limit_assigned_issues_count: true) - end - - it { is_expected.to eq 100 } - end + it { is_expected.to eq 100 } end end end @@ -142,19 +130,7 @@ RSpec.describe IssuablesHelper do context 'when assigned issues count is over 99' do let_it_be(:issues) { create_list(:issue, 100, project: project, assignees: [user]) } - before do - stub_feature_flags(limit_assigned_issues_count: false) - end - - it { is_expected.to eq '100' } - - context 'when FF limit_assigned_issues_count is enabled' do - before do - stub_feature_flags(limit_assigned_issues_count: true) - end - - it { is_expected.to eq '99+' } - end + it { is_expected.to eq '99+' } end end @@ -629,4 +605,28 @@ RSpec.describe IssuablesHelper do expect(helper.sidebar_milestone_tooltip_label(milestone)).to eq('<img onerror=alert(1)><br/>Milestone') end end + + describe '#hidden_issuable_icon', feature_category: :insider_threat do + let_it_be(:mock_svg) { '<svg></svg>'.html_safe } + + before do + allow(helper).to receive(:sprite_icon).and_return(mock_svg) + end + + context 'when issuable is an issue' do + let_it_be(:issuable) { build(:issue) } + + it 'returns icon with tooltip' do + expect(helper.hidden_issuable_icon(issuable)).to eq("<span class=\"has-tooltip\" title=\"This issue is hidden because its author has been banned\">#{mock_svg}</span>") + end + end + + context 'when issuable is a merge request' do + let_it_be(:issuable) { build(:merge_request) } + + it 'returns icon with tooltip' do + expect(helper.hidden_issuable_icon(issuable)).to eq("<span class=\"has-tooltip\" title=\"This merge request is hidden because its author has been banned\">#{mock_svg}</span>") + end + end + end end diff --git a/spec/helpers/issues_helper_spec.rb b/spec/helpers/issues_helper_spec.rb index ed363268cdf..0024d6b7b4e 100644 --- a/spec/helpers/issues_helper_spec.rb +++ b/spec/helpers/issues_helper_spec.rb @@ -266,7 +266,9 @@ RSpec.describe IssuesHelper do issue_type: 'issue', new_issue_path: new_project_issue_path(project, { add_related_issue: issue.iid }), project_path: project.full_path, - report_abuse_path: new_abuse_report_path(user_id: issue.author.id, ref_url: issue_url(issue)), + report_abuse_path: add_category_abuse_reports_path, + reported_user_id: issue.author.id, + reported_from_url: issue_url(issue), submit_as_spam_path: mark_as_spam_project_issue_path(project, issue) } @@ -389,8 +391,12 @@ RSpec.describe IssuesHelper do allow(helper).to receive(:url_for).and_return('#') expected = { + autocomplete_award_emojis_path: autocomplete_award_emojis_path, calendar_path: '#', - empty_state_svg_path: '#', + dashboard_labels_path: dashboard_labels_path(format: :json, include_ancestor_groups: true), + dashboard_milestones_path: dashboard_milestones_path(format: :json), + empty_state_with_filter_svg_path: '#', + empty_state_without_filter_svg_path: '#', initial_sort: current_user&.user_preference&.issues_sort, is_public_visibility_restricted: Gitlab::CurrentSettings.restricted_visibility_levels ? 'false' : '', is_signed_in: current_user.present?.to_s, @@ -472,43 +478,6 @@ RSpec.describe IssuesHelper do end end - describe '#status_box_class' do - context 'when object is expired' do - it 'returns orange background' do - milestone = build(:milestone, due_date: Date.today.prev_month) - expect(helper.status_box_class(milestone)).to eq('gl-bg-orange-500') - end - end - - context 'when object is merged' do - it 'returns blue background' do - merge_request = build(:merge_request, :merged) - expect(helper.status_box_class(merge_request)).to eq('badge-info') - end - end - - context 'when object is closed' do - it 'returns red background' do - merge_request = build(:merge_request, :closed) - expect(helper.status_box_class(merge_request)).to eq('badge-danger') - end - end - - context 'when object is upcoming' do - it 'returns gray background' do - milestone = build(:milestone, start_date: Date.today.next_month) - expect(helper.status_box_class(milestone)).to eq('gl-bg-gray-500') - end - end - - context 'when object is opened' do - it 'returns green background' do - merge_request = build(:merge_request, :opened) - expect(helper.status_box_class(merge_request)).to eq('badge-success') - end - end - end - describe '#issue_hidden?' do context 'when issue is hidden' do let_it_be(:banned_user) { build(:user, :banned) } diff --git a/spec/helpers/markup_helper_spec.rb b/spec/helpers/markup_helper_spec.rb index d1c86abf6e9..088519248c6 100644 --- a/spec/helpers/markup_helper_spec.rb +++ b/spec/helpers/markup_helper_spec.rb @@ -449,21 +449,21 @@ RSpec.describe MarkupHelper do object = create_object('Text with `inline code`') expected = 'Text with <code>inline code</code>' - expect(first_line_in_markdown(object, attribute, 100, is_todo: true, project: project)).to match(expected) + expect(helper.first_line_in_markdown(object, attribute, 100, is_todo: true, project: project)).to match(expected) end it 'truncates the text with multiple paragraphs' do object = create_object("Paragraph 1\n\nParagraph 2") expected = 'Paragraph 1...' - expect(first_line_in_markdown(object, attribute, 100, is_todo: true, project: project)).to match(expected) + expect(helper.first_line_in_markdown(object, attribute, 100, is_todo: true, project: project)).to match(expected) end it 'displays the first line of a code block' do object = create_object("```\nCode block\nwith two lines\n```") expected = %r{<pre.+><code><span class="line">Code block\.\.\.</span>\n</code></pre>} - expect(first_line_in_markdown(object, attribute, 100, is_todo: true, project: project)).to match(expected) + expect(helper.first_line_in_markdown(object, attribute, 100, is_todo: true, project: project)).to match(expected) end it 'truncates a single long line of text' do @@ -471,7 +471,7 @@ RSpec.describe MarkupHelper do object = create_object(text * 4) expected = (text * 2).sub(/.{3}/, '...') - expect(first_line_in_markdown(object, attribute, 150, is_todo: true, project: project)).to match(expected) + expect(helper.first_line_in_markdown(object, attribute, 150, is_todo: true, project: project)).to match(expected) end it 'preserves code color scheme' do @@ -480,12 +480,12 @@ RSpec.describe MarkupHelper do "<code><span class=\"line\"><span class=\"k\">def</span> <span class=\"nf\">test</span>...</span>\n" \ "</code></pre>\n" - expect(first_line_in_markdown(object, attribute, 150, is_todo: true, project: project)).to eq(expected) + expect(helper.first_line_in_markdown(object, attribute, 150, is_todo: true, project: project)).to eq(expected) end it 'removes any images' do object = create_object("![ImageTest](/uploads/test.png)") - text = first_line_in_markdown(object, attribute, 150, is_todo: true, project: project) + text = helper.first_line_in_markdown(object, attribute, 150, is_todo: true, project: project) expect(text).not_to match('<img') expect(text).not_to match('<a') @@ -498,7 +498,7 @@ RSpec.describe MarkupHelper do create(:label, title: 'label_1', project: project) object = create_object(label_title, project: project) - first_line_in_markdown(object, attribute, 150, is_todo: true, project: project) + helper.first_line_in_markdown(object, attribute, 150, is_todo: true, project: project) end it 'preserves style attribute for a label that can be accessed by current_user' do @@ -522,7 +522,7 @@ RSpec.describe MarkupHelper do html = '<i></i> <strong>strong</strong><em>em</em><b>b</b>' object = create_object(html) - result = first_line_in_markdown(object, attribute, 100, is_todo: true, project: project) + result = helper.first_line_in_markdown(object, attribute, 100, is_todo: true, project: project) expect(result).to include(html) end @@ -531,7 +531,7 @@ RSpec.describe MarkupHelper do object = create_object("hello \n\n [Test](README.md)") expect do - first_line_in_markdown(object, attribute, 100, is_todo: true, project: project) + helper.first_line_in_markdown(object, attribute, 100, is_todo: true, project: project) end.not_to change { Gitlab::GitalyClient.get_request_count } end end diff --git a/spec/helpers/nav_helper_spec.rb b/spec/helpers/nav_helper_spec.rb index 4a37e17fb08..adf784360c2 100644 --- a/spec/helpers/nav_helper_spec.rb +++ b/spec/helpers/nav_helper_spec.rb @@ -134,4 +134,62 @@ RSpec.describe NavHelper do it { is_expected.to eq(true) } end end + + describe '#show_super_sidebar?' do + shared_examples '#show_super_sidebar returns false' do + it 'returns false' do + expect(helper.show_super_sidebar?).to eq(false) + end + end + + it 'returns false by default' do + allow(helper).to receive(:current_user).and_return(nil) + + expect(helper.show_super_sidebar?).to be_falsy + end + + context 'when used is signed-in' do + let_it_be(:user) { create(:user) } + + before do + allow(helper).to receive(:current_user).and_return(user) + stub_feature_flags(super_sidebar_nav: new_nav_ff) + user.update!(use_new_navigation: user_preference) + end + + context 'with feature flag off' do + let(:new_nav_ff) { false } + + context 'when user has new nav disabled' do + let(:user_preference) { false } + + it_behaves_like '#show_super_sidebar returns false' + end + + context 'when user has new nav enabled' do + let(:user_preference) { true } + + it_behaves_like '#show_super_sidebar returns false' + end + end + + context 'with feature flag on' do + let(:new_nav_ff) { true } + + context 'when user has new nav disabled' do + let(:user_preference) { false } + + it_behaves_like '#show_super_sidebar returns false' + end + + context 'when user has new nav enabled' do + let(:user_preference) { true } + + it 'returns true' do + expect(helper.show_super_sidebar?).to eq(true) + end + end + end + end + end end diff --git a/spec/helpers/preferences_helper_spec.rb b/spec/helpers/preferences_helper_spec.rb index 99f750bb858..898999e328e 100644 --- a/spec/helpers/preferences_helper_spec.rb +++ b/spec/helpers/preferences_helper_spec.rb @@ -25,15 +25,15 @@ RSpec.describe PreferencesHelper do it 'provides better option descriptions' do expect(helper.dashboard_choices).to match_array [ - ['Your Projects (default)', 'projects'], - ['Starred Projects', 'stars'], - ["Your Projects' Activity", 'project_activity'], - ["Starred Projects' Activity", 'starred_project_activity'], - ["Followed Users' Activity", 'followed_user_activity'], - ["Your Groups", 'groups'], - ["Your To-Do List", 'todos'], - ["Assigned Issues", 'issues'], - ["Assigned merge requests", 'merge_requests'] + { text: "Your Projects (default)", value: 'projects' }, + { text: "Starred Projects", value: 'stars' }, + { text: "Your Projects' Activity", value: 'project_activity' }, + { text: "Starred Projects' Activity", value: 'starred_project_activity' }, + { text: "Followed Users' Activity", value: 'followed_user_activity' }, + { text: "Your Groups", value: 'groups' }, + { text: "Your To-Do List", value: 'todos' }, + { text: "Assigned Issues", value: 'issues' }, + { text: "Assigned merge requests", value: 'merge_requests' } ] end end @@ -214,9 +214,9 @@ RSpec.describe PreferencesHelper do stub_user(preferred_language: :en) expect(helper.language_choices).to eq([ - '<option selected="selected" value="en">English (100% translated)</option>', - '<option value="es">Spanish - español (65% translated)</option>' - ].join("\n")) + { text: "English (100% translated)", value: 'en' }, + { text: "Spanish - español (65% translated)", value: 'es' } + ]) end end diff --git a/spec/helpers/projects/ml/experiments_helper_spec.rb b/spec/helpers/projects/ml/experiments_helper_spec.rb index e6959a03c4a..2b70201456a 100644 --- a/spec/helpers/projects/ml/experiments_helper_spec.rb +++ b/spec/helpers/projects/ml/experiments_helper_spec.rb @@ -9,7 +9,7 @@ RSpec.describe Projects::Ml::ExperimentsHelper, feature_category: :mlops do let_it_be(:project) { create(:project, :private) } let_it_be(:experiment) { create(:ml_experiments, user_id: project.creator, project: project) } let_it_be(:candidate0) do - create(:ml_candidates, experiment: experiment, user: project.creator).tap do |c| + create(:ml_candidates, :with_artifact, experiment: experiment, user: project.creator).tap do |c| c.params.build([{ name: 'param1', value: 'p1' }, { name: 'param2', value: 'p2' }]) c.metrics.create!( [{ name: 'metric1', value: 0.1 }, { name: 'metric2', value: 0.2 }, { name: 'metric3', value: 0.3 }] @@ -18,7 +18,7 @@ RSpec.describe Projects::Ml::ExperimentsHelper, feature_category: :mlops do end let_it_be(:candidate1) do - create(:ml_candidates, experiment: experiment, user: project.creator).tap do |c| + create(:ml_candidates, experiment: experiment, user: project.creator, name: 'candidate1').tap do |c| c.params.build([{ name: 'param2', value: 'p3' }, { name: 'param3', value: 'p4' }]) c.metrics.create!(name: 'metric3', value: 0.4) end @@ -27,17 +27,39 @@ RSpec.describe Projects::Ml::ExperimentsHelper, feature_category: :mlops do let_it_be(:candidates) { [candidate0, candidate1] } describe '#candidates_table_items' do - subject { helper.candidates_table_items(candidates) } + subject { Gitlab::Json.parse(helper.candidates_table_items(candidates)) } - it 'creates the correct model for the table' do - expected_value = [ + it 'creates the correct model for the table', :aggregate_failures do + expected_values = [ { 'param1' => 'p1', 'param2' => 'p2', 'metric1' => '0.1000', 'metric2' => '0.2000', 'metric3' => '0.3000', - 'artifact' => nil, 'details' => "/#{project.full_path}/-/ml/candidates/#{candidate0.iid}" }, + 'artifact' => "/#{project.full_path}/-/packages/#{candidate0.artifact.id}", + 'details' => "/#{project.full_path}/-/ml/candidates/#{candidate0.iid}", + 'name' => candidate0.name, + 'created_at' => candidate0.created_at.strftime('%Y-%m-%dT%H:%M:%S.%LZ'), + 'user' => { 'username' => candidate0.user.username, 'path' => "/#{candidate0.user.username}" } }, { 'param2' => 'p3', 'param3' => 'p4', 'metric3' => '0.4000', - 'artifact' => nil, 'details' => "/#{project.full_path}/-/ml/candidates/#{candidate1.iid}" } + 'artifact' => nil, 'details' => "/#{project.full_path}/-/ml/candidates/#{candidate1.iid}", + 'name' => candidate1.name, + 'created_at' => candidate1.created_at.strftime('%Y-%m-%dT%H:%M:%S.%LZ'), + 'user' => { 'username' => candidate1.user.username, 'path' => "/#{candidate1.user.username}" } } ] - expect(Gitlab::Json.parse(subject)).to match_array(expected_value) + subject.sort_by! { |s| s[:name] } + + expect(subject[0]).to eq(expected_values[0]) + expect(subject[1]).to eq(expected_values[1]) + end + + context 'when candidate does not have user' do + let(:candidates) { [candidate0] } + + before do + allow(candidate0).to receive(:user).and_return(nil) + end + + it 'has the user property, but is nil' do + expect(subject[0]['user']).to be_nil + end end end @@ -57,9 +79,6 @@ RSpec.describe Projects::Ml::ExperimentsHelper, feature_category: :mlops do describe '#candidate_as_data' do let(:candidate) { candidate0 } - let(:package) do - create(:generic_package, name: candidate.package_name, version: candidate.package_version, project: project) - end subject { Gitlab::Json.parse(helper.candidate_as_data(candidate)) } @@ -81,7 +100,7 @@ RSpec.describe Projects::Ml::ExperimentsHelper, feature_category: :mlops do it 'generates the correct info' do expected_info = { 'iid' => candidate.iid, - 'path_to_artifact' => "/#{project.full_path}/-/packages/#{package.id}", + 'path_to_artifact' => "/#{project.full_path}/-/packages/#{candidate.artifact.id}", 'experiment_name' => candidate.experiment.name, 'path_to_experiment' => "/#{project.full_path}/-/ml/experiments/#{experiment.iid}", 'status' => 'running' diff --git a/spec/helpers/projects/project_members_helper_spec.rb b/spec/helpers/projects/project_members_helper_spec.rb index f3201ce0e14..2cc87e8aeb9 100644 --- a/spec/helpers/projects/project_members_helper_spec.rb +++ b/spec/helpers/projects/project_members_helper_spec.rb @@ -6,7 +6,7 @@ RSpec.describe Projects::ProjectMembersHelper do include MembersPresentation let_it_be(:current_user) { create(:user) } - let_it_be(:project) { create(:project) } + let_it_be(:project) { create(:project, group: create(:group)) } before do allow(helper).to receive(:current_user).and_return(current_user) @@ -42,7 +42,9 @@ RSpec.describe Projects::ProjectMembersHelper do expected = { source_id: project.id, can_manage_members: true, - can_manage_access_requests: true + can_manage_access_requests: true, + group_name: project.group.name, + group_path: project.group.path }.as_json expect(subject).to include(expected) @@ -138,8 +140,8 @@ RSpec.describe Projects::ProjectMembersHelper do where(:include_relations, :result) do [:inherited, :direct] | lazy { [group_link_7, group_link_4, group_link_9, group_link_5, group_link_3].map(&:id) } - [:inherited] | lazy { [group_link_1, group_link_4, group_link_5, group_link_3].map(&:id) } - [:direct] | lazy { [group_link_7, group_link_8, group_link_9].map(&:id) } + [:inherited] | lazy { [group_link_1, group_link_4, group_link_5, group_link_3].map(&:id) } + [:direct] | lazy { [group_link_7, group_link_8, group_link_9].map(&:id) } end with_them do diff --git a/spec/helpers/projects_helper_spec.rb b/spec/helpers/projects_helper_spec.rb index db50c74ec4e..91dd4c46a74 100644 --- a/spec/helpers/projects_helper_spec.rb +++ b/spec/helpers/projects_helper_spec.rb @@ -206,7 +206,7 @@ RSpec.describe ProjectsHelper do it 'loads the pipeline status in batch' do helper.load_pipeline_status([project]) # Skip lazy loading of the `pipeline_status` attribute - pipeline_status = project.instance_variable_get('@pipeline_status') + pipeline_status = project.instance_variable_get(:@pipeline_status) expect(pipeline_status).to be_a(Gitlab::Cache::Ci::ProjectPipelineStatus) end @@ -1086,7 +1086,7 @@ RSpec.describe ProjectsHelper do context 'as a user' do it 'returns a link to contact an administrator' do - allow(user).to receive(:admin?).and_return(false) + allow(user).to receive(:can_admin_all_resources?).and_return(false) expect(subject).to have_text("To enable importing projects from #{import_method}, ask your GitLab administrator to configure OAuth integration") end @@ -1094,7 +1094,7 @@ RSpec.describe ProjectsHelper do context 'as an administrator' do it 'returns a link to configure bitbucket' do - allow(user).to receive(:admin?).and_return(true) + allow(user).to receive(:can_admin_all_resources?).and_return(true) expect(subject).to have_text("To enable importing projects from #{import_method}, as administrator you need to configure OAuth integration") end @@ -1333,27 +1333,6 @@ RSpec.describe ProjectsHelper do end end - describe '#fork_divergence_message' do - using RSpec::Parameterized::TableSyntax - - where(:behind, :ahead, :message) do - 0 | 0 | 'Up to date with upstream repository' - 1 | 0 | '1 commit behind upstream repository' - 2 | 0 | '2 commits behind upstream repository' - 0 | 1 | '1 commit ahead of upstream repository' - 0 | 2 | '2 commits ahead of upstream repository' - 5 | 7 | '5 commits behind, 7 commits ahead of upstream repository' - nil | 7 | 'Fork has diverged from upstream repository' - 7 | nil | 'Fork has diverged from upstream repository' - end - - with_them do - it 'returns message based on behind/ahead values' do - expect(helper.fork_divergence_message({ behind: behind, ahead: ahead })).to eq(message) - end - end - end - describe '#localized_project_human_access' do using RSpec::Parameterized::TableSyntax diff --git a/spec/helpers/search_helper_spec.rb b/spec/helpers/search_helper_spec.rb index 45864320115..c7afe0bf391 100644 --- a/spec/helpers/search_helper_spec.rb +++ b/spec/helpers/search_helper_spec.rb @@ -284,8 +284,24 @@ RSpec.describe SearchHelper, feature_category: :global_search 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) + context 'when admin mode setting is disabled', :do_not_mock_admin_mode_setting do + it 'includes admin sections' do + expect(search_autocomplete_opts('admin').size).to eq(1) + end + end + + context 'when admin mode setting is enabled' do + context 'when in admin mode', :enable_admin_mode do + it 'includes admin sections' do + expect(search_autocomplete_opts('admin').size).to eq(1) + end + end + + context 'when not in admin mode' do + it 'does not include admin sections' do + expect(search_autocomplete_opts('admin').size).to eq(0) + end + end end end end diff --git a/spec/helpers/sidebars_helper_spec.rb b/spec/helpers/sidebars_helper_spec.rb index 6db955f3637..299e4cb0133 100644 --- a/spec/helpers/sidebars_helper_spec.rb +++ b/spec/helpers/sidebars_helper_spec.rb @@ -3,6 +3,8 @@ require 'spec_helper' RSpec.describe SidebarsHelper do + include Devise::Test::ControllerHelpers + describe '#sidebar_tracking_attributes_by_object' do subject { helper.sidebar_tracking_attributes_by_object(object) } @@ -42,4 +44,26 @@ RSpec.describe SidebarsHelper do end end end + + describe '#super_sidebar_context' do + let(:user) { build(:user) } + + subject { helper.super_sidebar_context(user) } + + it 'returns sidebar values from user', :use_clean_rails_memory_store_caching do + Rails.cache.write(['users', user.id, 'assigned_open_issues_count'], 1) + Rails.cache.write(['users', user.id, 'assigned_open_merge_requests_count'], 2) + Rails.cache.write(['users', user.id, 'todos_pending_count'], 3) + + expect(subject).to eq({ + name: user.name, + username: user.username, + avatar_url: user.avatar_url, + assigned_open_issues_count: 1, + assigned_open_merge_requests_count: 2, + todos_pending_count: 3, + issues_dashboard_path: issues_dashboard_path(assignee_username: user.username) + }) + end + end end diff --git a/spec/helpers/timeboxes_helper_spec.rb b/spec/helpers/timeboxes_helper_spec.rb index f9fb40a616b..f1f8683825e 100644 --- a/spec/helpers/timeboxes_helper_spec.rb +++ b/spec/helpers/timeboxes_helper_spec.rb @@ -2,8 +2,16 @@ require 'spec_helper' -RSpec.describe TimeboxesHelper do - describe "#timebox_date_range" do +RSpec.describe TimeboxesHelper, feature_category: :team_planning do + using RSpec::Parameterized::TableSyntax + + let_it_be(:milestone_expired) { build(:milestone, due_date: Date.today.prev_month) } + let_it_be(:milestone_closed) { build(:milestone, :closed) } + let_it_be(:milestone_upcoming) { build(:milestone, start_date: Date.today.next_month) } + let_it_be(:milestone_open) { build(:milestone) } + let_it_be(:milestone_closed_and_expired) { build(:milestone, :closed, due_date: Date.today.prev_month) } + + describe '#timebox_date_range' do let(:yesterday) { Date.yesterday } let(:tomorrow) { yesterday + 2 } let(:format) { '%b %-d, %Y' } @@ -24,11 +32,11 @@ RSpec.describe TimeboxesHelper do end end - describe "#group_milestone_route" do + describe '#group_milestone_route' do let(:group) { build_stubbed(:group) } - let(:subgroup) { build_stubbed(:group, parent: group, name: "Test Subgrp") } + let(:subgroup) { build_stubbed(:group, parent: group, name: 'Test Subgrp') } - context "when in subgroup" do + context 'when in subgroup' do let(:milestone) { build_stubbed(:group_milestone, group: subgroup) } it 'generates correct url despite assigned @group' do @@ -39,22 +47,53 @@ RSpec.describe TimeboxesHelper do end end - describe "#recent_releases_with_counts" do - let_it_be(:milestone) { create(:milestone) } - let_it_be(:project) { milestone.project } + describe '#recent_releases_with_counts' do + let_it_be(:project) { milestone_open.project } let_it_be(:user) { create(:user) } - subject { helper.recent_releases_with_counts(milestone, user) } + subject { helper.recent_releases_with_counts(milestone_open, user) } before do project.add_developer(user) end - it "returns releases with counts" do - _old_releases = create_list(:release, 2, project: project, milestones: [milestone]) - recent_public_releases = create_list(:release, 3, project: project, milestones: [milestone], released_at: '2022-01-01T18:00:00Z') + it 'returns releases with counts' do + _old_releases = create_list(:release, 2, project: project, milestones: [milestone_open]) + recent_public_releases = create_list(:release, 3, project: project, milestones: [milestone_open], released_at: '2022-01-01T18:00:00Z') is_expected.to match([match_array(recent_public_releases), 5, 2]) end end + + describe '#milestone_status_string' do + where(:milestone, :status) do + lazy { milestone_expired } | 'Expired' + lazy { milestone_closed } | 'Closed' + lazy { milestone_closed_and_expired } | 'Closed' + lazy { milestone_upcoming } | 'Upcoming' + lazy { milestone_open } | 'Open' + end + + with_them do + it 'returns status string' do + expect(helper.milestone_status_string(milestone)).to eq(status) + end + end + end + + describe '#milestone_badge_variant' do + where(:milestone, :variant) do + lazy { milestone_expired } | :warning + lazy { milestone_closed } | :danger + lazy { milestone_closed_and_expired } | :danger + lazy { milestone_upcoming } | :neutral + lazy { milestone_open } | :success + end + + with_them do + it 'returns badge variant' do + expect(helper.milestone_badge_variant(milestone)).to eq(variant) + end + end + end end diff --git a/spec/helpers/todos_helper_spec.rb b/spec/helpers/todos_helper_spec.rb index ca334a04fe9..fcdb41eb4af 100644 --- a/spec/helpers/todos_helper_spec.rb +++ b/spec/helpers/todos_helper_spec.rb @@ -43,6 +43,10 @@ RSpec.describe TodosHelper do create(:todo, target: group) end + let_it_be(:project_access_request_todo) do + create(:todo, target: project, action: Todo::MEMBER_ACCESS_REQUESTED) + end + describe '#todos_count_format' do it 'shows fuzzy count for 100 or more items' do expect(helper.todos_count_format(100)).to eq '99+' @@ -172,7 +176,17 @@ RSpec.describe TodosHelper do it 'responds with access requests tab' do path = helper.todo_target_path(group_access_request_todo) - access_request_path = Gitlab::Routing.url_helpers.group_group_members_url(group, tab: 'access_requests') + access_request_path = Gitlab::Routing.url_helpers.group_group_members_path(group, tab: 'access_requests') + + expect(path).to eq(access_request_path) + end + end + + context 'when a user requests access to project' do + it 'responds with access requests tab' do + path = helper.todo_target_path(project_access_request_todo) + + access_request_path = Gitlab::Routing.url_helpers.project_project_members_path(project, tab: 'access_requests') expect(path).to eq(access_request_path) end @@ -374,7 +388,7 @@ RSpec.describe TodosHelper do end context 'member access requested' do - context 'when source is group' do + context 'when target is group' do it 'returns group access message' do group_todo.action = Todo::MEMBER_ACCESS_REQUESTED @@ -383,6 +397,14 @@ RSpec.describe TodosHelper do ) end end + + context 'when target is project' do + it 'returns project access message' do + expect(helper.todo_action_name(project_access_request_todo)).to eq( + format(s_("Todos|has requested access to project %{which}"), which: _(project.name)) + ) + end + end end end diff --git a/spec/helpers/url_helper_spec.rb b/spec/helpers/url_helper_spec.rb new file mode 100644 index 00000000000..7955a41b63a --- /dev/null +++ b/spec/helpers/url_helper_spec.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe UrlHelper, feature_category: :integrations do + describe '#escaped_url' do + it 'escapes url' do + expect(helper.escaped_url('https://example.com?param=test value')).to eq('https://example.com?param=test%20value') + end + + it 'escapes XSS injection' do + expect(helper.escaped_url('https://example.com?injected_here"+eval(1)+"')) + .to eq('https://example.com?injected_here%22+eval(1)+%22') + end + + it 'returns nil if url is nil' do + expect(helper.escaped_url(nil)).to be_nil + end + + it 'returns nil when url is invalid' do + expect(helper.escaped_url('https://?&*^invalid-url')) + .to be_nil + end + end +end diff --git a/spec/helpers/users/callouts_helper_spec.rb b/spec/helpers/users/callouts_helper_spec.rb index 170ae098a2f..a43a73edd53 100644 --- a/spec/helpers/users/callouts_helper_spec.rb +++ b/spec/helpers/users/callouts_helper_spec.rb @@ -92,81 +92,32 @@ RSpec.describe Users::CalloutsHelper do end end - describe '.show_registration_enabled_user_callout?' do + describe '.show_registration_enabled_user_callout?', :do_not_mock_admin_mode_setting do let_it_be(:admin) { create(:user, :admin) } subject { helper.show_registration_enabled_user_callout? } - context 'when on gitlab.com' do - before do - allow(::Gitlab).to receive(:com?).and_return(true) - allow(helper).to receive(:current_user).and_return(admin) - stub_application_setting(signup_enabled: true) - allow(helper).to receive(:user_dismissed?).with(described_class::REGISTRATION_ENABLED_CALLOUT) { false } - allow(helper.controller).to receive(:controller_path).and_return("admin/users") - end - - it { is_expected.to be false } - end - - context 'when `current_user` is not an admin' do - before do - allow(::Gitlab).to receive(:com?).and_return(false) - allow(helper).to receive(:current_user).and_return(user) - stub_application_setting(signup_enabled: true) - allow(helper).to receive(:user_dismissed?).with(described_class::REGISTRATION_ENABLED_CALLOUT) { false } - allow(helper.controller).to receive(:controller_path).and_return("admin/users") - end - - it { is_expected.to be false } - end - - context 'when signup is disabled' do - before do - allow(::Gitlab).to receive(:com?).and_return(false) - allow(helper).to receive(:current_user).and_return(admin) - stub_application_setting(signup_enabled: false) - allow(helper).to receive(:user_dismissed?).with(described_class::REGISTRATION_ENABLED_CALLOUT) { false } - allow(helper.controller).to receive(:controller_path).and_return("admin/users") - end + using RSpec::Parameterized::TableSyntax - it { is_expected.to be false } - end - - context 'when user has dismissed callout' do - before do - allow(::Gitlab).to receive(:com?).and_return(false) - allow(helper).to receive(:current_user).and_return(admin) - stub_application_setting(signup_enabled: true) - allow(helper).to receive(:user_dismissed?).with(described_class::REGISTRATION_ENABLED_CALLOUT) { true } - allow(helper.controller).to receive(:controller_path).and_return("admin/users") - end - - it { is_expected.to be false } + where(:gitlab_com, :current_user, :signup_enabled, :user_dismissed, :controller_path, :expected_result) do + false | ref(:admin) | true | false | 'admin/users' | true + true | ref(:admin) | true | false | 'admin/users' | false + false | ref(:user) | true | false | 'admin/users' | false + false | ref(:admin) | false | false | 'admin/users' | false + false | ref(:admin) | true | true | 'admin/users' | false + false | ref(:admin) | true | false | 'projects/issues' | false end - context 'when controller path is not allowed' do + with_them do before do - allow(::Gitlab).to receive(:com?).and_return(false) - allow(helper).to receive(:current_user).and_return(admin) - stub_application_setting(signup_enabled: true) - allow(helper).to receive(:user_dismissed?).with(described_class::REGISTRATION_ENABLED_CALLOUT) { false } - allow(helper.controller).to receive(:controller_path).and_return("projects/issues") + allow(::Gitlab).to receive(:com?).and_return(gitlab_com) + allow(helper).to receive(:current_user).and_return(current_user) + stub_application_setting(signup_enabled: signup_enabled) + allow(helper).to receive(:user_dismissed?).with(described_class::REGISTRATION_ENABLED_CALLOUT) { user_dismissed } + allow(helper.controller).to receive(:controller_path).and_return(controller_path) end - it { is_expected.to be false } - end - - context 'when not gitlab.com, `current_user` is an admin, signup is enabled, user has not dismissed callout, and controller path is allowed' do - before do - allow(::Gitlab).to receive(:com?).and_return(false) - allow(helper).to receive(:current_user).and_return(admin) - stub_application_setting(signup_enabled: true) - allow(helper).to receive(:user_dismissed?).with(described_class::REGISTRATION_ENABLED_CALLOUT) { false } - allow(helper.controller).to receive(:controller_path).and_return("admin/users") - end - - it { is_expected.to be true } + it { is_expected.to be expected_result } end end @@ -190,7 +141,7 @@ RSpec.describe Users::CalloutsHelper do end end - describe '.show_security_newsletter_user_callout?' do + describe '.show_security_newsletter_user_callout?', :do_not_mock_admin_mode_setting do let_it_be(:admin) { create(:user, :admin) } subject { helper.show_security_newsletter_user_callout? } diff --git a/spec/helpers/version_check_helper_spec.rb b/spec/helpers/version_check_helper_spec.rb index 2bb85e7b6b8..c76eb08820a 100644 --- a/spec/helpers/version_check_helper_spec.rb +++ b/spec/helpers/version_check_helper_spec.rb @@ -49,19 +49,26 @@ RSpec.describe VersionCheckHelper do describe '#show_security_patch_upgrade_alert?' do describe 'return conditions' do - where(:show_version_check, :gitlab_version_check, :result) do + where(:feature_enabled, :show_version_check, :gitlab_version_check, :result) do [ - [false, nil, false], - [false, { "severity" => "success" }, false], - [false, { "severity" => "danger" }, false], - [true, nil, false], - [true, { "severity" => "success" }, false], - [true, { "severity" => "danger" }, true] + [false, false, nil, false], + [false, false, { "severity" => "success" }, false], + [false, false, { "severity" => "danger" }, false], + [false, true, nil, false], + [false, true, { "severity" => "success" }, false], + [false, true, { "severity" => "danger" }, false], + [true, false, nil, false], + [true, false, { "severity" => "success" }, false], + [true, false, { "severity" => "danger" }, false], + [true, true, nil, false], + [true, true, { "severity" => "success" }, false], + [true, true, { "severity" => "danger" }, true] ] end with_them do before do + stub_feature_flags(critical_security_alert: feature_enabled) allow(helper).to receive(:show_version_check?).and_return(show_version_check) allow(helper).to receive(:gitlab_version_check).and_return(gitlab_version_check) end |