diff --git a/app/models/work.rb b/app/models/work.rb index 09328dc1f..1bee0180a 100644 --- a/app/models/work.rb +++ b/app/models/work.rb @@ -27,7 +27,7 @@ class Work < ApplicationRecord transitions from: [:withdrawn, :awaiting_approval], to: :awaiting_approval end - after_all_transitions :track_state_change + after_all_events :track_state_change end class << self @@ -45,8 +45,7 @@ def create_skeleton(title, user_id, collection_id, work_type, profile) end # Convenience method to create Datasets with the DataCite profile - def create_dataset(title, user_id, collection_id, datacite_resource = nil, ark = nil) - datacite_resource = PULDatacite::Resource.new(title: title) if datacite_resource.nil? + def create_dataset(title, user_id, collection_id, datacite_resource, ark = nil) work = default_work(title, user_id, collection_id, datacite_resource, ark) work.draft_doi diff --git a/spec/controllers/works_controller_spec.rb b/spec/controllers/works_controller_spec.rb index 5fde662e0..015c8c242 100644 --- a/spec/controllers/works_controller_spec.rb +++ b/spec/controllers/works_controller_spec.rb @@ -423,6 +423,7 @@ post :approve, params: { id: work.id } expect(response.status).to be 302 expect(response.location).to eq "http://test.host/works/#{work.id}" + expect(work.reload).to be_approved end it "handles withdraw" do @@ -430,13 +431,16 @@ post :withdraw, params: { id: work.id } expect(response.status).to be 302 expect(response.location).to eq "http://test.host/works/#{work.id}" + expect(work.reload).to be_withdrawn end it "handles resubmit" do sign_in user + work.withdraw!(user) post :resubmit, params: { id: work.id } expect(response.status).to be 302 expect(response.location).to eq "http://test.host/works/#{work.id}" + expect(work.reload).to be_awaiting_approval end it "handles the show page" do diff --git a/spec/models/work_spec.rb b/spec/models/work_spec.rb index 9e4f8568d..0703ee591 100644 --- a/spec/models/work_spec.rb +++ b/spec/models/work_spec.rb @@ -127,7 +127,7 @@ describe "#created_by_user" do context "when the ID is invalid" do - subject(:work) { described_class.create_dataset(title, user_id, collection_id) } + subject(:work) { described_class.create_dataset(title, user_id, collection_id, nil) } let(:title) { "test title" } let(:user_id) { user.id } let(:collection_id) { collection.id } @@ -219,11 +219,11 @@ describe "datasets waiting for approval by user type" do before do - described_class.create_dataset("test title 1", user.id, collection.id) - described_class.create_dataset("test title 2", user.id, collection.id) - described_class.create_dataset("test title 3", pppl_user.id, Collection.plasma_laboratory.id) + described_class.create_dataset("test title 1", user.id, collection.id, nil) + described_class.create_dataset("test title 2", user.id, collection.id, nil) + described_class.create_dataset("test title 3", pppl_user.id, Collection.plasma_laboratory.id, nil) # Create the dataset for `lib_user`` and @mention `user` - ds = described_class.create_dataset("test title 4", lib_user.id, Collection.library_resources.id) + ds = described_class.create_dataset("test title 4", lib_user.id, Collection.library_resources.id, nil) WorkActivity.add_system_activity(ds.id, "Tagging @#{user.uid} in this dataset", lib_user.id) end