Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#7934] Fix processing of unsaved attachments #7935

Merged
merged 1 commit into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/models/foi_attachment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def body

if masked?
@cached_body = file.download
else
elsif persisted?
FoiAttachmentMaskJob.unlock!(self)
FoiAttachmentMaskJob.perform_now(self)
reload
Expand Down
12 changes: 12 additions & 0 deletions spec/models/foi_attachment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,18 @@
expect { attachment.body = 'foo' }.to_not change { attachment.hexdigest }
end

it 'allow calls to #body to be made before save' do
attachment = FactoryBot.build(:foi_attachment, :unmasked)
blob = attachment.file.blob

expect {
attachment.body
attachment.save!
}.to change {
ActiveStorage::Blob.services.fetch(blob.service_name).exist?(blob.key)
}.from(false).to(true)
end

end

describe '#body' do
Expand Down
Loading