Skip to content

Commit

Permalink
Merge pull request #515 from pulibrary/dpul_collection_links
Browse files Browse the repository at this point in the history
Collections in show view links to collections.
  • Loading branch information
escowles committed Feb 19, 2019
2 parents e983253 + cb3ae0d commit d34aa21
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
8 changes: 8 additions & 0 deletions app/presenters/rtl_show_presenter.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class RTLShowPresenter < ::Blacklight::ShowPresenter
include ActionView::Helpers::TagHelper
include ActionView::Helpers::UrlHelper
include ActionView::Context

def field_value_separator
Expand All @@ -16,6 +17,7 @@ def field_value_separator
# @options opts [String] :value
def field_value(field, options = {})
tags = super.split(field_value_separator).collect do |value|
value = collection_value(value) if field.to_s.include?("readonly_collections_ssim")
content_tag(:li, value.html_safe, dir: value.dir)
end

Expand All @@ -24,6 +26,12 @@ def field_value(field, options = {})
end
end

def collection_value(value)
collection = Spotlight::Exhibit.where(title: value).first
return value unless collection
link_to collection.title, view_context.exhibit_root_path(collection)
end

def header
fields = Array.wrap(title_field)
f = fields.detect { |field| @document.has? field }
Expand Down
1 change: 1 addition & 0 deletions spec/factories/exhibits.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FactoryBot.define do
factory :exhibit, class: Spotlight::Exhibit do
sequence(:title) { |n| "Exhibit Title #{n}" }
sequence(:slug) { |n| "slug-#{n}" }
published true
end
end
2 changes: 1 addition & 1 deletion spec/features/catalog_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@

scenario 'user browses all collections' do
visit spotlight.search_exhibit_catalog_path(exhibit, search_field: 'all_fields', q: '')
expect(page).to have_link 'Home', href: '/exhibit-a'
expect(page).to have_link 'Home', href: "/#{exhibit.slug}"
expect(page).to have_css '#documents .document h3.index_title', text: id
end
end
Expand Down
13 changes: 11 additions & 2 deletions spec/presenters/rtl_show_presenter_spec.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
require 'rails_helper'

RSpec.describe RTLShowPresenter do
subject(:presenter) { described_class.new(document, double(blacklight_config: blacklight_config)) }
subject(:presenter) { described_class.new(document, view_context) }

let(:document) do
SolrDocument.new(
field: ["بي"],
special: ["Traité sur l'art de la charpente : théorique et pratique"],
title: ["بي", "Traité sur l'art de la charpente : théorique et pratique"]
title: ["بي", "Traité sur l'art de la charpente : théorique et pratique"],
readonly_collections_ssim: [exhibit.title.to_s]
)
end
let(:view_context) { double(blacklight_config: blacklight_config) }
let(:exhibit) { FactoryBot.create(:exhibit) }
let(:cc_config) { CatalogController.new.blacklight_config }
let(:blacklight_config) do
double(
Expand All @@ -31,6 +34,12 @@
expect(presenter.field_value(:special)).to eq "<ul><li dir=\"ltr\">Traité sur l'art de la charpente : théorique et pratique</li></ul>"
end
end
context "when given a collection field" do
it "renders links to each collection" do
allow(view_context).to receive(:exhibit_root_path).with(exhibit).and_return("/#{exhibit.slug}")
expect(presenter.field_value(:readonly_collections_ssim)).to eq "<ul><li dir=\"ltr\"><a href=\"/#{exhibit.slug}\">#{exhibit.title}</a></li></ul>"
end
end
end

describe "#heading" do
Expand Down

0 comments on commit d34aa21

Please sign in to comment.