Commit 7b9b3c5a authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Fix part of api specs for rubocop

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent cf259cdb
...@@ -4,20 +4,20 @@ describe API::API, api: true do ...@@ -4,20 +4,20 @@ describe API::API, api: true do
include ApiHelpers include ApiHelpers
let!(:user) { create(:user) } let!(:user) { create(:user) }
let!(:application) { Doorkeeper::Application.create!(:name => "MyApp", :redirect_uri => "https://app.com", :owner => 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!(:token) { Doorkeeper::AccessToken.create! application_id: application.id, resource_owner_id: user.id }
describe "when unauthenticated" do describe "when unauthenticated" do
it "returns authentication success" 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) expect(response.status).to eq(200)
end end
end end
describe "when token invalid" do describe "when token invalid" do
it "returns authentication error" do it "returns authentication error" do
get api("/user"), :access_token => "123a" get api("/user"), access_token: "123a"
expect(response.status).to eq(401) expect(response.status).to eq(401)
end end
end end
......
...@@ -81,7 +81,7 @@ describe API::API, api: true do ...@@ -81,7 +81,7 @@ describe API::API, api: true do
end end
it 'should return the correct order when sorted by id' do 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(response.status).to eq(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first['id']).to eq(project3.id) expect(json_response.first['id']).to eq(project3.id)
...@@ -90,7 +90,7 @@ describe API::API, api: true do ...@@ -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 it 'returns projects in the correct order when ci_enabled_first parameter is passed' do
[project, project2, project3].each{ |project| project.build_missing_services } [project, project2, project3].each{ |project| project.build_missing_services }
project2.gitlab_ci_service.update(active: true, token: "token", project_url: "url") 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(response.status).to eq(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first['id']).to eq(project2.id) expect(json_response.first['id']).to eq(project2.id)
...@@ -123,13 +123,13 @@ describe API::API, api: true do ...@@ -123,13 +123,13 @@ describe API::API, api: true do
expect(json_response).to be_an Array expect(json_response).to be_an Array
project_name = project.name project_name = project.name
expect(json_response.detect { expect(json_response.detect do |project|
|project| project['name'] == project_name project['name'] == project_name
}['name']).to eq(project_name) end['name']).to eq(project_name)
expect(json_response.detect { expect(json_response.detect do |project|
|project| project['owner']['username'] == user.username project['owner']['username'] == user.username
}['owner']['username']).to eq(user.username) end['owner']['username']).to eq(user.username)
end end
end end
end end
...@@ -138,9 +138,9 @@ describe API::API, api: true do ...@@ -138,9 +138,9 @@ describe API::API, api: true do
context 'maximum number of projects reached' do context 'maximum number of projects reached' do
it 'should not create new project and respond with 403' 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) allow_any_instance_of(User).to receive(:projects_limit_left).and_return(0)
expect { expect do
post api('/projects', user2), name: 'foo' 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) expect(response.status).to eq(403)
end end
end end
...@@ -474,9 +474,9 @@ describe API::API, api: true do ...@@ -474,9 +474,9 @@ describe API::API, api: true do
before { snippet } before { snippet }
it 'should delete existing project snippet' do it 'should delete existing project snippet' do
expect { expect do
delete api("/projects/#{project.id}/snippets/#{snippet.id}", user) 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) expect(response.status).to eq(200)
end end
...@@ -548,9 +548,9 @@ describe API::API, api: true do ...@@ -548,9 +548,9 @@ describe API::API, api: true do
it 'should create new ssh key' do it 'should create new ssh key' do
key_attrs = attributes_for :key key_attrs = attributes_for :key
expect { expect do
post api("/projects/#{project.id}/keys", user), key_attrs 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
end end
...@@ -558,9 +558,9 @@ describe API::API, api: true do ...@@ -558,9 +558,9 @@ describe API::API, api: true do
before { deploy_key } before { deploy_key }
it 'should delete existing key' do it 'should delete existing key' do
expect { expect do
delete api("/projects/#{project.id}/keys/#{deploy_key.id}", user) 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 end
it 'should return 404 Not Found with invalid ID' do it 'should return 404 Not Found with invalid ID' do
......
...@@ -36,9 +36,9 @@ describe API::API, api: true do ...@@ -36,9 +36,9 @@ describe API::API, api: true do
describe "POST /hooks" do describe "POST /hooks" do
it "should create new hook" do it "should create new hook" do
expect { expect do
post api("/hooks", admin), url: 'http://example.com' post api("/hooks", admin), url: 'http://example.com'
}.to change { SystemHook.count }.by(1) end.to change { SystemHook.count }.by(1)
end end
it "should respond with 400 if url not given" do it "should respond with 400 if url not given" do
...@@ -47,9 +47,9 @@ describe API::API, api: true do ...@@ -47,9 +47,9 @@ describe API::API, api: true do
end end
it "should not create new hook without url" do it "should not create new hook without url" do
expect { expect do
post api("/hooks", admin) post api("/hooks", admin)
}.to_not change { SystemHook.count } end.to_not change { SystemHook.count }
end end
end end
...@@ -68,9 +68,9 @@ describe API::API, api: true do ...@@ -68,9 +68,9 @@ describe API::API, api: true do
describe "DELETE /hooks/:id" do describe "DELETE /hooks/:id" do
it "should delete a hook" do it "should delete a hook" do
expect { expect do
delete api("/hooks/#{hook.id}", admin) delete api("/hooks/#{hook.id}", admin)
}.to change { SystemHook.count }.by(-1) end.to change { SystemHook.count }.by(-1)
end end
it "should return success if hook id not found" do it "should return success if hook id not found" do
......
...@@ -21,9 +21,9 @@ describe API::API, api: true do ...@@ -21,9 +21,9 @@ describe API::API, api: true do
expect(response.status).to eq(200) expect(response.status).to eq(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
username = user.username username = user.username
expect(json_response.detect { expect(json_response.detect do |user|
|user| user['username'] == username user['username'] == username
}['username']).to eq(username) end['username']).to eq(username)
end end
end end
...@@ -62,9 +62,9 @@ describe API::API, api: true do ...@@ -62,9 +62,9 @@ describe API::API, api: true do
before{ admin } before{ admin }
it "should create user" do it "should create user" do
expect { expect do
post api("/users", admin), attributes_for(:user, projects_limit: 3) post api("/users", admin), attributes_for(:user, projects_limit: 3)
}.to change { User.count }.by(1) end.to change { User.count }.by(1)
end end
it "should create user with correct attributes" do it "should create user with correct attributes" do
...@@ -163,13 +163,13 @@ describe API::API, api: true do ...@@ -163,13 +163,13 @@ describe API::API, api: true do
end end
it 'should return 409 conflict error if user with same email exists' do it 'should return 409 conflict error if user with same email exists' do
expect { expect do
post api('/users', admin), post api('/users', admin),
name: 'foo', name: 'foo',
email: 'test@example.com', email: 'test@example.com',
password: 'password', password: 'password',
username: 'foo' username: 'foo'
}.to change { User.count }.by(0) end.to change { User.count }.by(0)
expect(response.status).to eq(409) expect(response.status).to eq(409)
expect(json_response['message']).to eq('Email has already been taken') expect(json_response['message']).to eq('Email has already been taken')
end end
...@@ -203,7 +203,7 @@ describe API::API, api: true do ...@@ -203,7 +203,7 @@ describe API::API, api: true do
before { admin } before { admin }
it "should update user with new bio" do 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(response.status).to eq(200)
expect(json_response['bio']).to eq('new test bio') expect(json_response['bio']).to eq('new test bio')
expect(user.reload.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 ...@@ -224,14 +224,14 @@ describe API::API, api: true do
end end
it "should update admin status" do 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(response.status).to eq(200)
expect(json_response['is_admin']).to eq(true) expect(json_response['is_admin']).to eq(true)
expect(user.reload.admin).to eq(true) expect(user.reload.admin).to eq(true)
end end
it "should not update admin status" do 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(response.status).to eq(200)
expect(json_response['is_admin']).to eq(true) expect(json_response['is_admin']).to eq(true)
expect(admin_user.reload.admin).to eq(true) expect(admin_user.reload.admin).to eq(true)
...@@ -239,7 +239,7 @@ describe API::API, api: true do ...@@ -239,7 +239,7 @@ describe API::API, api: true do
end end
it "should not allow invalid update" do 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(response.status).to eq(400)
expect(user.reload.email).not_to eq('invalid email') expect(user.reload.email).not_to eq('invalid email')
end end
...@@ -250,7 +250,7 @@ describe API::API, api: true do ...@@ -250,7 +250,7 @@ describe API::API, api: true do
end end
it "should return 404 for non-existing user" do 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(response.status).to eq(404)
expect(json_response['message']).to eq('404 Not found') expect(json_response['message']).to eq('404 Not found')
end end
...@@ -275,11 +275,11 @@ describe API::API, api: true do ...@@ -275,11 +275,11 @@ describe API::API, api: true do
end end
context "with existing user" do 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: 'test@example.com', password: 'password', username: 'test', name: 'test' }
post api("/users", admin), { email: 'foo@bar.com', password: 'password', username: 'john', name: 'john' } post api("/users", admin), { email: 'foo@bar.com', password: 'password', username: 'john', name: 'john' }
@user = User.all.last @user = User.all.last
} end
it 'should return 409 conflict error if email address exists' do it 'should return 409 conflict error if email address exists' do
put api("/users/#{@user.id}", admin), email: 'test@example.com' put api("/users/#{@user.id}", admin), email: 'test@example.com'
...@@ -313,9 +313,9 @@ describe API::API, api: true do ...@@ -313,9 +313,9 @@ describe API::API, api: true do
it "should create ssh key" do it "should create ssh key" do
key_attrs = attributes_for :key key_attrs = attributes_for :key
expect { expect do
post api("/users/#{user.id}/keys", admin), key_attrs 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
end end
...@@ -361,9 +361,9 @@ describe API::API, api: true do ...@@ -361,9 +361,9 @@ describe API::API, api: true do
it 'should delete existing key' do it 'should delete existing key' do
user.keys << key user.keys << key
user.save user.save
expect { expect do
delete api("/users/#{user.id}/keys/#{key.id}", admin) 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) expect(response.status).to eq(200)
end end
...@@ -475,9 +475,9 @@ describe API::API, api: true do ...@@ -475,9 +475,9 @@ describe API::API, api: true do
describe "POST /user/keys" do describe "POST /user/keys" do
it "should create ssh key" do it "should create ssh key" do
key_attrs = attributes_for :key key_attrs = attributes_for :key
expect { expect do
post api("/user/keys", user), key_attrs 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) expect(response.status).to eq(201)
end end
...@@ -508,9 +508,9 @@ describe API::API, api: true do ...@@ -508,9 +508,9 @@ describe API::API, api: true do
it "should delete existed key" do it "should delete existed key" do
user.keys << key user.keys << key
user.save user.save
expect { expect do
delete api("/user/keys/#{key.id}", user) 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) expect(response.status).to eq(200)
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment