mirror of
https://github.com/discourse/discourse.git
synced 2025-05-21 18:12:32 +08:00
FIX: Do not try to recover invalid Upload#short_url
in UploadRecovery
.
This commit is contained in:
@ -18,31 +18,45 @@ RSpec.describe UploadRecovery do
|
||||
).tap(&:link_post_uploads)
|
||||
end
|
||||
|
||||
let(:upload_recovery) { UploadRecovery.new }
|
||||
|
||||
before do
|
||||
SiteSetting.queue_jobs = false
|
||||
end
|
||||
|
||||
describe '#recover' do
|
||||
it 'should recover the upload' do
|
||||
begin
|
||||
stub_request(:get, "http://test.localhost#{upload.url}")
|
||||
.to_return(status: 200)
|
||||
after do
|
||||
public_path = "#{Discourse.store.public_dir}#{upload.url}"
|
||||
|
||||
expect do
|
||||
upload.destroy!
|
||||
end.to change { post.reload.uploads.count }.from(1).to(0)
|
||||
[
|
||||
public_path,
|
||||
public_path.sub("uploads", "uploads/tombstone")
|
||||
].each { |path| File.delete(path) if File.exists?(path) }
|
||||
end
|
||||
|
||||
expect do
|
||||
UploadRecovery.new.recover
|
||||
end.to change { post.reload.uploads.count }.from(0).to(1)
|
||||
ensure
|
||||
public_path = "#{Discourse.store.public_dir}#{upload.url}"
|
||||
describe 'when given an invalid sha1' do
|
||||
it 'should not do anything' do
|
||||
upload_recovery.expects(:recover_from_local).never
|
||||
|
||||
[
|
||||
public_path,
|
||||
public_path.sub("uploads", "uploads/tombstone")
|
||||
].each { |path| File.delete(path) if File.exists?(path) }
|
||||
post.update!(
|
||||
raw: ""
|
||||
)
|
||||
|
||||
upload_recovery.recover
|
||||
end
|
||||
end
|
||||
|
||||
it 'should recover the upload' do
|
||||
stub_request(:get, "http://test.localhost#{upload.url}")
|
||||
.to_return(status: 200)
|
||||
|
||||
expect do
|
||||
upload.destroy!
|
||||
end.to change { post.reload.uploads.count }.from(1).to(0)
|
||||
|
||||
expect do
|
||||
upload_recovery.recover
|
||||
end.to change { post.reload.uploads.count }.from(0).to(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user