Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow work form to display when wings is disabled #5242

Merged
merged 1 commit into from
Nov 4, 2021
Merged

Conversation

elrayle
Copy link
Contributor

@elrayle elrayle commented Nov 3, 2021

Description

When Hyrax.config.disable_wings # true the Wings constant is not defined. This is the correct behavior, but means that any reference to Wings in app needs to check if disable_wings #true before using the Wings constant.

This PR addresses a specific instance in Hyrax::ResourceForm where there was a check to see if the metadata adapter is wings.

This PR includes

  • update existing non-wings test to remove the Wings constant so that it provides a failing test for the scenario described in this PR
  • code fix to prevent the exception

Expected

Dashboard -> Works -> Add new work -> displays the work form

Actual

Dashboard -> Works -> Add new work -> raises an exception

image

Related Work

There are other places where Wings is used without checking disable_wings #true. A cursory review indicates that these locations are places not expected to be encountered when using a non-wings adapter for Valkyrie (e.g. actor stack code, AF forms). It is possible that other locations may be uncovered later that would need a similar approach as applied in this PR.

@samvera/hyrax-code-reviewers

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.
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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It already has a test using a non-wings adapter, but it doesn't fully simulate disabled wings. When it is disabled, the Wings constant doesn't exist. The new before block simulates disable_wings returning true and the Wings constant not existing.

it 'prepopulates as empty before save' do
expect(Hyrax.logger).to receive(:info)
.with(starting_with("trying to prepopulate a lock token for"))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It isn't a change that the logger adds this info message. This expect line just confirms the message was logged.

self.version =
case Hyrax.metadata_adapter
when Wings::Valkyrie::MetadataAdapter
if Hyrax.config.disable_wings || !Hyrax.metadata_adapter.is_a?(Wings::Valkyrie::MetadataAdapter)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The case statement didn't allow for checking disable_wings before trying to use the Wings constant. The change is a simple rewrite of the case into an if to allow for the more complex check. The code that is executed for each case is the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants