diff options
author | George Claghorn <george.claghorn@gmail.com> | 2018-02-01 21:57:09 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-01 21:57:09 -0500 |
commit | 74aa62cb691f1abd12e244c3498dc696e0b7ef77 (patch) | |
tree | 56bb954d7d74439cefef45ec79287ec5123d7929 /activestorage | |
parent | 8f2bb58ba2a74975b737f7f7655247b447b7ac08 (diff) | |
parent | 69ae9fe6b508acdf5bdfc64c5baae70bce15fad6 (diff) | |
download | rails-74aa62cb691f1abd12e244c3498dc696e0b7ef77.tar.gz rails-74aa62cb691f1abd12e244c3498dc696e0b7ef77.tar.bz2 rails-74aa62cb691f1abd12e244c3498dc696e0b7ef77.zip |
Merge pull request #31854 from huacnlee/allow-more-options-for-service-url
Allow ActiveStorage::Blob#service_url to pass addition options to service.url
Diffstat (limited to 'activestorage')
-rw-r--r-- | activestorage/app/models/active_storage/blob.rb | 5 | ||||
-rw-r--r-- | activestorage/test/models/blob_test.rb | 20 |
2 files changed, 23 insertions, 2 deletions
diff --git a/activestorage/app/models/active_storage/blob.rb b/activestorage/app/models/active_storage/blob.rb index 6112c57cc0..892a833fae 100644 --- a/activestorage/app/models/active_storage/blob.rb +++ b/activestorage/app/models/active_storage/blob.rb @@ -109,8 +109,9 @@ class ActiveStorage::Blob < ActiveRecord::Base # with users. Instead, the +service_url+ should only be exposed as a redirect from a stable, possibly authenticated URL. # Hiding the +service_url+ behind a redirect also gives you the power to change services without updating all URLs. And # it allows permanent URLs that redirect to the +service_url+ to be cached in the view. - def service_url(expires_in: service.url_expires_in, disposition: :inline, filename: self.filename) - service.url key, expires_in: expires_in, disposition: forcibly_serve_as_binary? ? :attachment : disposition, filename: filename, content_type: content_type + def service_url(expires_in: service.url_expires_in, disposition: :inline, filename: self.filename, **options) + service.url key, expires_in: expires_in, filename: filename, content_type: content_type, + disposition: forcibly_serve_as_binary? ? :attachment : disposition, **options end # Returns a URL that can be used to directly upload a file for this blob on the service. This URL is intended to be diff --git a/activestorage/test/models/blob_test.rb b/activestorage/test/models/blob_test.rb index 664939dfa7..5cd2a94326 100644 --- a/activestorage/test/models/blob_test.rb +++ b/activestorage/test/models/blob_test.rb @@ -2,8 +2,11 @@ require "test_helper" require "database/setup" +require "active_support/testing/method_call_assertions" class ActiveStorage::BlobTest < ActiveSupport::TestCase + include ActiveSupport::Testing::MethodCallAssertions + test "create after upload sets byte size and checksum" do data = "Hello world!" blob = create_blob data: data @@ -82,6 +85,23 @@ class ActiveStorage::BlobTest < ActiveSupport::TestCase end end + test "urls allow for custom options" do + blob = create_blob(filename: "original.txt") + + options = [ + blob.key, + expires_in: blob.service.url_expires_in, + disposition: :inline, + content_type: blob.content_type, + filename: blob.filename, + thumb_size: "300x300", + thumb_mode: "crop" + ] + assert_called_with(blob.service, :url, options) do + blob.service_url(thumb_size: "300x300", thumb_mode: "crop") + end + end + test "purge deletes file from external service" do blob = create_blob |