Skip to content

Commit

Permalink
Merge pull request #6252 from samvera/id-dispatch
Browse files Browse the repository at this point in the history
make `Hyrax::Identifier::Dispatcher` support Valkryie
  • Loading branch information
hackartisan authored Sep 14, 2023
2 parents 719bca2 + 1461fdb commit 14a3a34
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
11 changes: 9 additions & 2 deletions app/services/hyrax/identifier/dispatcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,15 @@ def assign_for(object:, attribute: :identifier)
#
# @see #assign_for
def assign_for!(object:, attribute: :identifier)
assign_for(object: object, attribute: attribute).save!
object
result = assign_for(object: object, attribute: attribute)

case result
when Valkyrie::Resource
Hyrax.persister.save(resource: result)
else
result.save
result
end
end
end
end
Expand Down
24 changes: 15 additions & 9 deletions spec/services/hyrax/identifier/dispatcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
RSpec.describe Hyrax::Identifier::Dispatcher do
subject(:dispatcher) { described_class.new(registrar: fake_registrar.new) }
let(:identifier) { 'moomin/123/abc' }
let(:object) { build(:generic_work) }
let(:object) { FactoryBot.build(:monograph) }

let(:fake_registrar) do
Class.new do
Expand All @@ -16,10 +16,6 @@ def register!(*)
end

shared_examples 'performs identifier assignment' do |method|
it 'returns the same object' do
expect(dispatcher.public_send(method, object: object)).to eql object
end

it 'assigns to the identifier attribute by default' do
dispatcher.public_send(method, object: object)
expect(object.identifier).to contain_exactly(identifier)
Expand Down Expand Up @@ -59,10 +55,20 @@ def register!(*)
include_examples 'performs identifier assignment', :assign_for!

it 'saves the object' do
expect { dispatcher.assign_for!(object: object) }
.to change { object.new_record? }
.from(true)
.to(false)
expect(dispatcher.assign_for!(object: object)).to be_persisted
end

context 'with an ActiveFedora model', :active_fedora do
let(:object) { FactoryBot.build(:work) }

include_examples 'performs identifier assignment', :assign_for!

it 'saves the object' do
expect { dispatcher.assign_for!(object: object) }
.to change { object.new_record? }
.from(true)
.to(false)
end
end
end
end

0 comments on commit 14a3a34

Please sign in to comment.