From 9c0afc81f493d59d362e55fc9e9f0de8874f8099 Mon Sep 17 00:00:00 2001
From: carolyncole <1599081+carolyncole@users.noreply.github.com>
Date: Mon, 22 Apr 2024 14:10:21 -0400
Subject: [PATCH] Require README for a work to be completed (#1777)
---
app/controllers/works_controller.rb | 8 +++
app/controllers/works_wizard_controller.rb | 3 +-
app/models/work.rb | 4 +-
app/services/work_validator.rb | 12 +++++
app/views/works_wizard/review.html.erb | 2 +-
config/routes.rb | 5 +-
spec/controllers/works_controller_spec.rb | 26 ++++++++--
.../works_wizard_controller_spec.rb | 2 +-
spec/models/upload_snapshot_spec.rb | 16 +++++-
spec/models/work_spec.rb | 52 +++++++++++--------
spec/models/work_state_spec.rb | 5 +-
spec/services/work_validator_spec.rb | 46 ++++++++++++++++
spec/system/authz_submitter_spec.rb | 3 +-
spec/system/authz_super_admin_spec.rb | 4 +-
spec/system/external_ids_spec.rb | 2 +-
spec/system/migrate_submission_spec.rb | 14 +++--
spec/system/rss_spec.rb | 2 +-
spec/system/work_wizard_spec.rb | 4 +-
18 files changed, 166 insertions(+), 44 deletions(-)
diff --git a/app/controllers/works_controller.rb b/app/controllers/works_controller.rb
index 1310a54f6..0ba2dba41 100644
--- a/app/controllers/works_controller.rb
+++ b/app/controllers/works_controller.rb
@@ -221,6 +221,14 @@ def upload_files
upload_service.update_precurated_file_list(params["files"], [])
end
+ # Validates that the work is ready to be approved
+ # GET /works/1/validate
+ def validate
+ @work = Work.find(params[:id])
+ @work.complete_submission!(current_user)
+ redirect_to user_path(current_user)
+ end
+
private
# Extract the Work ID parameter
diff --git a/app/controllers/works_wizard_controller.rb b/app/controllers/works_wizard_controller.rb
index e50739f15..78064ec0b 100644
--- a/app/controllers/works_wizard_controller.rb
+++ b/app/controllers/works_wizard_controller.rb
@@ -104,7 +104,8 @@ def review
end
# Validates that the work is ready to be approved
- # GET /works/1/validate
+ # POST /works/1/validate-wizard
+ # PATCH /works/1/validate-wizard
def validate
@work.submission_notes = params["submission_notes"]
if params[:save_only] == "true"
diff --git a/app/models/work.rb b/app/models/work.rb
index 2262afe81..e887e414f 100644
--- a/app/models/work.rb
+++ b/app/models/work.rb
@@ -19,7 +19,7 @@ class InvalidGroupError < ::ArgumentError; end
alias state_history user_work
- delegate :valid_to_submit, :valid_to_draft, :valid_to_approve, to: :work_validator
+ delegate :valid_to_submit, :valid_to_draft, :valid_to_approve, :valid_to_complete, to: :work_validator
include AASM
@@ -32,7 +32,7 @@ class InvalidGroupError < ::ArgumentError; end
end
event :complete_submission do
- transitions from: :draft, to: :awaiting_approval, guard: :valid_to_submit
+ transitions from: :draft, to: :awaiting_approval, guard: :valid_to_complete
end
event :request_changes do
diff --git a/app/services/work_validator.rb b/app/services/work_validator.rb
index 647259417..3eaa5216c 100644
--- a/app/services/work_validator.rb
+++ b/app/services/work_validator.rb
@@ -27,6 +27,11 @@ def valid_to_draft(*)
errors.count == 0
end
+ def valid_to_complete(*args)
+ validate_files
+ valid_to_submit(args)
+ end
+
def valid_to_submit(*args)
valid_to_draft(args)
validate_metadata
@@ -44,6 +49,7 @@ def valid_to_approve(user)
unless user.has_role? :group_admin, group
errors.add :base, "Unauthorized to Approve"
end
+ validate_files
if pre_curation_uploads.empty? && post_curation_uploads.empty?
errors.add :base, "Uploads must be present for a work to be approved"
end
@@ -151,4 +157,10 @@ def validate_metadata
errors.add(:base, "Must provide a Version number") if resource.version_number.blank?
validate_related_objects
end
+
+ def validate_files
+ return if @work.resource.migrated
+ readme = Readme.new(work, nil)
+ errors.add(:base, "Must provide a README") if readme.blank?
+ end
end
diff --git a/app/views/works_wizard/review.html.erb b/app/views/works_wizard/review.html.erb
index 62a82d167..f59301d0f 100644
--- a/app/views/works_wizard/review.html.erb
+++ b/app/views/works_wizard/review.html.erb
@@ -6,7 +6,7 @@
it more discoverable and reusable. Recommendations will be available in the "unfinished submissions"
section of this form within 5-10 business days.
- <%= form_with(model: @work, url: work_validate_path(@work)) do |form| %>
+ <%= form_with(model: @work, url: work_validate_wizard_path(@work)) do |form| %>
diff --git a/config/routes.rb b/config/routes.rb
index 080a7a0aa..63a9049ee 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -45,8 +45,9 @@
get "works/:id/review", to: "works_wizard#review", as: :work_review
post "works/:id/review", to: "works_wizard#review"
patch "works/:id/review", to: "works_wizard#review"
- post "works/:id/validate", to: "works_wizard#validate", as: :work_validate
- patch "works/:id/validate", to: "works_wizard#validate"
+ post "works/:id/validate-wizard", to: "works_wizard#validate", as: :work_validate_wizard
+ patch "works/:id/validate-wizard", to: "works_wizard#validate"
+ post "works/:id/validate", to: "works#validate", as: :work_validate
get "works/:id/attachment-select", to: "works_wizard#attachment_select", as: :work_attachment_select
post "works/:id/attachment-select", to: "works_wizard#attachment_selected", as: :work_attachment_selected
patch "works/:id/attachment-select", to: "works_wizard#attachment_selected"
diff --git a/spec/controllers/works_controller_spec.rb b/spec/controllers/works_controller_spec.rb
index 195d0d4cc..f307aec49 100644
--- a/spec/controllers/works_controller_spec.rb
+++ b/spec/controllers/works_controller_spec.rb
@@ -693,7 +693,7 @@
describe "#approve" do
before do
- stub_s3 data: [FactoryBot.build(:s3_file)]
+ stub_s3 data: [FactoryBot.build(:s3_readme), FactoryBot.build(:s3_file)]
allow(Work).to receive(:find).with(work.id).and_return(work)
allow(Work).to receive(:find).with(work.id.to_s).and_return(work)
allow(work).to receive(:publish_precurated_files).and_return(true)
@@ -742,13 +742,14 @@
context "no files attached" do
it "handles aproval errors" do
+ fake_s3_service = stub_s3 data: [FactoryBot.build(:s3_readme)]
work.complete_submission!(user)
- stub_s3 data: []
+ allow(fake_s3_service).to receive(:client_s3_files).and_return([])
sign_in curator
post :approve, params: { id: work.id }
expect(response.status).to be 302
# rubocop:disable Layout/LineLength
- expect(assigns[:errors]).to eq(["We apologize, the following errors were encountered: Uploads must be present for a work to be approved. Please contact the PDC Describe administrators for any assistance."])
+ expect(assigns[:errors]).to eq(["We apologize, the following errors were encountered: Must provide a README, Uploads must be present for a work to be approved. Please contact the PDC Describe administrators for any assistance."])
# rubocop:enable Layout/LineLength
end
end
@@ -1271,4 +1272,23 @@
expect(assigns[:errors]).to eq(["Contributor: Type cannot be nil"])
end
end
+
+ describe "#validate" do
+ it "validates a work and errors when there is no readme" do
+ stub_s3
+ sign_in user
+ post :validate, params: { id: work.id }
+ expect(response).to redirect_to(edit_work_path(work))
+ expect(controller.flash[:notice]).to eq("We apologize, the following errors were encountered: Must provide a README. Please contact the PDC Describe administrators for any assistance.")
+ end
+
+ it "validates a work completes it when there are no errors" do
+ stub_s3 data: [FactoryBot.build(:s3_readme)]
+ sign_in user
+ post :validate, params: { id: work.id }
+ expect(response).to redirect_to(user_path(user))
+ expect(controller.flash[:notice]).to be_nil
+ expect(work.reload).to be_awaiting_approval
+ end
+ end
end
diff --git a/spec/controllers/works_wizard_controller_spec.rb b/spec/controllers/works_wizard_controller_spec.rb
index 4ed43124a..a8372176c 100644
--- a/spec/controllers/works_wizard_controller_spec.rb
+++ b/spec/controllers/works_wizard_controller_spec.rb
@@ -334,7 +334,7 @@
describe "#validate" do
before do
- stub_s3
+ stub_s3 data: [FactoryBot.build(:s3_readme)]
sign_in user
end
diff --git a/spec/models/upload_snapshot_spec.rb b/spec/models/upload_snapshot_spec.rb
index b1b2f69d8..54c17e991 100644
--- a/spec/models/upload_snapshot_spec.rb
+++ b/spec/models/upload_snapshot_spec.rb
@@ -54,12 +54,18 @@
let(:fake_s3_service_pre) { stub_s3(data: [file1]) }
let(:fake_s3_service_post) { stub_s3(data: []) }
+ let(:readme) { FactoryBot.build(:s3_readme) }
before do
- allow(S3QueryService).to receive(:new).and_return(fake_s3_service_pre, fake_s3_service_post)
+ fake_s3_service_post
+ fake_s3_service_pre
+
+ allow(S3QueryService).to receive(:new).with(instance_of(Work), "precuration").and_return(fake_s3_service_pre)
+ allow(S3QueryService).to receive(:new).with(instance_of(Work), "postcuration").and_return(fake_s3_service_post)
allow(fake_s3_service_pre.client).to receive(:head_object).with(bucket: "example-post-bucket", key: work.s3_object_key).and_raise(Aws::S3::Errors::NotFound.new("blah", "error"))
allow(fake_s3_service_post).to receive(:bucket_name).and_return("example-post-bucket")
allow(fake_s3_service_pre).to receive(:bucket_name).and_return("example-pre-bucket")
+ allow(fake_s3_service_pre).to receive(:client_s3_files).and_return([readme], [readme, file1])
stub_ark
stub_datacite_doi
@@ -83,12 +89,18 @@
let(:fake_s3_service_pre) { stub_s3(data: [file2]) }
let(:fake_s3_service_post) { stub_s3(data: [file2]) }
+ let(:readme) { FactoryBot.build(:s3_readme) }
before do
- allow(S3QueryService).to receive(:new).and_return(fake_s3_service_pre, fake_s3_service_post)
+ fake_s3_service_post
+ fake_s3_service_pre
+
+ allow(S3QueryService).to receive(:new).with(instance_of(Work), "precuration").and_return(fake_s3_service_pre)
+ allow(S3QueryService).to receive(:new).with(instance_of(Work), "postcuration").and_return(fake_s3_service_post)
allow(fake_s3_service_pre.client).to receive(:head_object).with(bucket: "example-post-bucket", key: work.s3_object_key).and_raise(Aws::S3::Errors::NotFound.new("blah", "error"))
allow(fake_s3_service_post).to receive(:bucket_name).and_return("example-post-bucket")
allow(fake_s3_service_pre).to receive(:bucket_name).and_return("example-pre-bucket")
+ allow(fake_s3_service_pre).to receive(:client_s3_files).and_return([readme], [readme, file2])
stub_ark
stub_datacite_doi
diff --git a/spec/models/work_spec.rb b/spec/models/work_spec.rb
index 18e705d97..0bf1f9375 100644
--- a/spec/models/work_spec.rb
+++ b/spec/models/work_spec.rb
@@ -26,6 +26,7 @@
fixture_file_upload("us_covid_2019.csv", "text/csv")
end
let(:s3_file) { FactoryBot.build :s3_file, filename: "us_covid_2019.csv", work: }
+ let(:readme) { FactoryBot.build(:s3_readme) }
before do
stub_datacite(host: "api.datacite.org", body: datacite_register_body(prefix: "10.34770"))
@@ -168,23 +169,22 @@
let(:file1) { FactoryBot.build(:s3_file, filename: "#{work.doi}/#{work.id}/us_covid_2019.csv", work:, size: 1024) }
let(:file2) { FactoryBot.build(:s3_file, filename: "#{work.doi}/#{work.id}/us_covid_2019_2.csv", work:, size: 2048) }
+ let(:readme) { FactoryBot.build(:s3_readme) }
- let(:post_curation_data_profile) { { objects: [file1, file2] } }
- let(:pre_curated_data_profile) { { objects: [] } }
-
- let(:fake_s3_service_pre) { stub_s3(data: [file1, file2]) }
- let(:fake_s3_service_post) { stub_s3 }
+ let(:fake_s3_service_pre) { stub_s3 }
+ let(:fake_s3_service_post) { stub_s3(data: [file1, file2]) }
before do
# initialize so the next allows happen after the stubs
fake_s3_service_post
fake_s3_service_pre
- allow(S3QueryService).to receive(:new).with(work, "postcuration").and_return(fake_s3_service_post)
- allow(S3QueryService).to receive(:new).with(work, "precuration").and_return(fake_s3_service_pre)
+ allow(S3QueryService).to receive(:new).with(instance_of(Work), "precuration").and_return(fake_s3_service_pre)
+ allow(S3QueryService).to receive(:new).with(instance_of(Work), "postcuration").and_return(fake_s3_service_post)
allow(fake_s3_service_pre.client).to receive(:head_object).with(bucket: "example-post-bucket", key: work.s3_object_key).and_raise(Aws::S3::Errors::NotFound.new("blah", "error"))
allow(fake_s3_service_post).to receive(:bucket_name).and_return("example-post-bucket")
allow(fake_s3_service_pre).to receive(:bucket_name).and_return("example-pre-bucket")
+ allow(fake_s3_service_pre).to receive(:client_s3_files).and_return([readme], [readme, file1, file2])
end
it "approves works and records the change history" do
@@ -199,8 +199,10 @@
it "transfers the files to the AWS Bucket" do
stub_datacite_doi
work.approve!(curator_user)
- work.reload
+ work_id = work.id
+ work = Work.find(work_id)
+ expect(work).to be_approved
expect(fake_s3_service_pre).to have_received(:publish_files).once
expect(fake_s3_service_post).to have_received(:bucket_name).once
expect(fake_s3_service_pre.client).to have_received(:head_object).once
@@ -218,10 +220,8 @@
end
context "when the pre curation bucket is empty" do
- let(:fake_s3_service_pre) { stub_s3(data: []) }
-
before do
- allow(fake_s3_service_pre.client).to receive(:head_object).with(bucket: "example-post-bucket", key: work.s3_object_key).and_return(true)
+ allow(fake_s3_service_pre).to receive(:client_s3_files).and_return([])
end
it "raises an error" do
@@ -232,9 +232,10 @@
context "when the Work is under active embargo" do
subject(:work) { FactoryBot.create(:awaiting_approval_work, doi: "10.34770/123-abc", embargo_date:) }
+ let(:work_after_approve) { Work.find(work.id) }
let(:embargo_date) { Date.parse("2033-09-14") }
- let(:json) { JSON.parse(work.to_json) }
+ let(:json) { JSON.parse(work_after_approve.to_json) }
let(:uploaded_file) do
fixture_file_upload("us_covid_2019.csv", "text/csv")
end
@@ -258,7 +259,7 @@
end
it "does not serialize the files in JSON" do
- expect(work.post_curation_uploads).not_to be_empty
+ expect(work_after_approve.post_curation_uploads).not_to be_empty
expect(json).to include("files")
expect(json["files"]).to be_empty
@@ -267,9 +268,10 @@
context "when the Work is under an expired embargo" do
subject(:work) { FactoryBot.create(:awaiting_approval_work, doi: "10.34770/123-abc", embargo_date:) }
+ let(:work_after_approve) { Work.find(work.id) }
let(:embargo_date) { Date.parse("2023-09-14") }
- let(:json) { JSON.parse(work.to_json) }
+ let(:json) { JSON.parse(work_after_approve.to_json) }
let(:uploaded_file) do
fixture_file_upload("us_covid_2019.csv", "text/csv")
end
@@ -284,11 +286,10 @@
stub_datacite_doi
work.approve!(curator_user)
- work.reload
end
it "does serialize the files in JSON" do
- expect(work.post_curation_uploads).not_to be_empty
+ expect(work_after_approve.post_curation_uploads).not_to be_empty
expect(json).to include("files")
expect(json["files"]).not_to be_empty
@@ -335,7 +336,7 @@
end
before do
- fake_s3_service = stub_s3(data: [s3_file])
+ fake_s3_service = stub_s3(data: [readme, s3_file])
allow(fake_s3_service.client).to receive(:head_object).with(bucket: "example-bucket", key: work.s3_object_key).and_raise(Aws::S3::Errors::NotFound.new("blah", "error"))
end
@@ -564,7 +565,9 @@
end
describe "#complete_submission" do
+ let(:fake_s3_service) { stub_s3 data: [readme, s3_file] }
let(:awaiting_approval_work) do
+ fake_s3_service
work = FactoryBot.create :draft_work
work.complete_submission!(user)
work
@@ -581,7 +584,6 @@
it "transitions from awaiting_approval to approved" do
stub_datacite_doi
- fake_s3_service = stub_s3(data: [s3_file])
allow(fake_s3_service.client).to receive(:head_object).with(bucket: "example-bucket", key: awaiting_approval_work.s3_object_key).and_raise(Aws::S3::Errors::NotFound.new("blah", "error"))
awaiting_approval_work.approve!(curator_user)
@@ -624,13 +626,20 @@
end
describe "#approve" do
- let(:fake_s3_service_pre) { stub_s3(data: [s3_file]) }
- let(:fake_s3_service_post) { stub_s3(data: [s3_file]) }
+ let(:fake_s3_service_pre) { stub_s3(data: [readme, s3_file]) }
+ let(:fake_s3_service_post) { stub_s3(data: [readme, s3_file]) }
let(:approved_work) do
work = FactoryBot.create :awaiting_approval_work, doi: "10.34770/123-abc"
stub_request(:put, "https://api.datacite.org/dois/10.34770/123-abc")
- allow(S3QueryService).to receive(:new).and_return(fake_s3_service_pre, fake_s3_service_post)
+
+ # initialize so the next allows happen after the stubs
+ fake_s3_service_post
+ fake_s3_service_pre
+
+ allow(S3QueryService).to receive(:new).with(instance_of(Work), "precuration").and_return(fake_s3_service_pre)
+ allow(S3QueryService).to receive(:new).with(instance_of(Work), "postcuration").and_return(fake_s3_service_post)
+
allow(fake_s3_service_pre.client).to receive(:head_object).with(bucket: "example-post-bucket", key: work.s3_object_key).and_raise(Aws::S3::Errors::NotFound.new("blah", "error"))
allow(fake_s3_service_post).to receive(:bucket_name).and_return("example-post-bucket")
allow(fake_s3_service_pre).to receive(:bucket_name).and_return("example-pre-bucket")
@@ -1072,6 +1081,7 @@
describe "delete" do
it "cleans up all the related objects" do
+ work.resource.migrated = true
work.complete_submission!(user)
expect { work.destroy }.to change { Work.count }.by(-1)
.and change { UserWork.count }.by(-1)
diff --git a/spec/models/work_state_spec.rb b/spec/models/work_state_spec.rb
index d40aef524..0e65389d4 100644
--- a/spec/models/work_state_spec.rb
+++ b/spec/models/work_state_spec.rb
@@ -3,6 +3,9 @@
RSpec.describe "Work state transions", type: :model do
let(:curator_user) { FactoryBot.create :user, groups_to_admin: [work.group] }
+ before do
+ stub_s3 data: [FactoryBot.build(:s3_readme)]
+ end
{
none_work: :draft!,
@@ -32,7 +35,7 @@
it "Creates a work activity notification for the curator & the user when approved" do
allow(work).to receive(:publish)
- stub_s3 data: [FactoryBot.build(:s3_file)]
+ stub_s3 data: [FactoryBot.build(:s3_readme), FactoryBot.build(:s3_file)]
expect do
work.approve!(curator_user)
end.to change { WorkActivity.count }.by(2)
diff --git a/spec/services/work_validator_spec.rb b/spec/services/work_validator_spec.rb
index 13044d08b..704d4efe3 100644
--- a/spec/services/work_validator_spec.rb
+++ b/spec/services/work_validator_spec.rb
@@ -46,6 +46,7 @@
context "datacite xml is invalid" do
let(:work) do
+ stub_s3 data: [FactoryBot.build(:s3_readme)]
work = FactoryBot.create :draft_work
work.resource.individual_contributors = [PDCMetadata::Creator.new_individual_contributor("Sally", "Smith", "", "", 0)]
work.save
@@ -59,4 +60,49 @@
expect(work.errors.full_messages).to eq(["Contributor: Type cannot be nil"])
end
end
+
+ describe "#valid_to_complete" do
+ let(:work) { FactoryBot.create :draft_work }
+
+ it "is not valid" do
+ stub_s3
+ validator = WorkValidator.new(work)
+ expect(validator.valid?).to be_truthy # we can still save, we just can not transition to awaiting approval
+ expect(validator.valid_to_complete).to be_falsey
+ expect(work.errors.full_messages).to eq(["Must provide a README"])
+ end
+
+ context "a migrated work" do
+ it "is valid" do
+ work.resource.migrated = true
+ stub_s3
+ validator = WorkValidator.new(work)
+ expect(validator.valid?).to be_truthy # we can still save, we just can not transition to awaiting approval
+ expect(validator.valid_to_complete).to be_truthy
+ expect(work.errors.full_messages).to eq([])
+ end
+ end
+
+ context "a readme exisits" do
+ it "is valid" do
+ stub_s3 data: [FactoryBot.build(:s3_readme)]
+ validator = WorkValidator.new(work)
+ expect(validator.valid?).to be_truthy
+ expect(validator.valid_to_complete).to be_truthy
+ expect(work.errors.full_messages).to eq([])
+ end
+ end
+ end
+
+ describe "#valid_to_submit" do
+ let(:work) { FactoryBot.create :draft_work }
+
+ it "is valid" do
+ stub_s3
+ validator = WorkValidator.new(work)
+ expect(validator.valid?).to be_truthy
+ expect(validator.valid_to_submit).to be_truthy
+ expect(work.errors.full_messages).to eq([])
+ end
+ end
end
diff --git a/spec/system/authz_submitter_spec.rb b/spec/system/authz_submitter_spec.rb
index 37871418f..86f29f7e6 100644
--- a/spec/system/authz_submitter_spec.rb
+++ b/spec/system/authz_submitter_spec.rb
@@ -14,7 +14,8 @@
before do
Group.create_defaults
- stub_s3 data: [file1]
+
+ stub_s3 data: [FactoryBot.build(:s3_readme), file1]
stub_datacite(host: "api.datacite.org", body: datacite_register_body(prefix: "10.34770"))
end
diff --git a/spec/system/authz_super_admin_spec.rb b/spec/system/authz_super_admin_spec.rb
index 3d00a1b4a..86b3076d2 100644
--- a/spec/system/authz_super_admin_spec.rb
+++ b/spec/system/authz_super_admin_spec.rb
@@ -16,7 +16,7 @@
end
it "should be able to edit someone else's work" do
- stub_s3
+ stub_s3 data: [FactoryBot.build(:s3_readme)]
sign_in submitter2
visit user_path(submitter2)
expect(page).to have_content submitter2.given_name
@@ -76,7 +76,7 @@
it "should be able to approve a work" do
stub_datacite_doi
- stub_s3 data: [FactoryBot.build(:s3_file)]
+ stub_s3 data: [FactoryBot.build(:s3_readme), FactoryBot.build(:s3_file)]
work = FactoryBot.create :awaiting_approval_work
work.save!
diff --git a/spec/system/external_ids_spec.rb b/spec/system/external_ids_spec.rb
index 46af7effc..05e867dc4 100644
--- a/spec/system/external_ids_spec.rb
+++ b/spec/system/external_ids_spec.rb
@@ -7,7 +7,7 @@
before do
stub_datacite(host: "api.datacite.org", body: datacite_register_body(prefix: "10.34770"))
- stub_s3
+ stub_s3 data: [FactoryBot.build(:s3_readme)]
end
it "Mints a DOI, but does not mint an ark at any point in the wizard proccess" do
diff --git a/spec/system/migrate_submission_spec.rb b/spec/system/migrate_submission_spec.rb
index 41efda062..c24823ce3 100644
--- a/spec/system/migrate_submission_spec.rb
+++ b/spec/system/migrate_submission_spec.rb
@@ -49,7 +49,7 @@
context "happy path" do
before do
stub_request(:get, "https://handle.stage.datacite.org/10.34770/123-abc").to_return(status: 200, body: "", headers: {})
- stub_s3
+ stub_s3 data: [FactoryBot.build(:s3_readme)]
end
it "produces and saves a valid datacite record" do
@@ -106,11 +106,12 @@
context "validation errors" do
let(:work2) { FactoryBot.create :draft_work, ark: "ark:/99999/dsp01d791sj97j" }
+ let(:fake_s3_service) { stub_s3 }
before do
stub_request(:get, "https://handle.stage.datacite.org/10.34770/123-abc").to_return(status: 200, body: "", headers: {})
stub_request(:get, "https://handle.stage.datacite.org/10.34770/123-ab").to_return(status: 404, body: "", headers: {})
- stub_s3
+ fake_s3_service
work2
end
@@ -152,6 +153,12 @@
fill_in "title_main", with: title
click_on "Create"
click_on "Complete"
+ expect(page).to have_content "Must provide a README"
+
+ # fake that the user put a file up in globus
+ allow(fake_s3_service).to receive(:client_s3_files).and_return([FactoryBot.build(:s3_readme)])
+ click_on "Save Work"
+ click_on "Complete"
expect(page).to have_content "awaiting_approval"
end
end
@@ -166,6 +173,7 @@
let(:work) { Work.last }
before do
+ stub_s3 data: [FactoryBot.build(:s3_readme), FactoryBot.build(:s3_file)]
datacite_stub # make sure the stub is created before we start the test
allow(identifier).to receive(:save)
@@ -179,7 +187,6 @@
work.save!
work.reload
- stub_s3 data: [FactoryBot.build(:s3_file)]
allow(Work).to receive(:find).with(work.id).and_return(work)
allow(Work).to receive(:find).with(work.id.to_s).and_return(work)
allow(work).to receive(:publish_precurated_files).and_return(true)
@@ -187,6 +194,7 @@
visit work_path(work)
click_on "Approve"
page.driver.browser.switch_to.alert.accept
+ expect(page).to have_content "approved"
end
context "Approving a work with a DOI we own" do
diff --git a/spec/system/rss_spec.rb b/spec/system/rss_spec.rb
index 86192b79b..c23e84ef6 100644
--- a/spec/system/rss_spec.rb
+++ b/spec/system/rss_spec.rb
@@ -33,7 +33,7 @@
allow(work1).to receive(:publish).and_return(true)
allow(work2).to receive(:publish).and_return(true)
- stub_s3(data: [s3_file1])
+ stub_s3(data: [FactoryBot.build(:s3_readme), s3_file1])
# Works 1 & 2 are approved, so they should show up in the RSS feed
work1.complete_submission!(admin)
diff --git a/spec/system/work_wizard_spec.rb b/spec/system/work_wizard_spec.rb
index 76c6b33e6..0ed368a12 100644
--- a/spec/system/work_wizard_spec.rb
+++ b/spec/system/work_wizard_spec.rb
@@ -25,7 +25,7 @@
readme_form_css = "form[action='/works/#{work.id}/readme-uploaded']"
upload_form_css = "form[action='/works/#{work.id}/attachment-select']"
file_upload_form_css = "form[action='/works/#{work.id}/file-upload']"
- validate_form_css = "form[action='/works/#{work.id}/validate']"
+ validate_form_css = "form[action='/works/#{work.id}/validate-wizard']"
# edit form has no previous button so no need to test that it goes back
expect(page).not_to have_content("Previous")
@@ -105,7 +105,7 @@
visit work_attachment_select_path(work)
other_form_css = "form[action='/works/#{work.id}/review']"
upload_form_css = "form[action='/works/#{work.id}/attachment-select']"
- validate_form_css = "form[action='/works/#{work.id}/validate']"
+ validate_form_css = "form[action='/works/#{work.id}/validate-wizard']"
page.find(:xpath, "//input[@value='file_other']").choose
click_on "Save"