From f1277fbf0bbe8de330d5d80fdfe411a0c8571022 Mon Sep 17 00:00:00 2001 From: James Lopez Date: Fri, 7 Sep 2018 14:43:51 +0200 Subject: refactor code based on feedback --- app/controllers/projects_controller.rb | 2 +- app/models/project.rb | 6 +++--- lib/api/project_export.rb | 4 ++-- .../after_export_strategies/base_after_export_strategy.rb | 6 +++--- .../import_export/after_export_strategies/web_upload_strategy.rb | 4 ++-- lib/tasks/gitlab/update_templates.rake | 2 +- .../after_export_strategies/base_after_export_strategy_spec.rb | 2 +- spec/models/project_spec.rb | 2 +- spec/requests/api/project_export_spec.rb | 2 +- spec/support/import_export/export_file_helper.rb | 2 +- 10 files changed, 16 insertions(+), 16 deletions(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index f4049bbfa46..98076791ab9 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -191,7 +191,7 @@ class ProjectsController < Projects::ApplicationController end def download_export - if @project.export_project_exists? + if @project.export_file_exists? send_upload(@project.export_file) else redirect_to( diff --git a/app/models/project.rb b/app/models/project.rb index 60d3e99252f..e224eb52a3f 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1738,7 +1738,7 @@ class Project < ActiveRecord::Base :started elsif after_export_in_progress? :after_export_action - elsif export_project_exists? + elsif export_file_exists? :finished else :none @@ -1754,13 +1754,13 @@ class Project < ActiveRecord::Base end def remove_exports - return unless export_project_exists? + return unless export_file_exists? import_export_upload.remove_export_file! import_export_upload.save end - def export_project_exists? + def export_file_exists? export_file&.file end diff --git a/lib/api/project_export.rb b/lib/api/project_export.rb index 9163887ac61..8562ae6d737 100644 --- a/lib/api/project_export.rb +++ b/lib/api/project_export.rb @@ -21,8 +21,8 @@ module API detail 'This feature was introduced in GitLab 10.6.' end get ':id/export/download' do - if user_project.export_project_exists? - present_carrierwave_file!(user_ project.export_file) + if user_project.export_file_exists? + present_carrierwave_file!(user_project.export_file) else render_api_error!('404 Not found or has expired', 404) end diff --git a/lib/gitlab/import_export/after_export_strategies/base_after_export_strategy.rb b/lib/gitlab/import_export/after_export_strategies/base_after_export_strategy.rb index 21624cad43a..7cbf653dd97 100644 --- a/lib/gitlab/import_export/after_export_strategies/base_after_export_strategy.rb +++ b/lib/gitlab/import_export/after_export_strategies/base_after_export_strategy.rb @@ -53,7 +53,7 @@ module Gitlab end def self.lock_file_path(project) - return unless project.export_path || object_storage? + return unless project.export_path || export_file_exists? lock_path = project.import_export_shared.archive_path @@ -83,8 +83,8 @@ module Gitlab errors.full_messages.each { |msg| project.import_export_shared.add_error_message(msg) } end - def object_storage? - project.export_project_exists? + def export_file_exists? + project.export_file_exists? end end end diff --git a/lib/gitlab/import_export/after_export_strategies/web_upload_strategy.rb b/lib/gitlab/import_export/after_export_strategies/web_upload_strategy.rb index 01c1bca7ec9..4f29bdcea2c 100644 --- a/lib/gitlab/import_export/after_export_strategies/web_upload_strategy.rb +++ b/lib/gitlab/import_export/after_export_strategies/web_upload_strategy.rb @@ -44,7 +44,7 @@ module Gitlab end def export_file - project.export_file.open + project.export_file.open end def send_file_options @@ -59,7 +59,7 @@ module Gitlab end def export_size - project.export_file.file.size + project.export_file.file.size end end end diff --git a/lib/tasks/gitlab/update_templates.rake b/lib/tasks/gitlab/update_templates.rake index be22032287c..ef6a32d6730 100644 --- a/lib/tasks/gitlab/update_templates.rake +++ b/lib/tasks/gitlab/update_templates.rake @@ -54,7 +54,7 @@ namespace :gitlab do end Projects::ImportExport::ExportService.new(project, admin).execute - download_or_copy_upload( project.export_file, template.archive_path) + download_or_copy_upload(project.export_file, template.archive_path) Projects::DestroyService.new(admin, project).execute puts "Exported #{template.name}".green end diff --git a/spec/lib/gitlab/import_export/after_export_strategies/base_after_export_strategy_spec.rb b/spec/lib/gitlab/import_export/after_export_strategies/base_after_export_strategy_spec.rb index df8e06d8ec5..9a442de2900 100644 --- a/spec/lib/gitlab/import_export/after_export_strategies/base_after_export_strategy_spec.rb +++ b/spec/lib/gitlab/import_export/after_export_strategies/base_after_export_strategy_spec.rb @@ -12,7 +12,7 @@ describe Gitlab::ImportExport::AfterExportStrategies::BaseAfterExportStrategy do end it 'returns if project exported file is not found' do - allow(project).to receive(:export_project_exists?).and_return(false) + allow(project).to receive(:export_file_exists?).and_return(false) expect(service).not_to receive(:strategy_execute) diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 7e56a6d17bc..cb844cd2102 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -2859,7 +2859,7 @@ describe Project do it 'removes the export' do project.remove_exports - expect(project.export_project_exists?).to be_falsey + expect(project.export_file_exists?).to be_falsey end end diff --git a/spec/requests/api/project_export_spec.rb b/spec/requests/api/project_export_spec.rb index 8e835bcd470..0586025956f 100644 --- a/spec/requests/api/project_export_spec.rb +++ b/spec/requests/api/project_export_spec.rb @@ -189,7 +189,7 @@ describe API::ProjectExport do end it 'has removed the export' do - expect(project_after_export.export_project_exists?).to be_falsey + expect(project_after_export.export_file_exists?).to be_falsey end it_behaves_like '404 response' do diff --git a/spec/support/import_export/export_file_helper.rb b/spec/support/import_export/export_file_helper.rb index 248d34e59dd..d9ed405baf4 100644 --- a/spec/support/import_export/export_file_helper.rb +++ b/spec/support/import_export/export_file_helper.rb @@ -52,7 +52,7 @@ module ExportFileHelper # Expands the compressed file for an exported project into +tmpdir+ def in_directory_with_expanded_export(project) Dir.mktmpdir do |tmpdir| - export_file = project.export_file.path + export_file = project.export_file.path _output, exit_status = Gitlab::Popen.popen(%W{tar -zxf #{export_file} -C #{tmpdir}}) yield(exit_status, tmpdir) -- cgit v1.2.1