diff --git a/CHANGELOG.md b/CHANGELOG.md index e67a21111..1cda750fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,21 @@ # changelog +## [2021.3] - 2021-02-05 + +### enhancements ๐Ÿ”ง +- adds a locale for custom language labels (`"iso_639_1.<2 letter code>"`) (#693) +- creates a `Spot::WorksControllerBehavior` mixin for common mixins/behavior (#694) + - adds .csv handling to `Hyrax::ImagesController`, which was causing a bunch of honeybadger reports +- add "Center for the Integration of Teaching, Learning, and Scholarship" academic department option (#695) + +### dependencies ๐Ÿ‘ฉโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ง +- capistrano to 3.15.0 (#687) +- nokogiri locked at `~> "1.10.10"` until we can upgrade ruby (#688) +- okcomputer to 1.18.2 (#685) +- rails to 5.2.4.4 (#686) +- rspec-rails to 4.0.1 (#684) + + ## [2021.2] - 2021-01-21 ### bug fixes ๐Ÿž @@ -560,6 +576,7 @@ fixes: Initial pre-release (live on ldr.stage.lafayette.edu) +[2021.3]: https://github.com/LafayetteCollegeLibraries/spot/releases/tag/2021.3 [2021.2]: https://github.com/LafayetteCollegeLibraries/spot/releases/tag/2021.2 [2021.1]: https://github.com/LafayetteCollegeLibraries/spot/releases/tag/2021.1 [2020.13]: https://github.com/LafayetteCollegeLibraries/spot/releases/tag/2020.13 diff --git a/Gemfile b/Gemfile index 94b02a3f2..f238dd401 100644 --- a/Gemfile +++ b/Gemfile @@ -79,7 +79,7 @@ gem 'iso-639', '0.3.5' gem 'jquery-rails', '4.4.0' # system monitoring -gem 'okcomputer', '1.18.1' +gem 'okcomputer', '1.18.2' # we're using postgres as our database within rails gem 'pg', '1.2.3' @@ -125,12 +125,13 @@ gem 'mini_magick', '4.10.1' # manually add this gem to enable questioning_authority to parse linked-data results gem 'linkeddata', '~> 3.0' -# hydra-role-management requires bootstrap_form without declaring a version, -# bootstrap_form >=4.5.0 requires a ruby version >= 2.5 (we're stuck on 2.4.3 -# until we migrate to aws). # -# @todo remove this restriction after aws migration +# these are gems that we need to lock until we can upgrade ruby to >= 2.5 +# (on-prem is locked at 2.4.3). +# +# @todo remove these restriction after aws migration gem 'bootstrap_form', '~> 4.4.0' +gem 'nokogiri', '~> 1.10.10' # development dependencies (not as necessary to # lock down versions here) @@ -143,7 +144,7 @@ group :development do gem 'spring-watcher-listen', '~> 2.0.0' # Use Capistrano for deployment - gem 'capistrano', '~> 3.14', require: false + gem 'capistrano', '~> 3.15', require: false gem 'capistrano-bundler', '~> 1.3' gem 'capistrano-ext', '~> 1.2.1' gem 'capistrano-passenger', '~> 0.2.0' @@ -166,7 +167,7 @@ group :development, :test do gem 'rails-controller-testing', '~> 1.0.5' gem 'rspec', '~> 3.8' gem 'rspec-its', '~> 1.1' - gem 'rspec-rails', '~> 3.6' + gem 'rspec-rails', '~> 4.0' gem 'rspec_junit_formatter', '~> 0.4.1' gem 'rubocop', '~> 0.63' gem 'rubocop-rspec', '~> 1.3' diff --git a/Gemfile.lock b/Gemfile.lock index 20f4903be..082e404a9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,25 +1,25 @@ GEM remote: https://rubygems.org/ specs: - actioncable (5.2.4.3) - actionpack (= 5.2.4.3) + actioncable (5.2.4.4) + actionpack (= 5.2.4.4) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailer (5.2.4.3) - actionpack (= 5.2.4.3) - actionview (= 5.2.4.3) - activejob (= 5.2.4.3) + actionmailer (5.2.4.4) + actionpack (= 5.2.4.4) + actionview (= 5.2.4.4) + activejob (= 5.2.4.4) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (5.2.4.3) - actionview (= 5.2.4.3) - activesupport (= 5.2.4.3) + actionpack (5.2.4.4) + actionview (= 5.2.4.4) + activesupport (= 5.2.4.4) rack (~> 2.0, >= 2.0.8) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.2.4.3) - activesupport (= 5.2.4.3) + actionview (5.2.4.4) + activesupport (= 5.2.4.4) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) @@ -43,26 +43,26 @@ GEM active_encode (0.7.0) rails sprockets (< 4) - activejob (5.2.4.3) - activesupport (= 5.2.4.3) + activejob (5.2.4.4) + activesupport (= 5.2.4.4) globalid (>= 0.3.6) - activemodel (5.2.4.3) - activesupport (= 5.2.4.3) + activemodel (5.2.4.4) + activesupport (= 5.2.4.4) activemodel-serializers-xml (1.0.2) activemodel (> 5.x) activesupport (> 5.x) builder (~> 3.1) - activerecord (5.2.4.3) - activemodel (= 5.2.4.3) - activesupport (= 5.2.4.3) + activerecord (5.2.4.4) + activemodel (= 5.2.4.4) + activesupport (= 5.2.4.4) arel (>= 9.0) activerecord-import (1.0.5) activerecord (>= 3.2) - activestorage (5.2.4.3) - actionpack (= 5.2.4.3) - activerecord (= 5.2.4.3) + activestorage (5.2.4.4) + actionpack (= 5.2.4.4) + activerecord (= 5.2.4.4) marcel (~> 0.3.1) - activesupport (5.2.4.3) + activesupport (5.2.4.4) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 0.7, < 2) minitest (~> 5.1) @@ -165,7 +165,7 @@ GEM builder (3.2.4) byebug (11.1.1) cancancan (1.17.0) - capistrano (3.14.1) + capistrano (3.15.0) airbrussh (>= 1.0.0) i18n rake (>= 10.0.0) @@ -206,7 +206,7 @@ GEM coffee-script-source execjs coffee-script-source (1.12.2) - concurrent-ruby (1.1.7) + concurrent-ruby (1.1.8) connection_pool (2.2.3) crack (0.4.3) safe_yaml (~> 1.0.0) @@ -229,7 +229,7 @@ GEM devise_cas_authenticatable (1.10.4) devise (>= 1.2.0) rubycas-client (>= 2.2.1) - diff-lcs (1.3) + diff-lcs (1.4.4) docile (1.3.2) docopt (0.5.0) dotenv (2.7.5) @@ -479,7 +479,7 @@ GEM tinymce-rails (~> 4.1) hyrax-spec (0.3.2) rspec (~> 3.6) - i18n (1.8.5) + i18n (1.8.7) concurrent-ruby (~> 1.0) ice_nine (0.11.2) iiif_manifest (0.5.0) @@ -579,7 +579,7 @@ GEM listen (3.2.1) rb-fsevent (~> 0.10, >= 0.10.3) rb-inotify (~> 0.9, >= 0.9.10) - loofah (2.8.0) + loofah (2.9.0) crass (~> 1.0.2) nokogiri (>= 1.5.9) mail (2.7.1) @@ -598,7 +598,7 @@ GEM mini_magick (4.10.1) mini_mime (1.0.2) mini_portile2 (2.4.0) - minitest (5.14.2) + minitest (5.14.3) msgpack (1.3.3) multi_json (1.15.0) multi_xml (0.6.0) @@ -630,7 +630,7 @@ GEM multi_json (~> 1.3) multi_xml (~> 0.5) rack (>= 1.2, < 3) - okcomputer (1.18.1) + okcomputer (1.18.2) openseadragon (0.5.0) rails (> 3.2.0) orm_adapter (0.5.0) @@ -659,18 +659,18 @@ GEM rack rack-test (1.1.0) rack (>= 1.0, < 3) - rails (5.2.4.3) - actioncable (= 5.2.4.3) - actionmailer (= 5.2.4.3) - actionpack (= 5.2.4.3) - actionview (= 5.2.4.3) - activejob (= 5.2.4.3) - activemodel (= 5.2.4.3) - activerecord (= 5.2.4.3) - activestorage (= 5.2.4.3) - activesupport (= 5.2.4.3) + rails (5.2.4.4) + actioncable (= 5.2.4.4) + actionmailer (= 5.2.4.4) + actionpack (= 5.2.4.4) + actionview (= 5.2.4.4) + activejob (= 5.2.4.4) + activemodel (= 5.2.4.4) + activerecord (= 5.2.4.4) + activestorage (= 5.2.4.4) + activesupport (= 5.2.4.4) bundler (>= 1.3.0) - railties (= 5.2.4.3) + railties (= 5.2.4.4) sprockets-rails (>= 2.0.0) rails-controller-testing (1.0.5) actionpack (>= 5.0.1.rc1) @@ -683,9 +683,9 @@ GEM loofah (~> 2.3) rails_autolink (1.1.6) rails (> 3.1) - railties (5.2.4.3) - actionpack (= 5.2.4.3) - activesupport (= 5.2.4.3) + railties (5.2.4.4) + actionpack (= 5.2.4.4) + activesupport (= 5.2.4.4) method_source rake (>= 0.8.7) thor (>= 0.19.0, < 2.0) @@ -774,26 +774,26 @@ GEM rspec-core (~> 3.9.0) rspec-expectations (~> 3.9.0) rspec-mocks (~> 3.9.0) - rspec-core (3.9.0) - rspec-support (~> 3.9.0) - rspec-expectations (3.9.0) + rspec-core (3.9.3) + rspec-support (~> 3.9.3) + rspec-expectations (3.9.4) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.9.0) rspec-its (1.3.0) rspec-core (>= 3.0.0) rspec-expectations (>= 3.0.0) - rspec-mocks (3.9.0) + rspec-mocks (3.9.1) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.9.0) - rspec-rails (3.9.0) - actionpack (>= 3.0) - activesupport (>= 3.0) - railties (>= 3.0) - rspec-core (~> 3.9.0) - rspec-expectations (~> 3.9.0) - rspec-mocks (~> 3.9.0) - rspec-support (~> 3.9.0) - rspec-support (3.9.0) + rspec-rails (4.0.1) + actionpack (>= 4.2) + activesupport (>= 4.2) + railties (>= 4.2) + rspec-core (~> 3.9) + rspec-expectations (~> 3.9) + rspec-mocks (~> 3.9) + rspec-support (~> 3.9) + rspec-support (3.9.4) rspec_junit_formatter (0.4.1) rspec-core (>= 2, < 4, != 2.12.0) rubocop (0.63.1) @@ -911,7 +911,7 @@ GEM actionpack (>= 4.0) activesupport (>= 4.0) sprockets (>= 3.0.0) - sshkit (1.21.1) + sshkit (1.21.2) net-scp (>= 1.1.2) net-ssh (>= 2.8.0) stub_env (1.0.4) @@ -975,7 +975,7 @@ DEPENDENCIES bootsnap (= 1.4.7) bootstrap_form (~> 4.4.0) byebug - capistrano (~> 3.14) + capistrano (~> 3.15) capistrano-bundler (~> 1.3) capistrano-ext (~> 1.2.1) capistrano-passenger (~> 0.2.0) @@ -1007,7 +1007,8 @@ DEPENDENCIES linkeddata (~> 3.0) listen (>= 3.0.5, < 3.3) mini_magick (= 4.10.1) - okcomputer (= 1.18.1) + nokogiri (~> 1.10.10) + okcomputer (= 1.18.2) pg (= 1.2.3) puma (= 3.12.6) rails (~> 5.2) @@ -1016,7 +1017,7 @@ DEPENDENCIES rsolr (= 2.3.0) rspec (~> 3.8) rspec-its (~> 1.1) - rspec-rails (~> 3.6) + rspec-rails (~> 4.0) rspec_junit_formatter (~> 0.4.1) rubocop (~> 0.63) rubocop-rspec (~> 1.3) diff --git a/app/authorities/qa/authorities/language.rb b/app/authorities/qa/authorities/language.rb index 2c8946a8c..3de562bee 100644 --- a/app/authorities/qa/authorities/language.rb +++ b/app/authorities/qa/authorities/language.rb @@ -11,7 +11,7 @@ class Language < Qa::Authorities::Base # # @return [Array String>>] def all - Spot::ISO6391.all.map { |key, val| wrap(id: key, label: val) } + Spot::ISO6391.all.map { |key, val| wrap(id: key, label: val) }.compact end # @param [String] id @@ -38,7 +38,7 @@ def search(query) # @param [String] label # @return [Hash String>] def wrap(id:, label:) - return if id.nil? || label.nil? + return if id == label { id: id, label: label, value: id } end diff --git a/app/controllers/concerns/spot/configurable_iiif_manifest_presenter.rb b/app/controllers/concerns/spot/configurable_iiif_manifest_presenter.rb deleted file mode 100644 index 1f27c1f2f..000000000 --- a/app/controllers/concerns/spot/configurable_iiif_manifest_presenter.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true -module Spot - # abstracts out a +:iiif_manifest_presenter_klass+ attribute to override the Hyrax one. - # in our case, we want to change how the metadata is rendered. - # - # @see https://github.com/samvera/hyrax/blob/v2.9.0/app/controllers/concerns/hyrax/works_controller_behavior.rb#L146-L151 - module ConfigurableIiifManifestPresenter - extend ActiveSupport::Concern - - included do - class_attribute :iiif_manifest_presenter_klass - self.iiif_manifest_presenter_klass = ::Spot::IiifManifestPresenter - end - - private - - # same behavior as Hyrax::WorksControllerBehavior#iiif_manifest_presenter, - # but uses the configurable +:iiif_manifest_presenter_klass+ attribute - # to allow for other subclassed presenters. - # - # @return [Hyrax::IiifManifestPresenter] - def iiif_manifest_presenter - iiif_manifest_presenter_klass.new(curation_concern_from_search_results).tap do |p| - p.hostname = request.hostname - p.ability = current_ability - end - end - end -end diff --git a/app/controllers/concerns/spot/works_controller_behavior.rb b/app/controllers/concerns/spot/works_controller_behavior.rb new file mode 100644 index 000000000..bb9e5ef44 --- /dev/null +++ b/app/controllers/concerns/spot/works_controller_behavior.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true +module Spot + # Base controller for Works that we can inherit from. Inherits Hyrax work behaviors + # as well as handling for CSVs and using our own IIIF presenter. + # + # @example usage + # class DigitizedResourcesController < ApplicationController + # include Spot::WorksControllerBehavior + # end + # + module WorksControllerBehavior + extend ActiveSupport::Concern + include ::Hyrax::WorksControllerBehavior + include ::Hyrax::BreadcrumbsForWorks + include AdditionalFormatsForController + + private + + # Overrides Hyrax behavior by using our own IIIF presenter that relies on Blacklight locales + # to generate field labels. + # + # @return [Spot::IiifManifestPresenter] + def iiif_manifest_presenter + ::Spot::IiifManifestPresenter.new(curation_concern_from_search_results).tap do |p| + p.hostname = request.hostname + p.ability = current_ability + end + end + end +end diff --git a/app/controllers/hyrax/images_controller.rb b/app/controllers/hyrax/images_controller.rb index 028ff3431..aae3386fd 100644 --- a/app/controllers/hyrax/images_controller.rb +++ b/app/controllers/hyrax/images_controller.rb @@ -1,17 +1,9 @@ # frozen_string_literal: true module Hyrax - # Generated controller for Image class ImagesController < ApplicationController - # Adds Hyrax behaviors to the controller. - include Hyrax::WorksControllerBehavior - include Hyrax::BreadcrumbsForWorks - - # use our local IiifManifestPresenter for rendering manifest metadata - include Spot::ConfigurableIiifManifestPresenter + include ::Spot::WorksControllerBehavior self.curation_concern_type = ::Image - - # Use this line if you want to use a custom presenter self.show_presenter = Hyrax::ImagePresenter end end diff --git a/app/controllers/hyrax/publications_controller.rb b/app/controllers/hyrax/publications_controller.rb index 5f5091081..0eed8a5b8 100644 --- a/app/controllers/hyrax/publications_controller.rb +++ b/app/controllers/hyrax/publications_controller.rb @@ -1,17 +1,9 @@ # frozen_string_literal: true module Hyrax class PublicationsController < ApplicationController - # Adds Hyrax behaviors to the controller. - include Hyrax::WorksControllerBehavior - include Hyrax::BreadcrumbsForWorks - include Spot::AdditionalFormatsForController - - # use our local IiifManifestPresenter for rendering manifest metadata - include Spot::ConfigurableIiifManifestPresenter + include Spot::WorksControllerBehavior self.curation_concern_type = ::Publication - - # Use this line if you want to use a custom presenter self.show_presenter = Hyrax::PublicationPresenter end end diff --git a/app/indexers/concerns/indexes_language_and_label.rb b/app/indexers/concerns/indexes_language_and_label.rb index 4e2f97110..9cd7f4b73 100644 --- a/app/indexers/concerns/indexes_language_and_label.rb +++ b/app/indexers/concerns/indexes_language_and_label.rb @@ -14,7 +14,7 @@ def generate_solr_document object.language.each do |lang| doc[value_field] << lang - doc[label_field] << (Spot::ISO6391.label_for(lang) || lang) + doc[label_field] << Spot::ISO6391.label_for(lang) end end end diff --git a/app/services/spot/iso6391.rb b/app/services/spot/iso6391.rb index a99cab9bd..76543f1c6 100644 --- a/app/services/spot/iso6391.rb +++ b/app/services/spot/iso6391.rb @@ -1,39 +1,31 @@ # frozen_string_literal: true - -# An utility class for the +iso-639+ gem. We're storing the dictionary -# in a class variable so we don't need to load it every time. module Spot - class ISO6391 - class << self - # All of the ISO-639-1 entries in a key/val hash - # - # @example - # Spot::LanguageAuthority.all.first.to_h - # # => {'aa' => 'Afar'} - # - # @return [Array String>>] - def all - @all ||= mapped_639_1_entries - end - - # Find the label for a language by its 2-char entry. - # - # @param [String] id - # @return [String, NilClass] - def label_for(id) - all[id.downcase] - end - - private + # Helper module for obtaining labels for ISO-639-1 values. Uses +I18n+ gem to allow + # custom labels for languages to be provided as a locale file (see +config/locales/iso_639.en.yml+) + module ISO6391 + # All of the ISO-639-1 entries in a key/val hash + # + # @example + # Spot::LanguageAuthority.all.first.to_h + # # => {'aa' => 'Afar'} + # + # @return [Array String>>] + def self.all + @all ||= ISO_639::ISO_639_1.select { |e| e.alpha2.present? }.map { |e| [e.alpha2, label_for(e.alpha2)] }.to_h + end - # iso639-1 entries mapped to a key/val hash - # - # @return [Hash String>] - def mapped_639_1_entries - ISO_639::ISO_639_1.select { |e| e.alpha2.present? } - .map { |e| [e.alpha2, e.english_name] } - .to_h - end + # Find the label for a language by its 2-char entry. + # Possible values, in priority order, are: + # + # - locale value => I18n.t('iso_639_1.es') + # - iso-639 gem english name => ISO_639.find('es').english_name + # - the id value as provided => 'es' + # + # @param [String] id + # @return [String, NilClass] + def self.label_for(id) + id = id.to_s.downcase + I18n.t(id, scope: ['iso_639_1'], default: [ISO_639.find(id)&.english_name, id]) end end end diff --git a/config/authorities/lafayette_departments.yml b/config/authorities/lafayette_departments.yml index c5e3dff42..62d69370f 100644 --- a/config/authorities/lafayette_departments.yml +++ b/config/authorities/lafayette_departments.yml @@ -5,6 +5,7 @@ terms: - Art - Asian Studies - Biology + - Center for the Integration of Teaching, Learning, and Scholarship - Chemical & Biomolecular Engineering - Chemistry - Civil & Environmental Engineering diff --git a/config/locales/iso_639.en.yml b/config/locales/iso_639.en.yml new file mode 100644 index 000000000..cfb836513 --- /dev/null +++ b/config/locales/iso_639.en.yml @@ -0,0 +1,3 @@ +en: + iso_639_1: + es: Spanish diff --git a/spec/controllers/hyrax/images_controller_spec.rb b/spec/controllers/hyrax/images_controller_spec.rb index 2d5419c57..d0f53787d 100644 --- a/spec/controllers/hyrax/images_controller_spec.rb +++ b/spec/controllers/hyrax/images_controller_spec.rb @@ -1,11 +1,4 @@ # frozen_string_literal: true - -# Generated via -# `rails generate hyrax:work Image` -require 'rails_helper' - RSpec.describe Hyrax::ImagesController do - it "has tests" do - skip "Add your tests here" - end + it_behaves_like 'it includes Spot::WorksControllerBehavior' end diff --git a/spec/controllers/hyrax/publications_controller_spec.rb b/spec/controllers/hyrax/publications_controller_spec.rb index eaf1b3a68..08db6ed86 100644 --- a/spec/controllers/hyrax/publications_controller_spec.rb +++ b/spec/controllers/hyrax/publications_controller_spec.rb @@ -1,48 +1,4 @@ # frozen_string_literal: true RSpec.describe Hyrax::PublicationsController do - let(:doc) { create(:publication, :public) } - - context 'when visiting a known publication' do - before do - get :show, params: { id: doc.id } - end - - it { expect(response).to be_successful } - end - - context 'when visiting a non-existant publication' do - # TODO: this shouldn't be raising an exception, but rather be rendering a 404 - - it 'raises a Blacklight::RecordNotFound error' do - expect { get :show, params: { id: 'not-here' } } - .to raise_error(Blacklight::Exceptions::RecordNotFound) - end - end - - context 'when visiting a Private Publication as a guest' do - let(:doc) { create(:publication, :private) } - - before do - get :show, params: { id: doc.id } - end - - it 'redirects to the login page' do - expect(response.status).to eq 302 - expect(response.headers['Location']).to include '/users/sign_in' - end - end - - context 'when requesting the metadata as csv' do - let(:disposition) { response.header.fetch('Content-Disposition') } - let(:content_type) { response.header.fetch('Content-Type') } - - it 'downloads the file' do - get :show, params: { id: doc.id, format: 'csv' } - - expect(response).to be_successful - expect(disposition).to include 'attachment' - expect(content_type).to eq 'text/csv' - expect(response.body).to start_with('id,title') - end - end + it_behaves_like 'it includes Spot::WorksControllerBehavior' end diff --git a/spec/services/spot/iso_6391_spec.rb b/spec/services/spot/iso_6391_spec.rb index f461bfb8a..c0f588c56 100644 --- a/spec/services/spot/iso_6391_spec.rb +++ b/spec/services/spot/iso_6391_spec.rb @@ -1,13 +1,13 @@ # frozen_string_literal: true RSpec.describe Spot::ISO6391 do - describe '#all' do + describe '.all' do subject { described_class.all } it { is_expected.to be_a Hash } it { is_expected.not_to be_empty } end - describe '#label_for' do + describe '.label_for' do subject { described_class.label_for(id) } context 'when a 2-char entry exists' do @@ -16,10 +16,26 @@ it { is_expected.to eq 'Esperanto' } end + context 'when a local override for an entry exists' do + let(:id) { 'en' } + let(:original_value) { ISO_639.find(id).english_name } + let(:expected_value) { 'ANGLISH' } + + before do + allow(I18n) + .to receive(:t) + .with(id, default: [original_value, id], scope: ['iso_639_1']) + .and_return(expected_value) + end + + it { is_expected.not_to eq original_value } + it { is_expected.to eq expected_value } + end + context 'when an entry does not exist' do let(:id) { ':(' } - it { is_expected.to be_nil } + it { is_expected.to eq id } end end end diff --git a/spec/support/shared_examples/indexing/indexes_language_and_label.rb b/spec/support/shared_examples/indexing/indexes_language_and_label.rb index 838ae7b6d..259af0dcf 100644 --- a/spec/support/shared_examples/indexing/indexes_language_and_label.rb +++ b/spec/support/shared_examples/indexing/indexes_language_and_label.rb @@ -13,7 +13,7 @@ # rubocop:enable RSpec/InstanceVariable let(:languages) { ['en', 'ja', 'nope'] } - let(:labels) { ['English', 'Japanese', 'nope'] } + let(:labels) { languages.map { |lang| Spot::ISO6391.label_for(lang) } } it 'stores the raw values as _ssim' do expect(solr_doc['language_ssim']).to contain_exactly(*languages) diff --git a/spec/support/shared_examples/spot_works_controller.rb b/spec/support/shared_examples/spot_works_controller.rb new file mode 100644 index 000000000..e880f6f24 --- /dev/null +++ b/spec/support/shared_examples/spot_works_controller.rb @@ -0,0 +1,52 @@ +# frozen_string_literal: true +RSpec.shared_examples 'it includes Spot::WorksControllerBehavior' do + let(:work_type) { described_class.name.split('::').last.sub('Controller', '').singularize.downcase.to_sym } + let(:work) { create(work_type, :public) } + + describe 'Hyrax::WorksControllerBehavior' do + # @todo is this class_attribute going anywhere? keep an eye on it, i guess. + context "when visiting a known #{described_class.curation_concern_type}" do + before do + get :show, params: { id: work.id } + end + + it { expect(response).to be_successful } + end + + context 'when visiting a non-existant publication' do + it 'raises a Blacklight::RecordNotFound error' do + expect { get :show, params: { id: 'not-here' } } + .to raise_error(Blacklight::Exceptions::RecordNotFound) + end + end + + context 'when visiting a Private Publication as a guest' do + let(:doc) { create(:publication, :private) } + + before do + get :show, params: { id: doc.id } + end + + it 'redirects to the login page' do + expect(response.status).to eq 302 + expect(response.headers['Location']).to include '/users/sign_in' + end + end + end + + describe 'additional formats' do + context 'when requesting the metadata as csv' do + let(:disposition) { response.header.fetch('Content-Disposition') } + let(:content_type) { response.header.fetch('Content-Type') } + + it 'downloads the file' do + get :show, params: { id: work.id, format: 'csv' } + + expect(response).to be_successful + expect(disposition).to include 'attachment' + expect(content_type).to eq 'text/csv' + expect(response.body).to start_with('id,title') + end + end + end +end