2019-04-30 08:27:42 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-02-05 10:05:47 +08:00
|
|
|
require "global_path"
|
|
|
|
|
|
|
|
class GlobalPathInstance
|
|
|
|
extend GlobalPath
|
|
|
|
end
|
|
|
|
|
2022-07-28 10:27:38 +08:00
|
|
|
RSpec.describe GlobalPath do
|
2022-07-28 00:14:14 +08:00
|
|
|
describe ".cdn_relative_path" do
|
2016-02-05 10:05:47 +08:00
|
|
|
def cdn_relative_path(p)
|
|
|
|
GlobalPathInstance.cdn_relative_path(p)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "just returns path for no cdn" do
|
|
|
|
expect(cdn_relative_path("/test")).to eq("/test")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns path when a cdn is defined with a path" do
|
|
|
|
GlobalSetting.expects(:cdn_url).returns("//something.com/foo")
|
|
|
|
expect(cdn_relative_path("/test")).to eq("/foo/test")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns path when a cdn is defined with a path" do
|
|
|
|
GlobalSetting.expects(:cdn_url).returns("https://something.com:221/foo")
|
|
|
|
expect(cdn_relative_path("/test")).to eq("/foo/test")
|
|
|
|
end
|
2018-10-24 12:14:01 +08:00
|
|
|
end
|
|
|
|
|
2022-07-28 00:14:14 +08:00
|
|
|
describe ".upload_cdn_path" do
|
2018-10-24 12:14:01 +08:00
|
|
|
it "generates correctly when S3 bucket has a folder" do
|
|
|
|
global_setting :s3_access_key_id, "s3_access_key_id"
|
|
|
|
global_setting :s3_secret_access_key, "s3_secret_access_key"
|
|
|
|
global_setting :s3_bucket, "file-uploads/folder"
|
|
|
|
global_setting :s3_region, "us-west-2"
|
|
|
|
global_setting :s3_cdn_url, "https://cdn-aws.com/folder"
|
2023-01-09 19:18:21 +08:00
|
|
|
|
2018-10-24 12:14:01 +08:00
|
|
|
expect(
|
|
|
|
GlobalPathInstance.upload_cdn_path(
|
|
|
|
"#{Discourse.store.absolute_base_url}/folder/upload.jpg",
|
2023-01-09 19:18:21 +08:00
|
|
|
),
|
2018-10-24 12:14:01 +08:00
|
|
|
).to eq("https://cdn-aws.com/folder/upload.jpg")
|
|
|
|
end
|
2016-02-05 10:05:47 +08:00
|
|
|
end
|
|
|
|
end
|