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:
parent
a1b670e63c
commit
a741dceace
2 changed files with 25 additions and 9 deletions
|
|
@ -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
|
||||
|
|
|
|||
18
spec/initializers/carrierwave_monkeypatch_spec.rb
Normal file
18
spec/initializers/carrierwave_monkeypatch_spec.rb
Normal 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
|
||||
Loading…
Add table
Reference in a new issue