Skip to content
Please note that GitHub no longer supports your web browser.

We recommend upgrading to the latest Google Chrome or Firefox.

Learn more
Permalink
Browse files

Updated logic for PDF responses (#656)

  • Loading branch information
arfon committed Dec 27, 2019
1 parent 712b470 commit 454f2e95066b003136069356d271b6be2b7a71af
@@ -1,3 +1,5 @@
require 'uri'

class PapersController < ApplicationController
include SettingsHelper

@@ -217,8 +219,13 @@ def show
end

respond_to do |format|
format.pdf { redirect_to @paper.pdf_url, status: 301 }
format.html { render layout: false }
format.pdf {
data = open(@paper.pdf_url)
send_data data.read,
:type => data.content_type,
:disposition => 'inline'
}
end
end

@@ -3,3 +3,4 @@
# Add new mime types for use in respond_to blocks:
# Mime::Type.register "text/richtext", :rtf
Mime::Type.register "image/svg+xml", :svg
Mime::Type.register "application/pdf", :pdf
@@ -29,8 +29,8 @@
get '/papers/year/:year', to: "papers#filter", as: 'papers_by_year'
get '/papers/:id/status.svg', to: "papers#status", format: "svg", as: 'status_badge'
get '/papers/:doi/status.svg', to: "papers#status", format: "svg", constraints: { doi: /10.21105\/joss\.\d{5}/}
get '/papers/:doi.pdf', to: "papers#show", constraints: {doi: /.*/}, format: "pdf"
get '/papers/:doi', to: "papers#show", constraints: {doi: /.*/}
get '/papers/:doi', to: "papers#show", constraints: { doi: /10.21105\/joss\.\d{5}/}
get '/papers/:doi.:format', to: "papers#show", constraints: { doi: /10.21105\/joss\.\d{5}/}


get '/dashboard/all', to: "home#all"
@@ -201,11 +201,20 @@
end

describe "accepted papers" do
it "should redirect a URL for a PDF to the actual PDF location" do
it "should send_file a URL for a PDF" do
paper = create(:accepted_paper)
request.headers["HTTP_ACCEPT"] = "application/pdf"

get :show, params: {doi: paper.doi}, format: "pdf"
expect(response).to redirect_to(paper.pdf_url)
get :show, params: {doi: paper.doi}
expect(response.body).to eq(IO.binread('spec/fixtures/paper.pdf'))
end

it "should not redirect when accepting any content type" do
paper = create(:accepted_paper)
request.headers["HTTP_ACCEPT"] = "*/*"

get :show, params: {doi: paper.doi}
expect(response).to render_template("papers/show")
end

it "should not redirect for URLs with DOIs when asking for HTML response" do
@@ -215,6 +224,13 @@
expect(response).to render_template("papers/show")
end

it "should not redirect for URLs with DOIs when asking for any response" do
paper = create(:accepted_paper)

get :show, params: {doi: paper.doi}
expect(response).to render_template("papers/show")
end

it "should redirect URLs with the paper SHA to the URL with the DOI in the path" do
paper = create(:accepted_paper)

Binary file not shown.
@@ -102,5 +102,13 @@
with(body: "{\"assignee\":\"joss\",\"labels\":[\"pre-review\"],\"title\":\"[PRE REVIEW]: arfon / fidgit\",\"body\":\"**Submitting author:** @foobar (\\u003ca href=\\\"http://orcid.org/0000-0000-0000-1234\\\"\\u003eDoe, John\\u003c/a\\u003e)\\n**Repository:** \\u003ca href=\\\"http://github.com/arfon/fidgit\\\" target =\\\"_blank\\\"\\u003ehttp://github.com/arfon/fidgit\\u003c/a\\u003e\\n**Version:** v1.0.0\\n**Editor:** @joss\\n**Reviewer:** Pending\\n\\n**What this issue is for**\\n\\nThanks for submitting your paper to JOSS @foobar. The JOSS editor (shown at the top of this issue) will work with you on this issue to find a reviewer for your submission before creating the main review issue.\\n\\n**Editor instructions**\\n\\nThe JOSS submission bot @whedon is here to help you find and assign reviewers and start the main review. To find out what @whedon can do for you type:\\n\\n```\\n@whedon commands\\n```\\n\"}",
headers: {'Accept'=>'application/vnd.github.v3+json', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type'=>'application/json', 'User-Agent'=>'Octokit Ruby Gem 4.3.0'}).
to_return(status: 200, body: "", headers: {})
stub_request(:get, "https://www.theoj.org/joss-papers/joss.00000/10.21105.joss.00000.pdf").
with(
headers: {
'Accept'=>'*/*',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'User-Agent'=>'Ruby'
}).
to_return(status: 200, body: IO.binread('spec/fixtures/paper.pdf'), headers: {})
end
end

0 comments on commit 454f2e9

Please sign in to comment.
You can’t perform that action at this time.