Skip to content

Commit

Permalink
add parent_works and parent_work_ids
Browse files Browse the repository at this point in the history
  • Loading branch information
elrayle committed Mar 28, 2019
1 parent de18a79 commit 1850669
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 1 deletion.
16 changes: 16 additions & 0 deletions lib/wings/hydra/pcdm/models/concerns/pcdm_valkyrie_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,22 @@ def method_missing(name, *args, &block)
def respond_to_missing?(_name, _include_private = false)
true
end

# @param valkyrie [Boolean] Should the returned ids be for Valkyrie or AF objects?
# @return [Enumerable<Hydra::Works::Work>] The works this work contains
# NOTE: This method avoids using the Hydra::Works version of parent_works because of Issue #361
def parent_works(valkyrie: false)
af_child = Wings::ActiveFedoraConverter.new(resource: self).convert
af_parents = af_child.member_of_works
return af_parents unless valkyrie
af_parents.map(&:valkyrie_resource)
end

# @param valkyrie [Boolean] Should the returned ids be for Valkyrie or AF objects?
# @return [Enumerable<String> | Enumerable<Valkerie::ID] The ids of the file sets this work contains
def parent_work_ids(valkyrie: false)
parent_works.map(&:id)
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -330,4 +330,70 @@
expect { resource.a_missing_method }.to raise_error NoMethodError
end
end

describe '#parent_works' do
let(:pcdm_object) { work3 }
let(:child_work_resource) { resource }

before do
work1.ordered_members = [work3]
work2.ordered_members = [work3]
work1.save!
work2.save!
end

context 'when valkyrie resources requested' do
it 'returns parent works as valkyrie resources through pcdm_valkyrie_behavior' do
resources = child_work_resource.parent_works(valkyrie: true)
expect(resources.map(&:work?)).to all(be true)
expect(resources.map(&:id)).to match_valkyrie_ids_with_active_fedora_ids([work1.id, work2.id])
end
end
context 'when active fedora objects requested' do
it 'returns parent works as fedora objects through pcdm_valkyrie_behavior' do
af_objects = child_work_resource.parent_works(valkyrie: false)
expect(af_objects.map(&:work?)).to all(be true)
expect(af_objects.map(&:id)).to match_array [work1.id, work2.id]
end
end
context 'when return type is not specified' do
it 'returns parent works as fedora objects through pcdm_valkyrie_behavior' do
af_objects = child_work_resource.parent_works
expect(af_objects.map(&:work?)).to all(be true)
expect(af_objects.map(&:id)).to match_array [work1.id, work2.id]
end
end
end

describe '#parent_work_ids' do
let(:pcdm_object) { work3 }
let(:child_work_resource) { resource }

before do
work1.ordered_members = [work3]
work2.ordered_members = [work3]
work1.save!
work2.save!
end

context 'when valkyrie resources requested' do
it 'returns parent works as valkyrie resources through pcdm_valkyrie_behavior' do
pending "TODO: Implementation of this method for valkyrie"
resource_ids = child_work_resource.parent_work_ids(valkyrie: true)
expect(resource_ids).to match_valkyrie_ids_with_active_fedora_ids([work1.id, work2.id])
end
end
context 'when active fedora objects requested' do
it 'returns parent works as fedora objects through pcdm_valkyrie_behavior' do
af_object_ids = child_work_resource.parent_work_ids(valkyrie: false)
expect(af_object_ids).to match_array [work1.id, work2.id]
end
end
context 'when return type is not specified' do
it 'returns parent works as fedora objects through pcdm_valkyrie_behavior' do
af_object_ids = child_work_resource.parent_work_ids
expect(af_object_ids).to match_array [work1.id, work2.id]
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
work4.save!
work5.ordered_members << work1
work5.save!
work1.members = [work2, work3, fileset1, fileset2]
work1.ordered_members = [work2, work3, fileset1, fileset2]
work1.save!
end

Expand Down

0 comments on commit 1850669

Please sign in to comment.