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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
71c948d6
Commit
71c948d6
authored
Feb 09, 2018
by
Clement Ho
Committed by
Filipa Lacerda
Feb 09, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace $.post in importer status with axios
parent
d997fe13
Changes
13
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
328 additions
and
176 deletions
+328
-176
app/assets/javascripts/importer_status.js
app/assets/javascripts/importer_status.js
+44
-24
app/controllers/import/bitbucket_controller.rb
app/controllers/import/bitbucket_controller.rb
+14
-8
app/controllers/import/fogbugz_controller.rb
app/controllers/import/fogbugz_controller.rb
+8
-8
app/controllers/import/github_controller.rb
app/controllers/import/github_controller.rb
+12
-7
app/controllers/import/gitlab_controller.rb
app/controllers/import/gitlab_controller.rb
+11
-7
app/controllers/import/google_code_controller.rb
app/controllers/import/google_code_controller.rb
+8
-8
app/serializers/project_serializer.rb
app/serializers/project_serializer.rb
+3
-0
app/views/import/base/create.js.haml
app/views/import/base/create.js.haml
+0
-13
app/views/import/base/unauthorized.js.haml
app/views/import/base/unauthorized.js.haml
+0
-14
spec/controllers/import/bitbucket_controller_spec.rb
spec/controllers/import/bitbucket_controller_spec.rb
+60
-28
spec/controllers/import/gitlab_controller_spec.rb
spec/controllers/import/gitlab_controller_spec.rb
+58
-27
spec/javascripts/importer_status_spec.js
spec/javascripts/importer_status_spec.js
+47
-0
spec/support/controllers/githubish_import_controller_shared_examples.rb
...ontrollers/githubish_import_controller_shared_examples.rb
+63
-32
No files found.
app/assets/javascripts/importer_status.js
View file @
71c948d6
import
{
__
}
from
'
./locale
'
;
import
axios
from
'
./lib/utils/axios_utils
'
;
import
flash
from
'
./flash
'
;
class
ImporterStatus
{
constructor
(
jobsUrl
,
importUrl
)
{
this
.
jobsUrl
=
jobsUrl
;
...
...
@@ -9,7 +13,20 @@ class ImporterStatus {
initStatusPage
()
{
$
(
'
.js-add-to-import
'
)
.
off
(
'
click
'
)
.
on
(
'
click
'
,
(
event
)
=>
{
.
on
(
'
click
'
,
this
.
addToImport
.
bind
(
this
));
$
(
'
.js-import-all
'
)
.
off
(
'
click
'
)
.
on
(
'
click
'
,
function
onClickImportAll
()
{
const
$btn
=
$
(
this
);
$btn
.
disable
().
addClass
(
'
is-loading
'
);
return
$
(
'
.js-add-to-import
'
).
each
(
function
triggerAddImport
()
{
return
$
(
this
).
trigger
(
'
click
'
);
});
});
}
addToImport
(
event
)
{
const
$btn
=
$
(
event
.
currentTarget
);
const
$tr
=
$btn
.
closest
(
'
tr
'
);
const
$targetField
=
$tr
.
find
(
'
.import-target
'
);
...
...
@@ -24,24 +41,22 @@ class ImporterStatus {
}
$btn
.
disable
().
addClass
(
'
is-loading
'
);
return
$
.
post
(
this
.
importUrl
,
{
return
axios
.
post
(
this
.
importUrl
,
{
repo_id
:
id
,
target_namespace
:
targetNamespace
,
new_name
:
newName
,
},
{
dataType
:
'
script
'
,
}
);
}
);
})
.
then
(({
data
})
=>
{
const
job
=
$
(
`tr#repo_
${
id
}
`
);
job
.
attr
(
'
id
'
,
`project_
${
data
.
id
}
`
);
$
(
'
.js-import-all
'
)
.
off
(
'
click
'
)
.
on
(
'
click
'
,
function
onClickImportAll
()
{
const
$btn
=
$
(
this
);
$btn
.
disable
().
addClass
(
'
is-loading
'
);
return
$
(
'
.js-add-to-import
'
).
each
(
function
triggerAddImport
()
{
return
$
(
this
).
trigger
(
'
click
'
);
});
});
job
.
find
(
'
.import-target
'
).
html
(
`<a href="
${
data
.
full_path
}
">
${
data
.
full_path
}
</a>`
);
$
(
'
table.import-jobs tbody
'
).
prepend
(
job
);
job
.
addClass
(
'
active
'
);
job
.
find
(
'
.import-actions
'
).
html
(
'
<i class="fa fa-spinner fa-spin" aria-label="importing"></i> started
'
);
})
.
catch
(()
=>
flash
(
__
(
'
An error occurred while importing project
'
)));
}
setAutoUpdate
()
{
...
...
@@ -71,7 +86,7 @@ class ImporterStatus {
}
// eslint-disable-next-line consistent-return
export
default
function
initImporterStatus
()
{
function
initImporterStatus
()
{
const
importerStatus
=
document
.
querySelector
(
'
.js-importer-status
'
);
if
(
importerStatus
)
{
...
...
@@ -79,3 +94,8 @@ export default function initImporterStatus() {
return
new
ImporterStatus
(
data
.
jobsImportPath
,
data
.
importPath
);
}
}
export
{
initImporterStatus
as
default
,
ImporterStatus
,
};
app/controllers/import/bitbucket_controller.rb
View file @
71c948d6
...
...
@@ -37,24 +37,30 @@ class Import::BitbucketController < Import::BaseController
def
create
bitbucket_client
=
Bitbucket
::
Client
.
new
(
credentials
)
@
repo_id
=
params
[
:repo_id
].
to_s
name
=
@
repo_id
.
gsub
(
'___'
,
'/'
)
repo_id
=
params
[
:repo_id
].
to_s
name
=
repo_id
.
gsub
(
'___'
,
'/'
)
repo
=
bitbucket_client
.
repo
(
name
)
@
project_name
=
params
[
:new_name
].
presence
||
repo
.
name
project_name
=
params
[
:new_name
].
presence
||
repo
.
name
repo_owner
=
repo
.
owner
repo_owner
=
current_user
.
username
if
repo_owner
==
bitbucket_client
.
user
.
username
namespace_path
=
params
[
:new_namespace
].
presence
||
repo_owner
target_namespace
=
find_or_create_namespace
(
namespace_path
,
current_user
)
@target_namespace
=
find_or_create_namespace
(
namespace_path
,
current_user
)
if
current_user
.
can?
(
:create_projects
,
@target_namespace
)
if
current_user
.
can?
(
:create_projects
,
target_namespace
)
# The token in a session can be expired, we need to get most recent one because
# Bitbucket::Connection class refreshes it.
session
[
:bitbucket_token
]
=
bitbucket_client
.
connection
.
token
@project
=
Gitlab
::
BitbucketImport
::
ProjectCreator
.
new
(
repo
,
@project_name
,
@target_namespace
,
current_user
,
credentials
).
execute
project
=
Gitlab
::
BitbucketImport
::
ProjectCreator
.
new
(
repo
,
project_name
,
target_namespace
,
current_user
,
credentials
).
execute
if
project
.
persisted?
render
json:
ProjectSerializer
.
new
.
represent
(
project
)
else
render
json:
{
errors:
project
.
errors
.
full_messages
},
status: :unprocessable_entity
end
else
render
'unauthorized'
render
json:
{
errors:
'This namespace has already been taken! Please choose another one.'
},
status: :unprocessable_entity
end
end
...
...
app/controllers/import/fogbugz_controller.rb
View file @
71c948d6
...
...
@@ -58,17 +58,17 @@ class Import::FogbugzController < Import::BaseController
end
def
create
@repo_id
=
params
[
:repo_id
]
repo
=
client
.
repo
(
@repo_id
)
repo
=
client
.
repo
(
params
[
:repo_id
])
fb_session
=
{
uri:
session
[
:fogbugz_uri
],
token:
session
[
:fogbugz_token
]
}
@target_namespace
=
current_user
.
namespace
@project_name
=
repo
.
name
namespace
=
@target_namespace
umap
=
session
[
:fogbugz_user_map
]
||
client
.
user_map
@project
=
Gitlab
::
FogbugzImport
::
ProjectCreator
.
new
(
repo
,
fb_session
,
namespace
,
current_user
,
umap
).
execute
project
=
Gitlab
::
FogbugzImport
::
ProjectCreator
.
new
(
repo
,
fb_session
,
current_user
.
namespace
,
current_user
,
umap
).
execute
if
project
.
persisted?
render
json:
ProjectSerializer
.
new
.
represent
(
project
)
else
render
json:
{
errors:
project
.
errors
.
full_messages
},
status: :unprocessable_entity
end
end
private
...
...
app/controllers/import/github_controller.rb
View file @
71c948d6
...
...
@@ -36,16 +36,21 @@ class Import::GithubController < Import::BaseController
end
def
create
@repo_id
=
params
[
:repo_id
].
to_i
repo
=
client
.
repo
(
@repo_id
)
@project_name
=
params
[
:new_name
].
presence
||
repo
.
name
repo
=
client
.
repo
(
params
[
:repo_id
].
to_i
)
project_name
=
params
[
:new_name
].
presence
||
repo
.
name
namespace_path
=
params
[
:target_namespace
].
presence
||
current_user
.
namespace_path
@
target_namespace
=
find_or_create_namespace
(
namespace_path
,
current_user
.
namespace_path
)
target_namespace
=
find_or_create_namespace
(
namespace_path
,
current_user
.
namespace_path
)
if
can?
(
current_user
,
:create_projects
,
@target_namespace
)
@project
=
Gitlab
::
LegacyGithubImport
::
ProjectCreator
.
new
(
repo
,
@project_name
,
@target_namespace
,
current_user
,
access_params
,
type:
provider
).
execute
if
can?
(
current_user
,
:create_projects
,
target_namespace
)
project
=
Gitlab
::
LegacyGithubImport
::
ProjectCreator
.
new
(
repo
,
project_name
,
target_namespace
,
current_user
,
access_params
,
type:
provider
).
execute
if
project
.
persisted?
render
json:
ProjectSerializer
.
new
.
represent
(
project
)
else
render
json:
{
errors:
project
.
errors
.
full_messages
},
status: :unprocessable_entity
end
else
render
'unauthorized'
render
json:
{
errors:
'This namespace has already been taken! Please choose another one.'
},
status: :unprocessable_entity
end
end
...
...
app/controllers/import/gitlab_controller.rb
View file @
71c948d6
...
...
@@ -24,15 +24,19 @@ class Import::GitlabController < Import::BaseController
end
def
create
@repo_id
=
params
[
:repo_id
].
to_i
repo
=
client
.
project
(
@repo_id
)
@project_name
=
repo
[
'name'
]
@target_namespace
=
find_or_create_namespace
(
repo
[
'namespace'
][
'path'
],
client
.
user
[
'username'
])
repo
=
client
.
project
(
params
[
:repo_id
].
to_i
)
target_namespace
=
find_or_create_namespace
(
repo
[
'namespace'
][
'path'
],
client
.
user
[
'username'
])
if
current_user
.
can?
(
:create_projects
,
@target_namespace
)
@project
=
Gitlab
::
GitlabImport
::
ProjectCreator
.
new
(
repo
,
@target_namespace
,
current_user
,
access_params
).
execute
if
current_user
.
can?
(
:create_projects
,
target_namespace
)
project
=
Gitlab
::
GitlabImport
::
ProjectCreator
.
new
(
repo
,
target_namespace
,
current_user
,
access_params
).
execute
if
project
.
persisted?
render
json:
ProjectSerializer
.
new
.
represent
(
project
)
else
render
json:
{
errors:
project
.
errors
.
full_messages
},
status: :unprocessable_entity
end
else
render
'unauthorized'
render
json:
{
errors:
'This namespace has already been taken! Please choose another one.'
},
status: :unprocessable_entity
end
end
...
...
app/controllers/import/google_code_controller.rb
View file @
71c948d6
...
...
@@ -85,16 +85,16 @@ class Import::GoogleCodeController < Import::BaseController
end
def
create
@repo_id
=
params
[
:repo_id
]
repo
=
client
.
repo
(
@repo_id
)
@target_namespace
=
current_user
.
namespace
@project_name
=
repo
.
name
namespace
=
@target_namespace
repo
=
client
.
repo
(
params
[
:repo_id
])
user_map
=
session
[
:google_code_user_map
]
@project
=
Gitlab
::
GoogleCodeImport
::
ProjectCreator
.
new
(
repo
,
namespace
,
current_user
,
user_map
).
execute
project
=
Gitlab
::
GoogleCodeImport
::
ProjectCreator
.
new
(
repo
,
current_user
.
namespace
,
current_user
,
user_map
).
execute
if
project
.
persisted?
render
json:
ProjectSerializer
.
new
.
represent
(
project
)
else
render
json:
{
errors:
project
.
errors
.
full_messages
},
status: :unprocessable_entity
end
end
private
...
...
app/serializers/project_serializer.rb
0 → 100644
View file @
71c948d6
class
ProjectSerializer
<
BaseSerializer
entity
ProjectEntity
end
app/views/import/base/create.js.haml
deleted
100644 → 0
View file @
d997fe13
-
if
@project
.
persisted?
:plain
job = $("tr#repo_
#{
@repo_id
}
")
job.attr("id", "project_
#{
@project
.
id
}
")
target_field = job.find(".import-target")
target_field.empty()
target_field.append('
#{
link_to
@project
.
full_path
,
project_path
(
@project
)
}
')
$("table.import-jobs tbody").prepend(job)
job.addClass("active").find(".import-actions").html("<i class='fa fa-spinner fa-spin'></i> started")
-
else
:plain
job = $("tr#repo_
#{
@repo_id
}
")
job.find(".import-actions").html("<i class='fa fa-exclamation-circle'></i> Error saving project:
#{
escape_javascript
(
h
(
@project
.
errors
.
full_messages
.
join
(
','
)))
}
")
app/views/import/base/unauthorized.js.haml
deleted
100644 → 0
View file @
d997fe13
:plain
tr = $("tr#repo_
#{
@repo_id
}
")
target_field = tr.find(".import-target")
import_button = tr.find(".btn-import")
origin_target = target_field.text()
project_name = "
#{
@project_name
}
"
origin_namespace = "
#{
@target_namespace
.
full_path
}
"
target_field.empty()
target_field.append("<p class='alert alert-danger'>This namespace has already been taken! Please choose another one.</p>")
target_field.append("<input type='text' name='target_namespace' />")
target_field.append("/" + project_name)
target_field.data("project_name", project_name)
target_field.find('input').prop("value", origin_namespace)
import_button.enable().removeClass('is-loading')
spec/controllers/import/bitbucket_controller_spec.rb
View file @
71c948d6
...
...
@@ -84,20 +84,42 @@ describe Import::BitbucketController do
double
(
slug:
"vim"
,
owner:
bitbucket_username
,
name:
'vim'
)
end
let
(
:project
)
{
create
(
:project
)
}
before
do
allow_any_instance_of
(
Bitbucket
::
Client
).
to
receive
(
:repo
).
and_return
(
bitbucket_repo
)
allow_any_instance_of
(
Bitbucket
::
Client
).
to
receive
(
:user
).
and_return
(
bitbucket_user
)
assign_session_tokens
end
it
'returns 200 response when the project is imported successfully'
do
allow
(
Gitlab
::
BitbucketImport
::
ProjectCreator
)
.
to
receive
(
:new
).
with
(
bitbucket_repo
,
bitbucket_repo
.
name
,
user
.
namespace
,
user
,
access_params
)
.
and_return
(
double
(
execute:
project
))
post
:create
,
format: :json
expect
(
response
).
to
have_gitlab_http_status
(
200
)
end
it
'returns 422 response when the project could not be imported'
do
allow
(
Gitlab
::
BitbucketImport
::
ProjectCreator
)
.
to
receive
(
:new
).
with
(
bitbucket_repo
,
bitbucket_repo
.
name
,
user
.
namespace
,
user
,
access_params
)
.
and_return
(
double
(
execute:
build
(
:project
)))
post
:create
,
format: :json
expect
(
response
).
to
have_gitlab_http_status
(
422
)
end
context
"when the repository owner is the Bitbucket user"
do
context
"when the Bitbucket user and GitLab user's usernames match"
do
it
"takes the current user's namespace"
do
expect
(
Gitlab
::
BitbucketImport
::
ProjectCreator
)
.
to
receive
(
:new
).
with
(
bitbucket_repo
,
bitbucket_repo
.
name
,
user
.
namespace
,
user
,
access_params
)
.
and_return
(
double
(
execute:
true
))
.
and_return
(
double
(
execute:
project
))
post
:create
,
format: :js
post
:create
,
format: :js
on
end
end
...
...
@@ -107,9 +129,9 @@ describe Import::BitbucketController do
it
"takes the current user's namespace"
do
expect
(
Gitlab
::
BitbucketImport
::
ProjectCreator
)
.
to
receive
(
:new
).
with
(
bitbucket_repo
,
bitbucket_repo
.
name
,
user
.
namespace
,
user
,
access_params
)
.
and_return
(
double
(
execute:
true
))
.
and_return
(
double
(
execute:
project
))
post
:create
,
format: :js
post
:create
,
format: :js
on
end
end
...
...
@@ -120,7 +142,7 @@ describe Import::BitbucketController do
allow
(
controller
).
to
receive
(
:current_user
).
and_return
(
user
)
allow
(
user
).
to
receive
(
:can?
).
and_return
(
false
)
post
:create
,
format: :js
post
:create
,
format: :js
on
end
end
end
...
...
@@ -143,9 +165,9 @@ describe Import::BitbucketController do
it
"takes the existing namespace"
do
expect
(
Gitlab
::
BitbucketImport
::
ProjectCreator
)
.
to
receive
(
:new
).
with
(
bitbucket_repo
,
bitbucket_repo
.
name
,
existing_namespace
,
user
,
access_params
)
.
and_return
(
double
(
execute:
true
))
.
and_return
(
double
(
execute:
project
))
post
:create
,
format: :js
post
:create
,
format: :js
on
end
end
...
...
@@ -154,7 +176,7 @@ describe Import::BitbucketController do
expect
(
Gitlab
::
BitbucketImport
::
ProjectCreator
)
.
not_to
receive
(
:new
)
post
:create
,
format: :js
post
:create
,
format: :js
on
end
end
end
...
...
@@ -163,17 +185,17 @@ describe Import::BitbucketController do
context
"when current user can create namespaces"
do
it
"creates the namespace"
do
expect
(
Gitlab
::
BitbucketImport
::
ProjectCreator
)
.
to
receive
(
:new
).
and_return
(
double
(
execute:
true
))
.
to
receive
(
:new
).
and_return
(
double
(
execute:
project
))
expect
{
post
:create
,
format: :js
}.
to
change
(
Namespace
,
:count
).
by
(
1
)
expect
{
post
:create
,
format: :js
on
}.
to
change
(
Namespace
,
:count
).
by
(
1
)
end
it
"takes the new namespace"
do
expect
(
Gitlab
::
BitbucketImport
::
ProjectCreator
)
.
to
receive
(
:new
).
with
(
bitbucket_repo
,
bitbucket_repo
.
name
,
an_instance_of
(
Group
),
user
,
access_params
)
.
and_return
(
double
(
execute:
true
))
.
and_return
(
double
(
execute:
project
))
post
:create
,
format: :js
post
:create
,
format: :js
on
end
end
...
...
@@ -184,17 +206,17 @@ describe Import::BitbucketController do
it
"doesn't create the namespace"
do
expect
(
Gitlab
::
BitbucketImport
::
ProjectCreator
)
.
to
receive
(
:new
).
and_return
(
double
(
execute:
true
))
.
to
receive
(
:new
).
and_return
(
double
(
execute:
project
))
expect
{
post
:create
,
format: :js
}.
not_to
change
(
Namespace
,
:count
)
expect
{
post
:create
,
format: :js
on
}.
not_to
change
(
Namespace
,
:count
)
end
it
"takes the current user's namespace"
do
expect
(
Gitlab
::
BitbucketImport
::
ProjectCreator
)
.
to
receive
(
:new
).
with
(
bitbucket_repo
,
bitbucket_repo
.
name
,
user
.
namespace
,
user
,
access_params
)
.
and_return
(
double
(
execute:
true
))
.
and_return
(
double
(
execute:
project
))
post
:create
,
format: :js
post
:create
,
format: :js
on
end
end
end
...
...
@@ -212,9 +234,9 @@ describe Import::BitbucketController do
it
'takes the selected namespace and name'
do
expect
(
Gitlab
::
BitbucketImport
::
ProjectCreator
)
.
to
receive
(
:new
).
with
(
bitbucket_repo
,
test_name
,
nested_namespace
,
user
,
access_params
)
.
and_return
(
double
(
execute:
true
))
.
and_return
(
double
(
execute:
project
))
post
:create
,
{
target_namespace:
nested_namespace
.
full_path
,
new_name:
test_name
,
format: :js
}
post
:create
,
{
target_namespace:
nested_namespace
.
full_path
,
new_name:
test_name
,
format: :js
on
}
end
end
...
...
@@ -224,26 +246,26 @@ describe Import::BitbucketController do
it
'takes the selected namespace and name'
do
expect
(
Gitlab
::
BitbucketImport
::
ProjectCreator
)
.
to
receive
(
:new
).
with
(
bitbucket_repo
,
test_name
,
kind_of
(
Namespace
),
user
,
access_params
)
.
and_return
(
double
(
execute:
true
))
.
and_return
(
double
(
execute:
project
))
post
:create
,
{
target_namespace:
'foo/bar'
,
new_name:
test_name
,
format: :js
}
post
:create
,
{
target_namespace:
'foo/bar'
,
new_name:
test_name
,
format: :js
on
}
end
it
'creates the namespaces'
do
allow
(
Gitlab
::
BitbucketImport
::
ProjectCreator
)
.
to
receive
(
:new
).
with
(
bitbucket_repo
,
test_name
,
kind_of
(
Namespace
),
user
,
access_params
)
.
and_return
(
double
(
execute:
true
))
.
and_return
(
double
(
execute:
project
))
expect
{
post
:create
,
{
target_namespace:
'foo/bar'
,
new_name:
test_name
,
format: :js
}
}
expect
{
post
:create
,
{
target_namespace:
'foo/bar'
,
new_name:
test_name
,
format: :js
on
}
}
.
to
change
{
Namespace
.
count
}.
by
(
2
)
end
it
'new namespace has the right parent'
do
allow
(
Gitlab
::
BitbucketImport
::
ProjectCreator
)
.
to
receive
(
:new
).
with
(
bitbucket_repo
,
test_name
,
kind_of
(
Namespace
),
user
,
access_params
)
.
and_return
(
double
(
execute:
true
))
.
and_return
(
double
(
execute:
project
))
post
:create
,
{
target_namespace:
'foo/bar'
,
new_name:
test_name
,
format: :js
}
post
:create
,
{
target_namespace:
'foo/bar'
,
new_name:
test_name
,
format: :js
on
}
expect
(
Namespace
.
find_by_path_or_name
(
'bar'
).
parent
.
path
).
to
eq
(
'foo'
)
end
...
...
@@ -256,19 +278,29 @@ describe Import::BitbucketController do
it
'takes the selected namespace and name'
do
expect
(
Gitlab
::
BitbucketImport
::
ProjectCreator
)
.
to
receive
(
:new
).
with
(
bitbucket_repo
,
test_name
,
kind_of
(
Namespace
),
user
,
access_params
)
.
and_return
(
double
(
execute:
true
))
.
and_return
(
double
(
execute:
project
))
post
:create
,
{
target_namespace:
'foo/foobar/bar'
,
new_name:
test_name
,
format: :js
}
post
:create
,
{
target_namespace:
'foo/foobar/bar'
,
new_name:
test_name
,
format: :js
on
}
end
it
'creates the namespaces'
do
allow
(
Gitlab
::
BitbucketImport
::
ProjectCreator
)
.
to
receive
(
:new
).
with
(
bitbucket_repo
,
test_name
,
kind_of
(
Namespace
),
user
,
access_params
)
.
and_return
(
double
(
execute:
true
))
.
and_return
(
double
(
execute:
project
))
expect
{
post
:create
,
{
target_namespace:
'foo/foobar/bar'
,
new_name:
test_name
,
format: :js
}
}
expect
{
post
:create
,
{
target_namespace:
'foo/foobar/bar'
,
new_name:
test_name
,
format: :js
on
}
}
.
to
change
{
Namespace
.
count
}.
by
(
2
)
end
end
context
'when user can not create projects in the chosen namespace'
do
it
'returns 422 response'
do
other_namespace
=
create
(
:group
,
name:
'other_namespace'
)
post
:create
,
{
target_namespace:
other_namespace
.
name
,
format: :json
}
expect
(
response
).
to
have_gitlab_http_status
(
422
)
end
end
end
end
spec/controllers/import/gitlab_controller_spec.rb
View file @
71c948d6
...
...
@@ -57,6 +57,7 @@ describe Import::GitlabController do
end
describe
"POST create"
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:gitlab_username
)
{
user
.
username
}
let
(
:gitlab_user
)
do
{
username:
gitlab_username
}.
with_indifferent_access
...
...
@@ -75,14 +76,34 @@ describe Import::GitlabController do
assign_session_token
end
it
'returns 200 response when the project is imported successfully'
do
allow
(
Gitlab
::
GitlabImport
::
ProjectCreator
)
.
to
receive
(
:new
).
with
(
gitlab_repo
,
user
.
namespace
,
user
,
access_params
)
.
and_return
(
double
(
execute:
project
))
post
:create
,
format: :json
expect
(
response
).
to
have_gitlab_http_status
(
200
)
end
it
'returns 422 response when the project could not be imported'
do
allow
(
Gitlab
::
GitlabImport
::
ProjectCreator
)
.
to
receive
(
:new
).
with
(
gitlab_repo
,
user
.
namespace
,
user
,
access_params
)
.
and_return
(
double
(
execute:
build
(
:project
)))
post
:create
,
format: :json
expect
(
response
).
to
have_gitlab_http_status
(
422
)
end
context
"when the repository owner is the GitLab.com user"
do
context
"when the GitLab.com user and GitLab server user's usernames match"
do
it
"takes the current user's namespace"
do
expect
(
Gitlab
::
GitlabImport
::
ProjectCreator
)
.
to
receive
(
:new
).
with
(
gitlab_repo
,
user
.
namespace
,
user
,
access_params
)
.
and_return
(
double
(
execute:
true
))
.
and_return
(
double
(
execute:
project
))
post
:create
,
format: :js
post
:create
,
format: :js
on
end
end
...
...
@@ -92,9 +113,9 @@ describe Import::GitlabController do
it
"takes the current user's namespace"
do
expect
(
Gitlab
::
GitlabImport
::
ProjectCreator
)
.
to
receive
(
:new
).
with
(
gitlab_repo
,
user
.
namespace
,
user
,
access_params
)
.
and_return
(
double
(
execute:
true
))
.
and_return
(
double
(
execute:
project
))
post
:create
,
format: :js
post
:create
,
format: :js
on
end
end
end
...
...
@@ -118,9 +139,9 @@ describe Import::GitlabController do
it
"takes the existing namespace"
do
expect
(
Gitlab
::
GitlabImport
::
ProjectCreator
)
.
to
receive
(
:new
).
with
(
gitlab_repo
,
existing_namespace
,
user
,
access_params
)
.
and_return
(
double
(
execute:
true
))
.
and_return
(
double
(
execute:
project
))
post
:create
,
format: :js
post
:create
,
format: :js
on
end
end
...
...
@@ -129,7 +150,7 @@ describe Import::GitlabController do
expect
(
Gitlab
::
GitlabImport
::
ProjectCreator
)
.
not_to
receive
(
:new
)
post
:create
,
format: :js
post
:create
,
format: :js
on
end
end
end
...
...
@@ -138,17 +159,17 @@ describe Import::GitlabController do
context
"when current user can create namespaces"
do
it
"creates the namespace"
do
expect
(
Gitlab
::
GitlabImport
::
ProjectCreator
)
.
to
receive
(
:new
).
and_return
(
double
(
execute:
true
))
.
to
receive
(
:new
).
and_return
(
double
(
execute:
project
))
expect
{
post
:create
,
format: :js
}.
to
change
(
Namespace
,
:count
).
by
(
1
)
expect
{
post
:create
,
format: :js
on
}.
to
change
(
Namespace
,
:count
).
by
(
1
)
end
it
"takes the new namespace"
do
expect
(
Gitlab
::
GitlabImport
::
ProjectCreator
)
.
to
receive
(
:new
).
with
(
gitlab_repo
,
an_instance_of
(
Group
),
user
,
access_params
)
.
and_return
(
double
(
execute:
true
))
.
and_return
(
double
(
execute:
project
))
post
:create
,
format: :js
post
:create
,
format: :js
on
end
end
...
...
@@ -159,17 +180,17 @@ describe Import::GitlabController do
it
"doesn't create the namespace"
do
expect
(
Gitlab
::
GitlabImport
::
ProjectCreator
)
.
to
receive
(
:new
).
and_return
(
double
(
execute:
true
))
.
to
receive
(
:new
).
and_return
(
double
(
execute:
project
))
expect
{
post
:create
,
format: :js
}.
not_to
change
(
Namespace
,
:count
)
expect
{
post
:create
,
format: :js
on
}.
not_to
change
(
Namespace
,
:count
)
end
it
"takes the current user's namespace"
do
expect
(
Gitlab
::
GitlabImport
::
ProjectCreator
)
.
to
receive
(
:new
).
with
(
gitlab_repo
,
user
.
namespace
,
user
,
access_params
)
.
and_return
(
double
(
execute:
true
))
.
and_return
(
double
(
execute:
project
))
post
:create
,
format: :js
post
:create
,
format: :js
on
end
end
end
...
...
@@ -185,9 +206,9 @@ describe Import::GitlabController do
it
'takes the selected namespace and name'
do
expect
(
Gitlab
::
GitlabImport
::
ProjectCreator
)
.
to
receive
(
:new
).
with
(
gitlab_repo
,
nested_namespace
,
user
,
access_params
)
.
and_return
(
double
(
execute:
true
))
.
and_return
(
double
(
execute:
project
))
post
:create
,
{
target_namespace:
nested_namespace
.
full_path
,
format: :js
}
post
:create
,
{
target_namespace:
nested_namespace
.
full_path
,
format: :js
on
}
end
end
...
...
@@ -197,26 +218,26 @@ describe Import::GitlabController do
it
'takes the selected namespace and name'
do
expect
(
Gitlab
::
GitlabImport
::
ProjectCreator
)
.
to
receive
(
:new
).
with
(
gitlab_repo
,
kind_of
(
Namespace
),
user
,
access_params
)
.
and_return
(
double
(
execute:
true
))
.
and_return
(
double
(
execute:
project
))
post
:create
,
{
target_namespace:
'foo/bar'
,
format: :js
}
post
:create
,
{
target_namespace:
'foo/bar'
,
format: :js
on
}
end
it
'creates the namespaces'
do
allow
(
Gitlab
::
GitlabImport
::
ProjectCreator
)
.
to
receive
(
:new
).
with
(
gitlab_repo
,
kind_of
(
Namespace
),
user
,
access_params
)
.
and_return
(
double
(
execute:
true
))
.
and_return
(
double
(
execute:
project
))
expect
{
post
:create
,
{
target_namespace:
'foo/bar'
,
format: :js
}
}
expect
{
post
:create
,
{
target_namespace:
'foo/bar'
,
format: :js
on
}
}
.
to
change
{
Namespace
.
count
}.
by
(
2
)
end
it
'new namespace has the right parent'
do
allow
(
Gitlab
::
GitlabImport
::
ProjectCreator
)
.
to
receive
(
:new
).
with
(
gitlab_repo
,
kind_of
(
Namespace
),
user
,
access_params
)
.
and_return
(
double
(
execute:
true
))
.
and_return
(
double
(
execute:
project
))
post
:create
,
{
target_namespace:
'foo/bar'
,
format: :js
}
post
:create
,
{
target_namespace:
'foo/bar'
,
format: :js
on
}
expect
(
Namespace
.
find_by_path_or_name
(
'bar'
).
parent
.
path
).
to
eq
(
'foo'
)
end
...
...
@@ -229,20 +250,30 @@ describe Import::GitlabController do
it
'takes the selected namespace and name'
do
expect
(
Gitlab
::
GitlabImport
::
ProjectCreator
)
.
to
receive
(
:new
).
with
(
gitlab_repo
,
kind_of
(
Namespace
),
user
,
access_params
)
.
and_return
(
double
(
execute:
true
))
.
and_return
(
double
(
execute:
project
))
post
:create
,
{
target_namespace:
'foo/foobar/bar'
,
format: :js
}
post
:create
,
{
target_namespace:
'foo/foobar/bar'
,
format: :js
on
}
end
it
'creates the namespaces'
do
allow
(
Gitlab
::
GitlabImport
::
ProjectCreator
)
.
to
receive
(
:new
).
with
(
gitlab_repo
,
kind_of
(
Namespace
),
user
,
access_params
)
.
and_return
(
double
(
execute:
true
))
.
and_return
(
double
(
execute:
project
))
expect
{
post
:create
,
{
target_namespace:
'foo/foobar/bar'
,
format: :js
}
}
expect
{
post
:create
,
{
target_namespace:
'foo/foobar/bar'
,
format: :js
on
}
}
.
to
change
{
Namespace
.
count
}.
by
(
2
)
end
end
context
'when user can not create projects in the chosen namespace'
do
it
'returns 422 response'
do
other_namespace
=
create
(
:group
,
name:
'other_namespace'
)
post
:create
,
{
target_namespace:
other_namespace
.
name
,
format: :json
}
expect
(
response
).
to
have_gitlab_http_status
(
422
)
end
end
end
end
end
spec/javascripts/importer_status_spec.js
0 → 100644
View file @
71c948d6
import
{
ImporterStatus
}
from
'
~/importer_status
'
;
import
axios
from
'
~/lib/utils/axios_utils
'
;
import
MockAdapter
from
'
axios-mock-adapter
'
;
describe
(
'
Importer Status
'
,
()
=>
{
describe
(
'
addToImport
'
,
()
=>
{
let
instance
;
let
mock
;
const
importUrl
=
'
/import_url
'
;
beforeEach
(()
=>
{
setFixtures
(
`
<tr id="repo_123">
<td class="import-target"></td>
<td class="import-actions job-status">
<button name="button" type="submit" class="btn btn-import js-add-to-import">
</button>
</td>
</tr>
`
);
spyOn
(
ImporterStatus
.
prototype
,
'
initStatusPage
'
).
and
.
callFake
(()
=>
{});
spyOn
(
ImporterStatus
.
prototype
,
'
setAutoUpdate
'
).
and
.
callFake
(()
=>
{});
instance
=
new
ImporterStatus
(
''
,
importUrl
);
mock
=
new
MockAdapter
(
axios
);
});
afterEach
(()
=>
{
mock
.
restore
();
});
it
(
'
sets table row to active after post request
'
,
(
done
)
=>
{
mock
.
onPost
(
importUrl
).
reply
(
200
,
{
id
:
1
,
full_path
:
'
/full_path
'
,
});
instance
.
addToImport
({
currentTarget
:
document
.
querySelector
(
'
.js-add-to-import
'
),
})
.
then
(()
=>
{
expect
(
document
.
querySelector
(
'
tr
'
).
classList
.
contains
(
'
active
'
)).
toEqual
(
true
);
done
();
})
.
catch
(
done
.
fail
);
});
});
});
spec/support/controllers/githubish_import_controller_shared_examples.rb
View file @
71c948d6
This diff is collapsed.
Click to expand it.
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