diff options
Diffstat (limited to 'spec/presenters/packages')
-rw-r--r-- | spec/presenters/packages/detail/package_presenter_spec.rb | 3 | ||||
-rw-r--r-- | spec/presenters/packages/pypi/package_presenter_spec.rb | 55 |
2 files changed, 33 insertions, 25 deletions
diff --git a/spec/presenters/packages/detail/package_presenter_spec.rb b/spec/presenters/packages/detail/package_presenter_spec.rb index d8f1c98e762..3009f2bd56d 100644 --- a/spec/presenters/packages/detail/package_presenter_spec.rb +++ b/spec/presenters/packages/detail/package_presenter_spec.rb @@ -19,7 +19,8 @@ RSpec.describe ::Packages::Detail::PackagePresenter do size: file.size, file_md5: file.file_md5, file_sha1: file.file_sha1, - file_sha256: file.file_sha256 + file_sha256: file.file_sha256, + id: file.id } end end diff --git a/spec/presenters/packages/pypi/package_presenter_spec.rb b/spec/presenters/packages/pypi/package_presenter_spec.rb index e4d234a4688..25aa5c31034 100644 --- a/spec/presenters/packages/pypi/package_presenter_spec.rb +++ b/spec/presenters/packages/pypi/package_presenter_spec.rb @@ -5,45 +5,52 @@ require 'spec_helper' RSpec.describe ::Packages::Pypi::PackagePresenter do using RSpec::Parameterized::TableSyntax - let_it_be(:project) { create(:project) } + 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) { [package1, package2] } - let(:presenter) { described_class.new(packages, project) } - describe '#body' do - subject { presenter.body} + let(:file) { package.package_files.first } + let(:filename) { file.file_name } - shared_examples_for "pypi package presenter" do - let(:file) { package.package_files.first } - let(:filename) { file.file_name } - 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>" } + subject(:presenter) { described_class.new(packages, project_or_group).body} - before do - package.pypi_metadatum.required_python = python_version + describe '#body' do + shared_examples_for "pypi package presenter" do + where(:version, :expected_version, :with_package1) do + '>=2.7' | '>=2.7' | true + '"><script>alert(1)</script>' | '"><script>alert(1)</script>' | true + '>=2.7, !=3.0' | '>=2.7, !=3.0' | false end - it { is_expected.to include expected_file } - end + with_them do + let(:python_version) { version } + let(:expected_python_version) { expected_version } + let(:package) { with_package1 ? package1 : package2 } - it_behaves_like "pypi package presenter" do - let(:python_version) { '>=2.7' } - let(:expected_python_version) { '>=2.7' } - let(:package) { package1 } + before do + package.pypi_metadatum.required_python = python_version + end + + it { is_expected.to include expected_file } + end end - it_behaves_like "pypi package presenter" do - let(:python_version) { '"><script>alert(1)</script>' } - let(:expected_python_version) { '"><script>alert(1)</script>' } - let(:package) { package1 } + 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>" } + + it_behaves_like 'pypi package presenter' end - it_behaves_like "pypi package presenter" do - let(:python_version) { '>=2.7, !=3.0' } - let(:expected_python_version) { '>=2.7, !=3.0' } - let(:package) { package2 } + 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>" } + + it_behaves_like 'pypi package presenter' end end end |