Skip to content

Commit

Permalink
Enable class names for factories (#6700)
Browse files Browse the repository at this point in the history
* ☑️ Better allow downstream apps to reuse factories

Prior to this commit, a downstream implementation that re-uses a factory
cannot change it's inheritance.

In my experiments, I am unable to modify a factory's parent via
FactoryBot's current implementation.  This means that in a Hyku
application that has it's own AdminSet, FileSet, and Collection models,
I cannot re-use the `:hyrax_admin_set`, `:hyrax_collection`, and
`:hyrax_file_set` factories.  The problem emerges when I re-use a Hyrax
factory that then calls a Hyrax factory (e.g. the permission_template
factory can create a `:hyrax_admin_set`).

With this commit, I downstream applications can more easily re-use
factories.  I need the antics of sniffing out ancestry because of Hyrax
configurations under test.  Namely when we're testing wings the
Hyrax.admin_set_model is `"AdminSet"`; which breaks all sorts of things.

* ☑️ Remove hyrax/specs/factories

In my downstream testing this was creating absolute mayhem with
auto-loading.  Once I've settled on the pattern, I'll document how to do
this.

* 💄 endless and ever appeasing of the coppers
  • Loading branch information
jeremyf authored Feb 20, 2024
1 parent f0e3a3e commit cbb5b4f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 23 deletions.
19 changes: 0 additions & 19 deletions lib/hyrax/specs/factories.rb

This file was deleted.

12 changes: 11 additions & 1 deletion spec/factories/administrative_sets.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
# frozen_string_literal: true

FactoryBot.define do
factory :hyrax_admin_set, class: 'Hyrax::AdministrativeSet' do
##
# This factory creates a Valkyrized adminstrative set; by default a Hyrax::AdministrativeSet
#
# Why the antics around the class? Because of the Hyrax needs and potential downstream
# applciation needs.
#
# Downstream applications might implement a different # administrative set and the downstream
# application might leverage other Hyrax factories that create a `:hyrax_admin_set`
# (e.g. `:permission_template`)
factory :hyrax_admin_set, class: (Hyrax.config.admin_set_class < Valkyrie::Resource ? Hyrax.config.admin_set_class : Hyrax::AdministrativeSet) do
title { ['My Admin Set'] }

transient do
Expand Down
10 changes: 9 additions & 1 deletion spec/factories/hyrax_collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@

##
# Use this factory for generic Hyrax/HydraWorks Collections in valkyrie.
#
# This factory creates a Valkyrized collection set; by default a Hyrax::PcdmCollection
#
# Why the antics around the class? Because of the Hyrax needs and potential downstream
# applciation needs.
#
# Downstream applications might implement a different collection class and the downstream
# application might leverage other Hyrax factories that create a `:hyrax_collection`
FactoryBot.define do
factory :hyrax_collection, class: 'CollectionResource', aliases: [:collection_resource] do
factory :hyrax_collection, class: (Hyrax.config.collection_class < Valkyrie::Resource ? Hyrax.config.collection_class : 'CollectionResource'), aliases: [:collection_resource] do
sequence(:title) { |n| ["The Tove Jansson Collection #{n}"] }
collection_type_gid { Hyrax::CollectionType.find_or_create_default_collection_type.to_global_id.to_s }

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

##
# Use this factory for generic Hyrax/HydraWorks FileSets in valkyrie.
FactoryBot.define do
factory :hyrax_file_set, class: 'Hyrax::FileSet' do
transient do
Expand Down

0 comments on commit cbb5b4f

Please sign in to comment.