Commit 9e858cb4 authored by James Lopez's avatar James Lopez

Fix project templates spec failures

parent ec662fcf
......@@ -22,7 +22,6 @@ module EE
if custom_template
params[:import_type] = 'gitlab_custom_project_template'
params[:import_source] = custom_template.id
end
end
......
......@@ -8,8 +8,12 @@ module EE
validates :export_into_project_id, presence: true
attr_reader :params
def initialize(export_into_project_id:)
super
@params = {}
end
protected
......@@ -17,7 +21,7 @@ module EE
def strategy_execute
return unless export_into_project_exists?
prepare_template_environment(export_file_path)
prepare_template_environment(export_file)
set_import_attributes
......@@ -26,18 +30,18 @@ module EE
project.remove_exported_project_file
end
def export_file_path
strong_memoize(:export_file_path) do
def export_file
strong_memoize(:export_file) do
if object_storage?
project.import_export_upload.export_file.path
project.import_export_upload.export_file&.file
else
project.export_project_path
File.open(project.export_project_path)
end
end
end
def set_import_attributes
::Project.update(export_into_project_id, import_source: import_upload_path)
::Project.update(export_into_project_id, params)
end
def export_into_project_exists?
......
......@@ -71,12 +71,33 @@ describe ProjectsController do
stub_ee_application_setting(custom_project_templates_group_id: group.id)
end
it 'creates the project from project template' do
post :create, project: templates_params
context 'old upload' do
before do
stub_feature_flags(import_export_object_storage: false)
end
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
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
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
......
......@@ -23,12 +23,14 @@ describe EE::Gitlab::ImportExport::AfterExportStrategies::CustomTemplateExportIm
describe '#execute' do
it 'updates the project import_source with the path to import' do
allow(subject).to receive(:import_upload_path).and_return('path')
expect(Project).to receive(:update).with(project.id, import_source: 'path').and_call_original
path = Tempfile.new.path
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)
expect(project.reload.import_source).to eq 'path'
expect(project.reload.import_source).to eq path
end
it 'imports repository' do
......@@ -45,18 +47,16 @@ describe EE::Gitlab::ImportExport::AfterExportStrategies::CustomTemplateExportIm
subject.execute(user, project_template)
end
describe 'export_file_path' do
describe 'export_file' do
before do
allow(subject).to receive(:project).and_return(project_template)
end
after do
subject.send(:export_file_path)
end
context 'without object storage' 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
......@@ -64,7 +64,9 @@ describe EE::Gitlab::ImportExport::AfterExportStrategies::CustomTemplateExportIm
let(:project_template) { create(:project, :with_object_export) }
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
......
......@@ -3,7 +3,7 @@ module Gitlab
include Gitlab::Utils::StrongMemoize
def prepare_template_environment(file)
return unless file&.path.present?
return unless file
if Gitlab::ImportExport.object_storage?
params[:import_export_upload] = ImportExportUpload.new(import_file: file)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment