Commit 42d77f31 authored by Stan Hu's avatar Stan Hu

Add specs for Maven and do some cleanup

parent 0b0c6188
...@@ -6,16 +6,17 @@ RSpec.describe 'Upload a maven package', :api, :js do ...@@ -6,16 +6,17 @@ RSpec.describe 'Upload a maven package', :api, :js do
include_context 'file upload requests helpers' include_context 'file upload requests helpers'
let_it_be(:project) { create(:project) } let_it_be(:project) { create(:project) }
let_it_be(:user) { create(:user, :admin) } let_it_be(:user) { project.owner }
let_it_be(:personal_access_token) { create(:personal_access_token, user: user) } let_it_be(:personal_access_token) { create(:personal_access_token, user: user) }
let(:api_path) { "/projects/#{project.id}/packages/maven/com/example/my-app/1.0/my-app-1.0-20180724.124855-1.jar" } let(:project_id) { project.id }
let(:api_path) { "/projects/#{project_id}/packages/maven/com/example/my-app/1.0/my-app-1.0-20180724.124855-1.jar" }
let(:url) { capybara_url(api(api_path, personal_access_token: personal_access_token)) } let(:url) { capybara_url(api(api_path, personal_access_token: personal_access_token)) }
let(:file) { fixture_file_upload('spec/fixtures/dk.png') } let(:file) { fixture_file_upload('spec/fixtures/dk.png') }
subject { HTTParty.put(url, body: file.read) } subject { HTTParty.put(url, body: file.read) }
RSpec.shared_examples 'for a maven package' do shared_examples 'for a maven package' do
it 'creates package files' do it 'creates package files' do
expect { subject } expect { subject }
.to change { Packages::Package.maven.count }.by(1) .to change { Packages::Package.maven.count }.by(1)
...@@ -25,9 +26,9 @@ RSpec.describe 'Upload a maven package', :api, :js do ...@@ -25,9 +26,9 @@ RSpec.describe 'Upload a maven package', :api, :js do
it { expect(subject.code).to eq(200) } it { expect(subject.code).to eq(200) }
end end
RSpec.shared_examples 'for a maven sha1' do shared_examples 'for a maven sha1' do
let(:dummy_package) { double(Packages::Package) } let(:dummy_package) { double(Packages::Package) }
let(:api_path) { "/projects/#{project.id}/packages/maven/com/example/my-app/1.0/my-app-1.0-20180724.124855-1.jar.sha1" } let(:api_path) { "/projects/#{project_id}/packages/maven/com/example/my-app/1.0/my-app-1.0-20180724.124855-1.jar.sha1" }
before do before do
# The sha verification done by the maven api is between: # The sha verification done by the maven api is between:
...@@ -42,8 +43,8 @@ RSpec.describe 'Upload a maven package', :api, :js do ...@@ -42,8 +43,8 @@ RSpec.describe 'Upload a maven package', :api, :js do
it { expect(subject.code).to eq(204) } it { expect(subject.code).to eq(204) }
end end
RSpec.shared_examples 'for a maven md5' do shared_examples 'for a maven md5' do
let(:api_path) { "/projects/#{project.id}/packages/maven/com/example/my-app/1.0/my-app-1.0-20180724.124855-1.jar.md5" } let(:api_path) { "/projects/#{project_id}/packages/maven/com/example/my-app/1.0/my-app-1.0-20180724.124855-1.jar.md5" }
let(:file) { StringIO.new('dummy_package') } let(:file) { StringIO.new('dummy_package') }
it { expect(subject.code).to eq(200) } it { expect(subject.code).to eq(200) }
...@@ -52,4 +53,10 @@ RSpec.describe 'Upload a maven package', :api, :js do ...@@ -52,4 +53,10 @@ RSpec.describe 'Upload a maven package', :api, :js do
it_behaves_like 'handling file uploads', 'for a maven package' it_behaves_like 'handling file uploads', 'for a maven package'
it_behaves_like 'handling file uploads', 'for a maven sha1' it_behaves_like 'handling file uploads', 'for a maven sha1'
it_behaves_like 'handling file uploads', 'for a maven md5' it_behaves_like 'handling file uploads', 'for a maven md5'
context 'with an encoded project ID' do
let(:project_id) { "#{project.namespace.path}%2F#{project.path}" }
it_behaves_like 'handling file uploads', 'for a maven package'
end
end end
...@@ -6,7 +6,7 @@ RSpec.describe 'Upload a nuget package', :api, :js do ...@@ -6,7 +6,7 @@ RSpec.describe 'Upload a nuget package', :api, :js do
include_context 'file upload requests helpers' include_context 'file upload requests helpers'
let_it_be(:project) { create(:project) } let_it_be(:project) { create(:project) }
let_it_be(:user) { create(:user, :admin) } let_it_be(:user) { project.owner }
let_it_be(:personal_access_token) { create(:personal_access_token, user: user) } let_it_be(:personal_access_token) { create(:personal_access_token, user: user) }
let(:api_path) { "/projects/#{project.id}/packages/nuget/" } let(:api_path) { "/projects/#{project.id}/packages/nuget/" }
...@@ -21,7 +21,7 @@ RSpec.describe 'Upload a nuget package', :api, :js do ...@@ -21,7 +21,7 @@ RSpec.describe 'Upload a nuget package', :api, :js do
) )
end end
RSpec.shared_examples 'for a nuget package' do shared_examples 'for a nuget package' do
it 'creates package files' do it 'creates package files' do
expect { subject } expect { subject }
.to change { Packages::Package.nuget.count }.by(1) .to change { Packages::Package.nuget.count }.by(1)
......
...@@ -6,7 +6,7 @@ RSpec.describe 'Upload a RubyGems package', :api, :js do ...@@ -6,7 +6,7 @@ RSpec.describe 'Upload a RubyGems package', :api, :js do
include_context 'file upload requests helpers' include_context 'file upload requests helpers'
let_it_be(:project) { create(:project) } let_it_be(:project) { create(:project) }
let_it_be(:user) { create(:user) } let_it_be(:user) { project.owner }
let_it_be(:personal_access_token) { create(:personal_access_token, user: user) } let_it_be(:personal_access_token) { create(:personal_access_token, user: user) }
let(:api_path) { "/projects/#{project_id}/packages/rubygems/api/v1/gems" } let(:api_path) { "/projects/#{project_id}/packages/rubygems/api/v1/gems" }
...@@ -21,11 +21,7 @@ RSpec.describe 'Upload a RubyGems package', :api, :js do ...@@ -21,11 +21,7 @@ RSpec.describe 'Upload a RubyGems package', :api, :js do
) )
end end
before do shared_examples 'for a Rubygems package' do
project.add_maintainer(user)
end
RSpec.shared_examples 'for a Rubygems package' do
it 'creates package files' do it 'creates package files' do
expect { subject } expect { subject }
.to change { Packages::Package.rubygems.count }.by(1) .to change { Packages::Package.rubygems.count }.by(1)
......
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