FIX: username route was broken

This commit is contained in:
Arpit Jalan 2016-12-16 23:56:22 +05:30
parent 51679ef6b2
commit ab6843dcde
2 changed files with 24 additions and 1 deletions

View File

@ -326,7 +326,7 @@ Discourse::Application.routes.draw do
get "users/:username/messages/group/:group_name/archive" => "user_actions#private_messages", constraints: {username: USERNAME_ROUTE_FORMAT, group_name: USERNAME_ROUTE_FORMAT}
get "users/:username.json" => "users#show", constraints: {username: USERNAME_ROUTE_FORMAT}, defaults: {format: :json}
get "users/:username" => "users#show", as: 'user', constraints: {username: USERNAME_ROUTE_FORMAT}
get "users/:username" => "users#show", as: 'user', constraints: {username: USERNAME_ROUTE_FORMAT, format: /(json|html)/}
put "users/:username" => "users#update", constraints: {username: USERNAME_ROUTE_FORMAT}, defaults: { format: :json }
get "users/:username/emails" => "users#check_emails", constraints: {username: USERNAME_ROUTE_FORMAT}
get "users/:username/preferences" => "users#preferences", constraints: {username: USERNAME_ROUTE_FORMAT}, as: :email_preferences

View File

@ -3,6 +3,29 @@ require 'rails_helper'
RSpec.describe "Users" do
let(:user) { Fabricate(:user) }
describe "viewing a user" do
it "should be able to view a user" do
get "/users/#{user.username}"
expect(response).to be_success
expect(response.body).to include(user.username)
end
describe 'when username contains a period' do
before do
user.update!(username: 'test.test')
end
it "should be able to view a user" do
get "/users/#{user.username}"
expect(response).to be_success
expect(response.body).to include(user.username)
end
end
end
describe "updating a user" do
before do
sign_in(user)