Skip to content
Merged
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 config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@
get 'donate' => 'pages#show', id: 'donate'
get 'codebar-stories-podcast' => 'pages#show', id: 'codebar-stories-podcast'

get ':id' => 'chapter#show', as: :chapter
get ':id' => 'chapter#show', as: :chapter, format: false, constraints: { id: /[a-z0-9_-]+/ }

# Redirects
get '/my/jobs/new', to: redirect('https://jobs.codebar.io/my/jobs/new')
Expand Down
25 changes: 25 additions & 0 deletions spec/routing/chapter_routing_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe 'chapter catch-all route' do
it 'routes a chapter slug to chapter#show' do
expect(get: '/london').to route_to(controller: 'chapter', action: 'show', id: 'london')
end

# Chapter#set_slug builds slugs with name.parameterize, which produces
# lowercase letters, digits, hyphens, and underscores.
it 'routes every character class the slug generator can produce' do
expect(get: '/123').to route_to(controller: 'chapter', action: 'show', id: '123')
expect(get: '/south-london').to route_to(controller: 'chapter', action: 'show', id: 'south-london')
expect(get: '/spring_wildcats').to route_to(controller: 'chapter', action: 'show', id: 'spring_wildcats')
end

it 'does not route paths containing dots' do
expect(get: '/key.pem').not_to be_routable
end

it 'does not route paths containing uppercase characters' do
expect(get: '/Shanghai').not_to be_routable
end
end
Loading