mirror of https://github.com/rails/rails
Merge pull request #42506
This commit is contained in:
commit
e2585a21e3
|
@ -1,3 +1,7 @@
|
||||||
|
* Deprecate usage of `purge` and `purge_later` from the association extension.
|
||||||
|
|
||||||
|
*Jacopo Beschi*
|
||||||
|
|
||||||
* Passing extra parameters in `ActiveStorage::Blob#url` to S3 Client
|
* Passing extra parameters in `ActiveStorage::Blob#url` to S3 Client
|
||||||
|
|
||||||
This allows calls of `ActiveStorage::Blob#url` to have more interaction with
|
This allows calls of `ActiveStorage::Blob#url` to have more interaction with
|
||||||
|
|
|
@ -155,14 +155,26 @@ module ActiveStorage
|
||||||
|
|
||||||
has_many :"#{name}_attachments", -> { where(name: name) }, as: :record, class_name: "ActiveStorage::Attachment", inverse_of: :record, dependent: :destroy, strict_loading: strict_loading do
|
has_many :"#{name}_attachments", -> { where(name: name) }, as: :record, class_name: "ActiveStorage::Attachment", inverse_of: :record, dependent: :destroy, strict_loading: strict_loading do
|
||||||
def purge
|
def purge
|
||||||
|
deprecate(:purge)
|
||||||
each(&:purge)
|
each(&:purge)
|
||||||
reset
|
reset
|
||||||
end
|
end
|
||||||
|
|
||||||
def purge_later
|
def purge_later
|
||||||
|
deprecate(:purge_later)
|
||||||
each(&:purge_later)
|
each(&:purge_later)
|
||||||
reset
|
reset
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def deprecate(action)
|
||||||
|
reflection_name = proxy_association.reflection.name
|
||||||
|
attached_name = reflection_name.to_s.partition("_").first
|
||||||
|
ActiveSupport::Deprecation.warn(<<-MSG.squish)
|
||||||
|
Calling `#{action}` from `#{reflection_name}` is deprecated and will be removed in Rails 7.1.
|
||||||
|
To migrate to Rails 7.1's behavior call `#{action}` from `#{attached_name}` instead: `#{attached_name}.#{action}`.
|
||||||
|
MSG
|
||||||
|
end
|
||||||
end
|
end
|
||||||
has_many :"#{name}_blobs", through: :"#{name}_attachments", class_name: "ActiveStorage::Blob", source: :blob, strict_loading: strict_loading
|
has_many :"#{name}_blobs", through: :"#{name}_attachments", class_name: "ActiveStorage::Blob", source: :blob, strict_loading: strict_loading
|
||||||
|
|
||||||
|
|
|
@ -456,6 +456,28 @@ class ActiveStorage::ManyAttachedTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "purging from the attachments relation" do
|
||||||
|
[ create_blob(filename: "funky.jpg"), create_blob(filename: "town.jpg") ].tap do |blobs|
|
||||||
|
@user.highlights.attach blobs
|
||||||
|
assert @user.highlights.attached?
|
||||||
|
|
||||||
|
message = <<-MSG.squish
|
||||||
|
Calling `purge` from `highlights_attachments` is deprecated and will be removed in Rails 7.1.
|
||||||
|
To migrate to Rails 7.1's behavior call `purge` from `highlights` instead: `highlights.purge`.
|
||||||
|
MSG
|
||||||
|
assert_deprecated(message) do
|
||||||
|
assert_changes -> { @user.updated_at } do
|
||||||
|
@user.highlights_attachments.purge
|
||||||
|
end
|
||||||
|
end
|
||||||
|
assert_not @user.highlights.attached?
|
||||||
|
assert_not ActiveStorage::Blob.exists?(blobs.first.id)
|
||||||
|
assert_not ActiveStorage::Blob.exists?(blobs.second.id)
|
||||||
|
assert_not ActiveStorage::Blob.service.exist?(blobs.first.key)
|
||||||
|
assert_not ActiveStorage::Blob.service.exist?(blobs.second.key)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
test "purging attachment with shared blobs" do
|
test "purging attachment with shared blobs" do
|
||||||
[
|
[
|
||||||
create_blob(filename: "funky.jpg"),
|
create_blob(filename: "funky.jpg"),
|
||||||
|
@ -529,6 +551,31 @@ class ActiveStorage::ManyAttachedTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "purging later from the attachments relation" do
|
||||||
|
[ create_blob(filename: "funky.jpg"), create_blob(filename: "town.jpg") ].tap do |blobs|
|
||||||
|
@user.highlights.attach blobs
|
||||||
|
assert @user.highlights.attached?
|
||||||
|
|
||||||
|
message = <<-MSG.squish
|
||||||
|
Calling `purge_later` from `highlights_attachments` is deprecated and will be removed in Rails 7.1.
|
||||||
|
To migrate to Rails 7.1's behavior call `purge_later` from `highlights` instead: `highlights.purge_later`.
|
||||||
|
MSG
|
||||||
|
assert_deprecated(message) do
|
||||||
|
perform_enqueued_jobs do
|
||||||
|
assert_changes -> { @user.updated_at } do
|
||||||
|
@user.highlights_attachments.purge_later
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_not @user.highlights.attached?
|
||||||
|
assert_not ActiveStorage::Blob.exists?(blobs.first.id)
|
||||||
|
assert_not ActiveStorage::Blob.exists?(blobs.second.id)
|
||||||
|
assert_not ActiveStorage::Blob.service.exist?(blobs.first.key)
|
||||||
|
assert_not ActiveStorage::Blob.service.exist?(blobs.second.key)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
test "purging attachment later with shared blobs" do
|
test "purging attachment later with shared blobs" do
|
||||||
[
|
[
|
||||||
create_blob(filename: "funky.jpg"),
|
create_blob(filename: "funky.jpg"),
|
||||||
|
|
Loading…
Reference in New Issue