Skip to content

Commit

Permalink
require prefix for random dois. #235
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Jun 17, 2019
1 parent e879713 commit 1f2da3f
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 46 deletions.
6 changes: 1 addition & 5 deletions app/controllers/dois_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ def get_dois
authorize! :get_urls, Doi

client = Client.where('datacentre.symbol = ?', current_user.uid.upcase).first
client_prefix = client.prefixes.where.not('prefix.prefix = ?', "10.5072").first
client_prefix = client.prefixes.first
head :no_content and return unless client_prefix.present?

dois = Doi.get_dois(prefix: client_prefix.prefix, username: current_user.uid.upcase, password: current_user.password)
Expand Down Expand Up @@ -588,10 +588,6 @@ def safe_params
# generate random DOI if no DOI is provided
if p[:doi].blank? && p[:prefix].present?
p[:doi] = generate_random_dois(p[:prefix]).first
elsif p[:doi].blank? && client_id.present?
client = Client.where('datacentre.symbol = ?', client_id).first
client_prefix = client.client_prefixes.joins(:prefix).first
p[:doi] = generate_random_dois(client_prefix.prefix.prefix).first if client_prefix
end

# replace DOI, but otherwise don't touch the XML
Expand Down
41 changes: 0 additions & 41 deletions spec/requests/dois_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -872,47 +872,6 @@
end
end

context 'when the request is valid random doi with client prefix' do
let(:xml) { Base64.strict_encode64(file_fixture('datacite.xml').read) }
let(:valid_attributes) do
{
"data" => {
"type" => "dois",
"attributes" => {
"url" => "http://www.bl.uk/pdf/patspec.pdf",
"xml" => xml,
"source" => "test",
"event" => "publish"
}
}
}
end

it 'creates a Doi' do
post '/dois', valid_attributes, headers

expect(last_response.status).to eq(201)
expect(json.dig('data', 'attributes', 'url')).to eq("http://www.bl.uk/pdf/patspec.pdf")
expect(json.dig('data', 'attributes', 'doi')).to start_with("10.14454")
expect(json.dig('data', 'attributes', 'titles')).to eq([{"title"=>"Eating your own Dog Food"}])
expect(json.dig('data', 'attributes', 'creators')).to eq([{"familyName"=>"Fenner",
"givenName"=>"Martin",
"name"=>"Fenner, Martin",
"nameIdentifiers"=>
[{"nameIdentifier"=>"https://orcid.org/0000-0003-1419-2405",
"nameIdentifierScheme"=>"ORCID",
"schemeUri"=>"https://orcid.org"}],
"nameType"=>"Personal"}])
expect(json.dig('data', 'attributes', 'schemaVersion')).to eq("http://datacite.org/schema/kernel-4")
expect(json.dig('data', 'attributes', 'source')).to eq("test")
expect(json.dig('data', 'attributes', 'types')).to eq("bibtex"=>"article", "citeproc"=>"article-journal", "resourceType"=>"BlogPosting", "resourceTypeGeneral"=>"Text", "ris"=>"RPRT", "schemaOrg"=>"ScholarlyArticle")
expect(json.dig('data', 'attributes', 'state')).to eq("findable")

doc = Nokogiri::XML(Base64.decode64(json.dig('data', 'attributes', 'xml')), nil, 'UTF-8', &:noblanks)
expect(doc.at_css("identifier").content).to start_with("10.14454")
end
end

context 'when the request is valid with attributes' do
let(:valid_attributes) do
{
Expand Down

0 comments on commit 1f2da3f

Please sign in to comment.