Skip to content

Commit

Permalink
Update attachment masking
Browse files Browse the repository at this point in the history
We need to persist the attachment blob as the checksum and byte size can
change after masking.
  • Loading branch information
gbp committed Mar 28, 2024
1 parent 9ad45de commit b0d51b7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/models/foi_attachment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ def body=(d)
ensure_filename!
if file.attached?
file_blob.upload(StringIO.new(d.to_s), identify: false)
file_blob.save

else
file.attach(
io: StringIO.new(d.to_s),
Expand Down
10 changes: 10 additions & 0 deletions spec/models/foi_attachment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,16 @@
expect { attachment.update(body: 'masked', masked_at: Time.now) }.
to_not change { attachment.file_blob.metadata }
end

it 'persists changes to existing blob checksum' do
attachment = FactoryBot.create(
:foi_attachment, :unmasked, body: 'unmasked'
)

expect { attachment.update(body: 'masked', masked_at: Time.now) }.
to change { attachment.file_blob.checksum }
expect(attachment.file_blob.changed?).to eq false
end
end

describe '#body' do
Expand Down

0 comments on commit b0d51b7

Please sign in to comment.