Skip to content

Commit

Permalink
1578 make owl api work with ontohub urls that have no filename extens…
Browse files Browse the repository at this point in the history
…ion (#1768)

* API controller is now invoked when no Accept header is sent

* Use text/plain as default for ontology versions api

* Send correct accept header

* Fix the ref based locid route

* Remove ref_id

* Remove debug puts

* Fix locid routing tests

* route html to api

* Add routes.rb to ignore list

* Move plain text default helper to concern

* Fix test

* More tests require accept header

* Remove tags from steps
  • Loading branch information
phyrog committed Aug 14, 2016
1 parent 2007ce6 commit 554f2eb
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 12 deletions.
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ AllCops:
- 'spec/**/*'
- 'features/**/*'
- 'script/**/*'
- 'config/routes.rb'
TargetRubyVersion: 2.1

# These are all the cops that are enabled in the default configuration.
Expand Down
1 change: 1 addition & 0 deletions app/controllers/api/v1/ontologies_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class Api::V1::OntologiesController < Api::V1::Base
include PlainTextDefaultHelper
inherit_resources
actions :show

Expand Down
2 changes: 2 additions & 0 deletions app/controllers/api/v1/ontology_versions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class Api::V1::OntologyVersionsController < Api::V1::Base
include PlainTextDefaultHelper

inherit_resources
defaults collection_name: :versions, finder: :find_by_number!
belongs_to :ontology
Expand Down
11 changes: 11 additions & 0 deletions app/controllers/plain_text_default_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module PlainTextDefaultHelper
extend ActiveSupport::Concern

included do
before_filter :set_format
end

def set_format
request.format = :text unless request.format.to_sym == :json
end
end
24 changes: 12 additions & 12 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@
end

# Special (/ref-based) Loc/Id routes
specified_get '/ref/:reference/:repository_id/*locid' => 'api/v1/ontology_versions#show',
specified_get '/ref/:reference/:repository_id/*locid' => 'ontology_versions#show',
as: :ontology_iri_versioned,
constraints: [
RefLocIdRouterConstraint.new(Ontology, ontology: :ontology_id),
RefLocIdRouterConstraint.new(Ontology, ontology: :id),
] do
accept 'application/json', constraint: true
accept 'text/plain', constraint: true
# reroute_on_mime 'application/json', to: 'api/v1/ontology_versions#show'
accept 'text/html', constraint: true

doc title: 'Ontology IRI (loc/id) with version reference',
body: <<-BODY
Expand All @@ -33,12 +31,14 @@
BODY
end

specified_get '/ref/:reference/:repository_id/*locid' => 'ontologies#show',
specified_get '/ref/:reference/:repository_id/*locid' => 'api/v1/ontology_versions#show',
as: :ontology_iri_versioned,
constraints: [
RefLocIdRouterConstraint.new(Ontology, ontology: :id),
RefLocIdRouterConstraint.new(Ontology, ontology: :ontology_id),
] do
accept 'text/html'
accept 'application/json'
accept 'text/plain'
# reroute_on_mime 'application/json', to: 'api/v1/ontology_versions#show'

doc title: 'Ontology IRI (loc/id) with version reference',
body: <<-BODY
Expand Down Expand Up @@ -293,14 +293,14 @@

# Loc/Id-Show(-equivalent) routes
######
specified_get '/:repository_id/*locid' => 'ontologies#show',
specified_get '/:repository_id/*locid' => 'api/v1/ontologies#show',
as: :ontology_iri,
constraints: [
LocIdRouterConstraint.new(Ontology, ontology: :id),
] do
accept 'text/html'
reroute_on_mime 'text/plain', to: 'api/v1/ontologies#show'
reroute_on_mime 'application/json', to: 'api/v1/ontologies#show'
accept 'text/plain'
accept 'application/json'
reroute_on_mime 'text/html', to: 'ontologies#show'

doc title: 'loc/id reference to an ontology',
body: <<-BODY
Expand Down
3 changes: 3 additions & 0 deletions features/LocId.feature
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
Feature: Resolving LocId IRIs

@require_accept_html
Scenario: Loading a SingleOntology
Given there is a single ontology
When I visit the ontology via the loc/id
Then I should get a response with a status of 200
And I should have an API-command matching 'symbols'

@require_accept_html
Scenario: Loading a DistributedOntology
Given there is a distributed ontology
When I visit the ontology via the loc/id
Then I should get a response with a status of 200
And I should have an API-command matching 'children'

@require_accept_html
Scenario: Loading a Single-in-Distributed Ontology
Given there is a single-in-distributed ontology
When I visit the ontology via the loc/id
Expand Down
3 changes: 3 additions & 0 deletions features/LocIdRouting.feature
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
Feature: LocId Routing

@require_accept_html
Scenario: Visiting a SingleOntology
When my subject is a SingleOntology
And I visit my subject's locid
Then I should get a response with a status of 200
And the page title should include the subject's name

@require_accept_html
Scenario: Visiting a DistributedOntology
When my subject is a DistributedOntology
And I visit my subject's locid
Then I should get a response with a status of 200
And the page title should include the subject's name

@require_accept_html
Scenario: Visiting a child Ontology
When my subject is a child Ontology
And I visit my subject's locid
Expand Down
4 changes: 4 additions & 0 deletions features/support/hooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@
redis.del redis.keys if redis.keys.any?
Sidekiq::Worker.clear_all
end

Before('@require_accept_html') do
Capybara.current_session.driver.header('Accept', 'text/html')
end

0 comments on commit 554f2eb

Please sign in to comment.