Skip to content

Commit

Permalink
Picks up files uploaded during the initial run in the wizard
Browse files Browse the repository at this point in the history
  • Loading branch information
hectorcorrea committed Apr 21, 2023
1 parent 9508810 commit 8a48645
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
7 changes: 4 additions & 3 deletions app/controllers/works_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,12 @@ def file_upload

def file_uploaded
@work = Work.find(params[:id])
if pre_curation_uploads_param
@work.pre_curation_uploads.attach(pre_curation_uploads_param)
files = work_params.dig("patch", "pre_curation_uploads") || []
if files.count > 0
upload_service = WorkUploadsEditService.new(@work, current_user)
@work = upload_service.update_precurated_file_list(files, [])
@work.save!
end

redirect_to(work_review_path)
rescue StandardError => active_storage_error
Rails.logger.error("Failed to attach the file uploads for the work #{@work.doi}: #{active_storage_error}")
Expand Down
20 changes: 13 additions & 7 deletions spec/controllers/works_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -760,8 +760,10 @@
{
"_method" => "patch",
"authenticity_token" => "MbUfIQVvYoCefkOfSpzyS0EOuSuOYQG21nw8zgg2GVrvcebBYI6jy1-_3LSzbTg9uKgehxWauYS8r1yxcN1Lwg",
"patch" => {
"pre_curation_uploads_added" => [uploaded_file]
"work" => {
"patch" => {
"pre_curation_uploads" => [uploaded_file]
}
},
"commit" => "Continue",
"controller" => "works",
Expand All @@ -775,6 +777,7 @@
end

before do
stub_request(:get, /#{bucket_url}/).to_return(status: 200)
stub_request(:put, /#{bucket_url}/).to_return(status: 200)
sign_in user
post :file_uploaded, params: params
Expand Down Expand Up @@ -813,8 +816,10 @@
{
"_method" => "patch",
"authenticity_token" => "MbUfIQVvYoCefkOfSpzyS0EOuSuOYQG21nw8zgg2GVrvcebBYI6jy1-_3LSzbTg9uKgehxWauYS8r1yxcN1Lwg",
"patch" => {
"pre_curation_uploads_added" => [uploaded_file]
"work" => {
"patch" => {
"pre_curation_uploads" => [uploaded_file]
}
},
"commit" => "Continue",
"controller" => "works",
Expand All @@ -839,15 +844,16 @@
allow(Work).to receive(:find).and_return(persisted)
allow(persisted).to receive(:to_s).and_return(work.id)
allow(persisted).to receive(:doi).and_return(work.doi)
allow(persisted).to receive(:pre_curation_uploads).and_raise(StandardError, "test error")
allow(persisted).to receive(:s3_query_service).and_return(nil)
allow(persisted).to receive(:pre_curation_uploads).and_return([])

post :file_uploaded, params: params
end

it "does not update the work and renders an error messages" do
expect(response).to redirect_to(work_file_upload_path(work))
expect(controller.flash[:notice]).to eq("Failed to attach the file uploads for the work #{work.doi}: test error. Please contact rdss@princeton.edu for assistance.")
expect(Rails.logger).to have_received(:error).with("Failed to attach the file uploads for the work #{work.doi}: test error")
expect(controller.flash[:notice].start_with?("Failed to attach the file uploads for the work #{work.doi}")).to be true
expect(Rails.logger).to have_received(:error).with(/Failed to attach the file uploads for the work #{work.doi}/)
end
end

Expand Down

0 comments on commit 8a48645

Please sign in to comment.