Commit 298e4ece authored by Robert Speicher's avatar Robert Speicher

Merge branch 'regex-find-replace-http-matcher' into 'master'

Use `have_http_status` matcher where possible

See merge request !4955
parents 9c9b0eef abca19da
...@@ -22,7 +22,7 @@ describe Admin::ImpersonationsController do ...@@ -22,7 +22,7 @@ describe Admin::ImpersonationsController do
it "responds with status 404" do it "responds with status 404" do
delete :destroy delete :destroy
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
it "doesn't sign us in" do it "doesn't sign us in" do
...@@ -46,7 +46,7 @@ describe Admin::ImpersonationsController do ...@@ -46,7 +46,7 @@ describe Admin::ImpersonationsController do
it "responds with status 404" do it "responds with status 404" do
delete :destroy delete :destroy
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
it "doesn't sign us in as the impersonator" do it "doesn't sign us in as the impersonator" do
...@@ -65,7 +65,7 @@ describe Admin::ImpersonationsController do ...@@ -65,7 +65,7 @@ describe Admin::ImpersonationsController do
it "responds with status 404" do it "responds with status 404" do
delete :destroy delete :destroy
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
it "doesn't sign us in as the impersonator" do it "doesn't sign us in as the impersonator" do
......
...@@ -14,7 +14,7 @@ describe Admin::SpamLogsController do ...@@ -14,7 +14,7 @@ describe Admin::SpamLogsController do
it 'lists all spam logs' do it 'lists all spam logs' do
get :index get :index
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
end end
...@@ -22,14 +22,14 @@ describe Admin::SpamLogsController do ...@@ -22,14 +22,14 @@ describe Admin::SpamLogsController do
it 'removes only the spam log when removing log' do it 'removes only the spam log when removing log' do
expect { delete :destroy, id: first_spam.id }.to change { SpamLog.count }.by(-1) expect { delete :destroy, id: first_spam.id }.to change { SpamLog.count }.by(-1)
expect(User.find(user.id)).to be_truthy expect(User.find(user.id)).to be_truthy
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
it 'removes user and his spam logs when removing the user' do it 'removes user and his spam logs when removing the user' do
delete :destroy, id: first_spam.id, remove_user: true delete :destroy, id: first_spam.id, remove_user: true
expect(flash[:notice]).to eq "User #{user.username} was successfully removed." expect(flash[:notice]).to eq "User #{user.username} was successfully removed."
expect(response.status).to eq(302) expect(response).to have_http_status(302)
expect(SpamLog.count).to eq(0) expect(SpamLog.count).to eq(0)
expect { User.find(user.id) }.to raise_error(ActiveRecord::RecordNotFound) expect { User.find(user.id) }.to raise_error(ActiveRecord::RecordNotFound)
end end
......
...@@ -17,7 +17,7 @@ describe Admin::UsersController do ...@@ -17,7 +17,7 @@ describe Admin::UsersController do
it 'deletes user' do it 'deletes user' do
delete :destroy, id: user.username, format: :json delete :destroy, id: user.username, format: :json
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect { User.find(user.id) }.to raise_exception(ActiveRecord::RecordNotFound) expect { User.find(user.id) }.to raise_exception(ActiveRecord::RecordNotFound)
end end
end end
......
...@@ -44,7 +44,7 @@ describe ApplicationController do ...@@ -44,7 +44,7 @@ describe ApplicationController do
context "when the 'private_token' param is populated with the private token" do context "when the 'private_token' param is populated with the private token" do
it "logs the user in" do it "logs the user in" do
get :index, private_token: user.private_token get :index, private_token: user.private_token
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(response.body).to eq("authenticated") expect(response.body).to eq("authenticated")
end end
end end
...@@ -54,7 +54,7 @@ describe ApplicationController do ...@@ -54,7 +54,7 @@ describe ApplicationController do
it "logs the user in" do it "logs the user in" do
@request.headers['PRIVATE-TOKEN'] = user.private_token @request.headers['PRIVATE-TOKEN'] = user.private_token
get :index get :index
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(response.body).to eq("authenticated") expect(response.body).to eq("authenticated")
end end
end end
...@@ -80,7 +80,7 @@ describe ApplicationController do ...@@ -80,7 +80,7 @@ describe ApplicationController do
context "when the 'personal_access_token' param is populated with the personal access token" do context "when the 'personal_access_token' param is populated with the personal access token" do
it "logs the user in" do it "logs the user in" do
get :index, private_token: personal_access_token.token get :index, private_token: personal_access_token.token
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(response.body).to eq('authenticated') expect(response.body).to eq('authenticated')
end end
end end
...@@ -89,7 +89,7 @@ describe ApplicationController do ...@@ -89,7 +89,7 @@ describe ApplicationController do
it "logs the user in" do it "logs the user in" do
@request.headers["PRIVATE-TOKEN"] = personal_access_token.token @request.headers["PRIVATE-TOKEN"] = personal_access_token.token
get :index get :index
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(response.body).to eq('authenticated') expect(response.body).to eq('authenticated')
end end
end end
......
...@@ -29,7 +29,7 @@ describe AutocompleteController do ...@@ -29,7 +29,7 @@ describe AutocompleteController do
get(:users, project_id: 'unknown') get(:users, project_id: 'unknown')
end end
it { expect(response.status).to eq(404) } it { expect(response).to have_http_status(404) }
end end
end end
...@@ -58,7 +58,7 @@ describe AutocompleteController do ...@@ -58,7 +58,7 @@ describe AutocompleteController do
get(:users, group_id: 'unknown') get(:users, group_id: 'unknown')
end end
it { expect(response.status).to eq(404) } it { expect(response).to have_http_status(404) }
end end
end end
...@@ -114,7 +114,7 @@ describe AutocompleteController do ...@@ -114,7 +114,7 @@ describe AutocompleteController do
get(:users, project_id: project.id) get(:users, project_id: project.id)
end end
it { expect(response.status).to eq(404) } it { expect(response).to have_http_status(404) }
end end
describe 'GET #users with unknown project' do describe 'GET #users with unknown project' do
...@@ -122,7 +122,7 @@ describe AutocompleteController do ...@@ -122,7 +122,7 @@ describe AutocompleteController do
get(:users, project_id: 'unknown') get(:users, project_id: 'unknown')
end end
it { expect(response.status).to eq(404) } it { expect(response).to have_http_status(404) }
end end
describe 'GET #users with inaccessible group' do describe 'GET #users with inaccessible group' do
...@@ -131,7 +131,7 @@ describe AutocompleteController do ...@@ -131,7 +131,7 @@ describe AutocompleteController do
get(:users, group_id: user.namespace.id) get(:users, group_id: user.namespace.id)
end end
it { expect(response.status).to eq(404) } it { expect(response).to have_http_status(404) }
end end
describe 'GET #users with no project' do describe 'GET #users with no project' do
......
...@@ -155,7 +155,7 @@ describe Projects::CommitController do ...@@ -155,7 +155,7 @@ describe Projects::CommitController do
id: commit.id) id: commit.id)
expect(response).not_to be_success expect(response).not_to be_success
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
...@@ -204,7 +204,7 @@ describe Projects::CommitController do ...@@ -204,7 +204,7 @@ describe Projects::CommitController do
id: master_pickable_commit.id) id: master_pickable_commit.id)
expect(response).not_to be_success expect(response).not_to be_success
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
......
...@@ -13,7 +13,7 @@ describe Groups::GroupMembersController do ...@@ -13,7 +13,7 @@ describe Groups::GroupMembersController do
it 'renders index with group members' do it 'renders index with group members' do
get :index, group_id: group get :index, group_id: group
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(response).to render_template(:index) expect(response).to render_template(:index)
end end
end end
...@@ -26,7 +26,7 @@ describe Groups::GroupMembersController do ...@@ -26,7 +26,7 @@ describe Groups::GroupMembersController do
delete :destroy, group_id: group, delete :destroy, group_id: group,
id: 42 id: 42
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
end end
...@@ -48,7 +48,7 @@ describe Groups::GroupMembersController do ...@@ -48,7 +48,7 @@ describe Groups::GroupMembersController do
delete :destroy, group_id: group, delete :destroy, group_id: group,
id: member id: member
expect(response.status).to eq(403) expect(response).to have_http_status(403)
expect(group.users).to include group_user expect(group.users).to include group_user
end end
end end
...@@ -89,7 +89,7 @@ describe Groups::GroupMembersController do ...@@ -89,7 +89,7 @@ describe Groups::GroupMembersController do
it 'returns 403' do it 'returns 403' do
delete :leave, group_id: group delete :leave, group_id: group
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
end end
...@@ -118,7 +118,7 @@ describe Groups::GroupMembersController do ...@@ -118,7 +118,7 @@ describe Groups::GroupMembersController do
it 'cannot removes himself from the group' do it 'cannot removes himself from the group' do
delete :leave, group_id: group delete :leave, group_id: group
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
end end
...@@ -166,7 +166,7 @@ describe Groups::GroupMembersController do ...@@ -166,7 +166,7 @@ describe Groups::GroupMembersController do
post :approve_access_request, group_id: group, post :approve_access_request, group_id: group,
id: 42 id: 42
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
end end
...@@ -188,7 +188,7 @@ describe Groups::GroupMembersController do ...@@ -188,7 +188,7 @@ describe Groups::GroupMembersController do
post :approve_access_request, group_id: group, post :approve_access_request, group_id: group,
id: member id: member
expect(response.status).to eq(403) expect(response).to have_http_status(403)
expect(group.users).not_to include group_requester expect(group.users).not_to include group_requester
end end
end end
......
...@@ -65,21 +65,21 @@ describe HealthCheckController do ...@@ -65,21 +65,21 @@ describe HealthCheckController do
it 'supports passing the token in the header' do it 'supports passing the token in the header' do
request.headers['TOKEN'] = token request.headers['TOKEN'] = token
get :index get :index
expect(response.status).to eq(500) expect(response).to have_http_status(500)
expect(response.content_type).to eq 'text/plain' expect(response.content_type).to eq 'text/plain'
expect(response.body).to include('The server is on fire') expect(response.body).to include('The server is on fire')
end end
it 'supports failure plaintest response' do it 'supports failure plaintest response' do
get :index, token: token get :index, token: token
expect(response.status).to eq(500) expect(response).to have_http_status(500)
expect(response.content_type).to eq 'text/plain' expect(response.content_type).to eq 'text/plain'
expect(response.body).to include('The server is on fire') expect(response.body).to include('The server is on fire')
end end
it 'supports failure json response' do it 'supports failure json response' do
get :index, token: token, format: :json get :index, token: token, format: :json
expect(response.status).to eq(500) expect(response).to have_http_status(500)
expect(response.content_type).to eq 'application/json' expect(response.content_type).to eq 'application/json'
expect(json_response['healthy']).to be false expect(json_response['healthy']).to be false
expect(json_response['message']).to include('The server is on fire') expect(json_response['message']).to include('The server is on fire')
...@@ -87,7 +87,7 @@ describe HealthCheckController do ...@@ -87,7 +87,7 @@ describe HealthCheckController do
it 'supports failure xml response' do it 'supports failure xml response' do
get :index, token: token, format: :xml get :index, token: token, format: :xml
expect(response.status).to eq(500) expect(response).to have_http_status(500)
expect(response.content_type).to eq 'application/xml' expect(response.content_type).to eq 'application/xml'
expect(xml_response['healthy']).to be false expect(xml_response['healthy']).to be false
expect(xml_response['message']).to include('The server is on fire') expect(xml_response['message']).to include('The server is on fire')
...@@ -95,7 +95,7 @@ describe HealthCheckController do ...@@ -95,7 +95,7 @@ describe HealthCheckController do
it 'supports failure responses for specific checks' do it 'supports failure responses for specific checks' do
get :index, token: token, checks: 'email', format: :json get :index, token: token, checks: 'email', format: :json
expect(response.status).to eq(500) expect(response).to have_http_status(500)
expect(response.content_type).to eq 'application/json' expect(response.content_type).to eq 'application/json'
expect(json_response['healthy']).to be false expect(json_response['healthy']).to be false
expect(json_response['message']).to include('Email is on fire') expect(json_response['message']).to include('Email is on fire')
......
...@@ -15,7 +15,7 @@ describe InvitesController do ...@@ -15,7 +15,7 @@ describe InvitesController do
get :accept, id: token get :accept, id: token
member.reload member.reload
expect(response.status).to eq(302) expect(response).to have_http_status(302)
expect(member.user).to eq(user) expect(member.user).to eq(user)
expect(flash[:notice]).to include 'You have been granted' expect(flash[:notice]).to include 'You have been granted'
end end
...@@ -26,7 +26,7 @@ describe InvitesController do ...@@ -26,7 +26,7 @@ describe InvitesController do
get :decline, id: token get :decline, id: token
expect{member.reload}.to raise_error ActiveRecord::RecordNotFound expect{member.reload}.to raise_error ActiveRecord::RecordNotFound
expect(response.status).to eq(302) expect(response).to have_http_status(302)
expect(flash[:notice]).to include 'You have declined the invitation to join' expect(flash[:notice]).to include 'You have declined the invitation to join'
end end
end end
......
...@@ -86,7 +86,7 @@ describe NamespacesController do ...@@ -86,7 +86,7 @@ describe NamespacesController do
it "responds with status 404" do it "responds with status 404" do
get :show, id: group.path get :show, id: group.path
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
end end
...@@ -102,7 +102,7 @@ describe NamespacesController do ...@@ -102,7 +102,7 @@ describe NamespacesController do
it "responds with status 404" do it "responds with status 404" do
get :show, id: "doesntexist" get :show, id: "doesntexist"
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
......
...@@ -60,7 +60,7 @@ describe NotificationSettingsController do ...@@ -60,7 +60,7 @@ describe NotificationSettingsController do
project: { id: private_project.id }, project: { id: private_project.id },
notification_setting: { level: :participating } notification_setting: { level: :participating }
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
end end
...@@ -118,7 +118,7 @@ describe NotificationSettingsController do ...@@ -118,7 +118,7 @@ describe NotificationSettingsController do
id: notification_setting, id: notification_setting,
notification_setting: { level: :participating } notification_setting: { level: :participating }
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
end end
......
...@@ -12,7 +12,7 @@ describe Oauth::ApplicationsController do ...@@ -12,7 +12,7 @@ describe Oauth::ApplicationsController do
it 'shows list of applications' do it 'shows list of applications' do
get :index get :index
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
it 'redirects back to profile page if OAuth applications are disabled' do it 'redirects back to profile page if OAuth applications are disabled' do
...@@ -21,7 +21,7 @@ describe Oauth::ApplicationsController do ...@@ -21,7 +21,7 @@ describe Oauth::ApplicationsController do
get :index get :index
expect(response.status).to eq(302) expect(response).to have_http_status(302)
expect(response).to redirect_to(profile_path) expect(response).to redirect_to(profile_path)
end end
end end
......
...@@ -13,7 +13,7 @@ describe Profiles::AccountsController do ...@@ -13,7 +13,7 @@ describe Profiles::AccountsController do
delete :unlink, provider: 'saml' delete :unlink, provider: 'saml'
updated_user = User.find(user.id) updated_user = User.find(user.id)
expect(response.status).to eq(302) expect(response).to have_http_status(302)
expect(updated_user.identities.size).to eq(1) expect(updated_user.identities.size).to eq(1)
expect(updated_user.identities).to include(identity) expect(updated_user.identities).to include(identity)
end end
......
...@@ -103,7 +103,7 @@ describe Projects::BranchesController do ...@@ -103,7 +103,7 @@ describe Projects::BranchesController do
namespace_id: project.namespace.to_param, namespace_id: project.namespace.to_param,
project_id: project.to_param project_id: project.to_param
expect(response.status).to eq(303) expect(response).to have_http_status(303)
end end
end end
...@@ -121,24 +121,24 @@ describe Projects::BranchesController do ...@@ -121,24 +121,24 @@ describe Projects::BranchesController do
context "valid branch name, valid source" do context "valid branch name, valid source" do
let(:branch) { "feature" } let(:branch) { "feature" }
it { expect(response.status).to eq(200) } it { expect(response).to have_http_status(200) }
end end
context "valid branch name with unencoded slashes" do context "valid branch name with unencoded slashes" do
let(:branch) { "improve/awesome" } let(:branch) { "improve/awesome" }
it { expect(response.status).to eq(200) } it { expect(response).to have_http_status(200) }
end end
context "valid branch name with encoded slashes" do context "valid branch name with encoded slashes" do
let(:branch) { "improve%2Fawesome" } let(:branch) { "improve%2Fawesome" }
it { expect(response.status).to eq(200) } it { expect(response).to have_http_status(200) }
end end
context "invalid branch name, valid ref" do context "invalid branch name, valid ref" do
let(:branch) { "no-branch" } let(:branch) { "no-branch" }
it { expect(response.status).to eq(404) } it { expect(response).to have_http_status(404) }
end end
end end
end end
...@@ -14,7 +14,7 @@ describe Projects::IssuesController do ...@@ -14,7 +14,7 @@ describe Projects::IssuesController do
it "returns index" do it "returns index" do
get :index, namespace_id: project.namespace.path, project_id: project.path get :index, namespace_id: project.namespace.path, project_id: project.path
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
it "return 301 if request path doesn't match project path" do it "return 301 if request path doesn't match project path" do
...@@ -28,7 +28,7 @@ describe Projects::IssuesController do ...@@ -28,7 +28,7 @@ describe Projects::IssuesController do
project.save project.save
get :index, namespace_id: project.namespace.path, project_id: project.path get :index, namespace_id: project.namespace.path, project_id: project.path
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
it "returns 404 when external issue tracker is enabled" do it "returns 404 when external issue tracker is enabled" do
...@@ -36,7 +36,7 @@ describe Projects::IssuesController do ...@@ -36,7 +36,7 @@ describe Projects::IssuesController do
allow(project).to receive(:default_issues_tracker?).and_return(false) allow(project).to receive(:default_issues_tracker?).and_return(false)
get :index, namespace_id: project.namespace.path, project_id: project.path get :index, namespace_id: project.namespace.path, project_id: project.path
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
...@@ -248,7 +248,7 @@ describe Projects::IssuesController do ...@@ -248,7 +248,7 @@ describe Projects::IssuesController do
before { sign_in(user) } before { sign_in(user) }
it "rejects a developer to destroy an issue" do it "rejects a developer to destroy an issue" do
delete :destroy, namespace_id: project.namespace.path, project_id: project.path, id: issue.iid delete :destroy, namespace_id: project.namespace.path, project_id: project.path, id: issue.iid
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
...@@ -262,7 +262,7 @@ describe Projects::IssuesController do ...@@ -262,7 +262,7 @@ describe Projects::IssuesController do
it "deletes the issue" do it "deletes the issue" do
delete :destroy, namespace_id: project.namespace.path, project_id: project.path, id: issue.iid delete :destroy, namespace_id: project.namespace.path, project_id: project.path, id: issue.iid
expect(response.status).to eq(302) expect(response).to have_http_status(302)
expect(controller).to set_flash[:notice].to(/The issue was successfully deleted\./).now expect(controller).to set_flash[:notice].to(/The issue was successfully deleted\./).now
end end
end end
...@@ -280,7 +280,7 @@ describe Projects::IssuesController do ...@@ -280,7 +280,7 @@ describe Projects::IssuesController do
project_id: project.path, id: issue.iid, name: "thumbsup") project_id: project.path, id: issue.iid, name: "thumbsup")
end.to change { issue.award_emoji.count }.by(1) end.to change { issue.award_emoji.count }.by(1)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
end end
end end
...@@ -284,7 +284,7 @@ describe Projects::MergeRequestsController do ...@@ -284,7 +284,7 @@ describe Projects::MergeRequestsController do
it "denies access to users unless they're admin or project owner" do it "denies access to users unless they're admin or project owner" do
delete :destroy, namespace_id: project.namespace.path, project_id: project.path, id: merge_request.iid delete :destroy, namespace_id: project.namespace.path, project_id: project.path, id: merge_request.iid
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
context "when the user is owner" do context "when the user is owner" do
...@@ -297,7 +297,7 @@ describe Projects::MergeRequestsController do ...@@ -297,7 +297,7 @@ describe Projects::MergeRequestsController do
it "deletes the merge request" do it "deletes the merge request" do
delete :destroy, namespace_id: project.namespace.path, project_id: project.path, id: merge_request.iid delete :destroy, namespace_id: project.namespace.path, project_id: project.path, id: merge_request.iid
expect(response.status).to eq(302) expect(response).to have_http_status(302)
expect(controller).to set_flash[:notice].to(/The merge request was successfully deleted\./).now expect(controller).to set_flash[:notice].to(/The merge request was successfully deleted\./).now
end end
end end
......
...@@ -18,7 +18,7 @@ describe Projects::NotesController do ...@@ -18,7 +18,7 @@ describe Projects::NotesController do
project_id: project.path, id: note.id, name: "thumbsup") project_id: project.path, id: note.id, name: "thumbsup")
end.to change { note.award_emoji.count }.by(1) end.to change { note.award_emoji.count }.by(1)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
it "removes the already awarded emoji" do it "removes the already awarded emoji" do
...@@ -30,7 +30,7 @@ describe Projects::NotesController do ...@@ -30,7 +30,7 @@ describe Projects::NotesController do
project_id: project.path, id: note.id, name: "thumbsup") project_id: project.path, id: note.id, name: "thumbsup")
end.to change { AwardEmoji.count }.by(-1) end.to change { AwardEmoji.count }.by(-1)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
end end
end end
...@@ -58,7 +58,7 @@ describe Projects::ProjectMembersController do ...@@ -58,7 +58,7 @@ describe Projects::ProjectMembersController do
get :index, namespace_id: project.namespace, project_id: project get :index, namespace_id: project.namespace, project_id: project
end end
it { expect(response.status).to eq(200) } it { expect(response).to have_http_status(200) }
end end
end end
...@@ -71,7 +71,7 @@ describe Projects::ProjectMembersController do ...@@ -71,7 +71,7 @@ describe Projects::ProjectMembersController do
project_id: project, project_id: project,
id: 42 id: 42
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
...@@ -94,7 +94,7 @@ describe Projects::ProjectMembersController do ...@@ -94,7 +94,7 @@ describe Projects::ProjectMembersController do
project_id: project, project_id: project,
id: member id: member
expect(response.status).to eq(404) expect(response).to have_http_status(404)
expect(project.users).to include team_user expect(project.users).to include team_user
end end
end end
...@@ -139,7 +139,7 @@ describe Projects::ProjectMembersController do ...@@ -139,7 +139,7 @@ describe Projects::ProjectMembersController do
delete :leave, namespace_id: project.namespace, delete :leave, namespace_id: project.namespace,
project_id: project project_id: project
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
end end
...@@ -171,7 +171,7 @@ describe Projects::ProjectMembersController do ...@@ -171,7 +171,7 @@ describe Projects::ProjectMembersController do
delete :leave, namespace_id: project.namespace, delete :leave, namespace_id: project.namespace,
project_id: project project_id: project
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
end end
...@@ -224,7 +224,7 @@ describe Projects::ProjectMembersController do ...@@ -224,7 +224,7 @@ describe Projects::ProjectMembersController do
project_id: project, project_id: project,
id: 42 id: 42
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
...@@ -247,7 +247,7 @@ describe Projects::ProjectMembersController do ...@@ -247,7 +247,7 @@ describe Projects::ProjectMembersController do
project_id: project, project_id: project,
id: member id: member
expect(response.status).to eq(404) expect(response).to have_http_status(404)
expect(project.users).not_to include team_requester expect(project.users).not_to include team_requester
end end
end end
......
...@@ -13,7 +13,7 @@ describe Projects::RawController do ...@@ -13,7 +13,7 @@ describe Projects::RawController do
project_id: public_project.to_param, project_id: public_project.to_param,
id: id) id: id)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(response.header['Content-Type']).to eq('text/plain; charset=utf-8') expect(response.header['Content-Type']).to eq('text/plain; charset=utf-8')
expect(response.header['Content-Disposition']). expect(response.header['Content-Disposition']).
to eq("inline") to eq("inline")
...@@ -30,7 +30,7 @@ describe Projects::RawController do ...@@ -30,7 +30,7 @@ describe Projects::RawController do
project_id: public_project.to_param, project_id: public_project.to_param,
id: id) id: id)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(response.header['Content-Type']).to eq('image/jpeg') expect(response.header['Content-Type']).to eq('image/jpeg')
expect(response.header[Gitlab::Workhorse::SEND_DATA_HEADER]).to start_with("git-blob:") expect(response.header[Gitlab::Workhorse::SEND_DATA_HEADER]).to start_with("git-blob:")
end end
...@@ -54,7 +54,7 @@ describe Projects::RawController do ...@@ -54,7 +54,7 @@ describe Projects::RawController do
project_id: public_project.to_param, project_id: public_project.to_param,
id: id) id: id)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
end end
...@@ -65,7 +65,7 @@ describe Projects::RawController do ...@@ -65,7 +65,7 @@ describe Projects::RawController do
project_id: public_project.to_param, project_id: public_project.to_param,
id: id) id: id)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
end end
......
...@@ -36,7 +36,7 @@ describe Projects::RepositoriesController do ...@@ -36,7 +36,7 @@ describe Projects::RepositoriesController do
it "renders Not Found" do it "renders Not Found" do
get :archive, namespace_id: project.namespace.path, project_id: project.path, ref: "master", format: "zip" get :archive, namespace_id: project.namespace.path, project_id: project.path, ref: "master", format: "zip"
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
end end
......
...@@ -19,7 +19,7 @@ describe Projects::SnippetsController do ...@@ -19,7 +19,7 @@ describe Projects::SnippetsController do
get :index, namespace_id: project.namespace.path, project_id: project.path get :index, namespace_id: project.namespace.path, project_id: project.path
expect(assigns(:snippets)).not_to include(project_snippet) expect(assigns(:snippets)).not_to include(project_snippet)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
end end
...@@ -30,7 +30,7 @@ describe Projects::SnippetsController do ...@@ -30,7 +30,7 @@ describe Projects::SnippetsController do
get :index, namespace_id: project.namespace.path, project_id: project.path get :index, namespace_id: project.namespace.path, project_id: project.path
expect(assigns(:snippets)).to include(project_snippet) expect(assigns(:snippets)).to include(project_snippet)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
end end
...@@ -41,7 +41,7 @@ describe Projects::SnippetsController do ...@@ -41,7 +41,7 @@ describe Projects::SnippetsController do
get :index, namespace_id: project.namespace.path, project_id: project.path get :index, namespace_id: project.namespace.path, project_id: project.path
expect(assigns(:snippets)).to include(project_snippet) expect(assigns(:snippets)).to include(project_snippet)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
end end
end end
...@@ -56,7 +56,7 @@ describe Projects::SnippetsController do ...@@ -56,7 +56,7 @@ describe Projects::SnippetsController do
it 'responds with status 404' do it 'responds with status 404' do
get action, namespace_id: project.namespace.path, project_id: project.path, id: project_snippet.to_param get action, namespace_id: project.namespace.path, project_id: project.path, id: project_snippet.to_param
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
...@@ -67,7 +67,7 @@ describe Projects::SnippetsController do ...@@ -67,7 +67,7 @@ describe Projects::SnippetsController do
get action, namespace_id: project.namespace.path, project_id: project.path, id: project_snippet.to_param get action, namespace_id: project.namespace.path, project_id: project.path, id: project_snippet.to_param
expect(assigns(:snippet)).to eq(project_snippet) expect(assigns(:snippet)).to eq(project_snippet)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
end end
...@@ -78,7 +78,7 @@ describe Projects::SnippetsController do ...@@ -78,7 +78,7 @@ describe Projects::SnippetsController do
get action, namespace_id: project.namespace.path, project_id: project.path, id: project_snippet.to_param get action, namespace_id: project.namespace.path, project_id: project.path, id: project_snippet.to_param
expect(assigns(:snippet)).to eq(project_snippet) expect(assigns(:snippet)).to eq(project_snippet)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
end end
end end
...@@ -88,7 +88,7 @@ describe Projects::SnippetsController do ...@@ -88,7 +88,7 @@ describe Projects::SnippetsController do
it 'responds with status 404' do it 'responds with status 404' do
get action, namespace_id: project.namespace.path, project_id: project.path, id: 42 get action, namespace_id: project.namespace.path, project_id: project.path, id: 42
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
...@@ -98,7 +98,7 @@ describe Projects::SnippetsController do ...@@ -98,7 +98,7 @@ describe Projects::SnippetsController do
it 'responds with status 404' do it 'responds with status 404' do
get action, namespace_id: project.namespace.path, project_id: project.path, id: 42 get action, namespace_id: project.namespace.path, project_id: project.path, id: 42
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
end end
......
...@@ -22,7 +22,7 @@ describe Projects::TodosController do ...@@ -22,7 +22,7 @@ describe Projects::TodosController do
issuable_type: 'issue') issuable_type: 'issue')
end.to change { user.todos.count }.by(1) end.to change { user.todos.count }.by(1)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
end end
...@@ -36,7 +36,7 @@ describe Projects::TodosController do ...@@ -36,7 +36,7 @@ describe Projects::TodosController do
issuable_type: 'issue') issuable_type: 'issue')
end.to change { user.todos.count }.by(0) end.to change { user.todos.count }.by(0)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
it 'should not create todo for issue when user not logged in' do it 'should not create todo for issue when user not logged in' do
...@@ -47,7 +47,7 @@ describe Projects::TodosController do ...@@ -47,7 +47,7 @@ describe Projects::TodosController do
issuable_type: 'issue') issuable_type: 'issue')
end.to change { user.todos.count }.by(0) end.to change { user.todos.count }.by(0)
expect(response.status).to eq(302) expect(response).to have_http_status(302)
end end
end end
end end
...@@ -69,7 +69,7 @@ describe Projects::TodosController do ...@@ -69,7 +69,7 @@ describe Projects::TodosController do
issuable_type: 'merge_request') issuable_type: 'merge_request')
end.to change { user.todos.count }.by(1) end.to change { user.todos.count }.by(1)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
end end
...@@ -83,7 +83,7 @@ describe Projects::TodosController do ...@@ -83,7 +83,7 @@ describe Projects::TodosController do
issuable_type: 'merge_request') issuable_type: 'merge_request')
end.to change { user.todos.count }.by(0) end.to change { user.todos.count }.by(0)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
it 'should not create todo for merge request user has no access to' do it 'should not create todo for merge request user has no access to' do
...@@ -94,7 +94,7 @@ describe Projects::TodosController do ...@@ -94,7 +94,7 @@ describe Projects::TodosController do
issuable_type: 'merge_request') issuable_type: 'merge_request')
end.to change { user.todos.count }.by(0) end.to change { user.todos.count }.by(0)
expect(response.status).to eq(302) expect(response).to have_http_status(302)
end end
end end
end end
......
...@@ -64,7 +64,7 @@ describe Projects::TreeController do ...@@ -64,7 +64,7 @@ describe Projects::TreeController do
context "valid SHA commit ID with path" do context "valid SHA commit ID with path" do
let(:id) { '6d39438/.gitignore' } let(:id) { '6d39438/.gitignore' }
it { expect(response.status).to eq(302) } it { expect(response).to have_http_status(302) }
end end
end end
......
...@@ -18,7 +18,7 @@ describe Projects::UploadsController do ...@@ -18,7 +18,7 @@ describe Projects::UploadsController do
namespace_id: project.namespace.to_param, namespace_id: project.namespace.to_param,
project_id: project.to_param, project_id: project.to_param,
format: :json format: :json
expect(response.status).to eq(422) expect(response).to have_http_status(422)
end end
end end
...@@ -79,7 +79,7 @@ describe Projects::UploadsController do ...@@ -79,7 +79,7 @@ describe Projects::UploadsController do
it "responds with status 200" do it "responds with status 200" do
go go
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
end end
...@@ -87,7 +87,7 @@ describe Projects::UploadsController do ...@@ -87,7 +87,7 @@ describe Projects::UploadsController do
it "responds with status 404" do it "responds with status 404" do
go go
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
end end
...@@ -106,7 +106,7 @@ describe Projects::UploadsController do ...@@ -106,7 +106,7 @@ describe Projects::UploadsController do
it "responds with status 200" do it "responds with status 200" do
go go
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
end end
...@@ -114,7 +114,7 @@ describe Projects::UploadsController do ...@@ -114,7 +114,7 @@ describe Projects::UploadsController do
it "responds with status 404" do it "responds with status 404" do
go go
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
end end
...@@ -140,7 +140,7 @@ describe Projects::UploadsController do ...@@ -140,7 +140,7 @@ describe Projects::UploadsController do
it "responds with status 200" do it "responds with status 200" do
go go
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
end end
...@@ -192,7 +192,7 @@ describe Projects::UploadsController do ...@@ -192,7 +192,7 @@ describe Projects::UploadsController do
it "responds with status 200" do it "responds with status 200" do
go go
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
end end
...@@ -224,7 +224,7 @@ describe Projects::UploadsController do ...@@ -224,7 +224,7 @@ describe Projects::UploadsController do
it "responds with status 200" do it "responds with status 200" do
go go
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
end end
...@@ -232,7 +232,7 @@ describe Projects::UploadsController do ...@@ -232,7 +232,7 @@ describe Projects::UploadsController do
it "responds with status 404" do it "responds with status 404" do
go go
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
end end
...@@ -253,7 +253,7 @@ describe Projects::UploadsController do ...@@ -253,7 +253,7 @@ describe Projects::UploadsController do
it "responds with status 200" do it "responds with status 200" do
go go
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
end end
...@@ -261,7 +261,7 @@ describe Projects::UploadsController do ...@@ -261,7 +261,7 @@ describe Projects::UploadsController do
it "responds with status 404" do it "responds with status 404" do
go go
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
end end
...@@ -270,7 +270,7 @@ describe Projects::UploadsController do ...@@ -270,7 +270,7 @@ describe Projects::UploadsController do
it "responds with status 404" do it "responds with status 404" do
go go
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
end end
......
...@@ -77,7 +77,7 @@ describe ProjectsController do ...@@ -77,7 +77,7 @@ describe ProjectsController do
get :show, namespace_id: public_project.namespace.path, id: public_project.path get :show, namespace_id: public_project.namespace.path, id: public_project.path
expect(assigns(:project)).to eq(public_project) expect(assigns(:project)).to eq(public_project)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
end end
...@@ -101,7 +101,7 @@ describe ProjectsController do ...@@ -101,7 +101,7 @@ describe ProjectsController do
get :show, namespace_id: public_project.namespace.path, id: public_project.path.upcase get :show, namespace_id: public_project.namespace.path, id: public_project.path.upcase
expect(assigns(:project)).to eq(other_project) expect(assigns(:project)).to eq(other_project)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
end end
end end
...@@ -146,7 +146,7 @@ describe ProjectsController do ...@@ -146,7 +146,7 @@ describe ProjectsController do
expect(project.repository.path).to include(new_path) expect(project.repository.path).to include(new_path)
expect(assigns(:repository).path).to eq(project.repository.path) expect(assigns(:repository).path).to eq(project.repository.path)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
end end
...@@ -161,7 +161,7 @@ describe ProjectsController do ...@@ -161,7 +161,7 @@ describe ProjectsController do
delete :destroy, namespace_id: project.namespace.path, id: project.path delete :destroy, namespace_id: project.namespace.path, id: project.path
expect { Project.find(orig_id) }.to raise_error(ActiveRecord::RecordNotFound) expect { Project.find(orig_id) }.to raise_error(ActiveRecord::RecordNotFound)
expect(response.status).to eq(302) expect(response).to have_http_status(302)
expect(response).to redirect_to(dashboard_projects_path) expect(response).to redirect_to(dashboard_projects_path)
end end
end end
...@@ -234,7 +234,7 @@ describe ProjectsController do ...@@ -234,7 +234,7 @@ describe ProjectsController do
delete(:remove_fork, delete(:remove_fork,
namespace_id: project.namespace.to_param, namespace_id: project.namespace.to_param,
id: project.to_param, format: :js) id: project.to_param, format: :js)
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
......
...@@ -19,7 +19,7 @@ describe SnippetsController do ...@@ -19,7 +19,7 @@ describe SnippetsController do
it 'responds with status 404' do it 'responds with status 404' do
get :show, id: other_personal_snippet.to_param get :show, id: other_personal_snippet.to_param
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
...@@ -28,7 +28,7 @@ describe SnippetsController do ...@@ -28,7 +28,7 @@ describe SnippetsController do
get :show, id: personal_snippet.to_param get :show, id: personal_snippet.to_param
expect(assigns(:snippet)).to eq(personal_snippet) expect(assigns(:snippet)).to eq(personal_snippet)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
end end
end end
...@@ -54,7 +54,7 @@ describe SnippetsController do ...@@ -54,7 +54,7 @@ describe SnippetsController do
get :show, id: personal_snippet.to_param get :show, id: personal_snippet.to_param
expect(assigns(:snippet)).to eq(personal_snippet) expect(assigns(:snippet)).to eq(personal_snippet)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
end end
...@@ -79,7 +79,7 @@ describe SnippetsController do ...@@ -79,7 +79,7 @@ describe SnippetsController do
get :show, id: personal_snippet.to_param get :show, id: personal_snippet.to_param
expect(assigns(:snippet)).to eq(personal_snippet) expect(assigns(:snippet)).to eq(personal_snippet)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
end end
...@@ -88,7 +88,7 @@ describe SnippetsController do ...@@ -88,7 +88,7 @@ describe SnippetsController do
get :show, id: personal_snippet.to_param get :show, id: personal_snippet.to_param
expect(assigns(:snippet)).to eq(personal_snippet) expect(assigns(:snippet)).to eq(personal_snippet)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
end end
end end
...@@ -102,7 +102,7 @@ describe SnippetsController do ...@@ -102,7 +102,7 @@ describe SnippetsController do
it 'responds with status 404' do it 'responds with status 404' do
get :show, id: 'doesntexist' get :show, id: 'doesntexist'
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
...@@ -110,7 +110,7 @@ describe SnippetsController do ...@@ -110,7 +110,7 @@ describe SnippetsController do
it 'responds with status 404' do it 'responds with status 404' do
get :show, id: 'doesntexist' get :show, id: 'doesntexist'
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
end end
...@@ -134,7 +134,7 @@ describe SnippetsController do ...@@ -134,7 +134,7 @@ describe SnippetsController do
it 'responds with status 404' do it 'responds with status 404' do
get :raw, id: other_personal_snippet.to_param get :raw, id: other_personal_snippet.to_param
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
...@@ -143,7 +143,7 @@ describe SnippetsController do ...@@ -143,7 +143,7 @@ describe SnippetsController do
get :raw, id: personal_snippet.to_param get :raw, id: personal_snippet.to_param
expect(assigns(:snippet)).to eq(personal_snippet) expect(assigns(:snippet)).to eq(personal_snippet)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
end end
end end
...@@ -169,7 +169,7 @@ describe SnippetsController do ...@@ -169,7 +169,7 @@ describe SnippetsController do
get :raw, id: personal_snippet.to_param get :raw, id: personal_snippet.to_param
expect(assigns(:snippet)).to eq(personal_snippet) expect(assigns(:snippet)).to eq(personal_snippet)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
end end
...@@ -194,7 +194,7 @@ describe SnippetsController do ...@@ -194,7 +194,7 @@ describe SnippetsController do
get :raw, id: personal_snippet.to_param get :raw, id: personal_snippet.to_param
expect(assigns(:snippet)).to eq(personal_snippet) expect(assigns(:snippet)).to eq(personal_snippet)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
end end
...@@ -203,7 +203,7 @@ describe SnippetsController do ...@@ -203,7 +203,7 @@ describe SnippetsController do
get :raw, id: personal_snippet.to_param get :raw, id: personal_snippet.to_param
expect(assigns(:snippet)).to eq(personal_snippet) expect(assigns(:snippet)).to eq(personal_snippet)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
end end
end end
...@@ -217,7 +217,7 @@ describe SnippetsController do ...@@ -217,7 +217,7 @@ describe SnippetsController do
it 'responds with status 404' do it 'responds with status 404' do
get :raw, id: 'doesntexist' get :raw, id: 'doesntexist'
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
...@@ -225,7 +225,7 @@ describe SnippetsController do ...@@ -225,7 +225,7 @@ describe SnippetsController do
it 'responds with status 404' do it 'responds with status 404' do
get :raw, id: 'doesntexist' get :raw, id: 'doesntexist'
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
end end
......
...@@ -26,7 +26,7 @@ describe UploadsController do ...@@ -26,7 +26,7 @@ describe UploadsController do
it "responds with status 200" do it "responds with status 200" do
get :show, model: "user", mounted_as: "avatar", id: user.id, filename: "image.png" get :show, model: "user", mounted_as: "avatar", id: user.id, filename: "image.png"
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
end end
end end
...@@ -35,7 +35,7 @@ describe UploadsController do ...@@ -35,7 +35,7 @@ describe UploadsController do
it "responds with status 200" do it "responds with status 200" do
get :show, model: "user", mounted_as: "avatar", id: user.id, filename: "image.png" get :show, model: "user", mounted_as: "avatar", id: user.id, filename: "image.png"
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
end end
end end
...@@ -52,7 +52,7 @@ describe UploadsController do ...@@ -52,7 +52,7 @@ describe UploadsController do
it "responds with status 200" do it "responds with status 200" do
get :show, model: "project", mounted_as: "avatar", id: project.id, filename: "image.png" get :show, model: "project", mounted_as: "avatar", id: project.id, filename: "image.png"
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
end end
...@@ -64,7 +64,7 @@ describe UploadsController do ...@@ -64,7 +64,7 @@ describe UploadsController do
it "responds with status 200" do it "responds with status 200" do
get :show, model: "project", mounted_as: "avatar", id: project.id, filename: "image.png" get :show, model: "project", mounted_as: "avatar", id: project.id, filename: "image.png"
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
end end
end end
...@@ -109,7 +109,7 @@ describe UploadsController do ...@@ -109,7 +109,7 @@ describe UploadsController do
it "responds with status 200" do it "responds with status 200" do
get :show, model: "project", mounted_as: "avatar", id: project.id, filename: "image.png" get :show, model: "project", mounted_as: "avatar", id: project.id, filename: "image.png"
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
end end
end end
...@@ -118,7 +118,7 @@ describe UploadsController do ...@@ -118,7 +118,7 @@ describe UploadsController do
it "responds with status 404" do it "responds with status 404" do
get :show, model: "project", mounted_as: "avatar", id: project.id, filename: "image.png" get :show, model: "project", mounted_as: "avatar", id: project.id, filename: "image.png"
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
end end
...@@ -133,7 +133,7 @@ describe UploadsController do ...@@ -133,7 +133,7 @@ describe UploadsController do
it "responds with status 200" do it "responds with status 200" do
get :show, model: "group", mounted_as: "avatar", id: group.id, filename: "image.png" get :show, model: "group", mounted_as: "avatar", id: group.id, filename: "image.png"
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
end end
...@@ -145,7 +145,7 @@ describe UploadsController do ...@@ -145,7 +145,7 @@ describe UploadsController do
it "responds with status 200" do it "responds with status 200" do
get :show, model: "group", mounted_as: "avatar", id: group.id, filename: "image.png" get :show, model: "group", mounted_as: "avatar", id: group.id, filename: "image.png"
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
end end
end end
...@@ -181,7 +181,7 @@ describe UploadsController do ...@@ -181,7 +181,7 @@ describe UploadsController do
it "responds with status 200" do it "responds with status 200" do
get :show, model: "group", mounted_as: "avatar", id: group.id, filename: "image.png" get :show, model: "group", mounted_as: "avatar", id: group.id, filename: "image.png"
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
end end
end end
...@@ -190,7 +190,7 @@ describe UploadsController do ...@@ -190,7 +190,7 @@ describe UploadsController do
it "responds with status 404" do it "responds with status 404" do
get :show, model: "group", mounted_as: "avatar", id: group.id, filename: "image.png" get :show, model: "group", mounted_as: "avatar", id: group.id, filename: "image.png"
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
end end
...@@ -210,7 +210,7 @@ describe UploadsController do ...@@ -210,7 +210,7 @@ describe UploadsController do
it "responds with status 200" do it "responds with status 200" do
get :show, model: "note", mounted_as: "attachment", id: note.id, filename: "image.png" get :show, model: "note", mounted_as: "attachment", id: note.id, filename: "image.png"
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
end end
...@@ -222,7 +222,7 @@ describe UploadsController do ...@@ -222,7 +222,7 @@ describe UploadsController do
it "responds with status 200" do it "responds with status 200" do
get :show, model: "note", mounted_as: "attachment", id: note.id, filename: "image.png" get :show, model: "note", mounted_as: "attachment", id: note.id, filename: "image.png"
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
end end
end end
...@@ -267,7 +267,7 @@ describe UploadsController do ...@@ -267,7 +267,7 @@ describe UploadsController do
it "responds with status 200" do it "responds with status 200" do
get :show, model: "note", mounted_as: "attachment", id: note.id, filename: "image.png" get :show, model: "note", mounted_as: "attachment", id: note.id, filename: "image.png"
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
end end
end end
...@@ -276,7 +276,7 @@ describe UploadsController do ...@@ -276,7 +276,7 @@ describe UploadsController do
it "responds with status 404" do it "responds with status 404" do
get :show, model: "note", mounted_as: "attachment", id: note.id, filename: "image.png" get :show, model: "note", mounted_as: "attachment", id: note.id, filename: "image.png"
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
end end
......
...@@ -33,7 +33,7 @@ describe UsersController do ...@@ -33,7 +33,7 @@ describe UsersController do
it 'renders the show template' do it 'renders the show template' do
get :show, username: user.username get :show, username: user.username
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(response).to render_template('show') expect(response).to render_template('show')
end end
end end
...@@ -47,7 +47,7 @@ describe UsersController do ...@@ -47,7 +47,7 @@ describe UsersController do
context 'when logged out' do context 'when logged out' do
it 'renders 404' do it 'renders 404' do
get :show, username: user.username get :show, username: user.username
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
...@@ -56,7 +56,7 @@ describe UsersController do ...@@ -56,7 +56,7 @@ describe UsersController do
it 'renders show' do it 'renders show' do
get :show, username: user.username get :show, username: user.username
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(response).to render_template('show') expect(response).to render_template('show')
end end
end end
...@@ -121,7 +121,7 @@ describe UsersController do ...@@ -121,7 +121,7 @@ describe UsersController do
context 'format html' do context 'format html' do
it 'renders snippets page' do it 'renders snippets page' do
get :snippets, username: user.username get :snippets, username: user.username
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(response).to render_template('show') expect(response).to render_template('show')
end end
end end
...@@ -129,7 +129,7 @@ describe UsersController do ...@@ -129,7 +129,7 @@ describe UsersController do
context 'format json' do context 'format json' do
it 'response with snippets json data' do it 'response with snippets json data' do
get :snippets, username: user.username, format: :json get :snippets, username: user.username, format: :json
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(JSON.parse(response.body)).to have_key('html') expect(JSON.parse(response.body)).to have_key('html')
end end
end end
......
...@@ -17,7 +17,7 @@ describe API::API, api: true do ...@@ -17,7 +17,7 @@ describe API::API, api: true do
it "returns an array of award_emoji" do it "returns an array of award_emoji" do
get api("/projects/#{project.id}/issues/#{issue.id}/award_emoji", user) get api("/projects/#{project.id}/issues/#{issue.id}/award_emoji", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first['name']).to eq(award_emoji.name) expect(json_response.first['name']).to eq(award_emoji.name)
end end
...@@ -25,7 +25,7 @@ describe API::API, api: true do ...@@ -25,7 +25,7 @@ describe API::API, api: true do
it "should return a 404 error when issue id not found" do it "should return a 404 error when issue id not found" do
get api("/projects/#{project.id}/issues/12345/award_emoji", user) get api("/projects/#{project.id}/issues/12345/award_emoji", user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
...@@ -33,7 +33,7 @@ describe API::API, api: true do ...@@ -33,7 +33,7 @@ describe API::API, api: true do
it "returns an array of award_emoji" do it "returns an array of award_emoji" do
get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/award_emoji", user) get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/award_emoji", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first['name']).to eq(downvote.name) expect(json_response.first['name']).to eq(downvote.name)
end end
...@@ -45,7 +45,7 @@ describe API::API, api: true do ...@@ -45,7 +45,7 @@ describe API::API, api: true do
get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/award_emoji", user1) get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/award_emoji", user1)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
end end
...@@ -56,7 +56,7 @@ describe API::API, api: true do ...@@ -56,7 +56,7 @@ describe API::API, api: true do
it 'returns an array of award emoji' do it 'returns an array of award emoji' do
get api("/projects/#{project.id}/issues/#{issue.id}/notes/#{note.id}/award_emoji", user) get api("/projects/#{project.id}/issues/#{issue.id}/notes/#{note.id}/award_emoji", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first['name']).to eq(rocket.name) expect(json_response.first['name']).to eq(rocket.name)
end end
...@@ -68,7 +68,7 @@ describe API::API, api: true do ...@@ -68,7 +68,7 @@ describe API::API, api: true do
it "returns the award emoji" do it "returns the award emoji" do
get api("/projects/#{project.id}/issues/#{issue.id}/award_emoji/#{award_emoji.id}", user) get api("/projects/#{project.id}/issues/#{issue.id}/award_emoji/#{award_emoji.id}", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['name']).to eq(award_emoji.name) expect(json_response['name']).to eq(award_emoji.name)
expect(json_response['awardable_id']).to eq(issue.id) expect(json_response['awardable_id']).to eq(issue.id)
expect(json_response['awardable_type']).to eq("Issue") expect(json_response['awardable_type']).to eq("Issue")
...@@ -77,7 +77,7 @@ describe API::API, api: true do ...@@ -77,7 +77,7 @@ describe API::API, api: true do
it "returns a 404 error if the award is not found" do it "returns a 404 error if the award is not found" do
get api("/projects/#{project.id}/issues/#{issue.id}/award_emoji/12345", user) get api("/projects/#{project.id}/issues/#{issue.id}/award_emoji/12345", user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
...@@ -85,7 +85,7 @@ describe API::API, api: true do ...@@ -85,7 +85,7 @@ describe API::API, api: true do
it 'returns the award emoji' do it 'returns the award emoji' do
get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/award_emoji/#{downvote.id}", user) get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/award_emoji/#{downvote.id}", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['name']).to eq(downvote.name) expect(json_response['name']).to eq(downvote.name)
expect(json_response['awardable_id']).to eq(merge_request.id) expect(json_response['awardable_id']).to eq(merge_request.id)
expect(json_response['awardable_type']).to eq("MergeRequest") expect(json_response['awardable_type']).to eq("MergeRequest")
...@@ -98,7 +98,7 @@ describe API::API, api: true do ...@@ -98,7 +98,7 @@ describe API::API, api: true do
get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/award_emoji/#{downvote.id}", user1) get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/award_emoji/#{downvote.id}", user1)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
end end
...@@ -109,7 +109,7 @@ describe API::API, api: true do ...@@ -109,7 +109,7 @@ describe API::API, api: true do
it 'returns an award emoji' do it 'returns an award emoji' do
get api("/projects/#{project.id}/issues/#{issue.id}/notes/#{note.id}/award_emoji/#{rocket.id}", user) get api("/projects/#{project.id}/issues/#{issue.id}/notes/#{note.id}/award_emoji/#{rocket.id}", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).not_to be_an Array expect(json_response).not_to be_an Array
expect(json_response['name']).to eq(rocket.name) expect(json_response['name']).to eq(rocket.name)
end end
...@@ -120,7 +120,7 @@ describe API::API, api: true do ...@@ -120,7 +120,7 @@ describe API::API, api: true do
it "creates a new award emoji" do it "creates a new award emoji" do
post api("/projects/#{project.id}/issues/#{issue.id}/award_emoji", user), name: 'blowfish' post api("/projects/#{project.id}/issues/#{issue.id}/award_emoji", user), name: 'blowfish'
expect(response.status).to eq(201) expect(response).to have_http_status(201)
expect(json_response['name']).to eq('blowfish') expect(json_response['name']).to eq('blowfish')
expect(json_response['user']['username']).to eq(user.username) expect(json_response['user']['username']).to eq(user.username)
end end
...@@ -128,13 +128,13 @@ describe API::API, api: true do ...@@ -128,13 +128,13 @@ describe API::API, api: true do
it "should return a 400 bad request error if the name is not given" do it "should return a 400 bad request error if the name is not given" do
post api("/projects/#{project.id}/issues/#{issue.id}/award_emoji", user) post api("/projects/#{project.id}/issues/#{issue.id}/award_emoji", user)
expect(response.status).to eq(400) expect(response).to have_http_status(400)
end end
it "should return a 401 unauthorized error if the user is not authenticated" do it "should return a 401 unauthorized error if the user is not authenticated" do
post api("/projects/#{project.id}/issues/#{issue.id}/award_emoji"), name: 'thumbsup' post api("/projects/#{project.id}/issues/#{issue.id}/award_emoji"), name: 'thumbsup'
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
end end
...@@ -145,7 +145,7 @@ describe API::API, api: true do ...@@ -145,7 +145,7 @@ describe API::API, api: true do
post api("/projects/#{project.id}/issues/#{issue.id}/notes/#{note.id}/award_emoji", user), name: 'rocket' post api("/projects/#{project.id}/issues/#{issue.id}/notes/#{note.id}/award_emoji", user), name: 'rocket'
end.to change { note.award_emoji.count }.from(0).to(1) end.to change { note.award_emoji.count }.from(0).to(1)
expect(response.status).to eq(201) expect(response).to have_http_status(201)
expect(json_response['user']['username']).to eq(user.username) expect(json_response['user']['username']).to eq(user.username)
end end
end end
...@@ -157,13 +157,13 @@ describe API::API, api: true do ...@@ -157,13 +157,13 @@ describe API::API, api: true do
delete api("/projects/#{project.id}/issues/#{issue.id}/award_emoji/#{award_emoji.id}", user) delete api("/projects/#{project.id}/issues/#{issue.id}/award_emoji/#{award_emoji.id}", user)
end.to change { issue.award_emoji.count }.from(1).to(0) end.to change { issue.award_emoji.count }.from(1).to(0)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
it 'returns a 404 error when the award emoji can not be found' do it 'returns a 404 error when the award emoji can not be found' do
delete api("/projects/#{project.id}/issues/#{issue.id}/award_emoji/12345", user) delete api("/projects/#{project.id}/issues/#{issue.id}/award_emoji/12345", user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
...@@ -173,13 +173,13 @@ describe API::API, api: true do ...@@ -173,13 +173,13 @@ describe API::API, api: true do
delete api("/projects/#{project.id}/merge_requests/#{merge_request.id}/award_emoji/#{downvote.id}", user) delete api("/projects/#{project.id}/merge_requests/#{merge_request.id}/award_emoji/#{downvote.id}", user)
end.to change { merge_request.award_emoji.count }.from(1).to(0) end.to change { merge_request.award_emoji.count }.from(1).to(0)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
it 'returns a 404 error when note id not found' do it 'returns a 404 error when note id not found' do
delete api("/projects/#{project.id}/merge_requests/#{merge_request.id}/notes/12345", user) delete api("/projects/#{project.id}/merge_requests/#{merge_request.id}/notes/12345", user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
end end
...@@ -192,7 +192,7 @@ describe API::API, api: true do ...@@ -192,7 +192,7 @@ describe API::API, api: true do
delete api("/projects/#{project.id}/issues/#{issue.id}/notes/#{note.id}/award_emoji/#{rocket.id}", user) delete api("/projects/#{project.id}/issues/#{issue.id}/notes/#{note.id}/award_emoji/#{rocket.id}", user)
end.to change { note.award_emoji.count }.from(1).to(0) end.to change { note.award_emoji.count }.from(1).to(0)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
end end
end end
...@@ -17,7 +17,7 @@ describe API::API, api: true do ...@@ -17,7 +17,7 @@ describe API::API, api: true do
project.repository.expire_cache project.repository.expire_cache
get api("/projects/#{project.id}/repository/branches", user) get api("/projects/#{project.id}/repository/branches", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
branch_names = json_response.map { |x| x['name'] } branch_names = json_response.map { |x| x['name'] }
expect(branch_names).to match_array(project.repository.branch_names) expect(branch_names).to match_array(project.repository.branch_names)
...@@ -27,7 +27,7 @@ describe API::API, api: true do ...@@ -27,7 +27,7 @@ describe API::API, api: true do
describe "GET /projects/:id/repository/branches/:branch" do describe "GET /projects/:id/repository/branches/:branch" do
it "should return the branch information for a single branch" do it "should return the branch information for a single branch" do
get api("/projects/#{project.id}/repository/branches/#{branch_name}", user) get api("/projects/#{project.id}/repository/branches/#{branch_name}", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['name']).to eq(branch_name) expect(json_response['name']).to eq(branch_name)
expect(json_response['commit']['id']).to eq(branch_sha) expect(json_response['commit']['id']).to eq(branch_sha)
...@@ -36,19 +36,19 @@ describe API::API, api: true do ...@@ -36,19 +36,19 @@ describe API::API, api: true do
it "should return a 403 error if guest" do it "should return a 403 error if guest" do
get api("/projects/#{project.id}/repository/branches", user2) get api("/projects/#{project.id}/repository/branches", user2)
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
it "should return a 404 error if branch is not available" do it "should return a 404 error if branch is not available" do
get api("/projects/#{project.id}/repository/branches/unknown", user) get api("/projects/#{project.id}/repository/branches/unknown", user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
describe "PUT /projects/:id/repository/branches/:branch/protect" do describe "PUT /projects/:id/repository/branches/:branch/protect" do
it "should protect a single branch" do it "should protect a single branch" do
put api("/projects/#{project.id}/repository/branches/#{branch_name}/protect", user) put api("/projects/#{project.id}/repository/branches/#{branch_name}/protect", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['name']).to eq(branch_name) expect(json_response['name']).to eq(branch_name)
expect(json_response['commit']['id']).to eq(branch_sha) expect(json_response['commit']['id']).to eq(branch_sha)
...@@ -57,25 +57,25 @@ describe API::API, api: true do ...@@ -57,25 +57,25 @@ describe API::API, api: true do
it "should return a 404 error if branch not found" do it "should return a 404 error if branch not found" do
put api("/projects/#{project.id}/repository/branches/unknown/protect", user) put api("/projects/#{project.id}/repository/branches/unknown/protect", user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
it "should return a 403 error if guest" do it "should return a 403 error if guest" do
put api("/projects/#{project.id}/repository/branches/#{branch_name}/protect", user2) put api("/projects/#{project.id}/repository/branches/#{branch_name}/protect", user2)
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
it "should return success when protect branch again" do it "should return success when protect branch again" do
put api("/projects/#{project.id}/repository/branches/#{branch_name}/protect", user) put api("/projects/#{project.id}/repository/branches/#{branch_name}/protect", user)
put api("/projects/#{project.id}/repository/branches/#{branch_name}/protect", user) put api("/projects/#{project.id}/repository/branches/#{branch_name}/protect", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
end end
describe "PUT /projects/:id/repository/branches/:branch/unprotect" do describe "PUT /projects/:id/repository/branches/:branch/unprotect" do
it "should unprotect a single branch" do it "should unprotect a single branch" do
put api("/projects/#{project.id}/repository/branches/#{branch_name}/unprotect", user) put api("/projects/#{project.id}/repository/branches/#{branch_name}/unprotect", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['name']).to eq(branch_name) expect(json_response['name']).to eq(branch_name)
expect(json_response['commit']['id']).to eq(branch_sha) expect(json_response['commit']['id']).to eq(branch_sha)
...@@ -84,13 +84,13 @@ describe API::API, api: true do ...@@ -84,13 +84,13 @@ describe API::API, api: true do
it "should return success when unprotect branch" do it "should return success when unprotect branch" do
put api("/projects/#{project.id}/repository/branches/unknown/unprotect", user) put api("/projects/#{project.id}/repository/branches/unknown/unprotect", user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
it "should return success when unprotect branch again" do it "should return success when unprotect branch again" do
put api("/projects/#{project.id}/repository/branches/#{branch_name}/unprotect", user) put api("/projects/#{project.id}/repository/branches/#{branch_name}/unprotect", user)
put api("/projects/#{project.id}/repository/branches/#{branch_name}/unprotect", user) put api("/projects/#{project.id}/repository/branches/#{branch_name}/unprotect", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
end end
...@@ -100,7 +100,7 @@ describe API::API, api: true do ...@@ -100,7 +100,7 @@ describe API::API, api: true do
branch_name: 'feature1', branch_name: 'feature1',
ref: branch_sha ref: branch_sha
expect(response.status).to eq(201) expect(response).to have_http_status(201)
expect(json_response['name']).to eq('feature1') expect(json_response['name']).to eq('feature1')
expect(json_response['commit']['id']).to eq(branch_sha) expect(json_response['commit']['id']).to eq(branch_sha)
...@@ -110,14 +110,14 @@ describe API::API, api: true do ...@@ -110,14 +110,14 @@ describe API::API, api: true do
post api("/projects/#{project.id}/repository/branches", user2), post api("/projects/#{project.id}/repository/branches", user2),
branch_name: branch_name, branch_name: branch_name,
ref: branch_sha ref: branch_sha
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
it 'should return 400 if branch name is invalid' do it 'should return 400 if branch name is invalid' do
post api("/projects/#{project.id}/repository/branches", user), post api("/projects/#{project.id}/repository/branches", user),
branch_name: 'new design', branch_name: 'new design',
ref: branch_sha ref: branch_sha
expect(response.status).to eq(400) expect(response).to have_http_status(400)
expect(json_response['message']).to eq('Branch name is invalid') expect(json_response['message']).to eq('Branch name is invalid')
end end
...@@ -125,12 +125,12 @@ describe API::API, api: true do ...@@ -125,12 +125,12 @@ describe API::API, api: true do
post api("/projects/#{project.id}/repository/branches", user), post api("/projects/#{project.id}/repository/branches", user),
branch_name: 'new_design1', branch_name: 'new_design1',
ref: branch_sha ref: branch_sha
expect(response.status).to eq(201) expect(response).to have_http_status(201)
post api("/projects/#{project.id}/repository/branches", user), post api("/projects/#{project.id}/repository/branches", user),
branch_name: 'new_design1', branch_name: 'new_design1',
ref: branch_sha ref: branch_sha
expect(response.status).to eq(400) expect(response).to have_http_status(400)
expect(json_response['message']).to eq('Branch already exists') expect(json_response['message']).to eq('Branch already exists')
end end
...@@ -138,7 +138,7 @@ describe API::API, api: true do ...@@ -138,7 +138,7 @@ describe API::API, api: true do
post api("/projects/#{project.id}/repository/branches", user), post api("/projects/#{project.id}/repository/branches", user),
branch_name: 'new_design3', branch_name: 'new_design3',
ref: 'foo' ref: 'foo'
expect(response.status).to eq(400) expect(response).to have_http_status(400)
expect(json_response['message']).to eq('Invalid reference name') expect(json_response['message']).to eq('Invalid reference name')
end end
end end
...@@ -150,25 +150,25 @@ describe API::API, api: true do ...@@ -150,25 +150,25 @@ describe API::API, api: true do
it "should remove branch" do it "should remove branch" do
delete api("/projects/#{project.id}/repository/branches/#{branch_name}", user) delete api("/projects/#{project.id}/repository/branches/#{branch_name}", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['branch_name']).to eq(branch_name) expect(json_response['branch_name']).to eq(branch_name)
end end
it 'should return 404 if branch not exists' do it 'should return 404 if branch not exists' do
delete api("/projects/#{project.id}/repository/branches/foobar", user) delete api("/projects/#{project.id}/repository/branches/foobar", user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
it "should remove protected branch" do it "should remove protected branch" do
project.protected_branches.create(name: branch_name) project.protected_branches.create(name: branch_name)
delete api("/projects/#{project.id}/repository/branches/#{branch_name}", user) delete api("/projects/#{project.id}/repository/branches/#{branch_name}", user)
expect(response.status).to eq(405) expect(response).to have_http_status(405)
expect(json_response['message']).to eq('Protected branch cant be removed') expect(json_response['message']).to eq('Protected branch cant be removed')
end end
it "should not remove HEAD branch" do it "should not remove HEAD branch" do
delete api("/projects/#{project.id}/repository/branches/master", user) delete api("/projects/#{project.id}/repository/branches/master", user)
expect(response.status).to eq(405) expect(response).to have_http_status(405)
expect(json_response['message']).to eq('Cannot remove HEAD branch') expect(json_response['message']).to eq('Cannot remove HEAD branch')
end end
end end
......
...@@ -19,7 +19,7 @@ describe API::API, api: true do ...@@ -19,7 +19,7 @@ describe API::API, api: true do
context 'authorized user' do context 'authorized user' do
it 'should return project builds' do it 'should return project builds' do
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
end end
...@@ -32,7 +32,7 @@ describe API::API, api: true do ...@@ -32,7 +32,7 @@ describe API::API, api: true do
let(:query) { 'scope=pending' } let(:query) { 'scope=pending' }
it do it do
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
end end
end end
...@@ -41,7 +41,7 @@ describe API::API, api: true do ...@@ -41,7 +41,7 @@ describe API::API, api: true do
let(:query) { 'scope[0]=pending&scope[1]=running' } let(:query) { 'scope[0]=pending&scope[1]=running' }
it do it do
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
end end
end end
...@@ -49,7 +49,7 @@ describe API::API, api: true do ...@@ -49,7 +49,7 @@ describe API::API, api: true do
context 'respond 400 when scope contains invalid state' do context 'respond 400 when scope contains invalid state' do
let(:query) { 'scope[0]=pending&scope[1]=unknown_status' } let(:query) { 'scope[0]=pending&scope[1]=unknown_status' }
it { expect(response.status).to eq(400) } it { expect(response).to have_http_status(400) }
end end
end end
...@@ -57,7 +57,7 @@ describe API::API, api: true do ...@@ -57,7 +57,7 @@ describe API::API, api: true do
let(:api_user) { nil } let(:api_user) { nil }
it 'should not return project builds' do it 'should not return project builds' do
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
end end
...@@ -70,7 +70,7 @@ describe API::API, api: true do ...@@ -70,7 +70,7 @@ describe API::API, api: true do
context 'authorized user' do context 'authorized user' do
it 'should return project builds for specific commit' do it 'should return project builds for specific commit' do
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
end end
end end
...@@ -79,7 +79,7 @@ describe API::API, api: true do ...@@ -79,7 +79,7 @@ describe API::API, api: true do
let(:api_user) { nil } let(:api_user) { nil }
it 'should not return project builds' do it 'should not return project builds' do
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
end end
...@@ -89,7 +89,7 @@ describe API::API, api: true do ...@@ -89,7 +89,7 @@ describe API::API, api: true do
context 'authorized user' do context 'authorized user' do
it 'should return specific build data' do it 'should return specific build data' do
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['name']).to eq('test') expect(json_response['name']).to eq('test')
end end
end end
...@@ -98,7 +98,7 @@ describe API::API, api: true do ...@@ -98,7 +98,7 @@ describe API::API, api: true do
let(:api_user) { nil } let(:api_user) { nil }
it 'should not return specific build data' do it 'should not return specific build data' do
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
end end
...@@ -116,7 +116,7 @@ describe API::API, api: true do ...@@ -116,7 +116,7 @@ describe API::API, api: true do
end end
it 'should return specific build artifacts' do it 'should return specific build artifacts' do
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(response.headers).to include(download_headers) expect(response.headers).to include(download_headers)
end end
end end
...@@ -125,13 +125,13 @@ describe API::API, api: true do ...@@ -125,13 +125,13 @@ describe API::API, api: true do
let(:api_user) { nil } let(:api_user) { nil }
it 'should not return specific build artifacts' do it 'should not return specific build artifacts' do
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
end end
it 'should not return build artifacts if not uploaded' do it 'should not return build artifacts if not uploaded' do
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
...@@ -142,7 +142,7 @@ describe API::API, api: true do ...@@ -142,7 +142,7 @@ describe API::API, api: true do
context 'authorized user' do context 'authorized user' do
it 'should return specific build trace' do it 'should return specific build trace' do
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(response.body).to eq(build.trace) expect(response.body).to eq(build.trace)
end end
end end
...@@ -151,7 +151,7 @@ describe API::API, api: true do ...@@ -151,7 +151,7 @@ describe API::API, api: true do
let(:api_user) { nil } let(:api_user) { nil }
it 'should not return specific build trace' do it 'should not return specific build trace' do
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
end end
...@@ -162,7 +162,7 @@ describe API::API, api: true do ...@@ -162,7 +162,7 @@ describe API::API, api: true do
context 'authorized user' do context 'authorized user' do
context 'user with :update_build persmission' do context 'user with :update_build persmission' do
it 'should cancel running or pending build' do it 'should cancel running or pending build' do
expect(response.status).to eq(201) expect(response).to have_http_status(201)
expect(project.builds.first.status).to eq('canceled') expect(project.builds.first.status).to eq('canceled')
end end
end end
...@@ -171,7 +171,7 @@ describe API::API, api: true do ...@@ -171,7 +171,7 @@ describe API::API, api: true do
let(:api_user) { user2 } let(:api_user) { user2 }
it 'should not cancel build' do it 'should not cancel build' do
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
end end
end end
...@@ -180,7 +180,7 @@ describe API::API, api: true do ...@@ -180,7 +180,7 @@ describe API::API, api: true do
let(:api_user) { nil } let(:api_user) { nil }
it 'should not cancel build' do it 'should not cancel build' do
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
end end
...@@ -193,7 +193,7 @@ describe API::API, api: true do ...@@ -193,7 +193,7 @@ describe API::API, api: true do
context 'authorized user' do context 'authorized user' do
context 'user with :update_build permission' do context 'user with :update_build permission' do
it 'should retry non-running build' do it 'should retry non-running build' do
expect(response.status).to eq(201) expect(response).to have_http_status(201)
expect(project.builds.first.status).to eq('canceled') expect(project.builds.first.status).to eq('canceled')
expect(json_response['status']).to eq('pending') expect(json_response['status']).to eq('pending')
end end
...@@ -203,7 +203,7 @@ describe API::API, api: true do ...@@ -203,7 +203,7 @@ describe API::API, api: true do
let(:api_user) { user2 } let(:api_user) { user2 }
it 'should not retry build' do it 'should not retry build' do
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
end end
end end
...@@ -212,7 +212,7 @@ describe API::API, api: true do ...@@ -212,7 +212,7 @@ describe API::API, api: true do
let(:api_user) { nil } let(:api_user) { nil }
it 'should not retry build' do it 'should not retry build' do
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
end end
......
...@@ -41,7 +41,7 @@ describe API::CommitStatuses, api: true do ...@@ -41,7 +41,7 @@ describe API::CommitStatuses, api: true do
before { get api(get_url, reporter) } before { get api(get_url, reporter) }
it 'returns latest commit statuses' do it 'returns latest commit statuses' do
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(statuses_id).to contain_exactly(status3.id, status4.id, status5.id, status6.id) expect(statuses_id).to contain_exactly(status3.id, status4.id, status5.id, status6.id)
...@@ -54,7 +54,7 @@ describe API::CommitStatuses, api: true do ...@@ -54,7 +54,7 @@ describe API::CommitStatuses, api: true do
before { get api(get_url, reporter), all: 1 } before { get api(get_url, reporter), all: 1 }
it 'returns all commit statuses' do it 'returns all commit statuses' do
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(statuses_id).to contain_exactly(status1.id, status2.id, expect(statuses_id).to contain_exactly(status1.id, status2.id,
...@@ -67,7 +67,7 @@ describe API::CommitStatuses, api: true do ...@@ -67,7 +67,7 @@ describe API::CommitStatuses, api: true do
before { get api(get_url, reporter), ref: 'develop' } before { get api(get_url, reporter), ref: 'develop' }
it 'returns latest commit statuses for specific ref' do it 'returns latest commit statuses for specific ref' do
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(statuses_id).to contain_exactly(status3.id, status5.id) expect(statuses_id).to contain_exactly(status3.id, status5.id)
...@@ -78,7 +78,7 @@ describe API::CommitStatuses, api: true do ...@@ -78,7 +78,7 @@ describe API::CommitStatuses, api: true do
before { get api(get_url, reporter), name: 'coverage' } before { get api(get_url, reporter), name: 'coverage' }
it 'return latest commit statuses for specific name' do it 'return latest commit statuses for specific name' do
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(statuses_id).to contain_exactly(status4.id, status5.id) expect(statuses_id).to contain_exactly(status4.id, status5.id)
...@@ -101,7 +101,7 @@ describe API::CommitStatuses, api: true do ...@@ -101,7 +101,7 @@ describe API::CommitStatuses, api: true do
before { get api(get_url, guest) } before { get api(get_url, guest) }
it "should not return project commits" do it "should not return project commits" do
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
end end
...@@ -109,7 +109,7 @@ describe API::CommitStatuses, api: true do ...@@ -109,7 +109,7 @@ describe API::CommitStatuses, api: true do
before { get api(get_url) } before { get api(get_url) }
it "should not return project commits" do it "should not return project commits" do
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
end end
...@@ -122,7 +122,7 @@ describe API::CommitStatuses, api: true do ...@@ -122,7 +122,7 @@ describe API::CommitStatuses, api: true do
before { post api(post_url, developer), state: 'success' } before { post api(post_url, developer), state: 'success' }
it 'creates commit status' do it 'creates commit status' do
expect(response.status).to eq(201) expect(response).to have_http_status(201)
expect(json_response['sha']).to eq(commit.id) expect(json_response['sha']).to eq(commit.id)
expect(json_response['status']).to eq('success') expect(json_response['status']).to eq('success')
expect(json_response['name']).to eq('default') expect(json_response['name']).to eq('default')
...@@ -141,7 +141,7 @@ describe API::CommitStatuses, api: true do ...@@ -141,7 +141,7 @@ describe API::CommitStatuses, api: true do
end end
it 'creates commit status' do it 'creates commit status' do
expect(response.status).to eq(201) expect(response).to have_http_status(201)
expect(json_response['sha']).to eq(commit.id) expect(json_response['sha']).to eq(commit.id)
expect(json_response['status']).to eq('success') expect(json_response['status']).to eq('success')
expect(json_response['name']).to eq('coverage') expect(json_response['name']).to eq('coverage')
...@@ -155,7 +155,7 @@ describe API::CommitStatuses, api: true do ...@@ -155,7 +155,7 @@ describe API::CommitStatuses, api: true do
before { post api(post_url, developer), state: 'invalid' } before { post api(post_url, developer), state: 'invalid' }
it 'does not create commit status' do it 'does not create commit status' do
expect(response.status).to eq(400) expect(response).to have_http_status(400)
end end
end end
...@@ -163,7 +163,7 @@ describe API::CommitStatuses, api: true do ...@@ -163,7 +163,7 @@ describe API::CommitStatuses, api: true do
before { post api(post_url, developer) } before { post api(post_url, developer) }
it 'does not create commit status' do it 'does not create commit status' do
expect(response.status).to eq(400) expect(response).to have_http_status(400)
end end
end end
...@@ -172,7 +172,7 @@ describe API::CommitStatuses, api: true do ...@@ -172,7 +172,7 @@ describe API::CommitStatuses, api: true do
before { post api(post_url, developer), state: 'running' } before { post api(post_url, developer), state: 'running' }
it 'returns not found error' do it 'returns not found error' do
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
end end
...@@ -181,7 +181,7 @@ describe API::CommitStatuses, api: true do ...@@ -181,7 +181,7 @@ describe API::CommitStatuses, api: true do
before { post api(post_url, reporter) } before { post api(post_url, reporter) }
it 'should not create commit status' do it 'should not create commit status' do
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
end end
...@@ -189,7 +189,7 @@ describe API::CommitStatuses, api: true do ...@@ -189,7 +189,7 @@ describe API::CommitStatuses, api: true do
before { post api(post_url, guest) } before { post api(post_url, guest) }
it 'should not create commit status' do it 'should not create commit status' do
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
end end
...@@ -197,7 +197,7 @@ describe API::CommitStatuses, api: true do ...@@ -197,7 +197,7 @@ describe API::CommitStatuses, api: true do
before { post api(post_url) } before { post api(post_url) }
it 'should not create commit status' do it 'should not create commit status' do
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
end end
......
...@@ -19,7 +19,7 @@ describe API::API, api: true do ...@@ -19,7 +19,7 @@ describe API::API, api: true do
it "should return project commits" do it "should return project commits" do
get api("/projects/#{project.id}/repository/commits", user) get api("/projects/#{project.id}/repository/commits", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first['id']).to eq(project.repository.commit.id) expect(json_response.first['id']).to eq(project.repository.commit.id)
...@@ -29,7 +29,7 @@ describe API::API, api: true do ...@@ -29,7 +29,7 @@ describe API::API, api: true do
context "unauthorized user" do context "unauthorized user" do
it "should not return project commits" do it "should not return project commits" do
get api("/projects/#{project.id}/repository/commits") get api("/projects/#{project.id}/repository/commits")
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
...@@ -63,7 +63,7 @@ describe API::API, api: true do ...@@ -63,7 +63,7 @@ describe API::API, api: true do
it "should return an invalid parameter error message" do it "should return an invalid parameter error message" do
get api("/projects/#{project.id}/repository/commits?since=invalid-date", user) get api("/projects/#{project.id}/repository/commits?since=invalid-date", user)
expect(response.status).to eq(400) expect(response).to have_http_status(400)
expect(json_response['message']).to include "\"since\" must be a timestamp in ISO 8601 format" expect(json_response['message']).to include "\"since\" must be a timestamp in ISO 8601 format"
end end
end end
...@@ -73,26 +73,26 @@ describe API::API, api: true do ...@@ -73,26 +73,26 @@ describe API::API, api: true do
context "authorized user" do context "authorized user" do
it "should return a commit by sha" do it "should return a commit by sha" do
get api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}", user) get api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['id']).to eq(project.repository.commit.id) expect(json_response['id']).to eq(project.repository.commit.id)
expect(json_response['title']).to eq(project.repository.commit.title) expect(json_response['title']).to eq(project.repository.commit.title)
end end
it "should return a 404 error if not found" do it "should return a 404 error if not found" do
get api("/projects/#{project.id}/repository/commits/invalid_sha", user) get api("/projects/#{project.id}/repository/commits/invalid_sha", user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
it "should return nil for commit without CI" do it "should return nil for commit without CI" do
get api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}", user) get api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['status']).to be_nil expect(json_response['status']).to be_nil
end end
it "should return status for CI" do it "should return status for CI" do
pipeline = project.ensure_pipeline(project.repository.commit.sha, 'master') pipeline = project.ensure_pipeline(project.repository.commit.sha, 'master')
get api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}", user) get api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['status']).to eq(pipeline.status) expect(json_response['status']).to eq(pipeline.status)
end end
end end
...@@ -100,7 +100,7 @@ describe API::API, api: true do ...@@ -100,7 +100,7 @@ describe API::API, api: true do
context "unauthorized user" do context "unauthorized user" do
it "should not return the selected commit" do it "should not return the selected commit" do
get api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}") get api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}")
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
end end
...@@ -111,7 +111,7 @@ describe API::API, api: true do ...@@ -111,7 +111,7 @@ describe API::API, api: true do
it "should return the diff of the selected commit" do it "should return the diff of the selected commit" do
get api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}/diff", user) get api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}/diff", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to be >= 1 expect(json_response.length).to be >= 1
...@@ -120,14 +120,14 @@ describe API::API, api: true do ...@@ -120,14 +120,14 @@ describe API::API, api: true do
it "should return a 404 error if invalid commit" do it "should return a 404 error if invalid commit" do
get api("/projects/#{project.id}/repository/commits/invalid_sha/diff", user) get api("/projects/#{project.id}/repository/commits/invalid_sha/diff", user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
context "unauthorized user" do context "unauthorized user" do
it "should not return the diff of the selected commit" do it "should not return the diff of the selected commit" do
get api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}/diff") get api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}/diff")
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
end end
...@@ -136,7 +136,7 @@ describe API::API, api: true do ...@@ -136,7 +136,7 @@ describe API::API, api: true do
context 'authorized user' do context 'authorized user' do
it 'should return merge_request comments' do it 'should return merge_request comments' do
get api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}/comments", user) get api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}/comments", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(2) expect(json_response.length).to eq(2)
expect(json_response.first['note']).to eq('a comment on a commit') expect(json_response.first['note']).to eq('a comment on a commit')
...@@ -145,14 +145,14 @@ describe API::API, api: true do ...@@ -145,14 +145,14 @@ describe API::API, api: true do
it 'should return a 404 error if merge_request_id not found' do it 'should return a 404 error if merge_request_id not found' do
get api("/projects/#{project.id}/repository/commits/1234ab/comments", user) get api("/projects/#{project.id}/repository/commits/1234ab/comments", user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
context 'unauthorized user' do context 'unauthorized user' do
it 'should not return the diff of the selected commit' do it 'should not return the diff of the selected commit' do
get api("/projects/#{project.id}/repository/commits/1234ab/comments") get api("/projects/#{project.id}/repository/commits/1234ab/comments")
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
end end
...@@ -161,7 +161,7 @@ describe API::API, api: true do ...@@ -161,7 +161,7 @@ describe API::API, api: true do
context 'authorized user' do context 'authorized user' do
it 'should return comment' do it 'should return comment' do
post api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}/comments", user), note: 'My comment' post api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}/comments", user), note: 'My comment'
expect(response.status).to eq(201) expect(response).to have_http_status(201)
expect(json_response['note']).to eq('My comment') expect(json_response['note']).to eq('My comment')
expect(json_response['path']).to be_nil expect(json_response['path']).to be_nil
expect(json_response['line']).to be_nil expect(json_response['line']).to be_nil
...@@ -170,7 +170,7 @@ describe API::API, api: true do ...@@ -170,7 +170,7 @@ describe API::API, api: true do
it 'should return the inline comment' do it 'should return the inline comment' do
post api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}/comments", user), note: 'My comment', path: project.repository.commit.diffs.first.new_path, line: 7, line_type: 'new' post api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}/comments", user), note: 'My comment', path: project.repository.commit.diffs.first.new_path, line: 7, line_type: 'new'
expect(response.status).to eq(201) expect(response).to have_http_status(201)
expect(json_response['note']).to eq('My comment') expect(json_response['note']).to eq('My comment')
expect(json_response['path']).to eq(project.repository.commit.diffs.first.new_path) expect(json_response['path']).to eq(project.repository.commit.diffs.first.new_path)
expect(json_response['line']).to eq(7) expect(json_response['line']).to eq(7)
...@@ -179,19 +179,19 @@ describe API::API, api: true do ...@@ -179,19 +179,19 @@ describe API::API, api: true do
it 'should return 400 if note is missing' do it 'should return 400 if note is missing' do
post api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}/comments", user) post api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}/comments", user)
expect(response.status).to eq(400) expect(response).to have_http_status(400)
end end
it 'should return 404 if note is attached to non existent commit' do it 'should return 404 if note is attached to non existent commit' do
post api("/projects/#{project.id}/repository/commits/1234ab/comments", user), note: 'My comment' post api("/projects/#{project.id}/repository/commits/1234ab/comments", user), note: 'My comment'
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
context 'unauthorized user' do context 'unauthorized user' do
it 'should not return the diff of the selected commit' do it 'should not return the diff of the selected commit' do
post api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}/comments") post api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}/comments")
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
end end
......
...@@ -11,21 +11,21 @@ describe API::API, api: true do ...@@ -11,21 +11,21 @@ describe API::API, api: true do
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).to have_http_status(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).to have_http_status(401)
end end
end end
describe "authorization by private token" do describe "authorization by private token" do
it "returns authentication success" do it "returns authentication success" do
get api("/user", user) get api("/user", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
end end
end end
...@@ -16,7 +16,7 @@ describe API::API, api: true do ...@@ -16,7 +16,7 @@ describe API::API, api: true do
} }
get api("/projects/#{project.id}/repository/files", user), params get api("/projects/#{project.id}/repository/files", user), params
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['file_path']).to eq(file_path) expect(json_response['file_path']).to eq(file_path)
expect(json_response['file_name']).to eq('popen.rb') expect(json_response['file_name']).to eq('popen.rb')
expect(json_response['last_commit_id']).to eq('570e7b2abdd848b95f2f578043fc23bd6f6fd24d') expect(json_response['last_commit_id']).to eq('570e7b2abdd848b95f2f578043fc23bd6f6fd24d')
...@@ -25,7 +25,7 @@ describe API::API, api: true do ...@@ -25,7 +25,7 @@ describe API::API, api: true do
it "should return a 400 bad request if no params given" do it "should return a 400 bad request if no params given" do
get api("/projects/#{project.id}/repository/files", user) get api("/projects/#{project.id}/repository/files", user)
expect(response.status).to eq(400) expect(response).to have_http_status(400)
end end
it "should return a 404 if such file does not exist" do it "should return a 404 if such file does not exist" do
...@@ -35,7 +35,7 @@ describe API::API, api: true do ...@@ -35,7 +35,7 @@ describe API::API, api: true do
} }
get api("/projects/#{project.id}/repository/files", user), params get api("/projects/#{project.id}/repository/files", user), params
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
...@@ -51,13 +51,13 @@ describe API::API, api: true do ...@@ -51,13 +51,13 @@ describe API::API, api: true do
it "should create a new file in project repo" do it "should create a new file in project repo" do
post api("/projects/#{project.id}/repository/files", user), valid_params post api("/projects/#{project.id}/repository/files", user), valid_params
expect(response.status).to eq(201) expect(response).to have_http_status(201)
expect(json_response['file_path']).to eq('newfile.rb') expect(json_response['file_path']).to eq('newfile.rb')
end end
it "should return a 400 bad request if no params given" do it "should return a 400 bad request if no params given" do
post api("/projects/#{project.id}/repository/files", user) post api("/projects/#{project.id}/repository/files", user)
expect(response.status).to eq(400) expect(response).to have_http_status(400)
end end
it "should return a 400 if editor fails to create file" do it "should return a 400 if editor fails to create file" do
...@@ -65,7 +65,7 @@ describe API::API, api: true do ...@@ -65,7 +65,7 @@ describe API::API, api: true do
and_return(false) and_return(false)
post api("/projects/#{project.id}/repository/files", user), valid_params post api("/projects/#{project.id}/repository/files", user), valid_params
expect(response.status).to eq(400) expect(response).to have_http_status(400)
end end
end end
...@@ -81,13 +81,13 @@ describe API::API, api: true do ...@@ -81,13 +81,13 @@ describe API::API, api: true do
it "should update existing file in project repo" do it "should update existing file in project repo" do
put api("/projects/#{project.id}/repository/files", user), valid_params put api("/projects/#{project.id}/repository/files", user), valid_params
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['file_path']).to eq(file_path) expect(json_response['file_path']).to eq(file_path)
end end
it "should return a 400 bad request if no params given" do it "should return a 400 bad request if no params given" do
put api("/projects/#{project.id}/repository/files", user) put api("/projects/#{project.id}/repository/files", user)
expect(response.status).to eq(400) expect(response).to have_http_status(400)
end end
end end
...@@ -102,20 +102,20 @@ describe API::API, api: true do ...@@ -102,20 +102,20 @@ describe API::API, api: true do
it "should delete existing file in project repo" do it "should delete existing file in project repo" do
delete api("/projects/#{project.id}/repository/files", user), valid_params delete api("/projects/#{project.id}/repository/files", user), valid_params
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['file_path']).to eq(file_path) expect(json_response['file_path']).to eq(file_path)
end end
it "should return a 400 bad request if no params given" do it "should return a 400 bad request if no params given" do
delete api("/projects/#{project.id}/repository/files", user) delete api("/projects/#{project.id}/repository/files", user)
expect(response.status).to eq(400) expect(response).to have_http_status(400)
end end
it "should return a 400 if fails to create file" do it "should return a 400 if fails to create file" do
allow_any_instance_of(Repository).to receive(:remove_file).and_return(false) allow_any_instance_of(Repository).to receive(:remove_file).and_return(false)
delete api("/projects/#{project.id}/repository/files", user), valid_params delete api("/projects/#{project.id}/repository/files", user), valid_params
expect(response.status).to eq(400) expect(response).to have_http_status(400)
end end
end end
...@@ -143,7 +143,7 @@ describe API::API, api: true do ...@@ -143,7 +143,7 @@ describe API::API, api: true do
it "remains unchanged" do it "remains unchanged" do
get api("/projects/#{project.id}/repository/files", user), get_params get api("/projects/#{project.id}/repository/files", user), get_params
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['file_path']).to eq(file_path) expect(json_response['file_path']).to eq(file_path)
expect(json_response['file_name']).to eq(file_path) expect(json_response['file_name']).to eq(file_path)
expect(json_response['content']).to eq(put_params[:content]) expect(json_response['content']).to eq(put_params[:content])
......
...@@ -22,7 +22,7 @@ describe API::API, api: true do ...@@ -22,7 +22,7 @@ describe API::API, api: true do
context 'when authenticated' do context 'when authenticated' do
it 'should fork if user has sufficient access to project' do it 'should fork if user has sufficient access to project' do
post api("/projects/fork/#{project.id}", user2) post api("/projects/fork/#{project.id}", user2)
expect(response.status).to eq(201) expect(response).to have_http_status(201)
expect(json_response['name']).to eq(project.name) expect(json_response['name']).to eq(project.name)
expect(json_response['path']).to eq(project.path) expect(json_response['path']).to eq(project.path)
expect(json_response['owner']['id']).to eq(user2.id) expect(json_response['owner']['id']).to eq(user2.id)
...@@ -32,7 +32,7 @@ describe API::API, api: true do ...@@ -32,7 +32,7 @@ describe API::API, api: true do
it 'should fork if user is admin' do it 'should fork if user is admin' do
post api("/projects/fork/#{project.id}", admin) post api("/projects/fork/#{project.id}", admin)
expect(response.status).to eq(201) expect(response).to have_http_status(201)
expect(json_response['name']).to eq(project.name) expect(json_response['name']).to eq(project.name)
expect(json_response['path']).to eq(project.path) expect(json_response['path']).to eq(project.path)
expect(json_response['owner']['id']).to eq(admin.id) expect(json_response['owner']['id']).to eq(admin.id)
...@@ -42,20 +42,20 @@ describe API::API, api: true do ...@@ -42,20 +42,20 @@ describe API::API, api: true do
it 'should fail on missing project access for the project to fork' do it 'should fail on missing project access for the project to fork' do
post api("/projects/fork/#{project.id}", user3) post api("/projects/fork/#{project.id}", user3)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
expect(json_response['message']).to eq('404 Project Not Found') expect(json_response['message']).to eq('404 Project Not Found')
end end
it 'should fail if forked project exists in the user namespace' do it 'should fail if forked project exists in the user namespace' do
post api("/projects/fork/#{project.id}", user) post api("/projects/fork/#{project.id}", user)
expect(response.status).to eq(409) expect(response).to have_http_status(409)
expect(json_response['message']['name']).to eq(['has already been taken']) expect(json_response['message']['name']).to eq(['has already been taken'])
expect(json_response['message']['path']).to eq(['has already been taken']) expect(json_response['message']['path']).to eq(['has already been taken'])
end end
it 'should fail if project to fork from does not exist' do it 'should fail if project to fork from does not exist' do
post api('/projects/fork/424242', user) post api('/projects/fork/424242', user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
expect(json_response['message']).to eq('404 Project Not Found') expect(json_response['message']).to eq('404 Project Not Found')
end end
end end
...@@ -63,7 +63,7 @@ describe API::API, api: true do ...@@ -63,7 +63,7 @@ describe API::API, api: true do
context 'when unauthenticated' do context 'when unauthenticated' do
it 'should return authentication error' do it 'should return authentication error' do
post api("/projects/fork/#{project.id}") post api("/projects/fork/#{project.id}")
expect(response.status).to eq(401) expect(response).to have_http_status(401)
expect(json_response['message']).to eq('401 Unauthorized') expect(json_response['message']).to eq('401 Unauthorized')
end end
end end
......
...@@ -31,7 +31,7 @@ describe API::API, api: true do ...@@ -31,7 +31,7 @@ describe API::API, api: true do
it "each user: should return an array of members groups of group3" do it "each user: should return an array of members groups of group3" do
[owner, master, developer, reporter, guest].each do |user| [owner, master, developer, reporter, guest].each do |user|
get api("/groups/#{group_with_members.id}/members", user) get api("/groups/#{group_with_members.id}/members", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.size).to eq(5) expect(json_response.size).to eq(5)
expect(json_response.find { |e| e['id'] == owner.id }['access_level']).to eq(GroupMember::OWNER) expect(json_response.find { |e| e['id'] == owner.id }['access_level']).to eq(GroupMember::OWNER)
...@@ -45,7 +45,7 @@ describe API::API, api: true do ...@@ -45,7 +45,7 @@ describe API::API, api: true do
it 'users not part of the group should get access error' do it 'users not part of the group should get access error' do
get api("/groups/#{group_with_members.id}/members", stranger) get api("/groups/#{group_with_members.id}/members", stranger)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
end end
...@@ -54,7 +54,7 @@ describe API::API, api: true do ...@@ -54,7 +54,7 @@ describe API::API, api: true do
context "when not a member of the group" do context "when not a member of the group" do
it "should not add guest as member of group_no_members when adding being done by person outside the group" do it "should not add guest as member of group_no_members when adding being done by person outside the group" do
post api("/groups/#{group_no_members.id}/members", reporter), user_id: guest.id, access_level: GroupMember::MASTER post api("/groups/#{group_no_members.id}/members", reporter), user_id: guest.id, access_level: GroupMember::MASTER
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
end end
...@@ -66,7 +66,7 @@ describe API::API, api: true do ...@@ -66,7 +66,7 @@ describe API::API, api: true do
post api("/groups/#{group_no_members.id}/members", owner), user_id: new_user.id, access_level: GroupMember::MASTER post api("/groups/#{group_no_members.id}/members", owner), user_id: new_user.id, access_level: GroupMember::MASTER
end.to change { group_no_members.members.count }.by(1) end.to change { group_no_members.members.count }.by(1)
expect(response.status).to eq(201) expect(response).to have_http_status(201)
expect(json_response['name']).to eq(new_user.name) expect(json_response['name']).to eq(new_user.name)
expect(json_response['access_level']).to eq(GroupMember::MASTER) expect(json_response['access_level']).to eq(GroupMember::MASTER)
end end
...@@ -78,27 +78,27 @@ describe API::API, api: true do ...@@ -78,27 +78,27 @@ describe API::API, api: true do
post api("/groups/#{group_with_members.id}/members", guest), user_id: new_user.id, access_level: GroupMember::MASTER post api("/groups/#{group_with_members.id}/members", guest), user_id: new_user.id, access_level: GroupMember::MASTER
end.not_to change { group_with_members.members.count } end.not_to change { group_with_members.members.count }
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
it "should return error if member already exists" do it "should return error if member already exists" do
post api("/groups/#{group_with_members.id}/members", owner), user_id: master.id, access_level: GroupMember::MASTER post api("/groups/#{group_with_members.id}/members", owner), user_id: master.id, access_level: GroupMember::MASTER
expect(response.status).to eq(409) expect(response).to have_http_status(409)
end end
it "should return a 400 error when user id is not given" do it "should return a 400 error when user id is not given" do
post api("/groups/#{group_no_members.id}/members", owner), access_level: GroupMember::MASTER post api("/groups/#{group_no_members.id}/members", owner), access_level: GroupMember::MASTER
expect(response.status).to eq(400) expect(response).to have_http_status(400)
end end
it "should return a 400 error when access level is not given" do it "should return a 400 error when access level is not given" do
post api("/groups/#{group_no_members.id}/members", owner), user_id: master.id post api("/groups/#{group_no_members.id}/members", owner), user_id: master.id
expect(response.status).to eq(400) expect(response).to have_http_status(400)
end end
it "should return a 422 error when access level is not known" do it "should return a 422 error when access level is not known" do
post api("/groups/#{group_no_members.id}/members", owner), user_id: master.id, access_level: 1234 post api("/groups/#{group_no_members.id}/members", owner), user_id: master.id, access_level: 1234
expect(response.status).to eq(422) expect(response).to have_http_status(422)
end end
end end
end end
...@@ -110,7 +110,7 @@ describe API::API, api: true do ...@@ -110,7 +110,7 @@ describe API::API, api: true do
api("/groups/#{group_no_members.id}/members/#{developer.id}", api("/groups/#{group_no_members.id}/members/#{developer.id}",
owner), access_level: GroupMember::MASTER owner), access_level: GroupMember::MASTER
) )
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
...@@ -122,7 +122,7 @@ describe API::API, api: true do ...@@ -122,7 +122,7 @@ describe API::API, api: true do
access_level: GroupMember::MASTER access_level: GroupMember::MASTER
) )
expect(response.status).to eq(200) expect(response).to have_http_status(200)
get api("/groups/#{group_with_members.id}/members", owner) get api("/groups/#{group_with_members.id}/members", owner)
json_reporter = json_response.find do |e| json_reporter = json_response.find do |e|
...@@ -139,7 +139,7 @@ describe API::API, api: true do ...@@ -139,7 +139,7 @@ describe API::API, api: true do
access_level: GroupMember::MASTER access_level: GroupMember::MASTER
) )
expect(response.status).to eq(403) expect(response).to have_http_status(403)
get api("/groups/#{group_with_members.id}/members", owner) get api("/groups/#{group_with_members.id}/members", owner)
json_developer = json_response.find do |e| json_developer = json_response.find do |e|
...@@ -153,7 +153,7 @@ describe API::API, api: true do ...@@ -153,7 +153,7 @@ describe API::API, api: true do
put( put(
api("/groups/#{group_with_members.id}/members/#{master.id}", owner) api("/groups/#{group_with_members.id}/members/#{master.id}", owner)
) )
expect(response.status).to eq(400) expect(response).to have_http_status(400)
end end
it 'should return a 422 error when access level is not known' do it 'should return a 422 error when access level is not known' do
...@@ -161,7 +161,7 @@ describe API::API, api: true do ...@@ -161,7 +161,7 @@ describe API::API, api: true do
api("/groups/#{group_with_members.id}/members/#{master.id}", owner), api("/groups/#{group_with_members.id}/members/#{master.id}", owner),
access_level: 1234 access_level: 1234
) )
expect(response.status).to eq(422) expect(response).to have_http_status(422)
end end
end end
end end
...@@ -172,7 +172,7 @@ describe API::API, api: true do ...@@ -172,7 +172,7 @@ describe API::API, api: true do
random_user = create(:user) random_user = create(:user)
delete api("/groups/#{group_with_members.id}/members/#{owner.id}", random_user) delete api("/groups/#{group_with_members.id}/members/#{owner.id}", random_user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
...@@ -182,17 +182,17 @@ describe API::API, api: true do ...@@ -182,17 +182,17 @@ describe API::API, api: true do
delete api("/groups/#{group_with_members.id}/members/#{guest.id}", owner) delete api("/groups/#{group_with_members.id}/members/#{guest.id}", owner)
end.to change { group_with_members.members.count }.by(-1) end.to change { group_with_members.members.count }.by(-1)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
it "should return a 404 error when user id is not known" do it "should return a 404 error when user id is not known" do
delete api("/groups/#{group_with_members.id}/members/1328", owner) delete api("/groups/#{group_with_members.id}/members/1328", owner)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
it "should not allow guest to modify group members" do it "should not allow guest to modify group members" do
delete api("/groups/#{group_with_members.id}/members/#{master.id}", guest) delete api("/groups/#{group_with_members.id}/members/#{master.id}", guest)
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
end end
end end
......
...@@ -23,14 +23,14 @@ describe API::API, api: true do ...@@ -23,14 +23,14 @@ describe API::API, api: true do
context "when unauthenticated" do context "when unauthenticated" do
it "should return authentication error" do it "should return authentication error" do
get api("/groups") get api("/groups")
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
context "when authenticated as user" do context "when authenticated as user" do
it "normal user: should return an array of groups of user1" do it "normal user: should return an array of groups of user1" do
get api("/groups", user1) get api("/groups", user1)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response.first['name']).to eq(group1.name) expect(json_response.first['name']).to eq(group1.name)
...@@ -40,7 +40,7 @@ describe API::API, api: true do ...@@ -40,7 +40,7 @@ describe API::API, api: true do
context "when authenticated as admin" do context "when authenticated as admin" do
it "admin: should return an array of all groups" do it "admin: should return an array of all groups" do
get api("/groups", admin) get api("/groups", admin)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(2) expect(json_response.length).to eq(2)
end end
...@@ -51,51 +51,51 @@ describe API::API, api: true do ...@@ -51,51 +51,51 @@ describe API::API, api: true do
context "when authenticated as user" do context "when authenticated as user" do
it "should return one of user1's groups" do it "should return one of user1's groups" do
get api("/groups/#{group1.id}", user1) get api("/groups/#{group1.id}", user1)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
json_response['name'] == group1.name json_response['name'] == group1.name
end end
it "should not return a non existing group" do it "should not return a non existing group" do
get api("/groups/1328", user1) get api("/groups/1328", user1)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
it "should not return a group not attached to user1" do it "should not return a group not attached to user1" do
get api("/groups/#{group2.id}", user1) get api("/groups/#{group2.id}", user1)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
context "when authenticated as admin" do context "when authenticated as admin" do
it "should return any existing group" do it "should return any existing group" do
get api("/groups/#{group2.id}", admin) get api("/groups/#{group2.id}", admin)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['name']).to eq(group2.name) expect(json_response['name']).to eq(group2.name)
end end
it "should not return a non existing group" do it "should not return a non existing group" do
get api("/groups/1328", admin) get api("/groups/1328", admin)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
context 'when using group path in URL' do context 'when using group path in URL' do
it 'should return any existing group' do it 'should return any existing group' do
get api("/groups/#{group1.path}", admin) get api("/groups/#{group1.path}", admin)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['name']).to eq(group1.name) expect(json_response['name']).to eq(group1.name)
end end
it 'should not return a non existing group' do it 'should not return a non existing group' do
get api('/groups/unknown', admin) get api('/groups/unknown', admin)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
it 'should not return a group not attached to user1' do it 'should not return a group not attached to user1' do
get api("/groups/#{group2.path}", user1) get api("/groups/#{group2.path}", user1)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
end end
...@@ -107,14 +107,14 @@ describe API::API, api: true do ...@@ -107,14 +107,14 @@ describe API::API, api: true do
it 'updates the group' do it 'updates the group' do
put api("/groups/#{group1.id}", user1), name: new_group_name put api("/groups/#{group1.id}", user1), name: new_group_name
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['name']).to eq(new_group_name) expect(json_response['name']).to eq(new_group_name)
end end
it 'returns 404 for a non existing group' do it 'returns 404 for a non existing group' do
put api('/groups/1328', user1) put api('/groups/1328', user1)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
...@@ -122,7 +122,7 @@ describe API::API, api: true do ...@@ -122,7 +122,7 @@ describe API::API, api: true do
it 'updates the group' do it 'updates the group' do
put api("/groups/#{group1.id}", admin), name: new_group_name put api("/groups/#{group1.id}", admin), name: new_group_name
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['name']).to eq(new_group_name) expect(json_response['name']).to eq(new_group_name)
end end
end end
...@@ -131,7 +131,7 @@ describe API::API, api: true do ...@@ -131,7 +131,7 @@ describe API::API, api: true do
it 'does not updates the group' do it 'does not updates the group' do
put api("/groups/#{group1.id}", user2), name: new_group_name put api("/groups/#{group1.id}", user2), name: new_group_name
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
end end
...@@ -139,7 +139,7 @@ describe API::API, api: true do ...@@ -139,7 +139,7 @@ describe API::API, api: true do
it 'returns 404 when trying to update the group' do it 'returns 404 when trying to update the group' do
put api("/groups/#{group2.id}", user1), name: new_group_name put api("/groups/#{group2.id}", user1), name: new_group_name
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
end end
...@@ -149,7 +149,7 @@ describe API::API, api: true do ...@@ -149,7 +149,7 @@ describe API::API, api: true do
it "should return the group's projects" do it "should return the group's projects" do
get api("/groups/#{group1.id}/projects", user1) get api("/groups/#{group1.id}/projects", user1)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response.length).to eq(2) expect(json_response.length).to eq(2)
project_names = json_response.map { |proj| proj['name' ] } project_names = json_response.map { |proj| proj['name' ] }
expect(project_names).to match_array([project1.name, project3.name]) expect(project_names).to match_array([project1.name, project3.name])
...@@ -157,13 +157,13 @@ describe API::API, api: true do ...@@ -157,13 +157,13 @@ describe API::API, api: true do
it "should not return a non existing group" do it "should not return a non existing group" do
get api("/groups/1328/projects", user1) get api("/groups/1328/projects", user1)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
it "should not return a group not attached to user1" do it "should not return a group not attached to user1" do
get api("/groups/#{group2.id}/projects", user1) get api("/groups/#{group2.id}/projects", user1)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
it "should only return projects to which user has access" do it "should only return projects to which user has access" do
...@@ -171,7 +171,7 @@ describe API::API, api: true do ...@@ -171,7 +171,7 @@ describe API::API, api: true do
get api("/groups/#{group1.id}/projects", user3) get api("/groups/#{group1.id}/projects", user3)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response.first['name']).to eq(project3.name) expect(json_response.first['name']).to eq(project3.name)
end end
...@@ -180,14 +180,14 @@ describe API::API, api: true do ...@@ -180,14 +180,14 @@ describe API::API, api: true do
context "when authenticated as admin" do context "when authenticated as admin" do
it "should return any existing group" do it "should return any existing group" do
get api("/groups/#{group2.id}/projects", admin) get api("/groups/#{group2.id}/projects", admin)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response.first['name']).to eq(project2.name) expect(json_response.first['name']).to eq(project2.name)
end end
it "should not return a non existing group" do it "should not return a non existing group" do
get api("/groups/1328/projects", admin) get api("/groups/1328/projects", admin)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
...@@ -195,20 +195,20 @@ describe API::API, api: true do ...@@ -195,20 +195,20 @@ describe API::API, api: true do
it 'should return any existing group' do it 'should return any existing group' do
get api("/groups/#{group1.path}/projects", admin) get api("/groups/#{group1.path}/projects", admin)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
project_names = json_response.map { |proj| proj['name' ] } project_names = json_response.map { |proj| proj['name' ] }
expect(project_names).to match_array([project1.name, project3.name]) expect(project_names).to match_array([project1.name, project3.name])
end end
it 'should not return a non existing group' do it 'should not return a non existing group' do
get api('/groups/unknown/projects', admin) get api('/groups/unknown/projects', admin)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
it 'should not return a group not attached to user1' do it 'should not return a group not attached to user1' do
get api("/groups/#{group2.path}/projects", user1) get api("/groups/#{group2.path}/projects", user1)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
end end
...@@ -217,30 +217,30 @@ describe API::API, api: true do ...@@ -217,30 +217,30 @@ describe API::API, api: true do
context "when authenticated as user without group permissions" do context "when authenticated as user without group permissions" do
it "should not create group" do it "should not create group" do
post api("/groups", user1), attributes_for(:group) post api("/groups", user1), attributes_for(:group)
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
end end
context "when authenticated as user with group permissions" do context "when authenticated as user with group permissions" do
it "should create group" do it "should create group" do
post api("/groups", user3), attributes_for(:group) post api("/groups", user3), attributes_for(:group)
expect(response.status).to eq(201) expect(response).to have_http_status(201)
end end
it "should not create group, duplicate" do it "should not create group, duplicate" do
post api("/groups", user3), { name: 'Duplicate Test', path: group2.path } post api("/groups", user3), { name: 'Duplicate Test', path: group2.path }
expect(response.status).to eq(400) expect(response).to have_http_status(400)
expect(response.message).to eq("Bad Request") expect(response.message).to eq("Bad Request")
end end
it "should return 400 bad request error if name not given" do it "should return 400 bad request error if name not given" do
post api("/groups", user3), { path: group2.path } post api("/groups", user3), { path: group2.path }
expect(response.status).to eq(400) expect(response).to have_http_status(400)
end end
it "should return 400 bad request error if path not given" do it "should return 400 bad request error if path not given" do
post api("/groups", user3), { name: 'test' } post api("/groups", user3), { name: 'test' }
expect(response.status).to eq(400) expect(response).to have_http_status(400)
end end
end end
end end
...@@ -249,37 +249,37 @@ describe API::API, api: true do ...@@ -249,37 +249,37 @@ describe API::API, api: true do
context "when authenticated as user" do context "when authenticated as user" do
it "should remove group" do it "should remove group" do
delete api("/groups/#{group1.id}", user1) delete api("/groups/#{group1.id}", user1)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
it "should not remove a group if not an owner" do it "should not remove a group if not an owner" do
user4 = create(:user) user4 = create(:user)
group1.add_master(user4) group1.add_master(user4)
delete api("/groups/#{group1.id}", user3) delete api("/groups/#{group1.id}", user3)
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
it "should not remove a non existing group" do it "should not remove a non existing group" do
delete api("/groups/1328", user1) delete api("/groups/1328", user1)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
it "should not remove a group not attached to user1" do it "should not remove a group not attached to user1" do
delete api("/groups/#{group2.id}", user1) delete api("/groups/#{group2.id}", user1)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
context "when authenticated as admin" do context "when authenticated as admin" do
it "should remove any existing group" do it "should remove any existing group" do
delete api("/groups/#{group2.id}", admin) delete api("/groups/#{group2.id}", admin)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
it "should not remove a non existing group" do it "should not remove a non existing group" do
delete api("/groups/1328", admin) delete api("/groups/1328", admin)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
end end
...@@ -295,14 +295,14 @@ describe API::API, api: true do ...@@ -295,14 +295,14 @@ describe API::API, api: true do
context "when authenticated as user" do context "when authenticated as user" do
it "should not transfer project to group" do it "should not transfer project to group" do
post api("/groups/#{group1.id}/projects/#{project.id}", user2) post api("/groups/#{group1.id}/projects/#{project.id}", user2)
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
end end
context "when authenticated as admin" do context "when authenticated as admin" do
it "should transfer project to group" do it "should transfer project to group" do
post api("/groups/#{group1.id}/projects/#{project.id}", admin) post api("/groups/#{group1.id}/projects/#{project.id}", admin)
expect(response.status).to eq(201) expect(response).to have_http_status(201)
end end
end end
end end
......
...@@ -11,7 +11,7 @@ describe API::API, api: true do ...@@ -11,7 +11,7 @@ describe API::API, api: true do
it do it do
get api("/internal/check"), secret_token: secret_token get api("/internal/check"), secret_token: secret_token
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['api_version']).to eq(API::API.version) expect(json_response['api_version']).to eq(API::API.version)
end end
end end
...@@ -23,7 +23,7 @@ describe API::API, api: true do ...@@ -23,7 +23,7 @@ describe API::API, api: true do
it do it do
get api("/internal/broadcast_message"), secret_token: secret_token get api("/internal/broadcast_message"), secret_token: secret_token
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response["message"]).to eq(broadcast_message.message) expect(json_response["message"]).to eq(broadcast_message.message)
end end
end end
...@@ -32,7 +32,7 @@ describe API::API, api: true do ...@@ -32,7 +32,7 @@ describe API::API, api: true do
it do it do
get api("/internal/broadcast_message"), secret_token: secret_token get api("/internal/broadcast_message"), secret_token: secret_token
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_empty expect(json_response).to be_empty
end end
end end
...@@ -42,7 +42,7 @@ describe API::API, api: true do ...@@ -42,7 +42,7 @@ describe API::API, api: true do
it do it do
get(api("/internal/discover"), key_id: key.id, secret_token: secret_token) get(api("/internal/discover"), key_id: key.id, secret_token: secret_token)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['name']).to eq(user.name) expect(json_response['name']).to eq(user.name)
end end
...@@ -61,7 +61,7 @@ describe API::API, api: true do ...@@ -61,7 +61,7 @@ describe API::API, api: true do
push(key, project_wiki) push(key, project_wiki)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response["status"]).to be_truthy expect(json_response["status"]).to be_truthy
end end
end end
...@@ -70,7 +70,7 @@ describe API::API, api: true do ...@@ -70,7 +70,7 @@ describe API::API, api: true do
it do it do
pull(key, project) pull(key, project)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response["status"]).to be_truthy expect(json_response["status"]).to be_truthy
end end
end end
...@@ -79,7 +79,7 @@ describe API::API, api: true do ...@@ -79,7 +79,7 @@ describe API::API, api: true do
it do it do
push(key, project) push(key, project)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response["status"]).to be_truthy expect(json_response["status"]).to be_truthy
end end
end end
...@@ -94,7 +94,7 @@ describe API::API, api: true do ...@@ -94,7 +94,7 @@ describe API::API, api: true do
it do it do
pull(key, project) pull(key, project)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response["status"]).to be_falsey expect(json_response["status"]).to be_falsey
end end
end end
...@@ -103,7 +103,7 @@ describe API::API, api: true do ...@@ -103,7 +103,7 @@ describe API::API, api: true do
it do it do
push(key, project) push(key, project)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response["status"]).to be_falsey expect(json_response["status"]).to be_falsey
end end
end end
...@@ -120,7 +120,7 @@ describe API::API, api: true do ...@@ -120,7 +120,7 @@ describe API::API, api: true do
it do it do
pull(key, personal_project) pull(key, personal_project)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response["status"]).to be_falsey expect(json_response["status"]).to be_falsey
end end
end end
...@@ -129,7 +129,7 @@ describe API::API, api: true do ...@@ -129,7 +129,7 @@ describe API::API, api: true do
it do it do
push(key, personal_project) push(key, personal_project)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response["status"]).to be_falsey expect(json_response["status"]).to be_falsey
end end
end end
...@@ -147,7 +147,7 @@ describe API::API, api: true do ...@@ -147,7 +147,7 @@ describe API::API, api: true do
it do it do
pull(key, project) pull(key, project)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response["status"]).to be_truthy expect(json_response["status"]).to be_truthy
end end
end end
...@@ -156,7 +156,7 @@ describe API::API, api: true do ...@@ -156,7 +156,7 @@ describe API::API, api: true do
it do it do
push(key, project) push(key, project)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response["status"]).to be_falsey expect(json_response["status"]).to be_falsey
end end
end end
...@@ -173,7 +173,7 @@ describe API::API, api: true do ...@@ -173,7 +173,7 @@ describe API::API, api: true do
it do it do
archive(key, project) archive(key, project)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response["status"]).to be_truthy expect(json_response["status"]).to be_truthy
end end
end end
...@@ -182,7 +182,7 @@ describe API::API, api: true do ...@@ -182,7 +182,7 @@ describe API::API, api: true do
it do it do
archive(key, project) archive(key, project)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response["status"]).to be_falsey expect(json_response["status"]).to be_falsey
end end
end end
...@@ -192,7 +192,7 @@ describe API::API, api: true do ...@@ -192,7 +192,7 @@ describe API::API, api: true do
it do it do
pull(key, OpenStruct.new(path_with_namespace: 'gitlab/notexists')) pull(key, OpenStruct.new(path_with_namespace: 'gitlab/notexists'))
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response["status"]).to be_falsey expect(json_response["status"]).to be_falsey
end end
end end
...@@ -201,7 +201,7 @@ describe API::API, api: true do ...@@ -201,7 +201,7 @@ describe API::API, api: true do
it do it do
pull(OpenStruct.new(id: 0), project) pull(OpenStruct.new(id: 0), project)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response["status"]).to be_falsey expect(json_response["status"]).to be_falsey
end end
end end
......
...@@ -51,14 +51,14 @@ describe API::API, api: true do ...@@ -51,14 +51,14 @@ describe API::API, api: true do
context "when unauthenticated" do context "when unauthenticated" do
it "should return authentication error" do it "should return authentication error" do
get api("/issues") get api("/issues")
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
context "when authenticated" do context "when authenticated" do
it "should return an array of issues" do it "should return an array of issues" do
get api("/issues", user) get api("/issues", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first['title']).to eq(issue.title) expect(json_response.first['title']).to eq(issue.title)
end end
...@@ -72,7 +72,7 @@ describe API::API, api: true do ...@@ -72,7 +72,7 @@ describe API::API, api: true do
it 'should return an array of closed issues' do it 'should return an array of closed issues' do
get api('/issues?state=closed', user) get api('/issues?state=closed', user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response.first['id']).to eq(closed_issue.id) expect(json_response.first['id']).to eq(closed_issue.id)
...@@ -80,7 +80,7 @@ describe API::API, api: true do ...@@ -80,7 +80,7 @@ describe API::API, api: true do
it 'should return an array of opened issues' do it 'should return an array of opened issues' do
get api('/issues?state=opened', user) get api('/issues?state=opened', user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response.first['id']).to eq(issue.id) expect(json_response.first['id']).to eq(issue.id)
...@@ -88,7 +88,7 @@ describe API::API, api: true do ...@@ -88,7 +88,7 @@ describe API::API, api: true do
it 'should return an array of all issues' do it 'should return an array of all issues' do
get api('/issues?state=all', user) get api('/issues?state=all', user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(2) expect(json_response.length).to eq(2)
expect(json_response.first['id']).to eq(issue.id) expect(json_response.first['id']).to eq(issue.id)
...@@ -97,7 +97,7 @@ describe API::API, api: true do ...@@ -97,7 +97,7 @@ describe API::API, api: true do
it 'should return an array of labeled issues' do it 'should return an array of labeled issues' do
get api("/issues?labels=#{label.title}", user) get api("/issues?labels=#{label.title}", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response.first['labels']).to eq([label.title]) expect(json_response.first['labels']).to eq([label.title])
...@@ -105,7 +105,7 @@ describe API::API, api: true do ...@@ -105,7 +105,7 @@ describe API::API, api: true do
it 'should return an array of labeled issues when at least one label matches' do it 'should return an array of labeled issues when at least one label matches' do
get api("/issues?labels=#{label.title},foo,bar", user) get api("/issues?labels=#{label.title},foo,bar", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response.first['labels']).to eq([label.title]) expect(json_response.first['labels']).to eq([label.title])
...@@ -113,14 +113,14 @@ describe API::API, api: true do ...@@ -113,14 +113,14 @@ describe API::API, api: true do
it 'should return an empty array if no issue matches labels' do it 'should return an empty array if no issue matches labels' do
get api('/issues?labels=foo,bar', user) get api('/issues?labels=foo,bar', user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(0) expect(json_response.length).to eq(0)
end end
it 'should return an array of labeled issues matching given state' do it 'should return an array of labeled issues matching given state' do
get api("/issues?labels=#{label.title}&state=opened", user) get api("/issues?labels=#{label.title}&state=opened", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response.first['labels']).to eq([label.title]) expect(json_response.first['labels']).to eq([label.title])
...@@ -129,7 +129,7 @@ describe API::API, api: true do ...@@ -129,7 +129,7 @@ describe API::API, api: true do
it 'should return an empty array if no issue matches labels and state filters' do it 'should return an empty array if no issue matches labels and state filters' do
get api("/issues?labels=#{label.title}&state=closed", user) get api("/issues?labels=#{label.title}&state=closed", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(0) expect(json_response.length).to eq(0)
end end
...@@ -179,7 +179,7 @@ describe API::API, api: true do ...@@ -179,7 +179,7 @@ describe API::API, api: true do
it 'returns group issues without confidential issues for non project members' do it 'returns group issues without confidential issues for non project members' do
get api(base_url, non_member) get api(base_url, non_member)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response.first['title']).to eq(group_issue.title) expect(json_response.first['title']).to eq(group_issue.title)
...@@ -188,7 +188,7 @@ describe API::API, api: true do ...@@ -188,7 +188,7 @@ describe API::API, api: true do
it 'returns group confidential issues for author' do it 'returns group confidential issues for author' do
get api(base_url, author) get api(base_url, author)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(2) expect(json_response.length).to eq(2)
end end
...@@ -196,7 +196,7 @@ describe API::API, api: true do ...@@ -196,7 +196,7 @@ describe API::API, api: true do
it 'returns group confidential issues for assignee' do it 'returns group confidential issues for assignee' do
get api(base_url, assignee) get api(base_url, assignee)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(2) expect(json_response.length).to eq(2)
end end
...@@ -204,7 +204,7 @@ describe API::API, api: true do ...@@ -204,7 +204,7 @@ describe API::API, api: true do
it 'returns group issues with confidential issues for project members' do it 'returns group issues with confidential issues for project members' do
get api(base_url, user) get api(base_url, user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(2) expect(json_response.length).to eq(2)
end end
...@@ -212,7 +212,7 @@ describe API::API, api: true do ...@@ -212,7 +212,7 @@ describe API::API, api: true do
it 'returns group confidential issues for admin' do it 'returns group confidential issues for admin' do
get api(base_url, admin) get api(base_url, admin)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(2) expect(json_response.length).to eq(2)
end end
...@@ -220,7 +220,7 @@ describe API::API, api: true do ...@@ -220,7 +220,7 @@ describe API::API, api: true do
it 'returns an array of labeled group issues' do it 'returns an array of labeled group issues' do
get api("#{base_url}?labels=#{group_label.title}", user) get api("#{base_url}?labels=#{group_label.title}", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response.first['labels']).to eq([group_label.title]) expect(json_response.first['labels']).to eq([group_label.title])
...@@ -229,7 +229,7 @@ describe API::API, api: true do ...@@ -229,7 +229,7 @@ describe API::API, api: true do
it 'returns an array of labeled group issues where all labels match' do it 'returns an array of labeled group issues where all labels match' do
get api("#{base_url}?labels=#{group_label.title},foo,bar", user) get api("#{base_url}?labels=#{group_label.title},foo,bar", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(0) expect(json_response.length).to eq(0)
end end
...@@ -237,7 +237,7 @@ describe API::API, api: true do ...@@ -237,7 +237,7 @@ describe API::API, api: true do
it 'returns an empty array if no group issue matches labels' do it 'returns an empty array if no group issue matches labels' do
get api("#{base_url}?labels=foo,bar", user) get api("#{base_url}?labels=foo,bar", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(0) expect(json_response.length).to eq(0)
end end
...@@ -245,7 +245,7 @@ describe API::API, api: true do ...@@ -245,7 +245,7 @@ describe API::API, api: true do
it 'returns an empty array if no issue matches milestone' do it 'returns an empty array if no issue matches milestone' do
get api("#{base_url}?milestone=#{group_empty_milestone.title}", user) get api("#{base_url}?milestone=#{group_empty_milestone.title}", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(0) expect(json_response.length).to eq(0)
end end
...@@ -253,7 +253,7 @@ describe API::API, api: true do ...@@ -253,7 +253,7 @@ describe API::API, api: true do
it 'returns an empty array if milestone does not exist' do it 'returns an empty array if milestone does not exist' do
get api("#{base_url}?milestone=foo", user) get api("#{base_url}?milestone=foo", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(0) expect(json_response.length).to eq(0)
end end
...@@ -261,7 +261,7 @@ describe API::API, api: true do ...@@ -261,7 +261,7 @@ describe API::API, api: true do
it 'returns an array of issues in given milestone' do it 'returns an array of issues in given milestone' do
get api("#{base_url}?milestone=#{group_milestone.title}", user) get api("#{base_url}?milestone=#{group_milestone.title}", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response.first['id']).to eq(group_issue.id) expect(json_response.first['id']).to eq(group_issue.id)
...@@ -271,7 +271,7 @@ describe API::API, api: true do ...@@ -271,7 +271,7 @@ describe API::API, api: true do
get api("#{base_url}?milestone=#{group_milestone.title}"\ get api("#{base_url}?milestone=#{group_milestone.title}"\
'&state=closed', user) '&state=closed', user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response.first['id']).to eq(group_closed_issue.id) expect(json_response.first['id']).to eq(group_closed_issue.id)
...@@ -284,7 +284,7 @@ describe API::API, api: true do ...@@ -284,7 +284,7 @@ describe API::API, api: true do
it 'should return project issues without confidential issues for non project members' do it 'should return project issues without confidential issues for non project members' do
get api("#{base_url}/issues", non_member) get api("#{base_url}/issues", non_member)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(2) expect(json_response.length).to eq(2)
expect(json_response.first['title']).to eq(issue.title) expect(json_response.first['title']).to eq(issue.title)
...@@ -292,7 +292,7 @@ describe API::API, api: true do ...@@ -292,7 +292,7 @@ describe API::API, api: true do
it 'should return project issues without confidential issues for project members with guest role' do it 'should return project issues without confidential issues for project members with guest role' do
get api("#{base_url}/issues", guest) get api("#{base_url}/issues", guest)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(2) expect(json_response.length).to eq(2)
expect(json_response.first['title']).to eq(issue.title) expect(json_response.first['title']).to eq(issue.title)
...@@ -300,7 +300,7 @@ describe API::API, api: true do ...@@ -300,7 +300,7 @@ describe API::API, api: true do
it 'should return project confidential issues for author' do it 'should return project confidential issues for author' do
get api("#{base_url}/issues", author) get api("#{base_url}/issues", author)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(3) expect(json_response.length).to eq(3)
expect(json_response.first['title']).to eq(issue.title) expect(json_response.first['title']).to eq(issue.title)
...@@ -308,7 +308,7 @@ describe API::API, api: true do ...@@ -308,7 +308,7 @@ describe API::API, api: true do
it 'should return project confidential issues for assignee' do it 'should return project confidential issues for assignee' do
get api("#{base_url}/issues", assignee) get api("#{base_url}/issues", assignee)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(3) expect(json_response.length).to eq(3)
expect(json_response.first['title']).to eq(issue.title) expect(json_response.first['title']).to eq(issue.title)
...@@ -316,7 +316,7 @@ describe API::API, api: true do ...@@ -316,7 +316,7 @@ describe API::API, api: true do
it 'should return project issues with confidential issues for project members' do it 'should return project issues with confidential issues for project members' do
get api("#{base_url}/issues", user) get api("#{base_url}/issues", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(3) expect(json_response.length).to eq(3)
expect(json_response.first['title']).to eq(issue.title) expect(json_response.first['title']).to eq(issue.title)
...@@ -324,7 +324,7 @@ describe API::API, api: true do ...@@ -324,7 +324,7 @@ describe API::API, api: true do
it 'should return project confidential issues for admin' do it 'should return project confidential issues for admin' do
get api("#{base_url}/issues", admin) get api("#{base_url}/issues", admin)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(3) expect(json_response.length).to eq(3)
expect(json_response.first['title']).to eq(issue.title) expect(json_response.first['title']).to eq(issue.title)
...@@ -332,7 +332,7 @@ describe API::API, api: true do ...@@ -332,7 +332,7 @@ describe API::API, api: true do
it 'should return an array of labeled project issues' do it 'should return an array of labeled project issues' do
get api("#{base_url}/issues?labels=#{label.title}", user) get api("#{base_url}/issues?labels=#{label.title}", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response.first['labels']).to eq([label.title]) expect(json_response.first['labels']).to eq([label.title])
...@@ -340,7 +340,7 @@ describe API::API, api: true do ...@@ -340,7 +340,7 @@ describe API::API, api: true do
it 'should return an array of labeled project issues when at least one label matches' do it 'should return an array of labeled project issues when at least one label matches' do
get api("#{base_url}/issues?labels=#{label.title},foo,bar", user) get api("#{base_url}/issues?labels=#{label.title},foo,bar", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response.first['labels']).to eq([label.title]) expect(json_response.first['labels']).to eq([label.title])
...@@ -348,28 +348,28 @@ describe API::API, api: true do ...@@ -348,28 +348,28 @@ describe API::API, api: true do
it 'should return an empty array if no project issue matches labels' do it 'should return an empty array if no project issue matches labels' do
get api("#{base_url}/issues?labels=foo,bar", user) get api("#{base_url}/issues?labels=foo,bar", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(0) expect(json_response.length).to eq(0)
end end
it 'should return an empty array if no issue matches milestone' do it 'should return an empty array if no issue matches milestone' do
get api("#{base_url}/issues?milestone=#{empty_milestone.title}", user) get api("#{base_url}/issues?milestone=#{empty_milestone.title}", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(0) expect(json_response.length).to eq(0)
end end
it 'should return an empty array if milestone does not exist' do it 'should return an empty array if milestone does not exist' do
get api("#{base_url}/issues?milestone=foo", user) get api("#{base_url}/issues?milestone=foo", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(0) expect(json_response.length).to eq(0)
end end
it 'should return an array of issues in given milestone' do it 'should return an array of issues in given milestone' do
get api("#{base_url}/issues?milestone=#{title}", user) get api("#{base_url}/issues?milestone=#{title}", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(2) expect(json_response.length).to eq(2)
expect(json_response.first['id']).to eq(issue.id) expect(json_response.first['id']).to eq(issue.id)
...@@ -379,7 +379,7 @@ describe API::API, api: true do ...@@ -379,7 +379,7 @@ describe API::API, api: true do
it 'should return an array of issues matching state in milestone' do it 'should return an array of issues matching state in milestone' do
get api("#{base_url}/issues?milestone=#{milestone.title}"\ get api("#{base_url}/issues?milestone=#{milestone.title}"\
'&state=closed', user) '&state=closed', user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response.first['id']).to eq(closed_issue.id) expect(json_response.first['id']).to eq(closed_issue.id)
...@@ -390,7 +390,7 @@ describe API::API, api: true do ...@@ -390,7 +390,7 @@ describe API::API, api: true do
it 'exposes known attributes' do it 'exposes known attributes' do
get api("/projects/#{project.id}/issues/#{issue.id}", user) get api("/projects/#{project.id}/issues/#{issue.id}", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['id']).to eq(issue.id) expect(json_response['id']).to eq(issue.id)
expect(json_response['iid']).to eq(issue.iid) expect(json_response['iid']).to eq(issue.iid)
expect(json_response['project_id']).to eq(issue.project.id) expect(json_response['project_id']).to eq(issue.project.id)
...@@ -408,7 +408,7 @@ describe API::API, api: true do ...@@ -408,7 +408,7 @@ describe API::API, api: true do
it "should return a project issue by id" do it "should return a project issue by id" do
get api("/projects/#{project.id}/issues/#{issue.id}", user) get api("/projects/#{project.id}/issues/#{issue.id}", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['title']).to eq(issue.title) expect(json_response['title']).to eq(issue.title)
expect(json_response['iid']).to eq(issue.iid) expect(json_response['iid']).to eq(issue.iid)
end end
...@@ -423,44 +423,44 @@ describe API::API, api: true do ...@@ -423,44 +423,44 @@ describe API::API, api: true do
it "should return 404 if issue id not found" do it "should return 404 if issue id not found" do
get api("/projects/#{project.id}/issues/54321", user) get api("/projects/#{project.id}/issues/54321", user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
context 'confidential issues' do context 'confidential issues' do
it "should return 404 for non project members" do it "should return 404 for non project members" do
get api("/projects/#{project.id}/issues/#{confidential_issue.id}", non_member) get api("/projects/#{project.id}/issues/#{confidential_issue.id}", non_member)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
it "should return 404 for project members with guest role" do it "should return 404 for project members with guest role" do
get api("/projects/#{project.id}/issues/#{confidential_issue.id}", guest) get api("/projects/#{project.id}/issues/#{confidential_issue.id}", guest)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
it "should return confidential issue for project members" do it "should return confidential issue for project members" do
get api("/projects/#{project.id}/issues/#{confidential_issue.id}", user) get api("/projects/#{project.id}/issues/#{confidential_issue.id}", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['title']).to eq(confidential_issue.title) expect(json_response['title']).to eq(confidential_issue.title)
expect(json_response['iid']).to eq(confidential_issue.iid) expect(json_response['iid']).to eq(confidential_issue.iid)
end end
it "should return confidential issue for author" do it "should return confidential issue for author" do
get api("/projects/#{project.id}/issues/#{confidential_issue.id}", author) get api("/projects/#{project.id}/issues/#{confidential_issue.id}", author)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['title']).to eq(confidential_issue.title) expect(json_response['title']).to eq(confidential_issue.title)
expect(json_response['iid']).to eq(confidential_issue.iid) expect(json_response['iid']).to eq(confidential_issue.iid)
end end
it "should return confidential issue for assignee" do it "should return confidential issue for assignee" do
get api("/projects/#{project.id}/issues/#{confidential_issue.id}", assignee) get api("/projects/#{project.id}/issues/#{confidential_issue.id}", assignee)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['title']).to eq(confidential_issue.title) expect(json_response['title']).to eq(confidential_issue.title)
expect(json_response['iid']).to eq(confidential_issue.iid) expect(json_response['iid']).to eq(confidential_issue.iid)
end end
it "should return confidential issue for admin" do it "should return confidential issue for admin" do
get api("/projects/#{project.id}/issues/#{confidential_issue.id}", admin) get api("/projects/#{project.id}/issues/#{confidential_issue.id}", admin)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['title']).to eq(confidential_issue.title) expect(json_response['title']).to eq(confidential_issue.title)
expect(json_response['iid']).to eq(confidential_issue.iid) expect(json_response['iid']).to eq(confidential_issue.iid)
end end
...@@ -471,7 +471,7 @@ describe API::API, api: true do ...@@ -471,7 +471,7 @@ describe API::API, api: true do
it "should create a new project issue" do it "should create a new project issue" do
post api("/projects/#{project.id}/issues", user), post api("/projects/#{project.id}/issues", user),
title: 'new issue', labels: 'label, label2' title: 'new issue', labels: 'label, label2'
expect(response.status).to eq(201) expect(response).to have_http_status(201)
expect(json_response['title']).to eq('new issue') expect(json_response['title']).to eq('new issue')
expect(json_response['description']).to be_nil expect(json_response['description']).to be_nil
expect(json_response['labels']).to eq(['label', 'label2']) expect(json_response['labels']).to eq(['label', 'label2'])
...@@ -479,21 +479,21 @@ describe API::API, api: true do ...@@ -479,21 +479,21 @@ describe API::API, api: true do
it "should return a 400 bad request if title not given" do it "should return a 400 bad request if title not given" do
post api("/projects/#{project.id}/issues", user), labels: 'label, label2' post api("/projects/#{project.id}/issues", user), labels: 'label, label2'
expect(response.status).to eq(400) expect(response).to have_http_status(400)
end end
it 'should return 400 on invalid label names' do it 'should return 400 on invalid label names' do
post api("/projects/#{project.id}/issues", user), post api("/projects/#{project.id}/issues", user),
title: 'new issue', title: 'new issue',
labels: 'label, ?' labels: 'label, ?'
expect(response.status).to eq(400) expect(response).to have_http_status(400)
expect(json_response['message']['labels']['?']['title']).to eq(['is invalid']) expect(json_response['message']['labels']['?']['title']).to eq(['is invalid'])
end end
it 'should return 400 if title is too long' do it 'should return 400 if title is too long' do
post api("/projects/#{project.id}/issues", user), post api("/projects/#{project.id}/issues", user),
title: 'g' * 256 title: 'g' * 256
expect(response.status).to eq(400) expect(response).to have_http_status(400)
expect(json_response['message']['title']).to eq([ expect(json_response['message']['title']).to eq([
'is too long (maximum is 255 characters)' 'is too long (maximum is 255 characters)'
]) ])
...@@ -505,7 +505,7 @@ describe API::API, api: true do ...@@ -505,7 +505,7 @@ describe API::API, api: true do
post api("/projects/#{project.id}/issues", user), post api("/projects/#{project.id}/issues", user),
title: 'new issue', labels: 'label, label2', created_at: creation_time title: 'new issue', labels: 'label, label2', created_at: creation_time
expect(response.status).to eq(201) expect(response).to have_http_status(201)
expect(Time.parse(json_response['created_at'])).to be_within(1.second).of(creation_time) expect(Time.parse(json_response['created_at'])).to be_within(1.second).of(creation_time)
end end
end end
...@@ -529,7 +529,7 @@ describe API::API, api: true do ...@@ -529,7 +529,7 @@ describe API::API, api: true do
it "should not create a new project issue" do it "should not create a new project issue" do
expect { post api("/projects/#{project.id}/issues", user), params }.not_to change(Issue, :count) expect { post api("/projects/#{project.id}/issues", user), params }.not_to change(Issue, :count)
expect(response.status).to eq(400) expect(response).to have_http_status(400)
expect(json_response['message']).to eq({ "error" => "Spam detected" }) expect(json_response['message']).to eq({ "error" => "Spam detected" })
spam_logs = SpamLog.all spam_logs = SpamLog.all
...@@ -546,7 +546,7 @@ describe API::API, api: true do ...@@ -546,7 +546,7 @@ describe API::API, api: true do
it "should update a project issue" do it "should update a project issue" do
put api("/projects/#{project.id}/issues/#{issue.id}", user), put api("/projects/#{project.id}/issues/#{issue.id}", user),
title: 'updated title' title: 'updated title'
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['title']).to eq('updated title') expect(json_response['title']).to eq('updated title')
end end
...@@ -554,14 +554,14 @@ describe API::API, api: true do ...@@ -554,14 +554,14 @@ describe API::API, api: true do
it "should return 404 error if issue id not found" do it "should return 404 error if issue id not found" do
put api("/projects/#{project.id}/issues/44444", user), put api("/projects/#{project.id}/issues/44444", user),
title: 'updated title' title: 'updated title'
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
it 'should return 400 on invalid label names' do it 'should return 400 on invalid label names' do
put api("/projects/#{project.id}/issues/#{issue.id}", user), put api("/projects/#{project.id}/issues/#{issue.id}", user),
title: 'updated title', title: 'updated title',
labels: 'label, ?' labels: 'label, ?'
expect(response.status).to eq(400) expect(response).to have_http_status(400)
expect(json_response['message']['labels']['?']['title']).to eq(['is invalid']) expect(json_response['message']['labels']['?']['title']).to eq(['is invalid'])
end end
...@@ -569,33 +569,33 @@ describe API::API, api: true do ...@@ -569,33 +569,33 @@ describe API::API, api: true do
it "should return 403 for non project members" do it "should return 403 for non project members" do
put api("/projects/#{project.id}/issues/#{confidential_issue.id}", non_member), put api("/projects/#{project.id}/issues/#{confidential_issue.id}", non_member),
title: 'updated title' title: 'updated title'
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
it "should return 403 for project members with guest role" do it "should return 403 for project members with guest role" do
put api("/projects/#{project.id}/issues/#{confidential_issue.id}", guest), put api("/projects/#{project.id}/issues/#{confidential_issue.id}", guest),
title: 'updated title' title: 'updated title'
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
it "should update a confidential issue for project members" do it "should update a confidential issue for project members" do
put api("/projects/#{project.id}/issues/#{confidential_issue.id}", user), put api("/projects/#{project.id}/issues/#{confidential_issue.id}", user),
title: 'updated title' title: 'updated title'
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['title']).to eq('updated title') expect(json_response['title']).to eq('updated title')
end end
it "should update a confidential issue for author" do it "should update a confidential issue for author" do
put api("/projects/#{project.id}/issues/#{confidential_issue.id}", author), put api("/projects/#{project.id}/issues/#{confidential_issue.id}", author),
title: 'updated title' title: 'updated title'
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['title']).to eq('updated title') expect(json_response['title']).to eq('updated title')
end end
it "should update a confidential issue for admin" do it "should update a confidential issue for admin" do
put api("/projects/#{project.id}/issues/#{confidential_issue.id}", admin), put api("/projects/#{project.id}/issues/#{confidential_issue.id}", admin),
title: 'updated title' title: 'updated title'
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['title']).to eq('updated title') expect(json_response['title']).to eq('updated title')
end end
end end
...@@ -608,21 +608,21 @@ describe API::API, api: true do ...@@ -608,21 +608,21 @@ describe API::API, api: true do
it 'should not update labels if not present' do it 'should not update labels if not present' do
put api("/projects/#{project.id}/issues/#{issue.id}", user), put api("/projects/#{project.id}/issues/#{issue.id}", user),
title: 'updated title' title: 'updated title'
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['labels']).to eq([label.title]) expect(json_response['labels']).to eq([label.title])
end end
it 'should remove all labels' do it 'should remove all labels' do
put api("/projects/#{project.id}/issues/#{issue.id}", user), put api("/projects/#{project.id}/issues/#{issue.id}", user),
labels: '' labels: ''
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['labels']).to eq([]) expect(json_response['labels']).to eq([])
end end
it 'should update labels' do it 'should update labels' do
put api("/projects/#{project.id}/issues/#{issue.id}", user), put api("/projects/#{project.id}/issues/#{issue.id}", user),
labels: 'foo,bar' labels: 'foo,bar'
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['labels']).to include 'foo' expect(json_response['labels']).to include 'foo'
expect(json_response['labels']).to include 'bar' expect(json_response['labels']).to include 'bar'
end end
...@@ -630,14 +630,14 @@ describe API::API, api: true do ...@@ -630,14 +630,14 @@ describe API::API, api: true do
it 'should return 400 on invalid label names' do it 'should return 400 on invalid label names' do
put api("/projects/#{project.id}/issues/#{issue.id}", user), put api("/projects/#{project.id}/issues/#{issue.id}", user),
labels: 'label, ?' labels: 'label, ?'
expect(response.status).to eq(400) expect(response).to have_http_status(400)
expect(json_response['message']['labels']['?']['title']).to eq(['is invalid']) expect(json_response['message']['labels']['?']['title']).to eq(['is invalid'])
end end
it 'should allow special label names' do it 'should allow special label names' do
put api("/projects/#{project.id}/issues/#{issue.id}", user), put api("/projects/#{project.id}/issues/#{issue.id}", user),
labels: 'label:foo, label-bar,label_bar,label/bar' labels: 'label:foo, label-bar,label_bar,label/bar'
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['labels']).to include 'label:foo' expect(json_response['labels']).to include 'label:foo'
expect(json_response['labels']).to include 'label-bar' expect(json_response['labels']).to include 'label-bar'
expect(json_response['labels']).to include 'label_bar' expect(json_response['labels']).to include 'label_bar'
...@@ -647,7 +647,7 @@ describe API::API, api: true do ...@@ -647,7 +647,7 @@ describe API::API, api: true do
it 'should return 400 if title is too long' do it 'should return 400 if title is too long' do
put api("/projects/#{project.id}/issues/#{issue.id}", user), put api("/projects/#{project.id}/issues/#{issue.id}", user),
title: 'g' * 256 title: 'g' * 256
expect(response.status).to eq(400) expect(response).to have_http_status(400)
expect(json_response['message']['title']).to eq([ expect(json_response['message']['title']).to eq([
'is too long (maximum is 255 characters)' 'is too long (maximum is 255 characters)'
]) ])
...@@ -658,7 +658,7 @@ describe API::API, api: true do ...@@ -658,7 +658,7 @@ describe API::API, api: true do
it "should update a project issue" do it "should update a project issue" do
put api("/projects/#{project.id}/issues/#{issue.id}", user), put api("/projects/#{project.id}/issues/#{issue.id}", user),
labels: 'label2', state_event: "close" labels: 'label2', state_event: "close"
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['labels']).to include 'label2' expect(json_response['labels']).to include 'label2'
expect(json_response['state']).to eq "closed" expect(json_response['state']).to eq "closed"
...@@ -669,7 +669,7 @@ describe API::API, api: true do ...@@ -669,7 +669,7 @@ describe API::API, api: true do
update_time = 2.weeks.ago update_time = 2.weeks.ago
put api("/projects/#{project.id}/issues/#{issue.id}", user), put api("/projects/#{project.id}/issues/#{issue.id}", user),
labels: 'label3', state_event: 'close', updated_at: update_time labels: 'label3', state_event: 'close', updated_at: update_time
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['labels']).to include 'label3' expect(json_response['labels']).to include 'label3'
expect(Time.parse(json_response['updated_at'])).to be_within(1.second).of(update_time) expect(Time.parse(json_response['updated_at'])).to be_within(1.second).of(update_time)
...@@ -680,12 +680,12 @@ describe API::API, api: true do ...@@ -680,12 +680,12 @@ describe API::API, api: true do
describe "DELETE /projects/:id/issues/:issue_id" do describe "DELETE /projects/:id/issues/:issue_id" do
it "rejects a non member from deleting an issue" do it "rejects a non member from deleting an issue" do
delete api("/projects/#{project.id}/issues/#{issue.id}", non_member) delete api("/projects/#{project.id}/issues/#{issue.id}", non_member)
expect(response.status).to be(403) expect(response).to have_http_status(403)
end end
it "rejects a developer from deleting an issue" do it "rejects a developer from deleting an issue" do
delete api("/projects/#{project.id}/issues/#{issue.id}", author) delete api("/projects/#{project.id}/issues/#{issue.id}", author)
expect(response.status).to be(403) expect(response).to have_http_status(403)
end end
context "when the user is project owner" do context "when the user is project owner" do
...@@ -694,7 +694,7 @@ describe API::API, api: true do ...@@ -694,7 +694,7 @@ describe API::API, api: true do
it "deletes the issue if an admin requests it" do it "deletes the issue if an admin requests it" do
delete api("/projects/#{project.id}/issues/#{issue.id}", owner) delete api("/projects/#{project.id}/issues/#{issue.id}", owner)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['state']).to eq 'opened' expect(json_response['state']).to eq 'opened'
end end
end end
...@@ -708,7 +708,7 @@ describe API::API, api: true do ...@@ -708,7 +708,7 @@ describe API::API, api: true do
post api("/projects/#{project.id}/issues/#{issue.id}/move", user), post api("/projects/#{project.id}/issues/#{issue.id}/move", user),
to_project_id: target_project.id to_project_id: target_project.id
expect(response.status).to eq(201) expect(response).to have_http_status(201)
expect(json_response['project_id']).to eq(target_project.id) expect(json_response['project_id']).to eq(target_project.id)
end end
...@@ -717,7 +717,7 @@ describe API::API, api: true do ...@@ -717,7 +717,7 @@ describe API::API, api: true do
post api("/projects/#{project.id}/issues/#{issue.id}/move", user), post api("/projects/#{project.id}/issues/#{issue.id}/move", user),
to_project_id: project.id to_project_id: project.id
expect(response.status).to eq(400) expect(response).to have_http_status(400)
expect(json_response['message']).to eq('Cannot move issue to project it originates from!') expect(json_response['message']).to eq('Cannot move issue to project it originates from!')
end end
end end
...@@ -727,7 +727,7 @@ describe API::API, api: true do ...@@ -727,7 +727,7 @@ describe API::API, api: true do
post api("/projects/#{project.id}/issues/#{issue.id}/move", user), post api("/projects/#{project.id}/issues/#{issue.id}/move", user),
to_project_id: target_project2.id to_project_id: target_project2.id
expect(response.status).to eq(400) expect(response).to have_http_status(400)
expect(json_response['message']).to eq('Cannot move issue due to insufficient permissions!') expect(json_response['message']).to eq('Cannot move issue due to insufficient permissions!')
end end
end end
...@@ -736,7 +736,7 @@ describe API::API, api: true do ...@@ -736,7 +736,7 @@ describe API::API, api: true do
post api("/projects/#{project.id}/issues/#{issue.id}/move", admin), post api("/projects/#{project.id}/issues/#{issue.id}/move", admin),
to_project_id: target_project2.id to_project_id: target_project2.id
expect(response.status).to eq(201) expect(response).to have_http_status(201)
expect(json_response['project_id']).to eq(target_project2.id) expect(json_response['project_id']).to eq(target_project2.id)
end end
...@@ -745,7 +745,7 @@ describe API::API, api: true do ...@@ -745,7 +745,7 @@ describe API::API, api: true do
post api("/projects/#{project.id}/issues/123/move", user), post api("/projects/#{project.id}/issues/123/move", user),
to_project_id: target_project.id to_project_id: target_project.id
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
...@@ -754,7 +754,7 @@ describe API::API, api: true do ...@@ -754,7 +754,7 @@ describe API::API, api: true do
post api("/projects/123/issues/#{issue.id}/move", user), post api("/projects/123/issues/#{issue.id}/move", user),
to_project_id: target_project.id to_project_id: target_project.id
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
...@@ -763,7 +763,7 @@ describe API::API, api: true do ...@@ -763,7 +763,7 @@ describe API::API, api: true do
post api("/projects/#{project.id}/issues/#{issue.id}/move", user), post api("/projects/#{project.id}/issues/#{issue.id}/move", user),
to_project_id: 123 to_project_id: 123
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
end end
...@@ -772,26 +772,26 @@ describe API::API, api: true do ...@@ -772,26 +772,26 @@ describe API::API, api: true do
it 'subscribes to an issue' do it 'subscribes to an issue' do
post api("/projects/#{project.id}/issues/#{issue.id}/subscription", user2) post api("/projects/#{project.id}/issues/#{issue.id}/subscription", user2)
expect(response.status).to eq(201) expect(response).to have_http_status(201)
expect(json_response['subscribed']).to eq(true) expect(json_response['subscribed']).to eq(true)
end end
it 'returns 304 if already subscribed' do it 'returns 304 if already subscribed' do
post api("/projects/#{project.id}/issues/#{issue.id}/subscription", user) post api("/projects/#{project.id}/issues/#{issue.id}/subscription", user)
expect(response.status).to eq(304) expect(response).to have_http_status(304)
end end
it 'returns 404 if the issue is not found' do it 'returns 404 if the issue is not found' do
post api("/projects/#{project.id}/issues/123/subscription", user) post api("/projects/#{project.id}/issues/123/subscription", user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
it 'returns 404 if the issue is confidential' do it 'returns 404 if the issue is confidential' do
post api("/projects/#{project.id}/issues/#{confidential_issue.id}/subscription", non_member) post api("/projects/#{project.id}/issues/#{confidential_issue.id}/subscription", non_member)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
...@@ -799,26 +799,26 @@ describe API::API, api: true do ...@@ -799,26 +799,26 @@ describe API::API, api: true do
it 'unsubscribes from an issue' do it 'unsubscribes from an issue' do
delete api("/projects/#{project.id}/issues/#{issue.id}/subscription", user) delete api("/projects/#{project.id}/issues/#{issue.id}/subscription", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['subscribed']).to eq(false) expect(json_response['subscribed']).to eq(false)
end end
it 'returns 304 if not subscribed' do it 'returns 304 if not subscribed' do
delete api("/projects/#{project.id}/issues/#{issue.id}/subscription", user2) delete api("/projects/#{project.id}/issues/#{issue.id}/subscription", user2)
expect(response.status).to eq(304) expect(response).to have_http_status(304)
end end
it 'returns 404 if the issue is not found' do it 'returns 404 if the issue is not found' do
delete api("/projects/#{project.id}/issues/123/subscription", user) delete api("/projects/#{project.id}/issues/123/subscription", user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
it 'returns 404 if the issue is confidential' do it 'returns 404 if the issue is confidential' do
delete api("/projects/#{project.id}/issues/#{confidential_issue.id}/subscription", non_member) delete api("/projects/#{project.id}/issues/#{confidential_issue.id}/subscription", non_member)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
end end
...@@ -14,14 +14,14 @@ describe API::API, api: true do ...@@ -14,14 +14,14 @@ describe API::API, api: true do
context 'when unauthenticated' do context 'when unauthenticated' do
it 'should return authentication error' do it 'should return authentication error' do
get api("/keys/#{key.id}") get api("/keys/#{key.id}")
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
context 'when authenticated' do context 'when authenticated' do
it 'should return 404 for non-existing key' do it 'should return 404 for non-existing key' do
get api('/keys/999999', admin) get api('/keys/999999', admin)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
expect(json_response['message']).to eq('404 Not found') expect(json_response['message']).to eq('404 Not found')
end end
...@@ -29,7 +29,7 @@ describe API::API, api: true do ...@@ -29,7 +29,7 @@ describe API::API, api: true do
user.keys << key user.keys << key
user.save user.save
get api("/keys/#{key.id}", admin) get api("/keys/#{key.id}", admin)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['title']).to eq(key.title) expect(json_response['title']).to eq(key.title)
expect(json_response['user']['id']).to eq(user.id) expect(json_response['user']['id']).to eq(user.id)
expect(json_response['user']['username']).to eq(user.username) expect(json_response['user']['username']).to eq(user.username)
......
...@@ -15,7 +15,7 @@ describe API::API, api: true do ...@@ -15,7 +15,7 @@ describe API::API, api: true do
describe 'GET /projects/:id/labels' do describe 'GET /projects/:id/labels' do
it 'should return project labels' do it 'should return project labels' do
get api("/projects/#{project.id}/labels", user) get api("/projects/#{project.id}/labels", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.size).to eq(1) expect(json_response.size).to eq(1)
expect(json_response.first['name']).to eq(label1.name) expect(json_response.first['name']).to eq(label1.name)
...@@ -28,7 +28,7 @@ describe API::API, api: true do ...@@ -28,7 +28,7 @@ describe API::API, api: true do
name: 'Foo', name: 'Foo',
color: '#FFAABB', color: '#FFAABB',
description: 'test' description: 'test'
expect(response.status).to eq(201) expect(response).to have_http_status(201)
expect(json_response['name']).to eq('Foo') expect(json_response['name']).to eq('Foo')
expect(json_response['color']).to eq('#FFAABB') expect(json_response['color']).to eq('#FFAABB')
expect(json_response['description']).to eq('test') expect(json_response['description']).to eq('test')
...@@ -38,7 +38,7 @@ describe API::API, api: true do ...@@ -38,7 +38,7 @@ describe API::API, api: true do
post api("/projects/#{project.id}/labels", user), post api("/projects/#{project.id}/labels", user),
name: 'Foo', name: 'Foo',
color: '#FFAABB' color: '#FFAABB'
expect(response.status).to eq(201) expect(response).to have_http_status(201)
expect(json_response['name']).to eq('Foo') expect(json_response['name']).to eq('Foo')
expect(json_response['color']).to eq('#FFAABB') expect(json_response['color']).to eq('#FFAABB')
expect(json_response['description']).to be_nil expect(json_response['description']).to be_nil
...@@ -46,19 +46,19 @@ describe API::API, api: true do ...@@ -46,19 +46,19 @@ describe API::API, api: true do
it 'should return a 400 bad request if name not given' do it 'should return a 400 bad request if name not given' do
post api("/projects/#{project.id}/labels", user), color: '#FFAABB' post api("/projects/#{project.id}/labels", user), color: '#FFAABB'
expect(response.status).to eq(400) expect(response).to have_http_status(400)
end end
it 'should return a 400 bad request if color not given' do it 'should return a 400 bad request if color not given' do
post api("/projects/#{project.id}/labels", user), name: 'Foobar' post api("/projects/#{project.id}/labels", user), name: 'Foobar'
expect(response.status).to eq(400) expect(response).to have_http_status(400)
end end
it 'should return 400 for invalid color' do it 'should return 400 for invalid color' do
post api("/projects/#{project.id}/labels", user), post api("/projects/#{project.id}/labels", user),
name: 'Foo', name: 'Foo',
color: '#FFAA' color: '#FFAA'
expect(response.status).to eq(400) expect(response).to have_http_status(400)
expect(json_response['message']['color']).to eq(['must be a valid color code']) expect(json_response['message']['color']).to eq(['must be a valid color code'])
end end
...@@ -66,7 +66,7 @@ describe API::API, api: true do ...@@ -66,7 +66,7 @@ describe API::API, api: true do
post api("/projects/#{project.id}/labels", user), post api("/projects/#{project.id}/labels", user),
name: 'Foo', name: 'Foo',
color: '#FFAAFFFF' color: '#FFAAFFFF'
expect(response.status).to eq(400) expect(response).to have_http_status(400)
expect(json_response['message']['color']).to eq(['must be a valid color code']) expect(json_response['message']['color']).to eq(['must be a valid color code'])
end end
...@@ -74,7 +74,7 @@ describe API::API, api: true do ...@@ -74,7 +74,7 @@ describe API::API, api: true do
post api("/projects/#{project.id}/labels", user), post api("/projects/#{project.id}/labels", user),
name: '?', name: '?',
color: '#FFAABB' color: '#FFAABB'
expect(response.status).to eq(400) expect(response).to have_http_status(400)
expect(json_response['message']['title']).to eq(['is invalid']) expect(json_response['message']['title']).to eq(['is invalid'])
end end
...@@ -82,7 +82,7 @@ describe API::API, api: true do ...@@ -82,7 +82,7 @@ describe API::API, api: true do
post api("/projects/#{project.id}/labels", user), post api("/projects/#{project.id}/labels", user),
name: 'label1', name: 'label1',
color: '#FFAABB' color: '#FFAABB'
expect(response.status).to eq(409) expect(response).to have_http_status(409)
expect(json_response['message']).to eq('Label already exists') expect(json_response['message']).to eq('Label already exists')
end end
end end
...@@ -90,18 +90,18 @@ describe API::API, api: true do ...@@ -90,18 +90,18 @@ describe API::API, api: true do
describe 'DELETE /projects/:id/labels' do describe 'DELETE /projects/:id/labels' do
it 'should return 200 for existing label' do it 'should return 200 for existing label' do
delete api("/projects/#{project.id}/labels", user), name: 'label1' delete api("/projects/#{project.id}/labels", user), name: 'label1'
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
it 'should return 404 for non existing label' do it 'should return 404 for non existing label' do
delete api("/projects/#{project.id}/labels", user), name: 'label2' delete api("/projects/#{project.id}/labels", user), name: 'label2'
expect(response.status).to eq(404) expect(response).to have_http_status(404)
expect(json_response['message']).to eq('404 Label Not Found') expect(json_response['message']).to eq('404 Label Not Found')
end end
it 'should return 400 for wrong parameters' do it 'should return 400 for wrong parameters' do
delete api("/projects/#{project.id}/labels", user) delete api("/projects/#{project.id}/labels", user)
expect(response.status).to eq(400) expect(response).to have_http_status(400)
end end
end end
...@@ -112,7 +112,7 @@ describe API::API, api: true do ...@@ -112,7 +112,7 @@ describe API::API, api: true do
new_name: 'New Label', new_name: 'New Label',
color: '#FFFFFF', color: '#FFFFFF',
description: 'test' description: 'test'
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['name']).to eq('New Label') expect(json_response['name']).to eq('New Label')
expect(json_response['color']).to eq('#FFFFFF') expect(json_response['color']).to eq('#FFFFFF')
expect(json_response['description']).to eq('test') expect(json_response['description']).to eq('test')
...@@ -122,7 +122,7 @@ describe API::API, api: true do ...@@ -122,7 +122,7 @@ describe API::API, api: true do
put api("/projects/#{project.id}/labels", user), put api("/projects/#{project.id}/labels", user),
name: 'label1', name: 'label1',
new_name: 'New Label' new_name: 'New Label'
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['name']).to eq('New Label') expect(json_response['name']).to eq('New Label')
expect(json_response['color']).to eq(label1.color) expect(json_response['color']).to eq(label1.color)
end end
...@@ -131,7 +131,7 @@ describe API::API, api: true do ...@@ -131,7 +131,7 @@ describe API::API, api: true do
put api("/projects/#{project.id}/labels", user), put api("/projects/#{project.id}/labels", user),
name: 'label1', name: 'label1',
color: '#FFFFFF' color: '#FFFFFF'
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['name']).to eq(label1.name) expect(json_response['name']).to eq(label1.name)
expect(json_response['color']).to eq('#FFFFFF') expect(json_response['color']).to eq('#FFFFFF')
end end
...@@ -140,7 +140,7 @@ describe API::API, api: true do ...@@ -140,7 +140,7 @@ describe API::API, api: true do
put api("/projects/#{project.id}/labels", user), put api("/projects/#{project.id}/labels", user),
name: 'label1', name: 'label1',
description: 'test' description: 'test'
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['name']).to eq(label1.name) expect(json_response['name']).to eq(label1.name)
expect(json_response['description']).to eq('test') expect(json_response['description']).to eq('test')
end end
...@@ -149,18 +149,18 @@ describe API::API, api: true do ...@@ -149,18 +149,18 @@ describe API::API, api: true do
put api("/projects/#{project.id}/labels", user), put api("/projects/#{project.id}/labels", user),
name: 'label2', name: 'label2',
new_name: 'label3' new_name: 'label3'
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
it 'should return 400 if no label name given' do it 'should return 400 if no label name given' do
put api("/projects/#{project.id}/labels", user), new_name: 'label2' put api("/projects/#{project.id}/labels", user), new_name: 'label2'
expect(response.status).to eq(400) expect(response).to have_http_status(400)
expect(json_response['message']).to eq('400 (Bad request) "name" not given') expect(json_response['message']).to eq('400 (Bad request) "name" not given')
end end
it 'should return 400 if no new parameters given' do it 'should return 400 if no new parameters given' do
put api("/projects/#{project.id}/labels", user), name: 'label1' put api("/projects/#{project.id}/labels", user), name: 'label1'
expect(response.status).to eq(400) expect(response).to have_http_status(400)
expect(json_response['message']).to eq('Required parameters '\ expect(json_response['message']).to eq('Required parameters '\
'"new_name" or "color" missing') '"new_name" or "color" missing')
end end
...@@ -170,7 +170,7 @@ describe API::API, api: true do ...@@ -170,7 +170,7 @@ describe API::API, api: true do
name: 'label1', name: 'label1',
new_name: '?', new_name: '?',
color: '#FFFFFF' color: '#FFFFFF'
expect(response.status).to eq(400) expect(response).to have_http_status(400)
expect(json_response['message']['title']).to eq(['is invalid']) expect(json_response['message']['title']).to eq(['is invalid'])
end end
...@@ -178,7 +178,7 @@ describe API::API, api: true do ...@@ -178,7 +178,7 @@ describe API::API, api: true do
put api("/projects/#{project.id}/labels", user), put api("/projects/#{project.id}/labels", user),
name: 'label1', name: 'label1',
color: '#FF' color: '#FF'
expect(response.status).to eq(400) expect(response).to have_http_status(400)
expect(json_response['message']['color']).to eq(['must be a valid color code']) expect(json_response['message']['color']).to eq(['must be a valid color code'])
end end
...@@ -186,7 +186,7 @@ describe API::API, api: true do ...@@ -186,7 +186,7 @@ describe API::API, api: true do
post api("/projects/#{project.id}/labels", user), post api("/projects/#{project.id}/labels", user),
name: 'Foo', name: 'Foo',
color: '#FFAAFFFF' color: '#FFAAFFFF'
expect(response.status).to eq(400) expect(response).to have_http_status(400)
expect(json_response['message']['color']).to eq(['must be a valid color code']) expect(json_response['message']['color']).to eq(['must be a valid color code'])
end end
end end
...@@ -196,7 +196,7 @@ describe API::API, api: true do ...@@ -196,7 +196,7 @@ describe API::API, api: true do
it "should subscribe to the label" do it "should subscribe to the label" do
post api("/projects/#{project.id}/labels/#{label1.title}/subscription", user) post api("/projects/#{project.id}/labels/#{label1.title}/subscription", user)
expect(response.status).to eq(201) expect(response).to have_http_status(201)
expect(json_response["name"]).to eq(label1.title) expect(json_response["name"]).to eq(label1.title)
expect(json_response["subscribed"]).to be_truthy expect(json_response["subscribed"]).to be_truthy
end end
...@@ -206,7 +206,7 @@ describe API::API, api: true do ...@@ -206,7 +206,7 @@ describe API::API, api: true do
it "should subscribe to the label" do it "should subscribe to the label" do
post api("/projects/#{project.id}/labels/#{label1.id}/subscription", user) post api("/projects/#{project.id}/labels/#{label1.id}/subscription", user)
expect(response.status).to eq(201) expect(response).to have_http_status(201)
expect(json_response["name"]).to eq(label1.title) expect(json_response["name"]).to eq(label1.title)
expect(json_response["subscribed"]).to be_truthy expect(json_response["subscribed"]).to be_truthy
end end
...@@ -218,7 +218,7 @@ describe API::API, api: true do ...@@ -218,7 +218,7 @@ describe API::API, api: true do
it "should return 304" do it "should return 304" do
post api("/projects/#{project.id}/labels/#{label1.id}/subscription", user) post api("/projects/#{project.id}/labels/#{label1.id}/subscription", user)
expect(response.status).to eq(304) expect(response).to have_http_status(304)
end end
end end
...@@ -226,7 +226,7 @@ describe API::API, api: true do ...@@ -226,7 +226,7 @@ describe API::API, api: true do
it "should a return 404 error" do it "should a return 404 error" do
post api("/projects/#{project.id}/labels/1234/subscription", user) post api("/projects/#{project.id}/labels/1234/subscription", user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
end end
...@@ -238,7 +238,7 @@ describe API::API, api: true do ...@@ -238,7 +238,7 @@ describe API::API, api: true do
it "should unsubscribe from the label" do it "should unsubscribe from the label" do
delete api("/projects/#{project.id}/labels/#{label1.title}/subscription", user) delete api("/projects/#{project.id}/labels/#{label1.title}/subscription", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response["name"]).to eq(label1.title) expect(json_response["name"]).to eq(label1.title)
expect(json_response["subscribed"]).to be_falsey expect(json_response["subscribed"]).to be_falsey
end end
...@@ -248,7 +248,7 @@ describe API::API, api: true do ...@@ -248,7 +248,7 @@ describe API::API, api: true do
it "should unsubscribe from the label" do it "should unsubscribe from the label" do
delete api("/projects/#{project.id}/labels/#{label1.id}/subscription", user) delete api("/projects/#{project.id}/labels/#{label1.id}/subscription", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response["name"]).to eq(label1.title) expect(json_response["name"]).to eq(label1.title)
expect(json_response["subscribed"]).to be_falsey expect(json_response["subscribed"]).to be_falsey
end end
...@@ -260,7 +260,7 @@ describe API::API, api: true do ...@@ -260,7 +260,7 @@ describe API::API, api: true do
it "should return 304" do it "should return 304" do
delete api("/projects/#{project.id}/labels/#{label1.id}/subscription", user) delete api("/projects/#{project.id}/labels/#{label1.id}/subscription", user)
expect(response.status).to eq(304) expect(response).to have_http_status(304)
end end
end end
...@@ -268,7 +268,7 @@ describe API::API, api: true do ...@@ -268,7 +268,7 @@ describe API::API, api: true do
it "should a return 404 error" do it "should a return 404 error" do
delete api("/projects/#{project.id}/labels/1234/subscription", user) delete api("/projects/#{project.id}/labels/1234/subscription", user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
end end
......
...@@ -23,7 +23,7 @@ describe API::Licenses, api: true do ...@@ -23,7 +23,7 @@ describe API::Licenses, api: true do
it 'returns a list of available license templates' do it 'returns a list of available license templates' do
get api('/licenses') get api('/licenses')
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.size).to eq(15) expect(json_response.size).to eq(15)
expect(json_response.map { |l| l['key'] }).to include('agpl-3.0') expect(json_response.map { |l| l['key'] }).to include('agpl-3.0')
...@@ -34,7 +34,7 @@ describe API::Licenses, api: true do ...@@ -34,7 +34,7 @@ describe API::Licenses, api: true do
it 'returns a list of available popular license templates' do it 'returns a list of available popular license templates' do
get api('/licenses?popular=1') get api('/licenses?popular=1')
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.size).to eq(3) expect(json_response.size).to eq(3)
expect(json_response.map { |l| l['key'] }).to include('apache-2.0') expect(json_response.map { |l| l['key'] }).to include('apache-2.0')
...@@ -116,7 +116,7 @@ describe API::Licenses, api: true do ...@@ -116,7 +116,7 @@ describe API::Licenses, api: true do
let(:license_type) { 'muth-over9000' } let(:license_type) { 'muth-over9000' }
it 'returns a 404' do it 'returns a 404' do
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
end end
......
...@@ -22,14 +22,14 @@ describe API::API, api: true do ...@@ -22,14 +22,14 @@ describe API::API, api: true do
context "when unauthenticated" do context "when unauthenticated" do
it "should return authentication error" do it "should return authentication error" do
get api("/projects/#{project.id}/merge_requests") get api("/projects/#{project.id}/merge_requests")
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
context "when authenticated" do context "when authenticated" do
it "should return an array of all merge_requests" do it "should return an array of all merge_requests" do
get api("/projects/#{project.id}/merge_requests", user) get api("/projects/#{project.id}/merge_requests", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(3) expect(json_response.length).to eq(3)
expect(json_response.last['title']).to eq(merge_request.title) expect(json_response.last['title']).to eq(merge_request.title)
...@@ -37,7 +37,7 @@ describe API::API, api: true do ...@@ -37,7 +37,7 @@ describe API::API, api: true do
it "should return an array of all merge_requests" do it "should return an array of all merge_requests" do
get api("/projects/#{project.id}/merge_requests?state", user) get api("/projects/#{project.id}/merge_requests?state", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(3) expect(json_response.length).to eq(3)
expect(json_response.last['title']).to eq(merge_request.title) expect(json_response.last['title']).to eq(merge_request.title)
...@@ -45,7 +45,7 @@ describe API::API, api: true do ...@@ -45,7 +45,7 @@ describe API::API, api: true do
it "should return an array of open merge_requests" do it "should return an array of open merge_requests" do
get api("/projects/#{project.id}/merge_requests?state=opened", user) get api("/projects/#{project.id}/merge_requests?state=opened", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response.last['title']).to eq(merge_request.title) expect(json_response.last['title']).to eq(merge_request.title)
...@@ -53,7 +53,7 @@ describe API::API, api: true do ...@@ -53,7 +53,7 @@ describe API::API, api: true do
it "should return an array of closed merge_requests" do it "should return an array of closed merge_requests" do
get api("/projects/#{project.id}/merge_requests?state=closed", user) get api("/projects/#{project.id}/merge_requests?state=closed", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response.first['title']).to eq(merge_request_closed.title) expect(json_response.first['title']).to eq(merge_request_closed.title)
...@@ -61,7 +61,7 @@ describe API::API, api: true do ...@@ -61,7 +61,7 @@ describe API::API, api: true do
it "should return an array of merged merge_requests" do it "should return an array of merged merge_requests" do
get api("/projects/#{project.id}/merge_requests?state=merged", user) get api("/projects/#{project.id}/merge_requests?state=merged", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response.first['title']).to eq(merge_request_merged.title) expect(json_response.first['title']).to eq(merge_request_merged.title)
...@@ -75,7 +75,7 @@ describe API::API, api: true do ...@@ -75,7 +75,7 @@ describe API::API, api: true do
it "should return an array of merge_requests in ascending order" do it "should return an array of merge_requests in ascending order" do
get api("/projects/#{project.id}/merge_requests?sort=asc", user) get api("/projects/#{project.id}/merge_requests?sort=asc", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(3) expect(json_response.length).to eq(3)
response_dates = json_response.map{ |merge_request| merge_request['created_at'] } response_dates = json_response.map{ |merge_request| merge_request['created_at'] }
...@@ -84,7 +84,7 @@ describe API::API, api: true do ...@@ -84,7 +84,7 @@ describe API::API, api: true do
it "should return an array of merge_requests in descending order" do it "should return an array of merge_requests in descending order" do
get api("/projects/#{project.id}/merge_requests?sort=desc", user) get api("/projects/#{project.id}/merge_requests?sort=desc", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(3) expect(json_response.length).to eq(3)
response_dates = json_response.map{ |merge_request| merge_request['created_at'] } response_dates = json_response.map{ |merge_request| merge_request['created_at'] }
...@@ -93,7 +93,7 @@ describe API::API, api: true do ...@@ -93,7 +93,7 @@ describe API::API, api: true do
it "should return an array of merge_requests ordered by updated_at" do it "should return an array of merge_requests ordered by updated_at" do
get api("/projects/#{project.id}/merge_requests?order_by=updated_at", user) get api("/projects/#{project.id}/merge_requests?order_by=updated_at", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(3) expect(json_response.length).to eq(3)
response_dates = json_response.map{ |merge_request| merge_request['updated_at'] } response_dates = json_response.map{ |merge_request| merge_request['updated_at'] }
...@@ -102,7 +102,7 @@ describe API::API, api: true do ...@@ -102,7 +102,7 @@ describe API::API, api: true do
it "should return an array of merge_requests ordered by created_at" do it "should return an array of merge_requests ordered by created_at" do
get api("/projects/#{project.id}/merge_requests?order_by=created_at&sort=asc", user) get api("/projects/#{project.id}/merge_requests?order_by=created_at&sort=asc", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(3) expect(json_response.length).to eq(3)
response_dates = json_response.map{ |merge_request| merge_request['created_at'] } response_dates = json_response.map{ |merge_request| merge_request['created_at'] }
...@@ -116,7 +116,7 @@ describe API::API, api: true do ...@@ -116,7 +116,7 @@ describe API::API, api: true do
it 'exposes known attributes' do it 'exposes known attributes' do
get api("/projects/#{project.id}/merge_requests/#{merge_request.id}", user) get api("/projects/#{project.id}/merge_requests/#{merge_request.id}", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['id']).to eq(merge_request.id) expect(json_response['id']).to eq(merge_request.id)
expect(json_response['iid']).to eq(merge_request.iid) expect(json_response['iid']).to eq(merge_request.iid)
expect(json_response['project_id']).to eq(merge_request.project.id) expect(json_response['project_id']).to eq(merge_request.project.id)
...@@ -142,7 +142,7 @@ describe API::API, api: true do ...@@ -142,7 +142,7 @@ describe API::API, api: true do
it "should return merge_request" do it "should return merge_request" do
get api("/projects/#{project.id}/merge_requests/#{merge_request.id}", user) get api("/projects/#{project.id}/merge_requests/#{merge_request.id}", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['title']).to eq(merge_request.title) expect(json_response['title']).to eq(merge_request.title)
expect(json_response['iid']).to eq(merge_request.iid) expect(json_response['iid']).to eq(merge_request.iid)
expect(json_response['work_in_progress']).to eq(false) expect(json_response['work_in_progress']).to eq(false)
...@@ -159,7 +159,7 @@ describe API::API, api: true do ...@@ -159,7 +159,7 @@ describe API::API, api: true do
it "should return a 404 error if merge_request_id not found" do it "should return a 404 error if merge_request_id not found" do
get api("/projects/#{project.id}/merge_requests/999", user) get api("/projects/#{project.id}/merge_requests/999", user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
context 'Work in Progress' do context 'Work in Progress' do
...@@ -167,7 +167,7 @@ describe API::API, api: true do ...@@ -167,7 +167,7 @@ describe API::API, api: true do
it "should return merge_request" do it "should return merge_request" do
get api("/projects/#{project.id}/merge_requests/#{merge_request_wip.id}", user) get api("/projects/#{project.id}/merge_requests/#{merge_request_wip.id}", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['work_in_progress']).to eq(true) expect(json_response['work_in_progress']).to eq(true)
end end
end end
...@@ -186,7 +186,7 @@ describe API::API, api: true do ...@@ -186,7 +186,7 @@ describe API::API, api: true do
it 'returns a 404 when merge_request_id not found' do it 'returns a 404 when merge_request_id not found' do
get api("/projects/#{project.id}/merge_requests/999/commits", user) get api("/projects/#{project.id}/merge_requests/999/commits", user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
...@@ -199,7 +199,7 @@ describe API::API, api: true do ...@@ -199,7 +199,7 @@ describe API::API, api: true do
it 'returns a 404 when merge_request_id not found' do it 'returns a 404 when merge_request_id not found' do
get api("/projects/#{project.id}/merge_requests/999/changes", user) get api("/projects/#{project.id}/merge_requests/999/changes", user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
...@@ -213,7 +213,7 @@ describe API::API, api: true do ...@@ -213,7 +213,7 @@ describe API::API, api: true do
author: user, author: user,
labels: 'label, label2', labels: 'label, label2',
milestone_id: milestone.id milestone_id: milestone.id
expect(response.status).to eq(201) expect(response).to have_http_status(201)
expect(json_response['title']).to eq('Test merge_request') expect(json_response['title']).to eq('Test merge_request')
expect(json_response['labels']).to eq(['label', 'label2']) expect(json_response['labels']).to eq(['label', 'label2'])
expect(json_response['milestone']['id']).to eq(milestone.id) expect(json_response['milestone']['id']).to eq(milestone.id)
...@@ -222,25 +222,25 @@ describe API::API, api: true do ...@@ -222,25 +222,25 @@ describe API::API, api: true do
it "should return 422 when source_branch equals target_branch" do it "should return 422 when source_branch equals target_branch" do
post api("/projects/#{project.id}/merge_requests", user), post api("/projects/#{project.id}/merge_requests", user),
title: "Test merge_request", source_branch: "master", target_branch: "master", author: user title: "Test merge_request", source_branch: "master", target_branch: "master", author: user
expect(response.status).to eq(422) expect(response).to have_http_status(422)
end end
it "should return 400 when source_branch is missing" do it "should return 400 when source_branch is missing" do
post api("/projects/#{project.id}/merge_requests", user), post api("/projects/#{project.id}/merge_requests", user),
title: "Test merge_request", target_branch: "master", author: user title: "Test merge_request", target_branch: "master", author: user
expect(response.status).to eq(400) expect(response).to have_http_status(400)
end end
it "should return 400 when target_branch is missing" do it "should return 400 when target_branch is missing" do
post api("/projects/#{project.id}/merge_requests", user), post api("/projects/#{project.id}/merge_requests", user),
title: "Test merge_request", source_branch: "markdown", author: user title: "Test merge_request", source_branch: "markdown", author: user
expect(response.status).to eq(400) expect(response).to have_http_status(400)
end end
it "should return 400 when title is missing" do it "should return 400 when title is missing" do
post api("/projects/#{project.id}/merge_requests", user), post api("/projects/#{project.id}/merge_requests", user),
target_branch: 'master', source_branch: 'markdown' target_branch: 'master', source_branch: 'markdown'
expect(response.status).to eq(400) expect(response).to have_http_status(400)
end end
it 'should return 400 on invalid label names' do it 'should return 400 on invalid label names' do
...@@ -250,7 +250,7 @@ describe API::API, api: true do ...@@ -250,7 +250,7 @@ describe API::API, api: true do
target_branch: 'master', target_branch: 'master',
author: user, author: user,
labels: 'label, ?' labels: 'label, ?'
expect(response.status).to eq(400) expect(response).to have_http_status(400)
expect(json_response['message']['labels']['?']['title']).to eq( expect(json_response['message']['labels']['?']['title']).to eq(
['is invalid'] ['is invalid']
) )
...@@ -274,7 +274,7 @@ describe API::API, api: true do ...@@ -274,7 +274,7 @@ describe API::API, api: true do
target_branch: 'master', target_branch: 'master',
author: user author: user
end.to change { MergeRequest.count }.by(0) end.to change { MergeRequest.count }.by(0)
expect(response.status).to eq(409) expect(response).to have_http_status(409)
end end
end end
end end
...@@ -292,7 +292,7 @@ describe API::API, api: true do ...@@ -292,7 +292,7 @@ describe API::API, api: true do
post api("/projects/#{fork_project.id}/merge_requests", user2), post api("/projects/#{fork_project.id}/merge_requests", user2),
title: 'Test merge_request', source_branch: "feature_conflict", target_branch: "master", title: 'Test merge_request', source_branch: "feature_conflict", target_branch: "master",
author: user2, target_project_id: project.id, description: 'Test description for Test merge_request' author: user2, target_project_id: project.id, description: 'Test description for Test merge_request'
expect(response.status).to eq(201) expect(response).to have_http_status(201)
expect(json_response['title']).to eq('Test merge_request') expect(json_response['title']).to eq('Test merge_request')
expect(json_response['description']).to eq('Test description for Test merge_request') expect(json_response['description']).to eq('Test description for Test merge_request')
end end
...@@ -303,26 +303,26 @@ describe API::API, api: true do ...@@ -303,26 +303,26 @@ describe API::API, api: true do
expect(fork_project.forked_from_project).to eq(project) expect(fork_project.forked_from_project).to eq(project)
post api("/projects/#{fork_project.id}/merge_requests", user2), post api("/projects/#{fork_project.id}/merge_requests", user2),
title: 'Test merge_request', source_branch: "master", target_branch: "master", author: user2, target_project_id: project.id title: 'Test merge_request', source_branch: "master", target_branch: "master", author: user2, target_project_id: project.id
expect(response.status).to eq(201) expect(response).to have_http_status(201)
expect(json_response['title']).to eq('Test merge_request') expect(json_response['title']).to eq('Test merge_request')
end end
it "should return 400 when source_branch is missing" do it "should return 400 when source_branch is missing" do
post api("/projects/#{fork_project.id}/merge_requests", user2), post api("/projects/#{fork_project.id}/merge_requests", user2),
title: 'Test merge_request', target_branch: "master", author: user2, target_project_id: project.id title: 'Test merge_request', target_branch: "master", author: user2, target_project_id: project.id
expect(response.status).to eq(400) expect(response).to have_http_status(400)
end end
it "should return 400 when target_branch is missing" do it "should return 400 when target_branch is missing" do
post api("/projects/#{fork_project.id}/merge_requests", user2), post api("/projects/#{fork_project.id}/merge_requests", user2),
title: 'Test merge_request', target_branch: "master", author: user2, target_project_id: project.id title: 'Test merge_request', target_branch: "master", author: user2, target_project_id: project.id
expect(response.status).to eq(400) expect(response).to have_http_status(400)
end end
it "should return 400 when title is missing" do it "should return 400 when title is missing" do
post api("/projects/#{fork_project.id}/merge_requests", user2), post api("/projects/#{fork_project.id}/merge_requests", user2),
target_branch: 'master', source_branch: 'markdown', author: user2, target_project_id: project.id target_branch: 'master', source_branch: 'markdown', author: user2, target_project_id: project.id
expect(response.status).to eq(400) expect(response).to have_http_status(400)
end end
context 'when target_branch is specified' do context 'when target_branch is specified' do
...@@ -333,7 +333,7 @@ describe API::API, api: true do ...@@ -333,7 +333,7 @@ describe API::API, api: true do
source_branch: 'markdown', source_branch: 'markdown',
author: user, author: user,
target_project_id: fork_project.id target_project_id: fork_project.id
expect(response.status).to eq(422) expect(response).to have_http_status(422)
end end
it 'should return 422 if targeting a different fork' do it 'should return 422 if targeting a different fork' do
...@@ -343,14 +343,14 @@ describe API::API, api: true do ...@@ -343,14 +343,14 @@ describe API::API, api: true do
source_branch: 'markdown', source_branch: 'markdown',
author: user2, author: user2,
target_project_id: unrelated_project.id target_project_id: unrelated_project.id
expect(response.status).to eq(422) expect(response).to have_http_status(422)
end end
end end
it "should return 201 when target_branch is specified and for the same project" do it "should return 201 when target_branch is specified and for the same project" do
post api("/projects/#{fork_project.id}/merge_requests", user2), post api("/projects/#{fork_project.id}/merge_requests", user2),
title: 'Test merge_request', target_branch: 'master', source_branch: 'markdown', author: user2, target_project_id: fork_project.id title: 'Test merge_request', target_branch: 'master', source_branch: 'markdown', author: user2, target_project_id: fork_project.id
expect(response.status).to eq(201) expect(response).to have_http_status(201)
end end
end end
end end
...@@ -365,7 +365,7 @@ describe API::API, api: true do ...@@ -365,7 +365,7 @@ describe API::API, api: true do
it "denies the deletion of the merge request" do it "denies the deletion of the merge request" do
delete api("/projects/#{project.id}/merge_requests/#{merge_request.id}", developer) delete api("/projects/#{project.id}/merge_requests/#{merge_request.id}", developer)
expect(response.status).to be(403) expect(response).to have_http_status(403)
end end
end end
...@@ -373,7 +373,7 @@ describe API::API, api: true do ...@@ -373,7 +373,7 @@ describe API::API, api: true do
it "destroys the merge request owners can destroy" do it "destroys the merge request owners can destroy" do
delete api("/projects/#{project.id}/merge_requests/#{merge_request.id}", user) delete api("/projects/#{project.id}/merge_requests/#{merge_request.id}", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
end end
end end
...@@ -381,7 +381,7 @@ describe API::API, api: true do ...@@ -381,7 +381,7 @@ describe API::API, api: true do
describe "PUT /projects/:id/merge_requests/:merge_request_id to close MR" do describe "PUT /projects/:id/merge_requests/:merge_request_id to close MR" do
it "should return merge_request" do it "should return merge_request" do
put api("/projects/#{project.id}/merge_requests/#{merge_request.id}", user), state_event: "close" put api("/projects/#{project.id}/merge_requests/#{merge_request.id}", user), state_event: "close"
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['state']).to eq('closed') expect(json_response['state']).to eq('closed')
end end
end end
...@@ -392,7 +392,7 @@ describe API::API, api: true do ...@@ -392,7 +392,7 @@ describe API::API, api: true do
it "should return merge_request in case of success" do it "should return merge_request in case of success" do
put api("/projects/#{project.id}/merge_requests/#{merge_request.id}/merge", user) put api("/projects/#{project.id}/merge_requests/#{merge_request.id}/merge", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
it "should return 406 if branch can't be merged" do it "should return 406 if branch can't be merged" do
...@@ -401,21 +401,21 @@ describe API::API, api: true do ...@@ -401,21 +401,21 @@ describe API::API, api: true do
put api("/projects/#{project.id}/merge_requests/#{merge_request.id}/merge", user) put api("/projects/#{project.id}/merge_requests/#{merge_request.id}/merge", user)
expect(response.status).to eq(406) expect(response).to have_http_status(406)
expect(json_response['message']).to eq('Branch cannot be merged') expect(json_response['message']).to eq('Branch cannot be merged')
end end
it "should return 405 if merge_request is not open" do it "should return 405 if merge_request is not open" do
merge_request.close merge_request.close
put api("/projects/#{project.id}/merge_requests/#{merge_request.id}/merge", user) put api("/projects/#{project.id}/merge_requests/#{merge_request.id}/merge", user)
expect(response.status).to eq(405) expect(response).to have_http_status(405)
expect(json_response['message']).to eq('405 Method Not Allowed') expect(json_response['message']).to eq('405 Method Not Allowed')
end end
it "should return 405 if merge_request is a work in progress" do it "should return 405 if merge_request is a work in progress" do
merge_request.update_attribute(:title, "WIP: #{merge_request.title}") merge_request.update_attribute(:title, "WIP: #{merge_request.title}")
put api("/projects/#{project.id}/merge_requests/#{merge_request.id}/merge", user) put api("/projects/#{project.id}/merge_requests/#{merge_request.id}/merge", user)
expect(response.status).to eq(405) expect(response).to have_http_status(405)
expect(json_response['message']).to eq('405 Method Not Allowed') expect(json_response['message']).to eq('405 Method Not Allowed')
end end
...@@ -424,7 +424,7 @@ describe API::API, api: true do ...@@ -424,7 +424,7 @@ describe API::API, api: true do
put api("/projects/#{project.id}/merge_requests/#{merge_request.id}/merge", user) put api("/projects/#{project.id}/merge_requests/#{merge_request.id}/merge", user)
expect(response.status).to eq(405) expect(response).to have_http_status(405)
expect(json_response['message']).to eq('405 Method Not Allowed') expect(json_response['message']).to eq('405 Method Not Allowed')
end end
...@@ -432,21 +432,21 @@ describe API::API, api: true do ...@@ -432,21 +432,21 @@ describe API::API, api: true do
user2 = create(:user) user2 = create(:user)
project.team << [user2, :reporter] project.team << [user2, :reporter]
put api("/projects/#{project.id}/merge_requests/#{merge_request.id}/merge", user2) put api("/projects/#{project.id}/merge_requests/#{merge_request.id}/merge", user2)
expect(response.status).to eq(401) expect(response).to have_http_status(401)
expect(json_response['message']).to eq('401 Unauthorized') expect(json_response['message']).to eq('401 Unauthorized')
end end
it "returns 409 if the SHA parameter doesn't match" do it "returns 409 if the SHA parameter doesn't match" do
put api("/projects/#{project.id}/merge_requests/#{merge_request.id}/merge", user), sha: merge_request.source_sha.succ put api("/projects/#{project.id}/merge_requests/#{merge_request.id}/merge", user), sha: merge_request.source_sha.succ
expect(response.status).to eq(409) expect(response).to have_http_status(409)
expect(json_response['message']).to start_with('SHA does not match HEAD of source branch') expect(json_response['message']).to start_with('SHA does not match HEAD of source branch')
end end
it "succeeds if the SHA parameter matches" do it "succeeds if the SHA parameter matches" do
put api("/projects/#{project.id}/merge_requests/#{merge_request.id}/merge", user), sha: merge_request.source_sha put api("/projects/#{project.id}/merge_requests/#{merge_request.id}/merge", user), sha: merge_request.source_sha
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
it "enables merge when build succeeds if the ci is active" do it "enables merge when build succeeds if the ci is active" do
...@@ -455,7 +455,7 @@ describe API::API, api: true do ...@@ -455,7 +455,7 @@ describe API::API, api: true do
put api("/projects/#{project.id}/merge_requests/#{merge_request.id}/merge", user), merge_when_build_succeeds: true put api("/projects/#{project.id}/merge_requests/#{merge_request.id}/merge", user), merge_when_build_succeeds: true
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['title']).to eq('Test') expect(json_response['title']).to eq('Test')
expect(json_response['merge_when_build_succeeds']).to eq(true) expect(json_response['merge_when_build_succeeds']).to eq(true)
end end
...@@ -464,31 +464,31 @@ describe API::API, api: true do ...@@ -464,31 +464,31 @@ describe API::API, api: true do
describe "PUT /projects/:id/merge_requests/:merge_request_id" do describe "PUT /projects/:id/merge_requests/:merge_request_id" do
it "updates title and returns merge_request" do it "updates title and returns merge_request" do
put api("/projects/#{project.id}/merge_requests/#{merge_request.id}", user), title: "New title" put api("/projects/#{project.id}/merge_requests/#{merge_request.id}", user), title: "New title"
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['title']).to eq('New title') expect(json_response['title']).to eq('New title')
end end
it "updates description and returns merge_request" do it "updates description and returns merge_request" do
put api("/projects/#{project.id}/merge_requests/#{merge_request.id}", user), description: "New description" put api("/projects/#{project.id}/merge_requests/#{merge_request.id}", user), description: "New description"
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['description']).to eq('New description') expect(json_response['description']).to eq('New description')
end end
it "updates milestone_id and returns merge_request" do it "updates milestone_id and returns merge_request" do
put api("/projects/#{project.id}/merge_requests/#{merge_request.id}", user), milestone_id: milestone.id put api("/projects/#{project.id}/merge_requests/#{merge_request.id}", user), milestone_id: milestone.id
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['milestone']['id']).to eq(milestone.id) expect(json_response['milestone']['id']).to eq(milestone.id)
end end
it "should return 400 when source_branch is specified" do it "should return 400 when source_branch is specified" do
put api("/projects/#{project.id}/merge_requests/#{merge_request.id}", user), put api("/projects/#{project.id}/merge_requests/#{merge_request.id}", user),
source_branch: "master", target_branch: "master" source_branch: "master", target_branch: "master"
expect(response.status).to eq(400) expect(response).to have_http_status(400)
end end
it "should return merge_request with renamed target_branch" do it "should return merge_request with renamed target_branch" do
put api("/projects/#{project.id}/merge_requests/#{merge_request.id}", user), target_branch: "wiki" put api("/projects/#{project.id}/merge_requests/#{merge_request.id}", user), target_branch: "wiki"
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['target_branch']).to eq('wiki') expect(json_response['target_branch']).to eq('wiki')
end end
...@@ -497,7 +497,7 @@ describe API::API, api: true do ...@@ -497,7 +497,7 @@ describe API::API, api: true do
user), user),
title: 'new issue', title: 'new issue',
labels: 'label, ?' labels: 'label, ?'
expect(response.status).to eq(400) expect(response).to have_http_status(400)
expect(json_response['message']['labels']['?']['title']).to eq(['is invalid']) expect(json_response['message']['labels']['?']['title']).to eq(['is invalid'])
end end
end end
...@@ -507,7 +507,7 @@ describe API::API, api: true do ...@@ -507,7 +507,7 @@ describe API::API, api: true do
original_count = merge_request.notes.size original_count = merge_request.notes.size
post api("/projects/#{project.id}/merge_requests/#{merge_request.id}/comments", user), note: "My comment" post api("/projects/#{project.id}/merge_requests/#{merge_request.id}/comments", user), note: "My comment"
expect(response.status).to eq(201) expect(response).to have_http_status(201)
expect(json_response['note']).to eq('My comment') expect(json_response['note']).to eq('My comment')
expect(json_response['author']['name']).to eq(user.name) expect(json_response['author']['name']).to eq(user.name)
expect(json_response['author']['username']).to eq(user.username) expect(json_response['author']['username']).to eq(user.username)
...@@ -516,20 +516,20 @@ describe API::API, api: true do ...@@ -516,20 +516,20 @@ describe API::API, api: true do
it "should return 400 if note is missing" do it "should return 400 if note is missing" do
post api("/projects/#{project.id}/merge_requests/#{merge_request.id}/comments", user) post api("/projects/#{project.id}/merge_requests/#{merge_request.id}/comments", user)
expect(response.status).to eq(400) expect(response).to have_http_status(400)
end end
it "should return 404 if note is attached to non existent merge request" do it "should return 404 if note is attached to non existent merge request" do
post api("/projects/#{project.id}/merge_requests/404/comments", user), post api("/projects/#{project.id}/merge_requests/404/comments", user),
note: 'My comment' note: 'My comment'
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
describe "GET :id/merge_requests/:merge_request_id/comments" do describe "GET :id/merge_requests/:merge_request_id/comments" do
it "should return merge_request comments ordered by created_at" do it "should return merge_request comments ordered by created_at" do
get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/comments", user) get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/comments", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(2) expect(json_response.length).to eq(2)
expect(json_response.first['note']).to eq("a comment on a MR") expect(json_response.first['note']).to eq("a comment on a MR")
...@@ -539,7 +539,7 @@ describe API::API, api: true do ...@@ -539,7 +539,7 @@ describe API::API, api: true do
it "should return a 404 error if merge_request_id not found" do it "should return a 404 error if merge_request_id not found" do
get api("/projects/#{project.id}/merge_requests/999/comments", user) get api("/projects/#{project.id}/merge_requests/999/comments", user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
...@@ -551,7 +551,7 @@ describe API::API, api: true do ...@@ -551,7 +551,7 @@ describe API::API, api: true do
end end
get api("/projects/#{project.id}/merge_requests/#{mr.id}/closes_issues", user) get api("/projects/#{project.id}/merge_requests/#{mr.id}/closes_issues", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response.first['id']).to eq(issue.id) expect(json_response.first['id']).to eq(issue.id)
...@@ -559,7 +559,7 @@ describe API::API, api: true do ...@@ -559,7 +559,7 @@ describe API::API, api: true do
it 'returns an empty array when there are no issues to be closed' do it 'returns an empty array when there are no issues to be closed' do
get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/closes_issues", user) get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/closes_issues", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(0) expect(json_response.length).to eq(0)
end end
...@@ -572,7 +572,7 @@ describe API::API, api: true do ...@@ -572,7 +572,7 @@ describe API::API, api: true do
get api("/projects/#{jira_project.id}/merge_requests/#{merge_request.id}/closes_issues", user) get api("/projects/#{jira_project.id}/merge_requests/#{merge_request.id}/closes_issues", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response.first['title']).to eq(issue.title) expect(json_response.first['title']).to eq(issue.title)
...@@ -584,20 +584,20 @@ describe API::API, api: true do ...@@ -584,20 +584,20 @@ describe API::API, api: true do
it 'subscribes to a merge request' do it 'subscribes to a merge request' do
post api("/projects/#{project.id}/merge_requests/#{merge_request.id}/subscription", admin) post api("/projects/#{project.id}/merge_requests/#{merge_request.id}/subscription", admin)
expect(response.status).to eq(201) expect(response).to have_http_status(201)
expect(json_response['subscribed']).to eq(true) expect(json_response['subscribed']).to eq(true)
end end
it 'returns 304 if already subscribed' do it 'returns 304 if already subscribed' do
post api("/projects/#{project.id}/merge_requests/#{merge_request.id}/subscription", user) post api("/projects/#{project.id}/merge_requests/#{merge_request.id}/subscription", user)
expect(response.status).to eq(304) expect(response).to have_http_status(304)
end end
it 'returns 404 if the merge request is not found' do it 'returns 404 if the merge request is not found' do
post api("/projects/#{project.id}/merge_requests/123/subscription", user) post api("/projects/#{project.id}/merge_requests/123/subscription", user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
...@@ -605,20 +605,20 @@ describe API::API, api: true do ...@@ -605,20 +605,20 @@ describe API::API, api: true do
it 'unsubscribes from a merge request' do it 'unsubscribes from a merge request' do
delete api("/projects/#{project.id}/merge_requests/#{merge_request.id}/subscription", user) delete api("/projects/#{project.id}/merge_requests/#{merge_request.id}/subscription", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['subscribed']).to eq(false) expect(json_response['subscribed']).to eq(false)
end end
it 'returns 304 if not subscribed' do it 'returns 304 if not subscribed' do
delete api("/projects/#{project.id}/merge_requests/#{merge_request.id}/subscription", admin) delete api("/projects/#{project.id}/merge_requests/#{merge_request.id}/subscription", admin)
expect(response.status).to eq(304) expect(response).to have_http_status(304)
end end
it 'returns 404 if the merge request is not found' do it 'returns 404 if the merge request is not found' do
post api("/projects/#{project.id}/merge_requests/123/subscription", user) post api("/projects/#{project.id}/merge_requests/123/subscription", user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
......
...@@ -12,20 +12,20 @@ describe API::API, api: true do ...@@ -12,20 +12,20 @@ describe API::API, api: true do
describe 'GET /projects/:id/milestones' do describe 'GET /projects/:id/milestones' do
it 'should return project milestones' do it 'should return project milestones' do
get api("/projects/#{project.id}/milestones", user) get api("/projects/#{project.id}/milestones", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first['title']).to eq(milestone.title) expect(json_response.first['title']).to eq(milestone.title)
end end
it 'should return a 401 error if user not authenticated' do it 'should return a 401 error if user not authenticated' do
get api("/projects/#{project.id}/milestones") get api("/projects/#{project.id}/milestones")
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
it 'returns an array of active milestones' do it 'returns an array of active milestones' do
get api("/projects/#{project.id}/milestones?state=active", user) get api("/projects/#{project.id}/milestones?state=active", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response.first['id']).to eq(milestone.id) expect(json_response.first['id']).to eq(milestone.id)
...@@ -34,7 +34,7 @@ describe API::API, api: true do ...@@ -34,7 +34,7 @@ describe API::API, api: true do
it 'returns an array of closed milestones' do it 'returns an array of closed milestones' do
get api("/projects/#{project.id}/milestones?state=closed", user) get api("/projects/#{project.id}/milestones?state=closed", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response.first['id']).to eq(closed_milestone.id) expect(json_response.first['id']).to eq(closed_milestone.id)
...@@ -44,7 +44,7 @@ describe API::API, api: true do ...@@ -44,7 +44,7 @@ describe API::API, api: true do
describe 'GET /projects/:id/milestones/:milestone_id' do describe 'GET /projects/:id/milestones/:milestone_id' do
it 'should return a project milestone by id' do it 'should return a project milestone by id' do
get api("/projects/#{project.id}/milestones/#{milestone.id}", user) get api("/projects/#{project.id}/milestones/#{milestone.id}", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['title']).to eq(milestone.title) expect(json_response['title']).to eq(milestone.title)
expect(json_response['iid']).to eq(milestone.iid) expect(json_response['iid']).to eq(milestone.iid)
end end
...@@ -60,19 +60,19 @@ describe API::API, api: true do ...@@ -60,19 +60,19 @@ describe API::API, api: true do
it 'should return 401 error if user not authenticated' do it 'should return 401 error if user not authenticated' do
get api("/projects/#{project.id}/milestones/#{milestone.id}") get api("/projects/#{project.id}/milestones/#{milestone.id}")
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
it 'should return a 404 error if milestone id not found' do it 'should return a 404 error if milestone id not found' do
get api("/projects/#{project.id}/milestones/1234", user) get api("/projects/#{project.id}/milestones/1234", user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
describe 'POST /projects/:id/milestones' do describe 'POST /projects/:id/milestones' do
it 'should create a new project milestone' do it 'should create a new project milestone' do
post api("/projects/#{project.id}/milestones", user), title: 'new milestone' post api("/projects/#{project.id}/milestones", user), title: 'new milestone'
expect(response.status).to eq(201) expect(response).to have_http_status(201)
expect(json_response['title']).to eq('new milestone') expect(json_response['title']).to eq('new milestone')
expect(json_response['description']).to be_nil expect(json_response['description']).to be_nil
end end
...@@ -80,14 +80,14 @@ describe API::API, api: true do ...@@ -80,14 +80,14 @@ describe API::API, api: true do
it 'should create a new project milestone with description and due date' do it 'should create a new project milestone with description and due date' do
post api("/projects/#{project.id}/milestones", user), post api("/projects/#{project.id}/milestones", user),
title: 'new milestone', description: 'release', due_date: '2013-03-02' title: 'new milestone', description: 'release', due_date: '2013-03-02'
expect(response.status).to eq(201) expect(response).to have_http_status(201)
expect(json_response['description']).to eq('release') expect(json_response['description']).to eq('release')
expect(json_response['due_date']).to eq('2013-03-02') expect(json_response['due_date']).to eq('2013-03-02')
end end
it 'should return a 400 error if title is missing' do it 'should return a 400 error if title is missing' do
post api("/projects/#{project.id}/milestones", user) post api("/projects/#{project.id}/milestones", user)
expect(response.status).to eq(400) expect(response).to have_http_status(400)
end end
end end
...@@ -95,14 +95,14 @@ describe API::API, api: true do ...@@ -95,14 +95,14 @@ describe API::API, api: true do
it 'should update a project milestone' do it 'should update a project milestone' do
put api("/projects/#{project.id}/milestones/#{milestone.id}", user), put api("/projects/#{project.id}/milestones/#{milestone.id}", user),
title: 'updated title' title: 'updated title'
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['title']).to eq('updated title') expect(json_response['title']).to eq('updated title')
end end
it 'should return a 404 error if milestone id not found' do it 'should return a 404 error if milestone id not found' do
put api("/projects/#{project.id}/milestones/1234", user), put api("/projects/#{project.id}/milestones/1234", user),
title: 'updated title' title: 'updated title'
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
...@@ -110,7 +110,7 @@ describe API::API, api: true do ...@@ -110,7 +110,7 @@ describe API::API, api: true do
it 'should update a project milestone' do it 'should update a project milestone' do
put api("/projects/#{project.id}/milestones/#{milestone.id}", user), put api("/projects/#{project.id}/milestones/#{milestone.id}", user),
state_event: 'close' state_event: 'close'
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['state']).to eq('closed') expect(json_response['state']).to eq('closed')
end end
...@@ -131,14 +131,14 @@ describe API::API, api: true do ...@@ -131,14 +131,14 @@ describe API::API, api: true do
end end
it 'should return project issues for a particular milestone' do it 'should return project issues for a particular milestone' do
get api("/projects/#{project.id}/milestones/#{milestone.id}/issues", user) get api("/projects/#{project.id}/milestones/#{milestone.id}/issues", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first['milestone']['title']).to eq(milestone.title) expect(json_response.first['milestone']['title']).to eq(milestone.title)
end end
it 'should return a 401 error if user not authenticated' do it 'should return a 401 error if user not authenticated' do
get api("/projects/#{project.id}/milestones/#{milestone.id}/issues") get api("/projects/#{project.id}/milestones/#{milestone.id}/issues")
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
describe 'confidential issues' do describe 'confidential issues' do
...@@ -155,7 +155,7 @@ describe API::API, api: true do ...@@ -155,7 +155,7 @@ describe API::API, api: true do
it 'returns confidential issues to team members' do it 'returns confidential issues to team members' do
get api("/projects/#{public_project.id}/milestones/#{milestone.id}/issues", user) get api("/projects/#{public_project.id}/milestones/#{milestone.id}/issues", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.size).to eq(2) expect(json_response.size).to eq(2)
expect(json_response.map { |issue| issue['id'] }).to include(issue.id, confidential_issue.id) expect(json_response.map { |issue| issue['id'] }).to include(issue.id, confidential_issue.id)
...@@ -167,7 +167,7 @@ describe API::API, api: true do ...@@ -167,7 +167,7 @@ describe API::API, api: true do
get api("/projects/#{public_project.id}/milestones/#{milestone.id}/issues", member) get api("/projects/#{public_project.id}/milestones/#{milestone.id}/issues", member)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.size).to eq(1) expect(json_response.size).to eq(1)
expect(json_response.map { |issue| issue['id'] }).to include(issue.id) expect(json_response.map { |issue| issue['id'] }).to include(issue.id)
...@@ -176,7 +176,7 @@ describe API::API, api: true do ...@@ -176,7 +176,7 @@ describe API::API, api: true do
it 'does not return confidential issues to regular users' do it 'does not return confidential issues to regular users' do
get api("/projects/#{public_project.id}/milestones/#{milestone.id}/issues", create(:user)) get api("/projects/#{public_project.id}/milestones/#{milestone.id}/issues", create(:user))
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.size).to eq(1) expect(json_response.size).to eq(1)
expect(json_response.map { |issue| issue['id'] }).to include(issue.id) expect(json_response.map { |issue| issue['id'] }).to include(issue.id)
......
...@@ -11,14 +11,14 @@ describe API::API, api: true do ...@@ -11,14 +11,14 @@ describe API::API, api: true do
context "when unauthenticated" do context "when unauthenticated" do
it "should return authentication error" do it "should return authentication error" do
get api("/namespaces") get api("/namespaces")
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
context "when authenticated as admin" do context "when authenticated as admin" do
it "admin: should return an array of all namespaces" do it "admin: should return an array of all namespaces" do
get api("/namespaces", admin) get api("/namespaces", admin)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(Namespace.count) expect(json_response.length).to eq(Namespace.count)
...@@ -26,7 +26,7 @@ describe API::API, api: true do ...@@ -26,7 +26,7 @@ describe API::API, api: true do
it "admin: should return an array of matched namespaces" do it "admin: should return an array of matched namespaces" do
get api("/namespaces?search=#{group1.name}", admin) get api("/namespaces?search=#{group1.name}", admin)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
...@@ -36,7 +36,7 @@ describe API::API, api: true do ...@@ -36,7 +36,7 @@ describe API::API, api: true do
context "when authenticated as a regular user" do context "when authenticated as a regular user" do
it "user: should return an array of namespaces" do it "user: should return an array of namespaces" do
get api("/namespaces", user) get api("/namespaces", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
...@@ -44,7 +44,7 @@ describe API::API, api: true do ...@@ -44,7 +44,7 @@ describe API::API, api: true do
it "admin: should return an array of matched namespaces" do it "admin: should return an array of matched namespaces" do
get api("/namespaces?search=#{user.username}", user) get api("/namespaces?search=#{user.username}", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
......
...@@ -40,7 +40,7 @@ describe API::API, api: true do ...@@ -40,7 +40,7 @@ describe API::API, api: true do
it "should return an array of issue notes" do it "should return an array of issue notes" do
get api("/projects/#{project.id}/issues/#{issue.id}/notes", user) get api("/projects/#{project.id}/issues/#{issue.id}/notes", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first['body']).to eq(issue_note.note) expect(json_response.first['body']).to eq(issue_note.note)
end end
...@@ -48,14 +48,14 @@ describe API::API, api: true do ...@@ -48,14 +48,14 @@ describe API::API, api: true do
it "should return a 404 error when issue id not found" do it "should return a 404 error when issue id not found" do
get api("/projects/#{project.id}/issues/12345/notes", user) get api("/projects/#{project.id}/issues/12345/notes", user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
context "and current user cannot view the notes" do context "and current user cannot view the notes" do
it "should return an empty array" do it "should return an empty array" do
get api("/projects/#{ext_proj.id}/issues/#{ext_issue.id}/notes", user) get api("/projects/#{ext_proj.id}/issues/#{ext_issue.id}/notes", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response).to be_empty expect(json_response).to be_empty
end end
...@@ -66,7 +66,7 @@ describe API::API, api: true do ...@@ -66,7 +66,7 @@ describe API::API, api: true do
it "returns 404" do it "returns 404" do
get api("/projects/#{ext_proj.id}/issues/#{ext_issue.id}/notes", user) get api("/projects/#{ext_proj.id}/issues/#{ext_issue.id}/notes", user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
...@@ -74,7 +74,7 @@ describe API::API, api: true do ...@@ -74,7 +74,7 @@ describe API::API, api: true do
it "should return an empty array" do it "should return an empty array" do
get api("/projects/#{ext_proj.id}/issues/#{ext_issue.id}/notes", private_user) get api("/projects/#{ext_proj.id}/issues/#{ext_issue.id}/notes", private_user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first['body']).to eq(cross_reference_note.note) expect(json_response.first['body']).to eq(cross_reference_note.note)
end end
...@@ -86,7 +86,7 @@ describe API::API, api: true do ...@@ -86,7 +86,7 @@ describe API::API, api: true do
it "should return an array of snippet notes" do it "should return an array of snippet notes" do
get api("/projects/#{project.id}/snippets/#{snippet.id}/notes", user) get api("/projects/#{project.id}/snippets/#{snippet.id}/notes", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first['body']).to eq(snippet_note.note) expect(json_response.first['body']).to eq(snippet_note.note)
end end
...@@ -94,13 +94,13 @@ describe API::API, api: true do ...@@ -94,13 +94,13 @@ describe API::API, api: true do
it "should return a 404 error when snippet id not found" do it "should return a 404 error when snippet id not found" do
get api("/projects/#{project.id}/snippets/42/notes", user) get api("/projects/#{project.id}/snippets/42/notes", user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
it "returns 404 when not authorized" do it "returns 404 when not authorized" do
get api("/projects/#{project.id}/snippets/#{snippet.id}/notes", private_user) get api("/projects/#{project.id}/snippets/#{snippet.id}/notes", private_user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
...@@ -108,7 +108,7 @@ describe API::API, api: true do ...@@ -108,7 +108,7 @@ describe API::API, api: true do
it "should return an array of merge_requests notes" do it "should return an array of merge_requests notes" do
get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/notes", user) get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/notes", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first['body']).to eq(merge_request_note.note) expect(json_response.first['body']).to eq(merge_request_note.note)
end end
...@@ -116,13 +116,13 @@ describe API::API, api: true do ...@@ -116,13 +116,13 @@ describe API::API, api: true do
it "should return a 404 error if merge request id not found" do it "should return a 404 error if merge request id not found" do
get api("/projects/#{project.id}/merge_requests/4444/notes", user) get api("/projects/#{project.id}/merge_requests/4444/notes", user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
it "returns 404 when not authorized" do it "returns 404 when not authorized" do
get api("/projects/#{project.id}/merge_requests/4444/notes", private_user) get api("/projects/#{project.id}/merge_requests/4444/notes", private_user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
end end
...@@ -132,21 +132,21 @@ describe API::API, api: true do ...@@ -132,21 +132,21 @@ describe API::API, api: true do
it "should return an issue note by id" do it "should return an issue note by id" do
get api("/projects/#{project.id}/issues/#{issue.id}/notes/#{issue_note.id}", user) get api("/projects/#{project.id}/issues/#{issue.id}/notes/#{issue_note.id}", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['body']).to eq(issue_note.note) expect(json_response['body']).to eq(issue_note.note)
end end
it "should return a 404 error if issue note not found" do it "should return a 404 error if issue note not found" do
get api("/projects/#{project.id}/issues/#{issue.id}/notes/12345", user) get api("/projects/#{project.id}/issues/#{issue.id}/notes/12345", user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
context "and current user cannot view the note" do context "and current user cannot view the note" do
it "should return a 404 error" do it "should return a 404 error" do
get api("/projects/#{ext_proj.id}/issues/#{ext_issue.id}/notes/#{cross_reference_note.id}", user) get api("/projects/#{ext_proj.id}/issues/#{ext_issue.id}/notes/#{cross_reference_note.id}", user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
context "when issue is confidential" do context "when issue is confidential" do
...@@ -155,7 +155,7 @@ describe API::API, api: true do ...@@ -155,7 +155,7 @@ describe API::API, api: true do
it "returns 404" do it "returns 404" do
get api("/projects/#{project.id}/issues/#{issue.id}/notes/#{issue_note.id}", private_user) get api("/projects/#{project.id}/issues/#{issue.id}/notes/#{issue_note.id}", private_user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
...@@ -164,7 +164,7 @@ describe API::API, api: true do ...@@ -164,7 +164,7 @@ describe API::API, api: true do
it "should return an issue note by id" do it "should return an issue note by id" do
get api("/projects/#{ext_proj.id}/issues/#{ext_issue.id}/notes/#{cross_reference_note.id}", private_user) get api("/projects/#{ext_proj.id}/issues/#{ext_issue.id}/notes/#{cross_reference_note.id}", private_user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['body']).to eq(cross_reference_note.note) expect(json_response['body']).to eq(cross_reference_note.note)
end end
end end
...@@ -175,14 +175,14 @@ describe API::API, api: true do ...@@ -175,14 +175,14 @@ describe API::API, api: true do
it "should return a snippet note by id" do it "should return a snippet note by id" do
get api("/projects/#{project.id}/snippets/#{snippet.id}/notes/#{snippet_note.id}", user) get api("/projects/#{project.id}/snippets/#{snippet.id}/notes/#{snippet_note.id}", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['body']).to eq(snippet_note.note) expect(json_response['body']).to eq(snippet_note.note)
end end
it "should return a 404 error if snippet note not found" do it "should return a 404 error if snippet note not found" do
get api("/projects/#{project.id}/snippets/#{snippet.id}/notes/12345", user) get api("/projects/#{project.id}/snippets/#{snippet.id}/notes/12345", user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
end end
...@@ -192,7 +192,7 @@ describe API::API, api: true do ...@@ -192,7 +192,7 @@ describe API::API, api: true do
it "should create a new issue note" do it "should create a new issue note" do
post api("/projects/#{project.id}/issues/#{issue.id}/notes", user), body: 'hi!' post api("/projects/#{project.id}/issues/#{issue.id}/notes", user), body: 'hi!'
expect(response.status).to eq(201) expect(response).to have_http_status(201)
expect(json_response['body']).to eq('hi!') expect(json_response['body']).to eq('hi!')
expect(json_response['author']['username']).to eq(user.username) expect(json_response['author']['username']).to eq(user.username)
end end
...@@ -200,13 +200,13 @@ describe API::API, api: true do ...@@ -200,13 +200,13 @@ describe API::API, api: true do
it "should return a 400 bad request error if body not given" do it "should return a 400 bad request error if body not given" do
post api("/projects/#{project.id}/issues/#{issue.id}/notes", user) post api("/projects/#{project.id}/issues/#{issue.id}/notes", user)
expect(response.status).to eq(400) expect(response).to have_http_status(400)
end end
it "should return a 401 unauthorized error if user not authenticated" do it "should return a 401 unauthorized error if user not authenticated" do
post api("/projects/#{project.id}/issues/#{issue.id}/notes"), body: 'hi!' post api("/projects/#{project.id}/issues/#{issue.id}/notes"), body: 'hi!'
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
context 'when an admin or owner makes the request' do context 'when an admin or owner makes the request' do
...@@ -215,7 +215,7 @@ describe API::API, api: true do ...@@ -215,7 +215,7 @@ describe API::API, api: true do
post api("/projects/#{project.id}/issues/#{issue.id}/notes", user), post api("/projects/#{project.id}/issues/#{issue.id}/notes", user),
body: 'hi!', created_at: creation_time body: 'hi!', created_at: creation_time
expect(response.status).to eq(201) expect(response).to have_http_status(201)
expect(json_response['body']).to eq('hi!') expect(json_response['body']).to eq('hi!')
expect(json_response['author']['username']).to eq(user.username) expect(json_response['author']['username']).to eq(user.username)
expect(Time.parse(json_response['created_at'])).to be_within(1.second).of(creation_time) expect(Time.parse(json_response['created_at'])).to be_within(1.second).of(creation_time)
...@@ -228,7 +228,7 @@ describe API::API, api: true do ...@@ -228,7 +228,7 @@ describe API::API, api: true do
it "should create a new snippet note" do it "should create a new snippet note" do
post api("/projects/#{project.id}/snippets/#{snippet.id}/notes", user), body: 'hi!' post api("/projects/#{project.id}/snippets/#{snippet.id}/notes", user), body: 'hi!'
expect(response.status).to eq(201) expect(response).to have_http_status(201)
expect(json_response['body']).to eq('hi!') expect(json_response['body']).to eq('hi!')
expect(json_response['author']['username']).to eq(user.username) expect(json_response['author']['username']).to eq(user.username)
end end
...@@ -236,13 +236,13 @@ describe API::API, api: true do ...@@ -236,13 +236,13 @@ describe API::API, api: true do
it "should return a 400 bad request error if body not given" do it "should return a 400 bad request error if body not given" do
post api("/projects/#{project.id}/snippets/#{snippet.id}/notes", user) post api("/projects/#{project.id}/snippets/#{snippet.id}/notes", user)
expect(response.status).to eq(400) expect(response).to have_http_status(400)
end end
it "should return a 401 unauthorized error if user not authenticated" do it "should return a 401 unauthorized error if user not authenticated" do
post api("/projects/#{project.id}/snippets/#{snippet.id}/notes"), body: 'hi!' post api("/projects/#{project.id}/snippets/#{snippet.id}/notes"), body: 'hi!'
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
...@@ -282,7 +282,7 @@ describe API::API, api: true do ...@@ -282,7 +282,7 @@ describe API::API, api: true do
put api("/projects/#{project.id}/issues/#{issue.id}/"\ put api("/projects/#{project.id}/issues/#{issue.id}/"\
"notes/#{issue_note.id}", user), body: 'Hello!' "notes/#{issue_note.id}", user), body: 'Hello!'
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['body']).to eq('Hello!') expect(json_response['body']).to eq('Hello!')
end end
...@@ -290,14 +290,14 @@ describe API::API, api: true do ...@@ -290,14 +290,14 @@ describe API::API, api: true do
put api("/projects/#{project.id}/issues/#{issue.id}/notes/12345", user), put api("/projects/#{project.id}/issues/#{issue.id}/notes/12345", user),
body: 'Hello!' body: 'Hello!'
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
it 'should return a 400 bad request error if body not given' do it 'should return a 400 bad request error if body not given' do
put api("/projects/#{project.id}/issues/#{issue.id}/"\ put api("/projects/#{project.id}/issues/#{issue.id}/"\
"notes/#{issue_note.id}", user) "notes/#{issue_note.id}", user)
expect(response.status).to eq(400) expect(response).to have_http_status(400)
end end
end end
...@@ -306,7 +306,7 @@ describe API::API, api: true do ...@@ -306,7 +306,7 @@ describe API::API, api: true do
put api("/projects/#{project.id}/snippets/#{snippet.id}/"\ put api("/projects/#{project.id}/snippets/#{snippet.id}/"\
"notes/#{snippet_note.id}", user), body: 'Hello!' "notes/#{snippet_note.id}", user), body: 'Hello!'
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['body']).to eq('Hello!') expect(json_response['body']).to eq('Hello!')
end end
...@@ -314,7 +314,7 @@ describe API::API, api: true do ...@@ -314,7 +314,7 @@ describe API::API, api: true do
put api("/projects/#{project.id}/snippets/#{snippet.id}/"\ put api("/projects/#{project.id}/snippets/#{snippet.id}/"\
"notes/12345", user), body: "Hello!" "notes/12345", user), body: "Hello!"
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
...@@ -323,7 +323,7 @@ describe API::API, api: true do ...@@ -323,7 +323,7 @@ describe API::API, api: true do
put api("/projects/#{project.id}/merge_requests/#{merge_request.id}/"\ put api("/projects/#{project.id}/merge_requests/#{merge_request.id}/"\
"notes/#{merge_request_note.id}", user), body: 'Hello!' "notes/#{merge_request_note.id}", user), body: 'Hello!'
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['body']).to eq('Hello!') expect(json_response['body']).to eq('Hello!')
end end
...@@ -331,7 +331,7 @@ describe API::API, api: true do ...@@ -331,7 +331,7 @@ describe API::API, api: true do
put api("/projects/#{project.id}/merge_requests/#{merge_request.id}/"\ put api("/projects/#{project.id}/merge_requests/#{merge_request.id}/"\
"notes/12345", user), body: "Hello!" "notes/12345", user), body: "Hello!"
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
end end
...@@ -342,17 +342,17 @@ describe API::API, api: true do ...@@ -342,17 +342,17 @@ describe API::API, api: true do
delete api("/projects/#{project.id}/issues/#{issue.id}/"\ delete api("/projects/#{project.id}/issues/#{issue.id}/"\
"notes/#{issue_note.id}", user) "notes/#{issue_note.id}", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
# Check if note is really deleted # Check if note is really deleted
delete api("/projects/#{project.id}/issues/#{issue.id}/"\ delete api("/projects/#{project.id}/issues/#{issue.id}/"\
"notes/#{issue_note.id}", user) "notes/#{issue_note.id}", user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
it 'returns a 404 error when note id not found' do it 'returns a 404 error when note id not found' do
delete api("/projects/#{project.id}/issues/#{issue.id}/notes/12345", user) delete api("/projects/#{project.id}/issues/#{issue.id}/notes/12345", user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
...@@ -361,18 +361,18 @@ describe API::API, api: true do ...@@ -361,18 +361,18 @@ describe API::API, api: true do
delete api("/projects/#{project.id}/snippets/#{snippet.id}/"\ delete api("/projects/#{project.id}/snippets/#{snippet.id}/"\
"notes/#{snippet_note.id}", user) "notes/#{snippet_note.id}", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
# Check if note is really deleted # Check if note is really deleted
delete api("/projects/#{project.id}/snippets/#{snippet.id}/"\ delete api("/projects/#{project.id}/snippets/#{snippet.id}/"\
"notes/#{snippet_note.id}", user) "notes/#{snippet_note.id}", user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
it 'returns a 404 error when note id not found' do it 'returns a 404 error when note id not found' do
delete api("/projects/#{project.id}/snippets/#{snippet.id}/"\ delete api("/projects/#{project.id}/snippets/#{snippet.id}/"\
"notes/12345", user) "notes/12345", user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
...@@ -381,18 +381,18 @@ describe API::API, api: true do ...@@ -381,18 +381,18 @@ describe API::API, api: true do
delete api("/projects/#{project.id}/merge_requests/"\ delete api("/projects/#{project.id}/merge_requests/"\
"#{merge_request.id}/notes/#{merge_request_note.id}", user) "#{merge_request.id}/notes/#{merge_request_note.id}", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
# Check if note is really deleted # Check if note is really deleted
delete api("/projects/#{project.id}/merge_requests/"\ delete api("/projects/#{project.id}/merge_requests/"\
"#{merge_request.id}/notes/#{merge_request_note.id}", user) "#{merge_request.id}/notes/#{merge_request_note.id}", user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
it 'returns a 404 error when note id not found' do it 'returns a 404 error when note id not found' do
delete api("/projects/#{project.id}/merge_requests/"\ delete api("/projects/#{project.id}/merge_requests/"\
"#{merge_request.id}/notes/12345", user) "#{merge_request.id}/notes/12345", user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
end end
......
...@@ -22,7 +22,7 @@ describe API::API, 'ProjectHooks', api: true do ...@@ -22,7 +22,7 @@ describe API::API, 'ProjectHooks', api: true do
context "authorized user" do context "authorized user" do
it "should return project hooks" do it "should return project hooks" do
get api("/projects/#{project.id}/hooks", user) get api("/projects/#{project.id}/hooks", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.count).to eq(1) expect(json_response.count).to eq(1)
...@@ -40,7 +40,7 @@ describe API::API, 'ProjectHooks', api: true do ...@@ -40,7 +40,7 @@ describe API::API, 'ProjectHooks', api: true do
context "unauthorized user" do context "unauthorized user" do
it "should not access project hooks" do it "should not access project hooks" do
get api("/projects/#{project.id}/hooks", user3) get api("/projects/#{project.id}/hooks", user3)
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
end end
end end
...@@ -49,7 +49,7 @@ describe API::API, 'ProjectHooks', api: true do ...@@ -49,7 +49,7 @@ describe API::API, 'ProjectHooks', api: true do
context "authorized user" do context "authorized user" do
it "should return a project hook" do it "should return a project hook" do
get api("/projects/#{project.id}/hooks/#{hook.id}", user) get api("/projects/#{project.id}/hooks/#{hook.id}", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['url']).to eq(hook.url) expect(json_response['url']).to eq(hook.url)
expect(json_response['issues_events']).to eq(hook.issues_events) expect(json_response['issues_events']).to eq(hook.issues_events)
expect(json_response['push_events']).to eq(hook.push_events) expect(json_response['push_events']).to eq(hook.push_events)
...@@ -61,20 +61,20 @@ describe API::API, 'ProjectHooks', api: true do ...@@ -61,20 +61,20 @@ describe API::API, 'ProjectHooks', api: true do
it "should return a 404 error if hook id is not available" do it "should return a 404 error if hook id is not available" do
get api("/projects/#{project.id}/hooks/1234", user) get api("/projects/#{project.id}/hooks/1234", user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
context "unauthorized user" do context "unauthorized user" do
it "should not access an existing hook" do it "should not access an existing hook" do
get api("/projects/#{project.id}/hooks/#{hook.id}", user3) get api("/projects/#{project.id}/hooks/#{hook.id}", user3)
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
end end
it "should return a 404 error if hook id is not available" do it "should return a 404 error if hook id is not available" do
get api("/projects/#{project.id}/hooks/1234", user) get api("/projects/#{project.id}/hooks/1234", user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
...@@ -83,7 +83,7 @@ describe API::API, 'ProjectHooks', api: true do ...@@ -83,7 +83,7 @@ describe API::API, 'ProjectHooks', api: true do
expect do expect do
post api("/projects/#{project.id}/hooks", user), url: "http://example.com", issues_events: true post api("/projects/#{project.id}/hooks", user), url: "http://example.com", issues_events: true
end.to change {project.hooks.count}.by(1) end.to change {project.hooks.count}.by(1)
expect(response.status).to eq(201) expect(response).to have_http_status(201)
expect(json_response['url']).to eq('http://example.com') expect(json_response['url']).to eq('http://example.com')
expect(json_response['issues_events']).to eq(true) expect(json_response['issues_events']).to eq(true)
expect(json_response['push_events']).to eq(true) expect(json_response['push_events']).to eq(true)
...@@ -96,12 +96,12 @@ describe API::API, 'ProjectHooks', api: true do ...@@ -96,12 +96,12 @@ describe API::API, 'ProjectHooks', api: true do
it "should return a 400 error if url not given" do it "should return a 400 error if url not given" do
post api("/projects/#{project.id}/hooks", user) post api("/projects/#{project.id}/hooks", user)
expect(response.status).to eq(400) expect(response).to have_http_status(400)
end end
it "should return a 422 error if url not valid" do it "should return a 422 error if url not valid" do
post api("/projects/#{project.id}/hooks", user), "url" => "ftp://example.com" post api("/projects/#{project.id}/hooks", user), "url" => "ftp://example.com"
expect(response.status).to eq(422) expect(response).to have_http_status(422)
end end
end end
...@@ -109,7 +109,7 @@ describe API::API, 'ProjectHooks', api: true do ...@@ -109,7 +109,7 @@ describe API::API, 'ProjectHooks', api: true do
it "should update an existing project hook" do it "should update an existing project hook" do
put api("/projects/#{project.id}/hooks/#{hook.id}", user), put api("/projects/#{project.id}/hooks/#{hook.id}", user),
url: 'http://example.org', push_events: false url: 'http://example.org', push_events: false
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['url']).to eq('http://example.org') expect(json_response['url']).to eq('http://example.org')
expect(json_response['issues_events']).to eq(hook.issues_events) expect(json_response['issues_events']).to eq(hook.issues_events)
expect(json_response['push_events']).to eq(false) expect(json_response['push_events']).to eq(false)
...@@ -121,17 +121,17 @@ describe API::API, 'ProjectHooks', api: true do ...@@ -121,17 +121,17 @@ describe API::API, 'ProjectHooks', api: true do
it "should return 404 error if hook id not found" do it "should return 404 error if hook id not found" do
put api("/projects/#{project.id}/hooks/1234", user), url: 'http://example.org' put api("/projects/#{project.id}/hooks/1234", user), url: 'http://example.org'
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
it "should return 400 error if url is not given" do it "should return 400 error if url is not given" do
put api("/projects/#{project.id}/hooks/#{hook.id}", user) put api("/projects/#{project.id}/hooks/#{hook.id}", user)
expect(response.status).to eq(400) expect(response).to have_http_status(400)
end end
it "should return a 422 error if url is not valid" do it "should return a 422 error if url is not valid" do
put api("/projects/#{project.id}/hooks/#{hook.id}", user), url: 'ftp://example.com' put api("/projects/#{project.id}/hooks/#{hook.id}", user), url: 'ftp://example.com'
expect(response.status).to eq(422) expect(response).to have_http_status(422)
end end
end end
...@@ -140,22 +140,22 @@ describe API::API, 'ProjectHooks', api: true do ...@@ -140,22 +140,22 @@ describe API::API, 'ProjectHooks', api: true do
expect do expect do
delete api("/projects/#{project.id}/hooks/#{hook.id}", user) delete api("/projects/#{project.id}/hooks/#{hook.id}", user)
end.to change {project.hooks.count}.by(-1) end.to change {project.hooks.count}.by(-1)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
it "should return success when deleting hook" do it "should return success when deleting hook" do
delete api("/projects/#{project.id}/hooks/#{hook.id}", user) delete api("/projects/#{project.id}/hooks/#{hook.id}", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
it "should return a 404 error when deleting non existent hook" do it "should return a 404 error when deleting non existent hook" do
delete api("/projects/#{project.id}/hooks/42", user) delete api("/projects/#{project.id}/hooks/42", user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
it "should return a 405 error if hook id not given" do it "should return a 405 error if hook id not given" do
delete api("/projects/#{project.id}/hooks", user) delete api("/projects/#{project.id}/hooks", user)
expect(response.status).to eq(405) expect(response).to have_http_status(405)
end end
it "shold return a 404 if a user attempts to delete project hooks he/she does not own" do it "shold return a 404 if a user attempts to delete project hooks he/she does not own" do
...@@ -164,7 +164,7 @@ describe API::API, 'ProjectHooks', api: true do ...@@ -164,7 +164,7 @@ describe API::API, 'ProjectHooks', api: true do
other_project.team << [test_user, :master] other_project.team << [test_user, :master]
delete api("/projects/#{other_project.id}/hooks/#{hook.id}", test_user) delete api("/projects/#{other_project.id}/hooks/#{hook.id}", test_user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
expect(WebHook.exists?(hook.id)).to be_truthy expect(WebHook.exists?(hook.id)).to be_truthy
end end
end end
......
...@@ -15,7 +15,7 @@ describe API::API, api: true do ...@@ -15,7 +15,7 @@ describe API::API, api: true do
it "should return project team members" do it "should return project team members" do
get api("/projects/#{project.id}/members", user) get api("/projects/#{project.id}/members", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.count).to eq(2) expect(json_response.count).to eq(2)
expect(json_response.map { |u| u['username'] }).to include user.username expect(json_response.map { |u| u['username'] }).to include user.username
...@@ -23,7 +23,7 @@ describe API::API, api: true do ...@@ -23,7 +23,7 @@ describe API::API, api: true do
it "finds team members with query string" do it "finds team members with query string" do
get api("/projects/#{project.id}/members", user), query: user.username get api("/projects/#{project.id}/members", user), query: user.username
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.count).to eq(1) expect(json_response.count).to eq(1)
expect(json_response.first['username']).to eq(user.username) expect(json_response.first['username']).to eq(user.username)
...@@ -31,7 +31,7 @@ describe API::API, api: true do ...@@ -31,7 +31,7 @@ describe API::API, api: true do
it "should return a 404 error if id not found" do it "should return a 404 error if id not found" do
get api("/projects/9999/members", user) get api("/projects/9999/members", user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
...@@ -40,14 +40,14 @@ describe API::API, api: true do ...@@ -40,14 +40,14 @@ describe API::API, api: true do
it "should return project team member" do it "should return project team member" do
get api("/projects/#{project.id}/members/#{user.id}", user) get api("/projects/#{project.id}/members/#{user.id}", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['username']).to eq(user.username) expect(json_response['username']).to eq(user.username)
expect(json_response['access_level']).to eq(ProjectMember::MASTER) expect(json_response['access_level']).to eq(ProjectMember::MASTER)
end end
it "should return a 404 error if user id not found" do it "should return a 404 error if user id not found" do
get api("/projects/#{project.id}/members/1234", user) get api("/projects/#{project.id}/members/1234", user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
...@@ -57,7 +57,7 @@ describe API::API, api: true do ...@@ -57,7 +57,7 @@ describe API::API, api: true do
post api("/projects/#{project.id}/members", user), user_id: user2.id, access_level: ProjectMember::DEVELOPER post api("/projects/#{project.id}/members", user), user_id: user2.id, access_level: ProjectMember::DEVELOPER
end.to change { ProjectMember.count }.by(1) end.to change { ProjectMember.count }.by(1)
expect(response.status).to eq(201) expect(response).to have_http_status(201)
expect(json_response['username']).to eq(user2.username) expect(json_response['username']).to eq(user2.username)
expect(json_response['access_level']).to eq(ProjectMember::DEVELOPER) expect(json_response['access_level']).to eq(ProjectMember::DEVELOPER)
end end
...@@ -70,24 +70,24 @@ describe API::API, api: true do ...@@ -70,24 +70,24 @@ describe API::API, api: true do
post api("/projects/#{project.id}/members", user), user_id: user2.id, access_level: ProjectMember::DEVELOPER post api("/projects/#{project.id}/members", user), user_id: user2.id, access_level: ProjectMember::DEVELOPER
end.not_to change { ProjectMember.count } end.not_to change { ProjectMember.count }
expect(response.status).to eq(201) expect(response).to have_http_status(201)
expect(json_response['username']).to eq(user2.username) expect(json_response['username']).to eq(user2.username)
expect(json_response['access_level']).to eq(ProjectMember::DEVELOPER) expect(json_response['access_level']).to eq(ProjectMember::DEVELOPER)
end end
it "should return a 400 error when user id is not given" do it "should return a 400 error when user id is not given" do
post api("/projects/#{project.id}/members", user), access_level: ProjectMember::MASTER post api("/projects/#{project.id}/members", user), access_level: ProjectMember::MASTER
expect(response.status).to eq(400) expect(response).to have_http_status(400)
end end
it "should return a 400 error when access level is not given" do it "should return a 400 error when access level is not given" do
post api("/projects/#{project.id}/members", user), user_id: user2.id post api("/projects/#{project.id}/members", user), user_id: user2.id
expect(response.status).to eq(400) expect(response).to have_http_status(400)
end end
it "should return a 422 error when access level is not known" do it "should return a 422 error when access level is not known" do
post api("/projects/#{project.id}/members", user), user_id: user2.id, access_level: 1234 post api("/projects/#{project.id}/members", user), user_id: user2.id, access_level: 1234
expect(response.status).to eq(422) expect(response).to have_http_status(422)
end end
end end
...@@ -96,24 +96,24 @@ describe API::API, api: true do ...@@ -96,24 +96,24 @@ describe API::API, api: true do
it "should update project team member" do it "should update project team member" do
put api("/projects/#{project.id}/members/#{user3.id}", user), access_level: ProjectMember::MASTER put api("/projects/#{project.id}/members/#{user3.id}", user), access_level: ProjectMember::MASTER
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['username']).to eq(user3.username) expect(json_response['username']).to eq(user3.username)
expect(json_response['access_level']).to eq(ProjectMember::MASTER) expect(json_response['access_level']).to eq(ProjectMember::MASTER)
end end
it "should return a 404 error if user_id is not found" do it "should return a 404 error if user_id is not found" do
put api("/projects/#{project.id}/members/1234", user), access_level: ProjectMember::MASTER put api("/projects/#{project.id}/members/1234", user), access_level: ProjectMember::MASTER
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
it "should return a 400 error when access level is not given" do it "should return a 400 error when access level is not given" do
put api("/projects/#{project.id}/members/#{user3.id}", user) put api("/projects/#{project.id}/members/#{user3.id}", user)
expect(response.status).to eq(400) expect(response).to have_http_status(400)
end end
it "should return a 422 error when access level is not known" do it "should return a 422 error when access level is not known" do
put api("/projects/#{project.id}/members/#{user3.id}", user), access_level: 123 put api("/projects/#{project.id}/members/#{user3.id}", user), access_level: 123
expect(response.status).to eq(422) expect(response).to have_http_status(422)
end end
end end
...@@ -134,20 +134,20 @@ describe API::API, api: true do ...@@ -134,20 +134,20 @@ describe API::API, api: true do
expect do expect do
delete api("/projects/#{project.id}/members/#{user3.id}", user) delete api("/projects/#{project.id}/members/#{user3.id}", user)
end.not_to change { ProjectMember.count } end.not_to change { ProjectMember.count }
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
it "should return 200 if team member already removed" do it "should return 200 if team member already removed" do
delete api("/projects/#{project.id}/members/#{user3.id}", user) delete api("/projects/#{project.id}/members/#{user3.id}", user)
delete api("/projects/#{project.id}/members/#{user3.id}", user) delete api("/projects/#{project.id}/members/#{user3.id}", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
it "should return 200 OK when the user was not member" do it "should return 200 OK when the user was not member" do
expect do expect do
delete api("/projects/#{project.id}/members/1000000", user) delete api("/projects/#{project.id}/members/1000000", user)
end.to change { ProjectMember.count }.by(0) end.to change { ProjectMember.count }.by(0)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['id']).to eq(1000000) expect(json_response['id']).to eq(1000000)
expect(json_response['message']).to eq('Access revoked') expect(json_response['message']).to eq('Access revoked')
end end
...@@ -158,7 +158,7 @@ describe API::API, api: true do ...@@ -158,7 +158,7 @@ describe API::API, api: true do
delete api("/projects/#{project.id}/members/#{user3.id}", user3) delete api("/projects/#{project.id}/members/#{user3.id}", user3)
end.to change { ProjectMember.count }.by(-1) end.to change { ProjectMember.count }.by(-1)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['id']).to eq(project_member2.id) expect(json_response['id']).to eq(project_member2.id)
end end
end end
......
...@@ -27,7 +27,7 @@ describe API::API, api: true do ...@@ -27,7 +27,7 @@ describe API::API, api: true do
get api("/projects/#{project.id}/snippets/", user) get api("/projects/#{project.id}/snippets/", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response.size).to eq(3) expect(json_response.size).to eq(3)
expect(json_response.map{ |snippet| snippet['id']} ).to include(public_snippet.id, internal_snippet.id, private_snippet.id) expect(json_response.map{ |snippet| snippet['id']} ).to include(public_snippet.id, internal_snippet.id, private_snippet.id)
end end
...@@ -38,7 +38,7 @@ describe API::API, api: true do ...@@ -38,7 +38,7 @@ describe API::API, api: true do
create(:project_snippet, :private, project: project) create(:project_snippet, :private, project: project)
get api("/projects/#{project.id}/snippets/", user) get api("/projects/#{project.id}/snippets/", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response.size).to eq(0) expect(json_response.size).to eq(0)
end end
end end
...@@ -56,7 +56,7 @@ describe API::API, api: true do ...@@ -56,7 +56,7 @@ describe API::API, api: true do
post api("/projects/#{project.id}/snippets/", admin), params post api("/projects/#{project.id}/snippets/", admin), params
expect(response.status).to eq(201) expect(response).to have_http_status(201)
snippet = ProjectSnippet.find(json_response['id']) snippet = ProjectSnippet.find(json_response['id'])
expect(snippet.content).to eq(params[:code]) expect(snippet.content).to eq(params[:code])
expect(snippet.title).to eq(params[:title]) expect(snippet.title).to eq(params[:title])
...@@ -73,7 +73,7 @@ describe API::API, api: true do ...@@ -73,7 +73,7 @@ describe API::API, api: true do
put api("/projects/#{snippet.project.id}/snippets/#{snippet.id}/", admin), code: new_content put api("/projects/#{snippet.project.id}/snippets/#{snippet.id}/", admin), code: new_content
expect(response.status).to eq(200) expect(response).to have_http_status(200)
snippet.reload snippet.reload
expect(snippet.content).to eq(new_content) expect(snippet.content).to eq(new_content)
end end
...@@ -86,7 +86,7 @@ describe API::API, api: true do ...@@ -86,7 +86,7 @@ describe API::API, api: true do
delete api("/projects/#{snippet.project.id}/snippets/#{snippet.id}/", admin) delete api("/projects/#{snippet.project.id}/snippets/#{snippet.id}/", admin)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
end end
...@@ -97,7 +97,7 @@ describe API::API, api: true do ...@@ -97,7 +97,7 @@ describe API::API, api: true do
get api("/projects/#{snippet.project.id}/snippets/#{snippet.id}/raw", admin) get api("/projects/#{snippet.project.id}/snippets/#{snippet.id}/raw", admin)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(response.content_type).to eq 'text/plain' expect(response.content_type).to eq 'text/plain'
expect(response.body).to eq(snippet.content) expect(response.body).to eq(snippet.content)
end end
......
...@@ -45,14 +45,14 @@ describe API::API, api: true do ...@@ -45,14 +45,14 @@ describe API::API, api: true do
context 'when unauthenticated' do context 'when unauthenticated' do
it 'should return authentication error' do it 'should return authentication error' do
get api('/projects') get api('/projects')
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
context 'when authenticated' do context 'when authenticated' do
it 'should return an array of projects' do it 'should return an array of projects' do
get api('/projects', user) get api('/projects', user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first['name']).to eq(project.name) expect(json_response.first['name']).to eq(project.name)
expect(json_response.first['owner']['username']).to eq(user.username) expect(json_response.first['owner']['username']).to eq(user.username)
...@@ -84,7 +84,7 @@ describe API::API, api: true do ...@@ -84,7 +84,7 @@ describe API::API, api: true do
context 'and using search' do context 'and using search' do
it 'should return searched project' do it 'should return searched project' do
get api('/projects', user), { search: project.name } get api('/projects', user), { search: project.name }
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
end end
...@@ -93,21 +93,21 @@ describe API::API, api: true do ...@@ -93,21 +93,21 @@ describe API::API, api: true do
context 'and using the visibility filter' do context 'and using the visibility filter' do
it 'should filter based on private visibility param' do it 'should filter based on private visibility param' do
get api('/projects', user), { visibility: 'private' } get api('/projects', user), { visibility: 'private' }
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(user.namespace.projects.where(visibility_level: Gitlab::VisibilityLevel::PRIVATE).count) expect(json_response.length).to eq(user.namespace.projects.where(visibility_level: Gitlab::VisibilityLevel::PRIVATE).count)
end end
it 'should filter based on internal visibility param' do it 'should filter based on internal visibility param' do
get api('/projects', user), { visibility: 'internal' } get api('/projects', user), { visibility: 'internal' }
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(user.namespace.projects.where(visibility_level: Gitlab::VisibilityLevel::INTERNAL).count) expect(json_response.length).to eq(user.namespace.projects.where(visibility_level: Gitlab::VisibilityLevel::INTERNAL).count)
end end
it 'should filter based on public visibility param' do it 'should filter based on public visibility param' do
get api('/projects', user), { visibility: 'public' } get api('/projects', user), { visibility: 'public' }
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(user.namespace.projects.where(visibility_level: Gitlab::VisibilityLevel::PUBLIC).count) expect(json_response.length).to eq(user.namespace.projects.where(visibility_level: Gitlab::VisibilityLevel::PUBLIC).count)
end end
...@@ -121,7 +121,7 @@ describe API::API, api: true do ...@@ -121,7 +121,7 @@ describe API::API, api: true do
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).to have_http_status(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)
end end
...@@ -135,21 +135,21 @@ describe API::API, api: true do ...@@ -135,21 +135,21 @@ describe API::API, api: true do
context 'when unauthenticated' do context 'when unauthenticated' do
it 'should return authentication error' do it 'should return authentication error' do
get api('/projects/all') get api('/projects/all')
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
context 'when authenticated as regular user' do context 'when authenticated as regular user' do
it 'should return authentication error' do it 'should return authentication error' do
get api('/projects/all', user) get api('/projects/all', user)
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
end end
context 'when authenticated as admin' do context 'when authenticated as admin' do
it 'should return an array of all projects' do it 'should return an array of all projects' do
get api('/projects/all', admin) get api('/projects/all', admin)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response).to satisfy do |response| expect(json_response).to satisfy do |response|
...@@ -173,7 +173,7 @@ describe API::API, api: true do ...@@ -173,7 +173,7 @@ describe API::API, api: true do
it 'should return the starred projects viewable by the user' do it 'should return the starred projects viewable by the user' do
get api('/projects/starred', user3) get api('/projects/starred', user3)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.map { |project| project['id'] }).to contain_exactly(project.id, public_project.id) expect(json_response.map { |project| project['id'] }).to contain_exactly(project.id, public_project.id)
end end
...@@ -185,25 +185,25 @@ describe API::API, api: true do ...@@ -185,25 +185,25 @@ describe API::API, api: true 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 { post api('/projects', user2), name: 'foo' }. expect { post api('/projects', user2), name: 'foo' }.
to change {Project.count}.by(0) to change {Project.count}.by(0)
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
end end
it 'should create new project without path and return 201' do it 'should create new project without path and return 201' do
expect { post api('/projects', user), name: 'foo' }. expect { post api('/projects', user), name: 'foo' }.
to change { Project.count }.by(1) to change { Project.count }.by(1)
expect(response.status).to eq(201) expect(response).to have_http_status(201)
end end
it 'should create last project before reaching project limit' do it 'should create last project before reaching project limit' do
allow_any_instance_of(User).to receive(:projects_limit_left).and_return(1) allow_any_instance_of(User).to receive(:projects_limit_left).and_return(1)
post api('/projects', user2), name: 'foo' post api('/projects', user2), name: 'foo'
expect(response.status).to eq(201) expect(response).to have_http_status(201)
end end
it 'should not create new project without name and return 400' do it 'should not create new project without name and return 400' do
expect { post api('/projects', user) }.not_to change { Project.count } expect { post api('/projects', user) }.not_to change { Project.count }
expect(response.status).to eq(400) expect(response).to have_http_status(400)
end end
it "should assign attributes to project" do it "should assign attributes to project" do
...@@ -273,7 +273,7 @@ describe API::API, api: true do ...@@ -273,7 +273,7 @@ describe API::API, api: true do
it 'should not allow a non-admin to use a restricted visibility level' do it 'should not allow a non-admin to use a restricted visibility level' do
post api('/projects', user), @project post api('/projects', user), @project
expect(response.status).to eq(400) expect(response).to have_http_status(400)
expect(json_response['message']['visibility_level'].first).to( expect(json_response['message']['visibility_level'].first).to(
match('restricted by your GitLab administrator') match('restricted by your GitLab administrator')
) )
...@@ -295,14 +295,14 @@ describe API::API, api: true do ...@@ -295,14 +295,14 @@ describe API::API, api: true do
it 'should create new project without path and return 201' do it 'should create new project without path and return 201' do
expect { post api("/projects/user/#{user.id}", admin), name: 'foo' }.to change {Project.count}.by(1) expect { post api("/projects/user/#{user.id}", admin), name: 'foo' }.to change {Project.count}.by(1)
expect(response.status).to eq(201) expect(response).to have_http_status(201)
end end
it 'should respond with 400 on failure and not project' do it 'should respond with 400 on failure and not project' do
expect { post api("/projects/user/#{user.id}", admin) }. expect { post api("/projects/user/#{user.id}", admin) }.
not_to change { Project.count } not_to change { Project.count }
expect(response.status).to eq(400) expect(response).to have_http_status(400)
expect(json_response['message']['name']).to eq([ expect(json_response['message']['name']).to eq([
'can\'t be blank', 'can\'t be blank',
'is too short (minimum is 0 characters)', 'is too short (minimum is 0 characters)',
...@@ -380,7 +380,7 @@ describe API::API, api: true do ...@@ -380,7 +380,7 @@ describe API::API, api: true do
it "uploads the file and returns its info" do it "uploads the file and returns its info" do
post api("/projects/#{project.id}/uploads", user), file: fixture_file_upload(Rails.root + "spec/fixtures/dk.png", "image/png") post api("/projects/#{project.id}/uploads", user), file: fixture_file_upload(Rails.root + "spec/fixtures/dk.png", "image/png")
expect(response.status).to be(201) expect(response).to have_http_status(201)
expect(json_response['alt']).to eq("dk") expect(json_response['alt']).to eq("dk")
expect(json_response['url']).to start_with("/uploads/") expect(json_response['url']).to start_with("/uploads/")
expect(json_response['url']).to end_with("/dk.png") expect(json_response['url']).to end_with("/dk.png")
...@@ -394,27 +394,27 @@ describe API::API, api: true do ...@@ -394,27 +394,27 @@ describe API::API, api: true do
it 'should return a project by id' do it 'should return a project by id' do
get api("/projects/#{project.id}", user) get api("/projects/#{project.id}", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['name']).to eq(project.name) expect(json_response['name']).to eq(project.name)
expect(json_response['owner']['username']).to eq(user.username) expect(json_response['owner']['username']).to eq(user.username)
end end
it 'should return a project by path name' do it 'should return a project by path name' do
get api("/projects/#{project.id}", user) get api("/projects/#{project.id}", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['name']).to eq(project.name) expect(json_response['name']).to eq(project.name)
end end
it 'should return a 404 error if not found' do it 'should return a 404 error if not found' do
get api('/projects/42', user) get api('/projects/42', user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
expect(json_response['message']).to eq('404 Project Not Found') expect(json_response['message']).to eq('404 Project Not Found')
end end
it 'should return a 404 error if user is not a member' do it 'should return a 404 error if user is not a member' do
other_user = create(:user) other_user = create(:user)
get api("/projects/#{project.id}", other_user) get api("/projects/#{project.id}", other_user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
it 'should handle users with dots' do it 'should handle users with dots' do
...@@ -422,7 +422,7 @@ describe API::API, api: true do ...@@ -422,7 +422,7 @@ describe API::API, api: true do
project = create(:project, creator_id: dot_user.id, namespace: dot_user.namespace) project = create(:project, creator_id: dot_user.id, namespace: dot_user.namespace)
get api("/projects/#{dot_user.namespace.name}%2F#{project.path}", dot_user) get api("/projects/#{dot_user.namespace.name}%2F#{project.path}", dot_user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['name']).to eq(project.name) expect(json_response['name']).to eq(project.name)
end end
...@@ -433,7 +433,7 @@ describe API::API, api: true do ...@@ -433,7 +433,7 @@ describe API::API, api: true do
it 'contains permission information' do it 'contains permission information' do
get api("/projects", user) get api("/projects", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response.first['permissions']['project_access']['access_level']). expect(json_response.first['permissions']['project_access']['access_level']).
to eq(Gitlab::Access::MASTER) to eq(Gitlab::Access::MASTER)
expect(json_response.first['permissions']['group_access']).to be_nil expect(json_response.first['permissions']['group_access']).to be_nil
...@@ -445,7 +445,7 @@ describe API::API, api: true do ...@@ -445,7 +445,7 @@ describe API::API, api: true do
project.team << [user, :master] project.team << [user, :master]
get api("/projects/#{project.id}", user) get api("/projects/#{project.id}", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['permissions']['project_access']['access_level']). expect(json_response['permissions']['project_access']['access_level']).
to eq(Gitlab::Access::MASTER) to eq(Gitlab::Access::MASTER)
expect(json_response['permissions']['group_access']).to be_nil expect(json_response['permissions']['group_access']).to be_nil
...@@ -460,7 +460,7 @@ describe API::API, api: true do ...@@ -460,7 +460,7 @@ describe API::API, api: true do
it 'should set the owner and return 200' do it 'should set the owner and return 200' do
get api("/projects/#{project2.id}", user) get api("/projects/#{project2.id}", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['permissions']['project_access']).to be_nil expect(json_response['permissions']['project_access']).to be_nil
expect(json_response['permissions']['group_access']['access_level']). expect(json_response['permissions']['group_access']['access_level']).
to eq(Gitlab::Access::OWNER) to eq(Gitlab::Access::OWNER)
...@@ -479,7 +479,7 @@ describe API::API, api: true do ...@@ -479,7 +479,7 @@ describe API::API, api: true do
get api("/projects/#{project.id}/events", user) get api("/projects/#{project.id}/events", user)
end end
it { expect(response.status).to eq(200) } it { expect(response).to have_http_status(200) }
context 'joined event' do context 'joined event' do
let(:json_event) { json_response[1] } let(:json_event) { json_response[1] }
...@@ -500,14 +500,14 @@ describe API::API, api: true do ...@@ -500,14 +500,14 @@ describe API::API, api: true do
it 'should return a 404 error if not found' do it 'should return a 404 error if not found' do
get api('/projects/42/events', user) get api('/projects/42/events', user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
expect(json_response['message']).to eq('404 Project Not Found') expect(json_response['message']).to eq('404 Project Not Found')
end end
it 'should return a 404 error if user is not a member' do it 'should return a 404 error if user is not a member' do
other_user = create(:user) other_user = create(:user)
get api("/projects/#{project.id}/events", other_user) get api("/projects/#{project.id}/events", other_user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
...@@ -516,7 +516,7 @@ describe API::API, api: true do ...@@ -516,7 +516,7 @@ describe API::API, api: true do
it 'should return an array of project snippets' do it 'should return an array of project snippets' do
get api("/projects/#{project.id}/snippets", user) get api("/projects/#{project.id}/snippets", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first['title']).to eq(snippet.title) expect(json_response.first['title']).to eq(snippet.title)
end end
...@@ -525,13 +525,13 @@ describe API::API, api: true do ...@@ -525,13 +525,13 @@ describe API::API, api: true do
describe 'GET /projects/:id/snippets/:snippet_id' do describe 'GET /projects/:id/snippets/:snippet_id' do
it 'should return a project snippet' do it 'should return a project snippet' do
get api("/projects/#{project.id}/snippets/#{snippet.id}", user) get api("/projects/#{project.id}/snippets/#{snippet.id}", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['title']).to eq(snippet.title) expect(json_response['title']).to eq(snippet.title)
end end
it 'should return a 404 error if snippet id not found' do it 'should return a 404 error if snippet id not found' do
get api("/projects/#{project.id}/snippets/1234", user) get api("/projects/#{project.id}/snippets/1234", user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
...@@ -540,7 +540,7 @@ describe API::API, api: true do ...@@ -540,7 +540,7 @@ describe API::API, api: true do
post api("/projects/#{project.id}/snippets", user), post api("/projects/#{project.id}/snippets", user),
title: 'api test', file_name: 'sample.rb', code: 'test', title: 'api test', file_name: 'sample.rb', code: 'test',
visibility_level: '0' visibility_level: '0'
expect(response.status).to eq(201) expect(response).to have_http_status(201)
expect(json_response['title']).to eq('api test') expect(json_response['title']).to eq('api test')
end end
...@@ -554,7 +554,7 @@ describe API::API, api: true do ...@@ -554,7 +554,7 @@ describe API::API, api: true do
it 'should update an existing project snippet' do it 'should update an existing project snippet' do
put api("/projects/#{project.id}/snippets/#{snippet.id}", user), put api("/projects/#{project.id}/snippets/#{snippet.id}", user),
code: 'updated code' code: 'updated code'
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['title']).to eq('example') expect(json_response['title']).to eq('example')
expect(snippet.reload.content).to eq('updated code') expect(snippet.reload.content).to eq('updated code')
end end
...@@ -562,7 +562,7 @@ describe API::API, api: true do ...@@ -562,7 +562,7 @@ describe API::API, api: true do
it 'should update an existing project snippet with new title' do it 'should update an existing project snippet with new title' do
put api("/projects/#{project.id}/snippets/#{snippet.id}", user), put api("/projects/#{project.id}/snippets/#{snippet.id}", user),
title: 'other api test' title: 'other api test'
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['title']).to eq('other api test') expect(json_response['title']).to eq('other api test')
end end
end end
...@@ -574,24 +574,24 @@ describe API::API, api: true do ...@@ -574,24 +574,24 @@ describe API::API, api: true do
expect do expect do
delete api("/projects/#{project.id}/snippets/#{snippet.id}", user) delete api("/projects/#{project.id}/snippets/#{snippet.id}", user)
end.to change { Snippet.count }.by(-1) end.to change { Snippet.count }.by(-1)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
it 'should return 404 when deleting unknown snippet id' do it 'should return 404 when deleting unknown snippet id' do
delete api("/projects/#{project.id}/snippets/1234", user) delete api("/projects/#{project.id}/snippets/1234", user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
describe 'GET /projects/:id/snippets/:snippet_id/raw' do describe 'GET /projects/:id/snippets/:snippet_id/raw' do
it 'should get a raw project snippet' do it 'should get a raw project snippet' do
get api("/projects/#{project.id}/snippets/#{snippet.id}/raw", user) get api("/projects/#{project.id}/snippets/#{snippet.id}/raw", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
it 'should return a 404 error if raw project snippet not found' do it 'should return a 404 error if raw project snippet not found' do
get api("/projects/#{project.id}/snippets/5555/raw", user) get api("/projects/#{project.id}/snippets/5555/raw", user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
...@@ -604,7 +604,7 @@ describe API::API, api: true do ...@@ -604,7 +604,7 @@ describe API::API, api: true do
it 'should return array of ssh keys' do it 'should return array of ssh keys' do
get api("/projects/#{project.id}/keys", user) get api("/projects/#{project.id}/keys", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first['title']).to eq(deploy_key.title) expect(json_response.first['title']).to eq(deploy_key.title)
end end
...@@ -613,20 +613,20 @@ describe API::API, api: true do ...@@ -613,20 +613,20 @@ describe API::API, api: true do
describe 'GET /projects/:id/keys/:key_id' do describe 'GET /projects/:id/keys/:key_id' do
it 'should return a single key' do it 'should return a single key' do
get api("/projects/#{project.id}/keys/#{deploy_key.id}", user) get api("/projects/#{project.id}/keys/#{deploy_key.id}", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['title']).to eq(deploy_key.title) expect(json_response['title']).to eq(deploy_key.title)
end end
it 'should return 404 Not Found with invalid ID' do it 'should return 404 Not Found with invalid ID' do
get api("/projects/#{project.id}/keys/404", user) get api("/projects/#{project.id}/keys/404", user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
describe 'POST /projects/:id/keys' do describe 'POST /projects/:id/keys' do
it 'should not create an invalid ssh key' do it 'should not create an invalid ssh key' do
post api("/projects/#{project.id}/keys", user), { title: 'invalid key' } post api("/projects/#{project.id}/keys", user), { title: 'invalid key' }
expect(response.status).to eq(400) expect(response).to have_http_status(400)
expect(json_response['message']['key']).to eq([ expect(json_response['message']['key']).to eq([
'can\'t be blank', 'can\'t be blank',
'is too short (minimum is 0 characters)', 'is too short (minimum is 0 characters)',
...@@ -636,7 +636,7 @@ describe API::API, api: true do ...@@ -636,7 +636,7 @@ describe API::API, api: true do
it 'should not create a key without title' do it 'should not create a key without title' do
post api("/projects/#{project.id}/keys", user), key: 'some key' post api("/projects/#{project.id}/keys", user), key: 'some key'
expect(response.status).to eq(400) expect(response).to have_http_status(400)
expect(json_response['message']['title']).to eq([ expect(json_response['message']['title']).to eq([
'can\'t be blank', 'can\'t be blank',
'is too short (minimum is 0 characters)' 'is too short (minimum is 0 characters)'
...@@ -662,7 +662,7 @@ describe API::API, api: true do ...@@ -662,7 +662,7 @@ describe API::API, api: true do
it 'should return 404 Not Found with invalid ID' do it 'should return 404 Not Found with invalid ID' do
delete api("/projects/#{project.id}/keys/404", user) delete api("/projects/#{project.id}/keys/404", user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
end end
...@@ -676,13 +676,13 @@ describe API::API, api: true do ...@@ -676,13 +676,13 @@ describe API::API, api: true do
it "shouldn't available for non admin users" do it "shouldn't available for non admin users" do
post api("/projects/#{project_fork_target.id}/fork/#{project_fork_source.id}", user) post api("/projects/#{project_fork_target.id}/fork/#{project_fork_source.id}", user)
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
it 'should allow project to be forked from an existing project' do it 'should allow project to be forked from an existing project' do
expect(project_fork_target.forked?).not_to be_truthy expect(project_fork_target.forked?).not_to be_truthy
post api("/projects/#{project_fork_target.id}/fork/#{project_fork_source.id}", admin) post api("/projects/#{project_fork_target.id}/fork/#{project_fork_source.id}", admin)
expect(response.status).to eq(201) expect(response).to have_http_status(201)
project_fork_target.reload project_fork_target.reload
expect(project_fork_target.forked_from_project.id).to eq(project_fork_source.id) expect(project_fork_target.forked_from_project.id).to eq(project_fork_source.id)
expect(project_fork_target.forked_project_link).not_to be_nil expect(project_fork_target.forked_project_link).not_to be_nil
...@@ -691,7 +691,7 @@ describe API::API, api: true do ...@@ -691,7 +691,7 @@ describe API::API, api: true do
it 'should fail if forked_from project which does not exist' do it 'should fail if forked_from project which does not exist' do
post api("/projects/#{project_fork_target.id}/fork/9999", admin) post api("/projects/#{project_fork_target.id}/fork/9999", admin)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
it 'should fail with 409 if already forked' do it 'should fail with 409 if already forked' do
...@@ -699,7 +699,7 @@ describe API::API, api: true do ...@@ -699,7 +699,7 @@ describe API::API, api: true do
project_fork_target.reload project_fork_target.reload
expect(project_fork_target.forked_from_project.id).to eq(project_fork_source.id) expect(project_fork_target.forked_from_project.id).to eq(project_fork_source.id)
post api("/projects/#{project_fork_target.id}/fork/#{new_project_fork_source.id}", admin) post api("/projects/#{project_fork_target.id}/fork/#{new_project_fork_source.id}", admin)
expect(response.status).to eq(409) expect(response).to have_http_status(409)
project_fork_target.reload project_fork_target.reload
expect(project_fork_target.forked_from_project.id).to eq(project_fork_source.id) expect(project_fork_target.forked_from_project.id).to eq(project_fork_source.id)
expect(project_fork_target.forked?).to be_truthy expect(project_fork_target.forked?).to be_truthy
...@@ -710,7 +710,7 @@ describe API::API, api: true do ...@@ -710,7 +710,7 @@ describe API::API, api: true do
it "shouldn't be visible to users outside group" do it "shouldn't be visible to users outside group" do
delete api("/projects/#{project_fork_target.id}/fork", user) delete api("/projects/#{project_fork_target.id}/fork", user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
context 'when users belong to project group' do context 'when users belong to project group' do
...@@ -723,7 +723,7 @@ describe API::API, api: true do ...@@ -723,7 +723,7 @@ describe API::API, api: true do
it 'should be forbidden to non-owner users' do it 'should be forbidden to non-owner users' do
delete api("/projects/#{project_fork_target.id}/fork", user2) delete api("/projects/#{project_fork_target.id}/fork", user2)
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
it 'should make forked project unforked' do it 'should make forked project unforked' do
...@@ -732,7 +732,7 @@ describe API::API, api: true do ...@@ -732,7 +732,7 @@ describe API::API, api: true do
expect(project_fork_target.forked_from_project).not_to be_nil expect(project_fork_target.forked_from_project).not_to be_nil
expect(project_fork_target.forked?).to be_truthy expect(project_fork_target.forked?).to be_truthy
delete api("/projects/#{project_fork_target.id}/fork", admin) delete api("/projects/#{project_fork_target.id}/fork", admin)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
project_fork_target.reload project_fork_target.reload
expect(project_fork_target.forked_from_project).to be_nil expect(project_fork_target.forked_from_project).to be_nil
expect(project_fork_target.forked?).not_to be_truthy expect(project_fork_target.forked?).not_to be_truthy
...@@ -741,7 +741,7 @@ describe API::API, api: true do ...@@ -741,7 +741,7 @@ describe API::API, api: true do
it 'should be idempotent if not forked' do it 'should be idempotent if not forked' do
expect(project_fork_target.forked_from_project).to be_nil expect(project_fork_target.forked_from_project).to be_nil
delete api("/projects/#{project_fork_target.id}/fork", admin) delete api("/projects/#{project_fork_target.id}/fork", admin)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(project_fork_target.reload.forked_from_project).to be_nil expect(project_fork_target.reload.forked_from_project).to be_nil
end end
end end
...@@ -799,14 +799,14 @@ describe API::API, api: true do ...@@ -799,14 +799,14 @@ describe API::API, api: true do
context 'when unauthenticated' do context 'when unauthenticated' do
it 'should return authentication error' do it 'should return authentication error' do
get api("/projects/search/#{query}") get api("/projects/search/#{query}")
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
context 'when authenticated' do context 'when authenticated' do
it 'should return an array of projects' do it 'should return an array of projects' do
get api("/projects/search/#{query}",user) get api("/projects/search/#{query}",user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.size).to eq(6) expect(json_response.size).to eq(6)
json_response.each {|project| expect(project['name']).to match(/.*query.*/)} json_response.each {|project| expect(project['name']).to match(/.*query.*/)}
...@@ -816,7 +816,7 @@ describe API::API, api: true do ...@@ -816,7 +816,7 @@ describe API::API, api: true do
context 'when authenticated as a different user' do context 'when authenticated as a different user' do
it 'should return matching public projects' do it 'should return matching public projects' do
get api("/projects/search/#{query}", user2) get api("/projects/search/#{query}", user2)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.size).to eq(2) expect(json_response.size).to eq(2)
json_response.each {|project| expect(project['name']).to match(/(internal|public) query/)} json_response.each {|project| expect(project['name']).to match(/(internal|public) query/)}
...@@ -838,7 +838,7 @@ describe API::API, api: true do ...@@ -838,7 +838,7 @@ describe API::API, api: true do
it 'should return authentication error' do it 'should return authentication error' do
project_param = { name: 'bar' } project_param = { name: 'bar' }
put api("/projects/#{project.id}"), project_param put api("/projects/#{project.id}"), project_param
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
...@@ -846,7 +846,7 @@ describe API::API, api: true do ...@@ -846,7 +846,7 @@ describe API::API, api: true do
it 'should update name' do it 'should update name' do
project_param = { name: 'bar' } project_param = { name: 'bar' }
put api("/projects/#{project.id}", user), project_param put api("/projects/#{project.id}", user), project_param
expect(response.status).to eq(200) expect(response).to have_http_status(200)
project_param.each_pair do |k, v| project_param.each_pair do |k, v|
expect(json_response[k.to_s]).to eq(v) expect(json_response[k.to_s]).to eq(v)
end end
...@@ -855,7 +855,7 @@ describe API::API, api: true do ...@@ -855,7 +855,7 @@ describe API::API, api: true do
it 'should update visibility_level' do it 'should update visibility_level' do
project_param = { visibility_level: 20 } project_param = { visibility_level: 20 }
put api("/projects/#{project3.id}", user), project_param put api("/projects/#{project3.id}", user), project_param
expect(response.status).to eq(200) expect(response).to have_http_status(200)
project_param.each_pair do |k, v| project_param.each_pair do |k, v|
expect(json_response[k.to_s]).to eq(v) expect(json_response[k.to_s]).to eq(v)
end end
...@@ -866,7 +866,7 @@ describe API::API, api: true do ...@@ -866,7 +866,7 @@ describe API::API, api: true do
project_param = { public: false } project_param = { public: false }
put api("/projects/#{project3.id}", user), project_param put api("/projects/#{project3.id}", user), project_param
expect(response.status).to eq(200) expect(response).to have_http_status(200)
project_param.each_pair do |k, v| project_param.each_pair do |k, v|
expect(json_response[k.to_s]).to eq(v) expect(json_response[k.to_s]).to eq(v)
end end
...@@ -876,14 +876,14 @@ describe API::API, api: true do ...@@ -876,14 +876,14 @@ describe API::API, api: true do
it 'should not update name to existing name' do it 'should not update name to existing name' do
project_param = { name: project3.name } project_param = { name: project3.name }
put api("/projects/#{project.id}", user), project_param put api("/projects/#{project.id}", user), project_param
expect(response.status).to eq(400) expect(response).to have_http_status(400)
expect(json_response['message']['name']).to eq(['has already been taken']) expect(json_response['message']['name']).to eq(['has already been taken'])
end end
it 'should update path & name to existing path & name in different namespace' do it 'should update path & name to existing path & name in different namespace' do
project_param = { path: project4.path, name: project4.name } project_param = { path: project4.path, name: project4.name }
put api("/projects/#{project3.id}", user), project_param put api("/projects/#{project3.id}", user), project_param
expect(response.status).to eq(200) expect(response).to have_http_status(200)
project_param.each_pair do |k, v| project_param.each_pair do |k, v|
expect(json_response[k.to_s]).to eq(v) expect(json_response[k.to_s]).to eq(v)
end end
...@@ -894,7 +894,7 @@ describe API::API, api: true do ...@@ -894,7 +894,7 @@ describe API::API, api: true do
it 'should update path' do it 'should update path' do
project_param = { path: 'bar' } project_param = { path: 'bar' }
put api("/projects/#{project3.id}", user4), project_param put api("/projects/#{project3.id}", user4), project_param
expect(response.status).to eq(200) expect(response).to have_http_status(200)
project_param.each_pair do |k, v| project_param.each_pair do |k, v|
expect(json_response[k.to_s]).to eq(v) expect(json_response[k.to_s]).to eq(v)
end end
...@@ -908,7 +908,7 @@ describe API::API, api: true do ...@@ -908,7 +908,7 @@ describe API::API, api: true do
description: 'new description' } description: 'new description' }
put api("/projects/#{project3.id}", user4), project_param put api("/projects/#{project3.id}", user4), project_param
expect(response.status).to eq(200) expect(response).to have_http_status(200)
project_param.each_pair do |k, v| project_param.each_pair do |k, v|
expect(json_response[k.to_s]).to eq(v) expect(json_response[k.to_s]).to eq(v)
end end
...@@ -917,20 +917,20 @@ describe API::API, api: true do ...@@ -917,20 +917,20 @@ describe API::API, api: true do
it 'should not update path to existing path' do it 'should not update path to existing path' do
project_param = { path: project.path } project_param = { path: project.path }
put api("/projects/#{project3.id}", user4), project_param put api("/projects/#{project3.id}", user4), project_param
expect(response.status).to eq(400) expect(response).to have_http_status(400)
expect(json_response['message']['path']).to eq(['has already been taken']) expect(json_response['message']['path']).to eq(['has already been taken'])
end end
it 'should not update name' do it 'should not update name' do
project_param = { name: 'bar' } project_param = { name: 'bar' }
put api("/projects/#{project3.id}", user4), project_param put api("/projects/#{project3.id}", user4), project_param
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
it 'should not update visibility_level' do it 'should not update visibility_level' do
project_param = { visibility_level: 20 } project_param = { visibility_level: 20 }
put api("/projects/#{project3.id}", user4), project_param put api("/projects/#{project3.id}", user4), project_param
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
end end
...@@ -943,7 +943,7 @@ describe API::API, api: true do ...@@ -943,7 +943,7 @@ describe API::API, api: true do
merge_requests_enabled: true, merge_requests_enabled: true,
description: 'new description' } description: 'new description' }
put api("/projects/#{project.id}", user3), project_param put api("/projects/#{project.id}", user3), project_param
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
end end
end end
...@@ -953,7 +953,7 @@ describe API::API, api: true do ...@@ -953,7 +953,7 @@ describe API::API, api: true do
it 'archives the project' do it 'archives the project' do
post api("/projects/#{project.id}/archive", user) post api("/projects/#{project.id}/archive", user)
expect(response.status).to eq(201) expect(response).to have_http_status(201)
expect(json_response['archived']).to be_truthy expect(json_response['archived']).to be_truthy
end end
end end
...@@ -966,7 +966,7 @@ describe API::API, api: true do ...@@ -966,7 +966,7 @@ describe API::API, api: true do
it 'remains archived' do it 'remains archived' do
post api("/projects/#{project.id}/archive", user) post api("/projects/#{project.id}/archive", user)
expect(response.status).to eq(201) expect(response).to have_http_status(201)
expect(json_response['archived']).to be_truthy expect(json_response['archived']).to be_truthy
end end
end end
...@@ -979,7 +979,7 @@ describe API::API, api: true do ...@@ -979,7 +979,7 @@ describe API::API, api: true do
it 'rejects the action' do it 'rejects the action' do
post api("/projects/#{project.id}/archive", user3) post api("/projects/#{project.id}/archive", user3)
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
end end
end end
...@@ -989,7 +989,7 @@ describe API::API, api: true do ...@@ -989,7 +989,7 @@ describe API::API, api: true do
it 'remains unarchived' do it 'remains unarchived' do
post api("/projects/#{project.id}/unarchive", user) post api("/projects/#{project.id}/unarchive", user)
expect(response.status).to eq(201) expect(response).to have_http_status(201)
expect(json_response['archived']).to be_falsey expect(json_response['archived']).to be_falsey
end end
end end
...@@ -1002,7 +1002,7 @@ describe API::API, api: true do ...@@ -1002,7 +1002,7 @@ describe API::API, api: true do
it 'unarchives the project' do it 'unarchives the project' do
post api("/projects/#{project.id}/unarchive", user) post api("/projects/#{project.id}/unarchive", user)
expect(response.status).to eq(201) expect(response).to have_http_status(201)
expect(json_response['archived']).to be_falsey expect(json_response['archived']).to be_falsey
end end
end end
...@@ -1015,7 +1015,7 @@ describe API::API, api: true do ...@@ -1015,7 +1015,7 @@ describe API::API, api: true do
it 'rejects the action' do it 'rejects the action' do
post api("/projects/#{project.id}/unarchive", user3) post api("/projects/#{project.id}/unarchive", user3)
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
end end
end end
...@@ -1025,7 +1025,7 @@ describe API::API, api: true do ...@@ -1025,7 +1025,7 @@ describe API::API, api: true do
it 'stars the project' do it 'stars the project' do
expect { post api("/projects/#{project.id}/star", user) }.to change { project.reload.star_count }.by(1) expect { post api("/projects/#{project.id}/star", user) }.to change { project.reload.star_count }.by(1)
expect(response.status).to eq(201) expect(response).to have_http_status(201)
expect(json_response['star_count']).to eq(1) expect(json_response['star_count']).to eq(1)
end end
end end
...@@ -1039,7 +1039,7 @@ describe API::API, api: true do ...@@ -1039,7 +1039,7 @@ describe API::API, api: true do
it 'does not modify the star count' do it 'does not modify the star count' do
expect { post api("/projects/#{project.id}/star", user) }.not_to change { project.reload.star_count } expect { post api("/projects/#{project.id}/star", user) }.not_to change { project.reload.star_count }
expect(response.status).to eq(304) expect(response).to have_http_status(304)
end end
end end
end end
...@@ -1054,7 +1054,7 @@ describe API::API, api: true do ...@@ -1054,7 +1054,7 @@ describe API::API, api: true do
it 'unstars the project' do it 'unstars the project' do
expect { delete api("/projects/#{project.id}/star", user) }.to change { project.reload.star_count }.by(-1) expect { delete api("/projects/#{project.id}/star", user) }.to change { project.reload.star_count }.by(-1)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['star_count']).to eq(0) expect(json_response['star_count']).to eq(0)
end end
end end
...@@ -1063,7 +1063,7 @@ describe API::API, api: true do ...@@ -1063,7 +1063,7 @@ describe API::API, api: true do
it 'does not modify the star count' do it 'does not modify the star count' do
expect { delete api("/projects/#{project.id}/star", user) }.not_to change { project.reload.star_count } expect { delete api("/projects/#{project.id}/star", user) }.not_to change { project.reload.star_count }
expect(response.status).to eq(304) expect(response).to have_http_status(304)
end end
end end
end end
...@@ -1072,36 +1072,36 @@ describe API::API, api: true do ...@@ -1072,36 +1072,36 @@ describe API::API, api: true do
context 'when authenticated as user' do context 'when authenticated as user' do
it 'should remove project' do it 'should remove project' do
delete api("/projects/#{project.id}", user) delete api("/projects/#{project.id}", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
it 'should not remove a project if not an owner' do it 'should not remove a project if not an owner' do
user3 = create(:user) user3 = create(:user)
project.team << [user3, :developer] project.team << [user3, :developer]
delete api("/projects/#{project.id}", user3) delete api("/projects/#{project.id}", user3)
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
it 'should not remove a non existing project' do it 'should not remove a non existing project' do
delete api('/projects/1328', user) delete api('/projects/1328', user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
it 'should not remove a project not attached to user' do it 'should not remove a project not attached to user' do
delete api("/projects/#{project.id}", user2) delete api("/projects/#{project.id}", user2)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
context 'when authenticated as admin' do context 'when authenticated as admin' do
it 'should remove any existing project' do it 'should remove any existing project' do
delete api("/projects/#{project.id}", admin) delete api("/projects/#{project.id}", admin)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
it 'should not remove a non existing project' do it 'should not remove a non existing project' do
delete api('/projects/1328', admin) delete api('/projects/1328', admin)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
end end
......
...@@ -18,7 +18,7 @@ describe API::API, api: true do ...@@ -18,7 +18,7 @@ describe API::API, api: true do
it "should return project commits" do it "should return project commits" do
get api("/projects/#{project.id}/repository/tree", user) get api("/projects/#{project.id}/repository/tree", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first['name']).to eq('encoding') expect(json_response.first['name']).to eq('encoding')
...@@ -28,7 +28,7 @@ describe API::API, api: true do ...@@ -28,7 +28,7 @@ describe API::API, api: true do
it 'should return a 404 for unknown ref' do it 'should return a 404 for unknown ref' do
get api("/projects/#{project.id}/repository/tree?ref_name=foo", user) get api("/projects/#{project.id}/repository/tree?ref_name=foo", user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
expect(json_response).to be_an Object expect(json_response).to be_an Object
json_response['message'] == '404 Tree Not Found' json_response['message'] == '404 Tree Not Found'
...@@ -38,7 +38,7 @@ describe API::API, api: true do ...@@ -38,7 +38,7 @@ describe API::API, api: true do
context "unauthorized user" do context "unauthorized user" do
it "should not return project commits" do it "should not return project commits" do
get api("/projects/#{project.id}/repository/tree") get api("/projects/#{project.id}/repository/tree")
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
end end
...@@ -46,41 +46,41 @@ describe API::API, api: true do ...@@ -46,41 +46,41 @@ describe API::API, api: true do
describe "GET /projects/:id/repository/blobs/:sha" do describe "GET /projects/:id/repository/blobs/:sha" do
it "should get the raw file contents" do it "should get the raw file contents" do
get api("/projects/#{project.id}/repository/blobs/master?filepath=README.md", user) get api("/projects/#{project.id}/repository/blobs/master?filepath=README.md", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
it "should return 404 for invalid branch_name" do it "should return 404 for invalid branch_name" do
get api("/projects/#{project.id}/repository/blobs/invalid_branch_name?filepath=README.md", user) get api("/projects/#{project.id}/repository/blobs/invalid_branch_name?filepath=README.md", user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
it "should return 404 for invalid file" do it "should return 404 for invalid file" do
get api("/projects/#{project.id}/repository/blobs/master?filepath=README.invalid", user) get api("/projects/#{project.id}/repository/blobs/master?filepath=README.invalid", user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
it "should return a 400 error if filepath is missing" do it "should return a 400 error if filepath is missing" do
get api("/projects/#{project.id}/repository/blobs/master", user) get api("/projects/#{project.id}/repository/blobs/master", user)
expect(response.status).to eq(400) expect(response).to have_http_status(400)
end end
end end
describe "GET /projects/:id/repository/commits/:sha/blob" do describe "GET /projects/:id/repository/commits/:sha/blob" do
it "should get the raw file contents" do it "should get the raw file contents" do
get api("/projects/#{project.id}/repository/commits/master/blob?filepath=README.md", user) get api("/projects/#{project.id}/repository/commits/master/blob?filepath=README.md", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
end end
describe "GET /projects/:id/repository/raw_blobs/:sha" do describe "GET /projects/:id/repository/raw_blobs/:sha" do
it "should get the raw file contents" do it "should get the raw file contents" do
get api("/projects/#{project.id}/repository/raw_blobs/#{sample_blob.oid}", user) get api("/projects/#{project.id}/repository/raw_blobs/#{sample_blob.oid}", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
it 'should return a 404 for unknown blob' do it 'should return a 404 for unknown blob' do
get api("/projects/#{project.id}/repository/raw_blobs/123456", user) get api("/projects/#{project.id}/repository/raw_blobs/123456", user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
expect(json_response).to be_an Object expect(json_response).to be_an Object
json_response['message'] == '404 Blob Not Found' json_response['message'] == '404 Blob Not Found'
...@@ -91,7 +91,7 @@ describe API::API, api: true do ...@@ -91,7 +91,7 @@ describe API::API, api: true do
it "should get the archive" do it "should get the archive" do
get api("/projects/#{project.id}/repository/archive", user) get api("/projects/#{project.id}/repository/archive", user)
repo_name = project.repository.name.gsub("\.git", "") repo_name = project.repository.name.gsub("\.git", "")
expect(response.status).to eq(200) expect(response).to have_http_status(200)
type, params = workhorse_send_data type, params = workhorse_send_data
expect(type).to eq('git-archive') expect(type).to eq('git-archive')
expect(params['ArchivePath']).to match(/#{repo_name}\-[^\.]+\.tar.gz/) expect(params['ArchivePath']).to match(/#{repo_name}\-[^\.]+\.tar.gz/)
...@@ -100,7 +100,7 @@ describe API::API, api: true do ...@@ -100,7 +100,7 @@ describe API::API, api: true do
it "should get the archive.zip" do it "should get the archive.zip" do
get api("/projects/#{project.id}/repository/archive.zip", user) get api("/projects/#{project.id}/repository/archive.zip", user)
repo_name = project.repository.name.gsub("\.git", "") repo_name = project.repository.name.gsub("\.git", "")
expect(response.status).to eq(200) expect(response).to have_http_status(200)
type, params = workhorse_send_data type, params = workhorse_send_data
expect(type).to eq('git-archive') expect(type).to eq('git-archive')
expect(params['ArchivePath']).to match(/#{repo_name}\-[^\.]+\.zip/) expect(params['ArchivePath']).to match(/#{repo_name}\-[^\.]+\.zip/)
...@@ -109,7 +109,7 @@ describe API::API, api: true do ...@@ -109,7 +109,7 @@ describe API::API, api: true do
it "should get the archive.tar.bz2" do it "should get the archive.tar.bz2" do
get api("/projects/#{project.id}/repository/archive.tar.bz2", user) get api("/projects/#{project.id}/repository/archive.tar.bz2", user)
repo_name = project.repository.name.gsub("\.git", "") repo_name = project.repository.name.gsub("\.git", "")
expect(response.status).to eq(200) expect(response).to have_http_status(200)
type, params = workhorse_send_data type, params = workhorse_send_data
expect(type).to eq('git-archive') expect(type).to eq('git-archive')
expect(params['ArchivePath']).to match(/#{repo_name}\-[^\.]+\.tar.bz2/) expect(params['ArchivePath']).to match(/#{repo_name}\-[^\.]+\.tar.bz2/)
...@@ -117,28 +117,28 @@ describe API::API, api: true do ...@@ -117,28 +117,28 @@ describe API::API, api: true do
it "should return 404 for invalid sha" do it "should return 404 for invalid sha" do
get api("/projects/#{project.id}/repository/archive/?sha=xxx", user) get api("/projects/#{project.id}/repository/archive/?sha=xxx", user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
describe 'GET /projects/:id/repository/compare' do describe 'GET /projects/:id/repository/compare' do
it "should compare branches" do it "should compare branches" do
get api("/projects/#{project.id}/repository/compare", user), from: 'master', to: 'feature' get api("/projects/#{project.id}/repository/compare", user), from: 'master', to: 'feature'
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['commits']).to be_present expect(json_response['commits']).to be_present
expect(json_response['diffs']).to be_present expect(json_response['diffs']).to be_present
end end
it "should compare tags" do it "should compare tags" do
get api("/projects/#{project.id}/repository/compare", user), from: 'v1.0.0', to: 'v1.1.0' get api("/projects/#{project.id}/repository/compare", user), from: 'v1.0.0', to: 'v1.1.0'
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['commits']).to be_present expect(json_response['commits']).to be_present
expect(json_response['diffs']).to be_present expect(json_response['diffs']).to be_present
end end
it "should compare commits" do it "should compare commits" do
get api("/projects/#{project.id}/repository/compare", user), from: sample_commit.id, to: sample_commit.parent_id get api("/projects/#{project.id}/repository/compare", user), from: sample_commit.id, to: sample_commit.parent_id
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['commits']).to be_empty expect(json_response['commits']).to be_empty
expect(json_response['diffs']).to be_empty expect(json_response['diffs']).to be_empty
expect(json_response['compare_same_ref']).to be_falsey expect(json_response['compare_same_ref']).to be_falsey
...@@ -146,14 +146,14 @@ describe API::API, api: true do ...@@ -146,14 +146,14 @@ describe API::API, api: true do
it "should compare commits in reverse order" do it "should compare commits in reverse order" do
get api("/projects/#{project.id}/repository/compare", user), from: sample_commit.parent_id, to: sample_commit.id get api("/projects/#{project.id}/repository/compare", user), from: sample_commit.parent_id, to: sample_commit.id
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['commits']).to be_present expect(json_response['commits']).to be_present
expect(json_response['diffs']).to be_present expect(json_response['diffs']).to be_present
end end
it "should compare same refs" do it "should compare same refs" do
get api("/projects/#{project.id}/repository/compare", user), from: 'master', to: 'master' get api("/projects/#{project.id}/repository/compare", user), from: 'master', to: 'master'
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['commits']).to be_empty expect(json_response['commits']).to be_empty
expect(json_response['diffs']).to be_empty expect(json_response['diffs']).to be_empty
expect(json_response['compare_same_ref']).to be_truthy expect(json_response['compare_same_ref']).to be_truthy
...@@ -163,7 +163,7 @@ describe API::API, api: true do ...@@ -163,7 +163,7 @@ describe API::API, api: true do
describe 'GET /projects/:id/repository/contributors' do describe 'GET /projects/:id/repository/contributors' do
it 'should return valid data' do it 'should return valid data' do
get api("/projects/#{project.id}/repository/contributors", user) get api("/projects/#{project.id}/repository/contributors", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
contributor = json_response.first contributor = json_response.first
expect(contributor['email']).to eq('dmitriy.zaporozhets@gmail.com') expect(contributor['email']).to eq('dmitriy.zaporozhets@gmail.com')
......
...@@ -39,7 +39,7 @@ describe API::Runners, api: true do ...@@ -39,7 +39,7 @@ describe API::Runners, api: true do
get api('/runners', user) get api('/runners', user)
shared = json_response.any?{ |r| r['is_shared'] } shared = json_response.any?{ |r| r['is_shared'] }
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(shared).to be_falsey expect(shared).to be_falsey
end end
...@@ -48,14 +48,14 @@ describe API::Runners, api: true do ...@@ -48,14 +48,14 @@ describe API::Runners, api: true do
get api('/runners?scope=active', user) get api('/runners?scope=active', user)
shared = json_response.any?{ |r| r['is_shared'] } shared = json_response.any?{ |r| r['is_shared'] }
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(shared).to be_falsey expect(shared).to be_falsey
end end
it 'should avoid filtering if scope is invalid' do it 'should avoid filtering if scope is invalid' do
get api('/runners?scope=unknown', user) get api('/runners?scope=unknown', user)
expect(response.status).to eq(400) expect(response).to have_http_status(400)
end end
end end
...@@ -63,7 +63,7 @@ describe API::Runners, api: true do ...@@ -63,7 +63,7 @@ describe API::Runners, api: true do
it 'should not return runners' do it 'should not return runners' do
get api('/runners') get api('/runners')
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
end end
...@@ -75,7 +75,7 @@ describe API::Runners, api: true do ...@@ -75,7 +75,7 @@ describe API::Runners, api: true do
get api('/runners/all', admin) get api('/runners/all', admin)
shared = json_response.any?{ |r| r['is_shared'] } shared = json_response.any?{ |r| r['is_shared'] }
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(shared).to be_truthy expect(shared).to be_truthy
end end
...@@ -85,7 +85,7 @@ describe API::Runners, api: true do ...@@ -85,7 +85,7 @@ describe API::Runners, api: true do
it 'should not return runners list' do it 'should not return runners list' do
get api('/runners/all', user) get api('/runners/all', user)
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
end end
...@@ -93,14 +93,14 @@ describe API::Runners, api: true do ...@@ -93,14 +93,14 @@ describe API::Runners, api: true do
get api('/runners/all?scope=specific', admin) get api('/runners/all?scope=specific', admin)
shared = json_response.any?{ |r| r['is_shared'] } shared = json_response.any?{ |r| r['is_shared'] }
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(shared).to be_falsey expect(shared).to be_falsey
end end
it 'should avoid filtering if scope is invalid' do it 'should avoid filtering if scope is invalid' do
get api('/runners?scope=unknown', admin) get api('/runners?scope=unknown', admin)
expect(response.status).to eq(400) expect(response).to have_http_status(400)
end end
end end
...@@ -108,7 +108,7 @@ describe API::Runners, api: true do ...@@ -108,7 +108,7 @@ describe API::Runners, api: true do
it 'should not return runners' do it 'should not return runners' do
get api('/runners') get api('/runners')
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
end end
...@@ -119,7 +119,7 @@ describe API::Runners, api: true do ...@@ -119,7 +119,7 @@ describe API::Runners, api: true do
it "should return runner's details" do it "should return runner's details" do
get api("/runners/#{shared_runner.id}", admin) get api("/runners/#{shared_runner.id}", admin)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['description']).to eq(shared_runner.description) expect(json_response['description']).to eq(shared_runner.description)
end end
end end
...@@ -128,7 +128,7 @@ describe API::Runners, api: true do ...@@ -128,7 +128,7 @@ describe API::Runners, api: true do
it "should return runner's details" do it "should return runner's details" do
get api("/runners/#{specific_runner.id}", admin) get api("/runners/#{specific_runner.id}", admin)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['description']).to eq(specific_runner.description) expect(json_response['description']).to eq(specific_runner.description)
end end
end end
...@@ -136,7 +136,7 @@ describe API::Runners, api: true do ...@@ -136,7 +136,7 @@ describe API::Runners, api: true do
it 'should return 404 if runner does not exists' do it 'should return 404 if runner does not exists' do
get api('/runners/9999', admin) get api('/runners/9999', admin)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
...@@ -145,7 +145,7 @@ describe API::Runners, api: true do ...@@ -145,7 +145,7 @@ describe API::Runners, api: true do
it "should return runner's details" do it "should return runner's details" do
get api("/runners/#{specific_runner.id}", user) get api("/runners/#{specific_runner.id}", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['description']).to eq(specific_runner.description) expect(json_response['description']).to eq(specific_runner.description)
end end
end end
...@@ -154,7 +154,7 @@ describe API::Runners, api: true do ...@@ -154,7 +154,7 @@ describe API::Runners, api: true do
it "should return runner's details" do it "should return runner's details" do
get api("/runners/#{shared_runner.id}", user) get api("/runners/#{shared_runner.id}", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['description']).to eq(shared_runner.description) expect(json_response['description']).to eq(shared_runner.description)
end end
end end
...@@ -164,7 +164,7 @@ describe API::Runners, api: true do ...@@ -164,7 +164,7 @@ describe API::Runners, api: true do
it "should not return runner's details" do it "should not return runner's details" do
get api("/runners/#{specific_runner.id}", user2) get api("/runners/#{specific_runner.id}", user2)
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
end end
...@@ -172,7 +172,7 @@ describe API::Runners, api: true do ...@@ -172,7 +172,7 @@ describe API::Runners, api: true do
it "should not return runner's details" do it "should not return runner's details" do
get api("/runners/#{specific_runner.id}") get api("/runners/#{specific_runner.id}")
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
end end
...@@ -191,7 +191,7 @@ describe API::Runners, api: true do ...@@ -191,7 +191,7 @@ describe API::Runners, api: true do
locked: 'true') locked: 'true')
shared_runner.reload shared_runner.reload
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(shared_runner.description).to eq("#{description}_updated") expect(shared_runner.description).to eq("#{description}_updated")
expect(shared_runner.active).to eq(!active) expect(shared_runner.active).to eq(!active)
expect(shared_runner.tag_list).to include('ruby2.1', 'pgsql', 'mysql') expect(shared_runner.tag_list).to include('ruby2.1', 'pgsql', 'mysql')
...@@ -206,7 +206,7 @@ describe API::Runners, api: true do ...@@ -206,7 +206,7 @@ describe API::Runners, api: true do
update_runner(specific_runner.id, admin, description: 'test') update_runner(specific_runner.id, admin, description: 'test')
specific_runner.reload specific_runner.reload
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(specific_runner.description).to eq('test') expect(specific_runner.description).to eq('test')
expect(specific_runner.description).not_to eq(description) expect(specific_runner.description).not_to eq(description)
end end
...@@ -215,7 +215,7 @@ describe API::Runners, api: true do ...@@ -215,7 +215,7 @@ describe API::Runners, api: true do
it 'should return 404 if runner does not exists' do it 'should return 404 if runner does not exists' do
update_runner(9999, admin, description: 'test') update_runner(9999, admin, description: 'test')
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
def update_runner(id, user, args) def update_runner(id, user, args)
...@@ -228,7 +228,7 @@ describe API::Runners, api: true do ...@@ -228,7 +228,7 @@ describe API::Runners, api: true do
it 'should not update runner' do it 'should not update runner' do
put api("/runners/#{shared_runner.id}", user) put api("/runners/#{shared_runner.id}", user)
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
end end
...@@ -236,7 +236,7 @@ describe API::Runners, api: true do ...@@ -236,7 +236,7 @@ describe API::Runners, api: true do
it 'should not update runner without access to it' do it 'should not update runner without access to it' do
put api("/runners/#{specific_runner.id}", user2) put api("/runners/#{specific_runner.id}", user2)
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
it 'should update runner with access to it' do it 'should update runner with access to it' do
...@@ -244,7 +244,7 @@ describe API::Runners, api: true do ...@@ -244,7 +244,7 @@ describe API::Runners, api: true do
put api("/runners/#{specific_runner.id}", admin), description: 'test' put api("/runners/#{specific_runner.id}", admin), description: 'test'
specific_runner.reload specific_runner.reload
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(specific_runner.description).to eq('test') expect(specific_runner.description).to eq('test')
expect(specific_runner.description).not_to eq(description) expect(specific_runner.description).not_to eq(description)
end end
...@@ -255,7 +255,7 @@ describe API::Runners, api: true do ...@@ -255,7 +255,7 @@ describe API::Runners, api: true do
it 'should not delete runner' do it 'should not delete runner' do
put api("/runners/#{specific_runner.id}") put api("/runners/#{specific_runner.id}")
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
end end
...@@ -267,7 +267,7 @@ describe API::Runners, api: true do ...@@ -267,7 +267,7 @@ describe API::Runners, api: true do
expect do expect do
delete api("/runners/#{shared_runner.id}", admin) delete api("/runners/#{shared_runner.id}", admin)
end.to change{ Ci::Runner.shared.count }.by(-1) end.to change{ Ci::Runner.shared.count }.by(-1)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
end end
...@@ -276,21 +276,21 @@ describe API::Runners, api: true do ...@@ -276,21 +276,21 @@ describe API::Runners, api: true do
expect do expect do
delete api("/runners/#{unused_specific_runner.id}", admin) delete api("/runners/#{unused_specific_runner.id}", admin)
end.to change{ Ci::Runner.specific.count }.by(-1) end.to change{ Ci::Runner.specific.count }.by(-1)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
it 'should delete used runner' do it 'should delete used runner' do
expect do expect do
delete api("/runners/#{specific_runner.id}", admin) delete api("/runners/#{specific_runner.id}", admin)
end.to change{ Ci::Runner.specific.count }.by(-1) end.to change{ Ci::Runner.specific.count }.by(-1)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
end end
it 'should return 404 if runner does not exists' do it 'should return 404 if runner does not exists' do
delete api('/runners/9999', admin) delete api('/runners/9999', admin)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
...@@ -298,26 +298,26 @@ describe API::Runners, api: true do ...@@ -298,26 +298,26 @@ describe API::Runners, api: true do
context 'when runner is shared' do context 'when runner is shared' do
it 'should not delete runner' do it 'should not delete runner' do
delete api("/runners/#{shared_runner.id}", user) delete api("/runners/#{shared_runner.id}", user)
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
end end
context 'when runner is not shared' do context 'when runner is not shared' do
it 'should not delete runner without access to it' do it 'should not delete runner without access to it' do
delete api("/runners/#{specific_runner.id}", user2) delete api("/runners/#{specific_runner.id}", user2)
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
it 'should not delete runner with more than one associated project' do it 'should not delete runner with more than one associated project' do
delete api("/runners/#{two_projects_runner.id}", user) delete api("/runners/#{two_projects_runner.id}", user)
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
it 'should delete runner for one owned project' do it 'should delete runner for one owned project' do
expect do expect do
delete api("/runners/#{specific_runner.id}", user) delete api("/runners/#{specific_runner.id}", user)
end.to change{ Ci::Runner.specific.count }.by(-1) end.to change{ Ci::Runner.specific.count }.by(-1)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
end end
end end
...@@ -326,7 +326,7 @@ describe API::Runners, api: true do ...@@ -326,7 +326,7 @@ describe API::Runners, api: true do
it 'should not delete runner' do it 'should not delete runner' do
delete api("/runners/#{specific_runner.id}") delete api("/runners/#{specific_runner.id}")
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
end end
...@@ -337,7 +337,7 @@ describe API::Runners, api: true do ...@@ -337,7 +337,7 @@ describe API::Runners, api: true do
get api("/projects/#{project.id}/runners", user) get api("/projects/#{project.id}/runners", user)
shared = json_response.any?{ |r| r['is_shared'] } shared = json_response.any?{ |r| r['is_shared'] }
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(shared).to be_truthy expect(shared).to be_truthy
end end
...@@ -347,7 +347,7 @@ describe API::Runners, api: true do ...@@ -347,7 +347,7 @@ describe API::Runners, api: true do
it "should not return project's runners" do it "should not return project's runners" do
get api("/projects/#{project.id}/runners", user2) get api("/projects/#{project.id}/runners", user2)
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
end end
...@@ -355,7 +355,7 @@ describe API::Runners, api: true do ...@@ -355,7 +355,7 @@ describe API::Runners, api: true do
it "should not return project's runners" do it "should not return project's runners" do
get api("/projects/#{project.id}/runners") get api("/projects/#{project.id}/runners")
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
end end
...@@ -372,14 +372,14 @@ describe API::Runners, api: true do ...@@ -372,14 +372,14 @@ describe API::Runners, api: true do
expect do expect do
post api("/projects/#{project.id}/runners", user), runner_id: specific_runner2.id post api("/projects/#{project.id}/runners", user), runner_id: specific_runner2.id
end.to change{ project.runners.count }.by(+1) end.to change{ project.runners.count }.by(+1)
expect(response.status).to eq(201) expect(response).to have_http_status(201)
end end
it 'should avoid changes when enabling already enabled runner' do it 'should avoid changes when enabling already enabled runner' do
expect do expect do
post api("/projects/#{project.id}/runners", user), runner_id: specific_runner.id post api("/projects/#{project.id}/runners", user), runner_id: specific_runner.id
end.to change{ project.runners.count }.by(0) end.to change{ project.runners.count }.by(0)
expect(response.status).to eq(409) expect(response).to have_http_status(409)
end end
it 'should not enable locked runner' do it 'should not enable locked runner' do
...@@ -389,13 +389,13 @@ describe API::Runners, api: true do ...@@ -389,13 +389,13 @@ describe API::Runners, api: true do
post api("/projects/#{project.id}/runners", user), runner_id: specific_runner2.id post api("/projects/#{project.id}/runners", user), runner_id: specific_runner2.id
end.to change{ project.runners.count }.by(0) end.to change{ project.runners.count }.by(0)
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
it 'should not enable shared runner' do it 'should not enable shared runner' do
post api("/projects/#{project.id}/runners", user), runner_id: shared_runner.id post api("/projects/#{project.id}/runners", user), runner_id: shared_runner.id
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
context 'user is admin' do context 'user is admin' do
...@@ -403,7 +403,7 @@ describe API::Runners, api: true do ...@@ -403,7 +403,7 @@ describe API::Runners, api: true do
expect do expect do
post api("/projects/#{project.id}/runners", admin), runner_id: unused_specific_runner.id post api("/projects/#{project.id}/runners", admin), runner_id: unused_specific_runner.id
end.to change{ project.runners.count }.by(+1) end.to change{ project.runners.count }.by(+1)
expect(response.status).to eq(201) expect(response).to have_http_status(201)
end end
end end
...@@ -411,14 +411,14 @@ describe API::Runners, api: true do ...@@ -411,14 +411,14 @@ describe API::Runners, api: true do
it 'should not enable runner without access to' do it 'should not enable runner without access to' do
post api("/projects/#{project.id}/runners", user), runner_id: unused_specific_runner.id post api("/projects/#{project.id}/runners", user), runner_id: unused_specific_runner.id
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
end end
it 'should raise an error when no runner_id param is provided' do it 'should raise an error when no runner_id param is provided' do
post api("/projects/#{project.id}/runners", admin) post api("/projects/#{project.id}/runners", admin)
expect(response.status).to eq(400) expect(response).to have_http_status(400)
end end
end end
...@@ -426,7 +426,7 @@ describe API::Runners, api: true do ...@@ -426,7 +426,7 @@ describe API::Runners, api: true do
it 'should not enable runner' do it 'should not enable runner' do
post api("/projects/#{project.id}/runners", user2) post api("/projects/#{project.id}/runners", user2)
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
end end
...@@ -434,7 +434,7 @@ describe API::Runners, api: true do ...@@ -434,7 +434,7 @@ describe API::Runners, api: true do
it 'should not enable runner' do it 'should not enable runner' do
post api("/projects/#{project.id}/runners") post api("/projects/#{project.id}/runners")
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
end end
...@@ -446,7 +446,7 @@ describe API::Runners, api: true do ...@@ -446,7 +446,7 @@ describe API::Runners, api: true do
expect do expect do
delete api("/projects/#{project.id}/runners/#{two_projects_runner.id}", user) delete api("/projects/#{project.id}/runners/#{two_projects_runner.id}", user)
end.to change{ project.runners.count }.by(-1) end.to change{ project.runners.count }.by(-1)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
end end
...@@ -455,14 +455,14 @@ describe API::Runners, api: true do ...@@ -455,14 +455,14 @@ describe API::Runners, api: true do
expect do expect do
delete api("/projects/#{project.id}/runners/#{specific_runner.id}", user) delete api("/projects/#{project.id}/runners/#{specific_runner.id}", user)
end.to change{ project.runners.count }.by(0) end.to change{ project.runners.count }.by(0)
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
end end
it 'should return 404 is runner is not found' do it 'should return 404 is runner is not found' do
delete api("/projects/#{project.id}/runners/9999", user) delete api("/projects/#{project.id}/runners/9999", user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
...@@ -470,7 +470,7 @@ describe API::Runners, api: true do ...@@ -470,7 +470,7 @@ describe API::Runners, api: true do
it "should not disable project's runner" do it "should not disable project's runner" do
delete api("/projects/#{project.id}/runners/#{specific_runner.id}", user2) delete api("/projects/#{project.id}/runners/#{specific_runner.id}", user2)
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
end end
...@@ -478,7 +478,7 @@ describe API::Runners, api: true do ...@@ -478,7 +478,7 @@ describe API::Runners, api: true do
it "should not disable project's runner" do it "should not disable project's runner" do
delete api("/projects/#{project.id}/runners/#{specific_runner.id}") delete api("/projects/#{project.id}/runners/#{specific_runner.id}")
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
end end
......
...@@ -14,7 +14,7 @@ describe API::API, api: true do ...@@ -14,7 +14,7 @@ describe API::API, api: true do
it "should update #{service} settings" do it "should update #{service} settings" do
put api("/projects/#{project.id}/services/#{dashed_service}", user), service_attrs put api("/projects/#{project.id}/services/#{dashed_service}", user), service_attrs
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
it "should return if required fields missing" do it "should return if required fields missing" do
...@@ -45,7 +45,7 @@ describe API::API, api: true do ...@@ -45,7 +45,7 @@ describe API::API, api: true do
it "should delete #{service}" do it "should delete #{service}" do
delete api("/projects/#{project.id}/services/#{dashed_service}", user) delete api("/projects/#{project.id}/services/#{dashed_service}", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
project.send(service_method).reload project.send(service_method).reload
expect(project.send(service_method).activated?).to be_falsey expect(project.send(service_method).activated?).to be_falsey
end end
...@@ -64,20 +64,20 @@ describe API::API, api: true do ...@@ -64,20 +64,20 @@ describe API::API, api: true do
it 'should return authentication error when unauthenticated' do it 'should return authentication error when unauthenticated' do
get api("/projects/#{project.id}/services/#{dashed_service}") get api("/projects/#{project.id}/services/#{dashed_service}")
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
it "should return all properties of service #{service} when authenticated as admin" do it "should return all properties of service #{service} when authenticated as admin" do
get api("/projects/#{project.id}/services/#{dashed_service}", admin) get api("/projects/#{project.id}/services/#{dashed_service}", admin)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['properties'].keys.map(&:to_sym)).to match_array(service_attrs_list.map) expect(json_response['properties'].keys.map(&:to_sym)).to match_array(service_attrs_list.map)
end end
it "should return properties of service #{service} other than passwords when authenticated as project owner" do it "should return properties of service #{service} other than passwords when authenticated as project owner" do
get api("/projects/#{project.id}/services/#{dashed_service}", user) get api("/projects/#{project.id}/services/#{dashed_service}", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['properties'].keys.map(&:to_sym)).to match_array(service_attrs_list_without_passwords) expect(json_response['properties'].keys.map(&:to_sym)).to match_array(service_attrs_list_without_passwords)
end end
...@@ -85,7 +85,7 @@ describe API::API, api: true do ...@@ -85,7 +85,7 @@ describe API::API, api: true do
project.team << [user2, :developer] project.team << [user2, :developer]
get api("/projects/#{project.id}/services/#{dashed_service}", user2) get api("/projects/#{project.id}/services/#{dashed_service}", user2)
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
end end
......
...@@ -9,7 +9,7 @@ describe API::API, api: true do ...@@ -9,7 +9,7 @@ describe API::API, api: true do
context "when valid password" do context "when valid password" do
it "should return private token" do it "should return private token" do
post api("/session"), email: user.email, password: '12345678' post api("/session"), email: user.email, password: '12345678'
expect(response.status).to eq(201) expect(response).to have_http_status(201)
expect(json_response['email']).to eq(user.email) expect(json_response['email']).to eq(user.email)
expect(json_response['private_token']).to eq(user.private_token) expect(json_response['private_token']).to eq(user.private_token)
...@@ -48,7 +48,7 @@ describe API::API, api: true do ...@@ -48,7 +48,7 @@ describe API::API, api: true do
context "when invalid password" do context "when invalid password" do
it "should return authentication error" do it "should return authentication error" do
post api("/session"), email: user.email, password: '123' post api("/session"), email: user.email, password: '123'
expect(response.status).to eq(401) expect(response).to have_http_status(401)
expect(json_response['email']).to be_nil expect(json_response['email']).to be_nil
expect(json_response['private_token']).to be_nil expect(json_response['private_token']).to be_nil
...@@ -58,7 +58,7 @@ describe API::API, api: true do ...@@ -58,7 +58,7 @@ describe API::API, api: true do
context "when empty password" do context "when empty password" do
it "should return authentication error" do it "should return authentication error" do
post api("/session"), email: user.email post api("/session"), email: user.email
expect(response.status).to eq(401) expect(response).to have_http_status(401)
expect(json_response['email']).to be_nil expect(json_response['email']).to be_nil
expect(json_response['private_token']).to be_nil expect(json_response['private_token']).to be_nil
...@@ -68,7 +68,7 @@ describe API::API, api: true do ...@@ -68,7 +68,7 @@ describe API::API, api: true do
context "when empty name" do context "when empty name" do
it "should return authentication error" do it "should return authentication error" do
post api("/session"), password: user.password post api("/session"), password: user.password
expect(response.status).to eq(401) expect(response).to have_http_status(401)
expect(json_response['email']).to be_nil expect(json_response['email']).to be_nil
expect(json_response['private_token']).to be_nil expect(json_response['private_token']).to be_nil
......
...@@ -10,7 +10,7 @@ describe API::API, 'Settings', api: true do ...@@ -10,7 +10,7 @@ describe API::API, 'Settings', api: true do
describe "GET /application/settings" do describe "GET /application/settings" do
it "should return application settings" do it "should return application settings" do
get api("/application/settings", admin) get api("/application/settings", admin)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Hash expect(json_response).to be_an Hash
expect(json_response['default_projects_limit']).to eq(42) expect(json_response['default_projects_limit']).to eq(42)
expect(json_response['signin_enabled']).to be_truthy expect(json_response['signin_enabled']).to be_truthy
...@@ -21,7 +21,7 @@ describe API::API, 'Settings', api: true do ...@@ -21,7 +21,7 @@ describe API::API, 'Settings', api: true do
it "should update application settings" do it "should update application settings" do
put api("/application/settings", admin), put api("/application/settings", admin),
default_projects_limit: 3, signin_enabled: false default_projects_limit: 3, signin_enabled: false
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['default_projects_limit']).to eq(3) expect(json_response['default_projects_limit']).to eq(3)
expect(json_response['signin_enabled']).to be_falsey expect(json_response['signin_enabled']).to be_falsey
end end
......
...@@ -9,28 +9,28 @@ describe API::SidekiqMetrics, api: true do ...@@ -9,28 +9,28 @@ describe API::SidekiqMetrics, api: true do
it 'defines the `queue_metrics` endpoint' do it 'defines the `queue_metrics` endpoint' do
get api('/sidekiq/queue_metrics', admin) get api('/sidekiq/queue_metrics', admin)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_a Hash expect(json_response).to be_a Hash
end end
it 'defines the `process_metrics` endpoint' do it 'defines the `process_metrics` endpoint' do
get api('/sidekiq/process_metrics', admin) get api('/sidekiq/process_metrics', admin)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['processes']).to be_an Array expect(json_response['processes']).to be_an Array
end end
it 'defines the `job_stats` endpoint' do it 'defines the `job_stats` endpoint' do
get api('/sidekiq/job_stats', admin) get api('/sidekiq/job_stats', admin)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_a Hash expect(json_response).to be_a Hash
end end
it 'defines the `compound_metrics` endpoint' do it 'defines the `compound_metrics` endpoint' do
get api('/sidekiq/compound_metrics', admin) get api('/sidekiq/compound_metrics', admin)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_a Hash expect(json_response).to be_a Hash
expect(json_response['queues']).to be_a Hash expect(json_response['queues']).to be_a Hash
expect(json_response['processes']).to be_an Array expect(json_response['processes']).to be_an Array
......
...@@ -13,21 +13,21 @@ describe API::API, api: true do ...@@ -13,21 +13,21 @@ describe API::API, api: true do
context "when no user" do context "when no user" do
it "should return authentication error" do it "should return authentication error" do
get api("/hooks") get api("/hooks")
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
context "when not an admin" do context "when not an admin" do
it "should return forbidden error" do it "should return forbidden error" do
get api("/hooks", user) get api("/hooks", user)
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
end end
context "when authenticated as admin" do context "when authenticated as admin" do
it "should return an array of hooks" do it "should return an array of hooks" do
get api("/hooks", admin) get api("/hooks", admin)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first['url']).to eq(hook.url) expect(json_response.first['url']).to eq(hook.url)
end end
...@@ -43,7 +43,7 @@ describe API::API, api: true do ...@@ -43,7 +43,7 @@ describe API::API, api: true do
it "should respond with 400 if url not given" do it "should respond with 400 if url not given" do
post api("/hooks", admin) post api("/hooks", admin)
expect(response.status).to eq(400) expect(response).to have_http_status(400)
end end
it "should not create new hook without url" do it "should not create new hook without url" do
...@@ -56,13 +56,13 @@ describe API::API, api: true do ...@@ -56,13 +56,13 @@ describe API::API, api: true do
describe "GET /hooks/:id" do describe "GET /hooks/:id" do
it "should return hook by id" do it "should return hook by id" do
get api("/hooks/#{hook.id}", admin) get api("/hooks/#{hook.id}", admin)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['event_name']).to eq('project_create') expect(json_response['event_name']).to eq('project_create')
end end
it "should return 404 on failure" do it "should return 404 on failure" do
get api("/hooks/404", admin) get api("/hooks/404", admin)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
...@@ -75,7 +75,7 @@ describe API::API, api: true do ...@@ -75,7 +75,7 @@ describe API::API, api: true do
it "should return success if hook id not found" do it "should return success if hook id not found" do
delete api("/hooks/12345", admin) delete api("/hooks/12345", admin)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
end end
end end
...@@ -18,7 +18,7 @@ describe API::API, api: true do ...@@ -18,7 +18,7 @@ describe API::API, api: true do
context 'without releases' do context 'without releases' do
it "should return an array of project tags" do it "should return an array of project tags" do
get api("/projects/#{project.id}/repository/tags", user) get api("/projects/#{project.id}/repository/tags", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first['name']).to eq(tag_name) expect(json_response.first['name']).to eq(tag_name)
end end
...@@ -33,7 +33,7 @@ describe API::API, api: true do ...@@ -33,7 +33,7 @@ describe API::API, api: true do
it "should return an array of project tags with release info" do it "should return an array of project tags with release info" do
get api("/projects/#{project.id}/repository/tags", user) get api("/projects/#{project.id}/repository/tags", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first['name']).to eq(tag_name) expect(json_response.first['name']).to eq(tag_name)
expect(json_response.first['message']).to eq('Version 1.1.0') expect(json_response.first['message']).to eq('Version 1.1.0')
...@@ -48,14 +48,14 @@ describe API::API, api: true do ...@@ -48,14 +48,14 @@ describe API::API, api: true do
it 'returns a specific tag' do it 'returns a specific tag' do
get api("/projects/#{project.id}/repository/tags/#{tag_name}", user) get api("/projects/#{project.id}/repository/tags/#{tag_name}", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['name']).to eq(tag_name) expect(json_response['name']).to eq(tag_name)
end end
it 'returns 404 for an invalid tag name' do it 'returns 404 for an invalid tag name' do
get api("/projects/#{project.id}/repository/tags/foobar", user) get api("/projects/#{project.id}/repository/tags/foobar", user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
...@@ -66,7 +66,7 @@ describe API::API, api: true do ...@@ -66,7 +66,7 @@ describe API::API, api: true do
tag_name: 'v7.0.1', tag_name: 'v7.0.1',
ref: 'master' ref: 'master'
expect(response.status).to eq(201) expect(response).to have_http_status(201)
expect(json_response['name']).to eq('v7.0.1') expect(json_response['name']).to eq('v7.0.1')
end end
end end
...@@ -78,7 +78,7 @@ describe API::API, api: true do ...@@ -78,7 +78,7 @@ describe API::API, api: true do
ref: 'master', ref: 'master',
release_description: 'Wow' release_description: 'Wow'
expect(response.status).to eq(201) expect(response).to have_http_status(201)
expect(json_response['name']).to eq('v7.0.1') expect(json_response['name']).to eq('v7.0.1')
expect(json_response['release']['description']).to eq('Wow') expect(json_response['release']['description']).to eq('Wow')
end end
...@@ -94,13 +94,13 @@ describe API::API, api: true do ...@@ -94,13 +94,13 @@ describe API::API, api: true do
context 'delete tag' do context 'delete tag' do
it 'should delete an existing tag' do it 'should delete an existing tag' do
delete api("/projects/#{project.id}/repository/tags/#{tag_name}", user) delete api("/projects/#{project.id}/repository/tags/#{tag_name}", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['tag_name']).to eq(tag_name) expect(json_response['tag_name']).to eq(tag_name)
end end
it 'should raise 404 if the tag does not exist' do it 'should raise 404 if the tag does not exist' do
delete api("/projects/#{project.id}/repository/tags/foobar", user) delete api("/projects/#{project.id}/repository/tags/foobar", user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
end end
...@@ -117,7 +117,7 @@ describe API::API, api: true do ...@@ -117,7 +117,7 @@ describe API::API, api: true do
ref: 'master', ref: 'master',
message: 'Release 7.1.0' message: 'Release 7.1.0'
expect(response.status).to eq(201) expect(response).to have_http_status(201)
expect(json_response['name']).to eq('v7.1.0') expect(json_response['name']).to eq('v7.1.0')
expect(json_response['message']).to eq('Release 7.1.0') expect(json_response['message']).to eq('Release 7.1.0')
end end
...@@ -127,14 +127,14 @@ describe API::API, api: true do ...@@ -127,14 +127,14 @@ describe API::API, api: true do
post api("/projects/#{project.id}/repository/tags", user2), post api("/projects/#{project.id}/repository/tags", user2),
tag_name: 'v1.9.0', tag_name: 'v1.9.0',
ref: '621491c677087aa243f165eab467bfdfbee00be1' ref: '621491c677087aa243f165eab467bfdfbee00be1'
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
it 'should return 400 if tag name is invalid' do it 'should return 400 if tag name is invalid' do
post api("/projects/#{project.id}/repository/tags", user), post api("/projects/#{project.id}/repository/tags", user),
tag_name: 'v 1.0.0', tag_name: 'v 1.0.0',
ref: 'master' ref: 'master'
expect(response.status).to eq(400) expect(response).to have_http_status(400)
expect(json_response['message']).to eq('Tag name invalid') expect(json_response['message']).to eq('Tag name invalid')
end end
...@@ -142,11 +142,11 @@ describe API::API, api: true do ...@@ -142,11 +142,11 @@ describe API::API, api: true do
post api("/projects/#{project.id}/repository/tags", user), post api("/projects/#{project.id}/repository/tags", user),
tag_name: 'v8.0.0', tag_name: 'v8.0.0',
ref: 'master' ref: 'master'
expect(response.status).to eq(201) expect(response).to have_http_status(201)
post api("/projects/#{project.id}/repository/tags", user), post api("/projects/#{project.id}/repository/tags", user),
tag_name: 'v8.0.0', tag_name: 'v8.0.0',
ref: 'master' ref: 'master'
expect(response.status).to eq(400) expect(response).to have_http_status(400)
expect(json_response['message']).to eq('Tag v8.0.0 already exists') expect(json_response['message']).to eq('Tag v8.0.0 already exists')
end end
...@@ -154,7 +154,7 @@ describe API::API, api: true do ...@@ -154,7 +154,7 @@ describe API::API, api: true do
post api("/projects/#{project.id}/repository/tags", user), post api("/projects/#{project.id}/repository/tags", user),
tag_name: 'mytag', tag_name: 'mytag',
ref: 'foo' ref: 'foo'
expect(response.status).to eq(400) expect(response).to have_http_status(400)
expect(json_response['message']).to eq('Target foo is invalid') expect(json_response['message']).to eq('Target foo is invalid')
end end
end end
...@@ -167,7 +167,7 @@ describe API::API, api: true do ...@@ -167,7 +167,7 @@ describe API::API, api: true do
post api("/projects/#{project.id}/repository/tags/#{tag_name}/release", user), post api("/projects/#{project.id}/repository/tags/#{tag_name}/release", user),
description: description description: description
expect(response.status).to eq(201) expect(response).to have_http_status(201)
expect(json_response['tag_name']).to eq(tag_name) expect(json_response['tag_name']).to eq(tag_name)
expect(json_response['description']).to eq(description) expect(json_response['description']).to eq(description)
end end
...@@ -176,7 +176,7 @@ describe API::API, api: true do ...@@ -176,7 +176,7 @@ describe API::API, api: true do
post api("/projects/#{project.id}/repository/tags/foobar/release", user), post api("/projects/#{project.id}/repository/tags/foobar/release", user),
description: description description: description
expect(response.status).to eq(404) expect(response).to have_http_status(404)
expect(json_response['message']).to eq('Tag does not exist') expect(json_response['message']).to eq('Tag does not exist')
end end
...@@ -190,7 +190,7 @@ describe API::API, api: true do ...@@ -190,7 +190,7 @@ describe API::API, api: true do
post api("/projects/#{project.id}/repository/tags/#{tag_name}/release", user), post api("/projects/#{project.id}/repository/tags/#{tag_name}/release", user),
description: description description: description
expect(response.status).to eq(409) expect(response).to have_http_status(409)
expect(json_response['message']).to eq('Release already exists') expect(json_response['message']).to eq('Release already exists')
end end
end end
...@@ -211,7 +211,7 @@ describe API::API, api: true do ...@@ -211,7 +211,7 @@ describe API::API, api: true do
put api("/projects/#{project.id}/repository/tags/#{tag_name}/release", user), put api("/projects/#{project.id}/repository/tags/#{tag_name}/release", user),
description: new_description description: new_description
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['tag_name']).to eq(tag_name) expect(json_response['tag_name']).to eq(tag_name)
expect(json_response['description']).to eq(new_description) expect(json_response['description']).to eq(new_description)
end end
...@@ -221,7 +221,7 @@ describe API::API, api: true do ...@@ -221,7 +221,7 @@ describe API::API, api: true do
put api("/projects/#{project.id}/repository/tags/foobar/release", user), put api("/projects/#{project.id}/repository/tags/foobar/release", user),
description: new_description description: new_description
expect(response.status).to eq(404) expect(response).to have_http_status(404)
expect(json_response['message']).to eq('Tag does not exist') expect(json_response['message']).to eq('Tag does not exist')
end end
...@@ -229,7 +229,7 @@ describe API::API, api: true do ...@@ -229,7 +229,7 @@ describe API::API, api: true do
put api("/projects/#{project.id}/repository/tags/#{tag_name}/release", user), put api("/projects/#{project.id}/repository/tags/#{tag_name}/release", user),
description: new_description description: new_description
expect(response.status).to eq(404) expect(response).to have_http_status(404)
expect(json_response['message']).to eq('Release does not exist') expect(json_response['message']).to eq('Release does not exist')
end end
end end
......
...@@ -22,7 +22,7 @@ describe API::Templates, api: true do ...@@ -22,7 +22,7 @@ describe API::Templates, api: true do
it 'returns a list of available gitignore templates' do it 'returns a list of available gitignore templates' do
get api('/gitignores') get api('/gitignores')
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.size).to be > 15 expect(json_response.size).to be > 15
end end
...@@ -34,7 +34,7 @@ describe API::Templates, api: true do ...@@ -34,7 +34,7 @@ describe API::Templates, api: true do
it 'returns a list of available gitlab_ci_ymls' do it 'returns a list of available gitlab_ci_ymls' do
get api('/gitlab_ci_ymls') get api('/gitlab_ci_ymls')
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first['name']).not_to be_nil expect(json_response.first['name']).not_to be_nil
end end
...@@ -45,7 +45,7 @@ describe API::Templates, api: true do ...@@ -45,7 +45,7 @@ describe API::Templates, api: true do
it 'adds a disclaimer on the top' do it 'adds a disclaimer on the top' do
get api('/gitlab_ci_ymls/Ruby') get api('/gitlab_ci_ymls/Ruby')
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['content']).to start_with("# This file is a template,") expect(json_response['content']).to start_with("# This file is a template,")
end end
end end
......
...@@ -29,17 +29,17 @@ describe API::API do ...@@ -29,17 +29,17 @@ describe API::API do
context 'Handles errors' do context 'Handles errors' do
it 'should return bad request if token is missing' do it 'should return bad request if token is missing' do
post api("/projects/#{project.id}/trigger/builds"), ref: 'master' post api("/projects/#{project.id}/trigger/builds"), ref: 'master'
expect(response.status).to eq(400) expect(response).to have_http_status(400)
end end
it 'should return not found if project is not found' do it 'should return not found if project is not found' do
post api('/projects/0/trigger/builds'), options.merge(ref: 'master') post api('/projects/0/trigger/builds'), options.merge(ref: 'master')
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
it 'should return unauthorized if token is for different project' do it 'should return unauthorized if token is for different project' do
post api("/projects/#{project2.id}/trigger/builds"), options.merge(ref: 'master') post api("/projects/#{project2.id}/trigger/builds"), options.merge(ref: 'master')
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
...@@ -48,14 +48,14 @@ describe API::API do ...@@ -48,14 +48,14 @@ describe API::API do
it 'should create builds' do it 'should create builds' do
post api("/projects/#{project.id}/trigger/builds"), options.merge(ref: 'master') post api("/projects/#{project.id}/trigger/builds"), options.merge(ref: 'master')
expect(response.status).to eq(201) expect(response).to have_http_status(201)
pipeline.builds.reload pipeline.builds.reload
expect(pipeline.builds.size).to eq(2) expect(pipeline.builds.size).to eq(2)
end end
it 'should return bad request with no builds created if there\'s no commit for that ref' do it 'should return bad request with no builds created if there\'s no commit for that ref' do
post api("/projects/#{project.id}/trigger/builds"), options.merge(ref: 'other-branch') post api("/projects/#{project.id}/trigger/builds"), options.merge(ref: 'other-branch')
expect(response.status).to eq(400) expect(response).to have_http_status(400)
expect(json_response['message']).to eq('No builds created') expect(json_response['message']).to eq('No builds created')
end end
...@@ -66,19 +66,19 @@ describe API::API do ...@@ -66,19 +66,19 @@ describe API::API do
it 'should validate variables to be a hash' do it 'should validate variables to be a hash' do
post api("/projects/#{project.id}/trigger/builds"), options.merge(variables: 'value', ref: 'master') post api("/projects/#{project.id}/trigger/builds"), options.merge(variables: 'value', ref: 'master')
expect(response.status).to eq(400) expect(response).to have_http_status(400)
expect(json_response['message']).to eq('variables needs to be a hash') expect(json_response['message']).to eq('variables needs to be a hash')
end end
it 'should validate variables needs to be a map of key-valued strings' do it 'should validate variables needs to be a map of key-valued strings' do
post api("/projects/#{project.id}/trigger/builds"), options.merge(variables: { key: %w(1 2) }, ref: 'master') post api("/projects/#{project.id}/trigger/builds"), options.merge(variables: { key: %w(1 2) }, ref: 'master')
expect(response.status).to eq(400) expect(response).to have_http_status(400)
expect(json_response['message']).to eq('variables needs to be a map of key-valued strings') expect(json_response['message']).to eq('variables needs to be a map of key-valued strings')
end end
it 'create trigger request with variables' do it 'create trigger request with variables' do
post api("/projects/#{project.id}/trigger/builds"), options.merge(variables: variables, ref: 'master') post api("/projects/#{project.id}/trigger/builds"), options.merge(variables: variables, ref: 'master')
expect(response.status).to eq(201) expect(response).to have_http_status(201)
pipeline.builds.reload pipeline.builds.reload
expect(pipeline.builds.first.trigger_request.variables).to eq(variables) expect(pipeline.builds.first.trigger_request.variables).to eq(variables)
end end
...@@ -91,7 +91,7 @@ describe API::API do ...@@ -91,7 +91,7 @@ describe API::API do
it 'should return list of triggers' do it 'should return list of triggers' do
get api("/projects/#{project.id}/triggers", user) get api("/projects/#{project.id}/triggers", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_a(Array) expect(json_response).to be_a(Array)
expect(json_response[0]).to have_key('token') expect(json_response[0]).to have_key('token')
end end
...@@ -101,7 +101,7 @@ describe API::API do ...@@ -101,7 +101,7 @@ describe API::API do
it 'should not return triggers list' do it 'should not return triggers list' do
get api("/projects/#{project.id}/triggers", user2) get api("/projects/#{project.id}/triggers", user2)
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
end end
...@@ -109,7 +109,7 @@ describe API::API do ...@@ -109,7 +109,7 @@ describe API::API do
it 'should not return triggers list' do it 'should not return triggers list' do
get api("/projects/#{project.id}/triggers") get api("/projects/#{project.id}/triggers")
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
end end
...@@ -119,14 +119,14 @@ describe API::API do ...@@ -119,14 +119,14 @@ describe API::API do
it 'should return trigger details' do it 'should return trigger details' do
get api("/projects/#{project.id}/triggers/#{trigger.token}", user) get api("/projects/#{project.id}/triggers/#{trigger.token}", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_a(Hash) expect(json_response).to be_a(Hash)
end end
it 'should respond with 404 Not Found if requesting non-existing trigger' do it 'should respond with 404 Not Found if requesting non-existing trigger' do
get api("/projects/#{project.id}/triggers/abcdef012345", user) get api("/projects/#{project.id}/triggers/abcdef012345", user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
...@@ -134,7 +134,7 @@ describe API::API do ...@@ -134,7 +134,7 @@ describe API::API do
it 'should not return triggers list' do it 'should not return triggers list' do
get api("/projects/#{project.id}/triggers/#{trigger.token}", user2) get api("/projects/#{project.id}/triggers/#{trigger.token}", user2)
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
end end
...@@ -142,7 +142,7 @@ describe API::API do ...@@ -142,7 +142,7 @@ describe API::API do
it 'should not return triggers list' do it 'should not return triggers list' do
get api("/projects/#{project.id}/triggers/#{trigger.token}") get api("/projects/#{project.id}/triggers/#{trigger.token}")
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
end end
...@@ -154,7 +154,7 @@ describe API::API do ...@@ -154,7 +154,7 @@ describe API::API do
post api("/projects/#{project.id}/triggers", user) post api("/projects/#{project.id}/triggers", user)
end.to change{project.triggers.count}.by(1) end.to change{project.triggers.count}.by(1)
expect(response.status).to eq(201) expect(response).to have_http_status(201)
expect(json_response).to be_a(Hash) expect(json_response).to be_a(Hash)
end end
end end
...@@ -163,7 +163,7 @@ describe API::API do ...@@ -163,7 +163,7 @@ describe API::API do
it 'should not create trigger' do it 'should not create trigger' do
post api("/projects/#{project.id}/triggers", user2) post api("/projects/#{project.id}/triggers", user2)
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
end end
...@@ -171,7 +171,7 @@ describe API::API do ...@@ -171,7 +171,7 @@ describe API::API do
it 'should not create trigger' do it 'should not create trigger' do
post api("/projects/#{project.id}/triggers") post api("/projects/#{project.id}/triggers")
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
end end
...@@ -182,13 +182,13 @@ describe API::API do ...@@ -182,13 +182,13 @@ describe API::API do
expect do expect do
delete api("/projects/#{project.id}/triggers/#{trigger.token}", user) delete api("/projects/#{project.id}/triggers/#{trigger.token}", user)
end.to change{project.triggers.count}.by(-1) end.to change{project.triggers.count}.by(-1)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
it 'should respond with 404 Not Found if requesting non-existing trigger' do it 'should respond with 404 Not Found if requesting non-existing trigger' do
delete api("/projects/#{project.id}/triggers/abcdef012345", user) delete api("/projects/#{project.id}/triggers/abcdef012345", user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
...@@ -196,7 +196,7 @@ describe API::API do ...@@ -196,7 +196,7 @@ describe API::API do
it 'should not delete trigger' do it 'should not delete trigger' do
delete api("/projects/#{project.id}/triggers/#{trigger.token}", user2) delete api("/projects/#{project.id}/triggers/#{trigger.token}", user2)
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
end end
...@@ -204,7 +204,7 @@ describe API::API do ...@@ -204,7 +204,7 @@ describe API::API do
it 'should not delete trigger' do it 'should not delete trigger' do
delete api("/projects/#{project.id}/triggers/#{trigger.token}") delete api("/projects/#{project.id}/triggers/#{trigger.token}")
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
end end
......
...@@ -15,7 +15,7 @@ describe API::API, api: true do ...@@ -15,7 +15,7 @@ describe API::API, api: true do
context "when unauthenticated" do context "when unauthenticated" do
it "should return authentication error" do it "should return authentication error" do
get api("/users") get api("/users")
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
...@@ -29,18 +29,18 @@ describe API::API, api: true do ...@@ -29,18 +29,18 @@ describe API::API, api: true do
it "renders 403" do it "renders 403" do
get api("/users") get api("/users")
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
it "renders 404" do it "renders 404" do
get api("/users/#{user.id}") get api("/users/#{user.id}")
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
it "should return an array of users" do it "should return an array of users" do
get api("/users", user) get api("/users", user)
expect(response.status).to eq(200) expect(response).to have_http_status(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 do |user| expect(json_response.detect do |user|
...@@ -50,7 +50,7 @@ describe API::API, api: true do ...@@ -50,7 +50,7 @@ describe API::API, api: true do
it "should return one user" do it "should return one user" do
get api("/users?username=#{omniauth_user.username}", user) get api("/users?username=#{omniauth_user.username}", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first['username']).to eq(omniauth_user.username) expect(json_response.first['username']).to eq(omniauth_user.username)
end end
...@@ -59,7 +59,7 @@ describe API::API, api: true do ...@@ -59,7 +59,7 @@ describe API::API, api: true do
context "when admin" do context "when admin" do
it "should return an array of users" do it "should return an array of users" do
get api("/users", admin) get api("/users", admin)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first.keys).to include 'email' expect(json_response.first.keys).to include 'email'
expect(json_response.first.keys).to include 'identities' expect(json_response.first.keys).to include 'identities'
...@@ -74,24 +74,24 @@ describe API::API, api: true do ...@@ -74,24 +74,24 @@ describe API::API, api: true do
describe "GET /users/:id" do describe "GET /users/:id" do
it "should return a user by id" do it "should return a user by id" do
get api("/users/#{user.id}", user) get api("/users/#{user.id}", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['username']).to eq(user.username) expect(json_response['username']).to eq(user.username)
end end
it "should return a 401 if unauthenticated" do it "should return a 401 if unauthenticated" do
get api("/users/9998") get api("/users/9998")
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
it "should return a 404 error if user id not found" do it "should return a 404 error if user id not found" do
get api("/users/9999", user) get api("/users/9999", user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
expect(json_response['message']).to eq('404 Not found') expect(json_response['message']).to eq('404 Not found')
end end
it "should return a 404 if invalid ID" do it "should return a 404 if invalid ID" do
get api("/users/1ASDF", user) get api("/users/1ASDF", user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
...@@ -106,7 +106,7 @@ describe API::API, api: true do ...@@ -106,7 +106,7 @@ describe API::API, api: true do
it "should create user with correct attributes" do it "should create user with correct attributes" do
post api('/users', admin), attributes_for(:user, admin: true, can_create_group: true) post api('/users', admin), attributes_for(:user, admin: true, can_create_group: true)
expect(response.status).to eq(201) expect(response).to have_http_status(201)
user_id = json_response['id'] user_id = json_response['id']
new_user = User.find(user_id) new_user = User.find(user_id)
expect(new_user).not_to eq(nil) expect(new_user).not_to eq(nil)
...@@ -116,7 +116,7 @@ describe API::API, api: true do ...@@ -116,7 +116,7 @@ describe API::API, api: true do
it "should create non-admin user" do it "should create non-admin user" do
post api('/users', admin), attributes_for(:user, admin: false, can_create_group: false) post api('/users', admin), attributes_for(:user, admin: false, can_create_group: false)
expect(response.status).to eq(201) expect(response).to have_http_status(201)
user_id = json_response['id'] user_id = json_response['id']
new_user = User.find(user_id) new_user = User.find(user_id)
expect(new_user).not_to eq(nil) expect(new_user).not_to eq(nil)
...@@ -126,7 +126,7 @@ describe API::API, api: true do ...@@ -126,7 +126,7 @@ describe API::API, api: true do
it "should create non-admin users by default" do it "should create non-admin users by default" do
post api('/users', admin), attributes_for(:user) post api('/users', admin), attributes_for(:user)
expect(response.status).to eq(201) expect(response).to have_http_status(201)
user_id = json_response['id'] user_id = json_response['id']
new_user = User.find(user_id) new_user = User.find(user_id)
expect(new_user).not_to eq(nil) expect(new_user).not_to eq(nil)
...@@ -135,12 +135,12 @@ describe API::API, api: true do ...@@ -135,12 +135,12 @@ describe API::API, api: true do
it "should return 201 Created on success" do it "should return 201 Created on success" do
post api("/users", admin), attributes_for(:user, projects_limit: 3) post api("/users", admin), attributes_for(:user, projects_limit: 3)
expect(response.status).to eq(201) expect(response).to have_http_status(201)
end end
it 'creates non-external users by default' do it 'creates non-external users by default' do
post api("/users", admin), attributes_for(:user) post api("/users", admin), attributes_for(:user)
expect(response.status).to eq(201) expect(response).to have_http_status(201)
user_id = json_response['id'] user_id = json_response['id']
new_user = User.find(user_id) new_user = User.find(user_id)
...@@ -150,7 +150,7 @@ describe API::API, api: true do ...@@ -150,7 +150,7 @@ describe API::API, api: true do
it 'should allow an external user to be created' do it 'should allow an external user to be created' do
post api("/users", admin), attributes_for(:user, external: true) post api("/users", admin), attributes_for(:user, external: true)
expect(response.status).to eq(201) expect(response).to have_http_status(201)
user_id = json_response['id'] user_id = json_response['id']
new_user = User.find(user_id) new_user = User.find(user_id)
...@@ -163,27 +163,27 @@ describe API::API, api: true do ...@@ -163,27 +163,27 @@ describe API::API, api: true do
email: 'invalid email', email: 'invalid email',
password: 'password', password: 'password',
name: 'test' name: 'test'
expect(response.status).to eq(400) expect(response).to have_http_status(400)
end end
it 'should return 400 error if name not given' do it 'should return 400 error if name not given' do
post api('/users', admin), attributes_for(:user).except(:name) post api('/users', admin), attributes_for(:user).except(:name)
expect(response.status).to eq(400) expect(response).to have_http_status(400)
end end
it 'should return 400 error if password not given' do it 'should return 400 error if password not given' do
post api('/users', admin), attributes_for(:user).except(:password) post api('/users', admin), attributes_for(:user).except(:password)
expect(response.status).to eq(400) expect(response).to have_http_status(400)
end end
it 'should return 400 error if email not given' do it 'should return 400 error if email not given' do
post api('/users', admin), attributes_for(:user).except(:email) post api('/users', admin), attributes_for(:user).except(:email)
expect(response.status).to eq(400) expect(response).to have_http_status(400)
end end
it 'should return 400 error if username not given' do it 'should return 400 error if username not given' do
post api('/users', admin), attributes_for(:user).except(:username) post api('/users', admin), attributes_for(:user).except(:username)
expect(response.status).to eq(400) expect(response).to have_http_status(400)
end end
it 'should return 400 error if user does not validate' do it 'should return 400 error if user does not validate' do
...@@ -194,7 +194,7 @@ describe API::API, api: true do ...@@ -194,7 +194,7 @@ describe API::API, api: true do
name: 'test', name: 'test',
bio: 'g' * 256, bio: 'g' * 256,
projects_limit: -1 projects_limit: -1
expect(response.status).to eq(400) expect(response).to have_http_status(400)
expect(json_response['message']['password']). 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']). expect(json_response['message']['bio']).
...@@ -207,7 +207,7 @@ describe API::API, api: true do ...@@ -207,7 +207,7 @@ describe API::API, api: true do
it "shouldn't available for non admin users" do it "shouldn't available for non admin users" do
post api("/users", user), attributes_for(:user) post api("/users", user), attributes_for(:user)
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
context 'with existing user' do context 'with existing user' do
...@@ -227,7 +227,7 @@ describe API::API, api: true do ...@@ -227,7 +227,7 @@ describe API::API, api: true do
password: 'password', password: 'password',
username: 'foo' username: 'foo'
end.to change { User.count }.by(0) end.to change { User.count }.by(0)
expect(response.status).to eq(409) expect(response).to have_http_status(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
...@@ -239,7 +239,7 @@ describe API::API, api: true do ...@@ -239,7 +239,7 @@ describe API::API, api: true do
password: 'password', password: 'password',
username: 'test' username: 'test'
end.to change { User.count }.by(0) end.to change { User.count }.by(0)
expect(response.status).to eq(409) expect(response).to have_http_status(409)
expect(json_response['message']).to eq('Username has already been taken') expect(json_response['message']).to eq('Username has already been taken')
end end
end end
...@@ -249,7 +249,7 @@ describe API::API, api: true do ...@@ -249,7 +249,7 @@ describe API::API, api: true do
it "should redirect to sign in page" do it "should redirect to sign in page" do
get "/users/sign_up" get "/users/sign_up"
expect(response.status).to eq(302) expect(response).to have_http_status(302)
expect(response).to redirect_to(new_user_session_path) expect(response).to redirect_to(new_user_session_path)
end end
end end
...@@ -261,41 +261,41 @@ describe API::API, api: true do ...@@ -261,41 +261,41 @@ describe API::API, api: true do
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).to have_http_status(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')
end end
it 'should update user with his own email' do it 'should update user with his own email' do
put api("/users/#{user.id}", admin), email: user.email put api("/users/#{user.id}", admin), email: user.email
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['email']).to eq(user.email) expect(json_response['email']).to eq(user.email)
expect(user.reload.email).to eq(user.email) expect(user.reload.email).to eq(user.email)
end end
it 'should update user with his own username' do it 'should update user with his own username' do
put api("/users/#{user.id}", admin), username: user.username put api("/users/#{user.id}", admin), username: user.username
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['username']).to eq(user.username) expect(json_response['username']).to eq(user.username)
expect(user.reload.username).to eq(user.username) expect(user.reload.username).to eq(user.username)
end end
it "should update user's existing identity" do it "should update user's existing identity" do
put api("/users/#{omniauth_user.id}", admin), provider: 'ldapmain', extern_uid: '654321' put api("/users/#{omniauth_user.id}", admin), provider: 'ldapmain', extern_uid: '654321'
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(omniauth_user.reload.identities.first.extern_uid).to eq('654321') expect(omniauth_user.reload.identities.first.extern_uid).to eq('654321')
end end
it 'should update user with new identity' do it 'should update user with new identity' do
put api("/users/#{user.id}", admin), provider: 'github', extern_uid: '67890' put api("/users/#{user.id}", admin), provider: 'github', extern_uid: '67890'
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(user.reload.identities.first.extern_uid).to eq('67890') expect(user.reload.identities.first.extern_uid).to eq('67890')
expect(user.reload.identities.first.provider).to eq('github') expect(user.reload.identities.first.provider).to eq('github')
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).to have_http_status(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
...@@ -309,7 +309,7 @@ describe API::API, api: true do ...@@ -309,7 +309,7 @@ describe API::API, api: true do
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).to have_http_status(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)
expect(admin_user.can_create_group).to eq(false) expect(admin_user.can_create_group).to eq(false)
...@@ -317,18 +317,18 @@ describe API::API, api: true do ...@@ -317,18 +317,18 @@ describe API::API, api: true do
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).to have_http_status(400)
expect(user.reload.email).not_to eq('invalid email') expect(user.reload.email).not_to eq('invalid email')
end end
it "shouldn't available for non admin users" do it "shouldn't available for non admin users" do
put api("/users/#{user.id}", user), attributes_for(:user) put api("/users/#{user.id}", user), attributes_for(:user)
expect(response.status).to eq(403) expect(response).to have_http_status(403)
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).to have_http_status(404)
expect(json_response['message']).to eq('404 Not found') expect(json_response['message']).to eq('404 Not found')
end end
...@@ -344,7 +344,7 @@ describe API::API, api: true do ...@@ -344,7 +344,7 @@ describe API::API, api: true do
name: 'test', name: 'test',
bio: 'g' * 256, bio: 'g' * 256,
projects_limit: -1 projects_limit: -1
expect(response.status).to eq(400) expect(response).to have_http_status(400)
expect(json_response['message']['password']). 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']). expect(json_response['message']['bio']).
...@@ -364,14 +364,14 @@ describe API::API, api: true do ...@@ -364,14 +364,14 @@ describe API::API, api: true do
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'
expect(response.status).to eq(409) expect(response).to have_http_status(409)
expect(@user.reload.email).to eq(@user.email) expect(@user.reload.email).to eq(@user.email)
end end
it 'should return 409 conflict error if username taken' do it 'should return 409 conflict error if username taken' do
@user_id = User.all.last.id @user_id = User.all.last.id
put api("/users/#{@user.id}", admin), username: 'test' put api("/users/#{@user.id}", admin), username: 'test'
expect(response.status).to eq(409) expect(response).to have_http_status(409)
expect(@user.reload.username).to eq(@user.username) expect(@user.reload.username).to eq(@user.username)
end end
end end
...@@ -382,13 +382,13 @@ describe API::API, api: true do ...@@ -382,13 +382,13 @@ describe API::API, api: true do
it "should not create invalid ssh key" do it "should not create invalid ssh key" do
post api("/users/#{user.id}/keys", admin), { title: "invalid key" } post api("/users/#{user.id}/keys", admin), { title: "invalid key" }
expect(response.status).to eq(400) expect(response).to have_http_status(400)
expect(json_response['message']).to eq('400 (Bad request) "key" not given') expect(json_response['message']).to eq('400 (Bad request) "key" not given')
end end
it 'should not create key without title' do it 'should not create key without title' do
post api("/users/#{user.id}/keys", admin), key: 'some key' post api("/users/#{user.id}/keys", admin), key: 'some key'
expect(response.status).to eq(400) expect(response).to have_http_status(400)
expect(json_response['message']).to eq('400 (Bad request) "title" not given') expect(json_response['message']).to eq('400 (Bad request) "title" not given')
end end
...@@ -401,7 +401,7 @@ describe API::API, api: true do ...@@ -401,7 +401,7 @@ describe API::API, api: true do
it "should return 405 for invalid ID" do it "should return 405 for invalid ID" do
post api("/users/ASDF/keys", admin) post api("/users/ASDF/keys", admin)
expect(response.status).to eq(405) expect(response).to have_http_status(405)
end end
end end
...@@ -411,14 +411,14 @@ describe API::API, api: true do ...@@ -411,14 +411,14 @@ describe API::API, api: true do
context 'when unauthenticated' do context 'when unauthenticated' do
it 'should return authentication error' do it 'should return authentication error' do
get api("/users/#{user.id}/keys") get api("/users/#{user.id}/keys")
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
context 'when authenticated' do context 'when authenticated' do
it 'should return 404 for non-existing user' do it 'should return 404 for non-existing user' do
get api('/users/999999/keys', admin) get api('/users/999999/keys', admin)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
expect(json_response['message']).to eq('404 User Not Found') expect(json_response['message']).to eq('404 User Not Found')
end end
...@@ -426,14 +426,14 @@ describe API::API, api: true do ...@@ -426,14 +426,14 @@ describe API::API, api: true do
user.keys << key user.keys << key
user.save user.save
get api("/users/#{user.id}/keys", admin) get api("/users/#{user.id}/keys", admin)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first['title']).to eq(key.title) expect(json_response.first['title']).to eq(key.title)
end end
it "should return 405 for invalid ID" do it "should return 405 for invalid ID" do
get api("/users/ASDF/keys", admin) get api("/users/ASDF/keys", admin)
expect(response.status).to eq(405) expect(response).to have_http_status(405)
end end
end end
end end
...@@ -444,7 +444,7 @@ describe API::API, api: true do ...@@ -444,7 +444,7 @@ describe API::API, api: true do
context 'when unauthenticated' do context 'when unauthenticated' do
it 'should return authentication error' do it 'should return authentication error' do
delete api("/users/#{user.id}/keys/42") delete api("/users/#{user.id}/keys/42")
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
...@@ -455,20 +455,20 @@ describe API::API, api: true do ...@@ -455,20 +455,20 @@ describe API::API, api: true do
expect do expect do
delete api("/users/#{user.id}/keys/#{key.id}", admin) delete api("/users/#{user.id}/keys/#{key.id}", admin)
end.to change { user.keys.count }.by(-1) end.to change { user.keys.count }.by(-1)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
it 'should return 404 error if user not found' do it 'should return 404 error if user not found' do
user.keys << key user.keys << key
user.save user.save
delete api("/users/999999/keys/#{key.id}", admin) delete api("/users/999999/keys/#{key.id}", admin)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
expect(json_response['message']).to eq('404 User Not Found') expect(json_response['message']).to eq('404 User Not Found')
end end
it 'should return 404 error if key not foud' do it 'should return 404 error if key not foud' do
delete api("/users/#{user.id}/keys/42", admin) delete api("/users/#{user.id}/keys/42", admin)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
expect(json_response['message']).to eq('404 Key Not Found') expect(json_response['message']).to eq('404 Key Not Found')
end end
end end
...@@ -479,7 +479,7 @@ describe API::API, api: true do ...@@ -479,7 +479,7 @@ describe API::API, api: true do
it "should not create invalid email" do it "should not create invalid email" do
post api("/users/#{user.id}/emails", admin), {} post api("/users/#{user.id}/emails", admin), {}
expect(response.status).to eq(400) expect(response).to have_http_status(400)
expect(json_response['message']).to eq('400 (Bad request) "email" not given') expect(json_response['message']).to eq('400 (Bad request) "email" not given')
end end
...@@ -492,7 +492,7 @@ describe API::API, api: true do ...@@ -492,7 +492,7 @@ describe API::API, api: true do
it "should raise error for invalid ID" do it "should raise error for invalid ID" do
post api("/users/ASDF/emails", admin) post api("/users/ASDF/emails", admin)
expect(response.status).to eq(405) expect(response).to have_http_status(405)
end end
end end
...@@ -502,14 +502,14 @@ describe API::API, api: true do ...@@ -502,14 +502,14 @@ describe API::API, api: true do
context 'when unauthenticated' do context 'when unauthenticated' do
it 'should return authentication error' do it 'should return authentication error' do
get api("/users/#{user.id}/emails") get api("/users/#{user.id}/emails")
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
context 'when authenticated' do context 'when authenticated' do
it 'should return 404 for non-existing user' do it 'should return 404 for non-existing user' do
get api('/users/999999/emails', admin) get api('/users/999999/emails', admin)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
expect(json_response['message']).to eq('404 User Not Found') expect(json_response['message']).to eq('404 User Not Found')
end end
...@@ -517,14 +517,14 @@ describe API::API, api: true do ...@@ -517,14 +517,14 @@ describe API::API, api: true do
user.emails << email user.emails << email
user.save user.save
get api("/users/#{user.id}/emails", admin) get api("/users/#{user.id}/emails", admin)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first['email']).to eq(email.email) expect(json_response.first['email']).to eq(email.email)
end end
it "should raise error for invalid ID" do it "should raise error for invalid ID" do
put api("/users/ASDF/emails", admin) put api("/users/ASDF/emails", admin)
expect(response.status).to eq(405) expect(response).to have_http_status(405)
end end
end end
end end
...@@ -535,7 +535,7 @@ describe API::API, api: true do ...@@ -535,7 +535,7 @@ describe API::API, api: true do
context 'when unauthenticated' do context 'when unauthenticated' do
it 'should return authentication error' do it 'should return authentication error' do
delete api("/users/#{user.id}/emails/42") delete api("/users/#{user.id}/emails/42")
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
...@@ -546,20 +546,20 @@ describe API::API, api: true do ...@@ -546,20 +546,20 @@ describe API::API, api: true do
expect do expect do
delete api("/users/#{user.id}/emails/#{email.id}", admin) delete api("/users/#{user.id}/emails/#{email.id}", admin)
end.to change { user.emails.count }.by(-1) end.to change { user.emails.count }.by(-1)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
it 'should return 404 error if user not found' do it 'should return 404 error if user not found' do
user.emails << email user.emails << email
user.save user.save
delete api("/users/999999/emails/#{email.id}", admin) delete api("/users/999999/emails/#{email.id}", admin)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
expect(json_response['message']).to eq('404 User Not Found') expect(json_response['message']).to eq('404 User Not Found')
end end
it 'should return 404 error if email not foud' do it 'should return 404 error if email not foud' do
delete api("/users/#{user.id}/emails/42", admin) delete api("/users/#{user.id}/emails/42", admin)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
expect(json_response['message']).to eq('404 Email Not Found') expect(json_response['message']).to eq('404 Email Not Found')
end end
...@@ -574,24 +574,24 @@ describe API::API, api: true do ...@@ -574,24 +574,24 @@ describe API::API, api: true do
it "should delete user" do it "should delete user" do
delete api("/users/#{user.id}", admin) delete api("/users/#{user.id}", admin)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect { User.find(user.id) }.to raise_error ActiveRecord::RecordNotFound expect { User.find(user.id) }.to raise_error ActiveRecord::RecordNotFound
expect(json_response['email']).to eq(user.email) expect(json_response['email']).to eq(user.email)
end end
it "should not delete for unauthenticated user" do it "should not delete for unauthenticated user" do
delete api("/users/#{user.id}") delete api("/users/#{user.id}")
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
it "shouldn't available for non admin users" do it "shouldn't available for non admin users" do
delete api("/users/#{user.id}", user) delete api("/users/#{user.id}", user)
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
it "should return 404 for non-existing user" do it "should return 404 for non-existing user" do
delete api("/users/999999", admin) delete api("/users/999999", admin)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
expect(json_response['message']).to eq('404 User Not Found') expect(json_response['message']).to eq('404 User Not Found')
end end
...@@ -603,7 +603,7 @@ describe API::API, api: true do ...@@ -603,7 +603,7 @@ describe API::API, api: true do
describe "GET /user" do describe "GET /user" do
it "should return current user" do it "should return current user" do
get api("/user", user) get api("/user", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['email']).to eq(user.email) expect(json_response['email']).to eq(user.email)
expect(json_response['is_admin']).to eq(user.is_admin?) expect(json_response['is_admin']).to eq(user.is_admin?)
expect(json_response['can_create_project']).to eq(user.can_create_project?) expect(json_response['can_create_project']).to eq(user.can_create_project?)
...@@ -613,7 +613,7 @@ describe API::API, api: true do ...@@ -613,7 +613,7 @@ describe API::API, api: true do
it "should return 401 error if user is unauthenticated" do it "should return 401 error if user is unauthenticated" do
get api("/user") get api("/user")
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
...@@ -621,7 +621,7 @@ describe API::API, api: true do ...@@ -621,7 +621,7 @@ describe API::API, api: true do
context "when unauthenticated" do context "when unauthenticated" do
it "should return authentication error" do it "should return authentication error" do
get api("/user/keys") get api("/user/keys")
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
...@@ -630,7 +630,7 @@ describe API::API, api: true do ...@@ -630,7 +630,7 @@ describe API::API, api: true do
user.keys << key user.keys << key
user.save user.save
get api("/user/keys", user) get api("/user/keys", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first["title"]).to eq(key.title) expect(json_response.first["title"]).to eq(key.title)
end end
...@@ -642,13 +642,13 @@ describe API::API, api: true do ...@@ -642,13 +642,13 @@ describe API::API, api: true do
user.keys << key user.keys << key
user.save user.save
get api("/user/keys/#{key.id}", user) get api("/user/keys/#{key.id}", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response["title"]).to eq(key.title) expect(json_response["title"]).to eq(key.title)
end end
it "should return 404 Not Found within invalid ID" do it "should return 404 Not Found within invalid ID" do
get api("/user/keys/42", user) get api("/user/keys/42", user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
expect(json_response['message']).to eq('404 Not found') expect(json_response['message']).to eq('404 Not found')
end end
...@@ -657,13 +657,13 @@ describe API::API, api: true do ...@@ -657,13 +657,13 @@ describe API::API, api: true do
user.save user.save
admin admin
get api("/user/keys/#{key.id}", admin) get api("/user/keys/#{key.id}", admin)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
expect(json_response['message']).to eq('404 Not found') expect(json_response['message']).to eq('404 Not found')
end end
it "should return 404 for invalid ID" do it "should return 404 for invalid ID" do
get api("/users/keys/ASDF", admin) get api("/users/keys/ASDF", admin)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
...@@ -673,29 +673,29 @@ describe API::API, api: true do ...@@ -673,29 +673,29 @@ describe API::API, api: true do
expect do expect do
post api("/user/keys", user), key_attrs post api("/user/keys", user), key_attrs
end.to change{ user.keys.count }.by(1) end.to change{ user.keys.count }.by(1)
expect(response.status).to eq(201) expect(response).to have_http_status(201)
end end
it "should return a 401 error if unauthorized" do it "should return a 401 error if unauthorized" do
post api("/user/keys"), title: 'some title', key: 'some key' post api("/user/keys"), title: 'some title', key: 'some key'
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
it "should not create ssh key without key" do it "should not create ssh key without key" do
post api("/user/keys", user), title: 'title' post api("/user/keys", user), title: 'title'
expect(response.status).to eq(400) expect(response).to have_http_status(400)
expect(json_response['message']).to eq('400 (Bad request) "key" not given') expect(json_response['message']).to eq('400 (Bad request) "key" not given')
end end
it 'should not create ssh key without title' do it 'should not create ssh key without title' do
post api('/user/keys', user), key: 'some key' post api('/user/keys', user), key: 'some key'
expect(response.status).to eq(400) expect(response).to have_http_status(400)
expect(json_response['message']).to eq('400 (Bad request) "title" not given') expect(json_response['message']).to eq('400 (Bad request) "title" not given')
end end
it "should not create ssh key without title" do it "should not create ssh key without title" do
post api("/user/keys", user), key: "somekey" post api("/user/keys", user), key: "somekey"
expect(response.status).to eq(400) expect(response).to have_http_status(400)
end end
end end
...@@ -706,19 +706,19 @@ describe API::API, api: true do ...@@ -706,19 +706,19 @@ describe API::API, api: true do
expect do expect do
delete api("/user/keys/#{key.id}", user) delete api("/user/keys/#{key.id}", user)
end.to change{user.keys.count}.by(-1) end.to change{user.keys.count}.by(-1)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
it "should return success if key ID not found" do it "should return success if key ID not found" do
delete api("/user/keys/42", user) delete api("/user/keys/42", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
it "should return 401 error if unauthorized" do it "should return 401 error if unauthorized" do
user.keys << key user.keys << key
user.save user.save
delete api("/user/keys/#{key.id}") delete api("/user/keys/#{key.id}")
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
it "should raise error for invalid ID" do it "should raise error for invalid ID" do
...@@ -730,7 +730,7 @@ describe API::API, api: true do ...@@ -730,7 +730,7 @@ describe API::API, api: true do
context "when unauthenticated" do context "when unauthenticated" do
it "should return authentication error" do it "should return authentication error" do
get api("/user/emails") get api("/user/emails")
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
...@@ -739,7 +739,7 @@ describe API::API, api: true do ...@@ -739,7 +739,7 @@ describe API::API, api: true do
user.emails << email user.emails << email
user.save user.save
get api("/user/emails", user) get api("/user/emails", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first["email"]).to eq(email.email) expect(json_response.first["email"]).to eq(email.email)
end end
...@@ -751,13 +751,13 @@ describe API::API, api: true do ...@@ -751,13 +751,13 @@ describe API::API, api: true do
user.emails << email user.emails << email
user.save user.save
get api("/user/emails/#{email.id}", user) get api("/user/emails/#{email.id}", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response["email"]).to eq(email.email) expect(json_response["email"]).to eq(email.email)
end end
it "should return 404 Not Found within invalid ID" do it "should return 404 Not Found within invalid ID" do
get api("/user/emails/42", user) get api("/user/emails/42", user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
expect(json_response['message']).to eq('404 Not found') expect(json_response['message']).to eq('404 Not found')
end end
...@@ -766,13 +766,13 @@ describe API::API, api: true do ...@@ -766,13 +766,13 @@ describe API::API, api: true do
user.save user.save
admin admin
get api("/user/emails/#{email.id}", admin) get api("/user/emails/#{email.id}", admin)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
expect(json_response['message']).to eq('404 Not found') expect(json_response['message']).to eq('404 Not found')
end end
it "should return 404 for invalid ID" do it "should return 404 for invalid ID" do
get api("/users/emails/ASDF", admin) get api("/users/emails/ASDF", admin)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
...@@ -782,17 +782,17 @@ describe API::API, api: true do ...@@ -782,17 +782,17 @@ describe API::API, api: true do
expect do expect do
post api("/user/emails", user), email_attrs post api("/user/emails", user), email_attrs
end.to change{ user.emails.count }.by(1) end.to change{ user.emails.count }.by(1)
expect(response.status).to eq(201) expect(response).to have_http_status(201)
end end
it "should return a 401 error if unauthorized" do it "should return a 401 error if unauthorized" do
post api("/user/emails"), email: 'some email' post api("/user/emails"), email: 'some email'
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
it "should not create email with invalid email" do it "should not create email with invalid email" do
post api("/user/emails", user), {} post api("/user/emails", user), {}
expect(response.status).to eq(400) expect(response).to have_http_status(400)
expect(json_response['message']).to eq('400 (Bad request) "email" not given') expect(json_response['message']).to eq('400 (Bad request) "email" not given')
end end
end end
...@@ -804,19 +804,19 @@ describe API::API, api: true do ...@@ -804,19 +804,19 @@ describe API::API, api: true do
expect do expect do
delete api("/user/emails/#{email.id}", user) delete api("/user/emails/#{email.id}", user)
end.to change{user.emails.count}.by(-1) end.to change{user.emails.count}.by(-1)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
it "should return success if email ID not found" do it "should return success if email ID not found" do
delete api("/user/emails/42", user) delete api("/user/emails/42", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
it "should return 401 error if unauthorized" do it "should return 401 error if unauthorized" do
user.emails << email user.emails << email
user.save user.save
delete api("/user/emails/#{email.id}") delete api("/user/emails/#{email.id}")
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
it "should raise error for invalid ID" do it "should raise error for invalid ID" do
...@@ -828,25 +828,25 @@ describe API::API, api: true do ...@@ -828,25 +828,25 @@ describe API::API, api: true do
before { admin } before { admin }
it 'should block existing user' do it 'should block existing user' do
put api("/users/#{user.id}/block", admin) put api("/users/#{user.id}/block", admin)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(user.reload.state).to eq('blocked') expect(user.reload.state).to eq('blocked')
end end
it 'should not re-block ldap blocked users' do it 'should not re-block ldap blocked users' do
put api("/users/#{ldap_blocked_user.id}/block", admin) put api("/users/#{ldap_blocked_user.id}/block", admin)
expect(response.status).to eq(403) expect(response).to have_http_status(403)
expect(ldap_blocked_user.reload.state).to eq('ldap_blocked') expect(ldap_blocked_user.reload.state).to eq('ldap_blocked')
end end
it 'should not be available for non admin users' do it 'should not be available for non admin users' do
put api("/users/#{user.id}/block", user) put api("/users/#{user.id}/block", user)
expect(response.status).to eq(403) expect(response).to have_http_status(403)
expect(user.reload.state).to eq('active') expect(user.reload.state).to eq('active')
end end
it 'should return a 404 error if user id not found' do it 'should return a 404 error if user id not found' do
put api('/users/9999/block', admin) put api('/users/9999/block', admin)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
expect(json_response['message']).to eq('404 User Not Found') expect(json_response['message']).to eq('404 User Not Found')
end end
end end
...@@ -857,31 +857,31 @@ describe API::API, api: true do ...@@ -857,31 +857,31 @@ describe API::API, api: true do
it 'should unblock existing user' do it 'should unblock existing user' do
put api("/users/#{user.id}/unblock", admin) put api("/users/#{user.id}/unblock", admin)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(user.reload.state).to eq('active') expect(user.reload.state).to eq('active')
end end
it 'should unblock a blocked user' do it 'should unblock a blocked user' do
put api("/users/#{blocked_user.id}/unblock", admin) put api("/users/#{blocked_user.id}/unblock", admin)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(blocked_user.reload.state).to eq('active') expect(blocked_user.reload.state).to eq('active')
end end
it 'should not unblock ldap blocked users' do it 'should not unblock ldap blocked users' do
put api("/users/#{ldap_blocked_user.id}/unblock", admin) put api("/users/#{ldap_blocked_user.id}/unblock", admin)
expect(response.status).to eq(403) expect(response).to have_http_status(403)
expect(ldap_blocked_user.reload.state).to eq('ldap_blocked') expect(ldap_blocked_user.reload.state).to eq('ldap_blocked')
end end
it 'should not be available for non admin users' do it 'should not be available for non admin users' do
put api("/users/#{user.id}/unblock", user) put api("/users/#{user.id}/unblock", user)
expect(response.status).to eq(403) expect(response).to have_http_status(403)
expect(user.reload.state).to eq('active') expect(user.reload.state).to eq('active')
end end
it 'should return a 404 error if user id not found' do it 'should return a 404 error if user id not found' do
put api('/users/9999/block', admin) put api('/users/9999/block', admin)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
expect(json_response['message']).to eq('404 User Not Found') expect(json_response['message']).to eq('404 User Not Found')
end end
......
...@@ -15,7 +15,7 @@ describe API::API, api: true do ...@@ -15,7 +15,7 @@ describe API::API, api: true do
it 'should return project variables' do it 'should return project variables' do
get api("/projects/#{project.id}/variables", user) get api("/projects/#{project.id}/variables", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response).to be_a(Array) expect(json_response).to be_a(Array)
end end
end end
...@@ -24,7 +24,7 @@ describe API::API, api: true do ...@@ -24,7 +24,7 @@ describe API::API, api: true do
it 'should not return project variables' do it 'should not return project variables' do
get api("/projects/#{project.id}/variables", user2) get api("/projects/#{project.id}/variables", user2)
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
end end
...@@ -32,7 +32,7 @@ describe API::API, api: true do ...@@ -32,7 +32,7 @@ describe API::API, api: true do
it 'should not return project variables' do it 'should not return project variables' do
get api("/projects/#{project.id}/variables") get api("/projects/#{project.id}/variables")
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
end end
...@@ -42,14 +42,14 @@ describe API::API, api: true do ...@@ -42,14 +42,14 @@ describe API::API, api: true do
it 'should return project variable details' do it 'should return project variable details' do
get api("/projects/#{project.id}/variables/#{variable.key}", user) get api("/projects/#{project.id}/variables/#{variable.key}", user)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response['value']).to eq(variable.value) expect(json_response['value']).to eq(variable.value)
end end
it 'should respond with 404 Not Found if requesting non-existing variable' do it 'should respond with 404 Not Found if requesting non-existing variable' do
get api("/projects/#{project.id}/variables/non_existing_variable", user) get api("/projects/#{project.id}/variables/non_existing_variable", user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
...@@ -57,7 +57,7 @@ describe API::API, api: true do ...@@ -57,7 +57,7 @@ describe API::API, api: true do
it 'should not return project variable details' do it 'should not return project variable details' do
get api("/projects/#{project.id}/variables/#{variable.key}", user2) get api("/projects/#{project.id}/variables/#{variable.key}", user2)
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
end end
...@@ -65,7 +65,7 @@ describe API::API, api: true do ...@@ -65,7 +65,7 @@ describe API::API, api: true do
it 'should not return project variable details' do it 'should not return project variable details' do
get api("/projects/#{project.id}/variables/#{variable.key}") get api("/projects/#{project.id}/variables/#{variable.key}")
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
end end
...@@ -77,7 +77,7 @@ describe API::API, api: true do ...@@ -77,7 +77,7 @@ describe API::API, api: true do
post api("/projects/#{project.id}/variables", user), key: 'TEST_VARIABLE_2', value: 'VALUE_2' post api("/projects/#{project.id}/variables", user), key: 'TEST_VARIABLE_2', value: 'VALUE_2'
end.to change{project.variables.count}.by(1) end.to change{project.variables.count}.by(1)
expect(response.status).to eq(201) expect(response).to have_http_status(201)
expect(json_response['key']).to eq('TEST_VARIABLE_2') expect(json_response['key']).to eq('TEST_VARIABLE_2')
expect(json_response['value']).to eq('VALUE_2') expect(json_response['value']).to eq('VALUE_2')
end end
...@@ -87,7 +87,7 @@ describe API::API, api: true do ...@@ -87,7 +87,7 @@ describe API::API, api: true do
post api("/projects/#{project.id}/variables", user), key: variable.key, value: 'VALUE_2' post api("/projects/#{project.id}/variables", user), key: variable.key, value: 'VALUE_2'
end.to change{project.variables.count}.by(0) end.to change{project.variables.count}.by(0)
expect(response.status).to eq(400) expect(response).to have_http_status(400)
end end
end end
...@@ -95,7 +95,7 @@ describe API::API, api: true do ...@@ -95,7 +95,7 @@ describe API::API, api: true do
it 'should not create variable' do it 'should not create variable' do
post api("/projects/#{project.id}/variables", user2) post api("/projects/#{project.id}/variables", user2)
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
end end
...@@ -103,7 +103,7 @@ describe API::API, api: true do ...@@ -103,7 +103,7 @@ describe API::API, api: true do
it 'should not create variable' do it 'should not create variable' do
post api("/projects/#{project.id}/variables") post api("/projects/#{project.id}/variables")
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
end end
...@@ -118,7 +118,7 @@ describe API::API, api: true do ...@@ -118,7 +118,7 @@ describe API::API, api: true do
updated_variable = project.variables.first updated_variable = project.variables.first
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(value_before).to eq(variable.value) expect(value_before).to eq(variable.value)
expect(updated_variable.value).to eq('VALUE_1_UP') expect(updated_variable.value).to eq('VALUE_1_UP')
end end
...@@ -126,7 +126,7 @@ describe API::API, api: true do ...@@ -126,7 +126,7 @@ describe API::API, api: true do
it 'should responde with 404 Not Found if requesting non-existing variable' do it 'should responde with 404 Not Found if requesting non-existing variable' do
put api("/projects/#{project.id}/variables/non_existing_variable", user) put api("/projects/#{project.id}/variables/non_existing_variable", user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
...@@ -134,7 +134,7 @@ describe API::API, api: true do ...@@ -134,7 +134,7 @@ describe API::API, api: true do
it 'should not update variable' do it 'should not update variable' do
put api("/projects/#{project.id}/variables/#{variable.key}", user2) put api("/projects/#{project.id}/variables/#{variable.key}", user2)
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
end end
...@@ -142,7 +142,7 @@ describe API::API, api: true do ...@@ -142,7 +142,7 @@ describe API::API, api: true do
it 'should not update variable' do it 'should not update variable' do
put api("/projects/#{project.id}/variables/#{variable.key}") put api("/projects/#{project.id}/variables/#{variable.key}")
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
end end
...@@ -153,13 +153,13 @@ describe API::API, api: true do ...@@ -153,13 +153,13 @@ describe API::API, api: true do
expect do expect do
delete api("/projects/#{project.id}/variables/#{variable.key}", user) delete api("/projects/#{project.id}/variables/#{variable.key}", user)
end.to change{project.variables.count}.by(-1) end.to change{project.variables.count}.by(-1)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
it 'should responde with 404 Not Found if requesting non-existing variable' do it 'should responde with 404 Not Found if requesting non-existing variable' do
delete api("/projects/#{project.id}/variables/non_existing_variable", user) delete api("/projects/#{project.id}/variables/non_existing_variable", user)
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
...@@ -167,7 +167,7 @@ describe API::API, api: true do ...@@ -167,7 +167,7 @@ describe API::API, api: true do
it 'should not delete variable' do it 'should not delete variable' do
delete api("/projects/#{project.id}/variables/#{variable.key}", user2) delete api("/projects/#{project.id}/variables/#{variable.key}", user2)
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
end end
...@@ -175,7 +175,7 @@ describe API::API, api: true do ...@@ -175,7 +175,7 @@ describe API::API, api: true do
it 'should not delete variable' do it 'should not delete variable' do
delete api("/projects/#{project.id}/variables/#{variable.key}") delete api("/projects/#{project.id}/variables/#{variable.key}")
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
end end
......
...@@ -26,7 +26,7 @@ describe Ci::API::API do ...@@ -26,7 +26,7 @@ describe Ci::API::API do
post ci_api("/builds/register"), token: runner.token, info: { platform: :darwin } post ci_api("/builds/register"), token: runner.token, info: { platform: :darwin }
expect(response.status).to eq(201) expect(response).to have_http_status(201)
expect(json_response['sha']).to eq(build.sha) expect(json_response['sha']).to eq(build.sha)
expect(runner.reload.platform).to eq("darwin") expect(runner.reload.platform).to eq("darwin")
end end
...@@ -34,7 +34,7 @@ describe Ci::API::API do ...@@ -34,7 +34,7 @@ describe Ci::API::API do
it "should return 404 error if no pending build found" do it "should return 404 error if no pending build found" do
post ci_api("/builds/register"), token: runner.token post ci_api("/builds/register"), token: runner.token
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
it "should return 404 error if no builds for specific runner" do it "should return 404 error if no builds for specific runner" do
...@@ -43,7 +43,7 @@ describe Ci::API::API do ...@@ -43,7 +43,7 @@ describe Ci::API::API do
post ci_api("/builds/register"), token: runner.token post ci_api("/builds/register"), token: runner.token
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
it "should return 404 error if no builds for shared runner" do it "should return 404 error if no builds for shared runner" do
...@@ -52,7 +52,7 @@ describe Ci::API::API do ...@@ -52,7 +52,7 @@ describe Ci::API::API do
post ci_api("/builds/register"), token: shared_runner.token post ci_api("/builds/register"), token: shared_runner.token
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
it "returns options" do it "returns options" do
...@@ -61,7 +61,7 @@ describe Ci::API::API do ...@@ -61,7 +61,7 @@ describe Ci::API::API do
post ci_api("/builds/register"), token: runner.token, info: { platform: :darwin } post ci_api("/builds/register"), token: runner.token, info: { platform: :darwin }
expect(response.status).to eq(201) expect(response).to have_http_status(201)
expect(json_response["options"]).to eq({ "image" => "ruby:2.1", "services" => ["postgres"] }) expect(json_response["options"]).to eq({ "image" => "ruby:2.1", "services" => ["postgres"] })
end end
...@@ -72,7 +72,7 @@ describe Ci::API::API do ...@@ -72,7 +72,7 @@ describe Ci::API::API do
post ci_api("/builds/register"), token: runner.token, info: { platform: :darwin } post ci_api("/builds/register"), token: runner.token, info: { platform: :darwin }
expect(response.status).to eq(201) expect(response).to have_http_status(201)
expect(json_response["variables"]).to eq([ expect(json_response["variables"]).to eq([
{ "key" => "CI_BUILD_NAME", "value" => "spinach", "public" => true }, { "key" => "CI_BUILD_NAME", "value" => "spinach", "public" => true },
{ "key" => "CI_BUILD_STAGE", "value" => "test", "public" => true }, { "key" => "CI_BUILD_STAGE", "value" => "test", "public" => true },
...@@ -91,7 +91,7 @@ describe Ci::API::API do ...@@ -91,7 +91,7 @@ describe Ci::API::API do
post ci_api("/builds/register"), token: runner.token, info: { platform: :darwin } post ci_api("/builds/register"), token: runner.token, info: { platform: :darwin }
expect(response.status).to eq(201) expect(response).to have_http_status(201)
expect(json_response["variables"]).to eq([ expect(json_response["variables"]).to eq([
{ "key" => "CI_BUILD_NAME", "value" => "spinach", "public" => true }, { "key" => "CI_BUILD_NAME", "value" => "spinach", "public" => true },
{ "key" => "CI_BUILD_STAGE", "value" => "test", "public" => true }, { "key" => "CI_BUILD_STAGE", "value" => "test", "public" => true },
...@@ -109,7 +109,7 @@ describe Ci::API::API do ...@@ -109,7 +109,7 @@ describe Ci::API::API do
post ci_api("/builds/register"), token: runner.token, info: { platform: :darwin } post ci_api("/builds/register"), token: runner.token, info: { platform: :darwin }
expect(response.status).to eq(201) expect(response).to have_http_status(201)
expect(json_response["depends_on_builds"].count).to eq(2) expect(json_response["depends_on_builds"].count).to eq(2)
expect(json_response["depends_on_builds"][0]["name"]).to eq("rspec") expect(json_response["depends_on_builds"][0]["name"]).to eq("rspec")
end end
...@@ -122,7 +122,7 @@ describe Ci::API::API do ...@@ -122,7 +122,7 @@ describe Ci::API::API do
it do it do
post ci_api("/builds/register"), token: runner.token, info: { param => value } post ci_api("/builds/register"), token: runner.token, info: { param => value }
expect(response.status).to eq(404) expect(response).to have_http_status(404)
runner.reload runner.reload
is_expected.to eq(value) is_expected.to eq(value)
end end
...@@ -172,7 +172,7 @@ describe Ci::API::API do ...@@ -172,7 +172,7 @@ describe Ci::API::API do
end end
it "should update a running build" do it "should update a running build" do
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
it 'should not override trace information when no trace is given' do it 'should not override trace information when no trace is given' do
...@@ -252,13 +252,13 @@ describe Ci::API::API do ...@@ -252,13 +252,13 @@ describe Ci::API::API do
context "should authorize posting artifact to running build" do context "should authorize posting artifact to running build" do
it "using token as parameter" do it "using token as parameter" do
post authorize_url, { token: build.token }, headers post authorize_url, { token: build.token }, headers
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response["TempPath"]).not_to be_nil expect(json_response["TempPath"]).not_to be_nil
end end
it "using token as header" do it "using token as header" do
post authorize_url, {}, headers_with_token post authorize_url, {}, headers_with_token
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_response["TempPath"]).not_to be_nil expect(json_response["TempPath"]).not_to be_nil
end end
end end
...@@ -267,13 +267,13 @@ describe Ci::API::API do ...@@ -267,13 +267,13 @@ describe Ci::API::API do
it "using token as parameter" do it "using token as parameter" do
stub_application_setting(max_artifacts_size: 0) stub_application_setting(max_artifacts_size: 0)
post authorize_url, { token: build.token, filesize: 100 }, headers post authorize_url, { token: build.token, filesize: 100 }, headers
expect(response.status).to eq(413) expect(response).to have_http_status(413)
end end
it "using token as header" do it "using token as header" do
stub_application_setting(max_artifacts_size: 0) stub_application_setting(max_artifacts_size: 0)
post authorize_url, { filesize: 100 }, headers_with_token post authorize_url, { filesize: 100 }, headers_with_token
expect(response.status).to eq(413) expect(response).to have_http_status(413)
end end
end end
...@@ -281,7 +281,7 @@ describe Ci::API::API do ...@@ -281,7 +281,7 @@ describe Ci::API::API do
before { post authorize_url, { token: 'invalid', filesize: 100 } } before { post authorize_url, { token: 'invalid', filesize: 100 } }
it 'should respond with forbidden' do it 'should respond with forbidden' do
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
end end
end end
...@@ -305,20 +305,20 @@ describe Ci::API::API do ...@@ -305,20 +305,20 @@ describe Ci::API::API do
context "should post artifact to running build" do context "should post artifact to running build" do
it "uses regual file post" do it "uses regual file post" do
upload_artifacts(file_upload, headers_with_token, false) upload_artifacts(file_upload, headers_with_token, false)
expect(response.status).to eq(201) expect(response).to have_http_status(201)
expect(json_response["artifacts_file"]["filename"]).to eq(file_upload.original_filename) expect(json_response["artifacts_file"]["filename"]).to eq(file_upload.original_filename)
end end
it "uses accelerated file post" do it "uses accelerated file post" do
upload_artifacts(file_upload, headers_with_token, true) upload_artifacts(file_upload, headers_with_token, true)
expect(response.status).to eq(201) expect(response).to have_http_status(201)
expect(json_response["artifacts_file"]["filename"]).to eq(file_upload.original_filename) expect(json_response["artifacts_file"]["filename"]).to eq(file_upload.original_filename)
end end
it "updates artifact" do it "updates artifact" do
upload_artifacts(file_upload, headers_with_token) upload_artifacts(file_upload, headers_with_token)
upload_artifacts(file_upload2, headers_with_token) upload_artifacts(file_upload2, headers_with_token)
expect(response.status).to eq(201) expect(response).to have_http_status(201)
expect(json_response["artifacts_file"]["filename"]).to eq(file_upload2.original_filename) expect(json_response["artifacts_file"]["filename"]).to eq(file_upload2.original_filename)
end end
end end
...@@ -343,7 +343,7 @@ describe Ci::API::API do ...@@ -343,7 +343,7 @@ describe Ci::API::API do
end end
it 'stores artifacts and artifacts metadata' do it 'stores artifacts and artifacts metadata' do
expect(response.status).to eq(201) expect(response).to have_http_status(201)
expect(stored_artifacts_file.original_filename).to eq(artifacts.original_filename) expect(stored_artifacts_file.original_filename).to eq(artifacts.original_filename)
expect(stored_metadata_file.original_filename).to eq(metadata.original_filename) expect(stored_metadata_file.original_filename).to eq(metadata.original_filename)
end end
...@@ -355,7 +355,7 @@ describe Ci::API::API do ...@@ -355,7 +355,7 @@ describe Ci::API::API do
end end
it 'is expected to respond with bad request' do it 'is expected to respond with bad request' do
expect(response.status).to eq(400) expect(response).to have_http_status(400)
end end
it 'does not store metadata' do it 'does not store metadata' do
...@@ -382,7 +382,7 @@ describe Ci::API::API do ...@@ -382,7 +382,7 @@ describe Ci::API::API do
it 'updates when specified' do it 'updates when specified' do
build.reload build.reload
expect(response.status).to eq(201) expect(response).to have_http_status(201)
expect(json_response['artifacts_expire_at']).not_to be_empty expect(json_response['artifacts_expire_at']).not_to be_empty
expect(build.artifacts_expire_at).to be_within(5.minutes).of(Time.now + 7.days) expect(build.artifacts_expire_at).to be_within(5.minutes).of(Time.now + 7.days)
end end
...@@ -393,7 +393,7 @@ describe Ci::API::API do ...@@ -393,7 +393,7 @@ describe Ci::API::API do
it 'ignores if not specified' do it 'ignores if not specified' do
build.reload build.reload
expect(response.status).to eq(201) expect(response).to have_http_status(201)
expect(json_response['artifacts_expire_at']).to be_nil expect(json_response['artifacts_expire_at']).to be_nil
expect(build.artifacts_expire_at).to be_nil expect(build.artifacts_expire_at).to be_nil
end end
...@@ -404,21 +404,21 @@ describe Ci::API::API do ...@@ -404,21 +404,21 @@ describe Ci::API::API do
it "should fail to post too large artifact" do it "should fail to post too large artifact" do
stub_application_setting(max_artifacts_size: 0) stub_application_setting(max_artifacts_size: 0)
upload_artifacts(file_upload, headers_with_token) upload_artifacts(file_upload, headers_with_token)
expect(response.status).to eq(413) expect(response).to have_http_status(413)
end end
end end
context "artifacts post request does not contain file" do context "artifacts post request does not contain file" do
it "should fail to post artifacts without file" do it "should fail to post artifacts without file" do
post post_url, {}, headers_with_token post post_url, {}, headers_with_token
expect(response.status).to eq(400) expect(response).to have_http_status(400)
end end
end end
context 'GitLab Workhorse is not configured' do context 'GitLab Workhorse is not configured' do
it "should fail to post artifacts without GitLab-Workhorse" do it "should fail to post artifacts without GitLab-Workhorse" do
post post_url, { token: build.token }, {} post post_url, { token: build.token }, {}
expect(response.status).to eq(403) expect(response).to have_http_status(403)
end end
end end
end end
...@@ -437,7 +437,7 @@ describe Ci::API::API do ...@@ -437,7 +437,7 @@ describe Ci::API::API do
it "should fail to post artifacts for outside of tmp path" do it "should fail to post artifacts for outside of tmp path" do
upload_artifacts(file_upload, headers_with_token) upload_artifacts(file_upload, headers_with_token)
expect(response.status).to eq(400) expect(response).to have_http_status(400)
end end
end end
...@@ -458,7 +458,7 @@ describe Ci::API::API do ...@@ -458,7 +458,7 @@ describe Ci::API::API do
before { delete delete_url, token: build.token } before { delete delete_url, token: build.token }
it 'should remove build artifacts' do it 'should remove build artifacts' do
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(build.artifacts_file.exists?).to be_falsy expect(build.artifacts_file.exists?).to be_falsy
expect(build.artifacts_metadata.exists?).to be_falsy expect(build.artifacts_metadata.exists?).to be_falsy
end end
...@@ -475,14 +475,14 @@ describe Ci::API::API do ...@@ -475,14 +475,14 @@ describe Ci::API::API do
end end
it 'should download artifact' do it 'should download artifact' do
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(response.headers).to include download_headers expect(response.headers).to include download_headers
end end
end end
context 'build does not has artifacts' do context 'build does not has artifacts' do
it 'should respond with not found' do it 'should respond with not found' do
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
end end
......
...@@ -21,17 +21,17 @@ describe Ci::API::API do ...@@ -21,17 +21,17 @@ describe Ci::API::API do
context 'Handles errors' do context 'Handles errors' do
it 'should return bad request if token is missing' do it 'should return bad request if token is missing' do
post ci_api("/projects/#{project.ci_id}/refs/master/trigger") post ci_api("/projects/#{project.ci_id}/refs/master/trigger")
expect(response.status).to eq(400) expect(response).to have_http_status(400)
end end
it 'should return not found if project is not found' do it 'should return not found if project is not found' do
post ci_api('/projects/0/refs/master/trigger'), options post ci_api('/projects/0/refs/master/trigger'), options
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
it 'should return unauthorized if token is for different project' do it 'should return unauthorized if token is for different project' do
post ci_api("/projects/#{project2.ci_id}/refs/master/trigger"), options post ci_api("/projects/#{project2.ci_id}/refs/master/trigger"), options
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
...@@ -40,14 +40,14 @@ describe Ci::API::API do ...@@ -40,14 +40,14 @@ describe Ci::API::API do
it 'should create builds' do it 'should create builds' do
post ci_api("/projects/#{project.ci_id}/refs/master/trigger"), options post ci_api("/projects/#{project.ci_id}/refs/master/trigger"), options
expect(response.status).to eq(201) expect(response).to have_http_status(201)
pipeline.builds.reload pipeline.builds.reload
expect(pipeline.builds.size).to eq(2) expect(pipeline.builds.size).to eq(2)
end end
it 'should return bad request with no builds created if there\'s no commit for that ref' do it 'should return bad request with no builds created if there\'s no commit for that ref' do
post ci_api("/projects/#{project.ci_id}/refs/other-branch/trigger"), options post ci_api("/projects/#{project.ci_id}/refs/other-branch/trigger"), options
expect(response.status).to eq(400) expect(response).to have_http_status(400)
expect(json_response['message']).to eq('No builds created') expect(json_response['message']).to eq('No builds created')
end end
...@@ -58,19 +58,19 @@ describe Ci::API::API do ...@@ -58,19 +58,19 @@ describe Ci::API::API do
it 'should validate variables to be a hash' do it 'should validate variables to be a hash' do
post ci_api("/projects/#{project.ci_id}/refs/master/trigger"), options.merge(variables: 'value') post ci_api("/projects/#{project.ci_id}/refs/master/trigger"), options.merge(variables: 'value')
expect(response.status).to eq(400) expect(response).to have_http_status(400)
expect(json_response['message']).to eq('variables needs to be a hash') expect(json_response['message']).to eq('variables needs to be a hash')
end end
it 'should validate variables needs to be a map of key-valued strings' do it 'should validate variables needs to be a map of key-valued strings' do
post ci_api("/projects/#{project.ci_id}/refs/master/trigger"), options.merge(variables: { key: %w(1 2) }) post ci_api("/projects/#{project.ci_id}/refs/master/trigger"), options.merge(variables: { key: %w(1 2) })
expect(response.status).to eq(400) expect(response).to have_http_status(400)
expect(json_response['message']).to eq('variables needs to be a map of key-valued strings') expect(json_response['message']).to eq('variables needs to be a map of key-valued strings')
end end
it 'create trigger request with variables' do it 'create trigger request with variables' do
post ci_api("/projects/#{project.ci_id}/refs/master/trigger"), options.merge(variables: variables) post ci_api("/projects/#{project.ci_id}/refs/master/trigger"), options.merge(variables: variables)
expect(response.status).to eq(201) expect(response).to have_http_status(201)
pipeline.builds.reload pipeline.builds.reload
expect(pipeline.builds.first.trigger_request.variables).to eq(variables) expect(pipeline.builds.first.trigger_request.variables).to eq(variables)
end end
......
...@@ -14,7 +14,7 @@ describe 'Git HTTP requests', lib: true do ...@@ -14,7 +14,7 @@ describe 'Git HTTP requests', lib: true do
context "when no authentication is provided" do context "when no authentication is provided" do
it "responds with status 401 (no project existence information leak)" do it "responds with status 401 (no project existence information leak)" do
download('doesnt/exist.git') do |response| download('doesnt/exist.git') do |response|
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
end end
...@@ -23,7 +23,7 @@ describe 'Git HTTP requests', lib: true do ...@@ -23,7 +23,7 @@ describe 'Git HTTP requests', lib: true do
context "when authentication fails" do context "when authentication fails" do
it "responds with status 401" do it "responds with status 401" do
download('doesnt/exist.git', user: user.username, password: "nope") do |response| download('doesnt/exist.git', user: user.username, password: "nope") do |response|
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
end end
...@@ -31,7 +31,7 @@ describe 'Git HTTP requests', lib: true do ...@@ -31,7 +31,7 @@ describe 'Git HTTP requests', lib: true do
context "when authentication succeeds" do context "when authentication succeeds" do
it "responds with status 404" do it "responds with status 404" do
download('/doesnt/exist.git', user: user.username, password: user.password) do |response| download('/doesnt/exist.git', user: user.username, password: user.password) do |response|
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
end end
...@@ -46,7 +46,7 @@ describe 'Git HTTP requests', lib: true do ...@@ -46,7 +46,7 @@ describe 'Git HTTP requests', lib: true do
download("/#{wiki.repository.path_with_namespace}.git") do |response| download("/#{wiki.repository.path_with_namespace}.git") do |response|
json_body = ActiveSupport::JSON.decode(response.body) json_body = ActiveSupport::JSON.decode(response.body)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
expect(json_body['RepoPath']).to include(wiki.repository.path_with_namespace) expect(json_body['RepoPath']).to include(wiki.repository.path_with_namespace)
end end
end end
...@@ -62,13 +62,13 @@ describe 'Git HTTP requests', lib: true do ...@@ -62,13 +62,13 @@ describe 'Git HTTP requests', lib: true do
it "downloads get status 200" do it "downloads get status 200" do
download(path, {}) do |response| download(path, {}) do |response|
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
end end
it "uploads get status 401" do it "uploads get status 401" do
upload(path, {}) do |response| upload(path, {}) do |response|
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
...@@ -77,7 +77,7 @@ describe 'Git HTTP requests', lib: true do ...@@ -77,7 +77,7 @@ describe 'Git HTTP requests', lib: true do
it "uploads get status 200 (because Git hooks do the real check)" do it "uploads get status 200 (because Git hooks do the real check)" do
upload(path, env) do |response| upload(path, env) do |response|
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
end end
...@@ -86,7 +86,7 @@ describe 'Git HTTP requests', lib: true do ...@@ -86,7 +86,7 @@ describe 'Git HTTP requests', lib: true do
allow(Gitlab.config.gitlab_shell).to receive(:receive_pack).and_return(false) allow(Gitlab.config.gitlab_shell).to receive(:receive_pack).and_return(false)
upload(path, env) do |response| upload(path, env) do |response|
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
end end
...@@ -97,7 +97,7 @@ describe 'Git HTTP requests', lib: true do ...@@ -97,7 +97,7 @@ describe 'Git HTTP requests', lib: true do
allow(Gitlab.config.gitlab_shell).to receive(:upload_pack).and_return(false) allow(Gitlab.config.gitlab_shell).to receive(:upload_pack).and_return(false)
download(path, {}) do |response| download(path, {}) do |response|
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
end end
...@@ -111,13 +111,13 @@ describe 'Git HTTP requests', lib: true do ...@@ -111,13 +111,13 @@ describe 'Git HTTP requests', lib: true do
context "when no authentication is provided" do context "when no authentication is provided" do
it "responds with status 401 to downloads" do it "responds with status 401 to downloads" do
download(path, {}) do |response| download(path, {}) do |response|
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
it "responds with status 401 to uploads" do it "responds with status 401 to uploads" do
upload(path, {}) do |response| upload(path, {}) do |response|
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
end end
...@@ -128,7 +128,7 @@ describe 'Git HTTP requests', lib: true do ...@@ -128,7 +128,7 @@ describe 'Git HTTP requests', lib: true do
context "when authentication fails" do context "when authentication fails" do
it "responds with status 401" do it "responds with status 401" do
download(path, env) do |response| download(path, env) do |response|
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
...@@ -139,7 +139,7 @@ describe 'Git HTTP requests', lib: true do ...@@ -139,7 +139,7 @@ describe 'Git HTTP requests', lib: true do
clone_get(path, env) clone_get(path, env)
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
end end
...@@ -158,7 +158,7 @@ describe 'Git HTTP requests', lib: true do ...@@ -158,7 +158,7 @@ describe 'Git HTTP requests', lib: true do
project.team << [user, :master] project.team << [user, :master]
download(path, env) do |response| download(path, env) do |response|
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
end end
...@@ -169,12 +169,12 @@ describe 'Git HTTP requests', lib: true do ...@@ -169,12 +169,12 @@ describe 'Git HTTP requests', lib: true do
clone_get(path, env) clone_get(path, env)
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
it "uploads get status 200" do it "uploads get status 200" do
upload(path, env) do |response| upload(path, env) do |response|
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
end end
end end
...@@ -188,13 +188,13 @@ describe 'Git HTTP requests', lib: true do ...@@ -188,13 +188,13 @@ describe 'Git HTTP requests', lib: true do
it "downloads get status 200" do it "downloads get status 200" do
clone_get "#{project.path_with_namespace}.git", user: 'oauth2', password: @token.token clone_get "#{project.path_with_namespace}.git", user: 'oauth2', password: @token.token
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
it "uploads get status 401 (no project existence information leak)" do it "uploads get status 401 (no project existence information leak)" do
push_get "#{project.path_with_namespace}.git", user: 'oauth2', password: @token.token push_get "#{project.path_with_namespace}.git", user: 'oauth2', password: @token.token
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
...@@ -232,13 +232,13 @@ describe 'Git HTTP requests', lib: true do ...@@ -232,13 +232,13 @@ describe 'Git HTTP requests', lib: true do
context "when the user doesn't have access to the project" do context "when the user doesn't have access to the project" do
it "downloads get status 404" do it "downloads get status 404" do
download(path, user: user.username, password: user.password) do |response| download(path, user: user.username, password: user.password) do |response|
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
it "uploads get status 200 (because Git hooks do the real check)" do it "uploads get status 200 (because Git hooks do the real check)" do
upload(path, user: user.username, password: user.password) do |response| upload(path, user: user.username, password: user.password) do |response|
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
end end
end end
...@@ -256,13 +256,13 @@ describe 'Git HTTP requests', lib: true do ...@@ -256,13 +256,13 @@ describe 'Git HTTP requests', lib: true do
it "downloads get status 200" do it "downloads get status 200" do
clone_get "#{project.path_with_namespace}.git", user: 'gitlab-ci-token', password: token clone_get "#{project.path_with_namespace}.git", user: 'gitlab-ci-token', password: token
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
it "uploads get status 401 (no project existence information leak)" do it "uploads get status 401 (no project existence information leak)" do
push_get "#{project.path_with_namespace}.git", user: 'gitlab-ci-token', password: token push_get "#{project.path_with_namespace}.git", user: 'gitlab-ci-token', password: token
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
end end
...@@ -336,7 +336,7 @@ describe 'Git HTTP requests', lib: true do ...@@ -336,7 +336,7 @@ describe 'Git HTTP requests', lib: true do
end end
it "returns the file" do it "returns the file" do
expect(response.status).to eq(200) expect(response).to have_http_status(200)
end end
end end
...@@ -344,7 +344,7 @@ describe 'Git HTTP requests', lib: true do ...@@ -344,7 +344,7 @@ describe 'Git HTTP requests', lib: true do
before { get "/#{project.path_with_namespace}/blob/master/info/refs" } before { get "/#{project.path_with_namespace}/blob/master/info/refs" }
it "returns not found" do it "returns not found" do
expect(response.status).to eq(404) expect(response).to have_http_status(404)
end end
end end
end end
......
...@@ -11,12 +11,12 @@ describe JwtController do ...@@ -11,12 +11,12 @@ describe JwtController do
context 'existing service' do context 'existing service' do
subject! { get '/jwt/auth', parameters } subject! { get '/jwt/auth', parameters }
it { expect(response.status).to eq(200) } it { expect(response).to have_http_status(200) }
context 'returning custom http code' do context 'returning custom http code' do
let(:service) { double(execute: { http_status: 505 }) } let(:service) { double(execute: { http_status: 505 }) }
it { expect(response.status).to eq(505) } it { expect(response).to have_http_status(505) }
end end
end end
...@@ -36,7 +36,7 @@ describe JwtController do ...@@ -36,7 +36,7 @@ describe JwtController do
context 'project with disabled CI' do context 'project with disabled CI' do
let(:builds_enabled) { false } let(:builds_enabled) { false }
it { expect(response.status).to eq(403) } it { expect(response).to have_http_status(403) }
end end
end end
...@@ -56,14 +56,14 @@ describe JwtController do ...@@ -56,14 +56,14 @@ describe JwtController do
subject! { get '/jwt/auth', parameters, headers } subject! { get '/jwt/auth', parameters, headers }
it { expect(response.status).to eq(403) } it { expect(response).to have_http_status(403) }
end end
end end
context 'unknown service' do context 'unknown service' do
subject! { get '/jwt/auth', service: 'unknown' } subject! { get '/jwt/auth', service: 'unknown' }
it { expect(response.status).to eq(404) } it { expect(response).to have_http_status(404) }
end end
def credentials(login, password) def credentials(login, password)
......
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