Skip to content

Commit

Permalink
Merge pull request #237 from sul-dlss/dc
Browse files Browse the repository at this point in the history
Expose an endpoint for dublin core metadata
  • Loading branch information
justinlittman committed Apr 29, 2019
2 parents b587b9c + d65b86b commit 24d9a91
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
7 changes: 4 additions & 3 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2019-04-26 16:20:32 -0500 using RuboCop version 0.65.0.
# on 2019-04-29 12:10:56 -0500 using RuboCop version 0.65.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand Down Expand Up @@ -113,11 +113,12 @@ RSpec/ContextWording:
- 'spec/services/registration_service_spec.rb'
- 'spec/services/version_service_spec.rb'

# Offense count: 2
# Offense count: 3
RSpec/DescribeClass:
Exclude:
- 'spec/requests/about_spec.rb'
- 'spec/requests/metadata_refresh.rb'
- 'spec/requests/metadata_spec.rb'

# Offense count: 32
# Cop supports --auto-correct.
Expand Down Expand Up @@ -190,7 +191,7 @@ RSpec/MessageSpies:
- 'spec/services/registration_service_spec.rb'
- 'spec/services/version_service_spec.rb'

# Offense count: 76
# Offense count: 77
# Configuration parameters: AggregateFailuresByDefault.
RSpec/MultipleExpectations:
Max: 8
Expand Down
11 changes: 11 additions & 0 deletions app/controllers/metadata_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

# A controller to display derived metadata about an object
class MetadataController < ApplicationController
before_action :load_item

def dublin_core
service = DublinCoreService.new(@item)
render xml: service
end
end
6 changes: 6 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@
get 'contents/*path', to: 'content#read', format: false, as: :read_content
end

resources :metadata, only: [] do
collection do
get 'dublin_core'
end
end

resources :versions, only: [:create] do
collection do
get 'current'
Expand Down
22 changes: 22 additions & 0 deletions spec/requests/metadata_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe 'Refresh metadata' do
let(:user) { Settings.DOR.SERVICE_USER }
let(:password) { Settings.DOR.SERVICE_PASSWORD }
let(:basic_auth) { ActionController::HttpAuthentication::Basic.encode_credentials(user, password) }
let(:object) { Dor::Item.new(pid: 'druid:1234') }

before do
object.descMetadata.title_info.main_title = 'Hello'
allow(Dor).to receive(:find).and_return(object)
end

it 'returns the DC xml' do
get '/v1/objects/druid:mk420bs7601/metadata/dublin_core',
headers: { 'Authorization' => basic_auth }
expect(response).to be_successful
expect(response.body).to include '<dc:title>Hello</dc:title>'
end
end

0 comments on commit 24d9a91

Please sign in to comment.