Skip to content

Commit

Permalink
use id instead of call_number in seed data
Browse files Browse the repository at this point in the history
  • Loading branch information
rawOrlando committed Jul 29, 2024
1 parent 81f0a5e commit e3d3c80
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 26 deletions.
44 changes: 28 additions & 16 deletions app/lib/tufts/contribute_collections.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ def initialize
def make_seed_data_hash
seed_hash = {}
SEED_DATA.each do |c|
call_number = c[:call_number]
seed_hash[call_number] = c
data_id = c[:id]
seed_hash[data_id] = c
end
seed_hash
end
Expand All @@ -28,8 +28,8 @@ def self.create
def create
default = Hyrax::CollectionType.find_or_create_default_collection_type
# admin_set = Hyrax::CollectionType.find_or_create_admin_set_type
@seed_data.each_key do |call_number|
find_or_create_collection(call_number, default)
@seed_data.each_key do |data_id|
find_or_create_collection(data_id, default)
end
end

Expand All @@ -38,19 +38,20 @@ def create
# re-used, and re-create the collection object.
# @param [String] call_number
# @return [Collection]
def find_or_create_collection(call_number, default)
col = Collection.where(call_number: call_number)
create_collection(call_number, default) if col.empty?
def find_or_create_collection(data_id, default)
col = Collection.where(id: data_id)
create_collection(data_id, default) if col.empty?
end

# @param [String] call_number
# @param [String] data_id
# @return [Collection]
def create_collection(call_number, default = Hyrax::CollectionType.find_or_create_default_collection_type)
def create_collection(data_id, default = Hyrax::CollectionType.find_or_create_default_collection_type)
collection = Collection.new
collection_hash = @seed_data[call_number]
collection_hash = @seed_data[data_id]
collection.title = Array(collection_hash[:title])
collection.call_number = Array(collection_hash[:call_number])
collection.finding_aid = Array(collection_hash[:finding_aid])
collection.id = collection_hash[:id]
collection.call_number = Array(collection_hash[:call_number]) if collection_hash.key?(:call_number)
collection.finding_aid = Array(collection_hash[:finding_aid]) if collection_hash.key?(:finding_aid)
collection.visibility = Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC
collection.collection_type = default
collection.save
Expand All @@ -71,11 +72,11 @@ def self.collection_for_work_type(work_type)
# @param [Class] work_type
# @return [Collection]
def collection_for_work_type(work_type)
call_number = @seed_data.select { |_key, hash| hash[:work_types].include? work_type }.keys.first
data_id = @seed_data.select { |_key, hash| hash[:work_types].include? work_type }.keys.first

cols = Collection.where(call_number: call_number)
cols = Collection.where(id: data_id)
if cols.empty?
create_collection(call_number)
create_collection(data_id)
else
cols.first
end
Expand All @@ -84,39 +85,50 @@ def collection_for_work_type(work_type)
SEED_DATA = [
{
title: "Tufts Published Scholarship",
id: "2j62s484w",
call_number: "PB",
finding_aid: "https://archives.tufts.edu/repositories/2/resources/100",
work_types: [GenericDeposit, GenericTischDeposit, GisPoster, UndergradSummerScholar, FacultyScholarship, GradScholarship]
work_types: [GenericDeposit, GenericTischDeposit, GisPoster, UndergradSummerScholar, FacultyScholarship]
},
{
title: "Fletcher School Records",
id: "0g354f20t",
call_number: "UA015",
finding_aid: "https://archives.tufts.edu/repositories/2/resources/120",
work_types: [CapstoneProject]
},
{
title: "Cummings School of Veterinary Medicine Records",
id: "xd07gs68j",
call_number: "UA041",
finding_aid: "https://archives.tufts.edu/repositories/2/resources/4",
work_types: [CummingsThesis]
},
{
title: "Senior Honors Theses",
id: "8910jt56k",
call_number: "UA005",
finding_aid: "https://archives.tufts.edu/repositories/2/resources/123",
work_types: [HonorsThesis]
},
{
title: "Public Health and Professional Degree Programs Records",
id: "cz30q546w",
call_number: "UA187",
finding_aid: "https://archives.tufts.edu/repositories/2/resources/253",
work_types: [PublicHealth]
},
{
title: "Department of Education Records",
id: "sq87bt605",
call_number: "UA071",
finding_aid: "https://archives.tufts.edu/repositories/2/resources/9",
work_types: [QualifyingPaper]
},
{
title: "Student Scholarship",
id: "nk322d32h",
work_types: [GradScholarship]
}
].freeze
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

# NOTE: If you generated more than one work, you have to set "js: true"
RSpec.feature 'General Graduate Scholarship', :clean, js: true do
# TODO: make a csv file
let(:csv_path) { Rails.root.join('config', 'deposit_type_seed.csv').to_s }
let(:importer) { DepositTypeImporter.new(csv_path) }
let(:pdf_path) { Rails.root.join('spec', 'fixtures', 'hello.pdf') }
Expand Down
13 changes: 4 additions & 9 deletions spec/lib/tufts/contribute_collections_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
described_class.create
end
it "creates a collection object for each item in the seed array" do
expect(Collection.count).to eq(6)
expect(Collection.count).to eq(7)
end
it "populates title, call number and finding aid" do
c = Collection.where(call_number: "PB")
c = Collection.where(id: "2j62s484w")
expect(c.first.title.first).to eq("Tufts Published Scholarship")
expect(c.first.id).to eq("2j62s484w")
expect(c.first.call_number.first).to eq("PB")
expect(c.first.finding_aid.first).to eq("https://archives.tufts.edu/repositories/2/resources/100")
end
Expand All @@ -30,13 +31,7 @@
it "finds the right collection for a given work type" do
faculty_scholarship_collection = cc.collection_for_work_type(FacultyScholarship)
expect(faculty_scholarship_collection).to be_instance_of(Collection)
expect(faculty_scholarship_collection.call_number).to eq(['PB'])
expect(faculty_scholarship_collection.finding_aid).to eq(['https://archives.tufts.edu/repositories/2/resources/100'])
end
it "recovers if one of the expected collections has been deleted" do
Collection.where(call_number: 'PB').first.delete
faculty_scholarship_collection = cc.collection_for_work_type(FacultyScholarship)
expect(faculty_scholarship_collection).to be_instance_of(Collection)
expect(faculty_scholarship_collection.id).to eq("2j62s484w")
expect(faculty_scholarship_collection.call_number).to eq(['PB'])
expect(faculty_scholarship_collection.finding_aid).to eq(['https://archives.tufts.edu/repositories/2/resources/100'])
end
Expand Down

0 comments on commit e3d3c80

Please sign in to comment.