Skip to content

Commit

Permalink
Merge pull request rails#42598 from santib/remove-deprecated-methods-…
Browse files Browse the repository at this point in the history
…active-storage

Remove already deprecated methods in ActiveStorage
  • Loading branch information
pixeltrix authored Jun 28, 2021
2 parents f73b777 + 65b1e1b commit 306449b
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 43 deletions.
5 changes: 5 additions & 0 deletions activestorage/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
* Remove deprecated methods: `build_after_upload`, `create_after_upload!` in favor of `create_and_upload!`,
and `service_url` in favor of `url`.

*Santiago Bartesaghi*

* Add support of `strict_loading_by_default` to `ActiveStorage::Representations` controllers

*Anton Topchii*, *Andrew White*
Expand Down
14 changes: 0 additions & 14 deletions activestorage/app/models/active_storage/blob.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,6 @@ def find_signed!(id, record: nil, purpose: :blob_id)
super(id, purpose: purpose)
end

def build_after_upload(io:, filename:, content_type: nil, metadata: nil, service_name: nil, identify: true, record: nil) #:nodoc:
new(filename: filename, content_type: content_type, metadata: metadata, service_name: service_name).tap do |blob|
blob.upload(io, identify: identify)
end
end

deprecate :build_after_upload

def build_after_unfurling(key: nil, io:, filename:, content_type: nil, metadata: nil, service_name: nil, identify: true, record: nil) #:nodoc:
new(key: key, filename: filename, content_type: content_type, metadata: metadata, service_name: service_name).tap do |blob|
blob.unfurl(io, identify: identify)
Expand All @@ -115,9 +107,6 @@ def create_and_upload!(key: nil, io:, filename:, content_type: nil, metadata: ni
end
end

alias_method :create_after_upload!, :create_and_upload!
deprecate create_after_upload!: :create_and_upload!

# Returns a saved blob _without_ uploading a file to the service. This blob will point to a key where there is
# no file yet. It's intended to be used together with a client-side upload, which will first create the blob
# in order to produce the signed URL for uploading. This signed URL points to the key generated by the blob.
Expand Down Expand Up @@ -208,9 +197,6 @@ def url(expires_in: ActiveStorage.service_urls_expire_in, disposition: :inline,
content_type: content_type_for_serving, disposition: forced_disposition_for_serving || disposition, **options
end

alias_method :service_url, :url
deprecate service_url: :url

# Returns a URL that can be used to directly upload a file for this blob on the service. This URL is intended to be
# short-lived for security and only generated on-demand by the client-side JavaScript responsible for doing the uploading.
def service_url_for_direct_upload(expires_in: ActiveStorage.service_urls_expire_in)
Expand Down
3 changes: 0 additions & 3 deletions activestorage/app/models/active_storage/preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ def url(**options)
end
end

alias_method :service_url, :url
deprecate service_url: :url

# Returns a combination key of the blob and the variation that together identifies a specific variant.
def key
if processed?
Expand Down
3 changes: 0 additions & 3 deletions activestorage/app/models/active_storage/variant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,6 @@ def url(expires_in: ActiveStorage.service_urls_expire_in, disposition: :inline)
service.url key, expires_in: expires_in, disposition: disposition, filename: filename, content_type: content_type
end

alias_method :service_url, :url
deprecate service_url: :url

# Downloads the file associated with this variant. If no block is given, the entire file is read into memory and returned.
# That'll use a lot of RAM for very large files. If a block is given, then the download is streamed and yielded in chunks.
def download(&block)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ def image

delegate :key, :url, :download, to: :image, allow_nil: true

alias_method :service_url, :url
deprecate service_url: :url

private
def transform_blob
blob.open do |input|
Expand Down
20 changes: 0 additions & 20 deletions activestorage/test/models/blob_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,6 @@ class ActiveStorage::BlobTest < ActiveSupport::TestCase
assert_equal data, blob.download
end

test "create_after_upload! has the same effect as create_and_upload!" do
data = "Some other, even more funky file"
blob = assert_deprecated do
ActiveStorage::Blob.create_after_upload!(io: StringIO.new(data), filename: "funky.bin")
end

assert blob.persisted?
assert_equal data, blob.download
end

test "build_after_upload uploads to service but does not save the Blob" do
data = "A potentially overwriting file"
blob = assert_deprecated do
ActiveStorage::Blob.build_after_upload(io: StringIO.new(data), filename: "funky.bin")
end

assert_not blob.persisted?
assert_equal data, blob.download
end

test "create_and_upload sets byte size and checksum" do
data = "Hello world!"
blob = create_blob data: data
Expand Down

0 comments on commit 306449b

Please sign in to comment.