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
9e858cb4
Commit
9e858cb4
authored
Aug 03, 2018
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix project templates spec failures
parent
ec662fcf
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
49 additions
and
23 deletions
+49
-23
ee/app/services/ee/projects/gitlab_projects_import_service.rb
...pp/services/ee/projects/gitlab_projects_import_service.rb
+0
-1
ee/lib/ee/gitlab/import_export/after_export_strategies/custom_template_export_import_strategy.rb
...port_strategies/custom_template_export_import_strategy.rb
+10
-6
ee/spec/controllers/projects_controller_spec.rb
ee/spec/controllers/projects_controller_spec.rb
+26
-5
ee/spec/lib/ee/gitlab/import_export/after_export_strategies/custom_template_export_import_strategy_spec.rb
...strategies/custom_template_export_import_strategy_spec.rb
+12
-10
lib/gitlab/template_helper.rb
lib/gitlab/template_helper.rb
+1
-1
No files found.
ee/app/services/ee/projects/gitlab_projects_import_service.rb
View file @
9e858cb4
...
@@ -22,7 +22,6 @@ module EE
...
@@ -22,7 +22,6 @@ module EE
if
custom_template
if
custom_template
params
[
:import_type
]
=
'gitlab_custom_project_template'
params
[
:import_type
]
=
'gitlab_custom_project_template'
params
[
:import_source
]
=
custom_template
.
id
end
end
end
end
...
...
ee/lib/ee/gitlab/import_export/after_export_strategies/custom_template_export_import_strategy.rb
View file @
9e858cb4
...
@@ -8,8 +8,12 @@ module EE
...
@@ -8,8 +8,12 @@ module EE
validates
:export_into_project_id
,
presence:
true
validates
:export_into_project_id
,
presence:
true
attr_reader
:params
def
initialize
(
export_into_project_id
:)
def
initialize
(
export_into_project_id
:)
super
super
@params
=
{}
end
end
protected
protected
...
@@ -17,7 +21,7 @@ module EE
...
@@ -17,7 +21,7 @@ module EE
def
strategy_execute
def
strategy_execute
return
unless
export_into_project_exists?
return
unless
export_into_project_exists?
prepare_template_environment
(
export_file
_path
)
prepare_template_environment
(
export_file
)
set_import_attributes
set_import_attributes
...
@@ -26,18 +30,18 @@ module EE
...
@@ -26,18 +30,18 @@ module EE
project
.
remove_exported_project_file
project
.
remove_exported_project_file
end
end
def
export_file
_path
def
export_file
strong_memoize
(
:export_file
_path
)
do
strong_memoize
(
:export_file
)
do
if
object_storage?
if
object_storage?
project
.
import_export_upload
.
export_file
.
path
project
.
import_export_upload
.
export_file
&
.
file
else
else
project
.
export_project_path
File
.
open
(
project
.
export_project_path
)
end
end
end
end
end
end
def
set_import_attributes
def
set_import_attributes
::
Project
.
update
(
export_into_project_id
,
import_source:
import_upload_path
)
::
Project
.
update
(
export_into_project_id
,
params
)
end
end
def
export_into_project_exists?
def
export_into_project_exists?
...
...
ee/spec/controllers/projects_controller_spec.rb
View file @
9e858cb4
...
@@ -71,12 +71,33 @@ describe ProjectsController do
...
@@ -71,12 +71,33 @@ describe ProjectsController do
stub_ee_application_setting
(
custom_project_templates_group_id:
group
.
id
)
stub_ee_application_setting
(
custom_project_templates_group_id:
group
.
id
)
end
end
it
'creates the project from project template'
do
context
'old upload'
do
post
:create
,
project:
templates_params
before
do
stub_feature_flags
(
import_export_object_storage:
false
)
end
created_project
=
Project
.
find_by_path
(
'foo'
)
it
'creates the project from project template'
do
expect
(
flash
[
:notice
]).
to
eq
"Project 'foo' was successfully created."
post
:create
,
project:
templates_params
expect
(
created_project
.
repository
.
empty?
).
to
be
false
created_project
=
Project
.
find_by_path
(
'foo'
)
expect
(
flash
[
:notice
]).
to
eq
"Project 'foo' was successfully created."
expect
(
created_project
.
repository
.
empty?
).
to
be
false
end
end
context
'object storage'
do
before
do
stub_feature_flags
(
import_export_object_storage:
true
)
stub_uploads_object_storage
(
FileUploader
)
end
it
'creates the project from project template'
do
post
:create
,
project:
templates_params
created_project
=
Project
.
find_by_path
(
'foo'
)
expect
(
flash
[
:notice
]).
to
eq
"Project 'foo' was successfully created."
expect
(
created_project
.
repository
.
empty?
).
to
be
false
end
end
end
end
end
...
...
ee/spec/lib/ee/gitlab/import_export/after_export_strategies/custom_template_export_import_strategy_spec.rb
View file @
9e858cb4
...
@@ -23,12 +23,14 @@ describe EE::Gitlab::ImportExport::AfterExportStrategies::CustomTemplateExportIm
...
@@ -23,12 +23,14 @@ describe EE::Gitlab::ImportExport::AfterExportStrategies::CustomTemplateExportIm
describe
'#execute'
do
describe
'#execute'
do
it
'updates the project import_source with the path to import'
do
it
'updates the project import_source with the path to import'
do
allow
(
subject
).
to
receive
(
:import_upload_path
).
and_return
(
'path'
)
path
=
Tempfile
.
new
.
path
expect
(
Project
).
to
receive
(
:update
).
with
(
project
.
id
,
import_source:
'path'
).
and_call_original
allow
(
subject
).
to
receive
(
:import_upload_path
).
and_return
(
path
)
expect
(
Project
).
to
receive
(
:update
).
with
(
project
.
id
,
import_source:
path
).
and_call_original
subject
.
execute
(
user
,
project_template
)
subject
.
execute
(
user
,
project_template
)
expect
(
project
.
reload
.
import_source
).
to
eq
'path'
expect
(
project
.
reload
.
import_source
).
to
eq
path
end
end
it
'imports repository'
do
it
'imports repository'
do
...
@@ -45,18 +47,16 @@ describe EE::Gitlab::ImportExport::AfterExportStrategies::CustomTemplateExportIm
...
@@ -45,18 +47,16 @@ describe EE::Gitlab::ImportExport::AfterExportStrategies::CustomTemplateExportIm
subject
.
execute
(
user
,
project_template
)
subject
.
execute
(
user
,
project_template
)
end
end
describe
'export_file
_path
'
do
describe
'export_file'
do
before
do
before
do
allow
(
subject
).
to
receive
(
:project
).
and_return
(
project_template
)
allow
(
subject
).
to
receive
(
:project
).
and_return
(
project_template
)
end
end
after
do
subject
.
send
(
:export_file_path
)
end
context
'without object storage'
do
context
'without object storage'
do
it
'returns the local path'
do
it
'returns the local path'
do
expect
(
project_template
).
to
receive
(
:export_project_path
)
subject
.
execute
(
user
,
project_template
)
expect
(
subject
.
send
(
:export_file
)).
not_to
be_nil
end
end
end
end
...
@@ -64,7 +64,9 @@ describe EE::Gitlab::ImportExport::AfterExportStrategies::CustomTemplateExportIm
...
@@ -64,7 +64,9 @@ describe EE::Gitlab::ImportExport::AfterExportStrategies::CustomTemplateExportIm
let
(
:project_template
)
{
create
(
:project
,
:with_object_export
)
}
let
(
:project_template
)
{
create
(
:project
,
:with_object_export
)
}
it
'returns the path from object storage'
do
it
'returns the path from object storage'
do
expect
(
project_template
.
import_export_upload
.
export_file
).
to
receive
(
:path
)
subject
.
execute
(
user
,
project_template
)
expect
(
subject
.
send
(
:export_file
)).
not_to
be_nil
end
end
end
end
end
end
...
...
lib/gitlab/template_helper.rb
View file @
9e858cb4
...
@@ -3,7 +3,7 @@ module Gitlab
...
@@ -3,7 +3,7 @@ module Gitlab
include
Gitlab
::
Utils
::
StrongMemoize
include
Gitlab
::
Utils
::
StrongMemoize
def
prepare_template_environment
(
file
)
def
prepare_template_environment
(
file
)
return
unless
file
&
.
path
.
present?
return
unless
file
if
Gitlab
::
ImportExport
.
object_storage?
if
Gitlab
::
ImportExport
.
object_storage?
params
[
:import_export_upload
]
=
ImportExportUpload
.
new
(
import_file:
file
)
params
[
:import_export_upload
]
=
ImportExportUpload
.
new
(
import_file:
file
)
...
...
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