2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-03-03 23:54:20 +08:00
discourse/spec/support/uploads_helpers.rb
David Taylor 0f3720395a
DEV: Refactor test-specific setting overrides into rails_helper.rb (#35594)
Having overridden defaults in the test environment can be quite
confusing. This commit moves them from `environments/test` into
`spec/rails_helper`, and also makes them overrides on the 'local process
provider' rather than the defaults provider. This means that the
defaults remain 100% consistent with production, and these overrides
work just like a user-initiated override.

Also updates a number of specs which were changing settings in
surprising ways, or relying on the incorrect defaults.

Motivation is that I'm updating qunit to pull the default site settings
from Rails, and was getting differing behavior in the development vs.
test rails environments. (ref #35477)
2025-10-27 10:14:56 +00:00

41 lines
1.2 KiB
Ruby

# frozen_string_literal: true
module UploadsHelpers
def setup_s3
SiteSetting.s3_upload_bucket = "bucket"
SiteSetting.enable_s3_uploads = true
SiteSetting.s3_region = "us-west-1"
SiteSetting.s3_upload_bucket = "s3-upload-bucket"
SiteSetting.s3_access_key_id = "some key"
SiteSetting.s3_secret_access_key = "some secrets3_region key"
dualstack = SiteSetting.Upload.use_dualstack_endpoint ? ".dualstack" : ""
stub_request(
:head,
"https://#{SiteSetting.s3_upload_bucket}.s3#{dualstack}.#{SiteSetting.s3_region}.amazonaws.com/",
)
end
def enable_secure_uploads
setup_s3
SiteSetting.secure_uploads = true
end
def stub_upload(upload)
dualstack = SiteSetting.Upload.use_dualstack_endpoint ? ".dualstack" : ""
url =
%r{https://#{SiteSetting.s3_upload_bucket}.s3#{dualstack}.#{SiteSetting.s3_region}.amazonaws.com/original/\d+X.*#{upload.sha1}.#{upload.extension}\?acl}
stub_request(:put, url)
end
def stub_s3_store
store = FileStore::S3Store.new
client = Aws::S3::Client.new(stub_responses: true)
store.s3_helper.stubs(:s3_client).returns(client)
Discourse.stubs(:store).returns(store)
end
end