diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 6a7dc83f..eb6aae6a 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -32,6 +32,7 @@ RSpec/MultipleExpectations: # Configuration parameters: MaxNesting. RSpec/NestedGroups: Exclude: + - 'spec/helpers/index_helper_spec.rb' - 'spec/models/iiif_resource_spec.rb' # Offense count: 2 diff --git a/app/helpers/index_helper.rb b/app/helpers/index_helper.rb index a707874c..c65a2e1e 100644 --- a/app/helpers/index_helper.rb +++ b/app/helpers/index_helper.rb @@ -2,9 +2,9 @@ module IndexHelper def render_index_document(document) field = index_presenter(document).label(document_show_link_field(document)) span = [] - if field.length == 1 || !field.is_a?(Array) + if !field.is_a?(Array) span << content_tag(:span, style: 'display: block;', dir: field.dir) do - link_to_document(document, document_show_link_field(document)) + link_to(field, url_for_document(document), document_link_params(document, {})) end else field.each do |value| diff --git a/spec/helpers/index_helper_spec.rb b/spec/helpers/index_helper_spec.rb new file mode 100644 index 00000000..2544b932 --- /dev/null +++ b/spec/helpers/index_helper_spec.rb @@ -0,0 +1,61 @@ +require 'rails_helper' + +describe IndexHelper do + let(:helper) { TestingHelper.new } + let(:index_presenter) { instance_double('RTLIndexPresenter', class: RTLIndexPresenter) } + let(:document) do + { + title: 'title', + alternate_title: 'alternate_title' + } + end + before do + class TestingHelper + include IndexHelper + include ActionView::Helpers::TagHelper + include ActionView::Helpers::UrlHelper + include ActionView::Context + end + end + after do + Object.send(:remove_const, :TestingHelper) + end + + describe '#render_index_document' do + before do + allow(helper).to receive(:index_presenter).and_return(index_presenter) + allow(helper).to receive(:document_show_link_field).and_return(:title) + allow(helper).to receive(:url_for_document).and_return('link') + allow(helper).to receive(:document_link_params).and_return({}) + allow(index_presenter).to receive(:label).and_return(label) + end + + context 'when given a ltr label' do + let(:label) { 'title' } + + it 'returns a single ltr span tag' do + tag = helper.render_index_document(document) + expect(tag).to eq 'title' + end + end + + context 'when given a rtl label' do + let(:label) { 'تضيح المقال' } + + it 'returns a single rtl span tag' do + tag = helper.render_index_document(document) + expect(tag).to eq 'تضيح المقال' + end + end + + context 'when given a multivalued title' do + let(:label) { ['تضيح المقال', 'title'] } + + it 'returns span tags' do + tag = helper.render_index_document(document) + expect(tag).to eq 'تضيح المقال'\ + 'title' + end + end + end +end