diff --git a/app/controllers/catalog_controller.rb b/app/controllers/catalog_controller.rb index 3a6be43f..a9be6c94 100755 --- a/app/controllers/catalog_controller.rb +++ b/app/controllers/catalog_controller.rb @@ -29,7 +29,6 @@ def self.date_created_field end def set_solr_search_fields - blacklight_config.configure do |config| if !current_user.nil? @@ -69,8 +68,6 @@ def set_solr_search_fields end end end - - end end @@ -150,9 +147,8 @@ def set_solr_search_fields config.add_show_field solr_name("fedora3uuid", :stored_searchable), label: "UUID" config.add_sort_field "score desc, #{uploaded_field} desc", label: "Relevance \u25BC" - # TODO: uncomment once a re-index is complete and sortable_title is in Solr - #config.add_sort_field "sortable_title_ssi asc", label: "Title A-Z" - #config.add_sort_field "sortable_title_ssi desc", label: "Title Z-A" + config.add_sort_field "sortable_title_ssi asc", label: "Title A-Z" + config.add_sort_field "sortable_title_ssi desc", label: "Title Z-A" config.add_sort_field "#{date_created_field} desc", label: "Date (newest first)" config.add_sort_field "#{date_created_field} asc", label: "Date (oldest first)" config.add_sort_field "#{uploaded_field} desc", label: "New items" diff --git a/app/controllers/concerns/hydranorth/collections/base_query.rb b/app/controllers/concerns/hydranorth/collections/base_query.rb index 4a2ec159..fe371385 100644 --- a/app/controllers/concerns/hydranorth/collections/base_query.rb +++ b/app/controllers/concerns/hydranorth/collections/base_query.rb @@ -12,13 +12,22 @@ def access_levels { read: [:read, :edit], edit: [:edit] } end - def perform_collection_query(query_string, access_level) + def perform_collection_query(query_string, access_level, sort_order='sortable_title_ssi asc') authenticate_user! unless access_level.blank? + query_elements = {q: query_string} + + # This seems silly, but + # we need to pass the sort order through the search_builder because it does some sort-key demangling, but + # SearchBuilder#query fails to include the sort order in the final query, which I THINK is a bug, so we have to + # put the demangled version back in anyways. + query_elements[:sort] = sort_order if sort_order.present? + + search_builder = collections_search_builder(access_level).with(query_elements) + sort = search_builder.sort + query = search_builder.query + query[:sort] = sort if sort.present? - # run the solr query to find the collections - query = collections_search_builder(access_level).with({q: query_string}).query response = repository.search(query) - # return the user's collections (or public collections if no access_level is applied) response.documents end diff --git a/app/controllers/concerns/hydranorth/communities_controller_behavior.rb b/app/controllers/concerns/hydranorth/communities_controller_behavior.rb index a7a76470..be19b9cf 100644 --- a/app/controllers/concerns/hydranorth/communities_controller_behavior.rb +++ b/app/controllers/concerns/hydranorth/communities_controller_behavior.rb @@ -7,13 +7,6 @@ module CommunitiesControllerBehavior def index @user_communities = find_communities - - # TODO we should move this into the query itself, but that can't happen until after the re-index of communities & - # collections populates sortable_title_ssi - @user_communities.sort! do |a,b| - a.title.downcase <=> b.title.downcase - end - @user_collections, @grouped_user_collections = find_collections_grouped_by_community end diff --git a/app/helpers/generic_file_helper.rb b/app/helpers/generic_file_helper.rb index 43e3469e..86ac503d 100644 --- a/app/helpers/generic_file_helper.rb +++ b/app/helpers/generic_file_helper.rb @@ -10,7 +10,7 @@ def present_terms(presenter, terms=:all, &block) Hydranorth::PresenterRenderer.new(presenter, self).fields(terms, &block) end - def render_download_icon title = nil + def render_download_icon(title = nil) if @generic_file.label.present? || @generic_file.doi_url.present? || !@generic_file.filename.empty? if title.nil? link_to download_image_tag, download_path(@generic_file), { target: '_blank', rel: 'noopener noreferrer', title: "Download the document", id: "file_download", data: { label: @generic_file.id } } @@ -20,10 +20,17 @@ def render_download_icon title = nil end end - def render_download_link text = nil - if @generic_file.label.present? || !@generic_file.filename.empty? - link_to (text || "Download"), download_path(@generic_file), { id: "file_download", target: '_blank', rel: 'noopener noreferrer', data: { label: @generic_file.id } } - end + # if passed a block, this method conditionally renders the markup in the block only if the path is present. This + # provides an easy way of sanely dealing with some items having files (and thus download paths) and others not. + def render_download_link(item, text = nil) + # in Communities, Collections appear in lists alongside files, and so they are rendered through the same partial + # but collections have no download link + path = download_path(item) + return '' unless path.present? + + download_link = link_to (text || 'Download'), path, { id: 'file_download', target: '_blank', rel: 'noopener noreferrer', data: { label: item.id } } + yield download_link if block_given? + return download_link end # sufia.download path is from Sufia::Engine.routes.url_helpers @@ -33,41 +40,36 @@ def render_download_link text = nil # download_path(@generic_file, file: 'webm') # download_path(id: @asset) # download_path document, file: 'thumbnail' + # + # we shouldn't be overloading this to accept everything under the sun (GenericFiles, SolrDocs, Strings, + # Collections...) as it has lead to all manner of bugs and corner cases, but these usages are imposed by Hydra/Sufia, + # so we're forced to live with it. + # + # The precondition here is that if you're calling this, you're only going to get a sensible result on objects that + # actually have files. Not every object does, and there are various valid cases in which an object won't have one + # (Weiwei mentions that both dataverse objects and migrated items from Thesis deposit may not). + # + # Nil is returned for objects without files, to push decisions on how to sanely handle objects with no files up + # to the calling context. You probably want to use render_download_link or a different client function to generate + # the link for you -- it can cleanly not render the surrounding markup at all if this returns nil. def download_path(*args) - if args.first.is_a? String - item = GenericFile.find(args.first) - else - item = args.first - end - return sufia.download_path(*args) unless (item.is_a?(SolrDocument) || item.is_a?(GenericFile)) - return item.doi_url if item.respond_to?(:doi_url) && item.doi_url.present? + raise ArgumentError unless args.present? - # not all doi_urls will be in SolrDocuments until a full reindex happens - if item.is_a?(SolrDocument) && !item.doi_url_indexed? - gf = GenericFile.find(item.id) - return gf.doi_url if gf.doi_url.present? - end - if args[1].nil? - if !item.label.nil? - return "/files/" + item.id + "/" + URI::encode(item.label) - elsif !item.filename.empty? - return "/files/" + item.id + "/" + URI::encode(item.filename.first) - else - # items with no file (which should never happen in production) return nil - end - else - # handle thumbnail requests, in this form: - # /downloads/?file=thumbnail - # args[1] is therefore {:file=>"thumbnail"} - path = "/files/" + item.id + "?" - i = 0 - args[1].each do |key,value| - path = path + "&" if i > 0 - i = i + 1 - path = path + key.to_s + "=" + URI::encode(value) - end - return path + item = item_for_download(args.shift) + return nil unless item.present? && (item.label.present? || item.filename.present? || item.doi_url.present?) + + # doi supercedes anything else + return item.doi_url if item.doi_url.present? + + # otherwise path is /files/noid/(label or filename) + path = "/files/#{item.id}/" + (item.label.nil? ? URI::encode(item.filename.first) : URI::encode(item.label)) + + # appeand query args to download path, eg. /files/noid/label?file=thumbnail or file=mp3, etc + unless args.empty? + path += Hydranorth::RawFedora::stringify_args(args.shift) end + + return path end def render_collection_list(gf) @@ -90,6 +92,21 @@ def display_multiple(value) private + # this could be a string (item ID), a SolrDocument corresponding to the cache of a GenericFile, a fully reified + # GenericFile itself, or a Collection which isn't downloadable but which is rendered through the same partials. ( + # All of these are usages of download_path imposed on us by Sufia, unfortunately, so this can't + # be easily rationalized. Ideally, SolrDocuments are preferable to GenericFiles for performance reasons, so we try + # to minimize reification of IDs whenever possible. + def item_for_download(candidate) + return nil if candidate.is_a?(Collection) + return candidate if candidate.is_a?(SolrDocument) || candidate.is_a?(GenericFile) + + # TODO could we fish this out of Solr and send back a SolrDocument instead? + # it would be much faster + return GenericFile.find(candidate) if candidate.is_a?(String) + raise ArgumentError + end + def download_image_tag(title = nil) if title.nil? image_tag "default.png", { alt: "No preview available", class: "img-responsive" } diff --git a/app/helpers/sufia_helper.rb b/app/helpers/sufia_helper.rb index 467129c0..1d9f61f3 100644 --- a/app/helpers/sufia_helper.rb +++ b/app/helpers/sufia_helper.rb @@ -5,25 +5,21 @@ module SufiaHelper # override SufiaHelperBehavior method for institutional_access? condition def sufia_thumbnail_tag(document, options) - # collection if document.collection? - content_tag(:span, "", class: "glyphicon glyphicon-th collection-icon-search") - - # file + content_tag(:span, '', class: "glyphicon glyphicon-th collection-icon-search") else path = if cannot?(:download, document) - "default.png" + 'default.png' elsif document.image? || document.pdf? || document.video? || document.office_document? - sufia.download_path document, file: 'thumbnail' + download_path(document, file: 'thumbnail') elsif document.audio? - "audio.png" + 'audio.png' else - "default.png" + 'default.png' end - options[:alt] = "" - image_tag path, options + options[:alt] = '' + image_tag(path, options) end - end - + end end diff --git a/app/models/concerns/hydranorth/generic_file/export.rb b/app/models/concerns/hydranorth/generic_file/export.rb index 4c92aba9..469c327e 100755 --- a/app/models/concerns/hydranorth/generic_file/export.rb +++ b/app/models/concerns/hydranorth/generic_file/export.rb @@ -1,4 +1,4 @@ -module Hydranorth +module Hydranorth module GenericFile module Export @@ -19,30 +19,31 @@ def export_as_openurl_ctx_kev license: 'license' , rights: 'rights' } - Rails.logger.debug "field_map #{field_map}" + # this is making the rails dev console VERY noisy, so I'm disabling it for now + # Rails.logger.debug "field_map #{field_map}" field_map.each do |element, kev| - Rails.logger.debug "self #{self.inspect}" - Rails.logger.debug "self.title #{self.title.inspect}" - Rails.logger.debug "self.creator #{self.creator}" - Rails.logger.debug "self.subject #{self.subject}" - Rails.logger.debug "self.description #{self.description}" - Rails.logger.debug "self.publisher #{self.publisher}" - Rails.logger.debug "self.date_create #{self.date_created}" - Rails.logger.debug "self.resource_type #{self.resource_type}" - Rails.logger.debug "self.language #{self.language}" - Rails.logger.debug "self.license #{self.license}" - Rails.logger.debug "self.rights #{self.rights}" - Rails.logger.debug "self.contributor #{self.contributor.inspect}" + # Rails.logger.debug "self #{self.inspect}" + # Rails.logger.debug "self.title #{self.title.inspect}" + # Rails.logger.debug "self.creator #{self.creator}" + # Rails.logger.debug "self.subject #{self.subject}" + # Rails.logger.debug "self.description #{self.description}" + # Rails.logger.debug "self.publisher #{self.publisher}" + # Rails.logger.debug "self.date_create #{self.date_created}" + # Rails.logger.debug "self.resource_type #{self.resource_type}" + # Rails.logger.debug "self.language #{self.language}" + # Rails.logger.debug "self.license #{self.license}" + # Rails.logger.debug "self.rights #{self.rights}" + # Rails.logger.debug "self.contributor #{self.contributor.inspect}" values = self.send(element) - Rails.logger.debug "values #{values}" + # Rails.logger.debug "values #{values}" next if values.nil? || values.first.nil? || values.empty? if values.respond_to?(:each) values.each do |value| export_text << "rft.#{kev}=#{CGI::escape(value.to_s)}" end - else - + else + export_text << "rft.#{kev}=#{CGI::escape(values.to_s)}" end diff --git a/app/models/concerns/hydranorth/solr_document_behavior.rb b/app/models/concerns/hydranorth/solr_document_behavior.rb index 8e4100ee..12cfe845 100644 --- a/app/models/concerns/hydranorth/solr_document_behavior.rb +++ b/app/models/concerns/hydranorth/solr_document_behavior.rb @@ -24,6 +24,25 @@ def dissertant Array(self[Solrizer.solr_name('dissertant')]).first end + def filename + return Array(self[Solrizer.solr_name('filename')]) if self.has_key?(Solrizer.solr_name('filename')) + + # we can try to fish it out of the object profile, but this is kind of a hack + # if it doesn't work, we just return a link to the show page. This should be less + # necessary after the re-index + begin + # cache this, as it can get called repeatedly on the same object and + # parsing JSON is relatively expensive (though cheaper than a trip to Fedora) + @json ||= JSON.parse(self['object_profile_ssm'].first) + return @json['filename'] if @json.has_key?('filename') && @json['filename'].present? + rescue + # this would be a good place for hoptoad/airbrake/newrelic-style alerting + # this should indicate either a corrupted object cache in Solr or an object + # without an attached file. We return nil and deal with this in the caller + return nil + end + end + def doi_url doi = self[Solrizer.solr_name('doi_url')] return doi.first if doi.present? && !doi.first.nil? && doi.first != 'false' diff --git a/app/models/concerns/sufia/generic_file/characterization.rb b/app/models/concerns/sufia/generic_file/characterization.rb new file mode 100644 index 00000000..b1597d91 --- /dev/null +++ b/app/models/concerns/sufia/generic_file/characterization.rb @@ -0,0 +1,120 @@ +module Sufia + module GenericFile + module Characterization + extend ActiveSupport::Concern + included do + contains "characterization", class_name: 'FitsDatastream' + property :mime_type, delegate_to: 'characterization', multiple: false do |index| + index.as :stored_searchable + end + property :format_label, delegate_to: 'characterization' + property :file_size, delegate_to: 'characterization' + property :last_modified, delegate_to: 'characterization' + property :filename, delegate_to: 'characterization' do |index| + index.as :stored_searchable + end + property :original_checksum, delegate_to: 'characterization' + property :rights_basis, delegate_to: 'characterization' + property :copyright_basis, delegate_to: 'characterization' + property :copyright_note, delegate_to: 'characterization' + property :well_formed, delegate_to: 'characterization' + property :valid, delegate_to: 'characterization' + property :status_message, delegate_to: 'characterization' + property :file_title, delegate_to: 'characterization' + property :file_author, delegate_to: 'characterization' + property :page_count, delegate_to: 'characterization' + property :file_language, delegate_to: 'characterization' + property :word_count, delegate_to: 'characterization' + property :character_count, delegate_to: 'characterization' + property :paragraph_count, delegate_to: 'characterization' + property :line_count, delegate_to: 'characterization' + property :table_count, delegate_to: 'characterization' + property :graphics_count, delegate_to: 'characterization' + property :byte_order, delegate_to: 'characterization' + property :compression, delegate_to: 'characterization' + property :color_space, delegate_to: 'characterization' + property :profile_name, delegate_to: 'characterization' + property :profile_version, delegate_to: 'characterization' + property :orientation, delegate_to: 'characterization' + property :color_map, delegate_to: 'characterization' + property :image_producer, delegate_to: 'characterization' + property :capture_device, delegate_to: 'characterization' + property :scanning_software, delegate_to: 'characterization' + property :exif_version, delegate_to: 'characterization' + property :gps_timestamp, delegate_to: 'characterization' + property :latitude, delegate_to: 'characterization' + property :longitude, delegate_to: 'characterization' + property :character_set, delegate_to: 'characterization' + property :markup_basis, delegate_to: 'characterization' + property :markup_language, delegate_to: 'characterization' + property :bit_depth, delegate_to: 'characterization' + property :channels, delegate_to: 'characterization' + property :data_format, delegate_to: 'characterization' + property :offset, delegate_to: 'characterization' + property :frame_rate, delegate_to: 'characterization' + + end + + def width + characterization.width.blank? ? characterization.video_width : characterization.width + end + + def height + characterization.height.blank? ? characterization.video_height : characterization.height + end + + def duration + characterization.duration.blank? ? characterization.video_duration : characterization.duration + end + + def sample_rate + characterization.sample_rate.blank? ? characterization.video_sample_rate : characterization.sample_rate + end + + ## Extract the metadata from the content datastream and record it in the characterization datastream + def characterize + metadata = content.extract_metadata + characterization.ng_xml = metadata if metadata.present? + append_metadata + self.filename = [content.original_name] + save + end + + # Populate GenericFile's properties with fields from FITS (e.g. Author from pdfs) + def append_metadata + terms = self.characterization_terms + Sufia.config.fits_to_desc_mapping.each_pair do |k, v| + if terms.has_key?(k) + # coerce to array to remove a conditional + terms[k] = [terms[k]] unless terms[k].is_a? Array + terms[k].each do |term_value| + proxy_term = self.send(v) + if proxy_term.kind_of?(Array) + proxy_term << term_value unless proxy_term.include?(term_value) + else + # these are single-valued terms which cannot be appended to + self.send("#{v}=", term_value) + end + end + end + end + end + + def characterization_terms + h = {} + FitsDatastream.terminology.terms.each_pair do |k, v| + next unless v.respond_to? :proxied_term + term = v.proxied_term + begin + value = self.send(term.name) + h[term.name] = value unless value.empty? + rescue NoMethodError + next + end + end + h + end + + end + end +end diff --git a/app/models/concerns/sufia/generic_file/metadata.rb b/app/models/concerns/sufia/generic_file/metadata.rb index 5e737946..04cb8026 100644 --- a/app/models/concerns/sufia/generic_file/metadata.rb +++ b/app/models/concerns/sufia/generic_file/metadata.rb @@ -66,7 +66,7 @@ module Metadata property :source, predicate: ::RDF::DC.source, multiple: false do |index| index.as :stored_searchable end - + end end diff --git a/app/views/collections/_show_document_list_menu.html.erb b/app/views/collections/_show_document_list_menu.html.erb index bfa3bea8..f0ad89dd 100755 --- a/app/views/collections/_show_document_list_menu.html.erb +++ b/app/views/collections/_show_document_list_menu.html.erb @@ -17,10 +17,11 @@ <%= link_to raw(' Single-Use Link to File'), '#', class: "copypaste itemicon itemcode", title: "Single-Use Link to File", id: "copy_link_#{id}" %> -
  • - <%= link_to raw(' Download File'), sufia.download_path(id), - class: 'itemicon itemdownload', title: 'Download File', target: '_blank', rel: 'noopener noreferrer' %> -
  • + <% render_download_link(gf, raw(' Download File')) do |download_link| %> +
  • + <%= download_link %> +
  • + <% end %> <% if current_user %>
  • <%= display_trophy_link(current_user, id) do |text| %> diff --git a/app/views/generic_files/_generic_file.html.erb b/app/views/generic_files/_generic_file.html.erb index 8167a30a..47bedee7 100644 --- a/app/views/generic_files/_generic_file.html.erb +++ b/app/views/generic_files/_generic_file.html.erb @@ -1,6 +1,9 @@
  • <%= link_to generic_file.title_or_label, sufia.generic_file_path(generic_file) %> + <% render_download_link(generic_file) do |download_link| %> + [<%= download_link %>] + <% end %>

    diff --git a/app/views/generic_files/_media_display.html.erb b/app/views/generic_files/_media_display.html.erb new file mode 100644 index 00000000..c990b048 --- /dev/null +++ b/app/views/generic_files/_media_display.html.erb @@ -0,0 +1,33 @@ +<% if @generic_file.image? %> + + <%= render_download_icon "Download the full-sized image" %> + +<% elsif @generic_file.video? %> + + + +<% elsif @generic_file.audio? %> + + + +<% elsif @generic_file.pdf? %> + + <%= render_download_icon "Download the full-sized PDF" %> + +<% elsif @generic_file.office_document? %> + + <%= render_download_icon "Download the full-sized Document" %> + +<% else %> + + <%= render_download_icon %> + +<% end %> diff --git a/app/views/generic_files/_show_actions.html.erb b/app/views/generic_files/_show_actions.html.erb index 4c2f250c..4bff8eb8 100644 --- a/app/views/generic_files/_show_actions.html.erb +++ b/app/views/generic_files/_show_actions.html.erb @@ -1,7 +1,7 @@

    Actions

    - <%= render_download_link %> + <%= render_download_link(@generic_file) %> <% if Sufia.config.analytics %>  |  <%= link_to "Analytics", sufia.stats_generic_file_path(@generic_file), id: 'stats' %> diff --git a/app/views/my/_action_menu.html.erb b/app/views/my/_action_menu.html.erb index e2333582..26550558 100755 --- a/app/views/my/_action_menu.html.erb +++ b/app/views/my/_action_menu.html.erb @@ -15,10 +15,11 @@ class: 'itemicon itemedit', title: 'Edit File' %>

  • <% end %> -
  • - <%= link_to raw(' Download File'), download_path(gf), - class: 'itemicon itemdownload', title: 'Download File', target: '_blank', rel: 'noopener noreferrer' %> -
  • + <% render_download_link(gf, raw(' Download File')) do |download_link| %> +
  • + <%= download_link %> +
  • + <% end %>
  • <% if current_user.admin? %> <%= link_to raw(' Delete File'), sufia.generic_file_path(id), diff --git a/config/routes.rb b/config/routes.rb index 151770f5..1dd4c938 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,15 +1,8 @@ Hydranorth::Application.routes.draw do - - class WantsThumbnailConstraint - def self.matches?(request) - request.query_parameters['file'] == 'thumbnail' - end - end - get 'recent/index' namespace :admin do - get 'become/index' + get 'become/index' end blacklight_for :catalog @@ -104,8 +97,8 @@ def self.matches?(request) get 'collections/:id/:per_page', controller: 'collections', action: :show get 'collections/:id/edit', controller: 'collections', action: :edit get 'recent', controller: 'recent', action: :index - get 'files/:id/*file' => 'downloads#show', format: false - get 'files/:id' => 'downloads#show', constraints: WantsThumbnailConstraint + + get 'files/:id/*file' => 'downloads#show' # This must be the very last route in the file because it has a catch-all route for 404 errors. # This behavior seems to show up only in production mode. diff --git a/lib/hydranorth/raw_fedora.rb b/lib/hydranorth/raw_fedora.rb index b8823a95..bf8cb063 100644 --- a/lib/hydranorth/raw_fedora.rb +++ b/lib/hydranorth/raw_fedora.rb @@ -30,7 +30,7 @@ def to_pair_tree(id) def stringify_args(arg_hash) accumulator = [] - arg_hash.each { |k, v| accumulator << k.to_s + '=' + v.to_s } + arg_hash.each { |k, v| accumulator << k.to_s + '=' + URI::encode(v.to_s) } '?' << accumulator.join('&') end diff --git a/spec/features/collection/collection_spec.rb b/spec/features/collection/collection_spec.rb index 792edce9..8a926b0c 100755 --- a/spec/features/collection/collection_spec.rb +++ b/spec/features/collection/collection_spec.rb @@ -74,6 +74,7 @@ expect(page).to have_selector(:css, "div#community-logo") expect(page).to have_content('Collections and items in this Community') expect(page).to_not have_css("input#collection_search") + within("#facets") do within("#facet-resource_type_sim") do expect(page).to have_content("Book") @@ -363,11 +364,7 @@ expect(page).to have_content(generic_file.title.first) expect(page).to have_content("Test Item") - # this is now pending the work to reindex DOIs into Solr - # and Rspec 3 doesn't let you mark individual expectations as pending - # because ¯\_(ツ)_/¯ - #expect(page).to have_content("Download") - + click_link ('Test Item') expect(page).not_to have_content("Edit") expect(page).not_to have_content("Delete") diff --git a/spec/features/doi_spec.rb b/spec/features/doi_spec.rb index b36fb734..e50adfb2 100644 --- a/spec/features/doi_spec.rb +++ b/spec/features/doi_spec.rb @@ -27,7 +27,6 @@ expect(page).to have_link('file_download', {href: 'http://dx.doi.org'}) end it 'should be DOI on result page' do - pending 'pending doi_link inclusion in Solr index' visit '/' search gf_with_doi.subject.first expect(page).to have_link('Download', {href: 'http://dx.doi.org'}) @@ -57,7 +56,6 @@ expect(page).to have_xpath("//a[contains(@href, '#{download_path(gf_no_identifier)}')]", count: 2) end it 'should be download on result page' do - pending 'pending doi_link inclusion in Solr index' visit '/' search gf_no_identifier.subject.first expect(page).to have_xpath("//a[contains(@href, '#{download_path(gf_no_identifier)}')]", count: 1) diff --git a/spec/helpers/sufia_helper_spec.rb b/spec/helpers/sufia_helper_spec.rb index 5fafd7a7..a72dd1cf 100644 --- a/spec/helpers/sufia_helper_spec.rb +++ b/spec/helpers/sufia_helper_spec.rb @@ -3,10 +3,10 @@ describe SufiaHelper, type: :helper do describe "sufia_thumbnail_tag" do context "for an image object" do - let(:document) { SolrDocument.new(mime_type_tesim: 'image/jpeg', read_access_group_ssim: ["public"], id: '1234') } + let(:document) { SolrDocument.new(mime_type_tesim: 'image/jpeg', read_access_group_ssim: ["public"], id: '1234', label_tesim: 'foo') } it "shows the audio thumbnail" do rendered = helper.sufia_thumbnail_tag(document, width: 90) - expect(rendered).to match(/src="\/downloads\/1234\?file=thumbnail"/) + expect(rendered).to match(/src="\/files\/1234\/foo\?file=thumbnail"/) expect(rendered).to match(/width="90"/) end end @@ -18,15 +18,15 @@ end end context "for an document object" do - let(:document) { SolrDocument.new(mime_type_tesim: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', read_access_group_ssim: ["public"], id: '1234') } + let(:document) { SolrDocument.new(label_tesim: 'foo', mime_type_tesim: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', read_access_group_ssim: ["public"], id: '1234') } it "shows the document's thumbnail" do rendered = helper.sufia_thumbnail_tag(document, width: 90) - expect(rendered).to match(/src="\/downloads\/1234\?file=thumbnail"/) + expect(rendered).to match(/src="\/files\/1234\/foo\?file=thumbnail"/) expect(rendered).to match(/width="90"/) end end context "for an institutionally restricted object" do - let(:document) { SolrDocument.new(mime_type_tesim: 'image/jpeg', read_access_group_ssim: ["public","university_of_alberta"], id: '1234') } + let(:document) { SolrDocument.new(label_tesim: 'foo', mime_type_tesim: 'image/jpeg', read_access_group_ssim: ["public","university_of_alberta"], id: '1234') } it "shows the default thumbnail" do rendered = helper.sufia_thumbnail_tag(document, {}) expect(rendered).to match(/src="\/assets\/default-.*.png"/) @@ -35,9 +35,9 @@ let(:user) { FactoryGirl.find_or_create(:ccid) } it 'shows the real thumbnail' do allow_any_instance_of(User).to receive(:institutionally_authenticated?).and_return true - allow_any_instance_of(User).to receive(:authenticating_institution).and_return Hydranorth::AccessControls::InstitutionalVisibility::UNIVERSITY_OF_ALBERTA + allow_any_instance_of(User).to receive(:authenticating_institution).and_return Hydranorth::AccessControls::InstitutionalVisibility::UNIVERSITY_OF_ALBERTA rendered = helper.sufia_thumbnail_tag(document, width: 90) - expect(rendered).to match(/src="\/downloads\/1234\?file=thumbnail"/) + expect(rendered).to match(/src="\/files\/1234\/foo\?file=thumbnail"/) expect(rendered).to match(/width="90"/) end end