-
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.
- Loading branch information
Showing
10 changed files
with
86 additions
and
2 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
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
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
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
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,15 @@ | ||
module CatalogHelper | ||
include Blacklight::CatalogHelperBehavior | ||
|
||
def render_language_facet(value) | ||
content_tag(:span, label_for_code(value)) | ||
end | ||
|
||
def label_for_code(code) | ||
LanguageService.label_for_code(code) | ||
end | ||
|
||
def label_for_value(document) | ||
label_for_code((document[:value] || []).first) | ||
end | ||
end |
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
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
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,5 @@ | ||
class LanguageService | ||
def self.label_for_code(code) | ||
ISO_639.find_by_code(code).try(:english_name) || code | ||
end | ||
end |
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,36 @@ | ||
require 'rails_helper' | ||
|
||
describe CatalogHelper do | ||
let(:helper) { TestingHelper.new } | ||
let(:document) { { value: ['ara'] } } | ||
before do | ||
class TestingHelper | ||
include CatalogHelper | ||
include ActionView::Helpers::TagHelper | ||
include ActionView::Helpers::UrlHelper | ||
include ActionView::Context | ||
end | ||
end | ||
after do | ||
Object.send(:remove_const, :TestingHelper) | ||
end | ||
|
||
describe '#render_language_facet' do | ||
it 'maps the code to the language name' do | ||
allow(helper).to receive(:content_tag).with(:span, 'Italian') | ||
helper.render_language_facet('ita') | ||
end | ||
end | ||
|
||
describe '#label_for_code' do | ||
it 'maps the code to the language name' do | ||
expect(helper.label_for_code('eng')).to eq 'English' | ||
end | ||
end | ||
|
||
describe '#label_for_value' do | ||
it 'maps the code to the language name' do | ||
expect(helper.label_for_value(document)).to eq 'Arabic' | ||
end | ||
end | ||
end |
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