Skip to content

Commit

Permalink
don't use 10.5072 for random dois. datacite/datacite#765
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Jun 1, 2019
1 parent 267f005 commit d1bae27
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
10 changes: 6 additions & 4 deletions app/controllers/dois_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -363,10 +363,12 @@ def destroy
end

def random
prefix = params[:prefix].presence || "10.5072"
doi = generate_random_doi(prefix, number: params[:number])

render json: { doi: doi }.to_json
if params[:prefix].present?
doi = generate_random_doi(params[:prefix], number: params[:number])
render json: { doi: doi }.to_json
else
render json: { errors: [{ status: "422", title: "Parameter prefix is required" }] }.to_json, status: :unprocessable_entity
end
end

def get_url
Expand Down
12 changes: 6 additions & 6 deletions spec/requests/dois_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
let!(:prefix) { create(:prefix, prefix: "10.14454") }
let!(:client_prefix) { create(:client_prefix, client: client, prefix: prefix) }

let(:doi) { create(:doi, client: client) }
let(:doi) { create(:doi, client: client, aasm_state: "findable") }
let(:bearer) { Client.generate_token(role_id: "client_admin", uid: client.symbol, provider_id: provider.symbol.downcase, client_id: client.symbol.downcase, password: client.password) }
let(:headers) { { 'ACCEPT'=>'application/vnd.api+json', 'CONTENT_TYPE'=>'application/vnd.api+json', 'Authorization' => 'Bearer ' + bearer }}

describe 'GET /dois', elasticsearch: true do
let!(:dois) { create_list(:doi, 3, client: client) }
let!(:dois) { create_list(:doi, 3, client: client, aasm_state: "findable") }

before do
Doi.import
Expand Down Expand Up @@ -2411,10 +2411,10 @@
end

describe 'GET /dois/random' do
before { get '/dois/random', headers: headers }
before { get '/dois/random?prefix=10.14454', headers: headers }

it 'returns random doi' do
expect(json['doi']).to start_with("10.5072")
expect(json['doi']).to start_with("10.14454")
expect(response).to have_http_status(200)
end

Expand Down Expand Up @@ -2529,10 +2529,10 @@

describe 'GET /dois/random?number' do
let(:number) { 122149076 }
before { get "/dois/random?number=#{number}", headers: headers }
before { get "/dois/random?prefix=10.14454&number=#{number}", headers: headers }

it 'returns predictable doi' do
expect(json['doi']).to eq("10.5072/3mfp-6m52")
expect(json['doi']).to eq("10.14454/3mfp-6m52")
end

it 'returns status code 200' do
Expand Down

0 comments on commit d1bae27

Please sign in to comment.