Skip to content

Commit

Permalink
Merge pull request #453 from samvera-labs/remove-empty-id-when-settin…
Browse files Browse the repository at this point in the history
…g-object-attrs

remove-empty-id-when-setting-object-attrs
  • Loading branch information
alishaevn authored Apr 8, 2022
2 parents 27ee6f0 + f10ff83 commit a493070
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
10 changes: 10 additions & 0 deletions app/factories/bulkrax/object_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ def work_actor
end

def create_collection(attrs)
attrs = clean_attrs(attrs)
attrs = collection_type(attrs)
persist_collection_memberships(parent: find_collection(attributes[related_parents_parsed_mapping]), child: object) if attributes[related_parents_parsed_mapping].present?
object.attributes = attrs
Expand All @@ -154,6 +155,7 @@ def update_collection(attrs)
def create_file_set(attrs)
work = find_record(attributes[related_parents_parsed_mapping].first)
work_permissions = work.permissions.map(&:to_hash)
attrs = clean_attrs(attrs)
file_set_attrs = attrs.slice(*object.attributes.keys)
object.assign_attributes(file_set_attrs)

Expand Down Expand Up @@ -202,8 +204,16 @@ def find_collection(id)
end
end

def clean_attrs(attrs)
# avoid the "ArgumentError: Identifier must be a string of size > 0 in order to be treeified" error
# when setting object.attributes
attrs.delete('id') if attrs['id'].blank?
attrs
end

def collection_type(attrs)
return attrs if attrs['collection_type_gid'].present?

attrs['collection_type_gid'] = Hyrax::CollectionType.find_or_create_default_collection_type.gid
attrs
end
Expand Down
3 changes: 3 additions & 0 deletions spec/jobs/bulkrax/importer_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
module Bulkrax
RSpec.describe ImporterJob, type: :job do
subject(:importer_job) { described_class.new }
# the bulkrax_importer_oai base_url comes from a live website
# until it is stubbed, the values below will fluctuate as the api changes
# TODO(alishaevn): delete the above comments when issue 455 is complete
let(:importer) { FactoryBot.create(:bulkrax_importer_oai) }

before do
Expand Down

0 comments on commit a493070

Please sign in to comment.