Skip to content

Commit

Permalink
I1010 embargo lease support (#950)
Browse files Browse the repository at this point in the history
* 🎁 [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:
- scientist-softserv/palni-palci#1010

* 🧹 [i1010] combine embargo and lease test fixtures

Issue:
- scientist-softserv/palni-palci#1010
  • Loading branch information
ShanaLMoore authored Apr 17, 2024
1 parent 1048453 commit 855ce39
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 1 deletion.
6 changes: 6 additions & 0 deletions app/factories/bulkrax/object_factory_interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
]

Expand Down
13 changes: 12 additions & 1 deletion app/models/concerns/bulkrax/has_matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions spec/fixtures/csv/embargo-lease.csv
Original file line number Diff line number Diff line change
@@ -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
60 changes: 60 additions & 0 deletions spec/models/bulkrax/csv_entry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 855ce39

Please sign in to comment.