-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1541 from ubiquitypress/hyku-csv-importer
CSVImporter file upload bug fix
Showing
11 changed files
with
173 additions
and
89 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
Binary file not shown.
Binary file not shown.
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,3 @@ | ||
id,type,title,description,resource_type,contributor,contributor,date_created,file | ||
11111111-2465-1111-5468-000123456789,ETD,Hammock Tacos,,image,Tracy S Gertler,Cynthia V Stack,2015-03-29T22:12:12.100363+00:00,example3.tiff | ||
22222222-0971-2222-1353-000123456789,ETD,Freegan Intelligentsia,,text,Tracy S Gertler,Cynthia V Stack,2015-03-29T22:12:12.100363+00:00,sample.docx |
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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
module Importer | ||
# rubocop:disable Metrics/ClassLength | ||
class CSVParser | ||
include Enumerable | ||
|
||
|
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
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,57 @@ | ||
RSpec.shared_examples "csv_importer" do | ||
context "with a file" do | ||
let(:attributes) do | ||
{ | ||
id: "123", | ||
title: ["Gluten-free umami"], | ||
file: ["world.png"] | ||
} | ||
end | ||
let(:factory) { described_class.new(attributes, 'spec/fixtures/images') } | ||
|
||
before { factory.run } | ||
|
||
describe "#run" do | ||
it "uploads the content of the file" do | ||
expect(Hyrax::UploadedFile.last[:file]).to eq("world.png") | ||
end | ||
end | ||
|
||
describe "when a work with the same id already exists" do | ||
let(:new_attr) do | ||
{ | ||
id: "123", | ||
title: ["Squid tofu banjo"], | ||
file: ["nypl-hydra-of-lerna.jpg"] | ||
} | ||
end | ||
|
||
it "updates metadata" do | ||
new_factory = described_class.new(new_attr, 'spec/fixtures/images') | ||
new_factory.run | ||
expect(work.last.title).to eq(["Squid tofu banjo"]) | ||
end | ||
end | ||
end | ||
|
||
context "without a file" do | ||
## the csv_importer still creates a Work when no file is provided. | ||
## TO DO: handle invalid file in CSV; current behavior: | ||
## the importer stops if no file corresponding to a given file_name is found | ||
let(:attributes) { { id: "345", title: ["Artisan succulents"] } } | ||
let(:factory) { described_class.new(attributes) } | ||
|
||
before { factory.run } | ||
|
||
it "creates a Work with supplied metadata" do | ||
expect(work.find("345").title).to eq(["Artisan succulents"]) | ||
end | ||
|
||
it "updates a Work with supplied metadata" do | ||
new_attr = { id: "345", title: ["Retro humblebrag"] } | ||
new_factory = described_class.new(new_attr) | ||
new_factory.run | ||
expect(work.find("345").title).to eq(["Retro humblebrag"]) | ||
end | ||
end | ||
end |