diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-05 16:54:15 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-05 16:54:15 +0300 |
commit | be834a25982746ffd85252ff502df42bb88cb9d5 (patch) | |
tree | b4d6a8ba0931e12fac08f05abea33a3b8ec2c8a2 /spec/helpers | |
parent | ee925a3597f27e92f83a50937a64068109675b3d (diff) |
Add latest changes from gitlab-org/gitlab@13-5-stable-eev13.5.0-rc32
Diffstat (limited to 'spec/helpers')
-rw-r--r-- | spec/helpers/analytics/unique_visits_helper_spec.rb | 9 | ||||
-rw-r--r-- | spec/helpers/boards_helper_spec.rb | 5 | ||||
-rw-r--r-- | spec/helpers/clusters_helper_spec.rb | 44 | ||||
-rw-r--r-- | spec/helpers/emails_helper_spec.rb | 112 | ||||
-rw-r--r-- | spec/helpers/feature_flags_helper_spec.rb | 21 | ||||
-rw-r--r-- | spec/helpers/gitlab_routing_helper_spec.rb | 4 | ||||
-rw-r--r-- | spec/helpers/groups/group_members_helper_spec.rb | 15 | ||||
-rw-r--r-- | spec/helpers/issuables_helper_spec.rb | 32 | ||||
-rw-r--r-- | spec/helpers/issues_helper_spec.rb | 21 | ||||
-rw-r--r-- | spec/helpers/projects/incidents_helper_spec.rb | 14 | ||||
-rw-r--r-- | spec/helpers/projects_helper_spec.rb | 114 | ||||
-rw-r--r-- | spec/helpers/search_helper_spec.rb | 29 | ||||
-rw-r--r-- | spec/helpers/tree_helper_spec.rb | 10 | ||||
-rw-r--r-- | spec/helpers/whats_new_helper_spec.rb | 46 |
14 files changed, 335 insertions, 141 deletions
diff --git a/spec/helpers/analytics/unique_visits_helper_spec.rb b/spec/helpers/analytics/unique_visits_helper_spec.rb index ff9769078c4..ff363e81ac7 100644 --- a/spec/helpers/analytics/unique_visits_helper_spec.rb +++ b/spec/helpers/analytics/unique_visits_helper_spec.rb @@ -22,15 +22,6 @@ RSpec.describe Analytics::UniqueVisitsHelper do helper.track_visit(target_id) end - it 'does not track visits if usage ping is disabled' do - sign_in(current_user) - expect(Gitlab::CurrentSettings).to receive(:usage_ping_enabled?).and_return(false) - - expect_any_instance_of(Gitlab::Analytics::UniqueVisits).not_to receive(:track_visit) - - helper.track_visit(target_id) - end - it 'does not track visit if user is not logged in' do expect_any_instance_of(Gitlab::Analytics::UniqueVisits).not_to receive(:track_visit) diff --git a/spec/helpers/boards_helper_spec.rb b/spec/helpers/boards_helper_spec.rb index a805b96a8cc..6bdd6fb6813 100644 --- a/spec/helpers/boards_helper_spec.rb +++ b/spec/helpers/boards_helper_spec.rb @@ -43,6 +43,7 @@ RSpec.describe BoardsHelper do allow(helper).to receive(:current_user) { user } allow(helper).to receive(:can?).with(user, :create_non_backlog_issues, board).and_return(true) + allow(helper).to receive(:can?).with(user, :admin_issue, board).and_return(true) end it 'returns a board_lists_path as lists_endpoint' do @@ -52,6 +53,10 @@ RSpec.describe BoardsHelper do it 'returns board type as parent' do expect(helper.board_data[:parent]).to eq('project') end + + it 'returns can_update for user permissions on the board' do + expect(helper.board_data[:can_update]).to eq('true') + end end describe '#current_board_json' do diff --git a/spec/helpers/clusters_helper_spec.rb b/spec/helpers/clusters_helper_spec.rb index 6164f3b5e8d..6b08b6515cf 100644 --- a/spec/helpers/clusters_helper_spec.rb +++ b/spec/helpers/clusters_helper_spec.rb @@ -59,6 +59,24 @@ RSpec.describe ClustersHelper do end end + describe '#js_cluster_agents_list_data' do + let_it_be(:project) { build(:project, :repository) } + + subject { helper.js_cluster_agents_list_data(project) } + + it 'displays project default branch' do + expect(subject[:default_branch_name]).to eq(project.default_branch) + end + + it 'displays image path' do + expect(subject[:empty_state_image]).to match(%r(/illustrations/logos/clusters_empty|svg)) + end + + it 'displays project path' do + expect(subject[:project_path]).to eq(project.full_path) + end + end + describe '#js_clusters_list_data' do subject { helper.js_clusters_list_data('/path') } @@ -89,32 +107,6 @@ RSpec.describe ClustersHelper do end end - describe '#provider_icon' do - it 'will return GCP logo with gcp argument' do - logo = helper.provider_icon('gcp') - - expect(logo).to match(%r(img alt="Google GKE" data-src="|/illustrations/logos/google_gke|svg)) - end - - it 'will return AWS logo with aws argument' do - logo = helper.provider_icon('aws') - - expect(logo).to match(%r(img alt="Amazon EKS" data-src="|/illustrations/logos/amazon_eks|svg)) - end - - it 'will return default logo with unknown provider' do - logo = helper.provider_icon('unknown') - - expect(logo).to match(%r(img alt="Kubernetes Cluster" data-src="|/illustrations/logos/kubernetes|svg)) - end - - it 'will return default logo when provider is empty' do - logo = helper.provider_icon - - expect(logo).to match(%r(img alt="Kubernetes Cluster" data-src="|/illustrations/logos/kubernetes|svg)) - end - end - describe '#cluster_type_label' do subject { helper.cluster_type_label(cluster_type) } diff --git a/spec/helpers/emails_helper_spec.rb b/spec/helpers/emails_helper_spec.rb index 96ac4015c77..ef8b342a3f6 100644 --- a/spec/helpers/emails_helper_spec.rb +++ b/spec/helpers/emails_helper_spec.rb @@ -361,4 +361,116 @@ RSpec.describe EmailsHelper do end end end + + describe '#change_reviewer_notification_text' do + let(:mary) { build(:user, name: 'Mary') } + let(:john) { build(:user, name: 'John') } + let(:ted) { build(:user, name: 'Ted') } + + context 'to new reviewers only' do + let(:previous_reviewers) { [] } + let(:new_reviewers) { [john] } + + context 'with no html tag' do + let(:expected_output) do + 'Reviewer changed to John' + end + + it 'returns the expected output' do + expect(change_reviewer_notification_text(new_reviewers, previous_reviewers)).to eq(expected_output) + end + end + + context 'with <strong> tag' do + let(:expected_output) do + 'Reviewer changed to <strong>John</strong>' + end + + it 'returns the expected output' do + expect(change_reviewer_notification_text(new_reviewers, previous_reviewers, :strong)).to eq(expected_output) + end + end + end + + context 'from previous reviewers to new reviewers' do + let(:previous_reviewers) { [john, mary] } + let(:new_reviewers) { [ted] } + + context 'with no html tag' do + let(:expected_output) do + 'Reviewer changed from John and Mary to Ted' + end + + it 'returns the expected output' do + expect(change_reviewer_notification_text(new_reviewers, previous_reviewers)).to eq(expected_output) + end + end + + context 'with <strong> tag' do + let(:expected_output) do + 'Reviewer changed from <strong>John and Mary</strong> to <strong>Ted</strong>' + end + + it 'returns the expected output' do + expect(change_reviewer_notification_text(new_reviewers, previous_reviewers, :strong)).to eq(expected_output) + end + end + end + + context 'from previous reviewers to no reviewers' do + let(:previous_reviewers) { [john, mary] } + let(:new_reviewers) { [] } + + context 'with no html tag' do + let(:expected_output) do + 'Reviewer changed from John and Mary to Unassigned' + end + + it 'returns the expected output' do + expect(change_reviewer_notification_text(new_reviewers, previous_reviewers)).to eq(expected_output) + end + end + + context 'with <strong> tag' do + let(:expected_output) do + 'Reviewer changed from <strong>John and Mary</strong> to <strong>Unassigned</strong>' + end + + it 'returns the expected output' do + expect(change_reviewer_notification_text(new_reviewers, previous_reviewers, :strong)).to eq(expected_output) + end + end + end + + context "with a <script> tag in user's name" do + let(:previous_reviewers) { [] } + let(:new_reviewers) { [fishy_user] } + let(:fishy_user) { build(:user, name: "<script>alert('hi')</script>") } + + let(:expected_output) do + 'Reviewer changed to <strong><script>alert('hi')</script></strong>' + end + + it 'escapes the html tag' do + expect(change_reviewer_notification_text(new_reviewers, previous_reviewers, :strong)).to eq(expected_output) + end + end + + context "with url in user's name" do + subject(:email_helper) { Object.new.extend(described_class) } + + let(:previous_reviewers) { [] } + let(:new_reviewers) { [fishy_user] } + let(:fishy_user) { build(:user, name: "example.com") } + + let(:expected_output) do + 'Reviewer changed to example_com' + end + + it "sanitizes user's name" do + expect(email_helper).to receive(:sanitize_name).and_call_original + expect(email_helper.change_reviewer_notification_text(new_reviewers, previous_reviewers)).to eq(expected_output) + end + end + end end diff --git a/spec/helpers/feature_flags_helper_spec.rb b/spec/helpers/feature_flags_helper_spec.rb new file mode 100644 index 00000000000..9a080736595 --- /dev/null +++ b/spec/helpers/feature_flags_helper_spec.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe FeatureFlagsHelper do + let_it_be(:project) { create(:project) } + let_it_be(:feature_flag) { create(:operations_feature_flag, project: project) } + let_it_be(:user) { create(:user) } + + describe '#unleash_api_url' do + subject { helper.unleash_api_url(project) } + + it { is_expected.to end_with("/api/v4/feature_flags/unleash/#{project.id}") } + end + + describe '#unleash_api_instance_id' do + subject { helper.unleash_api_instance_id(project) } + + it { is_expected.not_to be_empty } + end +end diff --git a/spec/helpers/gitlab_routing_helper_spec.rb b/spec/helpers/gitlab_routing_helper_spec.rb index 1ad7c7bb9ff..0088f739879 100644 --- a/spec/helpers/gitlab_routing_helper_spec.rb +++ b/spec/helpers/gitlab_routing_helper_spec.rb @@ -187,7 +187,7 @@ RSpec.describe GitlabRoutingHelper do let(:ref) { 'test-ref' } let(:args) { {} } - subject { gitlab_raw_snippet_blob_path(snippet, blob.path, ref, args) } + subject { gitlab_raw_snippet_blob_path(snippet, blob.path, ref, **args) } it_behaves_like 'snippet blob raw path' @@ -222,7 +222,7 @@ RSpec.describe GitlabRoutingHelper do let(:ref) { 'snippet-test-ref' } let(:args) { {} } - subject { gitlab_raw_snippet_blob_url(snippet, blob.path, ref, args) } + subject { gitlab_raw_snippet_blob_url(snippet, blob.path, ref, **args) } it_behaves_like 'snippet blob raw url' diff --git a/spec/helpers/groups/group_members_helper_spec.rb b/spec/helpers/groups/group_members_helper_spec.rb index a25bf1c4157..abf621aee10 100644 --- a/spec/helpers/groups/group_members_helper_spec.rb +++ b/spec/helpers/groups/group_members_helper_spec.rb @@ -5,6 +5,8 @@ require "spec_helper" RSpec.describe Groups::GroupMembersHelper do include MembersPresentation + let_it_be(:current_user) { create(:user) } + describe '.group_member_select_options' do let(:group) { create(:group) } @@ -20,6 +22,10 @@ RSpec.describe Groups::GroupMembersHelper do describe '#linked_groups_data_json' do include_context 'group_group_link' + before do + allow(helper).to receive(:current_user).and_return(current_user) + end + it 'matches json schema' do json = helper.linked_groups_data_json(shared_group.shared_with_group_links) @@ -28,7 +34,6 @@ RSpec.describe Groups::GroupMembersHelper do end describe '#members_data_json' do - let(:current_user) { create(:user) } let(:group) { create(:group) } before do @@ -48,6 +53,14 @@ RSpec.describe Groups::GroupMembersHelper do let(:group_member) { create(:group_member, group: group, created_by: current_user) } it_behaves_like 'group_members.json' + + context 'with user status set' do + let(:user) { create(:user) } + let!(:status) { create(:user_status, user: user) } + let(:group_member) { create(:group_member, group: group, user: user, created_by: current_user) } + + it_behaves_like 'group_members.json' + end end context 'for an invited group member' do diff --git a/spec/helpers/issuables_helper_spec.rb b/spec/helpers/issuables_helper_spec.rb index 89a2a92ea57..821440db551 100644 --- a/spec/helpers/issuables_helper_spec.rb +++ b/spec/helpers/issuables_helper_spec.rb @@ -306,6 +306,38 @@ RSpec.describe IssuablesHelper do end end + describe '#reviewer_sidebar_data' do + let(:user) { create(:user) } + + subject { helper.reviewer_sidebar_data(user, merge_request: merge_request) } + + context 'without merge_request' do + let(:merge_request) { nil } + + it 'returns hash of reviewer data' do + is_expected.to eql({ + avatar_url: user.avatar_url, + name: user.name, + username: user.username + }) + end + end + + context 'with merge_request' do + let(:merge_request) { build(:merge_request) } + + where(can_merge: [true, false]) + + with_them do + before do + allow(merge_request).to receive(:can_be_merged_by?).and_return(can_merge) + end + + it { is_expected.to include({ can_merge: can_merge })} + end + end + end + describe '#issuable_squash_option?' do using RSpec::Parameterized::TableSyntax diff --git a/spec/helpers/issues_helper_spec.rb b/spec/helpers/issues_helper_spec.rb index 3f84eeb12c2..1ed61bd3144 100644 --- a/spec/helpers/issues_helper_spec.rb +++ b/spec/helpers/issues_helper_spec.rb @@ -233,4 +233,25 @@ RSpec.describe IssuesHelper do expect(helper.show_moved_service_desk_issue_warning?(new_issue)).to be(false) end end + + describe '#use_startup_call' do + it "returns false when a query param is present" do + allow(controller.request).to receive(:query_parameters).and_return({ foo: 'bar' }) + + expect(helper.use_startup_call?).to eq(false) + end + + it "returns false when user has stored sort preference" do + controller.instance_variable_set(:@sort, 'updated_asc') + + expect(helper.use_startup_call?).to eq(false) + end + + it 'returns true when request.query_parameters is empty with default sorting preference' do + controller.instance_variable_set(:@sort, 'created_date') + allow(controller.request).to receive(:query_parameters).and_return({}) + + expect(helper.use_startup_call?).to eq(true) + end + end end diff --git a/spec/helpers/projects/incidents_helper_spec.rb b/spec/helpers/projects/incidents_helper_spec.rb index 0affa67a902..68a5ce4eb91 100644 --- a/spec/helpers/projects/incidents_helper_spec.rb +++ b/spec/helpers/projects/incidents_helper_spec.rb @@ -9,9 +9,16 @@ RSpec.describe Projects::IncidentsHelper do let(:project_path) { project.full_path } let(:new_issue_path) { new_project_issue_path(project) } let(:issue_path) { project_issues_path(project) } + let(:params) do + { + search: 'search text', + author_username: 'root', + assignee_username: 'max.power' + } + end describe '#incidents_data' do - subject(:data) { helper.incidents_data(project) } + subject(:data) { helper.incidents_data(project, params) } it 'returns frontend configuration' do expect(data).to match( @@ -20,7 +27,10 @@ RSpec.describe Projects::IncidentsHelper do 'incident-template-name' => 'incident', 'incident-type' => 'incident', 'issue-path' => issue_path, - 'empty-list-svg-path' => match_asset_path('/assets/illustrations/incident-empty-state.svg') + 'empty-list-svg-path' => match_asset_path('/assets/illustrations/incident-empty-state.svg'), + 'text-query': 'search text', + 'author-usernames-query': 'root', + 'assignee-usernames-query': 'max.power' ) end end diff --git a/spec/helpers/projects_helper_spec.rb b/spec/helpers/projects_helper_spec.rb index 2b345ff3ae6..f081cf225b1 100644 --- a/spec/helpers/projects_helper_spec.rb +++ b/spec/helpers/projects_helper_spec.rb @@ -5,16 +5,15 @@ require 'spec_helper' RSpec.describe ProjectsHelper do include ProjectForksHelper - let_it_be(:project) { create(:project) } + let_it_be_with_reload(:project) { create(:project) } + let_it_be_with_refind(:project_with_repo) { create(:project, :repository) } let_it_be(:user) { create(:user) } - describe '#project_incident_management_setting' do - let(:project) { create(:project) } - - before do - helper.instance_variable_set(:@project, project) - end + before do + helper.instance_variable_set(:@project, project) + end + describe '#project_incident_management_setting' do context 'when incident_management_setting exists' do let(:project_incident_management_setting) do create(:project_incident_management_setting, project: project) @@ -40,20 +39,14 @@ RSpec.describe ProjectsHelper do end describe '#error_tracking_setting_project_json' do - let(:project) { create(:project) } - context 'error tracking setting does not exist' do - before do - helper.instance_variable_set(:@project, project) - end - it 'returns nil' do expect(helper.error_tracking_setting_project_json).to be_nil end end context 'error tracking setting exists' do - let!(:error_tracking_setting) { create(:project_error_tracking_setting, project: project) } + let_it_be(:error_tracking_setting) { create(:project_error_tracking_setting, project: project) } context 'api_url present' do let(:json) do @@ -65,24 +58,16 @@ RSpec.describe ProjectsHelper do }.to_json end - before do - helper.instance_variable_set(:@project, project) - end - it 'returns error tracking json' do expect(helper.error_tracking_setting_project_json).to eq(json) end end context 'api_url not present' do - before do + it 'returns nil' do project.error_tracking_setting.api_url = nil project.error_tracking_setting.enabled = false - helper.instance_variable_set(:@project, project) - end - - it 'returns nil' do expect(helper.error_tracking_setting_project_json).to be_nil end end @@ -98,8 +83,7 @@ RSpec.describe ProjectsHelper do end describe "can_change_visibility_level?" do - let(:project) { create(:project) } - let(:user) { create(:project_member, :reporter, user: create(:user), project: project).user } + let_it_be(:user) { create(:project_member, :reporter, user: create(:user), project: project).user } let(:forked_project) { fork_project(project, user) } it "returns false if there are no appropriate permissions" do @@ -142,8 +126,7 @@ RSpec.describe ProjectsHelper do end describe '#can_disable_emails?' do - let(:project) { create(:project) } - let(:user) { create(:project_member, :maintainer, user: create(:user), project: project).user } + let_it_be(:user) { create(:project_member, :maintainer, user: create(:user), project: project).user } it 'returns true for the project owner' do allow(helper).to receive(:can?).with(project.owner, :set_emails_disabled, project) { true } @@ -166,11 +149,7 @@ RSpec.describe ProjectsHelper do end describe "readme_cache_key" do - let(:project) { create(:project, :repository) } - - before do - helper.instance_variable_set(:@project, project) - end + let(:project) { project_with_repo } it "returns a valid cach key" do expect(helper.send(:readme_cache_key)).to eq("#{project.full_path}-#{project.commit.id}-readme") @@ -184,8 +163,7 @@ RSpec.describe ProjectsHelper do end describe "#project_list_cache_key", :clean_gitlab_redis_shared_state do - let(:project) { create(:project, :repository) } - let(:user) { create(:user) } + let(:project) { project_with_repo } before do allow(helper).to receive(:current_user).and_return(user) @@ -249,8 +227,6 @@ RSpec.describe ProjectsHelper do describe '#load_pipeline_status' do it 'loads the pipeline status in batch' do - project = build(:project) - helper.load_pipeline_status([project]) # Skip lazy loading of the `pipeline_status` attribute pipeline_status = project.instance_variable_get('@pipeline_status') @@ -260,8 +236,6 @@ RSpec.describe ProjectsHelper do end describe '#show_no_ssh_key_message?' do - let(:user) { create(:user) } - before do allow(helper).to receive(:current_user).and_return(user) end @@ -282,8 +256,6 @@ RSpec.describe ProjectsHelper do end describe '#show_no_password_message?' do - let(:user) { create(:user) } - before do allow(helper).to receive(:current_user).and_return(user) end @@ -424,7 +396,6 @@ RSpec.describe ProjectsHelper do before do allow(helper).to receive(:current_user).and_return(user) - helper.instance_variable_set(:@project, project) end context 'when there is no current_user' do @@ -444,9 +415,6 @@ RSpec.describe ProjectsHelper do end describe '#get_project_nav_tabs' do - let_it_be(:user) { create(:user) } - let(:project) { create(:project) } - before do allow(helper).to receive(:can?) { true } end @@ -524,7 +492,14 @@ RSpec.describe ProjectsHelper do subject { helper.send(:can_view_operations_tab?, user, project) } - [:read_environment, :read_cluster, :metrics_dashboard].each do |ability| + [ + :metrics_dashboard, + :read_alert_management_alert, + :read_environment, + :read_issue, + :read_sentry_issue, + :read_cluster + ].each do |ability| it 'includes operations tab' do allow(helper).to receive(:can?).and_return(false) allow(helper).to receive(:can?).with(user, ability, project).and_return(true) @@ -536,7 +511,6 @@ RSpec.describe ProjectsHelper do describe '#show_projects' do let(:projects) do - create(:project) Project.all end @@ -561,8 +535,8 @@ RSpec.describe ProjectsHelper do end end - describe('#push_to_create_project_command') do - let(:user) { create(:user, username: 'john') } + describe '#push_to_create_project_command' do + let(:user) { build_stubbed(:user, username: 'john') } it 'returns the command to push to create project over HTTP' do allow(Gitlab::CurrentSettings.current_application_settings).to receive(:enabled_git_access_protocol) { 'http' } @@ -578,8 +552,6 @@ RSpec.describe ProjectsHelper do end describe '#any_projects?' do - let!(:project) { create(:project) } - it 'returns true when projects will be returned' do expect(helper.any_projects?(Project.all)).to eq(true) end @@ -609,7 +581,7 @@ RSpec.describe ProjectsHelper do end describe '#git_user_name' do - let(:user) { double(:user, name: 'John "A" Doe53') } + let(:user) { build_stubbed(:user, name: 'John "A" Doe53') } before do allow(helper).to receive(:current_user).and_return(user) @@ -632,8 +604,6 @@ RSpec.describe ProjectsHelper do end context 'user logged in' do - let(:user) { create(:user) } - before do allow(helper).to receive(:current_user).and_return(user) end @@ -658,7 +628,6 @@ RSpec.describe ProjectsHelper do end describe 'show_xcode_link' do - let!(:project) { create(:project) } let(:mac_ua) { 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36' } let(:ios_ua) { 'Mozilla/5.0 (iPad; CPU OS 5_1_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9B206 Safari/7534.48.3' } @@ -799,7 +768,7 @@ RSpec.describe ProjectsHelper do describe '#show_auto_devops_implicitly_enabled_banner?' do using RSpec::Parameterized::TableSyntax - let(:user) { create(:user) } + let_it_be_with_reload(:project_with_auto_devops) { create(:project, :repository, :auto_devops) } let(:feature_visibilities) do { @@ -873,9 +842,9 @@ RSpec.describe ProjectsHelper do with_them do let(:project) do if project_setting.nil? - create(:project, :repository) + project_with_repo else - create(:project, :repository, :auto_devops) + project_with_auto_devops end end @@ -896,14 +865,8 @@ RSpec.describe ProjectsHelper do end describe '#can_import_members?' do - let(:project) { create(:project) } - let(:user) { create(:user) } let(:owner) { project.owner } - before do - helper.instance_variable_set(:@project, project) - end - it 'returns false if user cannot admin_project_member' do allow(helper).to receive(:current_user) { user } expect(helper.can_import_members?).to eq false @@ -916,12 +879,6 @@ RSpec.describe ProjectsHelper do end describe '#metrics_external_dashboard_url' do - let(:project) { create(:project) } - - before do - helper.instance_variable_set(:@project, project) - end - context 'metrics_setting exists' do it 'returns external_dashboard_url' do metrics_setting = create(:project_metrics_setting, project: project) @@ -938,12 +895,6 @@ RSpec.describe ProjectsHelper do end describe '#grafana_integration_url' do - let(:project) { create(:project) } - - before do - helper.instance_variable_set(:@project, project) - end - subject { helper.grafana_integration_url } it { is_expected.to eq(nil) } @@ -956,12 +907,6 @@ RSpec.describe ProjectsHelper do end describe '#grafana_integration_token' do - let(:project) { create(:project) } - - before do - helper.instance_variable_set(:@project, project) - end - subject { helper.grafana_integration_masked_token } it { is_expected.to eq(nil) } @@ -974,12 +919,6 @@ RSpec.describe ProjectsHelper do end describe '#grafana_integration_enabled?' do - let(:project) { create(:project) } - - before do - helper.instance_variable_set(:@project, project) - end - subject { helper.grafana_integration_enabled? } it { is_expected.to eq(nil) } @@ -992,7 +931,6 @@ RSpec.describe ProjectsHelper do end describe '#project_license_name(project)', :request_store do - let_it_be(:project) { create(:project) } let_it_be(:repository) { project.repository } subject { project_license_name(project) } diff --git a/spec/helpers/search_helper_spec.rb b/spec/helpers/search_helper_spec.rb index 594c5c11994..341606635c0 100644 --- a/spec/helpers/search_helper_spec.rb +++ b/spec/helpers/search_helper_spec.rb @@ -357,14 +357,6 @@ RSpec.describe SearchHelper do describe '#show_user_search_tab?' do subject { show_user_search_tab? } - context 'when users_search feature is disabled' do - before do - stub_feature_flags(users_search: false) - end - - it { is_expected.to eq(false) } - end - context 'when project search' do before do @project = :some_project @@ -399,4 +391,25 @@ RSpec.describe SearchHelper do end end end + + describe '#repository_ref' do + let_it_be(:project) { create(:project, :repository) } + let(:params) { { repository_ref: 'the-repository-ref-param' } } + + subject { repository_ref(project) } + + it { is_expected.to eq('the-repository-ref-param') } + + context 'when the param :repository_ref is not set' do + let(:params) { { repository_ref: nil } } + + it { is_expected.to eq(project.default_branch) } + end + + context 'when the repository_ref param is a number' do + let(:params) { { repository_ref: 111111 } } + + it { is_expected.to eq('111111') } + end + end end diff --git a/spec/helpers/tree_helper_spec.rb b/spec/helpers/tree_helper_spec.rb index 97b6802dde9..d347d8e6bfa 100644 --- a/spec/helpers/tree_helper_spec.rb +++ b/spec/helpers/tree_helper_spec.rb @@ -178,7 +178,7 @@ RSpec.describe TreeHelper do it 'returns a list of attributes related to the project' do expect(subject).to include( - ide_base_path: project.full_path, + web_ide_url_data: { path: project.full_path, is_fork: false }, needs_to_fork: false, show_web_ide_button: true, show_gitpod_button: false, @@ -200,9 +200,9 @@ RSpec.describe TreeHelper do allow(helper).to receive(:current_user).and_return(user) end - it 'includes ide_base_path: forked_project.full_path' do + it 'includes web_ide_url_data: forked_project.full_path' do expect(subject).to include( - ide_base_path: forked_project.full_path + web_ide_url_data: { path: forked_project.full_path, is_fork: true } ) end end @@ -216,9 +216,9 @@ RSpec.describe TreeHelper do allow(helper).to receive(:current_user).and_return(user) end - it 'includes ide_base_path: project.full_path' do + it 'includes web_ide_url_data: project.full_path' do expect(subject).to include( - ide_base_path: project.full_path + web_ide_url_data: { path: project.full_path, is_fork: false } ) end end diff --git a/spec/helpers/whats_new_helper_spec.rb b/spec/helpers/whats_new_helper_spec.rb index db880163454..7d8fb236b1e 100644 --- a/spec/helpers/whats_new_helper_spec.rb +++ b/spec/helpers/whats_new_helper_spec.rb @@ -3,6 +3,52 @@ require 'spec_helper' RSpec.describe WhatsNewHelper do + describe '#whats_new_storage_key' do + subject { helper.whats_new_storage_key } + + before do + allow(helper).to receive(:whats_new_most_recent_release_items).and_return(json) + end + + context 'when recent release items exist' do + let(:json) { [{ release: 84.0 }].to_json } + + it { is_expected.to eq('display-whats-new-notification-84.0') } + + context 'when the release items are missing the release key' do + let(:json) { [{ title: 'bells!' }].to_json } + + it { is_expected.to eq('display-whats-new-notification') } + end + end + + context 'when recent release items do NOT exist' do + let(:json) { WhatsNewHelper::EMPTY_JSON } + + it { is_expected.to be_nil } + end + end + + describe '#whats_new_most_recent_release_items_count' do + subject { helper.whats_new_most_recent_release_items_count } + + before do + allow(helper).to receive(:whats_new_most_recent_release_items).and_return(json) + end + + context 'when recent release items exist' do + let(:json) { [:bells, :and, :whistles].to_json } + + it { is_expected.to eq(3) } + end + + context 'when recent release items do NOT exist' do + let(:json) { WhatsNewHelper::EMPTY_JSON } + + it { is_expected.to be_nil } + end + end + describe '#whats_new_most_recent_release_items' do let(:fixture_dir_glob) { Dir.glob(File.join('spec', 'fixtures', 'whats_new', '*.yml')) } |