Commit 398f83e

mo khan <mo@mokhan.ca>
2015-06-09 03:13:36
fix route for usernames with periods.
1 parent e27aed2
Changed files (2)
config/routes.rb
@@ -8,8 +8,8 @@ Rails.application.routes.draw do
     end
   end
   resources :programs, only: [:show]
-  resources :profiles, only: [:show]
-  get "/u/:id" => "profiles#show"
+  resources :profiles, only: [:show], constraints: { id: /[^\/]+/ }
+  get "/u/:id" => "profiles#show", constraints: { id: /[^\/]+/ }
   get "/dashboard" => "training_sessions#index", as: :dashboard
   get "/terms" => "static_pages#terms"
 end
spec/routing/profiles_routing_spec.rb
@@ -16,4 +16,17 @@ describe "/profiles" do
       id: "mokha"
     )
   end
+
+  it 'routes to /profiles/<username> with funky usernames' do
+    expect(get: "/profiles/mo.kha").to route_to(
+      controller: "profiles",
+      action: "show",
+      id: "mo.kha"
+    )
+    expect(get: "/u/mo.kha").to route_to(
+      controller: "profiles",
+      action: "show",
+      id: "mo.kha"
+    )
+  end
 end