このコミットが含まれているのは:
@@ -187,12 +187,59 @@ RSpec.describe Post, type: :model do
|
||||
|
||||
post = described_class.create!(title: 'title', url: 'https://example.com/post')
|
||||
|
||||
expect(post.thumbnail).to receive(:attach).once.and_call_original
|
||||
post.attach_thumbnail_from_url!('https://example.com/thumb.png')
|
||||
|
||||
expect(post.thumbnail).to be_attached
|
||||
image = read_image(post.thumbnail)
|
||||
expect(image.dimensions).to eq([180, 180])
|
||||
end
|
||||
|
||||
it 'does not attach anything when thumbnail conversion fails' do
|
||||
response = Preview::HttpFetcher::Response.new(
|
||||
'not-an-image',
|
||||
'image/png',
|
||||
'https://example.com/thumb.png')
|
||||
allow(Preview::ThumbnailFetcher).to receive(:fetch_image_response)
|
||||
.with('https://example.com/thumb.png')
|
||||
.and_return(response)
|
||||
allow(described_class).to receive(:resized_thumbnail_attachment)
|
||||
.and_raise(MiniMagick::Error, 'convert failed')
|
||||
|
||||
post = described_class.create!(title: 'title', url: 'https://example.com/post')
|
||||
|
||||
expect {
|
||||
post.attach_thumbnail_from_url!('https://example.com/thumb.png')
|
||||
}.to raise_error(Post::RemoteThumbnailFetchFailed, 'convert failed')
|
||||
|
||||
expect(post.thumbnail).not_to be_attached
|
||||
end
|
||||
|
||||
it 'keeps an existing thumbnail when remote conversion fails' do
|
||||
existing = described_class.create!(title: 'title', url: 'https://example.com/post')
|
||||
existing.thumbnail.attach(
|
||||
io: StringIO.new('existing'),
|
||||
filename: 'existing.jpg',
|
||||
content_type: 'image/jpeg')
|
||||
blob_id = existing.thumbnail.blob.id
|
||||
response = Preview::HttpFetcher::Response.new(
|
||||
'not-an-image',
|
||||
'image/png',
|
||||
'https://example.com/thumb.png')
|
||||
allow(Preview::ThumbnailFetcher).to receive(:fetch_image_response)
|
||||
.with('https://example.com/thumb.png')
|
||||
.and_return(response)
|
||||
allow(described_class).to receive(:resized_thumbnail_attachment)
|
||||
.and_raise(MiniMagick::Error, 'convert failed')
|
||||
|
||||
expect {
|
||||
existing.attach_thumbnail_from_url!('https://example.com/thumb.png')
|
||||
}.to raise_error(Post::RemoteThumbnailFetchFailed, 'convert failed')
|
||||
|
||||
existing.reload
|
||||
expect(existing.thumbnail).to be_attached
|
||||
expect(existing.thumbnail.blob.id).to eq(blob_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
新しい課題から参照
ユーザをブロックする