diff --git a/app/presenters/hyrax/permission_badge.rb b/app/presenters/hyrax/permission_badge.rb index 6925973f10..fde26af8ba 100644 --- a/app/presenters/hyrax/permission_badge.rb +++ b/app/presenters/hyrax/permission_badge.rb @@ -24,14 +24,15 @@ def render private def dom_label_class - VISIBILITY_LABEL_CLASS.fetch(@visibility.to_sym, 'badge-info') + VISIBILITY_LABEL_CLASS.fetch(@visibility&.to_sym, 'badge-info') end def text if registered? Institution.name else - I18n.t("hyrax.visibility.#{@visibility}.text") + visibility_key = @visibility || 'unknown' + I18n.t("hyrax.visibility.#{visibility_key}.text") end end diff --git a/config/locales/hyrax.en.yml b/config/locales/hyrax.en.yml index 885f2cffe5..83ba84a671 100644 --- a/config/locales/hyrax.en.yml +++ b/config/locales/hyrax.en.yml @@ -1687,6 +1687,8 @@ en: note_html: Keep to myself with option to share. text: Private restricted_title_attr: Change the visibility of this resource + unknown: + text: Unknown work_button_row: attach_child: Attach Child workflow: diff --git a/spec/presenters/hyrax/permission_badge_spec.rb b/spec/presenters/hyrax/permission_badge_spec.rb index 5a8e4476db..5a0f22f7ad 100644 --- a/spec/presenters/hyrax/permission_badge_spec.rb +++ b/spec/presenters/hyrax/permission_badge_spec.rb @@ -35,6 +35,13 @@ context "when private" do it { is_expected.to eq "Private" } end + + # solr document can have no visibility indexed + it "does not fail when nil is passed" do + badge = described_class.new(nil) + + expect(badge.render).to eq "Unknown" + end end end