2020-07-10 11:09:07 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe Packages::CreatePackageFileService do
|
2020-11-16 19:09:16 -05:00
|
|
|
let_it_be(:package) { create(:maven_package) }
|
|
|
|
let_it_be(:user) { create(:user) }
|
2021-06-28 23:07:32 -04:00
|
|
|
|
2020-12-03 19:09:55 -05:00
|
|
|
let(:service) { described_class.new(package, params) }
|
2020-07-10 11:09:07 -04:00
|
|
|
|
|
|
|
describe '#execute' do
|
2020-12-03 19:09:55 -05:00
|
|
|
subject { service.execute }
|
|
|
|
|
2020-07-10 11:09:07 -04:00
|
|
|
context 'with valid params' do
|
|
|
|
let(:params) do
|
|
|
|
{
|
|
|
|
file: Tempfile.new,
|
|
|
|
file_name: 'foo.jar'
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates a new package file' do
|
2020-12-03 19:09:55 -05:00
|
|
|
package_file = subject
|
2020-07-10 11:09:07 -04:00
|
|
|
|
|
|
|
expect(package_file).to be_valid
|
|
|
|
expect(package_file.file_name).to eq('foo.jar')
|
|
|
|
end
|
2020-12-03 19:09:55 -05:00
|
|
|
|
|
|
|
it_behaves_like 'assigns build to package file'
|
2020-07-10 11:09:07 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'file is missing' do
|
|
|
|
let(:params) do
|
|
|
|
{
|
|
|
|
file_name: 'foo.jar'
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'raises an error' do
|
2020-12-03 19:09:55 -05:00
|
|
|
expect { subject }.to raise_error(ActiveRecord::RecordInvalid)
|
2020-07-10 11:09:07 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|