summaryrefslogtreecommitdiff
path: root/spec/requests/api/users_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/requests/api/users_spec.rb')
-rw-r--r--spec/requests/api/users_spec.rb114
1 files changed, 57 insertions, 57 deletions
diff --git a/spec/requests/api/users_spec.rb b/spec/requests/api/users_spec.rb
index 327f3e6d23c..c10998e171f 100644
--- a/spec/requests/api/users_spec.rb
+++ b/spec/requests/api/users_spec.rb
@@ -21,9 +21,9 @@ describe API::API, api: true do
expect(response.status).to eq(200)
expect(json_response).to be_an Array
username = user.username
- expect(json_response.detect {
- |user| user['username'] == username
- }['username']).to eq(username)
+ expect(json_response.detect do |user|
+ user['username'] == username
+ end['username']).to eq(username)
end
end
@@ -62,9 +62,9 @@ describe API::API, api: true do
before{ admin }
it "should create user" do
- expect {
+ expect do
post api("/users", admin), attributes_for(:user, projects_limit: 3)
- }.to change { User.count }.by(1)
+ end.to change { User.count }.by(1)
end
it "should create user with correct attributes" do
@@ -103,9 +103,9 @@ describe API::API, api: true do
it "should not create user with invalid email" do
post api('/users', admin),
- email: 'invalid email',
- password: 'password',
- name: 'test'
+ email: 'invalid email',
+ password: 'password',
+ name: 'test'
expect(response.status).to eq(400)
end
@@ -131,21 +131,21 @@ describe API::API, api: true do
it 'should return 400 error if user does not validate' do
post api('/users', admin),
- password: 'pass',
- email: 'test@example.com',
- username: 'test!',
- name: 'test',
- bio: 'g' * 256,
- projects_limit: -1
+ password: 'pass',
+ email: 'test@example.com',
+ username: 'test!',
+ name: 'test',
+ bio: 'g' * 256,
+ projects_limit: -1
expect(response.status).to eq(400)
expect(json_response['message']['password']).
- to eq(['is too short (minimum is 8 characters)'])
+ to eq(['is too short (minimum is 8 characters)'])
expect(json_response['message']['bio']).
- to eq(['is too long (maximum is 255 characters)'])
+ to eq(['is too long (maximum is 255 characters)'])
expect(json_response['message']['projects_limit']).
- to eq(['must be greater than or equal to 0'])
+ to eq(['must be greater than or equal to 0'])
expect(json_response['message']['username']).
- to eq([Gitlab::Regex.send(:namespace_regex_message)])
+ to eq([Gitlab::Regex.send(:namespace_regex_message)])
end
it "shouldn't available for non admin users" do
@@ -156,20 +156,20 @@ describe API::API, api: true do
context 'with existing user' do
before do
post api('/users', admin),
- email: 'test@example.com',
- password: 'password',
- username: 'test',
- name: 'foo'
+ email: 'test@example.com',
+ password: 'password',
+ username: 'test',
+ name: 'foo'
end
it 'should return 409 conflict error if user with same email exists' do
- expect {
+ expect do
post api('/users', admin),
- name: 'foo',
- email: 'test@example.com',
- password: 'password',
- username: 'foo'
- }.to change { User.count }.by(0)
+ name: 'foo',
+ email: 'test@example.com',
+ password: 'password',
+ username: 'foo'
+ end.to change { User.count }.by(0)
expect(response.status).to eq(409)
expect(json_response['message']).to eq('Email has already been taken')
end
@@ -177,10 +177,10 @@ describe API::API, api: true do
it 'should return 409 conflict error if same username exists' do
expect do
post api('/users', admin),
- name: 'foo',
- email: 'foo@example.com',
- password: 'password',
- username: 'test'
+ name: 'foo',
+ email: 'foo@example.com',
+ password: 'password',
+ username: 'test'
end.to change { User.count }.by(0)
expect(response.status).to eq(409)
expect(json_response['message']).to eq('Username has already been taken')
@@ -203,7 +203,7 @@ describe API::API, api: true do
before { admin }
it "should update user with new bio" do
- put api("/users/#{user.id}", admin), {bio: 'new test bio'}
+ put api("/users/#{user.id}", admin), { bio: 'new test bio' }
expect(response.status).to eq(200)
expect(json_response['bio']).to eq('new test bio')
expect(user.reload.bio).to eq('new test bio')
@@ -224,14 +224,14 @@ describe API::API, api: true do
end
it "should update admin status" do
- put api("/users/#{user.id}", admin), {admin: true}
+ put api("/users/#{user.id}", admin), { admin: true }
expect(response.status).to eq(200)
expect(json_response['is_admin']).to eq(true)
expect(user.reload.admin).to eq(true)
end
it "should not update admin status" do
- put api("/users/#{admin_user.id}", admin), {can_create_group: false}
+ put api("/users/#{admin_user.id}", admin), { can_create_group: false }
expect(response.status).to eq(200)
expect(json_response['is_admin']).to eq(true)
expect(admin_user.reload.admin).to eq(true)
@@ -239,7 +239,7 @@ describe API::API, api: true do
end
it "should not allow invalid update" do
- put api("/users/#{user.id}", admin), {email: 'invalid email'}
+ put api("/users/#{user.id}", admin), { email: 'invalid email' }
expect(response.status).to eq(400)
expect(user.reload.email).not_to eq('invalid email')
end
@@ -250,36 +250,36 @@ describe API::API, api: true do
end
it "should return 404 for non-existing user" do
- put api("/users/999999", admin), {bio: 'update should fail'}
+ put api("/users/999999", admin), { bio: 'update should fail' }
expect(response.status).to eq(404)
expect(json_response['message']).to eq('404 Not found')
end
it 'should return 400 error if user does not validate' do
put api("/users/#{user.id}", admin),
- password: 'pass',
- email: 'test@example.com',
- username: 'test!',
- name: 'test',
- bio: 'g' * 256,
- projects_limit: -1
+ password: 'pass',
+ email: 'test@example.com',
+ username: 'test!',
+ name: 'test',
+ bio: 'g' * 256,
+ projects_limit: -1
expect(response.status).to eq(400)
expect(json_response['message']['password']).
- to eq(['is too short (minimum is 8 characters)'])
+ to eq(['is too short (minimum is 8 characters)'])
expect(json_response['message']['bio']).
- to eq(['is too long (maximum is 255 characters)'])
+ to eq(['is too long (maximum is 255 characters)'])
expect(json_response['message']['projects_limit']).
- to eq(['must be greater than or equal to 0'])
+ to eq(['must be greater than or equal to 0'])
expect(json_response['message']['username']).
- to eq([Gitlab::Regex.send(:namespace_regex_message)])
+ to eq([Gitlab::Regex.send(:namespace_regex_message)])
end
context "with existing user" do
- before {
+ before do
post api("/users", admin), { email: 'test@example.com', password: 'password', username: 'test', name: 'test' }
post api("/users", admin), { email: 'foo@bar.com', password: 'password', username: 'john', name: 'john' }
@user = User.all.last
- }
+ end
it 'should return 409 conflict error if email address exists' do
put api("/users/#{@user.id}", admin), email: 'test@example.com'
@@ -313,9 +313,9 @@ describe API::API, api: true do
it "should create ssh key" do
key_attrs = attributes_for :key
- expect {
+ expect do
post api("/users/#{user.id}/keys", admin), key_attrs
- }.to change{ user.keys.count }.by(1)
+ end.to change{ user.keys.count }.by(1)
end
end
@@ -361,9 +361,9 @@ describe API::API, api: true do
it 'should delete existing key' do
user.keys << key
user.save
- expect {
+ expect do
delete api("/users/#{user.id}/keys/#{key.id}", admin)
- }.to change { user.keys.count }.by(-1)
+ end.to change { user.keys.count }.by(-1)
expect(response.status).to eq(200)
end
@@ -475,9 +475,9 @@ describe API::API, api: true do
describe "POST /user/keys" do
it "should create ssh key" do
key_attrs = attributes_for :key
- expect {
+ expect do
post api("/user/keys", user), key_attrs
- }.to change{ user.keys.count }.by(1)
+ end.to change{ user.keys.count }.by(1)
expect(response.status).to eq(201)
end
@@ -508,9 +508,9 @@ describe API::API, api: true do
it "should delete existed key" do
user.keys << key
user.save
- expect {
+ expect do
delete api("/user/keys/#{key.id}", user)
- }.to change{user.keys.count}.by(-1)
+ end.to change{user.keys.count}.by(-1)
expect(response.status).to eq(200)
end