Skip to content

Commit

Permalink
Allow work form to display when wings is disabled
Browse files Browse the repository at this point in the history
When `disable_wings=true`, the `Wings` constant is not defined.  As a result, you cannot check directly to see if the metadata adapter is “Wings::Valkyrie::MetadataAdapter”.  This check results in a “NameError”.  If we check for `disable_wings` first, then it avoids the check of the metadata adapter.
  • Loading branch information
elrayle committed Nov 3, 2021
1 parent 87f8845 commit 0de791a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
17 changes: 8 additions & 9 deletions app/forms/hyrax/forms/resource_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,15 @@ class ResourceForm < Hyrax::ChangeSet # rubocop:disable Metrics/ClassLength
# we want to move away from application side lock validation and rely
# on the adapter/database features instead.
LockKeyPopulator = lambda do |_options|
self.version =
case Hyrax.metadata_adapter
when Wings::Valkyrie::MetadataAdapter
if Hyrax.config.disable_wings || Hyrax.metadata_adapter != Wings::Valkyrie::MetadataAdapter
Hyrax.logger.info "trying to prepopulate a lock token for " \
"#{self.class.inspect}, but optimistic locking isn't " \
"supported for the configured adapter: #{Hyrax.metadata_adapter.class}"
self.version = ''
else
self.version =
model.persisted? ? Wings::ActiveFedoraConverter.convert(resource: model).etag : ''
else
Hyrax.logger.info 'trying to prepopulate a lock token for ' \
"#{self.class.inspect}, but optimistic locking isn't " \
"supported for the configured adapter: #{Hyrax.metadata_adapter.class}"
''
end
end
end

class_attribute :model_class
Expand Down
9 changes: 8 additions & 1 deletion spec/forms/hyrax/forms/resource_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,13 @@
end

context 'when using a generic valkyrie adapter', valkyrie_adapter: :test_adapter do
before do
allow(Hyrax).to receive_message_chain(:config, :disable_wings).and_return(true) # rubocop:disable RSpec/MessageChain
hide_const("Wings") # disable_wings=true removes the Wings constant
end
it 'prepopulates as empty before save' do
expect(Hyrax.logger).to receive(:info)
.with(starting_with("trying to prepopulate a lock token for"))
form.prepopulate!
expect(form.version).to eq ''
end
Expand All @@ -393,8 +399,9 @@
let(:work) { FactoryBot.valkyrie_create(:hyrax_work) }

it 'prepopulates empty' do
expect(Hyrax.logger).to receive(:info)
.with(starting_with("trying to prepopulate a lock token for"))
form.prepopulate!

expect(form.version).to eq ''
end
end
Expand Down

0 comments on commit 0de791a

Please sign in to comment.