mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Switch to the writer DB to generate ASt previews
This commit is contained in:
parent
34d66ca6ba
commit
9e06289a3b
2 changed files with 16 additions and 1 deletions
|
@ -74,7 +74,11 @@ class ActiveStorage::Preview
|
|||
end
|
||||
|
||||
def process
|
||||
previewer.preview { |attachable| image.attach(attachable) }
|
||||
previewer.preview do |attachable|
|
||||
ActiveRecord::Base.connected_to(role: ActiveRecord::Base.writing_role) do
|
||||
image.attach(attachable)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def variant
|
||||
|
|
|
@ -37,4 +37,15 @@ class ActiveStorage::PreviewTest < ActiveSupport::TestCase
|
|||
blob.preview resize: "640x280"
|
||||
end
|
||||
end
|
||||
|
||||
test "previewing on the writer DB" do
|
||||
blob = create_file_blob(filename: "report.pdf", content_type: "application/pdf")
|
||||
|
||||
# Simulate a selector middleware switching to a read-only replica.
|
||||
ActiveRecord::Base.connection_handler.while_preventing_writes do
|
||||
blob.preview(resize: "640x280").processed
|
||||
end
|
||||
|
||||
assert blob.reload.preview_image.attached?
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue