FIX: Better error message when username change fails.

https://meta.discourse.org/t/500-error-on-username-edit/64064
This commit is contained in:
Guo Xiang Tan
2017-06-07 10:45:27 +09:00
parent d4d0aa8ca7
commit 2cad739262
5 changed files with 35 additions and 34 deletions

View File

@@ -867,7 +867,7 @@ describe UsersController do
end
context '.username' do
context '#username' do
it 'raises an error when not logged in' do
expect { xhr :put, :username, username: 'somename' }.to raise_error(Discourse::NotLoggedIn)
end
@@ -894,10 +894,17 @@ describe UsersController do
expect(user.reload.username).to eq(old_username)
end
# Bad behavior, this should give a real JSON error, not an InvalidParameters
it 'raises an error when change_username fails' do
User.any_instance.expects(:save).returns(false)
expect { xhr :put, :username, username: user.username, new_username: new_username }.to raise_error(Discourse::InvalidParameters)
xhr :put, :username, username: user.username, new_username: '@'
expect(response).to_not be_success
body = JSON.parse(response.body)
expect(body['errors'].first).to include(I18n.t(
'user.username.short', min: User.username_length.begin
))
expect(user.reload.username).to eq(old_username)
end