Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 22 additions & 12 deletions app/controllers/index_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@ def show
doi = Doi.where(doi: params[:id], aasm_state: "findable").first
fail ActiveRecord::RecordNotFound if doi.blank?

if request.format.symbol.nil?
redirect_to_doi(doi)
return
end

respond_to do |format|
format.html do
# forward to URL registered in handle system for no content negotiation
redirect_to doi.url, status: :see_other
redirect_to_doi(doi)
end
format.citation do
# extract optional style and locale from header
Expand Down Expand Up @@ -56,18 +61,23 @@ def show
end
rescue ActionController::UnknownFormat, ActionController::RoutingError
# forward to URL registered in handle system for unrecognized format
redirect_to doi.url, status: :see_other, allow_other_host: true
redirect_to_doi(doi)
end

def routing_error
fail ActiveRecord::RecordNotFound
end
private
def redirect_to_doi(doi)
redirect_to doi.url, status: :see_other, allow_other_host: true
end

def method_not_allowed
response.set_header("Allow", "POST")
render json: {
"message": "This endpoint only supports POST requests.",
}.to_json,
status: :method_not_allowed
end
def routing_error
fail ActiveRecord::RecordNotFound
end

def method_not_allowed
response.set_header("Allow", "POST")
render json: {
"message": "This endpoint only supports POST requests.",
}.to_json,
status: :method_not_allowed
end
end
17 changes: 17 additions & 0 deletions spec/requests/index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,23 @@
end
end

%w[
*/*
application/xml
application/rdf+xml
text/turtle
application/x-turtle
].each do |accept|
context accept do
it "redirects to the DOI URL" do
get "/#{doi.doi}", nil, { "HTTP_ACCEPT" => accept }

expect(last_response.status).to eq(303)
expect(last_response.headers["Location"]).to eq(doi.url)
end
end
end

context "missing content type" do
it "returns the Doi" do
get "/#{doi.doi}"
Expand Down