Skip to content

Commit

Permalink
Merge branch 'reduce-activestorage-background-jobs' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
gbp committed Feb 9, 2024
2 parents 35a4314 + 4808dda commit 08aa218
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
14 changes: 9 additions & 5 deletions app/models/foi_attachment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,15 @@ def body=(d)
self.hexdigest ||= Digest::MD5.hexdigest(d)

ensure_filename!
file.attach(
io: StringIO.new(d.to_s),
filename: filename,
content_type: content_type
)
if file.attached?
file_blob.upload(StringIO.new(d.to_s), identify: false)
else
file.attach(
io: StringIO.new(d.to_s),
filename: filename,
content_type: content_type
)
end

@cached_body = d.force_encoding("ASCII-8BIT")
update_display_size!
Expand Down
1 change: 1 addition & 0 deletions doc/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Highlighted Features

* Reduce amount of storage related background jobs (Graeme Porteous)
* Add automatic parsing of emails contain Excel spreadsheets (Graeme Porteous)
* Improve rendering of admin hidden request prominence and explanations (Graeme
Porteous)
Expand Down
18 changes: 18 additions & 0 deletions spec/models/foi_attachment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,24 @@
ActiveStorage::Blob.services.fetch(blob.service_name).exist?(blob.key)
}.from(false).to(true)
end

it 'does not reset existing blob key' do
attachment = FactoryBot.create(
:foi_attachment, :unmasked, body: 'unmasked'
)

expect { attachment.update(body: 'masked', masked_at: Time.now) }.
to_not change { attachment.file_blob.key }
end

it 'does not reset existing blob metadata' do
attachment = FactoryBot.create(
:foi_attachment, :unmasked, body: 'unmasked'
)

expect { attachment.update(body: 'masked', masked_at: Time.now) }.
to_not change { attachment.file_blob.metadata }
end
end

describe '#body' do
Expand Down

0 comments on commit 08aa218

Please sign in to comment.