File tree Expand file tree Collapse file tree 4 files changed +14
-20
lines changed
app/models/active_storage
controllers/representations Expand file tree Collapse file tree 4 files changed +14
-20
lines changed Original file line number Diff line number Diff line change
1
+ * Prevent ` ActiveRecord::StrictLoadingViolationError ` when strict loading is
2
+ enabled and the variant of an Active Storage preview has already been
3
+ processed (for example, by calling ` ActiveStorage::Preview#url ` ).
4
+
5
+ * Jonathan Hefner*
6
+
1
7
* Fix ` preprocessed: true ` option for named variants of previewable files.
2
8
3
9
* Nico Wenterodt*
Original file line number Diff line number Diff line change @@ -134,7 +134,10 @@ def signed_id_verifier # :nodoc:
134
134
135
135
def scope_for_strict_loading # :nodoc:
136
136
if strict_loading_by_default? && ActiveStorage . track_variants
137
- includes ( variant_records : { image_attachment : :blob } , preview_image_attachment : :blob )
137
+ includes (
138
+ variant_records : { image_attachment : :blob } ,
139
+ preview_image_attachment : { blob : { variant_records : { image_attachment : :blob } } }
140
+ )
138
141
else
139
142
all
140
143
end
Original file line number Diff line number Diff line change @@ -110,7 +110,7 @@ class ActiveStorage::Representations::RedirectControllerWithPreviewsTest < Actio
110
110
class ActiveStorage ::Representations ::RedirectControllerWithPreviewsWithStrictLoadingTest < ActionDispatch ::IntegrationTest
111
111
setup do
112
112
@blob = create_file_blob filename : "report.pdf" , content_type : "application/pdf"
113
- @blob . preview ( resize_to_limit : [ 100 , 100 ] ) . processed
113
+ @blob . preview ( resize_to_limit : [ 100 , 100 ] ) . processed . send ( :variant ) . processed
114
114
end
115
115
116
116
test "showing existing preview record inline" do
Original file line number Diff line number Diff line change @@ -328,28 +328,13 @@ class ActiveStorage::BlobTest < ActiveSupport::TestCase
328
328
end
329
329
330
330
test "scope_for_strict_loading adds includes only when track_variants and strict_loading_by_default" do
331
- assert_empty (
332
- ActiveStorage ::Blob . scope_for_strict_loading . includes_values ,
333
- "Expected ActiveStorage::Blob.scope_for_strict_loading have no includes"
334
- )
331
+ assert_empty ActiveStorage ::Blob . scope_for_strict_loading . includes_values
335
332
336
333
with_strict_loading_by_default do
337
- includes_values = ActiveStorage ::Blob . scope_for_strict_loading . includes_values
338
-
339
- assert (
340
- includes_values . any? { |values | values [ :variant_records ] == { image_attachment : :blob } } ,
341
- "Expected ActiveStorage::Blob.scope_for_strict_loading to have variant_records included"
342
- )
343
- assert (
344
- includes_values . any? { |values | values [ :preview_image_attachment ] == :blob } ,
345
- "Expected ActiveStorage::Blob.scope_for_strict_loading to have preview_image_attachment included"
346
- )
334
+ assert_not_empty ActiveStorage ::Blob . scope_for_strict_loading . includes_values
347
335
348
336
without_variant_tracking do
349
- assert_empty (
350
- ActiveStorage ::Blob . scope_for_strict_loading . includes_values ,
351
- "Expected ActiveStorage::Blob.scope_for_strict_loading have no includes"
352
- )
337
+ assert_empty ActiveStorage ::Blob . scope_for_strict_loading . includes_values
353
338
end
354
339
end
355
340
end
You can’t perform that action at this time.
0 commit comments