提交 fd61bae0 编写于 作者: G George Claghorn

ActiveStorage::Attachment#signed_id must return a signed *blob* ID

Fixes that calling e.g. `url_for @user.avatar` would return an incorrect URL resulting in a 404. The Active Storage URL helper ends up calling ActiveStorage::Attachment#signed_id, which previously delegated to ActiveStorage::Blob#signed_id but changed to return a signed *attachment* ID in 1a3dc42c.

The Active Storage controllers pass signed IDs to ActiveStorage::Blob.find_signed, so we need signed blob IDs.
上级 55f519f5
......@@ -14,6 +14,7 @@ class ActiveStorage::Attachment < ActiveRecord::Base
belongs_to :blob, class_name: "ActiveStorage::Blob"
delegate_missing_to :blob
delegate :signed_id, to: :blob
after_create_commit :mirror_blob_later, :analyze_blob_later, :identify_blob
after_destroy_commit :purge_dependent_blob_later
......
......@@ -49,4 +49,12 @@ class ActiveStorage::AttachmentTest < ActiveSupport::TestCase
assert ActiveStorage::Blob.service.mirrors.second.exist?(blob.key)
end
end
test "getting a signed blob ID from an attachment" do
blob = create_blob
@user.avatar.attach(blob)
signed_id = @user.avatar.signed_id
assert_equal blob, ActiveStorage::Blob.find_signed(signed_id)
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册