From 04e599ed26c1e180d1fc16414c584b25125ea3d4 Mon Sep 17 00:00:00 2001 From: Shana Moore Date: Tue, 16 Apr 2024 17:13:50 -0700 Subject: [PATCH 1/2] :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 --- .../bulkrax/object_factory_interface.rb | 6 ++ app/models/concerns/bulkrax/has_matchers.rb | 13 ++++- spec/fixtures/csv/embargo.csv | 2 + spec/fixtures/csv/lease.csv | 2 + spec/models/bulkrax/csv_entry_spec.rb | 56 +++++++++++++++++++ spec/rails_helper.rb | 1 + 6 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 spec/fixtures/csv/embargo.csv create mode 100644 spec/fixtures/csv/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..c6452f4cd 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.csv b/spec/fixtures/csv/embargo.csv new file mode 100644 index 000000000..fabda9fcc --- /dev/null +++ b/spec/fixtures/csv/embargo.csv @@ -0,0 +1,2 @@ +model,title,creator,source_identifier,visibility, visibility_during_embargo,embargo_release_date,visibility_after_embargo +Work,An Image,user,123456789,restricted,embargo,2024-04-19,open \ No newline at end of file diff --git a/spec/fixtures/csv/lease.csv b/spec/fixtures/csv/lease.csv new file mode 100644 index 000000000..2e727d9e0 --- /dev/null +++ b/spec/fixtures/csv/lease.csv @@ -0,0 +1,2 @@ +model,title,creator,rights_statement,source_identifier,visibility,visibility_during_lease,lease_expiration_date,visibility_after_lease +Image,An Image,user,http://rightsstatements.org/vocab/InC/1.0,987654321,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..571b3b153 100644 --- a/spec/models/bulkrax/csv_entry_spec.rb +++ b/spec/models/bulkrax/csv_entry_spec.rb @@ -1256,6 +1256,62 @@ class ::Avacado < Work end end end + + describe 'exposing lease attributes for parser' do + let(:data) { + { + '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' + } + } + let(:entry) { Bulkrax::EntrySpecHelper.entry_for(identifier: '123456789', + data: data, + parser_class_name: 'Bulkrax::CsvParser', + parser_fields: { 'import_file_path': 'spec/fixtures/csv/embargo.csv'} ) } + + 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) { + { + 'model': 'Work', + 'title': 'Image', + 'creator': 'user A', + 'source_identifier': '123456789', + 'visibility': 'lease', + 'visibility_during_lease': 'restricted', + 'lease_expiration_date': '2054-04-19', + 'visibility_after_lease': 'open' + } + } + let(:entry) { Bulkrax::EntrySpecHelper.entry_for(identifier: '123456789', + data: data, + parser_class_name: 'Bulkrax::CsvParser', + parser_fields: { 'import_file_path': 'spec/fixtures/csv/lease.csv'} ) } + + it 'embargo 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 From 5148436e76e42ca99113884394cfd314a5d763cd Mon Sep 17 00:00:00 2001 From: Shana Moore Date: Tue, 16 Apr 2024 17:18:23 -0700 Subject: [PATCH 2/2] :broom: [i1010] combine embargo and lease test fixtures Issue: - https://github.com/scientist-softserv/palni-palci/issues/1010 --- app/models/concerns/bulkrax/has_matchers.rb | 4 +- spec/fixtures/csv/embargo-lease.csv | 3 + spec/fixtures/csv/embargo.csv | 2 - spec/fixtures/csv/lease.csv | 2 - spec/models/bulkrax/csv_entry_spec.rb | 66 +++++++++++---------- 5 files changed, 40 insertions(+), 37 deletions(-) create mode 100644 spec/fixtures/csv/embargo-lease.csv delete mode 100644 spec/fixtures/csv/embargo.csv delete mode 100644 spec/fixtures/csv/lease.csv diff --git a/app/models/concerns/bulkrax/has_matchers.rb b/app/models/concerns/bulkrax/has_matchers.rb index c6452f4cd..173f02195 100644 --- a/app/models/concerns/bulkrax/has_matchers.rb +++ b/app/models/concerns/bulkrax/has_matchers.rb @@ -148,11 +148,11 @@ def multiple?(field) end def fields_that_are_always_multiple - @fields_that_are_always_multiple = %W[ + @fields_that_are_always_multiple = %w[ id delete model - visibility + visibility visibility_during_embargo embargo_release_date visibility_after_embargo 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/fixtures/csv/embargo.csv b/spec/fixtures/csv/embargo.csv deleted file mode 100644 index fabda9fcc..000000000 --- a/spec/fixtures/csv/embargo.csv +++ /dev/null @@ -1,2 +0,0 @@ -model,title,creator,source_identifier,visibility, visibility_during_embargo,embargo_release_date,visibility_after_embargo -Work,An Image,user,123456789,restricted,embargo,2024-04-19,open \ No newline at end of file diff --git a/spec/fixtures/csv/lease.csv b/spec/fixtures/csv/lease.csv deleted file mode 100644 index 2e727d9e0..000000000 --- a/spec/fixtures/csv/lease.csv +++ /dev/null @@ -1,2 +0,0 @@ -model,title,creator,rights_statement,source_identifier,visibility,visibility_during_lease,lease_expiration_date,visibility_after_lease -Image,An Image,user,http://rightsstatements.org/vocab/InC/1.0,987654321,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 571b3b153..eb212e257 100644 --- a/spec/models/bulkrax/csv_entry_spec.rb +++ b/spec/models/bulkrax/csv_entry_spec.rb @@ -1257,23 +1257,25 @@ class ::Avacado < Work end end - describe 'exposing lease attributes for parser' do - let(:data) { + 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' + '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' } - } - let(:entry) { Bulkrax::EntrySpecHelper.entry_for(identifier: '123456789', - data: data, - parser_class_name: 'Bulkrax::CsvParser', - parser_fields: { 'import_file_path': 'spec/fixtures/csv/embargo.csv'} ) } + 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 @@ -1285,25 +1287,27 @@ class ::Avacado < Work end end - describe 'exposing lease attributes for parser' do - let(:data) { + describe 'exposing lease attributes for parser' do + let(:data) do { - 'model': 'Work', - 'title': 'Image', - 'creator': 'user A', - 'source_identifier': '123456789', - 'visibility': 'lease', - 'visibility_during_lease': 'restricted', - 'lease_expiration_date': '2054-04-19', - 'visibility_after_lease': 'open' + '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' } - } - let(:entry) { Bulkrax::EntrySpecHelper.entry_for(identifier: '123456789', - data: data, - parser_class_name: 'Bulkrax::CsvParser', - parser_fields: { 'import_file_path': 'spec/fixtures/csv/lease.csv'} ) } + 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 + it 'lease attributes are included in the parsed metadata' do entry.build_metadata expect(entry.parsed_metadata['visibility']).to eq('lease')