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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.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.

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
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.

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