Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary locale defaults; they don't seem necessary, and br… #1353

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/jobs/send_publish_state_change_notification_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 6 additions & 0 deletions app/services/upload_solr_document_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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
8 changes: 4 additions & 4 deletions spec/controllers/bibliography_resources_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions spec/controllers/dor_harvester_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions spec/helpers/catalog_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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']) }
Expand Down
3 changes: 3 additions & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions spec/support/optional_locale_route_param_injection.rb
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
let(:current_exhibit) { create(:exhibit) }

before do
view.extend OptionalLocaleRouteParamInjection
assign(:document, document)
end

Expand Down