summaryrefslogtreecommitdiff
path: root/spec/controllers/profiles_controller_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/controllers/profiles_controller_spec.rb')
-rw-r--r--spec/controllers/profiles_controller_spec.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/spec/controllers/profiles_controller_spec.rb b/spec/controllers/profiles_controller_spec.rb
index 891485406c6..de6ef919221 100644
--- a/spec/controllers/profiles_controller_spec.rb
+++ b/spec/controllers/profiles_controller_spec.rb
@@ -84,6 +84,28 @@ describe ProfilesController, :request_store do
expect(user.username).to eq(new_username)
end
+ it 'updates a username using JSON request' do
+ sign_in(user)
+
+ put :update_username,
+ user: { username: new_username },
+ format: :json
+
+ expect(response.status).to eq(200)
+ expect(json_response['message']).to eq('Username successfully changed')
+ end
+
+ it 'renders an error message when the username was not updated' do
+ sign_in(user)
+
+ put :update_username,
+ user: { username: 'invalid username.git' },
+ format: :json
+
+ expect(response.status).to eq(422)
+ expect(json_response['message']).to match(/Username change failed/)
+ end
+
it 'raises a correct error when the username is missing' do
sign_in(user)