FIX: Incorrect route for updating username.

This commit is contained in:
Guo Xiang Tan 2016-12-17 00:21:28 +08:00
parent ddd299f4aa
commit d8541c589a
6 changed files with 43 additions and 10 deletions

View File

@ -254,7 +254,7 @@ const User = RestModel.extend({
// TODO: We can remove this when migrated fully to rest model.
this.set('isSaving', true);
return ajax(`/users/${this.get('username_lower')}`, {
return ajax(`/users/${this.get('username_lower')}.json`, {
data: data,
type: 'PUT'
}).then(result => {

View File

@ -327,7 +327,7 @@ Discourse::Application.routes.draw do
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}
put "users/:username" => "users#update", constraints: {username: USERNAME_ROUTE_FORMAT}
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
get "users/:username/preferences/email" => "users_email#index", constraints: {username: USERNAME_ROUTE_FORMAT}

View File

@ -4,14 +4,6 @@ describe "Groups" do
let(:user) { Fabricate(:user) }
let(:group) { Fabricate(:group, users: [user]) }
def sign_in(user)
password = 'somecomplicatedpassword'
user.update!(password: password)
Fabricate(:email_token, confirmed: true, user: user)
post "/session.json", { login: user.username, password: password }
expect(response).to be_success
end
describe 'viewing groups' do
it 'should return the right response' do
group.update_attributes!(visible: true)

View File

@ -0,0 +1,31 @@
require 'rails_helper'
RSpec.describe "Users" do
let(:user) { Fabricate(:user) }
describe "updating a user" do
before do
sign_in(user)
end
it "should be able to update a user" do
put "/users/#{user.username}.json", { name: 'test.test' }
expect(response).to be_success
expect(user.reload.name).to eq('test.test')
end
describe 'when username contains a period' do
before do
user.update!(username: 'test.test')
end
it "should be able to update a user" do
put "/users/#{user.username}.json", { name: 'testing123' }
expect(response).to be_success
expect(user.reload.name).to eq('testing123')
end
end
end
end

View File

@ -43,6 +43,7 @@ Spork.prefork do
config.include Helpers
config.include MessageBus
config.include RSpecHtmlMatchers
config.include IntegrationHelpers, type: :request
config.mock_framework = :mocha
config.order = 'random'
config.infer_spec_type_from_file_location!

View File

@ -0,0 +1,9 @@
module IntegrationHelpers
def sign_in(user)
password = 'somecomplicatedpassword'
user.update!(password: password)
Fabricate(:email_token, confirmed: true, user: user)
post "/session.json", { login: user.username, password: password }
expect(response).to be_success
end
end