diff --git a/app/controllers/doi_requests_controller.rb b/app/controllers/doi_requests_controller.rb index 9114f6c492d927155c56d9fed010ad97b8361c39..13c19c716fd6839e17e9c732c6832416165c3fbd 100644 --- a/app/controllers/doi_requests_controller.rb +++ b/app/controllers/doi_requests_controller.rb @@ -14,14 +14,13 @@ class DoiRequestsController < ApplicationController # For now, assume the asset_type is Collection only # if params[:asset_type] == "Collection" @asset = Collection.find(params[:asset_id]) - @asset[:identifier] << t('doi.pending_doi') doi_request = DoiRequest.new(asset_id: params[:asset_id], asset_type: params[:asset_type]) - if doi_request.save && @asset.update_attributes({:identifier => @asset[:identifier]}) + if doi_request.save && @asset.update_attributes({:identifier => @asset.identifier.to_a.push(t('doi.pending_doi'))}) flash[:notice] = t('doi.messages.submit.success') redirect_to collections.collection_path(@asset) else flash[:error] = t('doi.messages.submit.failure') - redirect_to doi_requests_path + redirect_to dashboard_publishables_path end end diff --git a/app/jobs/assign_doi_job.rb b/app/jobs/assign_doi_job.rb index 0e48bb74f56ada3cd9136c3e8f818bb5663dc04d..f93b5c57c21c58462390788d8379b79dacc711d4 100644 --- a/app/jobs/assign_doi_job.rb +++ b/app/jobs/assign_doi_job.rb @@ -12,7 +12,7 @@ class AssignDoiJob def run doi_request = DoiRequest.find(doi_request_id) asset = Collection.find(doi_request.asset_id) - minted_doi = Ezid::Identifier.create( + minted_doi = Ezid::Identifier.mint( datacite_creator: (asset.creator.empty? ? "" : asset.creator.first), datacite_resourcetype: "Dataset", datacite_title: asset.title, diff --git a/app/views/records/edit_fields/_identifier.html.erb b/app/views/records/edit_fields/_identifier.html.erb deleted file mode 100644 index 3d0d1a4353d98198be9f8d164fbe11aaaf5a1f26..0000000000000000000000000000000000000000 --- a/app/views/records/edit_fields/_identifier.html.erb +++ /dev/null @@ -1,9 +0,0 @@ -<% if f.object.class.multiple? key %> - <%= f.input key, as: :multi_value_with_help, input_html: { class: 'form-control' }, required: f.object.required?(key) %> -<% else %> - <%= f.input key, required: f.object.required?(key) %> -<% end %> -<% if controller_name == 'collections' && f.object[:identifier] == [''] %> - <%= check_box_tag 'request_doi'%> - <%= label_tag(:request_doi, t('doi.labels.request')) %> -<% end %> diff --git a/spec/controllers/batch_edits_controller_spec.rb b/spec/controllers/batch_edits_controller_spec.rb index 00dc936461e6278df991adbde49af93c7bbcc929..7536eb24128f71c1820b1c454b6d901781317051 100644 --- a/spec/controllers/batch_edits_controller_spec.rb +++ b/spec/controllers/batch_edits_controller_spec.rb @@ -11,7 +11,7 @@ describe BatchEditsController, type: :controller do before do @one = GenericFile.new(creator: ["Fred"], provenance: ['foo']) @one.apply_depositor_metadata('mjg36') - @two = GenericFile.new(creator: ["Wilma"], publisher: ['Rand McNally'], provenance: ['foo'], language: ['en']) + @two = GenericFile.new(creator: ["Wilma"], provenance: ['foo']) @two.apply_depositor_metadata('mjg36') @one.save! @two.save! @@ -25,9 +25,7 @@ describe BatchEditsController, type: :controller do expect(response).to be_successful expect(assigns[:terms]).to eq [:creator, :contributor, :description, :tag, :rights, :publisher, :date_created, :subject, :language, :identifier, :based_near, :related_url, :provenance] - expect(assigns[:generic_file].creator).to eq ["Fred", "Wilma"] - expect(assigns[:generic_file].provenance).to eq ["foo"] - expect(assigns[:generic_file].language).to eq ["en"] + expect(assigns[:generic_file]).to have_attributes("creator": ["Fred", "Wilma"], "provenance": ["foo"]) end end diff --git a/spec/controllers/doi_requests_controller_spec.rb b/spec/controllers/doi_requests_controller_spec.rb index 5f888daf8df5e6dbe968206e322e2f6557fba969..e3b17211e71d75dfc602da8f5546dd5bbcde32b6 100644 --- a/spec/controllers/doi_requests_controller_spec.rb +++ b/spec/controllers/doi_requests_controller_spec.rb @@ -49,13 +49,21 @@ RSpec.describe DoiRequestsController, type: :controller do describe '#create' do let(:collection) {FactoryGirl.create(:collection, :with_default_user)} - before {sign_in user} + before(:example) do + sign_in user + end it "creates a Doi Request" do expect do post :create, asset_id: collection.id, asset_type: "Collection" end.to change { DoiRequest.count }.by(1) end + + it "successfully redirects to the collection show page" do + post :create, asset_id: collection.id, asset_type: "Collection" + expect(assigns(:asset).identifier).to include('doi:pending') + expect(response).to redirect_to('/collections/' + collection.id) + end end describe "#mint" do diff --git a/spec/controllers/publishables_controller_spec.rb b/spec/controllers/publishables_controller_spec.rb index 316855402aa36be0cb7a65d099e41d4c521ae280..3ffbcafb874756029916194dc8ed246fb2ae0dee 100644 --- a/spec/controllers/publishables_controller_spec.rb +++ b/spec/controllers/publishables_controller_spec.rb @@ -5,11 +5,7 @@ RSpec.describe PublishablesController, type: :controller do let(:user) {FactoryGirl.create(:user)} describe "#index" do - before do - sign_in user - end - - let(:collection) do + let!(:collection) do f = FactoryGirl.create(:generic_file) c = FactoryGirl.build(:collection) c.apply_depositor_metadata user.user_key @@ -18,10 +14,17 @@ RSpec.describe PublishablesController, type: :controller do c end - it "shows collections with files and without doi requests" do - collections = [collection] + before(:example) do + sign_in user get :index - expect(assigns[:publishables]).to eq collections + end + + + it "shows collections with files and without doi requests" do + expect(response).to render_template('index') + expect(assigns[:publishables]).to eq [collection] + expect(response.body).to have_content("mock title") + expect(response.body).to match(/Request DOI/) end end end diff --git a/spec/factories/collections.rb b/spec/factories/collections.rb index 10e168226e703783dee973933b3d883df1313c44..3ffd226c107cc2c473c01b01e87385de02784b83 100644 --- a/spec/factories/collections.rb +++ b/spec/factories/collections.rb @@ -11,8 +11,7 @@ FactoryGirl.define do trait :with_pending_doi do after(:create) do |collection| DoiRequest.create(asset_id: collection.id, asset_type: "Collection") - collection[:identifier] << 'doi:pending' - collection.update_attributes({:identifier => collection[:identifier]}) + collection.update_attributes({:identifier => collection.identifier.to_a.push("doi:pending")}) end end @@ -20,7 +19,7 @@ FactoryGirl.define do after(:create) do |collection| doi_request = DoiRequest.create(asset_id: collection.id, asset_type: 'Collection') - minted_doi = Ezid::Identifier.create( + minted_doi = Ezid::Identifier.mint( datacite_creator: (collection.creator.empty? ? "" : collection.creator.first), datacite_resourcetype: "Dataset", datacite_title: collection.title, diff --git a/spec/factories/doi_requests.rb b/spec/factories/doi_requests.rb index 64cb5012b341e9bdb1a6a50fa4c2d81067d99d80..f6f2b42b340e4d1cb935c2953f0ff195b482fa84 100644 --- a/spec/factories/doi_requests.rb +++ b/spec/factories/doi_requests.rb @@ -1,7 +1,5 @@ FactoryGirl.define do - # maybe this should have a trait "with :collection" that biulds the collection as well! factory :doi_request do asset_id 'mock-id' - asset_type 'Collection' end end diff --git a/spec/features/collection_view_spec.rb b/spec/features/collection_view_spec.rb index ae1529da0480418cb6ecb2b0f856a9518d8b27a7..fab443f4ce9e50c2da4ece52f5568a0b812b482a 100644 --- a/spec/features/collection_view_spec.rb +++ b/spec/features/collection_view_spec.rb @@ -22,11 +22,4 @@ RSpec.describe 'collection view page', type: :feature do expect(page).to have_content "Edited Title" end - it 'allows user to request doi for the collection' do - pending "this feature has been removed!" - visit '/collections/' + collection.id - click_button "Request DOI" - expect(page).to have_content "DOI request is pending..." - end - end diff --git a/spec/forms/datarepo_file_edit_form_spec.rb b/spec/forms/datarepo_file_edit_form_spec.rb index 61a9c90f122fe03d6c32c92a459c12f736d8cb50..40fe70930c199ce3a562134ac80756719319b9a4 100644 --- a/spec/forms/datarepo_file_edit_form_spec.rb +++ b/spec/forms/datarepo_file_edit_form_spec.rb @@ -5,13 +5,13 @@ describe DatarepoFileEditForm do describe "#terms" do it "returns a list" do - expect(subject.terms).to eq([:resource_type, :title, :creator, :contributor, :description, :tag, :rights, :publisher, + expect(subject.terms).to match_array([:resource_type, :title, :creator, :contributor, :description, :tag, :rights, :publisher, :date_created, :subject, :language, :identifier, :based_near, :related_url, :provenance]) end end it "initializes provenance field" do - expect(subject.provenance).to eq [''] + expect(subject.provenance).to match_array([""]) end describe ".model_attributes" do @@ -19,7 +19,7 @@ describe DatarepoFileEditForm do subject { described_class.model_attributes(params) } it "only changes provenance" do - expect(subject['provenance']).to eq ["foo"] + expect(subject['provenance']).to match_array(["foo"]) expect(subject['description']).to be_empty expect(subject['permissions_attributes']).to eq("2" => { "access" => "edit", "id" => "a987551e-b87f-427a-8721-3e5942273125", "_destroy" => "true" }) end diff --git a/spec/models/doi_request_spec.rb b/spec/models/doi_request_spec.rb index 072c6a684db0332f80e014bf31c0bd59f5ac2095..a1e1c6d6e14b4c20826968877f577b651cf0727c 100644 --- a/spec/models/doi_request_spec.rb +++ b/spec/models/doi_request_spec.rb @@ -1,19 +1,35 @@ require 'spec_helper' RSpec.describe DoiRequest, type: :model do - let(:doi_request) {FactoryGirl.build(:doi_request)} + subject {FactoryGirl.build(:doi_request)} + + it "initially saves as a pending request" do + subject.save + expect(subject).not_to be_completed + end + + it "saves as a Collection asset by default" do + subject.save + expect(subject).to be_collection + end it "can be created with asset_id" do - expect{doi_request.save}.to change {DoiRequest.count}.by(1) + expect{subject.save}.to change {DoiRequest.count}.by(1) + end + + it "can be completed with Ezid assigned doi" do + subject.ezid_doi = "doi:10.5072/FK22B91G0V" + subject.save + expect(subject).to be_completed end it "cannot have duplicate asset_id" do - expect{2.times {doi_request.save}}.to change {DoiRequest.count}.by(1) + expect{2.times {subject.save}}.to change {DoiRequest.count}.by(1) end it "can be deleted after saving" do - doi_request.save - expect{doi_request.delete}.to change {DoiRequest.count}.by(-1) + subject.save + expect{subject.delete}.to change {DoiRequest.count}.by(-1) end end diff --git a/spec/models/generic_file_spec.rb b/spec/models/generic_file_spec.rb index cbf17a0ea7e77c603893d137cd5a583a44a5fcb8..97ca7dc559dfe93566fcbac2c1d59e432ffe4adc 100644 --- a/spec/models/generic_file_spec.rb +++ b/spec/models/generic_file_spec.rb @@ -10,7 +10,7 @@ describe GenericFile, :type => :model do describe "#dc metadata" do it "allows reading and writing for dc provenance" do subject.provenance = ['foo', 'bar'] - expect(subject.provenance).to eq ['foo', 'bar'] + expect(subject.provenance).to match_array(['foo', 'bar']) end end diff --git a/spec/presenters/datarepo_generic_file_presenter_spec.rb b/spec/presenters/datarepo_generic_file_presenter_spec.rb index b6e12546fb5648898c4dae4c0046248257ab335e..8cbc2522cc2602936b4a730620bd944de8261806 100644 --- a/spec/presenters/datarepo_generic_file_presenter_spec.rb +++ b/spec/presenters/datarepo_generic_file_presenter_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe DatarepoGenericFilePresenter do describe ".terms" do it "returns a list" do - expect(described_class.terms).to eq([:resource_type, :title, + expect(described_class.terms).to match_array([:resource_type, :title, :creator, :contributor, :description, :tag, :rights, :publisher, :date_created, :subject, :language, :identifier, :based_near, :related_url, :provenance]) @@ -16,7 +16,7 @@ describe DatarepoGenericFilePresenter do let(:file) { build(:generic_file, provenance: ["processing history"]) } it "displays provenance metadata" do - expect(presenter.provenance). to eq ["processing history"] + expect(presenter.provenance). to match_array(["processing history"]) end end end