Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
79879145
Commit
79879145
authored
Feb 13, 2018
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add more specs
parent
4a0d56da
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
7 deletions
+36
-7
lib/api/project_import.rb
lib/api/project_import.rb
+4
-6
spec/requests/api/project_import_spec.rb
spec/requests/api/project_import_spec.rb
+32
-1
No files found.
lib/api/project_import.rb
View file @
79879145
...
@@ -17,7 +17,6 @@ module API
...
@@ -17,7 +17,6 @@ module API
end
end
resource
:projects
,
requirements:
{
id:
%r{[^/]+}
}
do
resource
:projects
,
requirements:
{
id:
%r{[^/]+}
}
do
params
do
params
do
requires
:path
,
type:
String
,
desc:
'The new project path and name'
requires
:path
,
type:
String
,
desc:
'The new project path and name'
optional
:namespace
,
type:
String
,
desc:
'The ID or name of the namespace that the project will be imported into. Defaults to the user namespace.'
optional
:namespace
,
type:
String
,
desc:
'The ID or name of the namespace that the project will be imported into. Defaults to the user namespace.'
...
@@ -30,11 +29,10 @@ module API
...
@@ -30,11 +29,10 @@ module API
render_api_error!
(
'The file is invalid'
,
400
)
unless
file_is_valid?
render_api_error!
(
'The file is invalid'
,
400
)
unless
file_is_valid?
namespace
=
import_params
[
:namespace
]
namespace
=
import_params
[
:namespace
]
namespace
=
if
namespace
.
blank?
namespace
=
if
namespace
&&
namespace
=~
/^\d+$/
Namespace
.
find_by
(
id:
namespace
)
elsif
namespace
.
blank?
current_user
.
namespace
current_user
.
namespace
elsif
namespace
=~
/^\d+$/
Namespace
.
find_by
(
id:
namespace
)
else
else
Namespace
.
find_by_path_or_name
(
namespace
)
Namespace
.
find_by_path_or_name
(
namespace
)
end
end
...
@@ -43,7 +41,7 @@ module API
...
@@ -43,7 +41,7 @@ module API
file:
import_params
[
:file
][
'tempfile'
])
file:
import_params
[
:file
][
'tempfile'
])
project
=
::
Projects
::
GitlabProjectsImportService
.
new
(
current_user
,
project_params
).
execute
project
=
::
Projects
::
GitlabProjectsImportService
.
new
(
current_user
,
project_params
).
execute
render_api_error!
(
project
&
.
full_messages
&
.
first
,
400
)
unless
project
&
.
saved?
render_api_error!
(
project
.
errors
.
full_messages
&
.
first
,
400
)
unless
project
.
saved?
present
project
,
with:
Entities
::
ProjectImportStatus
present
project
,
with:
Entities
::
ProjectImportStatus
end
end
...
...
spec/requests/api/project_import_spec.rb
View file @
79879145
...
@@ -16,13 +16,44 @@ describe API::ProjectImport do
...
@@ -16,13 +16,44 @@ describe API::ProjectImport do
end
end
describe
'POST /projects/import'
do
describe
'POST /projects/import'
do
it
'schedules an import'
do
it
'schedules an import
using a namespace
'
do
expect_any_instance_of
(
Project
).
to
receive
(
:import_schedule
)
expect_any_instance_of
(
Project
).
to
receive
(
:import_schedule
)
expect
(
Gitlab
::
ImportExport
::
ProjectCreator
).
to
receive
(
:new
).
with
(
namespace
.
id
,
any_args
).
and_call_original
post
api
(
'/projects/import'
,
user
),
path:
'test-import'
,
file:
fixture_file_upload
(
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
(
201
)
expect
(
response
).
to
have_gitlab_http_status
(
201
)
end
end
it
'schedules an import at the user namespace level'
do
expect_any_instance_of
(
Project
).
to
receive
(
:import_schedule
)
expect
(
Gitlab
::
ImportExport
::
ProjectCreator
).
to
receive
(
:new
).
with
(
user
.
namespace
.
id
,
any_args
).
and_call_original
post
api
(
'/projects/import'
,
user
),
path:
'test-import2'
,
file:
fixture_file_upload
(
file
)
expect
(
response
).
to
have_gitlab_http_status
(
201
)
end
it
'does not schedule an import if the user has no permission to the namespace'
do
expect_any_instance_of
(
Project
).
not_to
receive
(
:import_schedule
)
post
(
api
(
'/projects/import'
,
create
(
:user
)),
path:
'test-import3'
,
file:
fixture_file_upload
(
file
),
namespace:
namespace
.
full_path
)
expect
(
response
).
to
have_gitlab_http_status
(
400
)
expect
(
json_response
[
'message'
]).
to
eq
(
'Namespace is not valid'
)
end
it
'does not schedule an import if the user uploads no valid file'
do
expect_any_instance_of
(
Project
).
not_to
receive
(
:import_schedule
)
post
api
(
'/projects/import'
,
user
),
path:
'test-import3'
,
file:
'./random/test'
expect
(
response
).
to
have_gitlab_http_status
(
400
)
expect
(
json_response
[
'error'
]).
to
eq
(
'file is invalid'
)
end
end
end
describe
'GET /projects/:id/import'
do
describe
'GET /projects/:id/import'
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment