diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-06-22 16:05:19 +0300 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-06-22 16:05:19 +0300 |
commit | 7b9b3c5aab4fd4de55a1ba77cf4c043a110ad9cc (patch) | |
tree | 4cc1a5e2d6516551a9cf6a70c2f9aef0c13d0c04 /spec | |
parent | cf259cdb432481f28ce18487b78be0e3b5002df7 (diff) |
Fix part of api specs for rubocop
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Diffstat (limited to 'spec')
-rw-r--r-- | spec/requests/api/doorkeeper_access_spec.rb | 10 | ||||
-rw-r--r-- | spec/requests/api/projects_spec.rb | 32 | ||||
-rw-r--r-- | spec/requests/api/system_hooks_spec.rb | 12 | ||||
-rw-r--r-- | spec/requests/api/users_spec.rb | 114 |
4 files changed, 84 insertions, 84 deletions
diff --git a/spec/requests/api/doorkeeper_access_spec.rb b/spec/requests/api/doorkeeper_access_spec.rb index 39949a90422..0afc3e79339 100644 --- a/spec/requests/api/doorkeeper_access_spec.rb +++ b/spec/requests/api/doorkeeper_access_spec.rb @@ -4,20 +4,20 @@ describe API::API, api: true do include ApiHelpers let!(:user) { create(:user) } - let!(:application) { Doorkeeper::Application.create!(:name => "MyApp", :redirect_uri => "https://app.com", :owner => user) } - let!(:token) { Doorkeeper::AccessToken.create! :application_id => application.id, :resource_owner_id => user.id } + let!(:application) { Doorkeeper::Application.create!(name: "MyApp", redirect_uri: "https://app.com", owner: user) } + let!(:token) { Doorkeeper::AccessToken.create! application_id: application.id, resource_owner_id: user.id } + - describe "when unauthenticated" do it "returns authentication success" do - get api("/user"), :access_token => token.token + get api("/user"), access_token: token.token expect(response.status).to eq(200) end end describe "when token invalid" do it "returns authentication error" do - get api("/user"), :access_token => "123a" + get api("/user"), access_token: "123a" expect(response.status).to eq(401) end end diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb index 8fb1509c8b2..2ec8e0f354c 100644 --- a/spec/requests/api/projects_spec.rb +++ b/spec/requests/api/projects_spec.rb @@ -81,7 +81,7 @@ describe API::API, api: true do end it 'should return the correct order when sorted by id' do - get api('/projects', user), { order_by: 'id', sort: 'desc'} + get api('/projects', user), { order_by: 'id', sort: 'desc' } expect(response.status).to eq(200) expect(json_response).to be_an Array expect(json_response.first['id']).to eq(project3.id) @@ -90,7 +90,7 @@ describe API::API, api: true do it 'returns projects in the correct order when ci_enabled_first parameter is passed' do [project, project2, project3].each{ |project| project.build_missing_services } project2.gitlab_ci_service.update(active: true, token: "token", project_url: "url") - get api('/projects', user), { ci_enabled_first: 'true'} + get api('/projects', user), { ci_enabled_first: 'true' } expect(response.status).to eq(200) expect(json_response).to be_an Array expect(json_response.first['id']).to eq(project2.id) @@ -123,13 +123,13 @@ describe API::API, api: true do expect(json_response).to be_an Array project_name = project.name - expect(json_response.detect { - |project| project['name'] == project_name - }['name']).to eq(project_name) + expect(json_response.detect do |project| + project['name'] == project_name + end['name']).to eq(project_name) - expect(json_response.detect { - |project| project['owner']['username'] == user.username - }['owner']['username']).to eq(user.username) + expect(json_response.detect do |project| + project['owner']['username'] == user.username + end['owner']['username']).to eq(user.username) end end end @@ -138,9 +138,9 @@ describe API::API, api: true do context 'maximum number of projects reached' do it 'should not create new project and respond with 403' do allow_any_instance_of(User).to receive(:projects_limit_left).and_return(0) - expect { + expect do post api('/projects', user2), name: 'foo' - }.to change {Project.count}.by(0) + end.to change {Project.count}.by(0) expect(response.status).to eq(403) end end @@ -474,9 +474,9 @@ describe API::API, api: true do before { snippet } it 'should delete existing project snippet' do - expect { + expect do delete api("/projects/#{project.id}/snippets/#{snippet.id}", user) - }.to change { Snippet.count }.by(-1) + end.to change { Snippet.count }.by(-1) expect(response.status).to eq(200) end @@ -548,9 +548,9 @@ describe API::API, api: true do it 'should create new ssh key' do key_attrs = attributes_for :key - expect { + expect do post api("/projects/#{project.id}/keys", user), key_attrs - }.to change{ project.deploy_keys.count }.by(1) + end.to change{ project.deploy_keys.count }.by(1) end end @@ -558,9 +558,9 @@ describe API::API, api: true do before { deploy_key } it 'should delete existing key' do - expect { + expect do delete api("/projects/#{project.id}/keys/#{deploy_key.id}", user) - }.to change{ project.deploy_keys.count }.by(-1) + end.to change{ project.deploy_keys.count }.by(-1) end it 'should return 404 Not Found with invalid ID' do diff --git a/spec/requests/api/system_hooks_spec.rb b/spec/requests/api/system_hooks_spec.rb index a9d86bbce6c..3e676515488 100644 --- a/spec/requests/api/system_hooks_spec.rb +++ b/spec/requests/api/system_hooks_spec.rb @@ -36,9 +36,9 @@ describe API::API, api: true do describe "POST /hooks" do it "should create new hook" do - expect { + expect do post api("/hooks", admin), url: 'http://example.com' - }.to change { SystemHook.count }.by(1) + end.to change { SystemHook.count }.by(1) end it "should respond with 400 if url not given" do @@ -47,9 +47,9 @@ describe API::API, api: true do end it "should not create new hook without url" do - expect { + expect do post api("/hooks", admin) - }.to_not change { SystemHook.count } + end.to_not change { SystemHook.count } end end @@ -68,9 +68,9 @@ describe API::API, api: true do describe "DELETE /hooks/:id" do it "should delete a hook" do - expect { + expect do delete api("/hooks/#{hook.id}", admin) - }.to change { SystemHook.count }.by(-1) + end.to change { SystemHook.count }.by(-1) end it "should return success if hook id not found" do 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 |