Skip to content

Commit

Permalink
Ensure HashWithIndifferentAccess (#971)
Browse files Browse the repository at this point in the history
Attributes were not consistently using the same types of keys. By
converting to HashWithIndifferentAccess first, we ensure that we
find the keys we are looking for.
  • Loading branch information
laritakr authored Aug 22, 2024
1 parent ec8be99 commit 189b95c
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions app/factories/bulkrax/valkyrie_object_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ def create_file_set(attrs)
end

def create_work(attrs)
# NOTE: We do not add relationships here; that is part of the create
# relationships job.
# NOTE: We do not add relationships here; that is part of the create relationships job.
attrs = HashWithIndifferentAccess.new(attrs)
perform_transaction_for(object: object, attrs: attrs) do
uploaded_files = uploaded_files_from(attrs)
file_set_params = file_set_params_for(uploaded_files, combined_files_with(remote_files: attrs["remote_files"]))
Expand All @@ -259,13 +259,13 @@ def create_work(attrs)
'work_resource.add_file_sets' => { uploaded_files: uploaded_files, file_set_params: file_set_params },
"change_set.set_user_as_depositor" => { user: @user },
"work_resource.change_depositor" => { user: @user },
'work_resource.save_acl' => { permissions_params: [attrs['visibility'] || 'open'].compact }
'work_resource.save_acl' => { permissions_params: [attrs.try('visibility') || 'open'].compact }
)
end
end

def combined_files_with(remote_files:)
thumbnail_url = self.attributes['thumbnail_url']
thumbnail_url = HashWithIndifferentAccess.new(self.attributes)['thumbnail_url']
return [thumbnail_url] if remote_files.blank?
@combined_files ||= (thumbnail_url.present? ? remote_files + [thumbnail_url] : remote_files)
end
Expand All @@ -277,7 +277,7 @@ def file_set_params_for(uploaded_files, combined_files)
# - included in the file_set_metadata.yaml
# - overriden in file_set_args from Hyrax::WorkUploadsHandler
additional_attributes = combined_files.map do |hash|
hash.reject { |key, _| key == 'url' || key == 'file_name' }
hash.reject { |key, _| key.to_s == 'url' || key.to_s == 'file_name' }
end

file_attrs = []
Expand Down Expand Up @@ -353,6 +353,7 @@ def permitted_attributes
end

def update_work(attrs)
attrs = HashWithIndifferentAccess.new(attrs)
perform_transaction_for(object: object, attrs: attrs) do
uploaded_files = uploaded_files_from(attrs)
file_set_params = file_set_params_for(uploaded_files, combined_files_with(remote_files: attrs["remote_files"]))
Expand Down

0 comments on commit 189b95c

Please sign in to comment.