Commit d434bce5 authored by Giorgenes Gelatti's avatar Giorgenes Gelatti

Refactor package specs

parent 26bf2b67
...@@ -7,7 +7,7 @@ describe API::ProjectPackages do ...@@ -7,7 +7,7 @@ describe API::ProjectPackages do
let(:project) { create(:project, :public) } let(:project) { create(:project, :public) }
let!(:package1) { create(:npm_package, project: project, version: '3.1.0', name: "@#{project.root_namespace.path}/foo1") } let!(:package1) { create(:npm_package, project: project, version: '3.1.0', name: "@#{project.root_namespace.path}/foo1") }
let(:package_url) { "/projects/#{project.id}/packages/#{package1.id}" } let(:package_url) { "/projects/#{project.id}/packages/#{package1.id}" }
let!(:package2) { create(:npm_package, project: project, version: '2.0.4', name: "@#{project.root_namespace.path}/foo2") } let!(:package2) { create(:nuget_package, project: project, version: '2.0.4') }
let!(:another_package) { create(:npm_package) } let!(:another_package) { create(:npm_package) }
let(:no_package_url) { "/projects/#{project.id}/packages/0" } let(:no_package_url) { "/projects/#{project.id}/packages/0" }
let(:wrong_package_url) { "/projects/#{project.id}/packages/#{another_package.id}" } let(:wrong_package_url) { "/projects/#{project.id}/packages/#{another_package.id}" }
...@@ -70,11 +70,9 @@ describe API::ProjectPackages do ...@@ -70,11 +70,9 @@ describe API::ProjectPackages do
end end
context 'with sorting' do context 'with sorting' do
shared_examples 'package sorting' do |order_by, package_names| shared_examples 'package sorting' do |order_by|
subject { get api(url), params: { sort: sort, order_by: order_by } } subject { get api(url), params: { sort: sort, order_by: order_by } }
let(:packages) { package_names.map { |name| send(name) } }
context "sorting by #{order_by}" do context "sorting by #{order_by}" do
context 'ascending order' do context 'ascending order' do
let(:sort) { 'asc' } let(:sort) { 'asc' }
...@@ -106,18 +104,20 @@ describe API::ProjectPackages do ...@@ -106,18 +104,20 @@ describe API::ProjectPackages do
end end
end end
it_behaves_like 'package sorting', 'name', [:package1, :package2, :package3] it_behaves_like 'package sorting', 'name' do
it_behaves_like 'package sorting', 'created_at', [:package3, :package1, :package2] let(:packages) { [package1, package2, package3] }
it_behaves_like 'package sorting', 'version', [:package3, :package2, :package1] end
context 'by packages type' do it_behaves_like 'package sorting', 'created_at' do
before do let(:packages) { [package3, package1, package2] }
# get rid of extra npm package as it messes up end
# the package type sorting test
package2.destroy it_behaves_like 'package sorting', 'version' do
let(:packages) { [package3, package2, package1] }
end end
it_behaves_like 'package sorting', 'type', [:package3, :package1] it_behaves_like 'package sorting', 'type' do
let(:packages) { [package3, package1, package2] }
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment