Skip to content

Commit 809649f

Browse files
committed
Fix logic related to obtain strings, closes #428
1 parent b80e239 commit 809649f

File tree

6 files changed

+39
-8
lines changed

6 files changed

+39
-8
lines changed

app/components/obtain_online_component.rb

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# frozen_string_literal: true
22

33
class ObtainOnlineComponent < ViewComponent::Base
4-
def initialize(size: :medium, document:)
4+
attr_reader :string
5+
6+
def initialize(document:, size: :medium)
57
@size = size
68
@document = document
79
@url = document_url
@@ -12,7 +14,9 @@ def initialize(size: :medium, document:)
1214
private
1315

1416
def display_string
15-
return t(format_i18n_string) if I18n.exists? format_i18n_string
17+
return t('obtain.resource') if document_format.blank?
18+
19+
return t(format_i18n_string) if format_i18n_string
1620

1721
t('obtain.general_online', type: document_format)
1822
end
@@ -27,8 +31,10 @@ def document_url
2731

2832
def format_i18n_string
2933
raw_format = document_format
30-
"obtain.#{raw_format.downcase.sub(' ', '_')}"
31-
end
34+
key = "obtain.#{raw_format.downcase.sub(' ', '_')}"
3235

36+
return nil unless I18n.exists? key
3337

38+
key
39+
end
3440
end

app/views/bento/_catalog_results_list_author_date.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<%= "(#{record.first(:author_display) || record.first(:pub_date)})" %>
88
<% end %>
99
<% if online_record? record %>
10-
<%= link_to content_tag(:span, 'open_in_new', class: 'material-icons').prepend("#{t('obtain.catalog_record')} "),
10+
<%= link_to content_tag(:span, 'open_in_new', class: 'material-icons').prepend("#{t('obtain.resource')} "),
1111
record.first(:url_fulltext_display), class: 'badge badge-success' %>
1212
<% elsif(evergreen_record? record) %>
1313
<%= render(EvergreenHoldingsComponent.new(size: :small, record_id: record.id, service: @evergreen_service)) %>

app/views/bento/_catalog_results_list_minimal.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<%= "(#{record.first(:format) || record.first(:pub_date)})" %>
88
<% end %>
99
<% if online_record? record %>
10-
<%= link_to content_tag(:span, 'open_in_new', class: 'material-icons').prepend("#{t('obtain.catalog_record')} "),
10+
<%= link_to content_tag(:span, 'open_in_new', class: 'material-icons').prepend("#{t('obtain.resource')} "),
1111
record.first(:url_fulltext_display), class: 'badge badge-success' %>
1212
<% elsif(evergreen_record? record) %>
1313
<%= render(EvergreenHoldingsComponent.new(size: :small, record_id: record.id, service: @evergreen_service)) %>

config/locales/findit.en.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ en:
6767
available_at: "Available at %{library} (%{location}): %{call_number}"
6868
unavailable_at: "%{library} owns a copy, but it is currently unavailable."
6969
available_at_partner_libraries: Available at Partner Libraries
70-
catalog_record: Access resource online
70+
resource: Access resource online
7171
ebook: Read ebook online
7272
general_online: "Access %{type} online"
7373
place_hold: Request curbside pickup

config/locales/findit.es.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ es:
5050
unavailable: No disponible
5151
available_at: "Disponible en %{library} (%{location}): %{call_number}"
5252
unavailable_at: "Artículo de %{library} actualmente no disponible."
53-
catalog_record: Acceder a este recurso
53+
resource: Acceder a este recurso
5454
ebook: Leer ebook
5555
general_online: "Aceder %{type} en línea"
5656
place_hold: Recogida en la acera
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
require 'rails_helper'
2+
3+
RSpec.describe ObtainOnlineComponent, type: :component do
4+
it 'delivers a reasonable string when format is not known' do
5+
component = described_class.new(document: SolrDocument.new('id' => '12345', 'title' => 'Hello World'))
6+
expect(component.string).to eq(I18n.t('obtain.resource'))
7+
end
8+
9+
it 'delivers a reasonable string when format is an empty string' do
10+
component = described_class.new(document: SolrDocument.new('id' => '12345', 'format' => '', 'title' => 'Hello World'))
11+
expect(component.string).to eq(I18n.t('obtain.resource'))
12+
end
13+
14+
it 'delivers a customized string when format is Ebook' do
15+
component = described_class.new(document: SolrDocument.new('id' => '12345', 'title' => 'Hello World',
16+
'format' => 'Ebook'))
17+
expect(component.string).to eq(I18n.t('obtain.ebook'))
18+
end
19+
20+
it 'delivers a customized string when format does not have its own predefined format' do
21+
component = described_class.new(document: SolrDocument.new('id' => '12345', 'title' => 'Hello World',
22+
'format' => 'Espresso machine'))
23+
expect(component.string).to eq(I18n.t('obtain.general_online', type: 'Espresso machine'))
24+
end
25+
end

0 commit comments

Comments
 (0)