DEV: Use a tmp directory for storing uploads in tests (#9554)

This avoids development-mode upload files from polluting the test environment
This commit is contained in:
David Taylor
2020-04-28 14:03:04 +01:00
committed by GitHub
parent 7177b9d771
commit ba616ffb50
4 changed files with 7 additions and 11 deletions

View File

@ -519,8 +519,8 @@ Discourse::Application.routes.draw do
get "uploads/short-url/:base62(.:extension)" => "uploads#show_short", constraints: { site: /\w+/, base62: /[a-zA-Z0-9]+/, extension: /[a-z0-9\._]+/i }, as: :upload_short get "uploads/short-url/:base62(.:extension)" => "uploads#show_short", constraints: { site: /\w+/, base62: /[a-zA-Z0-9]+/, extension: /[a-z0-9\._]+/i }, as: :upload_short
# used to download attachments # used to download attachments
get "uploads/:site/original/:tree:sha(.:extension)" => "uploads#show", constraints: { site: /\w+/, tree: /([a-z0-9]+\/)+/i, sha: /\h{40}/, extension: /[a-z0-9\._]+/i } get "uploads/:site/original/:tree:sha(.:extension)" => "uploads#show", constraints: { site: /\w+/, tree: /([a-z0-9]+\/)+/i, sha: /\h{40}/, extension: /[a-z0-9\._]+/i }
if Discourse.is_parallel_test? if Rails.env.test?
get "uploads/:site/:index/original/:tree:sha(.:extension)" => "uploads#show", constraints: { site: /\w+/, index: /\d+/, tree: /([a-z0-9]+\/)+/i, sha: /\h{40}/, extension: /[a-z0-9\._]+/i } get "uploads/:site/test_:index/original/:tree:sha(.:extension)" => "uploads#show", constraints: { site: /\w+/, index: /\d+/, tree: /([a-z0-9]+\/)+/i, sha: /\h{40}/, extension: /[a-z0-9\._]+/i }
end end
# used to download attachments (old route) # used to download attachments (old route)
get "uploads/:site/:id/:sha" => "uploads#show", constraints: { site: /\w+/, id: /\d+/, sha: /\h{16}/, format: /.*/ } get "uploads/:site/:id/:sha" => "uploads#show", constraints: { site: /\w+/, id: /\d+/, sha: /\h{16}/, format: /.*/ }

View File

@ -32,10 +32,8 @@ module FileStore
def upload_path def upload_path
path = File.join("uploads", RailsMultisite::ConnectionManagement.current_db) path = File.join("uploads", RailsMultisite::ConnectionManagement.current_db)
return path unless Discourse.is_parallel_test? return path if !Rails.env.test?
File.join(path, "test_#{ENV['TEST_ENV_NUMBER'].presence || '0'}")
n = ENV['TEST_ENV_NUMBER'].presence || '1'
File.join(path, n)
end end
def has_been_uploaded?(url) def has_been_uploaded?(url)

View File

@ -248,8 +248,8 @@ class S3Helper
def multisite_upload_path def multisite_upload_path
path = File.join("uploads", RailsMultisite::ConnectionManagement.current_db, "/") path = File.join("uploads", RailsMultisite::ConnectionManagement.current_db, "/")
return path unless Discourse.is_parallel_test? return path if !Rails.env.test?
File.join(path, ENV['TEST_ENV_NUMBER'].presence || '1', "/") File.join(path, "test_#{ENV['TEST_ENV_NUMBER'].presence || '0'}", "/")
end end
def s3_resource def s3_resource

View File

@ -73,9 +73,7 @@ describe BackupRestore::UploadsRestorer do
def uploads_path(database) def uploads_path(database)
path = File.join("uploads", database) path = File.join("uploads", database)
if Discourse.is_parallel_test? path = File.join(path, "test_#{ENV['TEST_ENV_NUMBER'].presence || '0'}")
path = File.join(path, ENV['TEST_ENV_NUMBER'].presence || '1')
end
"/#{path}/" "/#{path}/"
end end