Skip to content

Commit

Permalink
set default doi state to draft. datacite/datacite#491
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Sep 24, 2018
1 parent 11064c8 commit 68af844
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 28 deletions.
2 changes: 1 addition & 1 deletion app/controllers/dois_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 6 additions & 14 deletions app/models/doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions spec/fixtures/files/datacite_89.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
12 changes: 2 additions & 10 deletions spec/models/doi_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -51,7 +48,6 @@
end

it "can't flag if draft" do
subject.start
subject.flag
expect(subject).to have_state(:draft)
end
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/requests/dois_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down

0 comments on commit 68af844

Please sign in to comment.