Fix PDF title PR and add test case for PDF titles (#833)

This commit is contained in:
Calvin Buckley 2020-03-04 09:58:17 -04:00 committed by GitHub
parent 3a1815a19f
commit 63d73ab80d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 1 deletions

View File

@ -976,7 +976,7 @@ class Story < ApplicationRecord
end
def fetched_attributes_pdf
return @fetched_attributes = {} if @fetched_response.body >= 5.megabytes
return @fetched_attributes = {} if @fetched_response.body.length >= 5.megabytes
# pdf-reader only accepts a stream or filename
pdf_stream = StringIO.new(@fetched_response.body)

BIN
spec/fixtures/story_pages/titled.pdf vendored Normal file

Binary file not shown.

View File

@ -161,6 +161,14 @@ describe Story do
return res
end
it "can fetch PDF titles properly" do
content = File.read(story_directory + "titled.pdf")
res = fake_response(content, "application/pdf")
s = build(:story)
s.fetched_response = res
expect(s.fetched_attributes[:title]).to eq("Taking a Long Look at QUIC")
end
it "can fetch its title properly" do
content = File.read(story_directory + "title_ampersand.html")
res = fake_response(content, "text/html")