Skip to content

Commit

Permalink
Merge eb211fa into f5f5165
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Mar 7, 2019
2 parents f5f5165 + eb211fa commit 123e8ba
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion config/routes.rb
Expand Up @@ -7,7 +7,7 @@
put "saved_searches/save/:id", :to => "saved_searches#save", :as => "save_search"
delete "saved_searches/forget/:id", :to => "saved_searches#forget", :as => "forget_search"
post "saved_searches/forget/:id", :to => "saved_searches#forget"
post "/catalog/:id/track", to: 'catalog#track', as: 'track_search_context'
post "/catalog/:id/track", to: 'catalog#track', as: 'track_search_context', constraints: { id: Blacklight::Engine.config.routes.identifier_constraint }

resources :suggest, only: :index, defaults: { format: 'json' }
end
8 changes: 6 additions & 2 deletions lib/blacklight/engine.rb
Expand Up @@ -7,7 +7,7 @@ class Engine < Rails::Engine
require 'twitter-typeahead-rails'

# BlacklightHelper is needed by all helpers, so we inject it
# into action view base here.
# into action view base here.
initializer 'blacklight.helpers' do |app|
ActionView::Base.send :include, BlacklightHelper
end
Expand Down Expand Up @@ -43,8 +43,12 @@ class Engine < Rails::Engine
'Cricket' => 'mms.mycricket.com'
}

config.routes = OpenStruct.new
# Set identifier_constraint to enforce a format for the document identifiers
config.routes.identifier_constraint = /[\w-]+/

config.bookmarks_http_method = :post

config.email_regexp = defined?(Devise) ? Devise.email_regexp : /\A[^@\s]+@[^@\s]+\z/
end
end
16 changes: 16 additions & 0 deletions spec/routing/catalog_routing_spec.rb
Expand Up @@ -21,6 +21,22 @@
end
end

describe 'tracking' do
context 'when the routing constraint is set to allow periods' do
before do
if Rails.version < '5.2.0'
skip 'requires https://github.com/rails/rails/pull/22435'
end
allow(Blacklight::Engine.config.routes).to receive(:identifier_constraint).and_return(%r{[^/]+})
Rails.application.reload_routes!
end

it 'routes to #track' do
expect(post('/catalog/gallica.bnf.fr/track')).to route_to('catalog#track', id: 'gallica.bnf.fr')
end
end
end


describe "solr_document_path for SolrDocument", :test => true do
it "routes correctly" do
Expand Down

0 comments on commit 123e8ba

Please sign in to comment.