diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-06-20 14:10:13 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-06-20 14:10:13 +0300 |
commit | 0ea3fcec397b69815975647f5e2aa5fe944a8486 (patch) | |
tree | 7979381b89d26011bcf9bdc989a40fcc2f1ed4ff /spec/presenters | |
parent | 72123183a20411a36d607d70b12d57c484394c8e (diff) |
Add latest changes from gitlab-org/gitlab@15-1-stable-eev15.1.0-rc42
Diffstat (limited to 'spec/presenters')
-rw-r--r-- | spec/presenters/blob_presenter_spec.rb | 49 | ||||
-rw-r--r-- | spec/presenters/merge_request_presenter_spec.rb | 40 | ||||
-rw-r--r-- | spec/presenters/packages/pypi/simple_index_presenter_spec.rb | 68 | ||||
-rw-r--r-- | spec/presenters/packages/pypi/simple_package_versions_presenter_spec.rb (renamed from spec/presenters/packages/pypi/package_presenter_spec.rb) | 21 | ||||
-rw-r--r-- | spec/presenters/project_presenter_spec.rb | 31 | ||||
-rw-r--r-- | spec/presenters/releases/link_presenter_spec.rb | 31 | ||||
-rw-r--r-- | spec/presenters/service_hook_presenter_spec.rb | 4 | ||||
-rw-r--r-- | spec/presenters/web_hook_log_presenter_spec.rb | 4 |
8 files changed, 163 insertions, 85 deletions
diff --git a/spec/presenters/blob_presenter_spec.rb b/spec/presenters/blob_presenter_spec.rb index 80e08db6099..7b7463e6abc 100644 --- a/spec/presenters/blob_presenter_spec.rb +++ b/spec/presenters/blob_presenter_spec.rb @@ -250,45 +250,6 @@ RSpec.describe BlobPresenter do presenter.highlight end end - - context 'when blob is ipynb' do - let(:blob) { repository.blob_at('f6b7a707', 'files/ipython/markdown-table.ipynb') } - let(:git_blob) { blob.__getobj__ } - - before do - allow(Gitlab::Diff::CustomDiff).to receive(:transformed_for_diff?).and_return(true) - end - - it 'uses md as the transformed language' do - expect(Gitlab::Highlight).to receive(:highlight).with('files/ipython/markdown-table.ipynb', anything, plain: nil, language: 'md') - - presenter.highlight - end - - it 'transforms the blob' do - expect(Gitlab::Highlight).to receive(:highlight).with('files/ipython/markdown-table.ipynb', include("%%"), plain: nil, language: 'md') - - presenter.highlight - end - end - - context 'when blob is other file type' do - let(:git_blob) { blob.__getobj__ } - - before do - allow(git_blob) - .to receive(:data) - .and_return("line one\nline two\nline 3") - - allow(blob).to receive(:language_from_gitattributes).and_return('ruby') - end - - it 'does not transform the file' do - expect(Gitlab::Highlight).to receive(:highlight).with('files/ruby/regex.rb', git_blob.data, plain: nil, language: 'ruby') - - presenter.highlight - end - end end describe '#blob_language' do @@ -304,16 +265,6 @@ RSpec.describe BlobPresenter do it { is_expected.to eq('cpp') } end - context 'when blob is ipynb' do - let(:blob) { repository.blob_at('f6b7a707', 'files/ipython/markdown-table.ipynb') } - - before do - allow(Gitlab::Diff::CustomDiff).to receive(:transformed_for_diff?).and_return(true) - end - - it { is_expected.to eq('md') } - end - context 'when blob is binary' do let(:blob) { repository.blob_at('HEAD', 'Gemfile.zip') } diff --git a/spec/presenters/merge_request_presenter_spec.rb b/spec/presenters/merge_request_presenter_spec.rb index dbf5af095cb..798bee70e42 100644 --- a/spec/presenters/merge_request_presenter_spec.rb +++ b/spec/presenters/merge_request_presenter_spec.rb @@ -4,9 +4,45 @@ require 'spec_helper' RSpec.describe MergeRequestPresenter do let_it_be(:project) { create(:project, :repository) } - let_it_be(:resource) { create(:merge_request, source_project: project) } + let(:resource) { create(:merge_request, source_project: project) } + let_it_be(:user) { create(:user) } + describe '#mergeable_discussions_state' do + subject { described_class.new(resource).mergeable_discussions_state } + + let(:discussions_state) { double } + + before do + allow(resource).to receive(:mergeable_discussions_state?).and_return(discussions_state) + end + + context 'when change_response_code_merge_status is enabled' do + it 'returns the mergeable_discussions_state' do + is_expected.to eq(discussions_state) + end + end + + context 'when change_response_code_merge_status is disabled' do + before do + stub_feature_flags(change_response_code_merge_status: false) + end + + context 'when it is not mergeable' do + it 'returns false' do + resource.close! + is_expected.to eq(false) + end + end + + context 'when it is mergeable' do + it 'returns the mergeable_discussions_state' do + is_expected.to eq(discussions_state) + end + end + end + end + describe '#ci_status' do subject { described_class.new(resource).ci_status } @@ -308,7 +344,7 @@ RSpec.describe MergeRequestPresenter do end before do - allow(resource).to receive(:work_in_progress?).and_return(true) + allow(resource).to receive(:draft?).and_return(true) end context 'when merge request enabled and has permission' do diff --git a/spec/presenters/packages/pypi/simple_index_presenter_spec.rb b/spec/presenters/packages/pypi/simple_index_presenter_spec.rb new file mode 100644 index 00000000000..d915706577f --- /dev/null +++ b/spec/presenters/packages/pypi/simple_index_presenter_spec.rb @@ -0,0 +1,68 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe ::Packages::Pypi::SimpleIndexPresenter, :aggregate_failures do + using RSpec::Parameterized::TableSyntax + + let_it_be(:group) { create(:group) } + let_it_be(:project) { create(:project, group: group) } + let_it_be(:package_name) { 'sample-project' } + let_it_be(:package1) { create(:pypi_package, project: project, name: package_name, version: '1.0.0') } + let_it_be(:package2) { create(:pypi_package, project: project, name: package_name, version: '2.0.0') } + + let(:packages) { project.packages } + + describe '#body' do + subject(:presenter) { described_class.new(packages, project_or_group).body } + + shared_examples_for "pypi package presenter" do + where(:version, :expected_version) do + '>=2.7' | '>=2.7' + '"><script>alert(1)</script>' | '"><script>alert(1)</script>' + '>=2.7, !=3.0' | '>=2.7, !=3.0' + end + + with_them do + let(:python_version) { version } + let(:expected_python_version) { expected_version } + + before do + package1.pypi_metadatum.update_column(:required_python, python_version) + package2.pypi_metadatum.update_column(:required_python, '') + end + + it 'contains links for all packages' do + expect(presenter).to include(expected_link1) + expect(presenter).to include(expected_link2) + end + end + end + + context 'for project' do + let(:project_or_group) { project } + let(:expected_link1) { "<a href=\"http://localhost/api/v4/projects/#{project.id}/packages/pypi/simple/#{package1.normalized_pypi_name}\" data-requires-python=\"#{expected_python_version}\">#{package1.name}</a>" } # rubocop:disable Layout/LineLength + let(:expected_link2) { "<a href=\"http://localhost/api/v4/projects/#{project.id}/packages/pypi/simple/#{package2.normalized_pypi_name}\" data-requires-python=\"\">#{package2.name}</a>" } # rubocop:disable Layout/LineLength + + it_behaves_like 'pypi package presenter' + end + + context 'for group' do + let(:project_or_group) { group } + let(:expected_link1) { "<a href=\"http://localhost/api/v4/groups/#{group.id}/-/packages/pypi/simple/#{package1.normalized_pypi_name}\" data-requires-python=\"#{expected_python_version}\">#{package1.name}</a>" } # rubocop:disable Layout/LineLength + let(:expected_link2) { "<a href=\"http://localhost/api/v4/groups/#{group.id}/-/packages/pypi/simple/#{package2.normalized_pypi_name}\" data-requires-python=\"\">#{package2.name}</a>" } # rubocop:disable Layout/LineLength + + it_behaves_like 'pypi package presenter' + end + + context 'with package files pending destruction' do + let_it_be(:package_pending_destruction) do + create(:package, :pending_destruction, project: project, name: "package_pending_destruction") + end + + let(:project_or_group) { project } + + it { is_expected.not_to include(package_pending_destruction.name) } + end + end +end diff --git a/spec/presenters/packages/pypi/package_presenter_spec.rb b/spec/presenters/packages/pypi/simple_package_versions_presenter_spec.rb index b19abdbc17a..be454e5168c 100644 --- a/spec/presenters/packages/pypi/package_presenter_spec.rb +++ b/spec/presenters/packages/pypi/simple_package_versions_presenter_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe ::Packages::Pypi::PackagePresenter do +RSpec.describe ::Packages::Pypi::SimplePackageVersionsPresenter, :aggregate_failures do using RSpec::Parameterized::TableSyntax let_it_be(:group) { create(:group) } @@ -11,14 +11,13 @@ RSpec.describe ::Packages::Pypi::PackagePresenter do let_it_be(:package1) { create(:pypi_package, project: project, name: package_name, version: '1.0.0') } let_it_be(:package2) { create(:pypi_package, project: project, name: package_name, version: '2.0.0') } - let(:packages) { [package1, package2] } - let(:file) { package.package_files.first } let(:filename) { file.file_name } - - subject(:presenter) { described_class.new(packages, project_or_group).body} + let(:packages) { project.packages } describe '#body' do + subject(:presenter) { described_class.new(packages, project_or_group).body } + shared_examples_for "pypi package presenter" do where(:version, :expected_version, :with_package1) do '>=2.7' | '>=2.7' | true @@ -32,29 +31,31 @@ RSpec.describe ::Packages::Pypi::PackagePresenter do let(:package) { with_package1 ? package1 : package2 } before do - package.pypi_metadatum.required_python = python_version + package.pypi_metadatum.update_column(:required_python, python_version) end - it { is_expected.to include expected_file } + it { is_expected.to include expected_link } end end context 'for project' do let(:project_or_group) { project } - let(:expected_file) { "<a href=\"http://localhost/api/v4/projects/#{project.id}/packages/pypi/files/#{file.file_sha256}/#{filename}#sha256=#{file.file_sha256}\" data-requires-python=\"#{expected_python_version}\">#{filename}</a><br>" } + let(:expected_link) { "<a href=\"http://localhost/api/v4/projects/#{project.id}/packages/pypi/files/#{file.file_sha256}/#{filename}#sha256=#{file.file_sha256}\" data-requires-python=\"#{expected_python_version}\">#{filename}</a>" } # rubocop:disable Layout/LineLength it_behaves_like 'pypi package presenter' end context 'for group' do let(:project_or_group) { group } - let(:expected_file) { "<a href=\"http://localhost/api/v4/groups/#{group.id}/-/packages/pypi/files/#{file.file_sha256}/#{filename}#sha256=#{file.file_sha256}\" data-requires-python=\"#{expected_python_version}\">#{filename}</a><br>" } + let(:expected_link) { "<a href=\"http://localhost/api/v4/groups/#{group.id}/-/packages/pypi/files/#{file.file_sha256}/#{filename}#sha256=#{file.file_sha256}\" data-requires-python=\"#{expected_python_version}\">#{filename}</a>" } # rubocop:disable Layout/LineLength it_behaves_like 'pypi package presenter' end context 'with package files pending destruction' do - let_it_be(:package_file_pending_destruction) { create(:package_file, :pending_destruction, package: package1, file_name: "package_file_pending_destruction") } + let_it_be(:package_file_pending_destruction) do + create(:package_file, :pending_destruction, package: package1, file_name: "package_file_pending_destruction") + end let(:project_or_group) { project } diff --git a/spec/presenters/project_presenter_spec.rb b/spec/presenters/project_presenter_spec.rb index 33a4a1b9d4c..df3e4b985ab 100644 --- a/spec/presenters/project_presenter_spec.rb +++ b/spec/presenters/project_presenter_spec.rb @@ -73,8 +73,6 @@ RSpec.describe ProjectPresenter do context 'when repository is not empty' do let_it_be(:project) { create(:project, :public, :repository) } - let(:release) { create(:release, project: project, author: user) } - it 'returns files and readme if user has repository access' do allow(presenter).to receive(:can?).with(nil, :download_code, project).and_return(true) @@ -98,6 +96,9 @@ RSpec.describe ProjectPresenter do end it 'returns releases anchor' do + user = create(:user) + release = create(:release, project: project, author: user) + expect(release).to be_truthy expect(presenter.releases_anchor_data).to have_attributes( is_link: true, @@ -211,16 +212,6 @@ RSpec.describe ProjectPresenter do context 'statistics anchors (empty repo)' do let_it_be(:project) { create(:project, :empty_repo) } - describe '#files_anchor_data' do - it 'returns files data' do - expect(presenter.files_anchor_data).to have_attributes( - is_link: true, - label: a_string_including('0 Bytes'), - link: nil - ) - end - end - describe '#storage_anchor_data' do it 'returns storage data' do expect(presenter.storage_anchor_data).to have_attributes( @@ -275,22 +266,22 @@ RSpec.describe ProjectPresenter do let(:presenter) { described_class.new(project, current_user: user) } - describe '#files_anchor_data' do - it 'returns files data' do - expect(presenter.files_anchor_data).to have_attributes( + describe '#storage_anchor_data' do + it 'returns storage data without usage quotas link for non-admin users' do + expect(presenter.storage_anchor_data).to have_attributes( is_link: true, label: a_string_including('0 Bytes'), - link: presenter.project_tree_path(project) + link: nil ) end - end - describe '#storage_anchor_data' do - it 'returns storage data' do + it 'returns storage data with usage quotas link for admin users' do + project.add_owner(user) + expect(presenter.storage_anchor_data).to have_attributes( is_link: true, label: a_string_including('0 Bytes'), - link: presenter.project_tree_path(project) + link: presenter.project_usage_quotas_path(project) ) end end diff --git a/spec/presenters/releases/link_presenter_spec.rb b/spec/presenters/releases/link_presenter_spec.rb new file mode 100644 index 00000000000..e52c68ffb38 --- /dev/null +++ b/spec/presenters/releases/link_presenter_spec.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Releases::LinkPresenter do + describe '#direct_asset_url' do + let_it_be(:release) { create(:release) } + + let(:link) { build(:release_link, release: release, url: url, filepath: filepath) } + let(:url) { 'https://google.com/-/jobs/140463678/artifacts/download' } + let(:presenter) { described_class.new(link) } + + subject { presenter.direct_asset_url } + + context 'when filepath is provided' do + let(:filepath) { '/bin/bigfile.exe' } + let(:expected_url) do + "http://localhost/#{release.project.namespace.path}/#{release.project.name}" \ + "/-/releases/#{release.tag}/downloads/bin/bigfile.exe" + end + + it { is_expected.to eq(expected_url) } + end + + context 'when filepath is not provided' do + let(:filepath) { nil } + + it { is_expected.to eq(url) } + end + end +end diff --git a/spec/presenters/service_hook_presenter_spec.rb b/spec/presenters/service_hook_presenter_spec.rb index 25ded17fb34..c7703593327 100644 --- a/spec/presenters/service_hook_presenter_spec.rb +++ b/spec/presenters/service_hook_presenter_spec.rb @@ -12,7 +12,7 @@ RSpec.describe ServiceHookPresenter do subject { service_hook.present.logs_details_path(web_hook_log) } let(:expected_path) do - "/#{project.namespace.path}/#{project.name}/-/integrations/#{integration.to_param}/hook_logs/#{web_hook_log.id}" + "/#{project.namespace.path}/#{project.name}/-/settings/integrations/#{integration.to_param}/hook_logs/#{web_hook_log.id}" end it { is_expected.to eq(expected_path) } @@ -22,7 +22,7 @@ RSpec.describe ServiceHookPresenter do subject { service_hook.present.logs_retry_path(web_hook_log) } let(:expected_path) do - "/#{project.namespace.path}/#{project.name}/-/integrations/#{integration.to_param}/hook_logs/#{web_hook_log.id}/retry" + "/#{project.namespace.path}/#{project.name}/-/settings/integrations/#{integration.to_param}/hook_logs/#{web_hook_log.id}/retry" end it { is_expected.to eq(expected_path) } diff --git a/spec/presenters/web_hook_log_presenter_spec.rb b/spec/presenters/web_hook_log_presenter_spec.rb index 5827f3378de..188737e0fb6 100644 --- a/spec/presenters/web_hook_log_presenter_spec.rb +++ b/spec/presenters/web_hook_log_presenter_spec.rb @@ -21,7 +21,7 @@ RSpec.describe WebHookLogPresenter do let(:web_hook) { create(:service_hook, integration: integration) } let(:integration) { create(:drone_ci_integration, project: project) } - it { is_expected.to eq(project_integration_hook_log_path(project, integration, web_hook_log)) } + it { is_expected.to eq(project_settings_integration_hook_log_path(project, integration, web_hook_log)) } end end @@ -41,7 +41,7 @@ RSpec.describe WebHookLogPresenter do let(:web_hook) { create(:service_hook, integration: integration) } let(:integration) { create(:drone_ci_integration, project: project) } - it { is_expected.to eq(retry_project_integration_hook_log_path(project, integration, web_hook_log)) } + it { is_expected.to eq(retry_project_settings_integration_hook_log_path(project, integration, web_hook_log)) } end end end |