From 68af84450d4cc2f9e552717da7cbae12c189de08 Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Mon, 24 Sep 2018 23:24:18 +0200 Subject: [PATCH] set default doi state to draft. datacite/datacite#491 --- app/controllers/dois_controller.rb | 2 +- app/models/doi.rb | 20 ++++++-------------- spec/fixtures/files/datacite_89.json | 3 +-- spec/models/doi_spec.rb | 12 ++---------- spec/requests/dois_spec.rb | 2 +- 5 files changed, 11 insertions(+), 28 deletions(-) diff --git a/app/controllers/dois_controller.rb b/app/controllers/dois_controller.rb index 3af1ed6a5..9e700513d 100644 --- a/app/controllers/dois_controller.rb +++ b/app/controllers/dois_controller.rb @@ -196,7 +196,7 @@ def validate def create # Rails.logger.info safe_params.inspect - @doi = Doi.new(safe_params.merge(event: safe_params[:event] || "start")) + @doi = Doi.new(safe_params.merge(event: safe_params[:event])) authorize! :create, @doi # capture username and password for reuse in the handle system diff --git a/app/models/doi.rb b/app/models/doi.rb index a1b18a172..2db69b662 100644 --- a/app/models/doi.rb +++ b/app/models/doi.rb @@ -26,26 +26,19 @@ class Doi < ActiveRecord::Base include Elasticsearch::Model aasm :whiny_transitions => false do - # initial is default state for new DOIs. This is needed to handle DOIs created - # outside of this application (i.e. the MDS API) - state :undetermined, :initial => true - state :draft, :tombstoned, :registered, :findable, :flagged, :broken - - event :start do - transitions :from => :undetermined, :to => :draft - end + # draft is initial istate for new DOIs. + state :draft, :initial => true + state :tombstoned, :registered, :findable, :flagged, :broken event :register do # can't register test prefix - transitions :from => [:undetermined, :draft], :to => :registered, :unless => :is_test_prefix? - transitions :from => :undetermined, :to => :draft + transitions :from => [:draft], :to => :registered, :unless => :is_test_prefix? end event :publish do # can't index test prefix - transitions :from => [:undetermined, :draft], :to => :findable, :unless => :is_test_prefix? + transitions :from => [:draft], :to => :findable, :unless => :is_test_prefix? transitions :from => :registered, :to => :findable - transitions :from => :undetermined, :to => :draft end event :hide do @@ -427,7 +420,7 @@ def cache_key end def event=(value) - self.send(value) if %w(start register publish hide).include?(value) + self.send(value) if %w(register publish hide).include?(value) end def timestamp @@ -494,7 +487,6 @@ def update_metadata end def set_defaults - self.start if aasm_state == "undetermined" self.is_active = (aasm_state == "findable") ? "\x01" : "\x00" self.version = version.present? ? version + 1 : 0 self.updated = Time.zone.now.utc.iso8601 diff --git a/spec/fixtures/files/datacite_89.json b/spec/fixtures/files/datacite_89.json index 851c71439..6c348c930 100644 --- a/spec/fixtures/files/datacite_89.json +++ b/spec/fixtures/files/datacite_89.json @@ -4,8 +4,7 @@ "attributes": { "doi": "10.24425/119496", "xml": "PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48cmVzb3VyY2UgeG1sbnM9Imh0dHA6Ly9kYXRhY2l0ZS5vcmcvc2NoZW1hL2tlcm5lbC00IiB4bWxuczp4c2k9Imh0dHA6Ly93d3cudzMub3JnLzIwMDEvWE1MU2NoZW1hLWluc3RhbmNlIiB4c2k6c2NoZW1hTG9jYXRpb249Imh0dHA6Ly9kYXRhY2l0ZS5vcmcvc2NoZW1hL2tlcm5lbC00IGh0dHA6Ly9zY2hlbWEuZGF0YWNpdGUub3JnL21ldGEva2VybmVsLTQuMS9tZXRhZGF0YS54c2QiPjxpZGVudGlmaWVyIGlkZW50aWZpZXJUeXBlPSJET0kiPjEwLjI0NDI1LzExOTQ5NjwvaWRlbnRpZmllcj48Y3JlYXRvcnM+PGNyZWF0b3I+PGNyZWF0b3JOYW1lPig6dW5hdik8L2NyZWF0b3JOYW1lPjwvY3JlYXRvcj48L2NyZWF0b3JzPjx0aXRsZXM+PHRpdGxlPjMyPC90aXRsZT48L3RpdGxlcz48cHVibGlzaGVyPkNvbW1pdHRlZSBmb3IgUHN5Y2hvbG9naWNhbCBTY2llbmNlIFBBUzwvcHVibGlzaGVyPjxwdWJsaWNhdGlvblllYXI+MjAxODwvcHVibGljYXRpb25ZZWFyPjxyZXNvdXJjZVR5cGUgcmVzb3VyY2VUeXBlR2VuZXJhbD0iVGV4dCI+QXJ0eWt1xYI8L3Jlc291cmNlVHlwZT48ZGF0ZXM+PGRhdGUgZGF0ZVR5cGU9Iklzc3VlZCI+MjAxODwvZGF0ZT48L2RhdGVzPjwvcmVzb3VyY2U+", - "validate": "true", - "event": "start" + "validate": "true" }, "relationships": { "client": { diff --git a/spec/models/doi_spec.rb b/spec/models/doi_spec.rb index 52d79b6d3..7fba42ce7 100644 --- a/spec/models/doi_spec.rb +++ b/spec/models/doi_spec.rb @@ -8,9 +8,8 @@ describe "state" do subject { create(:doi) } - describe "start" do - it "can start" do - subject.start + describe "draft" do + it "default" do expect(subject).to have_state(:draft) end end @@ -23,7 +22,6 @@ it "can't register with test prefix" do subject = create(:doi, doi: "10.5072/x") - subject.start subject.register expect(subject).to have_state(:draft) end @@ -37,7 +35,6 @@ it "can't register with test prefix" do subject = create(:doi, doi: "10.5072/x") - subject.start subject.publish expect(subject).to have_state(:draft) end @@ -51,7 +48,6 @@ end it "can't flag if draft" do - subject.start subject.flag expect(subject).to have_state(:draft) end @@ -65,8 +61,6 @@ end it "can't link_check if draft" do - subject.start - subject.link_check expect(subject).to have_state(:draft) end @@ -98,13 +92,11 @@ subject { build(:doi, client: client, current_user: current_user) } it "don't update state change" do - subject.start expect { subject.save }.not_to have_enqueued_job(HandleJob) expect(subject).to have_state(:draft) end it "don't update url change" do - subject.start subject.url = url expect { subject.save }.not_to have_enqueued_job(HandleJob) end diff --git a/spec/requests/dois_spec.rb b/spec/requests/dois_spec.rb index af6e9b1ea..979a8e987 100644 --- a/spec/requests/dois_spec.rb +++ b/spec/requests/dois_spec.rb @@ -1933,7 +1933,7 @@ end describe 'GET /dois/DOI/get-url draft doi', vcr: true do - let(:doi) { create(:doi, client: client, doi: "10.14454/61y1-e521", event: "start") } + let(:doi) { create(:doi, client: client, doi: "10.14454/61y1-e521") } before { get "/dois/#{doi.doi}/get-url", headers: headers }