FIX: Ensure old uploads can have animated field updated (#10963)

If admins decreased the maximum filesize limit the ActiveRecord
validations would fail.
This commit is contained in:
Bianca Nenciu 2020-10-20 19:11:43 +03:00 committed by GitHub
parent 94cbfa92e1
commit be5efc9410
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View File

@ -13,7 +13,8 @@ module Jobs
.limit(MAX_PROCESSED_GIF_IMAGES)
.each do |upload|
uri = Discourse.store.path_for(upload) || upload.url
upload.update!(animated: FastImage.animated?(uri))
upload.animated = FastImage.animated?(uri)
upload.save(validate: false)
upload.optimized_images.destroy_all if upload.animated
end

View File

@ -6,13 +6,23 @@ describe Jobs::UpdateAnimatedUploads do
let!(:upload) { Fabricate(:upload) }
let!(:gif_upload) { Fabricate(:upload, extension: "gif") }
it "affects only GIF uploads" do
before do
url = Discourse.store.path_for(gif_upload) || gif_upload.url
FastImage.expects(:animated?).with(url).returns(true).once
end
it "affects only GIF uploads" do
described_class.new.execute({})
expect(upload.reload.animated).to eq(nil)
expect(gif_upload.reload.animated).to eq(true)
end
it "works with uploads larger than current limits" do
SiteSetting.max_image_size_kb = 1
described_class.new.execute({})
expect(gif_upload.reload.animated).to eq(true)
end
end