Skip to content

Commit

Permalink
Add journal issue and etds factories
Browse files Browse the repository at this point in the history
  • Loading branch information
alepbloyd committed Aug 16, 2024
1 parent dcecd47 commit 91586af
Show file tree
Hide file tree
Showing 4 changed files with 163 additions and 13 deletions.
82 changes: 69 additions & 13 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,27 @@
non_admin_user = FactoryBot.create(:user, email: "nonadminuser@example.com")

# admin sets and collection types
default_admin_set_id = AdminSet.find_or_create_default_admin_set_id
default_admin_set_id = FactoryBot.create(:stored_default_admin_set_id)
admin_set_collection_type = FactoryBot.create(:admin_set_collection_type)
gw_etds_admin_set = FactoryBot.create(:admin_set, title: ["ETDs"],edit_users: [admin_user.user_key, content_admin_user.user_key])

permission_template = FactoryBot.create(:permission_template, source_id: gw_etds_admin_set.id, with_admin_set: true, with_active_workflow: true)

FactoryBot.create(:permission_template_access,
:deposit,
permission_template: FactoryBot.create(:permission_template, source_id: gw_etds_admin_set.id, with_admin_set: true, with_active_workflow: true),
permission_template: permission_template,
agent_type: 'user',
agent_id: admin_user.user_key)
# collections
5.times do
FactoryBot.create(:collection, user: admin_user)

# collection to add works to
main_collection = FactoryBot.create(:public_collection, with_permission_template: permission_template)

# other collections
4.times do
FactoryBot.create(:public_collection, with_permission_template: permission_template)
end

# works with specific configurations - will need to log in as admin to see them
# private works with specific configurations - will need to log in as admin to see them
FactoryBot.create(:work_with_image_files, user: admin_user, title: ["A Work with an Image File"])
FactoryBot.create(:embargoed_work, user: admin_user, title: ["An Embargoed Work"])
FactoryBot.create(:work_with_one_file, user: admin_user, title: ["A Work with a file"])
Expand All @@ -31,25 +37,75 @@
FactoryBot.create(:work_with_one_child, user: admin_user, title: ["A Work with one child"])
FactoryBot.create(:work_with_two_children, user: admin_user, title: ["A Work with two children"])

# public etds with metadata
# public GwWorks with metadata
5.times do |i|
FactoryBot.create(:public_work,
user: admin_user,
admin_set: gw_etds_admin_set,
title: ["Test work with metadata #{i}"],
gw_affiliation: ["Department of Testing"],
resource_type: ["Research Paper"],
title: ["Test Public ETD with metadata #{i}"],
gw_affiliation: ["Department of Testing", "Department of Quality Control", "Scholarly Technology Group"],
resource_type: [["Research Paper", "Article", "Archival Work"].sample],
creator: ["Professor Goodtests"],
contributor: ["Assistant Badtests", "Another Collaborator"],
description: ["A work for testing with metadata"],
abstract: Faker::Lorem.paragraphs(number: 1),
keyword: ["Testing", "Examining", "Prodding"],
license: ["http://www.europeana.eu/portal/rights/rr-r.html"],
rights_statement: ["http://rightsstatements.org/vocab/InC/1.0/"],
publisher: ["A Pretty Cool Publisher"],
date_created: [rand(1900..2010).to_s],
subject: ["Automated Testing"],
language: ["English"],
member_of_collections: [main_collection]
)
end

# public GwJournalIssues
5.times do |i|
FactoryBot.create(:public_journal_issue,
user: admin_user,
admin_set: gw_etds_admin_set,
title: ["Test Public GW Journal Issue with Metadata #{i}"],
gw_affiliation: ["Department of Testing", "Department of Quality Control", "Scholarly Technology Group"],
resource_type: ["Journal Issue"],
creator: ["Professor Goodtests"],
contributor: ["Assistant Badtests", "Another Collaborator"],
description: ["A work for testing with metadata"],
abstract: Faker::Lorem.paragraphs(number: 1),
keyword: ["Testing", "Examining", "Prodding"],
license: ["http://www.europeana.eu/portal/rights/rr-r.html"],
rights_statement: ["http://rightsstatements.org/vocab/InC/1.0/"],
publisher: ["A Pretty Cool Publisher"],
date_created: [rand(1900..2010).to_s],
subject: ["Automated Testing"],
language: ["English"],
issue: [rand(1..3).to_s],
volume: [rand(1..3).to_s]
)
end

# public ETDs
5.times do |i|
FactoryBot.create(:public_etd,
user: admin_user,
admin_set: gw_etds_admin_set,
title: ["Test Public GW Jouranl Issue with metadata #{i}"],
gw_affiliation: ["Department of Testing", "Department of Quality Control", "Scholarly Technology Group"],
resource_type: ["Journal Issue"],
creator: ["Professor Goodtests"],
contributor: ["Assistant Badtests"],
contributor: ["Assistant Badtests", "Another Collaborator"],
description: ["A work for testing with metadata"],
abstract: ["Ey I'm abstracting here"],
abstract: Faker::Lorem.paragraphs(number: 1),
keyword: ["Testing", "Examining", "Prodding"],
license: ["http://www.europeana.eu/portal/rights/rr-r.html"],
rights_statement: ["http://rightsstatements.org/vocab/InC/1.0/"],
publisher: ["A Pretty Cool Publisher"],
date_created: [rand(1900..2010).to_s],
subject: ["Automated Testing"],
language: ["English"]
language: ["English"],
degree: "Ph.D",
advisor: ["Doctor Advisor"],
committee_member: ["Committee Member 1", "Committee Member 2"]
)
end

Expand Down
45 changes: 45 additions & 0 deletions spec/factories/gw_etds.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# frozen_string_literal: true

FactoryBot.define do
factory :etd, aliases: [:gw_etd, :private_etd], class: 'GwEtd' do
transient do
user { FactoryBot.create(:user) }
# Set to true (or a hash) if you want to create an admin set
with_admin_set { false }
end

# It is reasonable to assume that a work has an admin set; However, we don't want to
# go through the entire rigors of creating that admin set.
before(:create) do |work, evaluator|
if evaluator.with_admin_set
attributes = {}
attributes[:id] = work.admin_set_id if work.admin_set_id.present?
attributes = evaluator.with_admin_set.merge(attributes) if evaluator.with_admin_set.respond_to?(:merge)
admin_set = create(:admin_set, attributes)
work.admin_set_id = admin_set.id
end
end

after(:create) do |work, _evaluator|
work.save! if work.try(:member_of_collections) && work.member_of_collections.present?
end

title { ["Test title"] }

after(:build) do |work, evaluator|
work.apply_depositor_metadata(evaluator.user.user_key) if work.try(:apply_depositor_metadata, evaluator.user.user_key)
end

factory :public_etd, traits: [:public]

trait :public do
visibility { Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC }
end

factory :authenticated_etd, traits: [:authenticated]

trait :authenticated do
visibility { Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED }
end
end
end
49 changes: 49 additions & 0 deletions spec/factories/gw_journal_issues.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# frozen_string_literal: true

FactoryBot.define do
factory :journal_issue, aliases: [:gw_journal_issue, :private_journal_issue], class: 'GwJournalIssue' do
transient do
user { FactoryBot.create(:user) }
# Set to true (or a hash) if you want to create an admin set
with_admin_set { false }
end

# It is reasonable to assume that a work has an admin set; However, we don't want to
# go through the entire rigors of creating that admin set.
before(:create) do |work, evaluator|
if evaluator.with_admin_set
attributes = {}
attributes[:id] = work.admin_set_id if work.admin_set_id.present?
attributes = evaluator.with_admin_set.merge(attributes) if evaluator.with_admin_set.respond_to?(:merge)
admin_set = create(:admin_set, attributes)
work.admin_set_id = admin_set.id
end
end

after(:create) do |work, _evaluator|
work.save! if work.try(:member_of_collections) && work.member_of_collections.present?
end

title { ["Test title"] }

after(:build) do |work, evaluator|
work.apply_depositor_metadata(evaluator.user.user_key) if work.try(:apply_depositor_metadata, evaluator.user.user_key)
end

factory :public_journal_issue, traits: [:public]

trait :public do
visibility { Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC }
end

factory :authenticated_journal_issue, traits: [:authenticated]

trait :authenticated do
visibility { Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED }
end

factory :invalid_journal_issue do
title { nil }
end
end
end
File renamed without changes.

0 comments on commit 91586af

Please sign in to comment.