Fix media attachment size validation not correctly accounting for file type (#16819)
* Fix media attachment size validation not correctly accounting for file type Fixes a regression introduced in #16724 caused by the fact that kt-paperclip now correctly runs validations before processing, meaning that file size verification could not rely on our before_post_processing hook. Moved the `before_post_processing` hooks to `before_validate` to make sure the media attachment type is set correctly before the file gets validated. * Add tests
This commit is contained in:
parent
900481b7fa
commit
84ceebe1c4
2 changed files with 31 additions and 4 deletions
|
@ -181,4 +181,32 @@ RSpec.describe MediaAttachment, type: :model do
|
|||
expect(media.description.size).to be <= 1_500
|
||||
end
|
||||
end
|
||||
|
||||
describe 'size limit validation' do
|
||||
it 'rejects video files that are too large' do
|
||||
stub_const 'MediaAttachment::IMAGE_LIMIT', 100.megabytes
|
||||
stub_const 'MediaAttachment::VIDEO_LIMIT', 1.kilobyte
|
||||
expect { MediaAttachment.create!(account: Fabricate(:account), file: attachment_fixture('attachment.webm')) }.to raise_error(ActiveRecord::RecordInvalid)
|
||||
end
|
||||
|
||||
it 'accepts video files that are small enough' do
|
||||
stub_const 'MediaAttachment::IMAGE_LIMIT', 1.kilobyte
|
||||
stub_const 'MediaAttachment::VIDEO_LIMIT', 100.megabytes
|
||||
media = MediaAttachment.create!(account: Fabricate(:account), file: attachment_fixture('attachment.webm'))
|
||||
expect(media.valid?).to be true
|
||||
end
|
||||
|
||||
it 'rejects image files that are too large' do
|
||||
stub_const 'MediaAttachment::IMAGE_LIMIT', 1.kilobyte
|
||||
stub_const 'MediaAttachment::VIDEO_LIMIT', 100.megabytes
|
||||
expect { MediaAttachment.create!(account: Fabricate(:account), file: attachment_fixture('attachment.jpg')) }.to raise_error(ActiveRecord::RecordInvalid)
|
||||
end
|
||||
|
||||
it 'accepts image files that are small enough' do
|
||||
stub_const 'MediaAttachment::IMAGE_LIMIT', 100.megabytes
|
||||
stub_const 'MediaAttachment::VIDEO_LIMIT', 1.kilobyte
|
||||
media = MediaAttachment.create!(account: Fabricate(:account), file: attachment_fixture('attachment.jpg'))
|
||||
expect(media.valid?).to be true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue