Skip to content
Merged
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
3 changes: 2 additions & 1 deletion app/controllers/oai_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ class OaiController < ApplicationController

# GET /oai-pmh
def index
provider = TrainingProvider.new
provider = TrainingProvider.new({ provider_context: :instance_based })
provider.model = OAI::Provider::ActiveRecordWrapper.new(Material.in_current_space.where(visible: true))
response = provider.process_request(oai_params.to_h)

# add XSLT prefix
Expand Down
6 changes: 0 additions & 6 deletions config/initializers/oai_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,3 @@ class TrainingProvider < OAI::Provider::Base

register_format(OAIRDF.instance)
end

Rails.application.config.after_initialize do
TrainingProvider.source_model OAI::Provider::ActiveRecordWrapper.new(Material.where(visible: true))
rescue ActiveRecord::ActiveRecordError
Rails.logger.debug 'There is no database yet or some other error, so the OAI-PMH endpoint is not configured.'
end
17 changes: 17 additions & 0 deletions test/controllers/oai_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,23 @@ class OaiControllerTest < ActionDispatch::IntegrationTest
assert_includes identifiers, @material.doi
end

test 'OAI-PMH endpoint respects current space' do
get '/oai-pmh', params: { verb: 'ListRecords', metadataPrefix: 'oai_dc' }
parsed = Nokogiri::XML(@response.body)
titles = parsed.xpath('//dc:title', @ns).map(&:text)
assert_includes titles, materials(:training_material).title
assert_includes titles, materials(:plant_space_material).title

plant_space = spaces(:plants)
with_host(plant_space.host) do
get '/oai-pmh', params: { verb: 'ListRecords', metadataPrefix: 'oai_dc' }
parsed = Nokogiri::XML(@response.body)
titles = parsed.xpath('//dc:title', @ns).map(&:text)
refute_includes titles, materials(:training_material).title
assert_includes titles, materials(:plant_space_material).title
end
end

test 'OAI ListRecords returns material in rdf format' do
get '/oai-pmh', params: { verb: 'ListRecords', metadataPrefix: 'rdf' }
assert_response :success
Expand Down
17 changes: 14 additions & 3 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,22 @@ def with_net_connection(&block)
end

def with_host(host, &block)
original_host = @request.host
@request.host = host
if respond_to?(:host=)
# ActionDispatch::IntegrationTest
original_host = self.host
self.host = host
else
# ActionController::TestCase
original_host = @request.host
@request.host = host
end
block.call
ensure
@request.host = original_host
if respond_to?(:host=)
self.host = original_host
else
@request.host = original_host
end
end

# reset dictionaries to their default values
Expand Down
Loading