Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provide default PermissionBadge presenter behavior when nil #5807

Merged
merged 1 commit into from
Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions app/presenters/hyrax/permission_badge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions config/locales/hyrax.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 7 additions & 0 deletions spec/presenters/hyrax/permission_badge_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@
context "when private" do
it { is_expected.to eq "<span class=\"badge badge-danger\">Private</span>" }
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 "<span class=\"badge badge-info\">Unknown</span>"
end
end
end

Expand Down