Skip to content
Open
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
4 changes: 3 additions & 1 deletion app/controllers/index_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def show
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.url, status: :see_other, allow_other_host: true
end
format.citation do
# extract optional style and locale from header
Expand All @@ -37,8 +37,10 @@ def show
:datacite,
:datacite_json,
:jats,
:rdf_xml,
:ris,
:schema_org,
:turtle,
) { render request.format.to_sym => doi }
header = %w[
doi
Expand Down
10 changes: 10 additions & 0 deletions config/initializers/mime_types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
Mime::Type.register "application/x-bibtex", :bibtex
Mime::Type.register "application/x-research-info-systems", :ris
Mime::Type.register "text/x-bibliography", :citation
Mime::Type.register "application/rdf+xml", :rdf_xml
Mime::Type.register "text/turtle", :turtle, %w[application/x-turtle]

# register renderers for these Mime types
# :citation and :datacite is handled differently
Expand Down Expand Up @@ -83,3 +85,11 @@
ActionController::Renderers.add :csv do |obj, options|
options[:header].to_csv + Array.wrap(obj).map { |o| o.send("csv") }.join("")
end

ActionController::Renderers.add :rdf_xml do |obj, _options|
Array.wrap(obj).map { |o| o.rdf_xml }.join("\n")
end

ActionController::Renderers.add :turtle do |obj, _options|
Array.wrap(obj).map { |o| o.turtle }.join("\n")
end
6 changes: 6 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@
to: "index#show", constraints: { id: /.+/ }, defaults: { format: :bibtex }
get "/application/x-research-info-systems/:id",
to: "index#show", constraints: { id: /.+/ }, defaults: { format: :ris }
get "/application/rdf+xml/:id",
to: "index#show", constraints: { id: /.+/ }, defaults: { format: :rdf_xml }
get "/application/x-turtle/:id",
to: "index#show", constraints: { id: /.+/ }, defaults: { format: :turtle }
get "/text/turtle/:id",
to: "index#show", constraints: { id: /.+/ }, defaults: { format: :turtle }
get "/text/csv/:id",
to: "index#show", constraints: { id: /.+/ }, defaults: { format: :csv }
get "/text/x-bibliography/:id",
Expand Down
69 changes: 69 additions & 0 deletions spec/requests/index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -337,5 +337,74 @@
expect(last_response.headers["Location"]).to eq(doi.url)
end
end

context "wildcard Accept: */*" do
it "redirects without 500" do
get "/#{doi.doi}", nil, { "HTTP_ACCEPT" => "*/*" }

expect(last_response.status).not_to eq(500)
expect([200, 302, 303]).to include(last_response.status)
end
end

context "application/rdf+xml" do
it "returns the Doi as RDF/XML" do
get "/#{doi.doi}", nil, { "HTTP_ACCEPT" => "application/rdf+xml" }

expect(last_response.status).to eq(200)
expect(last_response.headers["Content-Type"]).to include("application/rdf+xml")
expect(last_response.body).to include("rdf:RDF")
end
end

context "application/rdf+xml link" do
it "returns the Doi as RDF/XML" do
get "/application/rdf+xml/#{doi.doi}"

expect(last_response.status).to eq(200)
expect(last_response.headers["Content-Type"]).to include("application/rdf+xml")
expect(last_response.body).to include("rdf:RDF")
end
end

context "text/turtle" do
it "returns the Doi as Turtle" do
get "/#{doi.doi}", nil, { "HTTP_ACCEPT" => "text/turtle" }

expect(last_response.status).to eq(200)
expect(last_response.headers["Content-Type"]).to include("text/turtle")
expect(last_response.body).to include("@prefix schema:")
end
end

context "application/x-turtle" do
it "returns the Doi as Turtle" do
get "/#{doi.doi}", nil, { "HTTP_ACCEPT" => "application/x-turtle" }

expect(last_response.status).to eq(200)
expect(last_response.headers["Content-Type"]).to include("turtle")
expect(last_response.body).to include("@prefix schema:")
end
end

context "text/turtle link" do
it "returns the Doi as Turtle" do
get "/text/turtle/#{doi.doi}"

expect(last_response.status).to eq(200)
expect(last_response.headers["Content-Type"]).to include("text/turtle")
expect(last_response.body).to include("@prefix schema:")
end
end

context "application/x-turtle link" do
it "returns the Doi as Turtle" do
get "/application/x-turtle/#{doi.doi}"

expect(last_response.status).to eq(200)
expect(last_response.headers["Content-Type"]).to include("turtle")
expect(last_response.body).to include("@prefix schema:")
end
end
end
end