Refactor:Implement Carrierwave Monkeypatch in all Envs (#11233)

* Refactor:Implement Carrierwave Monkeypatch for all Envs

* add a spec for monkey patch
This commit is contained in:
Molly Struve 2020-11-03 11:51:53 -05:00 committed by GitHub
parent a1b670e63c
commit a741dceace
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 9 deletions

View file

@ -3,15 +3,13 @@
# We also force this to use the SiteConfig instead of APP_DOMAIN because the value
# could change after initial boot.
if Rails.env.production?
module CarrierWave
module Storage
class Fog < Abstract
class File
include CarrierWave::Utilities::Uri
def url
public_url.gsub(ApplicationConfig["APP_DOMAIN"], SiteConfig.app_domain)
end
module CarrierWave
module Storage
class Fog < Abstract
class File
include CarrierWave::Utilities::Uri
def url
public_url.gsub(ApplicationConfig["APP_DOMAIN"], SiteConfig.app_domain)
end
end
end

View file

@ -0,0 +1,18 @@
# rubocop:disable RSpec/FilePath
require "rails_helper"
describe CarrierWave::Storage::Fog::File do
it "replaces ApplicationConfig APP_DOMAIN with SiteConfig.app_domain" do
CarrierWave::Uploader::Base.fog_credentials = {
provider: "AWS", aws_access_key_id: "foo", aws_secret_access_key: "bar"
}
allow(ApplicationConfig).to receive(:[]).with("APP_DOMAIN").and_return("s3.amazonaws.com")
allow(SiteConfig).to receive(:app_domain).and_return("forem.com")
file_url = described_class.new(
CarrierWave::Uploader::Base, nil, "/a/path"
).url
expect(file_url).to include("forem.com")
end
end
# rubocop:enable RSpec/FilePath