From 855ce39e805295377eda9a7c24645fbb0ee5617c Mon Sep 17 00:00:00 2001 From: Shana Moore Date: Wed, 17 Apr 2024 09:49:04 -0700 Subject: [PATCH] I1010 embargo lease support (#950) * :gift: [i1010] - Add bulkrax support for Embargo and Lease Rules In this commit, user are able to import embargo and lease rules via CSV headers. Issue: - https://github.com/scientist-softserv/palni-palci/issues/1010 * :broom: [i1010] combine embargo and lease test fixtures Issue: - https://github.com/scientist-softserv/palni-palci/issues/1010 --- .../bulkrax/object_factory_interface.rb | 6 ++ app/models/concerns/bulkrax/has_matchers.rb | 13 +++- spec/fixtures/csv/embargo-lease.csv | 3 + spec/models/bulkrax/csv_entry_spec.rb | 60 +++++++++++++++++++ spec/rails_helper.rb | 1 + 5 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 spec/fixtures/csv/embargo-lease.csv diff --git a/app/factories/bulkrax/object_factory_interface.rb b/app/factories/bulkrax/object_factory_interface.rb index fae7a8f21..bc97acad1 100644 --- a/app/factories/bulkrax/object_factory_interface.rb +++ b/app/factories/bulkrax/object_factory_interface.rb @@ -224,6 +224,12 @@ def self.update_index_for_file_sets_of(resource:) id read_groups visibility + visibility_during_embargo + embargo_release_date + visibility_after_embargo + visibility_during_lease + lease_expiration_date + visibility_after_lease work_members_attributes ] diff --git a/app/models/concerns/bulkrax/has_matchers.rb b/app/models/concerns/bulkrax/has_matchers.rb index d00d36815..173f02195 100644 --- a/app/models/concerns/bulkrax/has_matchers.rb +++ b/app/models/concerns/bulkrax/has_matchers.rb @@ -148,7 +148,18 @@ def multiple?(field) end def fields_that_are_always_multiple - %w[id delete model visibility] + @fields_that_are_always_multiple = %w[ + id + delete + model + visibility + visibility_during_embargo + embargo_release_date + visibility_after_embargo + visibility_during_lease + lease_expiration_date + visibility_after_lease + ] end def fields_that_are_always_singular diff --git a/spec/fixtures/csv/embargo-lease.csv b/spec/fixtures/csv/embargo-lease.csv new file mode 100644 index 000000000..93acff0b5 --- /dev/null +++ b/spec/fixtures/csv/embargo-lease.csv @@ -0,0 +1,3 @@ +model,title,creator,source_identifier,visibility,visibility_during_embargo,embargo_release_date,visibility_after_embargo,visibility_during_lease,lease_expiration_date,visibility_after_lease +Work,An Image,user,123456789,embargo,restricted,2024-04-19,open,,,, +Work,An Image,user,1987654321,lease,,,,restricted,2024-04-19,open \ No newline at end of file diff --git a/spec/models/bulkrax/csv_entry_spec.rb b/spec/models/bulkrax/csv_entry_spec.rb index b72b24765..eb212e257 100644 --- a/spec/models/bulkrax/csv_entry_spec.rb +++ b/spec/models/bulkrax/csv_entry_spec.rb @@ -1256,6 +1256,66 @@ class ::Avacado < Work end end end + + describe 'exposing embargo attributes for parser' do + let(:data) do + { + 'model': 'Work', + 'title': 'Image', + 'creator': 'user A', + 'source_identifier': '123456789', + 'visibility': 'embargo', + 'visibility_during_embargo': 'restricted', + 'embargo_release_date': '2054-04-19', + 'visibility_after_embargo': 'open' + } + end + let(:entry) do + Bulkrax::EntrySpecHelper.entry_for(identifier: '123456789', + data: data, + parser_class_name: 'Bulkrax::CsvParser', + parser_fields: { 'import_file_path': 'spec/fixtures/csv/embargo-lease.csv' }) + end + + it 'embargo attributes are included in the parsed metadata' do + entry.build_metadata + + expect(entry.parsed_metadata['visibility']).to eq('embargo') + expect(entry.parsed_metadata['visibility_during_embargo']).to eq('restricted') + expect(entry.parsed_metadata['embargo_release_date']).to eq('2054-04-19') + expect(entry.parsed_metadata['visibility_after_embargo']).to eq('open') + end + end + + describe 'exposing lease attributes for parser' do + let(:data) do + { + 'model': 'Work', + 'title': 'Image', + 'creator': 'user A', + 'source_identifier': '987654321', + 'visibility': 'lease', + 'visibility_during_lease': 'restricted', + 'lease_expiration_date': '2054-04-19', + 'visibility_after_lease': 'open' + } + end + let(:entry) do + Bulkrax::EntrySpecHelper.entry_for(identifier: '123456789', + data: data, + parser_class_name: 'Bulkrax::CsvParser', + parser_fields: { 'import_file_path': 'spec/fixtures/csv/embargo-lease.csv' }) + end + + it 'lease attributes are included in the parsed metadata' do + entry.build_metadata + + expect(entry.parsed_metadata['visibility']).to eq('lease') + expect(entry.parsed_metadata['visibility_during_lease']).to eq('restricted') + expect(entry.parsed_metadata['lease_expiration_date']).to eq('2054-04-19') + expect(entry.parsed_metadata['visibility_after_lease']).to eq('open') + end + end end end # rubocop: enable Metrics/BlockLength diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index f69ed5d7f..7227d4b57 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -2,6 +2,7 @@ # This file is copied to spec/ when you run 'rails generate rspec:install' require 'spec_helper' +require 'bulkrax/entry_spec_helper' ENV['RAILS_ENV'] ||= 'test' require 'simplecov' SimpleCov.start