-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 Skip rendering badges on search_only tenants
*Background:* A search_only tenant renders SOLR documents that had home tenants different than the search_only tenant. Part of that rendering includes the underlying Work's collection type. The SOLR document stores the `Hyrax::CollectionType`'s ID. The search_only tenant might have the same ID for `Hyrax::CollectionType` but it is not the same thing. Further, the home tenant might have an ID that is not in the search_only tenant, which results in an `ActiveRecord::RecordNotFound` error. Prior to this commit, we always attempted to render the badge. With this commit, we add some guarding logic to avoid rendering the badge when we're likely not rendering within the SOLR documents home tenant. Related to: - #951 - samvera/hyku#1815
- Loading branch information
Showing
2 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
spec/presenters/hyrax/collection_presenter_decorator_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
RSpec.describe Hyrax::CollectionPresenter do | ||
describe '#collection_type_badge' do | ||
subject { presenter.collection_type_badge } | ||
|
||
# We're decorating an alternate base class so that we don't need the full pre-amble for testing | ||
# our decoration. In other words, let's trust Hyrax::CollectionPresenter's specs for the | ||
# "super" method call. | ||
let(:base_class) do | ||
Class.new do | ||
def collection_type_badge | ||
"<span>" | ||
end | ||
prepend Hyrax::CollectionPresenterDecorator | ||
end | ||
end | ||
let(:presenter) { base_class.new } | ||
|
||
before { allow(Site).to receive(:account).and_return(account) } | ||
|
||
context 'when the Site.account is nil' do | ||
let(:account) { nil } | ||
|
||
it { is_expected.to eq("") } | ||
end | ||
|
||
context 'when the Site.account is search_only' do | ||
let(:account) { FactoryBot.build(:account, search_only: true) } | ||
|
||
it { is_expected.to eq("") } | ||
end | ||
|
||
context 'when the Site.account is NOT search_only' do | ||
let(:account) { FactoryBot.build(:account, search_only: false) } | ||
|
||
it { is_expected.to start_with("<span") } | ||
end | ||
|
||
context 'super_method' do | ||
subject { Hyrax::CollectionPresenter.instance_method(:collection_type_badge).super_method } | ||
|
||
let(:account) { nil } | ||
|
||
it 'is Hyrax::CollectionPresenter#collection_type_badge' do | ||
expect(subject.source_location.first).to end_with("app/presenters/hyrax/collection_presenter.rb") | ||
end | ||
end | ||
end | ||
end |