fix file upload

This commit is contained in:
James Lopez 2018-02-12 16:02:15 +01:00
parent 516d33f5ac
commit 7ec1a022b7
No known key found for this signature in database
GPG Key ID: 756BF8E9D7C0CF39
2 changed files with 6 additions and 5 deletions

View File

@ -8,7 +8,7 @@ module API
end
def file_is_valid?
import_params[:file] && import_params[:file].respond_to?(:read)
import_params[:file] && import_params[:file]['tempfile'].respond_to?(:read)
end
end
@ -26,7 +26,7 @@ module API
success Entities::ProjectImportStatus
end
post 'import' do
render_api_error!('The branch refname is invalid', 400) unless file_is_valid?
render_api_error!('The file is invalid', 400) unless file_is_valid?
namespace = import_params[:namespace]
@ -38,7 +38,8 @@ module API
Namespace.find_by_path_or_name(namespace)
end
project_params = import_params.merge(namespace_id: namespace.id)
project_params = import_params.merge(namespace_id: namespace.id,
file: import_params[:file]['tempfile'])
project = ::Projects::GitlabProjectsImportService.new(current_user, project_params).execute

View File

@ -19,9 +19,9 @@ describe API::ProjectImport do
it 'schedules an import' do
expect_any_instance_of(Project).to receive(:import_schedule)
post api('/projects/import', user), path: 'test-import', file: file, namespace: namespace.full_path
post api('/projects/import', user), path: 'test-import', file: fixture_file_upload(file), namespace: namespace.full_path
expect(response).to have_gitlab_http_status(200)
expect(response).to have_gitlab_http_status(201)
expect(Project.find_by_name('test-import').first.status).to eq('started')
end