mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +08:00
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:
@ -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: /.*/ }
|
||||||
|
@ -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)
|
||||||
|
@ -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
|
||||||
|
@ -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
|
||||||
|
Reference in New Issue
Block a user