diff --git a/CHANGELOG.md b/CHANGELOG.md index bb914fb..ce96222 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ ### Fixed - Fix `calc_hashsums` info option name. +- Fix enabling `use_s3_urls` or `use_gcs_urls` without using S3 or GCS service ## [3.0.0] - 2023-12-28 diff --git a/lib/imgproxy/url_adapters/active_storage.rb b/lib/imgproxy/url_adapters/active_storage.rb index ffc2724..b6ff53b 100644 --- a/lib/imgproxy/url_adapters/active_storage.rb +++ b/lib/imgproxy/url_adapters/active_storage.rb @@ -30,6 +30,8 @@ def s3_url(image) end def use_s3_url(image) + return unless defined?(::ActiveStorage::Service::S3Service) + config.use_s3_urls && service(image).is_a?(::ActiveStorage::Service::S3Service) end @@ -38,6 +40,8 @@ def gcs_url(image) end def use_gcs_url(image) + return unless defined?(::ActiveStorage::Service::GCSService) + config.use_gcs_urls && service(image).is_a?(::ActiveStorage::Service::GCSService) end diff --git a/spec/url_adapters/active_storage_spec.rb b/spec/url_adapters/active_storage_spec.rb index c06a371..c9620cb 100644 --- a/spec/url_adapters/active_storage_spec.rb +++ b/spec/url_adapters/active_storage_spec.rb @@ -93,6 +93,15 @@ end end + context 'with non-S3 service' do + let(:active_storage_service_name) { :local } + + it 'builds http URL' do + expect(Imgproxy.url_for(user.avatar)).to end_with \ + "/plain/#{Rails.application.routes.url_helpers.url_for(user.avatar)}" + end + end + describe "extension" do it "builds URL with ActiveStorage extension" do expect(user.avatar.imgproxy_url(width: 200)).to eq( @@ -134,6 +143,15 @@ end end + context 'with non-GCS service' do + let(:active_storage_service_name) { :local } + + it 'builds http URL' do + expect(Imgproxy.url_for(user.avatar)).to end_with \ + "/plain/#{Rails.application.routes.url_helpers.url_for(user.avatar)}" + end + end + describe "extension" do it "build URL with ActiveStorage extension" do expect(user.avatar.imgproxy_url(width: 200)).to eq(