FIX: Destroy `OptimizedImage` record even if `Upload` record is invalid.
This commit is contained in:
parent
19c3c25db1
commit
839a54b97b
|
@ -130,7 +130,7 @@ class OptimizedImage < ActiveRecord::Base
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
OptimizedImage.transaction do
|
OptimizedImage.transaction do
|
||||||
Discourse.store.remove_optimized_image(self)
|
Discourse.store.remove_optimized_image(self) if self.upload
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -330,6 +330,18 @@ describe OptimizedImage do
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#destroy' do
|
||||||
|
describe 'when upload_id is no longer valid' do
|
||||||
|
it 'should still destroy the record' do
|
||||||
|
image = Fabricate(:optimized_image)
|
||||||
|
image.upload.delete
|
||||||
|
image.reload.destroy
|
||||||
|
|
||||||
|
expect(OptimizedImage.exists?(id: image.id)).to eq(false)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
class FakeInternalStore
|
class FakeInternalStore
|
||||||
|
|
Loading…
Reference in New Issue