diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-03-18 23:02:30 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-03-18 23:02:30 +0300 |
commit | 41fe97390ceddf945f3d967b8fdb3de4c66b7dea (patch) | |
tree | 9c8d89a8624828992f06d892cd2f43818ff5dcc8 /spec/presenters | |
parent | 0804d2dc31052fb45a1efecedc8e06ce9bc32862 (diff) |
Add latest changes from gitlab-org/gitlab@14-9-stable-eev14.9.0-rc42
Diffstat (limited to 'spec/presenters')
-rw-r--r-- | spec/presenters/blob_presenter_spec.rb | 46 | ||||
-rw-r--r-- | spec/presenters/blobs/notebook_presenter_spec.rb | 21 | ||||
-rw-r--r-- | spec/presenters/ci/build_runner_presenter_spec.rb | 18 | ||||
-rw-r--r-- | spec/presenters/group_clusterable_presenter_spec.rb | 6 | ||||
-rw-r--r-- | spec/presenters/instance_clusterable_presenter_spec.rb | 6 | ||||
-rw-r--r-- | spec/presenters/merge_request_presenter_spec.rb | 34 | ||||
-rw-r--r-- | spec/presenters/project_clusterable_presenter_spec.rb | 6 | ||||
-rw-r--r-- | spec/presenters/project_presenter_spec.rb | 6 | ||||
-rw-r--r-- | spec/presenters/projects/security/configuration_presenter_spec.rb | 2 | ||||
-rw-r--r-- | spec/presenters/search_service_presenter_spec.rb | 22 | ||||
-rw-r--r-- | spec/presenters/user_presenter_spec.rb | 65 |
11 files changed, 195 insertions, 37 deletions
diff --git a/spec/presenters/blob_presenter_spec.rb b/spec/presenters/blob_presenter_spec.rb index 225386d9596..80e08db6099 100644 --- a/spec/presenters/blob_presenter_spec.rb +++ b/spec/presenters/blob_presenter_spec.rb @@ -28,7 +28,7 @@ RSpec.describe BlobPresenter do end describe '#replace_path' do - it { expect(presenter.replace_path).to eq("/#{project.full_path}/-/create/#{blob.commit_id}/#{blob.path}") } + it { expect(presenter.replace_path).to eq("/#{project.full_path}/-/update/#{blob.commit_id}/#{blob.path}") } end describe '#can_current_user_push_to_branch' do @@ -71,6 +71,40 @@ RSpec.describe BlobPresenter do end end + context 'Gitpod' do + let(:gitpod_url) { "https://gitpod.io" } + let(:gitpod_application_enabled) { true } + let(:gitpod_user_enabled) { true } + + before do + allow(user).to receive(:gitpod_enabled).and_return(gitpod_user_enabled) + allow(Gitlab::CurrentSettings).to receive(:gitpod_enabled).and_return(gitpod_application_enabled) + allow(Gitlab::CurrentSettings).to receive(:gitpod_url).and_return(gitpod_url) + end + + context 'Gitpod enabled for application and user' do + describe '#gitpod_blob_url' do + it { expect(presenter.gitpod_blob_url).to eq("#{gitpod_url}##{"http://localhost/#{project.full_path}/-/tree/#{blob.commit_id}/#{blob.path}"}") } + end + end + + context 'Gitpod disabled at application level' do + let(:gitpod_application_enabled) { false } + + describe '#gitpod_blob_url' do + it { expect(presenter.gitpod_blob_url).to eq(nil) } + end + end + + context 'Gitpod disabled at user level' do + let(:gitpod_user_enabled) { false } + + describe '#gitpod_blob_url' do + it { expect(presenter.gitpod_blob_url).to eq(nil) } + end + end + end + describe '#find_file_path' do it { expect(presenter.find_file_path).to eq("/#{project.full_path}/-/find_file/HEAD/files/ruby/regex.rb") } end @@ -154,6 +188,16 @@ RSpec.describe BlobPresenter do end end + describe '#code_navigation_path' do + let(:code_navigation_path) { Gitlab::CodeNavigationPath.new(project, blob.commit_id).full_json_path_for(blob.path) } + + it { expect(presenter.code_navigation_path).to eq(code_navigation_path) } + end + + describe '#project_blob_path_root' do + it { expect(presenter.project_blob_path_root).to eq("/#{project.full_path}/-/blob/HEAD") } + end + context 'given a Gitlab::Graphql::Representation::TreeEntry' do let(:blob) { Gitlab::Graphql::Representation::TreeEntry.new(super(), repository) } diff --git a/spec/presenters/blobs/notebook_presenter_spec.rb b/spec/presenters/blobs/notebook_presenter_spec.rb new file mode 100644 index 00000000000..12f4ed67897 --- /dev/null +++ b/spec/presenters/blobs/notebook_presenter_spec.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Blobs::NotebookPresenter do + include RepoHelpers + + let(:project) { create(:project, :repository) } + let(:repository) { project.repository } + let(:blob) { repository.blob_at('HEAD', 'files/ruby/regex.rb') } + let(:user) { project.first_owner } + let(:git_blob) { blob.__getobj__ } + + subject(:presenter) { described_class.new(blob, current_user: user) } + + it 'highlight receives markdown' do + expect(Gitlab::Highlight).to receive(:highlight).with('files/ruby/regex.rb', git_blob.data, plain: nil, language: 'md') + + presenter.highlight + end +end diff --git a/spec/presenters/ci/build_runner_presenter_spec.rb b/spec/presenters/ci/build_runner_presenter_spec.rb index b8d0b093a24..d25102532a7 100644 --- a/spec/presenters/ci/build_runner_presenter_spec.rb +++ b/spec/presenters/ci/build_runner_presenter_spec.rb @@ -173,11 +173,7 @@ RSpec.describe Ci::BuildRunnerPresenter do it 'returns the correct refspecs' do is_expected.to contain_exactly("+refs/heads/#{build.ref}:refs/remotes/origin/#{build.ref}", - "+#{pipeline.sha}:refs/pipelines/#{pipeline.id}") - end - - it 'uses a SHA in the persistent refspec' do - expect(subject[0]).to match(%r{^\+[0-9a-f]{40}:refs/pipelines/[0-9]+$}) + "+refs/pipelines/#{pipeline.id}:refs/pipelines/#{pipeline.id}") end context 'when ref is tag' do @@ -185,7 +181,7 @@ RSpec.describe Ci::BuildRunnerPresenter do it 'returns the correct refspecs' do is_expected.to contain_exactly("+refs/tags/#{build.ref}:refs/tags/#{build.ref}", - "+#{pipeline.sha}:refs/pipelines/#{pipeline.id}") + "+refs/pipelines/#{pipeline.id}:refs/pipelines/#{pipeline.id}") end context 'when GIT_DEPTH is zero' do @@ -196,7 +192,7 @@ RSpec.describe Ci::BuildRunnerPresenter do it 'returns the correct refspecs' do is_expected.to contain_exactly('+refs/tags/*:refs/tags/*', '+refs/heads/*:refs/remotes/origin/*', - "+#{pipeline.sha}:refs/pipelines/#{pipeline.id}") + "+refs/pipelines/#{pipeline.id}:refs/pipelines/#{pipeline.id}") end end end @@ -212,7 +208,7 @@ RSpec.describe Ci::BuildRunnerPresenter do it 'returns the correct refspecs' do is_expected - .to contain_exactly("+#{pipeline.sha}:refs/pipelines/#{pipeline.id}") + .to contain_exactly("+refs/pipelines/#{pipeline.id}:refs/pipelines/#{pipeline.id}") end context 'when GIT_DEPTH is zero' do @@ -222,7 +218,7 @@ RSpec.describe Ci::BuildRunnerPresenter do it 'returns the correct refspecs' do is_expected - .to contain_exactly("+#{pipeline.sha}:refs/pipelines/#{pipeline.id}", + .to contain_exactly("+refs/pipelines/#{pipeline.id}:refs/pipelines/#{pipeline.id}", '+refs/heads/*:refs/remotes/origin/*', '+refs/tags/*:refs/tags/*') end @@ -232,7 +228,7 @@ RSpec.describe Ci::BuildRunnerPresenter do let(:merge_request) { create(:merge_request, :with_legacy_detached_merge_request_pipeline) } it 'returns the correct refspecs' do - is_expected.to contain_exactly("+#{pipeline.sha}:refs/pipelines/#{pipeline.id}", + is_expected.to contain_exactly("+refs/pipelines/#{pipeline.id}:refs/pipelines/#{pipeline.id}", "+refs/heads/#{build.ref}:refs/remotes/origin/#{build.ref}") end end @@ -250,7 +246,7 @@ RSpec.describe Ci::BuildRunnerPresenter do it 'exposes the persistent pipeline ref' do is_expected - .to contain_exactly("+#{pipeline.sha}:refs/pipelines/#{pipeline.id}", + .to contain_exactly("+refs/pipelines/#{pipeline.id}:refs/pipelines/#{pipeline.id}", "+refs/heads/#{build.ref}:refs/remotes/origin/#{build.ref}") end end diff --git a/spec/presenters/group_clusterable_presenter_spec.rb b/spec/presenters/group_clusterable_presenter_spec.rb index b2dff2e3546..f6389ba723e 100644 --- a/spec/presenters/group_clusterable_presenter_spec.rb +++ b/spec/presenters/group_clusterable_presenter_spec.rb @@ -43,6 +43,12 @@ RSpec.describe GroupClusterablePresenter do it { is_expected.to eq(new_group_cluster_path(group)) } end + describe '#connect_path' do + subject { presenter.connect_path } + + it { is_expected.to eq(connect_group_clusters_path(group)) } + end + describe '#authorize_aws_role_path' do subject { presenter.authorize_aws_role_path } diff --git a/spec/presenters/instance_clusterable_presenter_spec.rb b/spec/presenters/instance_clusterable_presenter_spec.rb index 0ace57bbf4d..3e871bf7ba5 100644 --- a/spec/presenters/instance_clusterable_presenter_spec.rb +++ b/spec/presenters/instance_clusterable_presenter_spec.rb @@ -15,6 +15,12 @@ RSpec.describe InstanceClusterablePresenter do it { is_expected.to eq(create_aws_admin_clusters_path) } end + describe '#connect_path' do + subject { described_class.new(instance).connect_path } + + it { is_expected.to eq(connect_admin_clusters_path) } + end + describe '#authorize_aws_role_path' do subject { described_class.new(instance).authorize_aws_role_path } diff --git a/spec/presenters/merge_request_presenter_spec.rb b/spec/presenters/merge_request_presenter_spec.rb index 60296cca058..dbf5af095cb 100644 --- a/spec/presenters/merge_request_presenter_spec.rb +++ b/spec/presenters/merge_request_presenter_spec.rb @@ -162,10 +162,19 @@ RSpec.describe MergeRequestPresenter do end end - describe '#assign_to_closing_issues_link' do + describe '#assign_to_closing_issues_path' do subject do described_class.new(resource, current_user: user) - .assign_to_closing_issues_link + .assign_to_closing_issues_path + end + + it { is_expected.to match("#{project.full_path}/-/merge_requests/#{resource.iid}/assign_related_issues") } + end + + describe '#assign_to_closing_issues_count' do + subject do + described_class.new(resource, current_user: user) + .assign_to_closing_issues_count end before do @@ -178,33 +187,28 @@ RSpec.describe MergeRequestPresenter do let(:issue) { create(:issue) } let(:assignable_issues) { [issue] } - it 'returns correct link with correct text' do + it 'returns correct count' do is_expected - .to match("#{project.full_path}/-/merge_requests/#{resource.iid}/assign_related_issues") - - is_expected - .to match("Assign yourself to this issue") + .to match(1) end end context 'multiple closing issues' do - let(:issues) { create_list(:issue, 2) } + let(:issues) { build_list(:issue, 2) } let(:assignable_issues) { issues } - it 'returns correct link with correct text' do - is_expected - .to match("#{project.full_path}/-/merge_requests/#{resource.iid}/assign_related_issues") - + it 'returns correct count' do is_expected - .to match("Assign yourself to these issues") + .to match(2) end end context 'no closing issue' do let(:assignable_issues) { [] } - it 'returns correct link with correct text' do - is_expected.to be_nil + it 'returns correct count' do + is_expected + .to match(0) end end end diff --git a/spec/presenters/project_clusterable_presenter_spec.rb b/spec/presenters/project_clusterable_presenter_spec.rb index 90b6671edd3..900630bb6e2 100644 --- a/spec/presenters/project_clusterable_presenter_spec.rb +++ b/spec/presenters/project_clusterable_presenter_spec.rb @@ -43,6 +43,12 @@ RSpec.describe ProjectClusterablePresenter do it { is_expected.to eq(new_project_cluster_path(project)) } end + describe '#connect_path' do + subject { presenter.connect_path } + + it { is_expected.to eq(connect_project_clusters_path(project)) } + end + describe '#authorize_aws_role_path' do subject { presenter.authorize_aws_role_path } diff --git a/spec/presenters/project_presenter_spec.rb b/spec/presenters/project_presenter_spec.rb index e4a08bd56c8..33a4a1b9d4c 100644 --- a/spec/presenters/project_presenter_spec.rb +++ b/spec/presenters/project_presenter_spec.rb @@ -747,10 +747,4 @@ RSpec.describe ProjectPresenter do end end end - - describe '#add_code_quality_ci_yml_path' do - subject { presenter.add_code_quality_ci_yml_path } - - it { is_expected.to match(/code_quality_walkthrough=true.*template=Code-Quality/) } - end end diff --git a/spec/presenters/projects/security/configuration_presenter_spec.rb b/spec/presenters/projects/security/configuration_presenter_spec.rb index 5f874ab5a3f..47ef0cf1192 100644 --- a/spec/presenters/projects/security/configuration_presenter_spec.rb +++ b/spec/presenters/projects/security/configuration_presenter_spec.rb @@ -13,8 +13,6 @@ RSpec.describe Projects::Security::ConfigurationPresenter do before do stub_licensed_features(licensed_scan_types.to_h { |type| [type, true] }) - - stub_feature_flags(corpus_management_ui: false) end describe '#to_html_data_attribute' do diff --git a/spec/presenters/search_service_presenter_spec.rb b/spec/presenters/search_service_presenter_spec.rb index 06ece838d8d..af9fee8cfd9 100644 --- a/spec/presenters/search_service_presenter_spec.rb +++ b/spec/presenters/search_service_presenter_spec.rb @@ -4,13 +4,33 @@ require 'spec_helper' RSpec.describe SearchServicePresenter do let(:user) { create(:user) } + let(:search) { '' } let(:search_service) { SearchService.new(user, search: search, scope: scope) } let(:presenter) { described_class.new(search_service, current_user: user) } + describe '#search_objects' do + let(:search_objects) { Kaminari::PaginatableArray.new([]) } + + context 'objects do not respond to eager_load' do + before do + allow(search_service).to receive(:search_objects).and_return(search_objects) + allow(search_objects).to receive(:respond_to?).with(:eager_load).and_return(false) + end + + context 'users scope' do + let(:scope) { 'users' } + + it 'does not eager load anything' do + expect(search_objects).not_to receive(:eager_load) + presenter.search_objects + end + end + end + end + describe '#show_results_status?' do using RSpec::Parameterized::TableSyntax - let(:search) { '' } let(:scope) { nil } before do diff --git a/spec/presenters/user_presenter_spec.rb b/spec/presenters/user_presenter_spec.rb index 9c51c0b0078..883eec68304 100644 --- a/spec/presenters/user_presenter_spec.rb +++ b/spec/presenters/user_presenter_spec.rb @@ -5,7 +5,9 @@ require 'spec_helper' RSpec.describe UserPresenter do let_it_be(:user) { create(:user) } - subject(:presenter) { described_class.new(user) } + let(:current_user) { user } + + subject(:presenter) { described_class.new(user, current_user: current_user) } describe '#web_path' do it { expect(presenter.web_path).to eq("/#{user.username}") } @@ -14,4 +16,65 @@ RSpec.describe UserPresenter do describe '#web_url' do it { expect(presenter.web_url).to eq("http://localhost/#{user.username}") } end + + context 'Gitpod' do + let(:gitpod_url) { "https://gitpod.io" } + let(:gitpod_application_enabled) { true } + + before do + allow(Gitlab::CurrentSettings).to receive(:gitpod_enabled).and_return(gitpod_application_enabled) + allow(Gitlab::CurrentSettings).to receive(:gitpod_url).and_return(gitpod_url) + end + + context 'Gitpod enabled for application' do + describe '#preferences_gitpod_path' do + it { expect(presenter.preferences_gitpod_path).to eq("/-/profile/preferences#user_gitpod_enabled") } + end + + describe '#profile_enable_gitpod_path' do + it { expect(presenter.profile_enable_gitpod_path).to eq("/-/profile?user%5Bgitpod_enabled%5D=true") } + end + end + + context 'Gitpod disabled for application' do + let(:gitpod_application_enabled) { false } + + describe '#preferences_gitpod_path' do + it { expect(presenter.preferences_gitpod_path).to eq(nil) } + end + + describe '#profile_enable_gitpod_path' do + it { expect(presenter.profile_enable_gitpod_path).to eq(nil) } + end + end + end + + describe '#saved_replies' do + let_it_be(:other_user) { create(:user) } + let_it_be(:saved_reply) { create(:saved_reply, user: user) } + + context 'when feature is disabled' do + before do + stub_feature_flags(saved_replies: false) + end + + it { expect(presenter.saved_replies).to eq(::Users::SavedReply.none) } + end + + context 'when feature is enabled' do + before do + stub_feature_flags(saved_replies: current_user) + end + + context 'when user has no permission to read saved replies' do + let(:current_user) { other_user } + + it { expect(presenter.saved_replies).to eq(::Users::SavedReply.none) } + end + + context 'when user has permission to read saved replies' do + it { expect(presenter.saved_replies).to eq([saved_reply]) } + end + end + end end |