From f742143bf1f22c365926a29debe8e89a9f5c113d Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Fri, 21 Jun 2019 13:23:43 -0400 Subject: [PATCH] fix tests. datacite/datacite#771 --- app/models/doi.rb | 4 ++-- spec/requests/dois_spec.rb | 11 ++++------- spec/requests/events_spec.rb | 10 +++++----- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/app/models/doi.rb b/app/models/doi.rb index 8edf86746..9d0f8674d 100644 --- a/app/models/doi.rb +++ b/app/models/doi.rb @@ -550,7 +550,7 @@ def registerable? # end def is_registered_or_findable? - %w(registered findable).include?(aasm_state) || agency != "DataCite" + %w(registered findable).include?(aasm_state) || %w(crossref).include?(provider_id) end def validatable? @@ -560,7 +560,7 @@ def validatable? # update URL in handle system for registered and findable state # providers europ and ethz do their own handle registration, so fetch url from handle system instead def update_url - return nil if current_user.nil? || !is_registered_or_findable? || %w(Crossref).include?(agency) + return nil if current_user.nil? || !is_registered_or_findable? if %w(europ ethz).include?(provider_id) UrlJob.perform_later(doi) diff --git a/spec/requests/dois_spec.rb b/spec/requests/dois_spec.rb index 72b484dca..ff2a831d3 100644 --- a/spec/requests/dois_spec.rb +++ b/spec/requests/dois_spec.rb @@ -1377,8 +1377,8 @@ end end - context 'state change with test prefix' do - let(:prefix) { create(:prefix, prefix: "10.5072") } + context 'draft doi no url' do + let(:prefix) { create(:prefix, prefix: "10.14454") } let!(:client_prefix) { create(:client_prefix, client: client, prefix: prefix) } let(:valid_attributes) do @@ -1386,9 +1386,7 @@ "data" => { "type" => "dois", "attributes" => { - "doi" => "10.5072/10704", - "url" => "http://www.bl.uk/pdf/patspec.pdf", - "event" => "publish" + "doi" => "10.14454/10704" } } } @@ -1398,8 +1396,7 @@ 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 eq("10.5072/10704") + expect(json.dig('data', 'attributes', 'doi')).to eq("10.14454/10704") expect(json.dig('data', 'attributes', 'state')).to eq("draft") end end diff --git a/spec/requests/events_spec.rb b/spec/requests/events_spec.rb index b83b7d065..8f375cd8a 100644 --- a/spec/requests/events_spec.rb +++ b/spec/requests/events_spec.rb @@ -66,7 +66,7 @@ expect(last_response.status).to eq(201) expect(json["errors"]).to be_nil expect(json.dig("data", "id")).to eq(event.uuid) - expect(json.dig("data", "relationships", "subj", "data")).to eq("id"=>event.subj_id, "type"=>"objects") + expect(json.dig("data", "relationships", "dois", "data")).to eq([{"id"=>"10.1371/journal.pmed.0030186", "type"=>"dois"}]) end end @@ -228,7 +228,7 @@ expect(last_response.status).to eq(200) expect(json["errors"]).to be_nil expect(json.dig("data", "id")).to eq(event.uuid) - expect(json.dig("data", "relationships", "subj", "data")).to eq("id" => event.subj_id, "type"=>"objects") + expect(json.dig("data", "relationships", "dois", "data")).to eq([{"id"=>"10.1371/journal.pmed.0030186", "type"=>"dois"}]) end end end @@ -254,7 +254,7 @@ expect(last_response.status).to eq(201) expect(json["errors"]).to be_nil expect(json.dig("data", "id")).to eq(event.uuid) - expect(json.dig("data", "relationships", "subj", "data")).to eq("id"=>event.subj_id, "type"=>"objects") + expect(json.dig("data", "relationships", "dois", "data")).to eq([{"id"=>"10.1371/journal.pmed.0030186", "type"=>"dois"}]) end end @@ -390,7 +390,7 @@ expect(last_response.status).to eq(200) expect(json["errors"]).to be_nil - expect(json.dig("data", "relationships", "subj", "data")).to eq("id"=>event.subj_id, "type"=>"objects") + expect(json.dig("data", "relationships", "dois", "data")).to eq([{"id"=>"10.1371/journal.pmed.0030186", "type"=>"dois"}]) end end end @@ -417,7 +417,7 @@ expect(last_response.status).to eq(200) expect(json["errors"]).to be_nil - expect(json.dig("data", "relationships", "subj", "data")).to eq("id"=>event.subj_id, "type"=>"objects") + expect(json.dig("data", "relationships", "dois", "data")).to eq([{"id"=>"10.1371/journal.pmed.0030186", "type"=>"dois"}]) end end