From 9dbe9fd9d7bf6507ae7418b8392422e1b0b1df59 Mon Sep 17 00:00:00 2001 From: Chris Beer Date: Wed, 17 Apr 2019 16:54:48 -0700 Subject: [PATCH 1/2] Remove unnecessary locale defaults; they don't seem necessary, and break named URL routes. Fixes #1349 --- config/routes.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 81b4fd43e..6fa9417f1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -11,7 +11,7 @@ mount Sidekiq::Web => '/sidekiq' end - scope '(:locale)', locale: Regexp.union(Spotlight::Engine.config.i18n_locales.keys.map(&:to_s)), defaults: { locale: nil } do + scope '(:locale)', locale: Regexp.union(Spotlight::Engine.config.i18n_locales.keys.map(&:to_s)) do mount Blacklight::Oembed::Engine, at: 'oembed' mount Riiif::Engine => '/images', as: 'riiif' @@ -60,9 +60,9 @@ end mount MiradorRails::Engine, at: MiradorRails::Engine.locales_mount_path - Blacklight::Engine.routes.default_scope = { path: "(:locale)", locale: Regexp.union(Spotlight::Engine.config.i18n_locales.keys.map(&:to_s)), module: 'blacklight', defaults: { locale: nil } } + Blacklight::Engine.routes.default_scope = { path: "(:locale)", locale: Regexp.union(Spotlight::Engine.config.i18n_locales.keys.map(&:to_s)), module: 'blacklight' } mount Blacklight::Engine => '/' - Spotlight::Engine.routes.default_scope = { path: "(:locale)", locale: Regexp.union(Spotlight::Engine.config.i18n_locales.keys.map(&:to_s)), module: 'spotlight', defaults: { locale: nil } } + Spotlight::Engine.routes.default_scope = { path: "(:locale)", locale: Regexp.union(Spotlight::Engine.config.i18n_locales.keys.map(&:to_s)), module: 'spotlight' } mount Spotlight::Engine, at: '/' end From d2dc69f1ed61ed4b4d253bc5ab4a039ca7cba87f Mon Sep 17 00:00:00 2001 From: Chris Beer Date: Thu, 18 Apr 2019 09:28:24 -0700 Subject: [PATCH 2/2] Inject a new spec module to make routes used in rspec behave like those used in the app --- app/jobs/send_publish_state_change_notification_job.rb | 2 +- app/services/upload_solr_document_builder.rb | 6 ++++++ .../bibliography_resources_controller_spec.rb | 8 ++++---- spec/controllers/dor_harvester_controller_spec.rb | 8 ++++---- spec/helpers/catalog_helper_spec.rb | 4 ++++ spec/rails_helper.rb | 3 +++ spec/support/optional_locale_route_param_injection.rb | 9 +++++++++ .../catalog/_metadata_button_default.html.erb_spec.rb | 1 + 8 files changed, 32 insertions(+), 9 deletions(-) create mode 100644 spec/support/optional_locale_route_param_injection.rb diff --git a/app/jobs/send_publish_state_change_notification_job.rb b/app/jobs/send_publish_state_change_notification_job.rb index c0f601201..11c3a04ef 100644 --- a/app/jobs/send_publish_state_change_notification_job.rb +++ b/app/jobs/send_publish_state_change_notification_job.rb @@ -22,6 +22,6 @@ def message_text(exhibit:, published:) def exhibit_url(exhibit) url_helpers = Spotlight::Engine.routes.url_helpers - url_helpers.exhibit_url(exhibit, host: Settings.action_mailer.default_url_options.host) + url_helpers.exhibit_url(exhibit, locale: nil, host: Settings.action_mailer.default_url_options.host) end end diff --git a/app/services/upload_solr_document_builder.rb b/app/services/upload_solr_document_builder.rb index 4abc574d0..7d933d203 100644 --- a/app/services/upload_solr_document_builder.rb +++ b/app/services/upload_solr_document_builder.rb @@ -7,4 +7,10 @@ def add_file_versions(solr_hash) solr_hash[:thumbnail_square_url_ssm] = riiif.image_path(resource.upload_id, region: 'square', size: '100,100') end + + # Override upstream to add an empty locale + def add_manifest_path(solr_hash) + path = spotlight_routes.manifest_exhibit_solr_document_path(exhibit, resource.compound_id, locale: nil) + solr_hash[Spotlight::Engine.config.iiif_manifest_field] = path + end end diff --git a/spec/controllers/bibliography_resources_controller_spec.rb b/spec/controllers/bibliography_resources_controller_spec.rb index 3f18a8588..c0c77161b 100644 --- a/spec/controllers/bibliography_resources_controller_spec.rb +++ b/spec/controllers/bibliography_resources_controller_spec.rb @@ -24,7 +24,7 @@ it 'goes to the exhibit' do post :create, params: { exhibit_id: exhibit.id, resource: attributes } - expect(response).to redirect_to Spotlight::Engine.routes.url_helpers.admin_exhibit_catalog_path(exhibit) + expect(response).to redirect_to spotlight.admin_exhibit_catalog_path(exhibit) expect(resource).to have_received(:update) expect(resource).to have_received(:save_and_index) @@ -37,7 +37,7 @@ it 'goes to the exhibit' do post :create, params: { exhibit_id: exhibit.id, resource: attributes } - expect(response).to redirect_to Spotlight::Engine.routes.url_helpers.new_exhibit_resource_path(exhibit) + expect(response).to redirect_to spotlight.new_exhibit_resource_path(exhibit) expect(resource).to have_received(:update) expect(resource).to have_received(:save_and_index) @@ -52,7 +52,7 @@ it 'goes to the exhibit' do patch :update, params: { exhibit_id: exhibit.id, resource: attributes } - expect(response).to redirect_to Spotlight::Engine.routes.url_helpers.admin_exhibit_catalog_path(exhibit) + expect(response).to redirect_to spotlight.admin_exhibit_catalog_path(exhibit) expect(resource).to have_received(:update) expect(resource).to have_received(:save_and_index) @@ -65,7 +65,7 @@ it 'goes to the exhibit' do patch :update, params: { exhibit_id: exhibit.id, resource: attributes } - expect(response).to redirect_to Spotlight::Engine.routes.url_helpers.new_exhibit_resource_path(exhibit) + expect(response).to redirect_to spotlight.new_exhibit_resource_path(exhibit) expect(resource).to have_received(:update) expect(resource).to have_received(:save_and_index) diff --git a/spec/controllers/dor_harvester_controller_spec.rb b/spec/controllers/dor_harvester_controller_spec.rb index e02c9969f..160a41739 100644 --- a/spec/controllers/dor_harvester_controller_spec.rb +++ b/spec/controllers/dor_harvester_controller_spec.rb @@ -22,7 +22,7 @@ it 'goes to the exhibit' do post :create, params: { exhibit_id: exhibit.id, dor_harvester: attributes } - expect(response).to redirect_to Spotlight::Engine.routes.url_helpers.admin_exhibit_catalog_path(exhibit) + expect(response).to redirect_to spotlight.admin_exhibit_catalog_path(exhibit) expect(resource).to have_received(:update) expect(resource).to have_received(:save_and_index) @@ -35,7 +35,7 @@ it 'goes to the exhibit' do post :create, params: { exhibit_id: exhibit.id, dor_harvester: attributes } - expect(response).to redirect_to Spotlight::Engine.routes.url_helpers.new_exhibit_resource_path(exhibit) + expect(response).to redirect_to spotlight.new_exhibit_resource_path(exhibit) expect(resource).to have_received(:update) expect(resource).to have_received(:save_and_index) @@ -50,7 +50,7 @@ it 'goes to the exhibit' do patch :update, params: { exhibit_id: exhibit.id, dor_harvester: attributes } - expect(response).to redirect_to Spotlight::Engine.routes.url_helpers.admin_exhibit_catalog_path(exhibit) + expect(response).to redirect_to spotlight.admin_exhibit_catalog_path(exhibit) expect(resource).to have_received(:update) expect(resource).to have_received(:save_and_index) @@ -63,7 +63,7 @@ it 'goes to the exhibit' do patch :update, params: { exhibit_id: exhibit.id, dor_harvester: attributes } - expect(response).to redirect_to Spotlight::Engine.routes.url_helpers.new_exhibit_resource_path(exhibit) + expect(response).to redirect_to spotlight.new_exhibit_resource_path(exhibit) expect(resource).to have_received(:update) expect(resource).to have_received(:save_and_index) diff --git a/spec/helpers/catalog_helper_spec.rb b/spec/helpers/catalog_helper_spec.rb index 2a4a66693..5aae1ba8b 100644 --- a/spec/helpers/catalog_helper_spec.rb +++ b/spec/helpers/catalog_helper_spec.rb @@ -3,6 +3,10 @@ require 'rails_helper' describe CatalogHelper, type: :helper do + before do + controller.extend OptionalLocaleRouteParamInjection + end + describe '#has_thumbnail?' do context 'for references' do let(:document) { SolrDocument.new(format_main_ssim: ['Reference']) } diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index fa1627ed7..ffa329a61 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -65,6 +65,9 @@ config.include FactoryBot::Syntax::Methods config.include RequestSpecHelper + config.include ::Rails.application.routes.url_helpers, type: :controller + config.include ::Rails.application.routes.mounted_helpers, type: :controller + config.include OptionalLocaleRouteParamInjection config.before do DatabaseCleaner.strategy = if Capybara.current_driver == :rack_test diff --git a/spec/support/optional_locale_route_param_injection.rb b/spec/support/optional_locale_route_param_injection.rb new file mode 100644 index 000000000..924d3e261 --- /dev/null +++ b/spec/support/optional_locale_route_param_injection.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +# This makes routes in rspec behave like routes in +# the application as run. +module OptionalLocaleRouteParamInjection + def url_options + default_url_options.merge(locale: nil) + end +end diff --git a/spec/views/catalog/_metadata_button_default.html.erb_spec.rb b/spec/views/catalog/_metadata_button_default.html.erb_spec.rb index f510e9a4a..9d5301d4d 100644 --- a/spec/views/catalog/_metadata_button_default.html.erb_spec.rb +++ b/spec/views/catalog/_metadata_button_default.html.erb_spec.rb @@ -7,6 +7,7 @@ let(:current_exhibit) { create(:exhibit) } before do + view.extend OptionalLocaleRouteParamInjection assign(:document, document) end