Skip to content

Commit

Permalink
Merge pull request #6553 from samvera/valkyrizes_file_set_csv_service…
Browse files Browse the repository at this point in the history
…_spec

Valkyrizes `spec/services/hyrax/file_set_csv_service_spec.rb`.
  • Loading branch information
dlpierce authored Jan 3, 2024
2 parents 48d62fd + c0aaf49 commit 6be7b64
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 42 deletions.
2 changes: 2 additions & 0 deletions config/metadata/core_metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ attributes:
depositor:
type: string
predicate: http://id.loc.gov/vocabulary/relators/dpt
index_keys:
- "depositor_tesim"
2 changes: 2 additions & 0 deletions config/metadata/file_set_metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ attributes:
required: false
primary: true
predicate: http://purl.org/dc/terms/license
index_keys:
- "license_tesim"

# Other attributes:
abstract:
Expand Down
79 changes: 37 additions & 42 deletions spec/services/hyrax/file_set_csv_service_spec.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
# frozen_string_literal: true
RSpec.describe Hyrax::FileSetCsvService do
let(:mock_file) do
Hydra::PCDM::File.new
RSpec.describe Hyrax::FileSetCsvService, :clean_repo do
let(:file) { create(:uploaded_file, file: File.open('spec/fixtures/sample-file.pdf')) }
let(:file_metadata) { valkyrie_create(:file_metadata, :original_file, :with_file, file: file, mime_type: 'application/pdf') }
let(:file_set) do
valkyrie_create(:hyrax_file_set,
depositor: 'jilluser@example.com',
title: ['My Title'],
creator: ['Von, Creator'],
resource_type: ['Book', 'Other'],
license: ['Mine'],
files: [file_metadata],
original_file: file_metadata)
end
let(:work) { create(:work, title: ['test title'], creator: ['Von, Creator']) }
let(:file_set_id) { '123abc456' }
let(:file) do
f = create(:file_set, id: file_set_id, title: ['My Title'], creator: ['Von, Creator'],
resource_type: ['Book', 'Other'], license: ['Mine'])
f.apply_depositor_metadata('jilluser@example.com')
work.ordered_members << f
work.save!
f
let(:solr_document) { SolrDocument.new(Hyrax::ValkyrieIndexer.for(resource: file_set).to_solr) }

shared_examples('with expected header text') do
describe "csv_header" do
subject { csv_service.csv_header }

it { is_expected.to eq "id,title,depositor,creator,visibility,resource_type,license,file_format\n" }
end
end
let(:solr_document) { SolrDocument.new(file.to_solr) }

before do
allow(mock_file).to receive(:mime_type).and_return('application/pdf')
allow(file).to receive(:resource_type).and_return(['Book', 'Other'])
allow(file).to receive(:original_file).and_return(mock_file)
shared_examples('with expected header text (specifying terms)') do
describe "csv_header" do
subject { csv_service.csv_header }

it { is_expected.to eq "id,title,resource_type\n" }
end
end

context "when using the defaults" do
Expand All @@ -27,32 +36,25 @@
describe "csv" do
subject { csv_service.csv }

it { is_expected.to eq "#{file_set_id},My Title,jilluser@example.com,\"Von, Creator\",restricted,Book|Other,Mine,pdf\n" }
it { is_expected.to include "#{file_set.id},My Title,jilluser@example.com,\"Von, Creator\",restricted,", "Book", "|", "Other", ",Mine,pdf\n" }
it "parses as valid csv" do
expect(::CSV.parse(subject)).to eq([[file_set_id, "My Title", "jilluser@example.com", "Von, Creator", "restricted", "Book|Other", "Mine", "pdf"]])
expect(::CSV.parse(subject).flatten).to include(file_set.id.to_s, "My Title", "jilluser@example.com", "Von, Creator", "restricted", "Mine", "pdf")
end
end

describe "csv_header" do
subject { csv_service.csv_header }

it { is_expected.to eq "id,title,depositor,creator,visibility,resource_type,license,file_format\n" }
end
include_examples 'with expected header text'
end

context "when specifying terms" do
let(:csv_service) { described_class.new(file, [:id, :title, :resource_type]) }
let(:csv_service) { described_class.new(file_set, [:id, :title, :resource_type]) }

describe "csv" do
subject { csv_service.csv }

it { is_expected.to eq "#{file_set_id},My Title,Book|Other\n" }
it { is_expected.to include "#{file_set.id},My Title,", "Book", "|", "Other", "\n" }
end
describe "csv_header" do
subject { csv_service.csv_header }

it { is_expected.to eq "id,title,resource_type\n" }
end
include_examples 'with expected header text (specifying terms)'
end

context "when specifying separator" do
Expand All @@ -61,28 +63,21 @@
describe "csv" do
subject { csv_service.csv }

it { is_expected.to eq "#{file_set_id},My Title,jilluser@example.com,\"Von, Creator\",restricted,Book&&Other,Mine,pdf\n" }
it { is_expected.to include "#{file_set.id},My Title,jilluser@example.com,\"Von, Creator\",restricted,", "Book", "&&", "Other", ",Mine,pdf\n" }
end

describe "csv_header" do
subject { csv_service.csv_header }

it { is_expected.to eq "id,title,depositor,creator,visibility,resource_type,license,file_format\n" }
end
include_examples 'with expected header text'
end

context "when specifying terms and separator" do
let(:csv_service) { described_class.new(file, [:id, :title, :resource_type], '*$*') }
let(:csv_service) { described_class.new(file_set, [:id, :title, :resource_type], '*$*') }

describe "csv" do
subject { csv_service.csv }

it { is_expected.to eq "#{file_set_id},My Title,Book*$*Other\n" }
it { is_expected.to include "#{file_set.id},My Title,", "Book", "*$*", "Other", "\n" }
end
describe "csv_header" do
subject { csv_service.csv_header }

it { is_expected.to eq "id,title,resource_type\n" }
end
include_examples 'with expected header text (specifying terms)'
end
end

0 comments on commit 6be7b64

Please sign in to comment.