diff --git a/lib/decidim/content_fixer.rb b/lib/decidim/content_fixer.rb index b89331d04d..8c81fd9d29 100644 --- a/lib/decidim/content_fixer.rb +++ b/lib/decidim/content_fixer.rb @@ -81,6 +81,9 @@ def new_source(source) def find_service_url_for_blob(blob_id) Rails.application.routes.url_helpers.rails_blob_path(ActiveStorage::Blob.find(blob_id), only_path: true) + rescue ActiveRecord::RecordNotFound + @logger.warn "Blob #{blob_id} not found" + nil end def nokogiri_will_wrap_with_p?(content) diff --git a/spec/lib/decidim/content_fixer_spec.rb b/spec/lib/decidim/content_fixer_spec.rb index c2abf513e0..1460643dff 100644 --- a/spec/lib/decidim/content_fixer_spec.rb +++ b/spec/lib/decidim/content_fixer_spec.rb @@ -135,5 +135,11 @@ it "returns the service url for the given blob" do expect(subject.find_service_url_for_blob(blob.id)).to eq(blob_path) end + + context "when blob is not found" do + it "returns nil" do + expect(subject.find_service_url_for_blob(blob.id + 1)).to eq(nil) + end + end end end