-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into issue-1021-edit-two
- Loading branch information
Showing
13 changed files
with
284 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# frozen_string_literal: true | ||
class Readme | ||
attr_reader :work | ||
|
||
def initialize(work) | ||
@work = work | ||
end | ||
|
||
def attach(readme_file_param) | ||
return "A README file is required!" if readme_file_param.blank? && blank? | ||
return nil if readme_file_param.blank? | ||
|
||
extension = File.extname(readme_file_param.original_filename) | ||
if work.s3_query_service.upload_file(io: readme_file_param.to_io, filename: "README#{extension}") | ||
nil | ||
else | ||
"An error uploading your README was encountered. Please try again." | ||
end | ||
end | ||
|
||
def blank? | ||
s3_readme_idx.nil? | ||
end | ||
|
||
private | ||
|
||
def s3_readme_idx | ||
file_names = work.pre_curation_uploads_fast.map(&:filename_display) | ||
file_names.find_index { |file_name| file_name.start_with?("README") } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
This readme file was generated on [YYYY-MM-DD] by [NAME] | ||
<help text in angle brackets should be deleted before finalizing your document> | ||
<[text in square brackets should be changed for your specific dataset]> | ||
|
||
|
||
GENERAL INFORMATION | ||
|
||
Title of Dataset: | ||
|
||
<provide at least two contacts> | ||
Author/Principal Investigator Information | ||
Name: | ||
ORCID: | ||
Institution: | ||
Address: | ||
Email: | ||
|
||
Author/Associate or Co-investigator Information | ||
Name: | ||
ORCID: | ||
Institution: | ||
Address: | ||
Email: | ||
|
||
Author/Alternate Contact Information | ||
Name: | ||
ORCID: | ||
Institution: | ||
Address: | ||
Email: | ||
|
||
Date of data collection: <provide single date, range, or approximate date; suggested format YYYY-MM-DD> | ||
|
||
Geographic location of data collection: <provide latitude, longiute, or city/region, State, Country> | ||
|
||
Information about funding sources that supported the collection of the data: | ||
|
||
|
||
SHARING/ACCESS INFORMATION | ||
|
||
Licenses/restrictions placed on the data: | ||
|
||
Links to publications that cite or use the data: | ||
|
||
Links to other publicly accessible locations of the data: | ||
|
||
Links/relationships to ancillary data sets: | ||
|
||
Was data derived from another source? | ||
If yes, list source(s): | ||
|
||
Recommended citation for this dataset: | ||
|
||
|
||
DATA & FILE OVERVIEW | ||
|
||
File List: <list all files (or folders, as appropriate for dataset organization) contained in the dataset, with a brief description> | ||
|
||
Relationship between files, if important: | ||
|
||
Additional related data collected that was not included in the current data package: | ||
|
||
Are there multiple versions of the dataset? | ||
If yes, name of file(s) that was updated: | ||
Why was the file updated? | ||
When was the file updated? | ||
|
||
|
||
METHODOLOGICAL INFORMATION | ||
|
||
Description of methods used for collection/generation of data: <include links or references to publications or other documentation containing experimental design or protocols used in data collection> | ||
|
||
Methods for processing the data: <describe how the submitted data were generated from the raw or collected data> | ||
|
||
Instrument- or software-specific information needed to interpret the data: <include full name and version of software, and any necessary packages or libraries needed to run scripts> | ||
|
||
Standards and calibration information, if appropriate: | ||
|
||
Environmental/experimental conditions: | ||
|
||
Describe any quality-assurance procedures performed on the data: | ||
|
||
People involved with sample collection, processing, analysis and/or submission: | ||
|
||
|
||
DATA-SPECIFIC INFORMATION FOR: [FILENAME] | ||
<repeat this section for each dataset, folder or file, as appropriate> | ||
|
||
Number of variables: | ||
|
||
Number of cases/rows: | ||
|
||
Variable List: <list variable name(s), description(s), unit(s) and value labels as appropriate for each> | ||
|
||
Missing data codes: <list code/symbol and definition> | ||
|
||
Specialized formats or other abbreviations used: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# frozen_string_literal: true | ||
require "rails_helper" | ||
|
||
RSpec.describe Readme, type: :model do | ||
let(:work) { FactoryBot.create :draft_work } | ||
let(:s3_files) { [FactoryBot.build(:s3_file, work: work), FactoryBot.build(:s3_file, filename: "filename-2.txt", work: work)] } | ||
let(:readme) { described_class.new(work) } | ||
let(:fake_s3_service) { stub_s3 data: s3_files } | ||
|
||
before do | ||
fake_s3_service | ||
end | ||
|
||
describe "#blank?" do | ||
it "Does not find a readme" do | ||
expect(readme.blank?).to be_truthy | ||
end | ||
|
||
context "with a readme present" do | ||
let(:s3_files) { [FactoryBot.build(:s3_file, work: work), FactoryBot.build(:s3_readme, work: work)] } | ||
it "Does not find a readme" do | ||
expect(readme.blank?).to be_falsey | ||
end | ||
end | ||
end | ||
|
||
describe "#attach" do | ||
let(:uploaded_file) do | ||
ActionDispatch::Http::UploadedFile.new({ | ||
filename: "orcid.csv", | ||
type: "text/csv", | ||
tempfile: File.new(Rails.root.join("spec", "fixtures", "files", "orcid.csv")) | ||
}) | ||
end | ||
|
||
it "attaches the file and renames to to README" do | ||
expect(readme.attach(uploaded_file)).to be_nil | ||
expect(fake_s3_service).to have_received(:upload_file).with(io: uploaded_file.to_io, filename: "README.csv") | ||
end | ||
|
||
context "when no uploaded file is sent" do | ||
let(:uploaded_file) { nil } | ||
|
||
it "returns an error message" do | ||
expect(readme.attach(uploaded_file)).to eq("A README file is required!") | ||
expect(fake_s3_service).not_to have_received(:upload_file) | ||
end | ||
|
||
context "when a readme is already present" do | ||
let(:s3_files) { [FactoryBot.build(:s3_file, work: work), FactoryBot.build(:s3_readme, work: work)] } | ||
|
||
it "returns no error message" do | ||
expect(readme.attach(uploaded_file)).to be_nil | ||
expect(fake_s3_service).not_to have_received(:upload_file) | ||
end | ||
end | ||
end | ||
|
||
context "there is an error with the upload" do | ||
before do | ||
allow(fake_s3_service).to receive(:upload_file).and_return(false) | ||
end | ||
|
||
it "returns an error message" do | ||
expect(readme.attach(uploaded_file)).to eq("An error uploading your README was encountered. Please try again.") | ||
expect(fake_s3_service).to have_received(:upload_file).with(io: uploaded_file.to_io, filename: "README.csv") | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.