Skip to content

Commit

Permalink
check whether metadataPrefix is present next-l/enju_leaf#765
Browse files Browse the repository at this point in the history
  • Loading branch information
nabeta committed Sep 25, 2015
1 parent 51bbb80 commit e44b953
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
29 changes: 16 additions & 13 deletions app/controllers/oai_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
class OaiController < ApplicationController
def provider
@oai = check_oai_params(params)
@oai[:errors] = []
if params[:verb] == 'GetRecord'
get_record; return
else
Expand Down Expand Up @@ -51,18 +50,22 @@ def provider

respond_to do |format|
format.xml {
case params[:verb]
when 'Identify'
render template: 'oai/identify', content_type: 'text/xml'
when 'ListMetadataFormats'
render template: 'oai/list_metadata_formats', content_type: 'text/xml'
when 'ListSets'
@series_statements = SeriesStatement.select([:id, :original_title])
render template: 'oai/list_sets', content_type: 'text/xml'
when 'ListIdentifiers'
render template: 'oai/list_identifiers', content_type: 'text/xml'
when 'ListRecords'
render template: 'oai/list_records', content_type: 'text/xml'
if @oai[:errors].empty?
case params[:verb]
when 'Identify'
render template: 'oai/identify', content_type: 'text/xml'
when 'ListMetadataFormats'
render template: 'oai/list_metadata_formats', content_type: 'text/xml'
when 'ListSets'
@series_statements = SeriesStatement.select([:id, :original_title])
render template: 'oai/list_sets', content_type: 'text/xml'
when 'ListIdentifiers'
render template: 'oai/list_identifiers', content_type: 'text/xml'
when 'ListRecords'
render template: 'oai/list_records', content_type: 'text/xml'
else
render template: 'oai/provider', content_type: 'text/xml'
end
else
render template: 'oai/provider', content_type: 'text/xml'
end
Expand Down
2 changes: 1 addition & 1 deletion lib/enju_oai/oai_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def valid_metadata_format?(format)
false
end
else
true
false
end
end

Expand Down
10 changes: 8 additions & 2 deletions spec/controllers/oai_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def valid_attributes
response.should render_template("oai/provider")
end

it "assigns all manifestations as @manifestations in oai format with ListRecords" do
it "should not assign all manifestations as @manifestations in oai format with ListRecords without metadataPrefix" do
get :provider, format: 'xml', :verb => 'ListRecords'
assigns(:manifestations).should_not be_nil
response.should render_template("oai/list_records")
Expand All @@ -31,12 +31,18 @@ def valid_attributes
response.should render_template("oai/list_records")
end

it "assigns all manifestations as @manifestations in oai format with ListIdentifiers" do
it "should not assign all manifestations as @manifestations in oai format with ListIdentifiers without metadataPrefix" do
get :provider, format: 'xml', :verb => 'ListIdentifiers'
assigns(:manifestations).should_not be_nil
response.should render_template("oai/list_identifiers")
end

it "assigns all manifestations as @manifestations in oai format with ListIdentifiers for junii2 metadata" do
get :provider, format: 'xml', :verb => 'ListIdentifiers', :metadataPrefix => 'junii2'
assigns(:manifestations).should_not be_nil
response.should render_template("oai/list_identifiers")
end

it "assigns all manifestations as @manifestations in oai format with GetRecord without identifier" do
get :provider, format: 'xml', :verb => 'GetRecord'
assigns(:manifestations).should be_nil
Expand Down

0 comments on commit e44b953

Please sign in to comment.