Skip to content

Commit

Permalink
Merge pull request #467 from datacite/bug_schemaVersion_missing_fix
Browse files Browse the repository at this point in the history
Bug schema version missing fix
  • Loading branch information
kjgarza authored Apr 24, 2020
2 parents 69114ab + c8e02a3 commit abdac33
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 3 deletions.
10 changes: 7 additions & 3 deletions app/controllers/dois_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,11 @@ def update
@doi.assign_attributes(safe_params.slice(:client_id))
else
authorize! :update, @doi
@doi.assign_attributes(safe_params.except(:doi, :client_id))
if safe_params[:schema_version].blank?
@doi.assign_attributes(safe_params.except(:doi, :client_id).merge(schema_version: @doi[:schema_version] || LAST_SCHEMA_VERSION))
else
@doi.assign_attributes(safe_params.except(:doi, :client_id))
end
end
else
doi_id = validate_doi(params[:id])
Expand Down Expand Up @@ -647,7 +651,7 @@ def safe_params
meta = xml.present? ? parse_xml(xml, doi: p[:doi]) : {}
p[:schemaVersion] = METADATA_FORMATS.include?(meta["from"]) ? LAST_SCHEMA_VERSION : p[:schemaVersion]
xml = meta["string"]

# if metadata for DOIs from other registration agencies are not found
fail ActiveRecord::RecordNotFound if meta["state"] == "not_found"

Expand Down Expand Up @@ -686,7 +690,7 @@ def safe_params
p[:version_info] = p[:version] || meta["version_info"] if p.has_key?(:version) || meta["version_info"].present?
# only update landing_page info if something is received via API to not overwrite existing data
p.merge!(landing_page: p[:landingPage]) if p[:landingPage].present?

p.merge(
regenerate: p[:regenerate] || regenerate
).except(
Expand Down
49 changes: 49 additions & 0 deletions spec/requests/dois_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2859,6 +2859,55 @@
# end
end

context 'mds doi' do
let(:xml) { Base64.strict_encode64(file_fixture('datacite_schema_3.xml').read) }
let(:valid_attributes) do
{
"data" => {
"type" => "dois",
"attributes" => {
"url" => "http://www.bl.uk/pdf/patspec.pdf",
"should_validate" => "true",
"source" => "mds",
"event" => "publish"
}
}
}
end

let(:update_attributes) do
{
"data" => {
"type" => "dois",
"attributes" => {
"doi" => "10.14454/10703",
"should_validate" => "true",
"xml" => xml,
"source" => "mds",
"event" => "show"
}
}
}
end


it 'add metadata' do
puts "####FIRST ROUND"
put "/dois/10.14454/10703", update_attributes, headers

puts json
expect(json.dig('data', 'attributes', 'doi')).to eq("10.14454/10703")
expect(json.dig('data', 'attributes', 'schemaVersion')).to eq("http://datacite.org/schema/kernel-3")

puts "####SECOND ROUND"
put '/dois/10.14454/10703', valid_attributes, headers

expect(json.dig('data', 'attributes', 'doi')).to eq("10.14454/10703")
expect(json.dig('data', 'attributes', 'schemaVersion')).to eq("http://datacite.org/schema/kernel-3")
expect(json.dig('data', 'attributes', 'titles')).to eq([{"title"=>"Data from: A new malaria agent in African hominids."}])
end
end

context 'update rightsList' do
let(:rights_list) { [{ "rights" => "Creative Commons Attribution 3.0", "rightsUri" => "http://creativecommons.org/licenses/by/3.0/", "lang" => "en"}] }
let(:update_attributes) do
Expand Down

0 comments on commit abdac33

Please sign in to comment.