Skip to content

Commit

Permalink
Enable PcdmMemberPresenterFactory to work with ActiveFedora
Browse files Browse the repository at this point in the history
  • Loading branch information
eliotjordan committed Mar 15, 2022
1 parent 99e5d96 commit 38ff5ac
Show file tree
Hide file tree
Showing 3 changed files with 155 additions and 59 deletions.
1 change: 1 addition & 0 deletions app/indexers/hyrax/file_set_indexer.rb
Expand Up @@ -30,6 +30,7 @@ def generate_solr_document # rubocop:disable Metrics/AbcSize, Metrics/MethodLeng
solr_doc['original_checksum_tesim'] = object.original_checksum
solr_doc['alpha_channels_ssi'] = object.alpha_channels
solr_doc['original_file_id_ssi'] = original_file_id
solr_doc['generic_type_si'] = 'FileSet'
end
end

Expand Down
4 changes: 3 additions & 1 deletion app/presenters/hyrax/pcdm_member_presenter_factory.rb
Expand Up @@ -99,6 +99,8 @@ def presenter_for(document:, ability:)
case document['has_model_ssim'].first
when Hyrax::FileSet.name
Hyrax::FileSetPresenter.new(document, ability)
when ::FileSet.name
Hyrax::FileSetPresenter.new(document, ability)
else
Hyrax::WorkShowPresenter.new(document, ability)
end
Expand All @@ -111,7 +113,7 @@ def query_docs(generic_type: nil, ids: object.member_ids)
query += "{!term f=generic_type_si}#{generic_type}" if generic_type

Hyrax::SolrService
.post(query, rows: 10_000)
.post(q: query, rows: 10_000)
.fetch('response')
.fetch('docs')
end
Expand Down
209 changes: 151 additions & 58 deletions spec/presenters/hyrax/pcdm_member_presenter_factory_spec.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true

RSpec.describe Hyrax::PcdmMemberPresenterFactory, index_adapter: :solr_index, valkyrie_adapter: :test_adapter do
RSpec.describe Hyrax::PcdmMemberPresenterFactory do
subject(:factory) { described_class.new(solr_doc, ability) }
let(:ability) { :FAKE_ABILITY }
let(:ids) { [] }
Expand All @@ -9,8 +9,7 @@
RSpec::Matchers.define :be_presenter_for do |expected|
match do |actual|
actual.id == expected.id &&
(actual.solr_document['has_model_ssim'].first ==
expected.class.name)
actual.model_name.name == expected.model_name.name
end
end

Expand All @@ -33,92 +32,186 @@
end
end

describe '#file_set_presenters' do
it 'is empty' do
expect(factory.file_set_presenters.to_a).to be_empty
context 'with ActiveFedora index adapter' do
describe '#file_set_presenters' do
it 'is empty' do
expect(factory.file_set_presenters.to_a).to be_empty
end

context 'with members' do
include_context 'with members'

it 'builds only file_set presenters' do
expect(factory.file_set_presenters)
.to contain_exactly(*file_sets.map { |fs| be_presenter_for(fs) })
end

it 'gives members in order' do
expect(factory.file_set_presenters.map(&:id)).to eq file_sets.map(&:id)
end
end
end

context 'with members' do
include_context 'with members'
describe '#member_presenters' do
it 'is empty' do
expect(factory.member_presenters.to_a).to be_empty
end

it 'builds only file_set presenters' do
expect(factory.file_set_presenters)
.to contain_exactly(*file_sets.map { |fs| be_presenter_for(fs) })
it 'accepts bespoke member ids' do
fs = FactoryBot.valkyrie_create(:hyrax_file_set)
Hyrax.index_adapter.save(resource: fs)

expect(factory.member_presenters([fs.id]).to_a)
.to contain_exactly(be_presenter_for(fs))
end

it 'gives members in order' do
expect(factory.file_set_presenters.map(&:id)).to eq file_sets.map(&:id)
it 'raises an error if given an unindexed id' do
expect { factory.member_presenters(['FAKE_ID']).to_a }
.to raise_error ArgumentError
end
end
end

describe '#member_presenters' do
it 'is empty' do
expect(factory.member_presenters.to_a).to be_empty
end
context 'with members' do
include_context 'with members'

it 'accepts bespoke member ids' do
fs = FactoryBot.valkyrie_create(:hyrax_file_set)
Hyrax.index_adapter.save(resource: fs)
it 'builds all member presenters' do
members = file_sets + works

expect(factory.member_presenters([fs.id]).to_a)
.to contain_exactly(be_presenter_for(fs))
end
expect(factory.member_presenters)
.to contain_exactly(*members.map { |fs| be_presenter_for(fs) })
end

it 'raises an error if given an unindexed id' do
expect { factory.member_presenters(['FAKE_ID']).to_a }
.to raise_error ArgumentError
it 'builds member presenters with appropriate classes' do
expect(factory.member_presenters)
.to contain_exactly(an_instance_of(Hyrax::WorkShowPresenter),
an_instance_of(Hyrax::WorkShowPresenter),
an_instance_of(Hyrax::FileSetPresenter),
an_instance_of(Hyrax::FileSetPresenter))
end

it 'gives members in order' do
expect(factory.member_presenters.map(&:id)).to eq ids
end
end
end

context 'with members' do
include_context 'with members'
describe '#ordered_ids' do
its(:ordered_ids) { is_expected.to eq ids }

it 'builds all member presenters' do
members = file_sets + works
context 'with members' do
include_context 'with members'

expect(factory.member_presenters)
.to contain_exactly(*members.map { |fs| be_presenter_for(fs) })
its(:ordered_ids) { is_expected.to eq ids }
end
end

it 'builds member presenters with appropriate classes' do
expect(factory.member_presenters)
.to contain_exactly(an_instance_of(Hyrax::WorkShowPresenter),
an_instance_of(Hyrax::WorkShowPresenter),
an_instance_of(Hyrax::FileSetPresenter),
an_instance_of(Hyrax::FileSetPresenter))
describe '#work_presenters' do
it 'is empty' do
expect(factory.work_presenters.to_a).to be_empty
end

it 'gives members in order' do
expect(factory.member_presenters.map(&:id)).to eq ids
context 'with members' do
include_context 'with members'

it 'builds only work presenters' do
expect(factory.work_presenters)
.to contain_exactly(*works.map { |fs| be_presenter_for(fs) })
end

it 'gives members in order' do
expect(factory.work_presenters.map(&:id)).to eq works.map(&:id)
end
end
end
end

describe '#ordered_ids' do
its(:ordered_ids) { is_expected.to eq ids }
context 'with Valkyrie index adapter', index_adapter: :solr_index, valkyrie_adapter: :test_adapter do
describe '#file_set_presenters' do
it 'is empty' do
expect(factory.file_set_presenters.to_a).to be_empty
end

context 'with members' do
include_context 'with members'
context 'with members' do
include_context 'with members'

its(:ordered_ids) { is_expected.to eq ids }
it 'builds only file_set presenters' do
expect(factory.file_set_presenters)
.to contain_exactly(*file_sets.map { |fs| be_presenter_for(fs) })
end

it 'gives members in order' do
expect(factory.file_set_presenters.map(&:id)).to eq file_sets.map(&:id)
end
end
end
end

describe '#work_presenters' do
it 'is empty' do
expect(factory.work_presenters.to_a).to be_empty
describe '#member_presenters' do
it 'is empty' do
expect(factory.member_presenters.to_a).to be_empty
end

it 'accepts bespoke member ids' do
fs = FactoryBot.valkyrie_create(:hyrax_file_set)
Hyrax.index_adapter.save(resource: fs)

expect(factory.member_presenters([fs.id]).to_a)
.to contain_exactly(be_presenter_for(fs))
end

it 'raises an error if given an unindexed id' do
expect { factory.member_presenters(['FAKE_ID']).to_a }
.to raise_error ArgumentError
end

context 'with members' do
include_context 'with members'

it 'builds all member presenters' do
members = file_sets + works

expect(factory.member_presenters)
.to contain_exactly(*members.map { |fs| be_presenter_for(fs) })
end

it 'builds member presenters with appropriate classes' do
expect(factory.member_presenters)
.to contain_exactly(an_instance_of(Hyrax::WorkShowPresenter),
an_instance_of(Hyrax::WorkShowPresenter),
an_instance_of(Hyrax::FileSetPresenter),
an_instance_of(Hyrax::FileSetPresenter))
end

it 'gives members in order' do
expect(factory.member_presenters.map(&:id)).to eq ids
end
end
end

context 'with members' do
include_context 'with members'
describe '#ordered_ids' do
its(:ordered_ids) { is_expected.to eq ids }

context 'with members' do
include_context 'with members'

it 'builds only work presenters' do
expect(factory.work_presenters)
.to contain_exactly(*works.map { |fs| be_presenter_for(fs) })
its(:ordered_ids) { is_expected.to eq ids }
end
end

describe '#work_presenters' do
it 'is empty' do
expect(factory.work_presenters.to_a).to be_empty
end

context 'with members' do
include_context 'with members'

it 'builds only work presenters' do
expect(factory.work_presenters)
.to contain_exactly(*works.map { |fs| be_presenter_for(fs) })
end

it 'gives members in order' do
expect(factory.work_presenters.map(&:id)).to eq works.map(&:id)
it 'gives members in order' do
expect(factory.work_presenters.map(&:id)).to eq works.map(&:id)
end
end
end
end
Expand Down

0 comments on commit 38ff5ac

Please sign in to comment.