diff --git a/lib/rails_ext/active_storage_analyze_job_suppress_broadcasts.rb b/lib/rails_ext/active_storage_analyze_job_suppress_broadcasts.rb index ba22603b6..030232ee4 100644 --- a/lib/rails_ext/active_storage_analyze_job_suppress_broadcasts.rb +++ b/lib/rails_ext/active_storage_analyze_job_suppress_broadcasts.rb @@ -4,6 +4,8 @@ # there is currently a bug https://github.com/rails/rails/issues/55144 module ActiveStorageAnalyzeJobSuppressBroadcasts def perform(blob) + return unless blob.attachments.exists? + Board.suppressing_turbo_broadcasts do Card.suppressing_turbo_broadcasts do super diff --git a/test/lib/rails_ext/active_storage_analyze_job_suppress_broadcasts_test.rb b/test/lib/rails_ext/active_storage_analyze_job_suppress_broadcasts_test.rb new file mode 100644 index 000000000..1015c957c --- /dev/null +++ b/test/lib/rails_ext/active_storage_analyze_job_suppress_broadcasts_test.rb @@ -0,0 +1,23 @@ +require "test_helper" + +class ActiveStorageAnalyzeJobSuppressBroadcastsTest < ActiveSupport::TestCase + test "skips analysis when blob has no attachments" do + blob = ActiveStorage::Blob.create_and_upload!( + io: StringIO.new("x" * 1024), filename: "orphan.txt", content_type: "text/plain" + ) + + blob.expects(:analyze).never + + ActiveStorage::AnalyzeJob.perform_now(blob) + end + + test "performs analysis when blob has attachments" do + card = cards(:logo) + card.image.attach io: StringIO.new("x" * 1024), filename: "test.png", content_type: "image/png" + blob = card.image.blob + + blob.expects(:analyze).once + + ActiveStorage::AnalyzeJob.perform_now(blob) + end +end