diff options
Diffstat (limited to 'spec/requests')
95 files changed, 10580 insertions, 10555 deletions
diff --git a/spec/requests/api/access_requests_spec.rb b/spec/requests/api/access_requests_spec.rb index 1af6602ea9e..117fb672448 100644 --- a/spec/requests/api/access_requests_spec.rb +++ b/spec/requests/api/access_requests_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe API::AccessRequests do set(:maintainer) { create(:user) } @@ -22,16 +22,16 @@ describe API::AccessRequests do end end - shared_examples 'GET /:sources/:id/access_requests' do |source_type| + shared_examples "GET /:sources/:id/access_requests" do |source_type| context "with :sources == #{source_type.pluralize}" do - it_behaves_like 'a 404 response when source is private' do + it_behaves_like "a 404 response when source is private" do let(:route) { get api("/#{source_type.pluralize}/#{source.id}/access_requests", stranger) } end - context 'when authenticated as a non-maintainer/owner' do + context "when authenticated as a non-maintainer/owner" do %i[developer access_requester stranger].each do |type| context "as a #{type}" do - it 'returns 403' do + it "returns 403" do user = public_send(type) get api("/#{source_type.pluralize}/#{source.id}/access_requests", user) @@ -41,8 +41,8 @@ describe API::AccessRequests do end end - context 'when authenticated as a maintainer/owner' do - it 'returns access requesters' do + context "when authenticated as a maintainer/owner" do + it "returns access requesters" do get api("/#{source_type.pluralize}/#{source.id}/access_requests", maintainer) expect(response).to have_gitlab_http_status(200) @@ -54,84 +54,84 @@ describe API::AccessRequests do end end - shared_examples 'POST /:sources/:id/access_requests' do |source_type| + shared_examples "POST /:sources/:id/access_requests" do |source_type| context "with :sources == #{source_type.pluralize}" do - it_behaves_like 'a 404 response when source is private' do + it_behaves_like "a 404 response when source is private" do let(:route) { post api("/#{source_type.pluralize}/#{source.id}/access_requests", stranger) } end - context 'when authenticated as a member' do + context "when authenticated as a member" do %i[developer maintainer].each do |type| context "as a #{type}" do - it 'returns 403' do - expect do + it "returns 403" do + expect { user = public_send(type) post api("/#{source_type.pluralize}/#{source.id}/access_requests", user) expect(response).to have_gitlab_http_status(403) - end.not_to change { source.requesters.count } + }.not_to change { source.requesters.count } end end end end - context 'when authenticated as an access requester' do - it 'returns 400' do - expect do + context "when authenticated as an access requester" do + it "returns 400" do + expect { post api("/#{source_type.pluralize}/#{source.id}/access_requests", access_requester) expect(response).to have_gitlab_http_status(400) - end.not_to change { source.requesters.count } + }.not_to change { source.requesters.count } end end - context 'when authenticated as a stranger' do + context "when authenticated as a stranger" do context "when access request is disabled for the #{source_type}" do before do source.update(request_access_enabled: false) end - it 'returns 403' do - expect do + it "returns 403" do + expect { post api("/#{source_type.pluralize}/#{source.id}/access_requests", stranger) expect(response).to have_gitlab_http_status(403) - end.not_to change { source.requesters.count } + }.not_to change { source.requesters.count } end end - it 'returns 201' do - expect do + it "returns 201" do + expect { post api("/#{source_type.pluralize}/#{source.id}/access_requests", stranger) expect(response).to have_gitlab_http_status(201) - end.to change { source.requesters.count }.by(1) + }.to change { source.requesters.count }.by(1) # User attributes - expect(json_response['id']).to eq(stranger.id) - expect(json_response['name']).to eq(stranger.name) - expect(json_response['username']).to eq(stranger.username) - expect(json_response['state']).to eq(stranger.state) - expect(json_response['avatar_url']).to eq(stranger.avatar_url) - expect(json_response['web_url']).to eq(Gitlab::Routing.url_helpers.user_url(stranger)) + expect(json_response["id"]).to eq(stranger.id) + expect(json_response["name"]).to eq(stranger.name) + expect(json_response["username"]).to eq(stranger.username) + expect(json_response["state"]).to eq(stranger.state) + expect(json_response["avatar_url"]).to eq(stranger.avatar_url) + expect(json_response["web_url"]).to eq(Gitlab::Routing.url_helpers.user_url(stranger)) # Member attributes - expect(json_response['requested_at']).to be_present + expect(json_response["requested_at"]).to be_present end end end end - shared_examples 'PUT /:sources/:id/access_requests/:user_id/approve' do |source_type| + shared_examples "PUT /:sources/:id/access_requests/:user_id/approve" do |source_type| context "with :sources == #{source_type.pluralize}" do - it_behaves_like 'a 404 response when source is private' do + it_behaves_like "a 404 response when source is private" do let(:route) { put api("/#{source_type.pluralize}/#{source.id}/access_requests/#{access_requester.id}/approve", stranger) } end - context 'when authenticated as a non-maintainer/owner' do + context "when authenticated as a non-maintainer/owner" do %i[developer access_requester stranger].each do |type| context "as a #{type}" do - it 'returns 403' do + it "returns 403" do user = public_send(type) put api("/#{source_type.pluralize}/#{source.id}/access_requests/#{access_requester.id}/approve", user) @@ -141,49 +141,49 @@ describe API::AccessRequests do end end - context 'when authenticated as a maintainer/owner' do - it 'returns 201' do - expect do + context "when authenticated as a maintainer/owner" do + it "returns 201" do + expect { put api("/#{source_type.pluralize}/#{source.id}/access_requests/#{access_requester.id}/approve", maintainer), - params: { access_level: Member::MAINTAINER } + params: {access_level: Member::MAINTAINER} expect(response).to have_gitlab_http_status(201) - end.to change { source.members.count }.by(1) + }.to change { source.members.count }.by(1) # User attributes - expect(json_response['id']).to eq(access_requester.id) - expect(json_response['name']).to eq(access_requester.name) - expect(json_response['username']).to eq(access_requester.username) - expect(json_response['state']).to eq(access_requester.state) - expect(json_response['avatar_url']).to eq(access_requester.avatar_url) - expect(json_response['web_url']).to eq(Gitlab::Routing.url_helpers.user_url(access_requester)) + expect(json_response["id"]).to eq(access_requester.id) + expect(json_response["name"]).to eq(access_requester.name) + expect(json_response["username"]).to eq(access_requester.username) + expect(json_response["state"]).to eq(access_requester.state) + expect(json_response["avatar_url"]).to eq(access_requester.avatar_url) + expect(json_response["web_url"]).to eq(Gitlab::Routing.url_helpers.user_url(access_requester)) # Member attributes - expect(json_response['access_level']).to eq(Member::MAINTAINER) + expect(json_response["access_level"]).to eq(Member::MAINTAINER) end - context 'user_id does not match an existing access requester' do - it 'returns 404' do - expect do + context "user_id does not match an existing access requester" do + it "returns 404" do + expect { put api("/#{source_type.pluralize}/#{source.id}/access_requests/#{stranger.id}/approve", maintainer) expect(response).to have_gitlab_http_status(404) - end.not_to change { source.members.count } + }.not_to change { source.members.count } end end end end end - shared_examples 'DELETE /:sources/:id/access_requests/:user_id' do |source_type| + shared_examples "DELETE /:sources/:id/access_requests/:user_id" do |source_type| context "with :sources == #{source_type.pluralize}" do - it_behaves_like 'a 404 response when source is private' do + it_behaves_like "a 404 response when source is private" do let(:route) { delete api("/#{source_type.pluralize}/#{source.id}/access_requests/#{access_requester.id}", stranger) } end - context 'when authenticated as a non-maintainer/owner' do + context "when authenticated as a non-maintainer/owner" do %i[developer stranger].each do |type| context "as a #{type}" do - it 'returns 403' do + it "returns 403" do user = public_send(type) delete api("/#{source_type.pluralize}/#{source.id}/access_requests/#{access_requester.id}", user) @@ -193,77 +193,77 @@ describe API::AccessRequests do end end - context 'when authenticated as the access requester' do - it 'deletes the access requester' do - expect do + context "when authenticated as the access requester" do + it "deletes the access requester" do + expect { delete api("/#{source_type.pluralize}/#{source.id}/access_requests/#{access_requester.id}", access_requester) expect(response).to have_gitlab_http_status(204) - end.to change { source.requesters.count }.by(-1) + }.to change { source.requesters.count }.by(-1) end end - context 'when authenticated as a maintainer/owner' do - it 'deletes the access requester' do - expect do + context "when authenticated as a maintainer/owner" do + it "deletes the access requester" do + expect { delete api("/#{source_type.pluralize}/#{source.id}/access_requests/#{access_requester.id}", maintainer) expect(response).to have_gitlab_http_status(204) - end.to change { source.requesters.count }.by(-1) + }.to change { source.requesters.count }.by(-1) end - context 'user_id matches a member, not an access requester' do - it 'returns 404' do - expect do + context "user_id matches a member, not an access requester" do + it "returns 404" do + expect { delete api("/#{source_type.pluralize}/#{source.id}/access_requests/#{developer.id}", maintainer) expect(response).to have_gitlab_http_status(404) - end.not_to change { source.requesters.count } + }.not_to change { source.requesters.count } end end - context 'user_id does not match an existing access requester' do - it 'returns 404' do - expect do + context "user_id does not match an existing access requester" do + it "returns 404" do + expect { delete api("/#{source_type.pluralize}/#{source.id}/access_requests/#{stranger.id}", maintainer) expect(response).to have_gitlab_http_status(404) - end.not_to change { source.requesters.count } + }.not_to change { source.requesters.count } end end end end end - it_behaves_like 'GET /:sources/:id/access_requests', 'project' do + it_behaves_like "GET /:sources/:id/access_requests", "project" do let(:source) { project } end - it_behaves_like 'GET /:sources/:id/access_requests', 'group' do + it_behaves_like "GET /:sources/:id/access_requests", "group" do let(:source) { group } end - it_behaves_like 'POST /:sources/:id/access_requests', 'project' do + it_behaves_like "POST /:sources/:id/access_requests", "project" do let(:source) { project } end - it_behaves_like 'POST /:sources/:id/access_requests', 'group' do + it_behaves_like "POST /:sources/:id/access_requests", "group" do let(:source) { group } end - it_behaves_like 'PUT /:sources/:id/access_requests/:user_id/approve', 'project' do + it_behaves_like "PUT /:sources/:id/access_requests/:user_id/approve", "project" do let(:source) { project } end - it_behaves_like 'PUT /:sources/:id/access_requests/:user_id/approve', 'group' do + it_behaves_like "PUT /:sources/:id/access_requests/:user_id/approve", "group" do let(:source) { group } end - it_behaves_like 'DELETE /:sources/:id/access_requests/:user_id', 'project' do + it_behaves_like "DELETE /:sources/:id/access_requests/:user_id", "project" do let(:source) { project } end - it_behaves_like 'DELETE /:sources/:id/access_requests/:user_id', 'group' do + it_behaves_like "DELETE /:sources/:id/access_requests/:user_id", "group" do let(:source) { group } end end diff --git a/spec/requests/api/applications_spec.rb b/spec/requests/api/applications_spec.rb index e47166544d9..1817d8638cf 100644 --- a/spec/requests/api/applications_spec.rb +++ b/spec/requests/api/applications_spec.rb @@ -1,148 +1,148 @@ -require 'spec_helper' +require "spec_helper" describe API::Applications, :api do include ApiHelpers let(:admin_user) { create(:user, admin: true) } let(:user) { create(:user, admin: false) } - let!(:application) { create(:application, name: 'another_application', redirect_uri: 'http://other_application.url', scopes: '') } + let!(:application) { create(:application, name: "another_application", redirect_uri: "http://other_application.url", scopes: "") } - describe 'POST /applications' do - context 'authenticated and authorized user' do - it 'creates and returns an OAuth application' do - expect do - post api('/applications', admin_user), params: { name: 'application_name', redirect_uri: 'http://application.url', scopes: '' } - end.to change { Doorkeeper::Application.count }.by 1 + describe "POST /applications" do + context "authenticated and authorized user" do + it "creates and returns an OAuth application" do + expect { + post api("/applications", admin_user), params: {name: "application_name", redirect_uri: "http://application.url", scopes: ""} + }.to change { Doorkeeper::Application.count }.by 1 - application = Doorkeeper::Application.find_by(name: 'application_name', redirect_uri: 'http://application.url') + application = Doorkeeper::Application.find_by(name: "application_name", redirect_uri: "http://application.url") expect(response).to have_gitlab_http_status(201) expect(json_response).to be_a Hash - expect(json_response['application_id']).to eq application.uid - expect(json_response['secret']).to eq application.secret - expect(json_response['callback_url']).to eq application.redirect_uri + expect(json_response["application_id"]).to eq application.uid + expect(json_response["secret"]).to eq application.secret + expect(json_response["callback_url"]).to eq application.redirect_uri end - it 'does not allow creating an application with the wrong redirect_uri format' do - expect do - post api('/applications', admin_user), params: { name: 'application_name', redirect_uri: 'http://', scopes: '' } - end.not_to change { Doorkeeper::Application.count } + it "does not allow creating an application with the wrong redirect_uri format" do + expect { + post api("/applications", admin_user), params: {name: "application_name", redirect_uri: "http://", scopes: ""} + }.not_to change { Doorkeeper::Application.count } expect(response).to have_gitlab_http_status(400) expect(json_response).to be_a Hash - expect(json_response['message']['redirect_uri'][0]).to eq('must be an absolute URI.') + expect(json_response["message"]["redirect_uri"][0]).to eq("must be an absolute URI.") end - it 'does not allow creating an application with a forbidden URI format' do - expect do - post api('/applications', admin_user), params: { name: 'application_name', redirect_uri: 'javascript://alert()', scopes: '' } - end.not_to change { Doorkeeper::Application.count } + it "does not allow creating an application with a forbidden URI format" do + expect { + post api("/applications", admin_user), params: {name: "application_name", redirect_uri: "javascript://alert()", scopes: ""} + }.not_to change { Doorkeeper::Application.count } expect(response).to have_gitlab_http_status(400) expect(json_response).to be_a Hash - expect(json_response['message']['redirect_uri'][0]).to eq('is forbidden by the server.') + expect(json_response["message"]["redirect_uri"][0]).to eq("is forbidden by the server.") end - it 'does not allow creating an application without a name' do - expect do - post api('/applications', admin_user), params: { redirect_uri: 'http://application.url', scopes: '' } - end.not_to change { Doorkeeper::Application.count } + it "does not allow creating an application without a name" do + expect { + post api("/applications", admin_user), params: {redirect_uri: "http://application.url", scopes: ""} + }.not_to change { Doorkeeper::Application.count } expect(response).to have_gitlab_http_status(400) expect(json_response).to be_a Hash - expect(json_response['error']).to eq('name is missing') + expect(json_response["error"]).to eq("name is missing") end - it 'does not allow creating an application without a redirect_uri' do - expect do - post api('/applications', admin_user), params: { name: 'application_name', scopes: '' } - end.not_to change { Doorkeeper::Application.count } + it "does not allow creating an application without a redirect_uri" do + expect { + post api("/applications", admin_user), params: {name: "application_name", scopes: ""} + }.not_to change { Doorkeeper::Application.count } expect(response).to have_gitlab_http_status(400) expect(json_response).to be_a Hash - expect(json_response['error']).to eq('redirect_uri is missing') + expect(json_response["error"]).to eq("redirect_uri is missing") end - it 'does not allow creating an application without scopes' do - expect do - post api('/applications', admin_user), params: { name: 'application_name', redirect_uri: 'http://application.url' } - end.not_to change { Doorkeeper::Application.count } + it "does not allow creating an application without scopes" do + expect { + post api("/applications", admin_user), params: {name: "application_name", redirect_uri: "http://application.url"} + }.not_to change { Doorkeeper::Application.count } expect(response).to have_gitlab_http_status(400) expect(json_response).to be_a Hash - expect(json_response['error']).to eq('scopes is missing') + expect(json_response["error"]).to eq("scopes is missing") end end - context 'authorized user without authorization' do - it 'does not create application' do - expect do - post api('/applications', user), params: { name: 'application_name', redirect_uri: 'http://application.url', scopes: '' } - end.not_to change { Doorkeeper::Application.count } + context "authorized user without authorization" do + it "does not create application" do + expect { + post api("/applications", user), params: {name: "application_name", redirect_uri: "http://application.url", scopes: ""} + }.not_to change { Doorkeeper::Application.count } expect(response).to have_gitlab_http_status(403) end end - context 'non-authenticated user' do - it 'does not create application' do - expect do - post api('/applications'), params: { name: 'application_name', redirect_uri: 'http://application.url' } - end.not_to change { Doorkeeper::Application.count } + context "non-authenticated user" do + it "does not create application" do + expect { + post api("/applications"), params: {name: "application_name", redirect_uri: "http://application.url"} + }.not_to change { Doorkeeper::Application.count } expect(response).to have_gitlab_http_status(401) end end end - describe 'GET /applications' do - context 'authenticated and authorized user' do - it 'can list application' do - get api('/applications', admin_user) + describe "GET /applications" do + context "authenticated and authorized user" do + it "can list application" do + get api("/applications", admin_user) expect(response).to have_gitlab_http_status(200) expect(json_response).to be_a(Array) end end - context 'authorized user without authorization' do - it 'cannot list application' do - get api('/applications', user) + context "authorized user without authorization" do + it "cannot list application" do + get api("/applications", user) expect(response).to have_gitlab_http_status(403) end end - context 'non-authenticated user' do - it 'cannot list application' do - get api('/applications') + context "non-authenticated user" do + it "cannot list application" do + get api("/applications") expect(response).to have_gitlab_http_status(401) end end end - describe 'DELETE /applications/:id' do - context 'authenticated and authorized user' do - it 'can delete an application' do - expect do + describe "DELETE /applications/:id" do + context "authenticated and authorized user" do + it "can delete an application" do + expect { delete api("/applications/#{application.id}", admin_user) - end.to change { Doorkeeper::Application.count }.by(-1) + }.to change { Doorkeeper::Application.count }.by(-1) expect(response).to have_gitlab_http_status(204) end end - context 'authorized user without authorization' do - it 'cannot delete an application' do + context "authorized user without authorization" do + it "cannot delete an application" do delete api("/applications/#{application.id}", user) expect(response).to have_gitlab_http_status(403) end end - context 'non-authenticated user' do - it 'cannot delete an application' do + context "non-authenticated user" do + it "cannot delete an application" do delete api("/applications/#{application.id}") expect(response).to have_gitlab_http_status(401) diff --git a/spec/requests/api/avatar_spec.rb b/spec/requests/api/avatar_spec.rb index 9bc49bd5982..bbf73ec5107 100644 --- a/spec/requests/api/avatar_spec.rb +++ b/spec/requests/api/avatar_spec.rb @@ -1,46 +1,47 @@ -require 'spec_helper' +require "spec_helper" describe API::Avatar do - let(:gravatar_service) { double('GravatarService') } + let(:gravatar_service) { double("GravatarService") } - describe 'GET /avatar' do - context 'avatar uploaded to GitLab' do - context 'user with matching public email address' do - let(:user) { create(:user, :with_avatar, email: 'public@example.com', public_email: 'public@example.com') } + describe "GET /avatar" do + context "avatar uploaded to GitLab" do + context "user with matching public email address" do + let(:user) { create(:user, :with_avatar, email: "public@example.com", public_email: "public@example.com") } before do user end - it 'returns the avatar url' do - get api('/avatar'), params: { email: 'public@example.com' } + it "returns the avatar url" do + get api("/avatar"), params: {email: "public@example.com"} expect(response.status).to eq 200 - expect(json_response['avatar_url']).to eql("#{::Settings.gitlab.base_url}#{user.avatar.local_url}") + expect(json_response["avatar_url"]).to eql("#{::Settings.gitlab.base_url}#{user.avatar.local_url}") end end - context 'no user with matching public email address' do + context "no user with matching public email address" do before do expect(GravatarService).to receive(:new).and_return(gravatar_service) expect(gravatar_service).to( receive(:execute) - .with('private@example.com', nil, 2, { username: nil }) - .and_return('https://gravatar')) + .with("private@example.com", nil, 2, {username: nil}) + .and_return("https://gravatar") + ) end - it 'returns the avatar url from Gravatar' do - get api('/avatar'), params: { email: 'private@example.com' } + it "returns the avatar url from Gravatar" do + get api("/avatar"), params: {email: "private@example.com"} expect(response.status).to eq 200 - expect(json_response['avatar_url']).to eq('https://gravatar') + expect(json_response["avatar_url"]).to eq("https://gravatar") end end end - context 'avatar uploaded to Gravatar' do - context 'user with matching public email address' do - let(:user) { create(:user, email: 'public@example.com', public_email: 'public@example.com') } + context "avatar uploaded to Gravatar" do + context "user with matching public email address" do + let(:user) { create(:user, email: "public@example.com", public_email: "public@example.com") } before do user @@ -48,37 +49,39 @@ describe API::Avatar do expect(GravatarService).to receive(:new).and_return(gravatar_service) expect(gravatar_service).to( receive(:execute) - .with('public@example.com', nil, 2, { username: user.username }) - .and_return('https://gravatar')) + .with("public@example.com", nil, 2, {username: user.username}) + .and_return("https://gravatar") + ) end - it 'returns the avatar url from Gravatar' do - get api('/avatar'), params: { email: 'public@example.com' } + it "returns the avatar url from Gravatar" do + get api("/avatar"), params: {email: "public@example.com"} expect(response.status).to eq 200 - expect(json_response['avatar_url']).to eq('https://gravatar') + expect(json_response["avatar_url"]).to eq("https://gravatar") end end - context 'no user with matching public email address' do + context "no user with matching public email address" do before do expect(GravatarService).to receive(:new).and_return(gravatar_service) expect(gravatar_service).to( receive(:execute) - .with('private@example.com', nil, 2, { username: nil }) - .and_return('https://gravatar')) + .with("private@example.com", nil, 2, {username: nil}) + .and_return("https://gravatar") + ) end - it 'returns the avatar url from Gravatar' do - get api('/avatar'), params: { email: 'private@example.com' } + it "returns the avatar url from Gravatar" do + get api("/avatar"), params: {email: "private@example.com"} expect(response.status).to eq 200 - expect(json_response['avatar_url']).to eq('https://gravatar') + expect(json_response["avatar_url"]).to eq("https://gravatar") end end - context 'public visibility level restricted' do - let(:user) { create(:user, :with_avatar, email: 'public@example.com', public_email: 'public@example.com') } + context "public visibility level restricted" do + let(:user) { create(:user, :with_avatar, email: "public@example.com", public_email: "public@example.com") } before do user @@ -86,18 +89,18 @@ describe API::Avatar do stub_application_setting(restricted_visibility_levels: [Gitlab::VisibilityLevel::PUBLIC]) end - context 'when authenticated' do - it 'returns the avatar url' do - get api('/avatar', user), params: { email: 'public@example.com' } + context "when authenticated" do + it "returns the avatar url" do + get api("/avatar", user), params: {email: "public@example.com"} expect(response.status).to eq 200 - expect(json_response['avatar_url']).to eql("#{::Settings.gitlab.base_url}#{user.avatar.local_url}") + expect(json_response["avatar_url"]).to eql("#{::Settings.gitlab.base_url}#{user.avatar.local_url}") end end - context 'when unauthenticated' do - it_behaves_like '403 response' do - let(:request) { get api('/avatar'), params: { email: 'public@example.com' } } + context "when unauthenticated" do + it_behaves_like "403 response" do + let(:request) { get api("/avatar"), params: {email: "public@example.com"} } end end end diff --git a/spec/requests/api/award_emoji_spec.rb b/spec/requests/api/award_emoji_spec.rb index 6c67d84b59b..08d20bd3bf6 100644 --- a/spec/requests/api/award_emoji_spec.rb +++ b/spec/requests/api/award_emoji_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe API::AwardEmoji do set(:user) { create(:user) } @@ -14,13 +14,13 @@ describe API::AwardEmoji do end describe "GET /projects/:id/awardable/:awardable_id/award_emoji" do - context 'on an issue' do + context "on an issue" do it "returns an array of award_emoji" do get api("/projects/#{project.id}/issues/#{issue.iid}/award_emoji", user) expect(response).to have_gitlab_http_status(200) 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 it "returns a 404 error when issue id not found" do @@ -30,32 +30,32 @@ describe API::AwardEmoji do end end - context 'on a merge request' do + context "on a merge request" do it "returns an array of award_emoji" do get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/award_emoji", user) expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers 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 - context 'on a snippet' do + context "on a snippet" do let(:snippet) { create(:project_snippet, :public, project: project) } let!(:award) { create(:award_emoji, awardable: snippet) } - it 'returns the awarded emoji' do + it "returns the awarded emoji" do get api("/projects/#{project.id}/snippets/#{snippet.id}/award_emoji", user) expect(response).to have_gitlab_http_status(200) expect(json_response).to be_an Array - expect(json_response.first['name']).to eq(award.name) + expect(json_response.first["name"]).to eq(award.name) end end - context 'when the user has no access' do - it 'returns a status code 404' do + context "when the user has no access" do + it "returns a status code 404" do user1 = create(:user) get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/award_emoji", user1) @@ -65,27 +65,27 @@ describe API::AwardEmoji do end end - describe 'GET /projects/:id/awardable/:awardable_id/notes/:note_id/award_emoji' do - let!(:rocket) { create(:award_emoji, awardable: note, name: 'rocket') } + describe "GET /projects/:id/awardable/:awardable_id/notes/:note_id/award_emoji" do + let!(:rocket) { create(:award_emoji, awardable: note, name: "rocket") } - it 'returns an array of award emoji' do + it "returns an array of award emoji" do get api("/projects/#{project.id}/issues/#{issue.iid}/notes/#{note.id}/award_emoji", user) expect(response).to have_gitlab_http_status(200) 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 describe "GET /projects/:id/awardable/:awardable_id/award_emoji/:award_id" do - context 'on an issue' do + context "on an issue" do it "returns the award emoji" do get api("/projects/#{project.id}/issues/#{issue.iid}/award_emoji/#{award_emoji.id}", user) expect(response).to have_gitlab_http_status(200) - expect(json_response['name']).to eq(award_emoji.name) - expect(json_response['awardable_id']).to eq(issue.id) - expect(json_response['awardable_type']).to eq("Issue") + expect(json_response["name"]).to eq(award_emoji.name) + expect(json_response["awardable_id"]).to eq(issue.id) + expect(json_response["awardable_type"]).to eq("Issue") end it "returns a 404 error if the award is not found" do @@ -95,33 +95,33 @@ describe API::AwardEmoji do end end - context 'on a merge request' do - it 'returns the award emoji' do + context "on a merge request" do + it "returns the award emoji" do get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/award_emoji/#{downvote.id}", user) expect(response).to have_gitlab_http_status(200) - expect(json_response['name']).to eq(downvote.name) - expect(json_response['awardable_id']).to eq(merge_request.id) - expect(json_response['awardable_type']).to eq("MergeRequest") + expect(json_response["name"]).to eq(downvote.name) + expect(json_response["awardable_id"]).to eq(merge_request.id) + expect(json_response["awardable_type"]).to eq("MergeRequest") end end - context 'on a snippet' do + context "on a snippet" do let(:snippet) { create(:project_snippet, :public, project: project) } let!(:award) { create(:award_emoji, awardable: snippet) } - it 'returns the awarded emoji' do + it "returns the awarded emoji" do get api("/projects/#{project.id}/snippets/#{snippet.id}/award_emoji/#{award.id}", user) expect(response).to have_gitlab_http_status(200) - expect(json_response['name']).to eq(award.name) - expect(json_response['awardable_id']).to eq(snippet.id) - expect(json_response['awardable_type']).to eq("Snippet") + expect(json_response["name"]).to eq(award.name) + expect(json_response["awardable_id"]).to eq(snippet.id) + expect(json_response["awardable_type"]).to eq("Snippet") end end - context 'when the user has no access' do - it 'returns a status code 404' do + context "when the user has no access" do + it "returns a status code 404" do user1 = create(:user) get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/award_emoji/#{downvote.id}", user1) @@ -131,15 +131,15 @@ describe API::AwardEmoji do end end - describe 'GET /projects/:id/awardable/:awardable_id/notes/:note_id/award_emoji/:award_id' do - let!(:rocket) { create(:award_emoji, awardable: note, name: 'rocket') } + describe "GET /projects/:id/awardable/:awardable_id/notes/:note_id/award_emoji/:award_id" do + let!(:rocket) { create(:award_emoji, awardable: note, name: "rocket") } - it 'returns an award emoji' do + it "returns an award emoji" do get api("/projects/#{project.id}/issues/#{issue.iid}/notes/#{note.id}/award_emoji/#{rocket.id}", user) expect(response).to have_gitlab_http_status(200) 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 @@ -148,11 +148,11 @@ describe API::AwardEmoji do context "on an issue" do it "creates a new award emoji" do - post api("/projects/#{project.id}/issues/#{issue.iid}/award_emoji", user), params: { name: 'blowfish' } + post api("/projects/#{project.id}/issues/#{issue.iid}/award_emoji", user), params: {name: "blowfish"} expect(response).to have_gitlab_http_status(201) - expect(json_response['name']).to eq('blowfish') - expect(json_response['user']['username']).to eq(user.username) + expect(json_response["name"]).to eq("blowfish") + expect(json_response["user"]["username"]).to eq(user.username) end it "returns a 400 bad request error if the name is not given" do @@ -162,21 +162,21 @@ describe API::AwardEmoji do end it "returns a 401 unauthorized error if the user is not authenticated" do - post api("/projects/#{project.id}/issues/#{issue.iid}/award_emoji"), params: { name: 'thumbsup' } + post api("/projects/#{project.id}/issues/#{issue.iid}/award_emoji"), params: {name: "thumbsup"} expect(response).to have_gitlab_http_status(401) end it "normalizes +1 as thumbsup award" do - post api("/projects/#{project.id}/issues/#{issue.iid}/award_emoji", user), params: { name: '+1' } + post api("/projects/#{project.id}/issues/#{issue.iid}/award_emoji", user), params: {name: "+1"} expect(issue.award_emoji.last.name).to eq("thumbsup") end - context 'when the emoji already has been awarded' do - it 'returns a 404 status code' do - post api("/projects/#{project.id}/issues/#{issue.iid}/award_emoji", user), params: { name: 'thumbsup' } - post api("/projects/#{project.id}/issues/#{issue.iid}/award_emoji", user), params: { name: 'thumbsup' } + context "when the emoji already has been awarded" do + it "returns a 404 status code" do + post api("/projects/#{project.id}/issues/#{issue.iid}/award_emoji", user), params: {name: "thumbsup"} + post api("/projects/#{project.id}/issues/#{issue.iid}/award_emoji", user), params: {name: "thumbsup"} expect(response).to have_gitlab_http_status(404) expect(json_response["message"]).to match("has already been taken") @@ -184,15 +184,15 @@ describe API::AwardEmoji do end end - context 'on a snippet' do - it 'creates a new award emoji' do + context "on a snippet" do + it "creates a new award emoji" do snippet = create(:project_snippet, :public, project: project) - post api("/projects/#{project.id}/snippets/#{snippet.id}/award_emoji", user), params: { name: 'blowfish' } + post api("/projects/#{project.id}/snippets/#{snippet.id}/award_emoji", user), params: {name: "blowfish"} expect(response).to have_gitlab_http_status(201) - expect(json_response['name']).to eq('blowfish') - expect(json_response['user']['username']).to eq(user.username) + expect(json_response["name"]).to eq("blowfish") + expect(json_response["user"]["username"]).to eq(user.username) end end end @@ -200,25 +200,25 @@ describe API::AwardEmoji do describe "POST /projects/:id/awardable/:awardable_id/notes/:note_id/award_emoji" do let(:note2) { create(:note, project: project, noteable: issue, author: user) } - it 'creates a new award emoji' do - expect do - post api("/projects/#{project.id}/issues/#{issue.iid}/notes/#{note.id}/award_emoji", user), params: { name: 'rocket' } - end.to change { note.award_emoji.count }.from(0).to(1) + it "creates a new award emoji" do + expect { + post api("/projects/#{project.id}/issues/#{issue.iid}/notes/#{note.id}/award_emoji", user), params: {name: "rocket"} + }.to change { note.award_emoji.count }.from(0).to(1) expect(response).to have_gitlab_http_status(201) - expect(json_response['user']['username']).to eq(user.username) + expect(json_response["user"]["username"]).to eq(user.username) end it "normalizes +1 as thumbsup award" do - post api("/projects/#{project.id}/issues/#{issue.iid}/notes/#{note.id}/award_emoji", user), params: { name: '+1' } + post api("/projects/#{project.id}/issues/#{issue.iid}/notes/#{note.id}/award_emoji", user), params: {name: "+1"} expect(note.award_emoji.last.name).to eq("thumbsup") end - context 'when the emoji already has been awarded' do - it 'returns a 404 status code' do - post api("/projects/#{project.id}/issues/#{issue.iid}/notes/#{note.id}/award_emoji", user), params: { name: 'rocket' } - post api("/projects/#{project.id}/issues/#{issue.iid}/notes/#{note.id}/award_emoji", user), params: { name: 'rocket' } + context "when the emoji already has been awarded" do + it "returns a 404 status code" do + post api("/projects/#{project.id}/issues/#{issue.iid}/notes/#{note.id}/award_emoji", user), params: {name: "rocket"} + post api("/projects/#{project.id}/issues/#{issue.iid}/notes/#{note.id}/award_emoji", user), params: {name: "rocket"} expect(response).to have_gitlab_http_status(404) expect(json_response["message"]).to match("has already been taken") @@ -226,77 +226,77 @@ describe API::AwardEmoji do end end - describe 'DELETE /projects/:id/awardable/:awardable_id/award_emoji/:award_id' do - context 'when the awardable is an Issue' do - it 'deletes the award' do - expect do + describe "DELETE /projects/:id/awardable/:awardable_id/award_emoji/:award_id" do + context "when the awardable is an Issue" do + it "deletes the award" do + expect { delete api("/projects/#{project.id}/issues/#{issue.iid}/award_emoji/#{award_emoji.id}", user) expect(response).to have_gitlab_http_status(204) - end.to change { issue.award_emoji.count }.from(1).to(0) + }.to change { issue.award_emoji.count }.from(1).to(0) 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.iid}/award_emoji/12345", user) expect(response).to have_gitlab_http_status(404) end - it_behaves_like '412 response' do + it_behaves_like "412 response" do let(:request) { api("/projects/#{project.id}/issues/#{issue.iid}/award_emoji/#{award_emoji.id}", user) } end end - context 'when the awardable is a Merge Request' do - it 'deletes the award' do - expect do + context "when the awardable is a Merge Request" do + it "deletes the award" do + expect { delete api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/award_emoji/#{downvote.id}", user) expect(response).to have_gitlab_http_status(204) - end.to change { merge_request.award_emoji.count }.from(1).to(0) + }.to change { merge_request.award_emoji.count }.from(1).to(0) 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.iid}/notes/12345", user) expect(response).to have_gitlab_http_status(404) end - it_behaves_like '412 response' do + it_behaves_like "412 response" do let(:request) { api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/award_emoji/#{downvote.id}", user) } end end - context 'when the awardable is a Snippet' do + context "when the awardable is a Snippet" do let(:snippet) { create(:project_snippet, :public, project: project) } let!(:award) { create(:award_emoji, awardable: snippet, user: user) } - it 'deletes the award' do - expect do + it "deletes the award" do + expect { delete api("/projects/#{project.id}/snippets/#{snippet.id}/award_emoji/#{award.id}", user) expect(response).to have_gitlab_http_status(204) - end.to change { snippet.award_emoji.count }.from(1).to(0) + }.to change { snippet.award_emoji.count }.from(1).to(0) end - it_behaves_like '412 response' do + it_behaves_like "412 response" do let(:request) { api("/projects/#{project.id}/snippets/#{snippet.id}/award_emoji/#{award.id}", user) } end end end - describe 'DELETE /projects/:id/awardable/:awardable_id/award_emoji/:award_emoji_id' do - let!(:rocket) { create(:award_emoji, awardable: note, name: 'rocket', user: user) } + describe "DELETE /projects/:id/awardable/:awardable_id/award_emoji/:award_emoji_id" do + let!(:rocket) { create(:award_emoji, awardable: note, name: "rocket", user: user) } - it 'deletes the award' do - expect do + it "deletes the award" do + expect { delete api("/projects/#{project.id}/issues/#{issue.iid}/notes/#{note.id}/award_emoji/#{rocket.id}", user) expect(response).to have_gitlab_http_status(204) - end.to change { note.award_emoji.count }.from(1).to(0) + }.to change { note.award_emoji.count }.from(1).to(0) end - it_behaves_like '412 response' do + it_behaves_like "412 response" do let(:request) { api("/projects/#{project.id}/issues/#{issue.iid}/notes/#{note.id}/award_emoji/#{rocket.id}", user) } end end diff --git a/spec/requests/api/badges_spec.rb b/spec/requests/api/badges_spec.rb index 1271324a2ba..9578905d8fc 100644 --- a/spec/requests/api/badges_spec.rb +++ b/spec/requests/api/badges_spec.rb @@ -1,7 +1,7 @@ -require 'spec_helper' +require "spec_helper" describe API::Badges do - let(:maintainer) { create(:user, username: 'maintainer_user') } + let(:maintainer) { create(:user, username: "maintainer_user") } let(:developer) { create(:user) } let(:access_requester) { create(:user) } let(:stranger) { create(:user) } @@ -9,27 +9,27 @@ describe API::Badges do let(:project) { setup_project } let!(:group) { setup_group } - shared_context 'source helpers' do + shared_context "source helpers" do def get_source(source_type) - source_type == 'project' ? project : group + source_type == "project" ? project : group end end - shared_examples 'GET /:sources/:id/badges' do |source_type| - include_context 'source helpers' + shared_examples "GET /:sources/:id/badges" do |source_type| + include_context "source helpers" let(:source) { get_source(source_type) } context "with :sources == #{source_type.pluralize}" do - it_behaves_like 'a 404 response when source is private' do + it_behaves_like "a 404 response when source is private" do let(:route) { get api("/#{source_type.pluralize}/#{source.id}/badges", stranger) } end %i[maintainer developer access_requester stranger].each do |type| context "when authenticated as a #{type}" do - it 'returns 200' do + it "returns 200" do user = public_send(type) - badges_count = source_type == 'project' ? 3 : 2 + badges_count = source_type == "project" ? 3 : 2 get api("/#{source_type.pluralize}/#{source.id}/badges", user) @@ -41,50 +41,50 @@ describe API::Badges do end end - it 'avoids N+1 queries' do + it "avoids N+1 queries" do # Establish baseline get api("/#{source_type.pluralize}/#{source.id}/badges", maintainer) - control = ActiveRecord::QueryRecorder.new do + control = ActiveRecord::QueryRecorder.new { get api("/#{source_type.pluralize}/#{source.id}/badges", maintainer) - end + } project.add_developer(create(:user)) - expect do + expect { get api("/#{source_type.pluralize}/#{source.id}/badges", maintainer) - end.not_to exceed_query_limit(control) + }.not_to exceed_query_limit(control) end end end - shared_examples 'GET /:sources/:id/badges/:badge_id' do |source_type| - include_context 'source helpers' + shared_examples "GET /:sources/:id/badges/:badge_id" do |source_type| + include_context "source helpers" let(:source) { get_source(source_type) } context "with :sources == #{source_type.pluralize}" do - it_behaves_like 'a 404 response when source is private' do + it_behaves_like "a 404 response when source is private" do let(:route) { get api("/#{source_type.pluralize}/#{source.id}/badges/#{developer.id}", stranger) } end - context 'when authenticated as a non-member' do + context "when authenticated as a non-member" do %i[maintainer developer access_requester stranger].each do |type| let(:badge) { source.badges.first } context "as a #{type}" do - it 'returns 200' do + it "returns 200" do user = public_send(type) get api("/#{source_type.pluralize}/#{source.id}/badges/#{badge.id}", user) expect(response).to have_gitlab_http_status(200) - expect(json_response['id']).to eq(badge.id) - expect(json_response['link_url']).to eq(badge.link_url) - expect(json_response['rendered_link_url']).to eq(badge.rendered_link_url) - expect(json_response['image_url']).to eq(badge.image_url) - expect(json_response['rendered_image_url']).to eq(badge.rendered_image_url) - expect(json_response['kind']).to eq source_type + expect(json_response["id"]).to eq(badge.id) + expect(json_response["link_url"]).to eq(badge.link_url) + expect(json_response["rendered_link_url"]).to eq(badge.rendered_link_url) + expect(json_response["image_url"]).to eq(badge.image_url) + expect(json_response["rendered_image_url"]).to eq(badge.rendered_image_url) + expect(json_response["kind"]).to eq source_type end end end @@ -92,29 +92,29 @@ describe API::Badges do end end - shared_examples 'POST /:sources/:id/badges' do |source_type| - include_context 'source helpers' + shared_examples "POST /:sources/:id/badges" do |source_type| + include_context "source helpers" let(:source) { get_source(source_type) } - let(:example_url) { 'http://www.example.com' } - let(:example_url2) { 'http://www.example1.com' } + let(:example_url) { "http://www.example.com" } + let(:example_url2) { "http://www.example1.com" } context "with :sources == #{source_type.pluralize}" do - it_behaves_like 'a 404 response when source is private' do + it_behaves_like "a 404 response when source is private" do let(:route) do post api("/#{source_type.pluralize}/#{source.id}/badges", stranger), - params: { link_url: example_url, image_url: example_url2 } + params: {link_url: example_url, image_url: example_url2} end end - context 'when authenticated as a non-member or member with insufficient rights' do + context "when authenticated as a non-member or member with insufficient rights" do %i[access_requester stranger developer].each do |type| context "as a #{type}" do - it 'returns 403' do + it "returns 403" do user = public_send(type) post api("/#{source_type.pluralize}/#{source.id}/badges", user), - params: { link_url: example_url, image_url: example_url2 } + params: {link_url: example_url, image_url: example_url2} expect(response).to have_gitlab_http_status(403) end @@ -122,69 +122,69 @@ describe API::Badges do end end - context 'when authenticated as a maintainer/owner' do - it 'creates a new badge' do - expect do + context "when authenticated as a maintainer/owner" do + it "creates a new badge" do + expect { post api("/#{source_type.pluralize}/#{source.id}/badges", maintainer), - params: { link_url: example_url, image_url: example_url2 } + params: {link_url: example_url, image_url: example_url2} expect(response).to have_gitlab_http_status(201) - end.to change { source.badges.count }.by(1) + }.to change { source.badges.count }.by(1) - expect(json_response['link_url']).to eq(example_url) - expect(json_response['image_url']).to eq(example_url2) - expect(json_response['kind']).to eq source_type + expect(json_response["link_url"]).to eq(example_url) + expect(json_response["image_url"]).to eq(example_url2) + expect(json_response["kind"]).to eq source_type end end - it 'returns 400 when link_url is not given' do + it "returns 400 when link_url is not given" do post api("/#{source_type.pluralize}/#{source.id}/badges", maintainer), - params: { link_url: example_url } + params: {link_url: example_url} expect(response).to have_gitlab_http_status(400) end - it 'returns 400 when image_url is not given' do + it "returns 400 when image_url is not given" do post api("/#{source_type.pluralize}/#{source.id}/badges", maintainer), - params: { image_url: example_url2 } + params: {image_url: example_url2} expect(response).to have_gitlab_http_status(400) end - it 'returns 400 when link_url or image_url is not valid' do + it "returns 400 when link_url or image_url is not valid" do post api("/#{source_type.pluralize}/#{source.id}/badges", maintainer), - params: { link_url: 'whatever', image_url: 'whatever' } + params: {link_url: "whatever", image_url: "whatever"} expect(response).to have_gitlab_http_status(400) end end end - shared_examples 'PUT /:sources/:id/badges/:badge_id' do |source_type| - include_context 'source helpers' + shared_examples "PUT /:sources/:id/badges/:badge_id" do |source_type| + include_context "source helpers" let(:source) { get_source(source_type) } context "with :sources == #{source_type.pluralize}" do let(:badge) { source.badges.first } - let(:example_url) { 'http://www.example.com' } - let(:example_url2) { 'http://www.example1.com' } + let(:example_url) { "http://www.example.com" } + let(:example_url2) { "http://www.example1.com" } - it_behaves_like 'a 404 response when source is private' do + it_behaves_like "a 404 response when source is private" do let(:route) do put api("/#{source_type.pluralize}/#{source.id}/badges/#{badge.id}", stranger), - params: { link_url: example_url } + params: {link_url: example_url} end end - context 'when authenticated as a non-member or member with insufficient rights' do + context "when authenticated as a non-member or member with insufficient rights" do %i[access_requester stranger developer].each do |type| context "as a #{type}" do - it 'returns 403' do + it "returns 403" do user = public_send(type) put api("/#{source_type.pluralize}/#{source.id}/badges/#{badge.id}", user), - params: { link_url: example_url } + params: {link_url: example_url} expect(response).to have_gitlab_http_status(403) end @@ -192,43 +192,43 @@ describe API::Badges do end end - context 'when authenticated as a maintainer/owner' do - it 'updates the member' do + context "when authenticated as a maintainer/owner" do + it "updates the member" do put api("/#{source_type.pluralize}/#{source.id}/badges/#{badge.id}", maintainer), - params: { link_url: example_url, image_url: example_url2 } + params: {link_url: example_url, image_url: example_url2} expect(response).to have_gitlab_http_status(200) - expect(json_response['link_url']).to eq(example_url) - expect(json_response['image_url']).to eq(example_url2) - expect(json_response['kind']).to eq source_type + expect(json_response["link_url"]).to eq(example_url) + expect(json_response["image_url"]).to eq(example_url2) + expect(json_response["kind"]).to eq source_type end end - it 'returns 400 when link_url or image_url is not valid' do + it "returns 400 when link_url or image_url is not valid" do put api("/#{source_type.pluralize}/#{source.id}/badges/#{badge.id}", maintainer), - params: { link_url: 'whatever', image_url: 'whatever' } + params: {link_url: "whatever", image_url: "whatever"} expect(response).to have_gitlab_http_status(400) end end end - shared_examples 'DELETE /:sources/:id/badges/:badge_id' do |source_type| - include_context 'source helpers' + shared_examples "DELETE /:sources/:id/badges/:badge_id" do |source_type| + include_context "source helpers" let(:source) { get_source(source_type) } context "with :sources == #{source_type.pluralize}" do let(:badge) { source.badges.first } - it_behaves_like 'a 404 response when source is private' do + it_behaves_like "a 404 response when source is private" do let(:route) { delete api("/#{source_type.pluralize}/#{source.id}/badges/#{badge.id}", stranger) } end - context 'when authenticated as a non-member or member with insufficient rights' do + context "when authenticated as a non-member or member with insufficient rights" do %i[access_requester developer stranger].each do |type| context "as a #{type}" do - it 'returns 403' do + it "returns 403" do user = public_send(type) delete api("/#{source_type.pluralize}/#{source.id}/badges/#{badge.id}", user) @@ -239,21 +239,21 @@ describe API::Badges do end end - context 'when authenticated as a maintainer/owner' do - it 'deletes the badge' do - expect do + context "when authenticated as a maintainer/owner" do + it "deletes the badge" do + expect { delete api("/#{source_type.pluralize}/#{source.id}/badges/#{badge.id}", maintainer) expect(response).to have_gitlab_http_status(204) - end.to change { source.badges.count }.by(-1) + }.to change { source.badges.count }.by(-1) end - it_behaves_like '412 response' do + it_behaves_like "412 response" do let(:request) { api("/#{source_type.pluralize}/#{source.id}/badges/#{badge.id}", maintainer) } end end - it 'returns 404 if badge does not exist' do + it "returns 404 if badge does not exist" do delete api("/#{source_type.pluralize}/#{source.id}/badges/123", maintainer) expect(response).to have_gitlab_http_status(404) @@ -261,24 +261,24 @@ describe API::Badges do end end - shared_examples 'GET /:sources/:id/badges/render' do |source_type| - include_context 'source helpers' + shared_examples "GET /:sources/:id/badges/render" do |source_type| + include_context "source helpers" let(:source) { get_source(source_type) } - let(:example_url) { 'http://www.example.com' } - let(:example_url2) { 'http://www.example1.com' } + let(:example_url) { "http://www.example.com" } + let(:example_url2) { "http://www.example1.com" } context "with :sources == #{source_type.pluralize}" do - it_behaves_like 'a 404 response when source is private' do + it_behaves_like "a 404 response when source is private" do let(:route) do get api("/#{source_type.pluralize}/#{source.id}/badges/render?link_url=#{example_url}&image_url=#{example_url2}", stranger) end end - context 'when authenticated as a non-member or member with insufficient rights' do + context "when authenticated as a non-member or member with insufficient rights" do %i[access_requester stranger developer].each do |type| context "as a #{type}" do - it 'returns 403' do + it "returns 403" do user = public_send(type) get api("/#{source_type.pluralize}/#{source.id}/badges/render?link_url=#{example_url}&image_url=#{example_url2}", user) @@ -289,33 +289,33 @@ describe API::Badges do end end - context 'when authenticated as a maintainer/owner' do - it 'gets the rendered badge values' do + context "when authenticated as a maintainer/owner" do + it "gets the rendered badge values" do get api("/#{source_type.pluralize}/#{source.id}/badges/render?link_url=#{example_url}&image_url=#{example_url2}", maintainer) expect(response).to have_gitlab_http_status(200) - expect(json_response.keys).to contain_exactly('link_url', 'rendered_link_url', 'image_url', 'rendered_image_url') - expect(json_response['link_url']).to eq(example_url) - expect(json_response['image_url']).to eq(example_url2) - expect(json_response['rendered_link_url']).to eq(example_url) - expect(json_response['rendered_image_url']).to eq(example_url2) + expect(json_response.keys).to contain_exactly("link_url", "rendered_link_url", "image_url", "rendered_image_url") + expect(json_response["link_url"]).to eq(example_url) + expect(json_response["image_url"]).to eq(example_url2) + expect(json_response["rendered_link_url"]).to eq(example_url) + expect(json_response["rendered_image_url"]).to eq(example_url2) end end - it 'returns 400 when link_url is not given' do + it "returns 400 when link_url is not given" do get api("/#{source_type.pluralize}/#{source.id}/badges/render?link_url=#{example_url}", maintainer) expect(response).to have_gitlab_http_status(400) end - it 'returns 400 when image_url is not given' do + it "returns 400 when image_url is not given" do get api("/#{source_type.pluralize}/#{source.id}/badges/render?image_url=#{example_url}", maintainer) expect(response).to have_gitlab_http_status(400) end - it 'returns 400 when link_url or image_url is not valid' do + it "returns 400 when link_url or image_url is not valid" do get api("/#{source_type.pluralize}/#{source.id}/badges/render?link_url=whatever&image_url=whatever", maintainer) expect(response).to have_gitlab_http_status(400) @@ -323,9 +323,9 @@ describe API::Badges do end end - context 'when deleting a badge' do - context 'and the source is a project' do - it 'cannot delete badges owned by the project group' do + context "when deleting a badge" do + context "and the source is a project" do + it "cannot delete badges owned by the project group" do delete api("/projects/#{project.id}/badges/#{project_group.badges.first.id}", maintainer) expect(response).to have_gitlab_http_status(403) @@ -333,14 +333,14 @@ describe API::Badges do end end - describe 'Endpoints' do - %w(project group).each do |source_type| - it_behaves_like 'GET /:sources/:id/badges', source_type - it_behaves_like 'GET /:sources/:id/badges/:badge_id', source_type - it_behaves_like 'GET /:sources/:id/badges/render', source_type - it_behaves_like 'POST /:sources/:id/badges', source_type - it_behaves_like 'PUT /:sources/:id/badges/:badge_id', source_type - it_behaves_like 'DELETE /:sources/:id/badges/:badge_id', source_type + describe "Endpoints" do + %w[project group].each do |source_type| + it_behaves_like "GET /:sources/:id/badges", source_type + it_behaves_like "GET /:sources/:id/badges/:badge_id", source_type + it_behaves_like "GET /:sources/:id/badges/render", source_type + it_behaves_like "POST /:sources/:id/badges", source_type + it_behaves_like "PUT /:sources/:id/badges/:badge_id", source_type + it_behaves_like "DELETE /:sources/:id/badges/:badge_id", source_type end end diff --git a/spec/requests/api/boards_spec.rb b/spec/requests/api/boards_spec.rb index de79e8c4c5c..e80df38b954 100644 --- a/spec/requests/api/boards_spec.rb +++ b/spec/requests/api/boards_spec.rb @@ -1,22 +1,22 @@ -require 'spec_helper' +require "spec_helper" describe API::Boards do set(:user) { create(:user) } set(:non_member) { create(:user) } set(:guest) { create(:user) } set(:admin) { create(:user, :admin) } - set(:board_parent) { create(:project, :public, creator_id: user.id, namespace: user.namespace ) } + set(:board_parent) { create(:project, :public, creator_id: user.id, namespace: user.namespace) } set(:dev_label) do - create(:label, title: 'Development', color: '#FFAABB', project: board_parent) + create(:label, title: "Development", color: "#FFAABB", project: board_parent) end set(:test_label) do - create(:label, title: 'Testing', color: '#FFAACC', project: board_parent) + create(:label, title: "Testing", color: "#FFAACC", project: board_parent) end set(:ux_label) do - create(:label, title: 'UX', color: '#FF0000', project: board_parent) + create(:label, title: "UX", color: "#FF0000", project: board_parent) end set(:dev_list) do @@ -31,24 +31,24 @@ describe API::Boards do set(:board_label) { create(:label, project: board_parent) } set(:board) { create(:board, project: board_parent, lists: [dev_list, test_list]) } - it_behaves_like 'group and project boards', "/projects/:id/boards" + it_behaves_like "group and project boards", "/projects/:id/boards" describe "POST /projects/:id/boards/lists" do let(:url) { "/projects/#{board_parent.id}/boards/#{board.id}/lists" } - it 'creates a new issue board list for group labels' do + it "creates a new issue board list for group labels" do group = create(:group) group_label = create(:group_label, group: group) board_parent.update(group: group) - post api(url, user), params: { label_id: group_label.id } + post api(url, user), params: {label_id: group_label.id} expect(response).to have_gitlab_http_status(201) - expect(json_response['label']['name']).to eq(group_label.title) - expect(json_response['position']).to eq(3) + expect(json_response["label"]["name"]).to eq(group_label.title) + expect(json_response["position"]).to eq(3) end - it 'creates a new board list for ancestor group labels' do + it "creates a new board list for ancestor group labels" do group = create(:group) sub_group = create(:group, parent: group) group_label = create(:group_label, group: group) @@ -56,27 +56,27 @@ describe API::Boards do group.add_developer(user) sub_group.add_developer(user) - post api(url, user), params: { label_id: group_label.id } + post api(url, user), params: {label_id: group_label.id} expect(response).to have_gitlab_http_status(201) - expect(json_response['label']['name']).to eq(group_label.title) + expect(json_response["label"]["name"]).to eq(group_label.title) end end describe "POST /groups/:id/boards/lists", :nested_groups do set(:group) { create(:group) } - set(:board_parent) { create(:group, parent: group ) } + set(:board_parent) { create(:group, parent: group) } let(:url) { "/groups/#{board_parent.id}/boards/#{board.id}/lists" } set(:board) { create(:board, group: board_parent) } - it 'creates a new board list for ancestor group labels' do + it "creates a new board list for ancestor group labels" do group.add_developer(user) group_label = create(:group_label, group: group) - post api(url, user), params: { label_id: group_label.id } + post api(url, user), params: {label_id: group_label.id} expect(response).to have_gitlab_http_status(201) - expect(json_response['label']['name']).to eq(group_label.title) + expect(json_response["label"]["name"]).to eq(group_label.title) end end end diff --git a/spec/requests/api/branches_spec.rb b/spec/requests/api/branches_spec.rb index b38cd66986f..fa191105fc6 100644 --- a/spec/requests/api/branches_spec.rb +++ b/spec/requests/api/branches_spec.rb @@ -1,13 +1,13 @@ -require 'spec_helper' +require "spec_helper" describe API::Branches do set(:user) { create(:user) } - let(:project) { create(:project, :repository, creator: user, path: 'my.project') } + let(:project) { create(:project, :repository, creator: user, path: "my.project") } let(:guest) { create(:user).tap { |u| project.add_guest(u) } } - let(:branch_name) { 'feature' } - let(:branch_sha) { '0b4bc9a49b562e85de7cc9e834518ea6828729b9' } - let(:branch_with_dot) { project.repository.find_branch('ends-with.json') } - let(:branch_with_slash) { project.repository.find_branch('improve/awesome') } + let(:branch_name) { "feature" } + let(:branch_sha) { "0b4bc9a49b562e85de7cc9e834518ea6828729b9" } + let(:branch_with_dot) { project.repository.find_branch("ends-with.json") } + let(:branch_with_slash) { project.repository.find_branch("improve/awesome") } let(:project_id) { project.id } let(:current_user) { nil } @@ -19,88 +19,88 @@ describe API::Branches do describe "GET /projects/:id/repository/branches" do let(:route) { "/projects/#{project_id}/repository/branches" } - shared_examples_for 'repository branches' do + shared_examples_for "repository branches" do RSpec::Matchers.define :has_merged_branch_names_count do |expected| match do |actual| actual[:merged_branch_names].count == expected end end - it 'returns the repository branches' do - get api(route, current_user), params: { per_page: 100 } + it "returns the repository branches" do + get api(route, current_user), params: {per_page: 100} expect(response).to have_gitlab_http_status(200) - expect(response).to match_response_schema('public_api/v4/branches') + expect(response).to match_response_schema("public_api/v4/branches") expect(response).to include_pagination_headers - 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) end - it 'determines only a limited number of merged branch names' do + it "determines only a limited number of merged branch names" do expect(API::Entities::Branch).to receive(:represent).with(anything, has_merged_branch_names_count(2)) - get api(route, current_user), params: { per_page: 2 } + get api(route, current_user), params: {per_page: 2} end - context 'when repository is disabled' do - include_context 'disabled repository' + context "when repository is disabled" do + include_context "disabled repository" - it_behaves_like '403 response' do + it_behaves_like "403 response" do let(:request) { get api(route, current_user) } end end end - context 'when search parameter is passed' do - context 'and branch exists' do - it 'returns correct branches' do - get api(route, user), params: { per_page: 100, search: branch_name } + context "when search parameter is passed" do + context "and branch exists" do + it "returns correct branches" do + get api(route, user), params: {per_page: 100, search: branch_name} - searched_branch_names = json_response.map { |branch| branch['name'] } + searched_branch_names = json_response.map { |branch| branch["name"] } project_branch_names = project.repository.branch_names.grep(/#{branch_name}/) expect(searched_branch_names).to match_array(project_branch_names) end end - context 'and branch does not exist' do - it 'returns an empty array' do - get api(route, user), params: { per_page: 100, search: 'no_such_branch_name_entropy_of_jabadabadu' } + context "and branch does not exist" do + it "returns an empty array" do + get api(route, user), params: {per_page: 100, search: "no_such_branch_name_entropy_of_jabadabadu"} expect(json_response).to eq [] end end end - context 'when unauthenticated', 'and project is public' do + context "when unauthenticated", "and project is public" do before do project.update(visibility_level: Gitlab::VisibilityLevel::PUBLIC) end - it_behaves_like 'repository branches' + it_behaves_like "repository branches" end - context 'when unauthenticated', 'and project is private' do - it_behaves_like '404 response' do + context "when unauthenticated", "and project is private" do + it_behaves_like "404 response" do let(:request) { get api(route) } - let(:message) { '404 Project Not Found' } + let(:message) { "404 Project Not Found" } end end - context 'when authenticated', 'as a maintainer' do + context "when authenticated", "as a maintainer" do let(:current_user) { user } - it_behaves_like 'repository branches' + it_behaves_like "repository branches" - context 'requesting with the escaped project full path' do + context "requesting with the escaped project full path" do let(:project_id) { CGI.escape(project.full_path) } - it_behaves_like 'repository branches' + it_behaves_like "repository branches" end end - context 'when authenticated', 'as a guest' do - it_behaves_like '403 response' do + context "when authenticated", "as a guest" do + it_behaves_like "403 response" do let(:request) { get api(route, guest) } end end @@ -109,16 +109,16 @@ describe API::Branches do describe "GET /projects/:id/repository/branches/:branch" do let(:route) { "/projects/#{project_id}/repository/branches/#{branch_name}" } - shared_examples_for 'repository branch' do - context 'HEAD request' do - it 'returns 204 No Content' do + shared_examples_for "repository branch" do + context "HEAD request" do + it "returns 204 No Content" do head api(route, user) expect(response).to have_gitlab_http_status(204) expect(response.body).to be_empty end - it 'returns 404 Not Found' do + it "returns 404 Not Found" do head api("/projects/#{project_id}/repository/branches/unknown", user) expect(response).to have_gitlab_http_status(404) @@ -126,107 +126,107 @@ describe API::Branches do end end - it 'returns the repository branch' do + it "returns the repository branch" do get api(route, current_user) expect(response).to have_gitlab_http_status(200) - expect(response).to match_response_schema('public_api/v4/branch') - expect(json_response['name']).to eq(CGI.unescape(branch_name)) + expect(response).to match_response_schema("public_api/v4/branch") + expect(json_response["name"]).to eq(CGI.unescape(branch_name)) end - context 'when branch does not exist' do - let(:branch_name) { 'unknown' } + context "when branch does not exist" do + let(:branch_name) { "unknown" } - it_behaves_like '404 response' do + it_behaves_like "404 response" do let(:request) { get api(route, current_user) } - let(:message) { '404 Branch Not Found' } + let(:message) { "404 Branch Not Found" } end end - context 'when the branch refname is invalid' do - let(:branch_name) { 'branch*' } - let(:message) { 'The branch refname is invalid' } + context "when the branch refname is invalid" do + let(:branch_name) { "branch*" } + let(:message) { "The branch refname is invalid" } - it_behaves_like '400 response' do + it_behaves_like "400 response" do let(:request) { get api(route, current_user) } end end - context 'when repository is disabled' do - include_context 'disabled repository' + context "when repository is disabled" do + include_context "disabled repository" - it_behaves_like '403 response' do + it_behaves_like "403 response" do let(:request) { get api(route, current_user) } end end end - context 'when unauthenticated', 'and project is public' do + context "when unauthenticated", "and project is public" do before do project.update(visibility_level: Gitlab::VisibilityLevel::PUBLIC) end - it_behaves_like 'repository branch' + it_behaves_like "repository branch" - it 'returns that the current user cannot push' do + it "returns that the current user cannot push" do get api(route, current_user) - expect(json_response['can_push']).to eq(false) + expect(json_response["can_push"]).to eq(false) end end - context 'when unauthenticated', 'and project is private' do - it_behaves_like '404 response' do + context "when unauthenticated", "and project is private" do + it_behaves_like "404 response" do let(:request) { get api(route) } - let(:message) { '404 Project Not Found' } + let(:message) { "404 Project Not Found" } end end - context 'when authenticated', 'as a maintainer' do + context "when authenticated", "as a maintainer" do let(:current_user) { user } - it_behaves_like 'repository branch' + it_behaves_like "repository branch" - it 'returns that the current user can push' do + it "returns that the current user can push" do get api(route, current_user) - expect(json_response['can_push']).to eq(true) + expect(json_response["can_push"]).to eq(true) end - context 'when branch contains a dot' do + context "when branch contains a dot" do let(:branch_name) { branch_with_dot.name } - it_behaves_like 'repository branch' + it_behaves_like "repository branch" end - context 'when branch contains a slash' do + context "when branch contains a slash" do let(:branch_name) { branch_with_slash.name } - it_behaves_like '404 response' do + it_behaves_like "404 response" do let(:request) { get api(route, current_user) } end end - context 'when branch contains an escaped slash' do + context "when branch contains an escaped slash" do let(:branch_name) { CGI.escape(branch_with_slash.name) } - it_behaves_like 'repository branch' + it_behaves_like "repository branch" end - context 'requesting with the escaped project full path' do + context "requesting with the escaped project full path" do let(:project_id) { CGI.escape(project.full_path) } - it_behaves_like 'repository branch' + it_behaves_like "repository branch" - context 'when branch contains a dot' do + context "when branch contains a dot" do let(:branch_name) { branch_with_dot.name } - it_behaves_like 'repository branch' + it_behaves_like "repository branch" end end end - context 'when authenticated', 'as a developer and branch is protected' do + context "when authenticated", "as a developer and branch is protected" do let(:current_user) { create(:user) } let!(:protected_branch) { create(:protected_branch, project: project, name: branch_name) } @@ -234,408 +234,408 @@ describe API::Branches do project.add_developer(current_user) end - it_behaves_like 'repository branch' + it_behaves_like "repository branch" - it 'returns that the current user cannot push' do + it "returns that the current user cannot push" do get api(route, current_user) - expect(json_response['can_push']).to eq(false) + expect(json_response["can_push"]).to eq(false) end end - context 'when authenticated', 'as a guest' do - it_behaves_like '403 response' do + context "when authenticated", "as a guest" do + it_behaves_like "403 response" do let(:request) { get api(route, guest) } end end end - describe 'PUT /projects/:id/repository/branches/:branch/protect' do + describe "PUT /projects/:id/repository/branches/:branch/protect" do let(:route) { "/projects/#{project_id}/repository/branches/#{branch_name}/protect" } - shared_examples_for 'repository new protected branch' do - it 'protects a single branch' do + shared_examples_for "repository new protected branch" do + it "protects a single branch" do put api(route, current_user) expect(response).to have_gitlab_http_status(200) - expect(response).to match_response_schema('public_api/v4/branch') - expect(json_response['name']).to eq(CGI.unescape(branch_name)) - expect(json_response['protected']).to eq(true) + expect(response).to match_response_schema("public_api/v4/branch") + expect(json_response["name"]).to eq(CGI.unescape(branch_name)) + expect(json_response["protected"]).to eq(true) end - it 'protects a single branch and developers can push' do - put api(route, current_user), params: { developers_can_push: true } + it "protects a single branch and developers can push" do + put api(route, current_user), params: {developers_can_push: true} expect(response).to have_gitlab_http_status(200) - expect(response).to match_response_schema('public_api/v4/branch') - expect(json_response['name']).to eq(CGI.unescape(branch_name)) - expect(json_response['protected']).to eq(true) - expect(json_response['developers_can_push']).to eq(true) - expect(json_response['developers_can_merge']).to eq(false) + expect(response).to match_response_schema("public_api/v4/branch") + expect(json_response["name"]).to eq(CGI.unescape(branch_name)) + expect(json_response["protected"]).to eq(true) + expect(json_response["developers_can_push"]).to eq(true) + expect(json_response["developers_can_merge"]).to eq(false) end - it 'protects a single branch and developers can merge' do - put api(route, current_user), params: { developers_can_merge: true } + it "protects a single branch and developers can merge" do + put api(route, current_user), params: {developers_can_merge: true} expect(response).to have_gitlab_http_status(200) - expect(response).to match_response_schema('public_api/v4/branch') - expect(json_response['name']).to eq(CGI.unescape(branch_name)) - expect(json_response['protected']).to eq(true) - expect(json_response['developers_can_push']).to eq(false) - expect(json_response['developers_can_merge']).to eq(true) + expect(response).to match_response_schema("public_api/v4/branch") + expect(json_response["name"]).to eq(CGI.unescape(branch_name)) + expect(json_response["protected"]).to eq(true) + expect(json_response["developers_can_push"]).to eq(false) + expect(json_response["developers_can_merge"]).to eq(true) end - it 'protects a single branch and developers can push and merge' do - put api(route, current_user), params: { developers_can_push: true, developers_can_merge: true } + it "protects a single branch and developers can push and merge" do + put api(route, current_user), params: {developers_can_push: true, developers_can_merge: true} expect(response).to have_gitlab_http_status(200) - expect(response).to match_response_schema('public_api/v4/branch') - expect(json_response['name']).to eq(CGI.unescape(branch_name)) - expect(json_response['protected']).to eq(true) - expect(json_response['developers_can_push']).to eq(true) - expect(json_response['developers_can_merge']).to eq(true) + expect(response).to match_response_schema("public_api/v4/branch") + expect(json_response["name"]).to eq(CGI.unescape(branch_name)) + expect(json_response["protected"]).to eq(true) + expect(json_response["developers_can_push"]).to eq(true) + expect(json_response["developers_can_merge"]).to eq(true) end - context 'when branch does not exist' do - let(:branch_name) { 'unknown' } + context "when branch does not exist" do + let(:branch_name) { "unknown" } - it_behaves_like '404 response' do + it_behaves_like "404 response" do let(:request) { put api(route, current_user) } - let(:message) { '404 Branch Not Found' } + let(:message) { "404 Branch Not Found" } end end - context 'when the branch refname is invalid' do - let(:branch_name) { 'branch*' } - let(:message) { 'The branch refname is invalid' } + context "when the branch refname is invalid" do + let(:branch_name) { "branch*" } + let(:message) { "The branch refname is invalid" } - it_behaves_like '400 response' do + it_behaves_like "400 response" do let(:request) { put api(route, current_user) } end end - context 'when repository is disabled' do - include_context 'disabled repository' + context "when repository is disabled" do + include_context "disabled repository" - it_behaves_like '403 response' do + it_behaves_like "403 response" do let(:request) { put api(route, current_user) } end end end - context 'when unauthenticated', 'and project is private' do - it_behaves_like '404 response' do + context "when unauthenticated", "and project is private" do + it_behaves_like "404 response" do let(:request) { put api(route) } - let(:message) { '404 Project Not Found' } + let(:message) { "404 Project Not Found" } end end - context 'when authenticated', 'as a guest' do - it_behaves_like '403 response' do + context "when authenticated", "as a guest" do + it_behaves_like "403 response" do let(:request) { put api(route, guest) } end end - context 'when authenticated', 'as a maintainer' do + context "when authenticated", "as a maintainer" do let(:current_user) { user } context "when a protected branch doesn't already exist" do - it_behaves_like 'repository new protected branch' + it_behaves_like "repository new protected branch" - context 'when branch contains a dot' do + context "when branch contains a dot" do let(:branch_name) { branch_with_dot.name } - it_behaves_like 'repository new protected branch' + it_behaves_like "repository new protected branch" end - context 'when branch contains a slash' do + context "when branch contains a slash" do let(:branch_name) { branch_with_slash.name } - it_behaves_like '404 response' do + it_behaves_like "404 response" do let(:request) { put api(route, current_user) } end end - context 'when branch contains an escaped slash' do + context "when branch contains an escaped slash" do let(:branch_name) { CGI.escape(branch_with_slash.name) } - it_behaves_like 'repository new protected branch' + it_behaves_like "repository new protected branch" end - context 'requesting with the escaped project full path' do + context "requesting with the escaped project full path" do let(:project_id) { CGI.escape(project.full_path) } - it_behaves_like 'repository new protected branch' + it_behaves_like "repository new protected branch" - context 'when branch contains a dot' do + context "when branch contains a dot" do let(:branch_name) { branch_with_dot.name } - it_behaves_like 'repository new protected branch' + it_behaves_like "repository new protected branch" end end end - context 'when protected branch already exists' do + context "when protected branch already exists" do before do - project.repository.add_branch(user, protected_branch.name, 'master') + project.repository.add_branch(user, protected_branch.name, "master") end - context 'when developers can push and merge' do - let(:protected_branch) { create(:protected_branch, :developers_can_push, :developers_can_merge, project: project, name: 'protected_branch') } + context "when developers can push and merge" do + let(:protected_branch) { create(:protected_branch, :developers_can_push, :developers_can_merge, project: project, name: "protected_branch") } - it 'updates that a developer cannot push or merge' do + it "updates that a developer cannot push or merge" do put api("/projects/#{project.id}/repository/branches/#{protected_branch.name}/protect", user), - params: { developers_can_push: false, developers_can_merge: false } + params: {developers_can_push: false, developers_can_merge: false} expect(response).to have_gitlab_http_status(200) - expect(response).to match_response_schema('public_api/v4/branch') - expect(json_response['name']).to eq(protected_branch.name) - expect(json_response['protected']).to eq(true) - expect(json_response['developers_can_push']).to eq(false) - expect(json_response['developers_can_merge']).to eq(false) + expect(response).to match_response_schema("public_api/v4/branch") + expect(json_response["name"]).to eq(protected_branch.name) + expect(json_response["protected"]).to eq(true) + expect(json_response["developers_can_push"]).to eq(false) + expect(json_response["developers_can_merge"]).to eq(false) expect(protected_branch.reload.push_access_levels.first.access_level).to eq(Gitlab::Access::MAINTAINER) expect(protected_branch.reload.merge_access_levels.first.access_level).to eq(Gitlab::Access::MAINTAINER) end end - context 'when developers cannot push or merge' do - let(:protected_branch) { create(:protected_branch, project: project, name: 'protected_branch') } + context "when developers cannot push or merge" do + let(:protected_branch) { create(:protected_branch, project: project, name: "protected_branch") } - it 'updates that a developer can push and merge' do + it "updates that a developer can push and merge" do put api("/projects/#{project.id}/repository/branches/#{protected_branch.name}/protect", user), - params: { developers_can_push: true, developers_can_merge: true } + params: {developers_can_push: true, developers_can_merge: true} expect(response).to have_gitlab_http_status(200) - expect(response).to match_response_schema('public_api/v4/branch') - expect(json_response['name']).to eq(protected_branch.name) - expect(json_response['protected']).to eq(true) - expect(json_response['developers_can_push']).to eq(true) - expect(json_response['developers_can_merge']).to eq(true) + expect(response).to match_response_schema("public_api/v4/branch") + expect(json_response["name"]).to eq(protected_branch.name) + expect(json_response["protected"]).to eq(true) + expect(json_response["developers_can_push"]).to eq(true) + expect(json_response["developers_can_merge"]).to eq(true) end end end end end - describe 'PUT /projects/:id/repository/branches/:branch/unprotect' do + describe "PUT /projects/:id/repository/branches/:branch/unprotect" do let(:route) { "/projects/#{project_id}/repository/branches/#{branch_name}/unprotect" } - shared_examples_for 'repository unprotected branch' do - it 'unprotects a single branch' do + shared_examples_for "repository unprotected branch" do + it "unprotects a single branch" do put api(route, current_user) expect(response).to have_gitlab_http_status(200) - expect(response).to match_response_schema('public_api/v4/branch') - expect(json_response['name']).to eq(CGI.unescape(branch_name)) - expect(json_response['protected']).to eq(false) + expect(response).to match_response_schema("public_api/v4/branch") + expect(json_response["name"]).to eq(CGI.unescape(branch_name)) + expect(json_response["protected"]).to eq(false) end - context 'when branch does not exist' do - let(:branch_name) { 'unknown' } + context "when branch does not exist" do + let(:branch_name) { "unknown" } - it_behaves_like '404 response' do + it_behaves_like "404 response" do let(:request) { put api(route, current_user) } - let(:message) { '404 Branch Not Found' } + let(:message) { "404 Branch Not Found" } end end - context 'when the branch refname is invalid' do - let(:branch_name) { 'branch*' } - let(:message) { 'The branch refname is invalid' } + context "when the branch refname is invalid" do + let(:branch_name) { "branch*" } + let(:message) { "The branch refname is invalid" } - it_behaves_like '400 response' do + it_behaves_like "400 response" do let(:request) { put api(route, current_user) } end end - context 'when repository is disabled' do - include_context 'disabled repository' + context "when repository is disabled" do + include_context "disabled repository" - it_behaves_like '403 response' do + it_behaves_like "403 response" do let(:request) { put api(route, current_user) } end end end - context 'when unauthenticated', 'and project is private' do - it_behaves_like '404 response' do + context "when unauthenticated", "and project is private" do + it_behaves_like "404 response" do let(:request) { put api(route) } - let(:message) { '404 Project Not Found' } + let(:message) { "404 Project Not Found" } end end - context 'when authenticated', 'as a guest' do - it_behaves_like '403 response' do + context "when authenticated", "as a guest" do + it_behaves_like "403 response" do let(:request) { put api(route, guest) } end end - context 'when authenticated', 'as a maintainer' do + context "when authenticated", "as a maintainer" do let(:current_user) { user } context "when a protected branch doesn't already exist" do - it_behaves_like 'repository unprotected branch' + it_behaves_like "repository unprotected branch" - context 'when branch contains a dot' do + context "when branch contains a dot" do let(:branch_name) { branch_with_dot.name } - it_behaves_like 'repository unprotected branch' + it_behaves_like "repository unprotected branch" end - context 'when branch contains a slash' do + context "when branch contains a slash" do let(:branch_name) { branch_with_slash.name } - it_behaves_like '404 response' do + it_behaves_like "404 response" do let(:request) { put api(route, current_user) } end end - context 'when branch contains an escaped slash' do + context "when branch contains an escaped slash" do let(:branch_name) { CGI.escape(branch_with_slash.name) } - it_behaves_like 'repository unprotected branch' + it_behaves_like "repository unprotected branch" end - context 'requesting with the escaped project full path' do + context "requesting with the escaped project full path" do let(:project_id) { CGI.escape(project.full_path) } - it_behaves_like 'repository unprotected branch' + it_behaves_like "repository unprotected branch" - context 'when branch contains a dot' do + context "when branch contains a dot" do let(:branch_name) { branch_with_dot.name } - it_behaves_like 'repository unprotected branch' + it_behaves_like "repository unprotected branch" end end end end end - describe 'POST /projects/:id/repository/branches' do + describe "POST /projects/:id/repository/branches" do let(:route) { "/projects/#{project_id}/repository/branches" } - shared_examples_for 'repository new branch' do - it 'creates a new branch' do - post api(route, current_user), params: { branch: 'feature1', ref: branch_sha } + shared_examples_for "repository new branch" do + it "creates a new branch" do + post api(route, current_user), params: {branch: "feature1", ref: branch_sha} expect(response).to have_gitlab_http_status(201) - expect(response).to match_response_schema('public_api/v4/branch') - expect(json_response['name']).to eq('feature1') - expect(json_response['commit']['id']).to eq(branch_sha) + expect(response).to match_response_schema("public_api/v4/branch") + expect(json_response["name"]).to eq("feature1") + expect(json_response["commit"]["id"]).to eq(branch_sha) end - context 'when repository is disabled' do - include_context 'disabled repository' + context "when repository is disabled" do + include_context "disabled repository" - it_behaves_like '403 response' do + it_behaves_like "403 response" do let(:request) { post api(route, current_user) } end end end - context 'when unauthenticated', 'and project is private' do - it_behaves_like '404 response' do + context "when unauthenticated", "and project is private" do + it_behaves_like "404 response" do let(:request) { post api(route) } - let(:message) { '404 Project Not Found' } + let(:message) { "404 Project Not Found" } end end - context 'when authenticated', 'as a guest' do - it_behaves_like '403 response' do + context "when authenticated", "as a guest" do + it_behaves_like "403 response" do let(:request) { post api(route, guest) } end end - context 'when authenticated', 'as a maintainer' do + context "when authenticated", "as a maintainer" do let(:current_user) { user } context "when a protected branch doesn't already exist" do - it_behaves_like 'repository new branch' + it_behaves_like "repository new branch" - context 'requesting with the escaped project full path' do + context "requesting with the escaped project full path" do let(:project_id) { CGI.escape(project.full_path) } - it_behaves_like 'repository new branch' + it_behaves_like "repository new branch" end end end - it 'returns 400 if branch name is invalid' do - post api(route, user), params: { branch: 'new design', ref: branch_sha } + it "returns 400 if branch name is invalid" do + post api(route, user), params: {branch: "new design", ref: branch_sha} expect(response).to have_gitlab_http_status(400) - expect(json_response['message']).to eq('Branch name is invalid') + expect(json_response["message"]).to eq("Branch name is invalid") end - it 'returns 400 if branch already exists' do - post api(route, user), params: { branch: 'new_design1', ref: branch_sha } + it "returns 400 if branch already exists" do + post api(route, user), params: {branch: "new_design1", ref: branch_sha} expect(response).to have_gitlab_http_status(201) - post api(route, user), params: { branch: 'new_design1', ref: branch_sha } + post api(route, user), params: {branch: "new_design1", ref: branch_sha} expect(response).to have_gitlab_http_status(400) - expect(json_response['message']).to eq('Branch already exists') + expect(json_response["message"]).to eq("Branch already exists") end - it 'returns 400 if ref name is invalid' do - post api(route, user), params: { branch: 'new_design3', ref: 'foo' } + it "returns 400 if ref name is invalid" do + post api(route, user), params: {branch: "new_design3", ref: "foo"} expect(response).to have_gitlab_http_status(400) - expect(json_response['message']).to eq('Invalid reference name') + expect(json_response["message"]).to eq("Invalid reference name") end end - describe 'DELETE /projects/:id/repository/branches/:branch' do + describe "DELETE /projects/:id/repository/branches/:branch" do before do allow_any_instance_of(Repository).to receive(:rm_branch).and_return(true) end - it 'removes branch' do + it "removes branch" do delete api("/projects/#{project.id}/repository/branches/#{branch_name}", user) expect(response).to have_gitlab_http_status(204) end - it 'removes a branch with dots in the branch name' do + it "removes a branch with dots in the branch name" do delete api("/projects/#{project.id}/repository/branches/#{branch_with_dot.name}", user) expect(response).to have_gitlab_http_status(204) end - it 'returns 404 if branch not exists' do + it "returns 404 if branch not exists" do delete api("/projects/#{project.id}/repository/branches/foobar", user) expect(response).to have_gitlab_http_status(404) end - context 'when the branch refname is invalid' do - let(:branch_name) { 'branch*' } - let(:message) { 'The branch refname is invalid' } + context "when the branch refname is invalid" do + let(:branch_name) { "branch*" } + let(:message) { "The branch refname is invalid" } - it_behaves_like '400 response' do + it_behaves_like "400 response" do let(:request) { delete api("/projects/#{project.id}/repository/branches/#{branch_name}", user) } end end - it_behaves_like '412 response' do + it_behaves_like "412 response" do let(:request) { api("/projects/#{project.id}/repository/branches/#{branch_name}", user) } end end - describe 'DELETE /projects/:id/repository/merged_branches' do + describe "DELETE /projects/:id/repository/merged_branches" do before do allow_any_instance_of(Repository).to receive(:rm_branch).and_return(true) end - it 'returns 202 with json body' do + it "returns 202 with json body" do delete api("/projects/#{project.id}/repository/merged_branches", user) expect(response).to have_gitlab_http_status(202) - expect(json_response['message']).to eql('202 Accepted') + expect(json_response["message"]).to eql("202 Accepted") end - it 'returns a 403 error if guest' do + it "returns a 403 error if guest" do delete api("/projects/#{project.id}/repository/merged_branches", guest) expect(response).to have_gitlab_http_status(403) diff --git a/spec/requests/api/broadcast_messages_spec.rb b/spec/requests/api/broadcast_messages_spec.rb index 0b48b79219c..bb5598431b3 100644 --- a/spec/requests/api/broadcast_messages_spec.rb +++ b/spec/requests/api/broadcast_messages_spec.rb @@ -1,181 +1,181 @@ -require 'spec_helper' +require "spec_helper" describe API::BroadcastMessages do set(:user) { create(:user) } set(:admin) { create(:admin) } set(:message) { create(:broadcast_message) } - describe 'GET /broadcast_messages' do - it 'returns a 401 for anonymous users' do - get api('/broadcast_messages') + describe "GET /broadcast_messages" do + it "returns a 401 for anonymous users" do + get api("/broadcast_messages") expect(response).to have_gitlab_http_status(401) end - it 'returns a 403 for users' do - get api('/broadcast_messages', user) + it "returns a 403 for users" do + get api("/broadcast_messages", user) expect(response).to have_gitlab_http_status(403) end - it 'returns an Array of BroadcastMessages for admins' do + it "returns an Array of BroadcastMessages for admins" do create(:broadcast_message) - get api('/broadcast_messages', admin) + get api("/broadcast_messages", admin) expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response).to be_kind_of(Array) expect(json_response.first.keys) - .to match_array(%w(id message starts_at ends_at color font active)) + .to match_array(%w[id message starts_at ends_at color font active]) end end - describe 'GET /broadcast_messages/:id' do - it 'returns a 401 for anonymous users' do + describe "GET /broadcast_messages/:id" do + it "returns a 401 for anonymous users" do get api("/broadcast_messages/#{message.id}") expect(response).to have_gitlab_http_status(401) end - it 'returns a 403 for users' do + it "returns a 403 for users" do get api("/broadcast_messages/#{message.id}", user) expect(response).to have_gitlab_http_status(403) end - it 'returns the specified message for admins' do + it "returns the specified message for admins" do get api("/broadcast_messages/#{message.id}", admin) expect(response).to have_gitlab_http_status(200) - expect(json_response['id']).to eq message.id + expect(json_response["id"]).to eq message.id expect(json_response.keys) - .to match_array(%w(id message starts_at ends_at color font active)) + .to match_array(%w[id message starts_at ends_at color font active]) end end - describe 'POST /broadcast_messages' do - it 'returns a 401 for anonymous users' do - post api('/broadcast_messages'), params: attributes_for(:broadcast_message) + describe "POST /broadcast_messages" do + it "returns a 401 for anonymous users" do + post api("/broadcast_messages"), params: attributes_for(:broadcast_message) expect(response).to have_gitlab_http_status(401) end - it 'returns a 403 for users' do - post api('/broadcast_messages', user), params: attributes_for(:broadcast_message) + it "returns a 403 for users" do + post api("/broadcast_messages", user), params: attributes_for(:broadcast_message) expect(response).to have_gitlab_http_status(403) end - context 'as an admin' do - it 'requires the `message` parameter' do + context "as an admin" do + it "requires the `message` parameter" do attrs = attributes_for(:broadcast_message) attrs.delete(:message) - post api('/broadcast_messages', admin), params: attrs + post api("/broadcast_messages", admin), params: attrs expect(response).to have_gitlab_http_status(400) - expect(json_response['error']).to eq 'message is missing' + expect(json_response["error"]).to eq "message is missing" end - it 'defines sane default start and end times' do - time = Time.zone.parse('2016-07-02 10:11:12') + it "defines sane default start and end times" do + time = Time.zone.parse("2016-07-02 10:11:12") travel_to(time) do - post api('/broadcast_messages', admin), params: { message: 'Test message' } + post api("/broadcast_messages", admin), params: {message: "Test message"} expect(response).to have_gitlab_http_status(201) - expect(json_response['starts_at']).to eq '2016-07-02T10:11:12.000Z' - expect(json_response['ends_at']).to eq '2016-07-02T11:11:12.000Z' + expect(json_response["starts_at"]).to eq "2016-07-02T10:11:12.000Z" + expect(json_response["ends_at"]).to eq "2016-07-02T11:11:12.000Z" end end - it 'accepts a custom background and foreground color' do - attrs = attributes_for(:broadcast_message, color: '#000000', font: '#cecece') + it "accepts a custom background and foreground color" do + attrs = attributes_for(:broadcast_message, color: "#000000", font: "#cecece") - post api('/broadcast_messages', admin), params: attrs + post api("/broadcast_messages", admin), params: attrs expect(response).to have_gitlab_http_status(201) - expect(json_response['color']).to eq attrs[:color] - expect(json_response['font']).to eq attrs[:font] + expect(json_response["color"]).to eq attrs[:color] + expect(json_response["font"]).to eq attrs[:font] end end end - describe 'PUT /broadcast_messages/:id' do - it 'returns a 401 for anonymous users' do + describe "PUT /broadcast_messages/:id" do + it "returns a 401 for anonymous users" do put api("/broadcast_messages/#{message.id}"), params: attributes_for(:broadcast_message) expect(response).to have_gitlab_http_status(401) end - it 'returns a 403 for users' do + it "returns a 403 for users" do put api("/broadcast_messages/#{message.id}", user), params: attributes_for(:broadcast_message) expect(response).to have_gitlab_http_status(403) end - context 'as an admin' do - it 'accepts new background and foreground colors' do - attrs = { color: '#000000', font: '#cecece' } + context "as an admin" do + it "accepts new background and foreground colors" do + attrs = {color: "#000000", font: "#cecece"} put api("/broadcast_messages/#{message.id}", admin), params: attrs expect(response).to have_gitlab_http_status(200) - expect(json_response['color']).to eq attrs[:color] - expect(json_response['font']).to eq attrs[:font] + expect(json_response["color"]).to eq attrs[:color] + expect(json_response["font"]).to eq attrs[:font] end - it 'accepts new start and end times' do - time = Time.zone.parse('2016-07-02 10:11:12') + it "accepts new start and end times" do + time = Time.zone.parse("2016-07-02 10:11:12") travel_to(time) do - attrs = { starts_at: Time.zone.now, ends_at: 3.hours.from_now } + attrs = {starts_at: Time.zone.now, ends_at: 3.hours.from_now} put api("/broadcast_messages/#{message.id}", admin), params: attrs expect(response).to have_gitlab_http_status(200) - expect(json_response['starts_at']).to eq '2016-07-02T10:11:12.000Z' - expect(json_response['ends_at']).to eq '2016-07-02T13:11:12.000Z' + expect(json_response["starts_at"]).to eq "2016-07-02T10:11:12.000Z" + expect(json_response["ends_at"]).to eq "2016-07-02T13:11:12.000Z" end end - it 'accepts a new message' do - attrs = { message: 'new message' } + it "accepts a new message" do + attrs = {message: "new message"} put api("/broadcast_messages/#{message.id}", admin), params: attrs expect(response).to have_gitlab_http_status(200) - expect { message.reload }.to change { message.message }.to('new message') + expect { message.reload }.to change { message.message }.to("new message") end end end - describe 'DELETE /broadcast_messages/:id' do - it 'returns a 401 for anonymous users' do + describe "DELETE /broadcast_messages/:id" do + it "returns a 401 for anonymous users" do delete api("/broadcast_messages/#{message.id}"), params: attributes_for(:broadcast_message) expect(response).to have_gitlab_http_status(401) end - it 'returns a 403 for users' do + it "returns a 403 for users" do delete api("/broadcast_messages/#{message.id}", user), params: attributes_for(:broadcast_message) expect(response).to have_gitlab_http_status(403) end - it_behaves_like '412 response' do + it_behaves_like "412 response" do let(:request) { api("/broadcast_messages/#{message.id}", admin) } end - it 'deletes the broadcast message for admins' do - expect do + it "deletes the broadcast message for admins" do + expect { delete api("/broadcast_messages/#{message.id}", admin) expect(response).to have_gitlab_http_status(204) - end.to change { BroadcastMessage.count }.by(-1) + }.to change { BroadcastMessage.count }.by(-1) end end end diff --git a/spec/requests/api/circuit_breakers_spec.rb b/spec/requests/api/circuit_breakers_spec.rb index 6c7cb151c74..105aaed4acb 100644 --- a/spec/requests/api/circuit_breakers_spec.rb +++ b/spec/requests/api/circuit_breakers_spec.rb @@ -1,33 +1,33 @@ -require 'spec_helper' +require "spec_helper" describe API::CircuitBreakers do set(:user) { create(:user) } set(:admin) { create(:admin) } - describe 'GET circuit_breakers/repository_storage' do - it 'returns a 401 for anonymous users' do - get api('/circuit_breakers/repository_storage') + describe "GET circuit_breakers/repository_storage" do + it "returns a 401 for anonymous users" do + get api("/circuit_breakers/repository_storage") expect(response).to have_gitlab_http_status(401) end - it 'returns a 403 for users' do - get api('/circuit_breakers/repository_storage', user) + it "returns a 403 for users" do + get api("/circuit_breakers/repository_storage", user) expect(response).to have_gitlab_http_status(403) end - it 'returns an Array of storages' do - get api('/circuit_breakers/repository_storage', admin) + it "returns an Array of storages" do + get api("/circuit_breakers/repository_storage", admin) expect(response).to have_gitlab_http_status(200) expect(json_response).to be_kind_of(Array) expect(json_response).to be_empty end - describe 'GET circuit_breakers/repository_storage/failing' do - it 'returns an array of failing storages' do - get api('/circuit_breakers/repository_storage/failing', admin) + describe "GET circuit_breakers/repository_storage/failing" do + it "returns an array of failing storages" do + get api("/circuit_breakers/repository_storage/failing", admin) expect(response).to have_gitlab_http_status(200) expect(json_response).to be_kind_of(Array) @@ -36,9 +36,9 @@ describe API::CircuitBreakers do end end - describe 'DELETE circuit_breakers/repository_storage' do - it 'clears all circuit_breakers' do - delete api('/circuit_breakers/repository_storage', admin) + describe "DELETE circuit_breakers/repository_storage" do + it "clears all circuit_breakers" do + delete api("/circuit_breakers/repository_storage", admin) expect(response).to have_gitlab_http_status(204) end diff --git a/spec/requests/api/commit_statuses_spec.rb b/spec/requests/api/commit_statuses_spec.rb index 9388343c392..33987da94ab 100644 --- a/spec/requests/api/commit_statuses_spec.rb +++ b/spec/requests/api/commit_statuses_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe API::CommitStatuses do let!(:project) { create(:project, :repository) } @@ -15,61 +15,61 @@ describe API::CommitStatuses do describe "GET /projects/:id/repository/commits/:sha/statuses" do let(:get_url) { "/projects/#{project.id}/repository/commits/#{sha}/statuses" } - context 'ci commit exists' do - let!(:master) { project.ci_pipelines.create(source: :push, sha: commit.id, ref: 'master', protected: false) } - let!(:develop) { project.ci_pipelines.create(source: :push, sha: commit.id, ref: 'develop', protected: false) } + context "ci commit exists" do + let!(:master) { project.ci_pipelines.create(source: :push, sha: commit.id, ref: "master", protected: false) } + let!(:develop) { project.ci_pipelines.create(source: :push, sha: commit.id, ref: "develop", protected: false) } context "reporter user" do - let(:statuses_id) { json_response.map { |status| status['id'] } } + let(:statuses_id) { json_response.map { |status| status["id"] } } def create_status(commit, opts = {}) - create(:commit_status, { pipeline: commit, ref: commit.ref }.merge(opts)) + create(:commit_status, {pipeline: commit, ref: commit.ref}.merge(opts)) end - let!(:status1) { create_status(master, status: 'running', retried: true) } - let!(:status2) { create_status(master, name: 'coverage', status: 'pending', retried: true) } - let!(:status3) { create_status(develop, status: 'running', allow_failure: true) } - let!(:status4) { create_status(master, name: 'coverage', status: 'success') } - let!(:status5) { create_status(develop, name: 'coverage', status: 'success') } - let!(:status6) { create_status(master, status: 'success') } + let!(:status1) { create_status(master, status: "running", retried: true) } + let!(:status2) { create_status(master, name: "coverage", status: "pending", retried: true) } + let!(:status3) { create_status(develop, status: "running", allow_failure: true) } + let!(:status4) { create_status(master, name: "coverage", status: "success") } + let!(:status5) { create_status(develop, name: "coverage", status: "success") } + let!(:status6) { create_status(master, status: "success") } - context 'latest commit statuses' do + context "latest commit statuses" do before do get api(get_url, reporter) end - it 'returns latest commit statuses' do + it "returns latest commit statuses" do expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response).to be_an Array expect(statuses_id).to contain_exactly(status3.id, status4.id, status5.id, status6.id) - json_response.sort_by! { |status| status['id'] } - expect(json_response.map { |status| status['allow_failure'] }).to eq([true, false, false, false]) + json_response.sort_by! { |status| status["id"] } + expect(json_response.map { |status| status["allow_failure"] }).to eq([true, false, false, false]) end end - context 'all commit statuses' do + context "all commit statuses" do before do - get api(get_url, reporter), params: { all: 1 } + get api(get_url, reporter), params: {all: 1} end - it 'returns all commit statuses' do + it "returns all commit statuses" do expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response).to be_an Array expect(statuses_id).to contain_exactly(status1.id, status2.id, - status3.id, status4.id, - status5.id, status6.id) + status3.id, status4.id, + status5.id, status6.id) end end - context 'latest commit statuses for specific ref' do + context "latest commit statuses for specific ref" do before do - get api(get_url, reporter), params: { ref: 'develop' } + get api(get_url, reporter), params: {ref: "develop"} end - it 'returns latest commit statuses for specific ref' do + it "returns latest commit statuses for specific ref" do expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response).to be_an Array @@ -77,12 +77,12 @@ describe API::CommitStatuses do end end - context 'latest commit statues for specific name' do + context "latest commit statues for specific name" do before do - get api(get_url, reporter), params: { name: 'coverage' } + get api(get_url, reporter), params: {name: "coverage"} end - it 'return latest commit statuses for specific name' do + it "return latest commit statuses for specific name" do expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response).to be_an Array @@ -92,12 +92,12 @@ describe API::CommitStatuses do end end - context 'ci commit does not exist' do + context "ci commit does not exist" do before do get api(get_url, reporter) end - it 'returns empty array' do + it "returns empty array" do expect(response.status).to eq 200 expect(json_response).to be_an Array expect(json_response).to be_empty @@ -125,77 +125,77 @@ describe API::CommitStatuses do end end - describe 'POST /projects/:id/statuses/:sha' do + describe "POST /projects/:id/statuses/:sha" do let(:post_url) { "/projects/#{project.id}/statuses/#{sha}" } - context 'developer user' do + context "developer user" do %w[pending running success failed canceled].each do |status| context "for #{status}" do - context 'uses only required parameters' do - it 'creates commit status' do - post api(post_url, developer), params: { state: status } + context "uses only required parameters" do + it "creates commit status" do + post api(post_url, developer), params: {state: status} expect(response).to have_gitlab_http_status(201) - expect(json_response['sha']).to eq(commit.id) - expect(json_response['status']).to eq(status) - expect(json_response['name']).to eq('default') - expect(json_response['ref']).not_to be_empty - expect(json_response['target_url']).to be_nil - expect(json_response['description']).to be_nil - - if status == 'failed' - expect(CommitStatus.find(json_response['id'])).to be_api_failure + expect(json_response["sha"]).to eq(commit.id) + expect(json_response["status"]).to eq(status) + expect(json_response["name"]).to eq("default") + expect(json_response["ref"]).not_to be_empty + expect(json_response["target_url"]).to be_nil + expect(json_response["description"]).to be_nil + + if status == "failed" + expect(CommitStatus.find(json_response["id"])).to be_api_failure end end end end end - context 'transitions status from pending' do + context "transitions status from pending" do before do - post api(post_url, developer), params: { state: 'pending' } + post api(post_url, developer), params: {state: "pending"} end %w[running success failed canceled].each do |status| it "to #{status}" do - expect { post api(post_url, developer), params: { state: status } }.not_to change { CommitStatus.count } + expect { post api(post_url, developer), params: {state: status} }.not_to change { CommitStatus.count } expect(response).to have_gitlab_http_status(201) - expect(json_response['status']).to eq(status) + expect(json_response["status"]).to eq(status) end end end - context 'with all optional parameters' do - context 'when creating a commit status' do + context "with all optional parameters" do + context "when creating a commit status" do subject do post api(post_url, developer), params: { - state: 'success', - context: 'coverage', - ref: 'master', - description: 'test', + state: "success", + context: "coverage", + ref: "master", + description: "test", coverage: 80.0, - target_url: 'http://gitlab.com/status' + target_url: "http://gitlab.com/status", } end - it 'creates commit status' do + it "creates commit status" do subject expect(response).to have_gitlab_http_status(201) - expect(json_response['sha']).to eq(commit.id) - expect(json_response['status']).to eq('success') - expect(json_response['name']).to eq('coverage') - expect(json_response['ref']).to eq('master') - expect(json_response['coverage']).to eq(80.0) - expect(json_response['description']).to eq('test') - expect(json_response['target_url']).to eq('http://gitlab.com/status') + expect(json_response["sha"]).to eq(commit.id) + expect(json_response["status"]).to eq("success") + expect(json_response["name"]).to eq("coverage") + expect(json_response["ref"]).to eq("master") + expect(json_response["coverage"]).to eq(80.0) + expect(json_response["description"]).to eq("test") + expect(json_response["target_url"]).to eq("http://gitlab.com/status") end - context 'when merge request exists for given branch' do - let!(:merge_request) { create(:merge_request, source_project: project, source_branch: 'master', target_branch: 'develop') } + context "when merge request exists for given branch" do + let!(:merge_request) { create(:merge_request, source_project: project, source_branch: "master", target_branch: "develop") } - it 'sets head pipeline' do + it "sets head pipeline" do subject expect(response).to have_gitlab_http_status(201) @@ -204,139 +204,139 @@ describe API::CommitStatuses do end end - context 'when updatig a commit status' do + context "when updatig a commit status" do before do post api(post_url, developer), params: { - state: 'running', - context: 'coverage', - ref: 'master', - description: 'coverage test', + state: "running", + context: "coverage", + ref: "master", + description: "coverage test", coverage: 0.0, - target_url: 'http://gitlab.com/status' + target_url: "http://gitlab.com/status", } post api(post_url, developer), params: { - state: 'success', - name: 'coverage', - ref: 'master', - description: 'new description', - coverage: 90.0 + state: "success", + name: "coverage", + ref: "master", + description: "new description", + coverage: 90.0, } end - it 'updates a commit status' do + it "updates a commit status" do expect(response).to have_gitlab_http_status(201) - expect(json_response['sha']).to eq(commit.id) - expect(json_response['status']).to eq('success') - expect(json_response['name']).to eq('coverage') - expect(json_response['ref']).to eq('master') - expect(json_response['coverage']).to eq(90.0) - expect(json_response['description']).to eq('new description') - expect(json_response['target_url']).to eq('http://gitlab.com/status') + expect(json_response["sha"]).to eq(commit.id) + expect(json_response["status"]).to eq("success") + expect(json_response["name"]).to eq("coverage") + expect(json_response["ref"]).to eq("master") + expect(json_response["coverage"]).to eq(90.0) + expect(json_response["description"]).to eq("new description") + expect(json_response["target_url"]).to eq("http://gitlab.com/status") end - it 'does not create a new commit status' do + it "does not create a new commit status" do expect(CommitStatus.count).to eq 1 end end end - context 'when retrying a commit status' do + context "when retrying a commit status" do before do post api(post_url, developer), - params: { state: 'failed', name: 'test', ref: 'master' } + params: {state: "failed", name: "test", ref: "master"} post api(post_url, developer), - params: { state: 'success', name: 'test', ref: 'master' } + params: {state: "success", name: "test", ref: "master"} end - it 'correctly posts a new commit status' do + it "correctly posts a new commit status" do expect(response).to have_gitlab_http_status(201) - expect(json_response['sha']).to eq(commit.id) - expect(json_response['status']).to eq('success') + expect(json_response["sha"]).to eq(commit.id) + expect(json_response["status"]).to eq("success") end - it 'retries a commit status' do + it "retries a commit status" do expect(CommitStatus.count).to eq 2 expect(CommitStatus.first).to be_retried expect(CommitStatus.last.pipeline).to be_success end end - context 'when status is invalid' do + context "when status is invalid" do before do - post api(post_url, developer), params: { state: 'invalid' } + post api(post_url, developer), params: {state: "invalid"} end - it 'does not create commit status' do + it "does not create commit status" do expect(response).to have_gitlab_http_status(400) end end - context 'when request without a state made' do + context "when request without a state made" do before do post api(post_url, developer) end - it 'does not create commit status' do + it "does not create commit status" do expect(response).to have_gitlab_http_status(400) end end - context 'when commit SHA is invalid' do - let(:sha) { 'invalid_sha' } + context "when commit SHA is invalid" do + let(:sha) { "invalid_sha" } before do - post api(post_url, developer), params: { state: 'running' } + post api(post_url, developer), params: {state: "running"} end - it 'returns not found error' do + it "returns not found error" do expect(response).to have_gitlab_http_status(404) end end - context 'when target URL is an invalid address' do + context "when target URL is an invalid address" do before do post api(post_url, developer), params: { - state: 'pending', - target_url: 'invalid url' - } + state: "pending", + target_url: "invalid url", + } end - it 'responds with bad request status and validation errors' do + it "responds with bad request status and validation errors" do expect(response).to have_gitlab_http_status(400) - expect(json_response['message']['target_url']) - .to include 'is blocked: Only allowed protocols are http, https' + expect(json_response["message"]["target_url"]) + .to include "is blocked: Only allowed protocols are http, https" end end end - context 'reporter user' do + context "reporter user" do before do - post api(post_url, reporter), params: { state: 'running' } + post api(post_url, reporter), params: {state: "running"} end - it 'does not create commit status' do + it "does not create commit status" do expect(response).to have_gitlab_http_status(403) end end - context 'guest user' do + context "guest user" do before do - post api(post_url, guest), params: { state: 'running' } + post api(post_url, guest), params: {state: "running"} end - it 'does not create commit status' do + it "does not create commit status" do expect(response).to have_gitlab_http_status(403) end end - context 'unauthorized user' do + context "unauthorized user" do before do post api(post_url) end - it 'does not create commit status' do + it "does not create commit status" do expect(response).to have_gitlab_http_status(401) end end diff --git a/spec/requests/api/commits_spec.rb b/spec/requests/api/commits_spec.rb index 066f1d6862a..97471b17528 100644 --- a/spec/requests/api/commits_spec.rb +++ b/spec/requests/api/commits_spec.rb @@ -1,12 +1,12 @@ -require 'spec_helper' -require 'mime/types' +require "spec_helper" +require "mime/types" describe API::Commits do let(:user) { create(:user) } let(:guest) { create(:user).tap { |u| project.add_guest(u) } } - let(:project) { create(:project, :repository, creator: user, path: 'my.project') } - let(:branch_with_dot) { project.repository.find_branch('ends-with.json') } - let(:branch_with_slash) { project.repository.find_branch('improve/awesome') } + let(:project) { create(:project, :repository, creator: user, path: "my.project") } + let(:branch_with_dot) { project.repository.find_branch("ends-with.json") } + let(:branch_with_slash) { project.repository.find_branch("improve/awesome") } let(:project_id) { project.id } let(:current_user) { nil } @@ -15,10 +15,10 @@ describe API::Commits do project.add_maintainer(user) end - describe 'GET /projects/:id/repository/commits' do + describe "GET /projects/:id/repository/commits" do let(:route) { "/projects/#{project_id}/repository/commits" } - shared_examples_for 'project commits' do |schema: 'public_api/v4/commits'| + shared_examples_for "project commits" do |schema: "public_api/v4/commits"| it "returns project commits" do commit = project.repository.commit @@ -26,39 +26,39 @@ describe API::Commits do expect(response).to have_gitlab_http_status(200) expect(response).to match_response_schema(schema) - expect(json_response.first['id']).to eq(commit.id) - expect(json_response.first['committer_name']).to eq(commit.committer_name) - expect(json_response.first['committer_email']).to eq(commit.committer_email) + expect(json_response.first["id"]).to eq(commit.id) + expect(json_response.first["committer_name"]).to eq(commit.committer_name) + expect(json_response.first["committer_email"]).to eq(commit.committer_email) end - it 'include correct pagination headers' do - commit_count = project.repository.count_commits(ref: 'master').to_s + it "include correct pagination headers" do + commit_count = project.repository.count_commits(ref: "master").to_s get api(route, current_user) expect(response).to include_pagination_headers - expect(response.headers['X-Total']).to eq(commit_count) - expect(response.headers['X-Page']).to eql('1') + expect(response.headers["X-Total"]).to eq(commit_count) + expect(response.headers["X-Page"]).to eql("1") end end - context 'when unauthenticated', 'and project is public' do + context "when unauthenticated", "and project is public" do let(:project) { create(:project, :public, :repository) } - it_behaves_like 'project commits' + it_behaves_like "project commits" end - context 'when unauthenticated', 'and project is private' do - it_behaves_like '404 response' do + context "when unauthenticated", "and project is private" do + it_behaves_like "404 response" do let(:request) { get api(route) } - let(:message) { '404 Project Not Found' } + let(:message) { "404 Project Not Found" } end end - context 'when authenticated', 'as a maintainer' do + context "when authenticated", "as a maintainer" do let(:current_user) { user } - it_behaves_like 'project commits' + it_behaves_like "project commits" context "since optional parameter" do it "returns project commits since provided parameter" do @@ -72,16 +72,16 @@ describe API::Commits do expect(json_response.second["id"]).to eq(commits.second.id) end - it 'include correct pagination headers' do + it "include correct pagination headers" do commits = project.repository.commits("master", limit: 2) after = commits.second.created_at - commit_count = project.repository.count_commits(ref: 'master', after: after).to_s + commit_count = project.repository.count_commits(ref: "master", after: after).to_s get api("/projects/#{project_id}/repository/commits?since=#{after.utc.iso8601}", user) expect(response).to include_pagination_headers - expect(response.headers['X-Total']).to eq(commit_count) - expect(response.headers['X-Page']).to eql('1') + expect(response.headers["X-Total"]).to eq(commit_count) + expect(response.headers["X-Page"]).to eql("1") end end @@ -102,16 +102,16 @@ describe API::Commits do expect(json_response.second["id"]).to eq(commits.third.id) end - it 'include correct pagination headers' do + it "include correct pagination headers" do commits = project.repository.commits("master", limit: 2) before = commits.second.created_at - commit_count = project.repository.count_commits(ref: 'master', before: before).to_s + commit_count = project.repository.count_commits(ref: "master", before: before).to_s get api("/projects/#{project_id}/repository/commits?until=#{before.utc.iso8601}", user) expect(response).to include_pagination_headers - expect(response.headers['X-Total']).to eq(commit_count) - expect(response.headers['X-Page']).to eql('1') + expect(response.headers["X-Total"]).to eq(commit_count) + expect(response.headers["X-Page"]).to eql("1") end end @@ -120,101 +120,101 @@ describe API::Commits do get api("/projects/#{project_id}/repository/commits?since=invalid-date", user) expect(response).to have_gitlab_http_status(400) - expect(json_response['error']).to eq('since is invalid') + expect(json_response["error"]).to eq("since is invalid") end end context "path optional parameter" do it "returns project commits matching provided path parameter" do - path = 'files/ruby/popen.rb' - commit_count = project.repository.count_commits(ref: 'master', path: path).to_s + path = "files/ruby/popen.rb" + commit_count = project.repository.count_commits(ref: "master", path: path).to_s get api("/projects/#{project_id}/repository/commits?path=#{path}", user) expect(json_response.size).to eq(3) expect(json_response.first["id"]).to eq("570e7b2abdd848b95f2f578043fc23bd6f6fd24d") expect(response).to include_pagination_headers - expect(response.headers['X-Total']).to eq(commit_count) + expect(response.headers["X-Total"]).to eq(commit_count) end - it 'include correct pagination headers' do - path = 'files/ruby/popen.rb' - commit_count = project.repository.count_commits(ref: 'master', path: path).to_s + it "include correct pagination headers" do + path = "files/ruby/popen.rb" + commit_count = project.repository.count_commits(ref: "master", path: path).to_s get api("/projects/#{project_id}/repository/commits?path=#{path}", user) expect(response).to include_pagination_headers - expect(response.headers['X-Total']).to eq(commit_count) - expect(response.headers['X-Page']).to eql('1') + expect(response.headers["X-Total"]).to eq(commit_count) + expect(response.headers["X-Page"]).to eql("1") end end - context 'all optional parameter' do - it 'returns all project commits' do + context "all optional parameter" do + it "returns all project commits" do commit_count = project.repository.count_commits(all: true) get api("/projects/#{project_id}/repository/commits?all=true", user) expect(response).to include_pagination_headers - expect(response.headers['X-Total']).to eq(commit_count.to_s) - expect(response.headers['X-Page']).to eql('1') + expect(response.headers["X-Total"]).to eq(commit_count.to_s) + expect(response.headers["X-Page"]).to eql("1") end end - context 'with_stats optional parameter' do + context "with_stats optional parameter" do let(:project) { create(:project, :public, :repository) } - it_behaves_like 'project commits', schema: 'public_api/v4/commits_with_stats' do + it_behaves_like "project commits", schema: "public_api/v4/commits_with_stats" do let(:route) { "/projects/#{project_id}/repository/commits?with_stats=true" } - it 'include commits details' do + it "include commits details" do commit = project.repository.commit get api(route, current_user) - expect(json_response.first['stats']['additions']).to eq(commit.stats.additions) - expect(json_response.first['stats']['deletions']).to eq(commit.stats.deletions) - expect(json_response.first['stats']['total']).to eq(commit.stats.total) + expect(json_response.first["stats"]["additions"]).to eq(commit.stats.additions) + expect(json_response.first["stats"]["deletions"]).to eq(commit.stats.deletions) + expect(json_response.first["stats"]["total"]).to eq(commit.stats.total) end end end - context 'with pagination params' do + context "with pagination params" do let(:page) { 1 } let(:per_page) { 5 } - let(:ref_name) { 'master' } + let(:ref_name) { "master" } let!(:request) do get api("/projects/#{project_id}/repository/commits?page=#{page}&per_page=#{per_page}&ref_name=#{ref_name}", user) end - it 'returns correct headers' do + it "returns correct headers" do commit_count = project.repository.count_commits(ref: ref_name).to_s expect(response).to include_pagination_headers - expect(response.headers['X-Total']).to eq(commit_count) - expect(response.headers['X-Page']).to eq('1') - expect(response.headers['Link']).to match(/page=1&per_page=5/) - expect(response.headers['Link']).to match(/page=2&per_page=5/) + expect(response.headers["X-Total"]).to eq(commit_count) + expect(response.headers["X-Page"]).to eq("1") + expect(response.headers["Link"]).to match(/page=1&per_page=5/) + expect(response.headers["Link"]).to match(/page=2&per_page=5/) end - context 'viewing the first page' do - it 'returns the first 5 commits' do + context "viewing the first page" do + it "returns the first 5 commits" do commit = project.repository.commit expect(json_response.size).to eq(per_page) - expect(json_response.first['id']).to eq(commit.id) - expect(response.headers['X-Page']).to eq('1') + expect(json_response.first["id"]).to eq(commit.id) + expect(response.headers["X-Page"]).to eq("1") end end - context 'viewing the third page' do + context "viewing the third page" do let(:page) { 3 } - it 'returns the third 5 commits' do - commit = project.repository.commits('HEAD', limit: per_page, offset: (page - 1) * per_page).first + it "returns the third 5 commits" do + commit = project.repository.commits("HEAD", limit: per_page, offset: (page - 1) * per_page).first expect(json_response.size).to eq(per_page) - expect(json_response.first['id']).to eq(commit.id) - expect(response.headers['X-Page']).to eq('3') + expect(json_response.first["id"]).to eq(commit.id) + expect(response.headers["X-Page"]).to eq("3") end end end @@ -224,94 +224,94 @@ describe API::Commits do describe "POST /projects/:id/repository/commits" do let!(:url) { "/projects/#{project_id}/repository/commits" } - it 'returns a 403 unauthorized for user without permissions' do + it "returns a 403 unauthorized for user without permissions" do post api(url, guest) expect(response).to have_gitlab_http_status(403) end - it 'returns a 400 bad request if no params are given' do + it "returns a 400 bad request if no params are given" do post api(url, user) expect(response).to have_gitlab_http_status(400) end - describe 'create' do - let(:message) { 'Created a new file with a very very looooooooooooooooooooooooooooooooooooooooooooooong commit message' } + describe "create" do + let(:message) { "Created a new file with a very very looooooooooooooooooooooooooooooooooooooooooooooong commit message" } let(:invalid_c_params) do { - branch: 'master', + branch: "master", commit_message: message, actions: [ { - action: 'create', - file_path: 'files/ruby/popen.rb', - content: 'puts 8' - } - ] + action: "create", + file_path: "files/ruby/popen.rb", + content: "puts 8", + }, + ], } end let(:valid_c_params) do { - branch: 'master', + branch: "master", commit_message: message, actions: [ { - action: 'create', - file_path: 'foo/bar/baz.txt', - content: 'puts 8' - } - ] + action: "create", + file_path: "foo/bar/baz.txt", + content: "puts 8", + }, + ], } end let(:valid_utf8_c_params) do { - branch: 'master', + branch: "master", commit_message: message, actions: [ { - action: 'create', - file_path: 'foo/bar/baz.txt', - content: 'puts 🦊' - } - ] + action: "create", + file_path: "foo/bar/baz.txt", + content: "puts 🦊", + }, + ], } end - it 'does not increment the usage counters using access token authentication' do + it "does not increment the usage counters using access token authentication" do expect(::Gitlab::WebIdeCommitsCounter).not_to receive(:increment) post api(url, user), params: valid_c_params end - it 'a new file in project repo' do + it "a new file in project repo" do post api(url, user), params: valid_c_params expect(response).to have_gitlab_http_status(201) - expect(json_response['title']).to eq(message) - expect(json_response['committer_name']).to eq(user.name) - expect(json_response['committer_email']).to eq(user.email) + expect(json_response["title"]).to eq(message) + expect(json_response["committer_name"]).to eq(user.name) + expect(json_response["committer_email"]).to eq(user.email) end - it 'a new file with utf8 chars in project repo' do + it "a new file with utf8 chars in project repo" do post api(url, user), params: valid_utf8_c_params expect(response).to have_gitlab_http_status(201) - expect(json_response['title']).to eq(message) - expect(json_response['committer_name']).to eq(user.name) - expect(json_response['committer_email']).to eq(user.email) + expect(json_response["title"]).to eq(message) + expect(json_response["committer_name"]).to eq(user.name) + expect(json_response["committer_email"]).to eq(user.email) end - it 'returns a 400 bad request if file exists' do + it "returns a 400 bad request if file exists" do post api(url, user), params: invalid_c_params expect(response).to have_gitlab_http_status(400) end - context 'with project path containing a dot in URL' do + context "with project path containing a dot in URL" do let(:url) { "/projects/#{CGI.escape(project.full_path)}/repository/commits" } - it 'a new file in project repo' do + it "a new file in project repo" do post api(url, user), params: valid_c_params expect(response).to have_gitlab_http_status(201) @@ -319,1131 +319,1131 @@ describe API::Commits do end end - describe 'delete' do - let(:message) { 'Deleted file' } + describe "delete" do + let(:message) { "Deleted file" } let(:invalid_d_params) do { - branch: 'markdown', + branch: "markdown", commit_message: message, actions: [ { - action: 'delete', - file_path: 'doc/api/projects.md' - } - ] + action: "delete", + file_path: "doc/api/projects.md", + }, + ], } end let(:valid_d_params) do { - branch: 'markdown', + branch: "markdown", commit_message: message, actions: [ { - action: 'delete', - file_path: 'doc/api/users.md' - } - ] + action: "delete", + file_path: "doc/api/users.md", + }, + ], } end - it 'an existing file in project repo' do + it "an existing file in project repo" do post api(url, user), params: valid_d_params expect(response).to have_gitlab_http_status(201) - expect(json_response['title']).to eq(message) + expect(json_response["title"]).to eq(message) end - it 'returns a 400 bad request if file does not exist' do + it "returns a 400 bad request if file does not exist" do post api(url, user), params: invalid_d_params expect(response).to have_gitlab_http_status(400) end end - describe 'move' do - let(:message) { 'Moved file' } + describe "move" do + let(:message) { "Moved file" } let(:invalid_m_params) do { - branch: 'feature', + branch: "feature", commit_message: message, actions: [ { - action: 'move', - file_path: 'CHANGELOG', - previous_path: 'VERSION', - content: '6.7.0.pre' - } - ] + action: "move", + file_path: "CHANGELOG", + previous_path: "VERSION", + content: "6.7.0.pre", + }, + ], } end let(:valid_m_params) do { - branch: 'feature', + branch: "feature", commit_message: message, actions: [ { - action: 'move', - file_path: 'VERSION.txt', - previous_path: 'VERSION', - content: '6.7.0.pre' - } - ] + action: "move", + file_path: "VERSION.txt", + previous_path: "VERSION", + content: "6.7.0.pre", + }, + ], } end - it 'an existing file in project repo' do + it "an existing file in project repo" do post api(url, user), params: valid_m_params expect(response).to have_gitlab_http_status(201) - expect(json_response['title']).to eq(message) + expect(json_response["title"]).to eq(message) end - it 'returns a 400 bad request if file does not exist' do + it "returns a 400 bad request if file does not exist" do post api(url, user), params: invalid_m_params expect(response).to have_gitlab_http_status(400) end end - describe 'update' do - let(:message) { 'Updated file' } + describe "update" do + let(:message) { "Updated file" } let(:invalid_u_params) do { - branch: 'master', + branch: "master", commit_message: message, actions: [ { - action: 'update', - file_path: 'foo/bar.baz', - content: 'puts 8' - } - ] + action: "update", + file_path: "foo/bar.baz", + content: "puts 8", + }, + ], } end let(:valid_u_params) do { - branch: 'master', + branch: "master", commit_message: message, actions: [ { - action: 'update', - file_path: 'files/ruby/popen.rb', - content: 'puts 8' - } - ] + action: "update", + file_path: "files/ruby/popen.rb", + content: "puts 8", + }, + ], } end - it 'an existing file in project repo' do + it "an existing file in project repo" do post api(url, user), params: valid_u_params expect(response).to have_gitlab_http_status(201) - expect(json_response['title']).to eq(message) + expect(json_response["title"]).to eq(message) end - it 'returns a 400 bad request if file does not exist' do + it "returns a 400 bad request if file does not exist" do post api(url, user), params: invalid_u_params expect(response).to have_gitlab_http_status(400) end end - describe 'chmod' do - let(:message) { 'Chmod +x file' } - let(:file_path) { 'files/ruby/popen.rb' } + describe "chmod" do + let(:message) { "Chmod +x file" } + let(:file_path) { "files/ruby/popen.rb" } let(:execute_filemode) { true } let(:params) do { - branch: 'master', + branch: "master", commit_message: message, actions: [ { - action: 'chmod', + action: "chmod", file_path: file_path, - execute_filemode: execute_filemode - } - ] + execute_filemode: execute_filemode, + }, + ], } end - it 'responds with success' do + it "responds with success" do post api(url, user), params: params expect(response).to have_gitlab_http_status(201) - expect(json_response['title']).to eq(message) + expect(json_response["title"]).to eq(message) end - context 'when execute_filemode is false' do + context "when execute_filemode is false" do let(:execute_filemode) { false } - it 'responds with success' do + it "responds with success" do post api(url, user), params: params expect(response).to have_gitlab_http_status(201) - expect(json_response['title']).to eq(message) + expect(json_response["title"]).to eq(message) end end context "when the file doesn't exists" do - let(:file_path) { 'foo/bar.baz' } + let(:file_path) { "foo/bar.baz" } it "responds with 400" do post api(url, user), params: params expect(response).to have_gitlab_http_status(400) - expect(json_response['message']).to eq("A file with this name doesn't exist") + expect(json_response["message"]).to eq("A file with this name doesn't exist") end end end - describe 'multiple operations' do - let(:message) { 'Multiple actions' } + describe "multiple operations" do + let(:message) { "Multiple actions" } let(:invalid_mo_params) do { - branch: 'master', + branch: "master", commit_message: message, actions: [ { - action: 'create', - file_path: 'files/ruby/popen.rb', - content: 'puts 8' + action: "create", + file_path: "files/ruby/popen.rb", + content: "puts 8", }, { - action: 'delete', - file_path: 'doc/api/projects.md' + action: "delete", + file_path: "doc/api/projects.md", }, { - action: 'move', - file_path: 'CHANGELOG', - previous_path: 'VERSION', - content: '6.7.0.pre' + action: "move", + file_path: "CHANGELOG", + previous_path: "VERSION", + content: "6.7.0.pre", }, { - action: 'update', - file_path: 'foo/bar.baz', - content: 'puts 8' + action: "update", + file_path: "foo/bar.baz", + content: "puts 8", }, { - action: 'chmod', - file_path: 'files/ruby/popen.rb', - execute_filemode: true - } - ] + action: "chmod", + file_path: "files/ruby/popen.rb", + execute_filemode: true, + }, + ], } end let(:valid_mo_params) do { - branch: 'master', + branch: "master", commit_message: message, actions: [ { - action: 'create', - file_path: 'foo/bar/baz.txt', - content: 'puts 8' + action: "create", + file_path: "foo/bar/baz.txt", + content: "puts 8", }, { - action: 'delete', - file_path: 'Gemfile.zip' + action: "delete", + file_path: "Gemfile.zip", }, { - action: 'move', - file_path: 'VERSION.txt', - previous_path: 'VERSION', - content: '6.7.0.pre' + action: "move", + file_path: "VERSION.txt", + previous_path: "VERSION", + content: "6.7.0.pre", }, { - action: 'update', - file_path: 'files/ruby/popen.rb', - content: 'puts 8' + action: "update", + file_path: "files/ruby/popen.rb", + content: "puts 8", }, { - action: 'chmod', - file_path: 'files/ruby/popen.rb', - execute_filemode: true - } - ] + action: "chmod", + file_path: "files/ruby/popen.rb", + execute_filemode: true, + }, + ], } end - it 'are committed as one in project repo' do + it "are committed as one in project repo" do post api(url, user), params: valid_mo_params expect(response).to have_gitlab_http_status(201) - expect(json_response['title']).to eq(message) + expect(json_response["title"]).to eq(message) end - it 'includes the commit stats' do + it "includes the commit stats" do post api(url, user), params: valid_mo_params expect(response).to have_gitlab_http_status(201) - expect(json_response).to include 'stats' + expect(json_response).to include "stats" end it "doesn't include the commit stats when stats is false" do post api(url, user), params: valid_mo_params.merge(stats: false) expect(response).to have_gitlab_http_status(201) - expect(json_response).not_to include 'stats' + expect(json_response).not_to include "stats" end - it 'return a 400 bad request if there are any issues' do + it "return a 400 bad request if there are any issues" do post api(url, user), params: invalid_mo_params expect(response).to have_gitlab_http_status(400) end end - context 'when committing into a fork as a maintainer' do - include_context 'merge request allowing collaboration' + context "when committing into a fork as a maintainer" do + include_context "merge request allowing collaboration" let(:project_id) { forked_project.id } def push_params(branch_name) { branch: branch_name, - commit_message: 'Hello world', + commit_message: "Hello world", actions: [ { - action: 'create', - file_path: 'foo/bar/baz.txt', - content: 'puts 8' - } - ] + action: "create", + file_path: "foo/bar/baz.txt", + content: "puts 8", + }, + ], } end - it 'allows pushing to the source branch of the merge request' do - post api(url, user), params: push_params('feature') + it "allows pushing to the source branch of the merge request" do + post api(url, user), params: push_params("feature") expect(response).to have_gitlab_http_status(:created) end - it 'denies pushing to another branch' do - post api(url, user), params: push_params('other-branch') + it "denies pushing to another branch" do + post api(url, user), params: push_params("other-branch") expect(response).to have_gitlab_http_status(:forbidden) end end end - describe 'GET /projects/:id/repository/commits/:sha/refs' do + describe "GET /projects/:id/repository/commits/:sha/refs" do let(:project) { create(:project, :public, :repository) } - let(:tag) { project.repository.find_tag('v1.1.0') } + let(:tag) { project.repository.find_tag("v1.1.0") } let(:commit_id) { tag.dereferenced_target.id } let(:route) { "/projects/#{project_id}/repository/commits/#{commit_id}/refs" } - context 'when ref does not exist' do - let(:commit_id) { 'unknown' } + context "when ref does not exist" do + let(:commit_id) { "unknown" } - it_behaves_like '404 response' do + it_behaves_like "404 response" do let(:request) { get api(route, current_user) } - let(:message) { '404 Commit Not Found' } + let(:message) { "404 Commit Not Found" } end end - context 'when repository is disabled' do - include_context 'disabled repository' + context "when repository is disabled" do + include_context "disabled repository" - it_behaves_like '403 response' do + it_behaves_like "403 response" do let(:request) { get api(route, current_user) } end end - context 'for a valid commit' do - it 'returns all refs with no scope' do - get api(route, current_user), params: { per_page: 100 } + context "for a valid commit" do + it "returns all refs with no scope" do + get api(route, current_user), params: {per_page: 100} - refs = project.repository.branch_names_contains(commit_id).map {|name| ['branch', name]} - refs.concat(project.repository.tag_names_contains(commit_id).map {|name| ['tag', name]}) + refs = project.repository.branch_names_contains(commit_id).map {|name| ["branch", name]} + refs.concat(project.repository.tag_names_contains(commit_id).map {|name| ["tag", name]}) expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response).to be_an Array - expect(json_response.map { |r| [r['type'], r['name']] }.compact).to eq(refs) + expect(json_response.map { |r| [r["type"], r["name"]] }.compact).to eq(refs) end - it 'returns all refs' do - get api(route, current_user), params: { type: 'all', per_page: 100 } + it "returns all refs" do + get api(route, current_user), params: {type: "all", per_page: 100} - refs = project.repository.branch_names_contains(commit_id).map {|name| ['branch', name]} - refs.concat(project.repository.tag_names_contains(commit_id).map {|name| ['tag', name]}) + refs = project.repository.branch_names_contains(commit_id).map {|name| ["branch", name]} + refs.concat(project.repository.tag_names_contains(commit_id).map {|name| ["tag", name]}) expect(response).to have_gitlab_http_status(200) - expect(json_response.map { |r| [r['type'], r['name']] }.compact).to eq(refs) + expect(json_response.map { |r| [r["type"], r["name"]] }.compact).to eq(refs) end - it 'returns the branch refs' do - get api(route, current_user), params: { type: 'branch', per_page: 100 } + it "returns the branch refs" do + get api(route, current_user), params: {type: "branch", per_page: 100} - refs = project.repository.branch_names_contains(commit_id).map {|name| ['branch', name]} + refs = project.repository.branch_names_contains(commit_id).map {|name| ["branch", name]} expect(response).to have_gitlab_http_status(200) - expect(json_response.map { |r| [r['type'], r['name']] }.compact).to eq(refs) + expect(json_response.map { |r| [r["type"], r["name"]] }.compact).to eq(refs) end - it 'returns the tag refs' do - get api(route, current_user), params: { type: 'tag', per_page: 100 } + it "returns the tag refs" do + get api(route, current_user), params: {type: "tag", per_page: 100} - refs = project.repository.tag_names_contains(commit_id).map {|name| ['tag', name]} + refs = project.repository.tag_names_contains(commit_id).map {|name| ["tag", name]} expect(response).to have_gitlab_http_status(200) - expect(json_response.map { |r| [r['type'], r['name']] }.compact).to eq(refs) + expect(json_response.map { |r| [r["type"], r["name"]] }.compact).to eq(refs) end end end - describe 'GET /projects/:id/repository/commits/:sha' do + describe "GET /projects/:id/repository/commits/:sha" do let(:commit) { project.repository.commit } let(:commit_id) { commit.id } let(:route) { "/projects/#{project_id}/repository/commits/#{commit_id}" } - shared_examples_for 'ref commit' do - it 'returns the ref last commit' do + shared_examples_for "ref commit" do + it "returns the ref last commit" do get api(route, current_user) expect(response).to have_gitlab_http_status(200) - expect(response).to match_response_schema('public_api/v4/commit/detail') - expect(json_response['id']).to eq(commit.id) - expect(json_response['short_id']).to eq(commit.short_id) - expect(json_response['title']).to eq(commit.title) - expect(json_response['message']).to eq(commit.safe_message) - expect(json_response['author_name']).to eq(commit.author_name) - expect(json_response['author_email']).to eq(commit.author_email) - expect(json_response['authored_date']).to eq(commit.authored_date.iso8601(3)) - expect(json_response['committer_name']).to eq(commit.committer_name) - expect(json_response['committer_email']).to eq(commit.committer_email) - expect(json_response['committed_date']).to eq(commit.committed_date.iso8601(3)) - expect(json_response['parent_ids']).to eq(commit.parent_ids) - expect(json_response['stats']['additions']).to eq(commit.stats.additions) - expect(json_response['stats']['deletions']).to eq(commit.stats.deletions) - expect(json_response['stats']['total']).to eq(commit.stats.total) - expect(json_response['status']).to be_nil - expect(json_response['last_pipeline']).to be_nil - end - - context 'when ref does not exist' do - let(:commit_id) { 'unknown' } - - it_behaves_like '404 response' do + expect(response).to match_response_schema("public_api/v4/commit/detail") + expect(json_response["id"]).to eq(commit.id) + expect(json_response["short_id"]).to eq(commit.short_id) + expect(json_response["title"]).to eq(commit.title) + expect(json_response["message"]).to eq(commit.safe_message) + expect(json_response["author_name"]).to eq(commit.author_name) + expect(json_response["author_email"]).to eq(commit.author_email) + expect(json_response["authored_date"]).to eq(commit.authored_date.iso8601(3)) + expect(json_response["committer_name"]).to eq(commit.committer_name) + expect(json_response["committer_email"]).to eq(commit.committer_email) + expect(json_response["committed_date"]).to eq(commit.committed_date.iso8601(3)) + expect(json_response["parent_ids"]).to eq(commit.parent_ids) + expect(json_response["stats"]["additions"]).to eq(commit.stats.additions) + expect(json_response["stats"]["deletions"]).to eq(commit.stats.deletions) + expect(json_response["stats"]["total"]).to eq(commit.stats.total) + expect(json_response["status"]).to be_nil + expect(json_response["last_pipeline"]).to be_nil + end + + context "when ref does not exist" do + let(:commit_id) { "unknown" } + + it_behaves_like "404 response" do let(:request) { get api(route, current_user) } - let(:message) { '404 Commit Not Found' } + let(:message) { "404 Commit Not Found" } end end - context 'when repository is disabled' do - include_context 'disabled repository' + context "when repository is disabled" do + include_context "disabled repository" - it_behaves_like '403 response' do + it_behaves_like "403 response" do let(:request) { get api(route, current_user) } end end end - context 'when stat param' do + context "when stat param" do let(:route) { "/projects/#{project_id}/repository/commits/#{commit_id}" } - it 'is not present return stats by default' do + it "is not present return stats by default" do get api(route, user) expect(response).to have_gitlab_http_status(200) - expect(json_response).to include 'stats' + expect(json_response).to include "stats" end it "is false it does not include stats" do - get api(route, user), params: { stats: false } + get api(route, user), params: {stats: false} expect(response).to have_gitlab_http_status(200) - expect(json_response).not_to include 'stats' + expect(json_response).not_to include "stats" end it "is true it includes stats" do - get api(route, user), params: { stats: true } + get api(route, user), params: {stats: true} expect(response).to have_gitlab_http_status(200) - expect(json_response).to include 'stats' + expect(json_response).to include "stats" end end - context 'when unauthenticated', 'and project is public' do + context "when unauthenticated", "and project is public" do let(:project) { create(:project, :public, :repository) } - it_behaves_like 'ref commit' + it_behaves_like "ref commit" end - context 'when unauthenticated', 'and project is private' do - it_behaves_like '404 response' do + context "when unauthenticated", "and project is private" do + it_behaves_like "404 response" do let(:request) { get api(route) } - let(:message) { '404 Project Not Found' } + let(:message) { "404 Project Not Found" } end end - context 'when authenticated', 'as a maintainer' do + context "when authenticated", "as a maintainer" do let(:current_user) { user } - it_behaves_like 'ref commit' + it_behaves_like "ref commit" - context 'when branch contains a dot' do + context "when branch contains a dot" do let(:commit) { project.repository.commit(branch_with_dot.name) } let(:commit_id) { branch_with_dot.name } - it_behaves_like 'ref commit' + it_behaves_like "ref commit" end - context 'when branch contains a slash' do + context "when branch contains a slash" do let(:commit_id) { branch_with_slash.name } - it_behaves_like '404 response' do + it_behaves_like "404 response" do let(:request) { get api(route, current_user) } end end - context 'when branch contains an escaped slash' do + context "when branch contains an escaped slash" do let(:commit) { project.repository.commit(branch_with_slash.name) } let(:commit_id) { CGI.escape(branch_with_slash.name) } - it_behaves_like 'ref commit' + it_behaves_like "ref commit" end - context 'requesting with the escaped project full path' do + context "requesting with the escaped project full path" do let(:project_id) { CGI.escape(project.full_path) } - it_behaves_like 'ref commit' + it_behaves_like "ref commit" - context 'when branch contains a dot' do + context "when branch contains a dot" do let(:commit) { project.repository.commit(branch_with_dot.name) } let(:commit_id) { branch_with_dot.name } - it_behaves_like 'ref commit' + it_behaves_like "ref commit" end end - context 'when the ref has a pipeline' do - let!(:pipeline) { project.ci_pipelines.create(source: :push, ref: 'master', sha: commit.sha, protected: false) } + context "when the ref has a pipeline" do + let!(:pipeline) { project.ci_pipelines.create(source: :push, ref: "master", sha: commit.sha, protected: false) } it 'includes a "created" status' do get api(route, current_user) expect(response).to have_gitlab_http_status(200) - expect(response).to match_response_schema('public_api/v4/commit/detail') - expect(json_response['status']).to eq('created') - expect(json_response['last_pipeline']['id']).to eq(pipeline.id) - expect(json_response['last_pipeline']['ref']).to eq(pipeline.ref) - expect(json_response['last_pipeline']['sha']).to eq(pipeline.sha) - expect(json_response['last_pipeline']['status']).to eq(pipeline.status) + expect(response).to match_response_schema("public_api/v4/commit/detail") + expect(json_response["status"]).to eq("created") + expect(json_response["last_pipeline"]["id"]).to eq(pipeline.id) + expect(json_response["last_pipeline"]["ref"]).to eq(pipeline.ref) + expect(json_response["last_pipeline"]["sha"]).to eq(pipeline.sha) + expect(json_response["last_pipeline"]["status"]).to eq(pipeline.status) end - context 'when pipeline succeeds' do + context "when pipeline succeeds" do before do - pipeline.update(status: 'success') + pipeline.update(status: "success") end it 'includes a "success" status' do get api(route, current_user) expect(response).to have_gitlab_http_status(200) - expect(response).to match_response_schema('public_api/v4/commit/detail') - expect(json_response['status']).to eq('success') + expect(response).to match_response_schema("public_api/v4/commit/detail") + expect(json_response["status"]).to eq("success") end end end end end - describe 'GET /projects/:id/repository/commits/:sha/diff' do + describe "GET /projects/:id/repository/commits/:sha/diff" do let(:commit) { project.repository.commit } let(:commit_id) { commit.id } let(:route) { "/projects/#{project_id}/repository/commits/#{commit_id}/diff" } - shared_examples_for 'ref diff' do - it 'returns the diff of the selected commit' do + shared_examples_for "ref diff" do + it "returns the diff of the selected commit" do get api(route, current_user) expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response.size).to be >= 1 - expect(json_response.first.keys).to include 'diff' + expect(json_response.first.keys).to include "diff" end - context 'when ref does not exist' do - let(:commit_id) { 'unknown' } + context "when ref does not exist" do + let(:commit_id) { "unknown" } - it_behaves_like '404 response' do + it_behaves_like "404 response" do let(:request) { get api(route, current_user) } - let(:message) { '404 Commit Not Found' } + let(:message) { "404 Commit Not Found" } end end - context 'when repository is disabled' do - include_context 'disabled repository' + context "when repository is disabled" do + include_context "disabled repository" - it_behaves_like '403 response' do + it_behaves_like "403 response" do let(:request) { get api(route, current_user) } end end end - context 'when unauthenticated', 'and project is public' do + context "when unauthenticated", "and project is public" do let(:project) { create(:project, :public, :repository) } - it_behaves_like 'ref diff' + it_behaves_like "ref diff" end - context 'when unauthenticated', 'and project is private' do - it_behaves_like '404 response' do + context "when unauthenticated", "and project is private" do + it_behaves_like "404 response" do let(:request) { get api(route) } - let(:message) { '404 Project Not Found' } + let(:message) { "404 Project Not Found" } end end - context 'when authenticated', 'as a maintainer' do + context "when authenticated", "as a maintainer" do let(:current_user) { user } - it_behaves_like 'ref diff' + it_behaves_like "ref diff" - context 'when branch contains a dot' do + context "when branch contains a dot" do let(:commit_id) { branch_with_dot.name } - it_behaves_like 'ref diff' + it_behaves_like "ref diff" end - context 'when branch contains a slash' do + context "when branch contains a slash" do let(:commit_id) { branch_with_slash.name } - it_behaves_like '404 response' do + it_behaves_like "404 response" do let(:request) { get api(route, current_user) } end end - context 'when branch contains an escaped slash' do + context "when branch contains an escaped slash" do let(:commit_id) { CGI.escape(branch_with_slash.name) } - it_behaves_like 'ref diff' + it_behaves_like "ref diff" end - context 'requesting with the escaped project full path' do + context "requesting with the escaped project full path" do let(:project_id) { CGI.escape(project.full_path) } - it_behaves_like 'ref diff' + it_behaves_like "ref diff" - context 'when branch contains a dot' do + context "when branch contains a dot" do let(:commit_id) { branch_with_dot.name } - it_behaves_like 'ref diff' + it_behaves_like "ref diff" end end - context 'when binary diff are treated as text' do - let(:commit_id) { TestEnv::BRANCH_SHA['add-pdf-text-binary'] } + context "when binary diff are treated as text" do + let(:commit_id) { TestEnv::BRANCH_SHA["add-pdf-text-binary"] } - it_behaves_like 'ref diff' + it_behaves_like "ref diff" end end end - describe 'GET /projects/:id/repository/commits/:sha/comments' do + describe "GET /projects/:id/repository/commits/:sha/comments" do let(:commit) { project.repository.commit } let(:commit_id) { commit.id } let(:route) { "/projects/#{project_id}/repository/commits/#{commit_id}/comments" } - shared_examples_for 'ref comments' do - context 'when ref exists' do + shared_examples_for "ref comments" do + context "when ref exists" do before do - create(:note_on_commit, author: user, project: project, commit_id: commit.id, note: 'a comment on a commit') - create(:note_on_commit, author: user, project: project, commit_id: commit.id, note: 'another comment on a commit') + create(:note_on_commit, author: user, project: project, commit_id: commit.id, note: "a comment on a commit") + create(:note_on_commit, author: user, project: project, commit_id: commit.id, note: "another comment on a commit") end - it 'returns the diff of the selected commit' do + it "returns the diff of the selected commit" do get api(route, current_user) expect(response).to have_gitlab_http_status(200) - expect(response).to match_response_schema('public_api/v4/commit_notes') + expect(response).to match_response_schema("public_api/v4/commit_notes") expect(json_response.size).to eq(2) - expect(json_response.first['note']).to eq('a comment on a commit') - expect(json_response.first['author']['id']).to eq(user.id) + expect(json_response.first["note"]).to eq("a comment on a commit") + expect(json_response.first["author"]["id"]).to eq(user.id) end end - context 'when ref does not exist' do - let(:commit_id) { 'unknown' } + context "when ref does not exist" do + let(:commit_id) { "unknown" } - it_behaves_like '404 response' do + it_behaves_like "404 response" do let(:request) { get api(route, current_user) } - let(:message) { '404 Commit Not Found' } + let(:message) { "404 Commit Not Found" } end end - context 'when repository is disabled' do - include_context 'disabled repository' + context "when repository is disabled" do + include_context "disabled repository" - it_behaves_like '403 response' do + it_behaves_like "403 response" do let(:request) { get api(route, current_user) } end end end - context 'when unauthenticated', 'and project is public' do + context "when unauthenticated", "and project is public" do let(:project) { create(:project, :public, :repository) } - it_behaves_like 'ref comments' + it_behaves_like "ref comments" end - context 'when unauthenticated', 'and project is private' do - it_behaves_like '404 response' do + context "when unauthenticated", "and project is private" do + it_behaves_like "404 response" do let(:request) { get api(route) } - let(:message) { '404 Project Not Found' } + let(:message) { "404 Project Not Found" } end end - context 'when authenticated', 'as a maintainer' do + context "when authenticated", "as a maintainer" do let(:current_user) { user } - it_behaves_like 'ref comments' + it_behaves_like "ref comments" - context 'when branch contains a dot' do + context "when branch contains a dot" do let(:commit) { project.repository.commit(branch_with_dot.name) } let(:commit_id) { branch_with_dot.name } - it_behaves_like 'ref comments' + it_behaves_like "ref comments" end - context 'when branch contains a slash' do + context "when branch contains a slash" do let(:commit) { project.repository.commit(branch_with_slash.name) } let(:commit_id) { branch_with_slash.name } - it_behaves_like '404 response' do + it_behaves_like "404 response" do let(:request) { get api(route, current_user) } end end - context 'when branch contains an escaped slash' do + context "when branch contains an escaped slash" do let(:commit) { project.repository.commit(branch_with_slash.name) } let(:commit_id) { CGI.escape(branch_with_slash.name) } - it_behaves_like 'ref comments' + it_behaves_like "ref comments" end - context 'requesting with the escaped project full path' do + context "requesting with the escaped project full path" do let(:project_id) { CGI.escape(project.full_path) } - it_behaves_like 'ref comments' + it_behaves_like "ref comments" - context 'when branch contains a dot' do + context "when branch contains a dot" do let(:commit) { project.repository.commit(branch_with_dot.name) } let(:commit_id) { branch_with_dot.name } - it_behaves_like 'ref comments' + it_behaves_like "ref comments" end end end - context 'when the commit is present on two projects' do + context "when the commit is present on two projects" do let(:forked_project) { create(:project, :repository, creator: guest, namespace: guest.namespace) } - let!(:forked_project_note) { create(:note_on_commit, author: guest, project: forked_project, commit_id: forked_project.repository.commit.id, note: 'a comment on a commit for fork') } + let!(:forked_project_note) { create(:note_on_commit, author: guest, project: forked_project, commit_id: forked_project.repository.commit.id, note: "a comment on a commit for fork") } let(:project_id) { forked_project.id } let(:commit_id) { forked_project.repository.commit.id } - it 'returns the comments for the target project' do + it "returns the comments for the target project" do get api(route, guest) expect(response).to have_gitlab_http_status(200) - expect(response).to match_response_schema('public_api/v4/commit_notes') + expect(response).to match_response_schema("public_api/v4/commit_notes") expect(json_response.size).to eq(1) - expect(json_response.first['note']).to eq('a comment on a commit for fork') - expect(json_response.first['author']['id']).to eq(guest.id) + expect(json_response.first["note"]).to eq("a comment on a commit for fork") + expect(json_response.first["author"]["id"]).to eq(guest.id) end end end - describe 'POST :id/repository/commits/:sha/cherry_pick' do - let(:commit) { project.commit('7d3b0f7cff5f37573aea97cebfd5692ea1689924') } + describe "POST :id/repository/commits/:sha/cherry_pick" do + let(:commit) { project.commit("7d3b0f7cff5f37573aea97cebfd5692ea1689924") } let(:commit_id) { commit.id } - let(:branch) { 'master' } + let(:branch) { "master" } let(:route) { "/projects/#{project_id}/repository/commits/#{commit_id}/cherry_pick" } - shared_examples_for 'ref cherry-pick' do - context 'when ref exists' do - it 'cherry-picks the ref commit' do - post api(route, current_user), params: { branch: branch } + shared_examples_for "ref cherry-pick" do + context "when ref exists" do + it "cherry-picks the ref commit" do + post api(route, current_user), params: {branch: branch} expect(response).to have_gitlab_http_status(201) - expect(response).to match_response_schema('public_api/v4/commit/basic') - expect(json_response['title']).to eq(commit.title) - expect(json_response['message']).to eq(commit.cherry_pick_message(user)) - expect(json_response['author_name']).to eq(commit.author_name) - expect(json_response['committer_name']).to eq(user.name) + expect(response).to match_response_schema("public_api/v4/commit/basic") + expect(json_response["title"]).to eq(commit.title) + expect(json_response["message"]).to eq(commit.cherry_pick_message(user)) + expect(json_response["author_name"]).to eq(commit.author_name) + expect(json_response["committer_name"]).to eq(user.name) end end - context 'when repository is disabled' do - include_context 'disabled repository' + context "when repository is disabled" do + include_context "disabled repository" - it_behaves_like '403 response' do - let(:request) { post api(route, current_user), params: { branch: 'master' } } + it_behaves_like "403 response" do + let(:request) { post api(route, current_user), params: {branch: "master"} } end end end - context 'when unauthenticated', 'and project is public' do + context "when unauthenticated", "and project is public" do let(:project) { create(:project, :public, :repository) } - it_behaves_like '403 response' do - let(:request) { post api(route), params: { branch: 'master' } } + it_behaves_like "403 response" do + let(:request) { post api(route), params: {branch: "master"} } end end - context 'when unauthenticated', 'and project is private' do - it_behaves_like '404 response' do - let(:request) { post api(route), params: { branch: 'master' } } - let(:message) { '404 Project Not Found' } + context "when unauthenticated", "and project is private" do + it_behaves_like "404 response" do + let(:request) { post api(route), params: {branch: "master"} } + let(:message) { "404 Project Not Found" } end end - context 'when authenticated', 'as an owner' do + context "when authenticated", "as an owner" do let(:current_user) { user } - it_behaves_like 'ref cherry-pick' + it_behaves_like "ref cherry-pick" - context 'when ref does not exist' do - let(:commit_id) { 'unknown' } + context "when ref does not exist" do + let(:commit_id) { "unknown" } - it_behaves_like '404 response' do - let(:request) { post api(route, current_user), params: { branch: 'master' } } - let(:message) { '404 Commit Not Found' } + it_behaves_like "404 response" do + let(:request) { post api(route, current_user), params: {branch: "master"} } + let(:message) { "404 Commit Not Found" } end end - context 'when branch is missing' do - it_behaves_like '400 response' do + context "when branch is missing" do + it_behaves_like "400 response" do let(:request) { post api(route, current_user) } end end - context 'when branch is empty' do - ['', ' '].each do |branch| - it_behaves_like '400 response' do - let(:request) { post api(route, current_user), params: { branch: branch } } + context "when branch is empty" do + ["", " "].each do |branch| + it_behaves_like "400 response" do + let(:request) { post api(route, current_user), params: {branch: branch} } end end end - context 'when branch does not exist' do - it_behaves_like '404 response' do - let(:request) { post api(route, current_user), params: { branch: 'foo' } } - let(:message) { '404 Branch Not Found' } + context "when branch does not exist" do + it_behaves_like "404 response" do + let(:request) { post api(route, current_user), params: {branch: "foo"} } + let(:message) { "404 Branch Not Found" } end end - context 'when commit is already included in the target branch' do - it_behaves_like '400 response' do - let(:request) { post api(route, current_user), params: { branch: 'markdown' } } + context "when commit is already included in the target branch" do + it_behaves_like "400 response" do + let(:request) { post api(route, current_user), params: {branch: "markdown"} } end end - context 'when ref contains a dot' do + context "when ref contains a dot" do let(:commit) { project.repository.commit(branch_with_dot.name) } let(:commit_id) { branch_with_dot.name } - it_behaves_like 'ref cherry-pick' + it_behaves_like "ref cherry-pick" end - context 'when ref contains a slash' do + context "when ref contains a slash" do let(:commit_id) { branch_with_slash.name } - it_behaves_like '404 response' do - let(:request) { post api(route, current_user), params: { branch: 'master' } } + it_behaves_like "404 response" do + let(:request) { post api(route, current_user), params: {branch: "master"} } end end - context 'requesting with the escaped project full path' do + context "requesting with the escaped project full path" do let(:project_id) { CGI.escape(project.full_path) } - it_behaves_like 'ref cherry-pick' + it_behaves_like "ref cherry-pick" - context 'when ref contains a dot' do + context "when ref contains a dot" do let(:commit) { project.repository.commit(branch_with_dot.name) } let(:commit_id) { branch_with_dot.name } - it_behaves_like 'ref cherry-pick' + it_behaves_like "ref cherry-pick" end end end - context 'when authenticated', 'as a developer' do + context "when authenticated", "as a developer" do let(:current_user) { guest } before do project.add_developer(guest) end - context 'when branch is protected' do + context "when branch is protected" do before do - create(:protected_branch, project: project, name: 'feature') + create(:protected_branch, project: project, name: "feature") end - it 'returns 400 if you are not allowed to push to the target branch' do - post api(route, current_user), params: { branch: 'feature' } + it "returns 400 if you are not allowed to push to the target branch" do + post api(route, current_user), params: {branch: "feature"} expect(response).to have_gitlab_http_status(:forbidden) - expect(json_response['message']).to match(/You are not allowed to push into this branch/) + expect(json_response["message"]).to match(/You are not allowed to push into this branch/) end end end - context 'when cherry picking to a fork as a maintainer' do - include_context 'merge request allowing collaboration' + context "when cherry picking to a fork as a maintainer" do + include_context "merge request allowing collaboration" let(:project_id) { forked_project.id } - it 'allows access from a maintainer that to the source branch' do - post api(route, user), params: { branch: 'feature' } + it "allows access from a maintainer that to the source branch" do + post api(route, user), params: {branch: "feature"} expect(response).to have_gitlab_http_status(:created) end - it 'denies cherry picking to another branch' do - post api(route, user), params: { branch: 'master' } + it "denies cherry picking to another branch" do + post api(route, user), params: {branch: "master"} expect(response).to have_gitlab_http_status(:forbidden) end end end - describe 'POST :id/repository/commits/:sha/revert' do - let(:commit_id) { 'b83d6e391c22777fca1ed3012fce84f633d7fed0' } + describe "POST :id/repository/commits/:sha/revert" do + let(:commit_id) { "b83d6e391c22777fca1ed3012fce84f633d7fed0" } let(:commit) { project.commit(commit_id) } - let(:branch) { 'master' } + let(:branch) { "master" } let(:route) { "/projects/#{project_id}/repository/commits/#{commit_id}/revert" } - shared_examples_for 'ref revert' do - context 'when ref exists' do - it 'reverts the ref commit' do - post api(route, current_user), params: { branch: branch } + shared_examples_for "ref revert" do + context "when ref exists" do + it "reverts the ref commit" do + post api(route, current_user), params: {branch: branch} expect(response).to have_gitlab_http_status(201) - expect(response).to match_response_schema('public_api/v4/commit/basic') + expect(response).to match_response_schema("public_api/v4/commit/basic") - expect(json_response['message']).to eq(commit.revert_message(user)) - expect(json_response['author_name']).to eq(user.name) - expect(json_response['committer_name']).to eq(user.name) - expect(json_response['parent_ids']).to contain_exactly(commit_id) + expect(json_response["message"]).to eq(commit.revert_message(user)) + expect(json_response["author_name"]).to eq(user.name) + expect(json_response["committer_name"]).to eq(user.name) + expect(json_response["parent_ids"]).to contain_exactly(commit_id) end end - context 'when repository is disabled' do - include_context 'disabled repository' + context "when repository is disabled" do + include_context "disabled repository" - it_behaves_like '403 response' do - let(:request) { post api(route, current_user), params: { branch: branch } } + it_behaves_like "403 response" do + let(:request) { post api(route, current_user), params: {branch: branch} } end end end - context 'when unauthenticated', 'and project is public' do + context "when unauthenticated", "and project is public" do let(:project) { create(:project, :public, :repository) } - it_behaves_like '403 response' do - let(:request) { post api(route), params: { branch: branch } } + it_behaves_like "403 response" do + let(:request) { post api(route), params: {branch: branch} } end end - context 'when unauthenticated', 'and project is private' do - it_behaves_like '404 response' do - let(:request) { post api(route), params: { branch: branch } } - let(:message) { '404 Project Not Found' } + context "when unauthenticated", "and project is private" do + it_behaves_like "404 response" do + let(:request) { post api(route), params: {branch: branch} } + let(:message) { "404 Project Not Found" } end end - context 'when authenticated', 'as an owner' do + context "when authenticated", "as an owner" do let(:current_user) { user } - it_behaves_like 'ref revert' + it_behaves_like "ref revert" - context 'when ref does not exist' do - let(:commit_id) { 'unknown' } + context "when ref does not exist" do + let(:commit_id) { "unknown" } - it_behaves_like '404 response' do - let(:request) { post api(route, current_user), params: { branch: branch } } - let(:message) { '404 Commit Not Found' } + it_behaves_like "404 response" do + let(:request) { post api(route, current_user), params: {branch: branch} } + let(:message) { "404 Commit Not Found" } end end - context 'when branch is missing' do - it_behaves_like '400 response' do + context "when branch is missing" do + it_behaves_like "400 response" do let(:request) { post api(route, current_user) } end end - context 'when branch is empty' do - ['', ' '].each do |branch| - it_behaves_like '400 response' do - let(:request) { post api(route, current_user), params: { branch: branch } } + context "when branch is empty" do + ["", " "].each do |branch| + it_behaves_like "400 response" do + let(:request) { post api(route, current_user), params: {branch: branch} } end end end - context 'when branch does not exist' do - it_behaves_like '404 response' do - let(:request) { post api(route, current_user), params: { branch: 'foo' } } - let(:message) { '404 Branch Not Found' } + context "when branch does not exist" do + it_behaves_like "404 response" do + let(:request) { post api(route, current_user), params: {branch: "foo"} } + let(:message) { "404 Branch Not Found" } end end - context 'when ref contains a dot' do + context "when ref contains a dot" do let(:commit_id) { branch_with_dot.name } let(:commit) { project.repository.commit(commit_id) } - it_behaves_like '400 response' do + it_behaves_like "400 response" do let(:request) { post api(route, current_user) } end end end - context 'when authenticated', 'as a developer' do + context "when authenticated", "as a developer" do let(:current_user) { user } before do project.add_developer(user) end - context 'when branch is protected' do + context "when branch is protected" do before do - create(:protected_branch, project: project, name: 'feature') + create(:protected_branch, project: project, name: "feature") end - it 'returns 400 if you are not allowed to push to the target branch' do - post api(route, current_user), params: { branch: 'feature' } + it "returns 400 if you are not allowed to push to the target branch" do + post api(route, current_user), params: {branch: "feature"} expect(response).to have_gitlab_http_status(:forbidden) - expect(json_response['message']).to match(/You are not allowed to push into this branch/) + expect(json_response["message"]).to match(/You are not allowed to push into this branch/) end end end end - describe 'POST /projects/:id/repository/commits/:sha/comments' do + describe "POST /projects/:id/repository/commits/:sha/comments" do let(:commit) { project.repository.commit } let(:commit_id) { commit.id } - let(:note) { 'My comment' } + let(:note) { "My comment" } let(:route) { "/projects/#{project_id}/repository/commits/#{commit_id}/comments" } - shared_examples_for 'ref new comment' do - context 'when ref exists' do - it 'creates the comment' do - post api(route, current_user), params: { note: note } + shared_examples_for "ref new comment" do + context "when ref exists" do + it "creates the comment" do + post api(route, current_user), params: {note: note} expect(response).to have_gitlab_http_status(201) - expect(response).to match_response_schema('public_api/v4/commit_note') - expect(json_response['note']).to eq('My comment') - expect(json_response['path']).to be_nil - expect(json_response['line']).to be_nil - expect(json_response['line_type']).to be_nil + expect(response).to match_response_schema("public_api/v4/commit_note") + expect(json_response["note"]).to eq("My comment") + expect(json_response["path"]).to be_nil + expect(json_response["line"]).to be_nil + expect(json_response["line_type"]).to be_nil end end - context 'when repository is disabled' do - include_context 'disabled repository' + context "when repository is disabled" do + include_context "disabled repository" - it_behaves_like '403 response' do - let(:request) { post api(route, current_user), params: { note: 'My comment' } } + it_behaves_like "403 response" do + let(:request) { post api(route, current_user), params: {note: "My comment"} } end end end - context 'when unauthenticated', 'and project is public' do + context "when unauthenticated", "and project is public" do let(:project) { create(:project, :public, :repository) } - it_behaves_like '400 response' do - let(:request) { post api(route), params: { note: 'My comment' } } + it_behaves_like "400 response" do + let(:request) { post api(route), params: {note: "My comment"} } end end - context 'when unauthenticated', 'and project is private' do - it_behaves_like '404 response' do - let(:request) { post api(route), params: { note: 'My comment' } } - let(:message) { '404 Project Not Found' } + context "when unauthenticated", "and project is private" do + it_behaves_like "404 response" do + let(:request) { post api(route), params: {note: "My comment"} } + let(:message) { "404 Project Not Found" } end end - context 'when authenticated', 'as an owner' do + context "when authenticated", "as an owner" do let(:current_user) { user } - it_behaves_like 'ref new comment' + it_behaves_like "ref new comment" - it 'returns the inline comment' do - post api(route, current_user), params: { note: 'My comment', path: project.repository.commit.raw_diffs.first.new_path, line: 1, line_type: 'new' } + it "returns the inline comment" do + post api(route, current_user), params: {note: "My comment", path: project.repository.commit.raw_diffs.first.new_path, line: 1, line_type: "new"} expect(response).to have_gitlab_http_status(201) - expect(response).to match_response_schema('public_api/v4/commit_note') - expect(json_response['note']).to eq('My comment') - expect(json_response['path']).to eq(project.repository.commit.raw_diffs.first.new_path) - expect(json_response['line']).to eq(1) - expect(json_response['line_type']).to eq('new') + expect(response).to match_response_schema("public_api/v4/commit_note") + expect(json_response["note"]).to eq("My comment") + expect(json_response["path"]).to eq(project.repository.commit.raw_diffs.first.new_path) + expect(json_response["line"]).to eq(1) + expect(json_response["line_type"]).to eq("new") end - context 'when ref does not exist' do - let(:commit_id) { 'unknown' } + context "when ref does not exist" do + let(:commit_id) { "unknown" } - it_behaves_like '404 response' do - let(:request) { post api(route, current_user), params: { note: 'My comment' } } - let(:message) { '404 Commit Not Found' } + it_behaves_like "404 response" do + let(:request) { post api(route, current_user), params: {note: "My comment"} } + let(:message) { "404 Commit Not Found" } end end - it 'returns 400 if note is missing' do + it "returns 400 if note is missing" do post api(route, current_user) expect(response).to have_gitlab_http_status(400) end - context 'when ref contains a dot' do + context "when ref contains a dot" do let(:commit_id) { branch_with_dot.name } - it_behaves_like 'ref new comment' + it_behaves_like "ref new comment" end - context 'when ref contains a slash' do + context "when ref contains a slash" do let(:commit_id) { branch_with_slash.name } - it_behaves_like '404 response' do - let(:request) { post api(route, current_user), params: { note: 'My comment' } } + it_behaves_like "404 response" do + let(:request) { post api(route, current_user), params: {note: "My comment"} } end end - context 'when ref contains an escaped slash' do + context "when ref contains an escaped slash" do let(:commit_id) { CGI.escape(branch_with_slash.name) } - it_behaves_like 'ref new comment' + it_behaves_like "ref new comment" end - context 'requesting with the escaped project full path' do + context "requesting with the escaped project full path" do let(:project_id) { CGI.escape(project.full_path) } - it_behaves_like 'ref new comment' + it_behaves_like "ref new comment" - context 'when ref contains a dot' do + context "when ref contains a dot" do let(:commit_id) { branch_with_dot.name } - it_behaves_like 'ref new comment' + it_behaves_like "ref new comment" end end end end - describe 'GET /projects/:id/repository/commits/:sha/merge_requests' do + describe "GET /projects/:id/repository/commits/:sha/merge_requests" do let!(:project) { create(:project, :repository, :private) } - let!(:merged_mr) { create(:merge_request, source_project: project, source_branch: 'master', target_branch: 'feature') } + let!(:merged_mr) { create(:merge_request, source_project: project, source_branch: "master", target_branch: "feature") } let(:commit) { merged_mr.merge_request_diff.commits.last } - it 'returns the correct merge request' do + it "returns the correct merge request" do get api("/projects/#{project.id}/repository/commits/#{commit.id}/merge_requests", user) expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response.length).to eq(1) - expect(json_response[0]['id']).to eq(merged_mr.id) + expect(json_response[0]["id"]).to eq(merged_mr.id) end - it 'returns 403 for an unauthorized user' do + it "returns 403 for an unauthorized user" do project.add_guest(user) get api("/projects/#{project.id}/repository/commits/#{commit.id}/merge_requests", user) @@ -1451,47 +1451,47 @@ describe API::Commits do expect(response).to have_gitlab_http_status(403) end - it 'responds 404 when the commit does not exist' do + it "responds 404 when the commit does not exist" do get api("/projects/#{project.id}/repository/commits/a7d26f00c35b/merge_requests", user) expect(response).to have_gitlab_http_status(404) end end - describe 'GET /projects/:id/repository/commits/:sha/signature' do + describe "GET /projects/:id/repository/commits/:sha/signature" do let!(:project) { create(:project, :repository, :public) } let(:project_id) { project.id } let(:commit_id) { project.repository.commit.id } let(:route) { "/projects/#{project_id}/repository/commits/#{commit_id}/signature" } - context 'when commit does not exist' do - let(:commit_id) { 'unknown' } + context "when commit does not exist" do + let(:commit_id) { "unknown" } - it_behaves_like '404 response' do + it_behaves_like "404 response" do let(:request) { get api(route, current_user) } - let(:message) { '404 Commit Not Found' } + let(:message) { "404 Commit Not Found" } end end - context 'unsigned commit' do - it_behaves_like '404 response' do + context "unsigned commit" do + it_behaves_like "404 response" do let(:request) { get api(route, current_user) } - let(:message) { '404 GPG Signature Not Found'} + let(:message) { "404 GPG Signature Not Found"} end end - context 'signed commit' do + context "signed commit" do let(:commit) { project.repository.commit(GpgHelpers::SIGNED_COMMIT_SHA) } let(:commit_id) { commit.id } - it 'returns correct JSON' do + it "returns correct JSON" do get api(route, current_user) expect(response).to have_gitlab_http_status(200) - expect(json_response['gpg_key_id']).to eq(commit.signature.gpg_key_id) - expect(json_response['gpg_key_subkey_id']).to eq(commit.signature.gpg_key_subkey_id) - expect(json_response['gpg_key_primary_keyid']).to eq(commit.signature.gpg_key_primary_keyid) - expect(json_response['verification_status']).to eq(commit.signature.verification_status) + expect(json_response["gpg_key_id"]).to eq(commit.signature.gpg_key_id) + expect(json_response["gpg_key_subkey_id"]).to eq(commit.signature.gpg_key_subkey_id) + expect(json_response["gpg_key_primary_keyid"]).to eq(commit.signature.gpg_key_primary_keyid) + expect(json_response["verification_status"]).to eq(commit.signature.verification_status) end end end diff --git a/spec/requests/api/container_registry_spec.rb b/spec/requests/api/container_registry_spec.rb index ea035a8be4a..f9f992b8438 100644 --- a/spec/requests/api/container_registry_spec.rb +++ b/spec/requests/api/container_registry_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe API::ContainerRegistry do set(:project) { create(:project, :private) } @@ -25,11 +25,11 @@ describe API::ContainerRegistry do test_repository end - shared_examples 'being disallowed' do |param| + shared_examples "being disallowed" do |param| context "for #{param}" do let(:api_user) { public_send(param) } - it 'returns access denied' do + it "returns access denied" do subject expect(response).to have_gitlab_http_status(:forbidden) @@ -39,7 +39,7 @@ describe API::ContainerRegistry do context "for anonymous" do let(:api_user) { nil } - it 'returns not found' do + it "returns not found" do subject expect(response).to have_gitlab_http_status(:not_found) @@ -47,40 +47,41 @@ describe API::ContainerRegistry do end end - describe 'GET /projects/:id/registry/repositories' do + describe "GET /projects/:id/registry/repositories" do subject { get api("/projects/#{project.id}/registry/repositories", api_user) } - it_behaves_like 'being disallowed', :guest + it_behaves_like "being disallowed", :guest - context 'for reporter' do + context "for reporter" do let(:api_user) { reporter } - it 'returns a list of repositories' do + it "returns a list of repositories" do subject expect(json_response.length).to eq(2) - expect(json_response.map { |repository| repository['id'] }).to contain_exactly( - root_repository.id, test_repository.id) + expect(json_response.map { |repository| repository["id"] }).to contain_exactly( + root_repository.id, test_repository.id + ) end - it 'returns a matching schema' do + it "returns a matching schema" do subject expect(response).to have_gitlab_http_status(:ok) - expect(response).to match_response_schema('registry/repositories') + expect(response).to match_response_schema("registry/repositories") end end end - describe 'DELETE /projects/:id/registry/repositories/:repository_id' do + describe "DELETE /projects/:id/registry/repositories/:repository_id" do subject { delete api("/projects/#{project.id}/registry/repositories/#{root_repository.id}", api_user) } - it_behaves_like 'being disallowed', :developer + it_behaves_like "being disallowed", :developer - context 'for maintainer' do + context "for maintainer" do let(:api_user) { maintainer } - it 'schedules removal of repository' do + it "schedules removal of repository" do expect(DeleteContainerRepositoryWorker).to receive(:perform_async) .with(maintainer.id, root_repository.id) @@ -91,71 +92,71 @@ describe API::ContainerRegistry do end end - describe 'GET /projects/:id/registry/repositories/:repository_id/tags' do + describe "GET /projects/:id/registry/repositories/:repository_id/tags" do subject { get api("/projects/#{project.id}/registry/repositories/#{root_repository.id}/tags", api_user) } - it_behaves_like 'being disallowed', :guest + it_behaves_like "being disallowed", :guest - context 'for reporter' do + context "for reporter" do let(:api_user) { reporter } before do - stub_container_registry_tags(repository: root_repository.path, tags: %w(rootA latest)) + stub_container_registry_tags(repository: root_repository.path, tags: %w[rootA latest]) end - it 'returns a list of tags' do + it "returns a list of tags" do subject expect(json_response.length).to eq(2) - expect(json_response.map { |repository| repository['name'] }).to eq %w(latest rootA) + expect(json_response.map { |repository| repository["name"] }).to eq %w[latest rootA] end - it 'returns a matching schema' do + it "returns a matching schema" do subject expect(response).to have_gitlab_http_status(:ok) - expect(response).to match_response_schema('registry/tags') + expect(response).to match_response_schema("registry/tags") end end end - describe 'DELETE /projects/:id/registry/repositories/:repository_id/tags' do + describe "DELETE /projects/:id/registry/repositories/:repository_id/tags" do subject { delete api("/projects/#{project.id}/registry/repositories/#{root_repository.id}/tags", api_user), params: params } - it_behaves_like 'being disallowed', :developer do + it_behaves_like "being disallowed", :developer do let(:params) do - { name_regex: 'v10.*' } + {name_regex: "v10.*"} end end - context 'for maintainer' do + context "for maintainer" do let(:api_user) { maintainer } - context 'without required parameters' do + context "without required parameters" do let(:params) { } - it 'returns bad request' do + it "returns bad request" do subject expect(response).to have_gitlab_http_status(:bad_request) end end - context 'passes all declared parameters' do + context "passes all declared parameters" do let(:params) do - { name_regex: 'v10.*', - keep_n: 100, - older_than: '1 day', - other: 'some value' } + {name_regex: "v10.*", + keep_n: 100, + older_than: "1 day", + other: "some value",} end let(:worker_params) do - { name_regex: 'v10.*', - keep_n: 100, - older_than: '1 day' } + {name_regex: "v10.*", + keep_n: 100, + older_than: "1 day",} end - it 'schedules cleanup of tags repository' do + it "schedules cleanup of tags repository" do expect(CleanupContainerRepositoryWorker).to receive(:perform_async) .with(maintainer.id, root_repository.id, worker_params) @@ -167,53 +168,54 @@ describe API::ContainerRegistry do end end - describe 'GET /projects/:id/registry/repositories/:repository_id/tags/:tag_name' do + describe "GET /projects/:id/registry/repositories/:repository_id/tags/:tag_name" do subject { get api("/projects/#{project.id}/registry/repositories/#{root_repository.id}/tags/rootA", api_user) } - it_behaves_like 'being disallowed', :guest + it_behaves_like "being disallowed", :guest - context 'for reporter' do + context "for reporter" do let(:api_user) { reporter } before do - stub_container_registry_tags(repository: root_repository.path, tags: %w(rootA), with_manifest: true) + stub_container_registry_tags(repository: root_repository.path, tags: %w[rootA], with_manifest: true) end - it 'returns a details of tag' do + it "returns a details of tag" do subject expect(json_response).to include( - 'name' => 'rootA', - 'digest' => 'sha256:4c8e63ca4cb663ce6c688cb06f1c372b088dac5b6d7ad7d49cd620d85cf72a15', - 'revision' => 'd7a513a663c1a6dcdba9ed832ca53c02ac2af0c333322cd6ca92936d1d9917ac', - 'total_size' => 2319870) + "name" => "rootA", + "digest" => "sha256:4c8e63ca4cb663ce6c688cb06f1c372b088dac5b6d7ad7d49cd620d85cf72a15", + "revision" => "d7a513a663c1a6dcdba9ed832ca53c02ac2af0c333322cd6ca92936d1d9917ac", + "total_size" => 2319870 + ) end - it 'returns a matching schema' do + it "returns a matching schema" do subject expect(response).to have_gitlab_http_status(:ok) - expect(response).to match_response_schema('registry/tag') + expect(response).to match_response_schema("registry/tag") end end end - describe 'DELETE /projects/:id/registry/repositories/:repository_id/tags/:tag_name' do + describe "DELETE /projects/:id/registry/repositories/:repository_id/tags/:tag_name" do subject { delete api("/projects/#{project.id}/registry/repositories/#{root_repository.id}/tags/rootA", api_user) } - it_behaves_like 'being disallowed', :developer + it_behaves_like "being disallowed", :developer - context 'for maintainer' do + context "for maintainer" do let(:api_user) { maintainer } before do - stub_container_registry_tags(repository: root_repository.path, tags: %w(rootA), with_manifest: true) + stub_container_registry_tags(repository: root_repository.path, tags: %w[rootA], with_manifest: true) end - it 'properly removes tag' do + it "properly removes tag" do expect_any_instance_of(ContainerRegistry::Client) .to receive(:delete_repository_tag).with(root_repository.path, - 'sha256:4c8e63ca4cb663ce6c688cb06f1c372b088dac5b6d7ad7d49cd620d85cf72a15') + "sha256:4c8e63ca4cb663ce6c688cb06f1c372b088dac5b6d7ad7d49cd620d85cf72a15") subject diff --git a/spec/requests/api/deploy_keys_spec.rb b/spec/requests/api/deploy_keys_spec.rb index b93ee148736..2977f33e08a 100644 --- a/spec/requests/api/deploy_keys_spec.rb +++ b/spec/requests/api/deploy_keys_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe API::DeployKeys do let(:user) { create(:user) } @@ -11,239 +11,239 @@ describe API::DeployKeys do create(:deploy_keys_project, project: project, deploy_key: deploy_key) end - describe 'GET /deploy_keys' do - context 'when unauthenticated' do - it 'returns authentication error' do - get api('/deploy_keys') + describe "GET /deploy_keys" do + context "when unauthenticated" do + it "returns authentication error" do + get api("/deploy_keys") expect(response.status).to eq(401) end end - context 'when authenticated as non-admin user' do - it 'returns a 403 error' do - get api('/deploy_keys', user) + context "when authenticated as non-admin user" do + it "returns a 403 error" do + get api("/deploy_keys", user) expect(response.status).to eq(403) end end - context 'when authenticated as admin' do - it 'returns all deploy keys' do - get api('/deploy_keys', admin) + context "when authenticated as admin" do + it "returns all deploy keys" do + get api("/deploy_keys", admin) expect(response.status).to eq(200) expect(response).to include_pagination_headers expect(json_response).to be_an Array - expect(json_response.first['id']).to eq(deploy_keys_project.deploy_key.id) + expect(json_response.first["id"]).to eq(deploy_keys_project.deploy_key.id) end end end - describe 'GET /projects/:id/deploy_keys' do + describe "GET /projects/:id/deploy_keys" do before do deploy_key end - it 'returns array of ssh keys' do + it "returns array of ssh keys" do get api("/projects/#{project.id}/deploy_keys", admin) expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers 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 - describe 'GET /projects/:id/deploy_keys/:key_id' do - it 'returns a single key' do + describe "GET /projects/:id/deploy_keys/:key_id" do + it "returns a single key" do get api("/projects/#{project.id}/deploy_keys/#{deploy_key.id}", admin) expect(response).to have_gitlab_http_status(200) - expect(json_response['title']).to eq(deploy_key.title) + expect(json_response["title"]).to eq(deploy_key.title) end - it 'returns 404 Not Found with invalid ID' do + it "returns 404 Not Found with invalid ID" do get api("/projects/#{project.id}/deploy_keys/404", admin) expect(response).to have_gitlab_http_status(404) end end - describe 'POST /projects/:id/deploy_keys' do - it 'does not create an invalid ssh key' do - post api("/projects/#{project.id}/deploy_keys", admin), params: { title: 'invalid key' } + describe "POST /projects/:id/deploy_keys" do + it "does not create an invalid ssh key" do + post api("/projects/#{project.id}/deploy_keys", admin), params: {title: "invalid key"} expect(response).to have_gitlab_http_status(400) - expect(json_response['error']).to eq('key is missing') + expect(json_response["error"]).to eq("key is missing") end - it 'does not create a key without title' do - post api("/projects/#{project.id}/deploy_keys", admin), params: { key: 'some key' } + it "does not create a key without title" do + post api("/projects/#{project.id}/deploy_keys", admin), params: {key: "some key"} expect(response).to have_gitlab_http_status(400) - expect(json_response['error']).to eq('title is missing') + expect(json_response["error"]).to eq("title is missing") end - it 'creates new ssh key' do + it "creates new ssh key" do key_attrs = attributes_for :another_key - expect do + expect { post api("/projects/#{project.id}/deploy_keys", admin), params: key_attrs - end.to change { project.deploy_keys.count }.by(1) + }.to change { project.deploy_keys.count }.by(1) new_key = project.deploy_keys.last expect(new_key.key).to eq(key_attrs[:key]) expect(new_key.user).to eq(admin) end - it 'returns an existing ssh key when attempting to add a duplicate' do - expect do - post api("/projects/#{project.id}/deploy_keys", admin), params: { key: deploy_key.key, title: deploy_key.title } - end.not_to change { project.deploy_keys.count } + it "returns an existing ssh key when attempting to add a duplicate" do + expect { + post api("/projects/#{project.id}/deploy_keys", admin), params: {key: deploy_key.key, title: deploy_key.title} + }.not_to change { project.deploy_keys.count } expect(response).to have_gitlab_http_status(201) end - it 'joins an existing ssh key to a new project' do - expect do - post api("/projects/#{project2.id}/deploy_keys", admin), params: { key: deploy_key.key, title: deploy_key.title } - end.to change { project2.deploy_keys.count }.by(1) + it "joins an existing ssh key to a new project" do + expect { + post api("/projects/#{project2.id}/deploy_keys", admin), params: {key: deploy_key.key, title: deploy_key.title} + }.to change { project2.deploy_keys.count }.by(1) expect(response).to have_gitlab_http_status(201) end - it 'accepts can_push parameter' do + it "accepts can_push parameter" do key_attrs = attributes_for(:another_key).merge(can_push: true) post api("/projects/#{project.id}/deploy_keys", admin), params: key_attrs expect(response).to have_gitlab_http_status(201) - expect(json_response['can_push']).to eq(true) + expect(json_response["can_push"]).to eq(true) end end - describe 'PUT /projects/:id/deploy_keys/:key_id' do + describe "PUT /projects/:id/deploy_keys/:key_id" do let(:private_deploy_key) { create(:another_deploy_key, public: false) } let(:project_private_deploy_key) do create(:deploy_keys_project, project: project, deploy_key: private_deploy_key) end - it 'updates a public deploy key as admin' do - expect do - put api("/projects/#{project.id}/deploy_keys/#{deploy_key.id}", admin), params: { title: 'new title' } - end.not_to change(deploy_key, :title) + it "updates a public deploy key as admin" do + expect { + put api("/projects/#{project.id}/deploy_keys/#{deploy_key.id}", admin), params: {title: "new title"} + }.not_to change(deploy_key, :title) expect(response).to have_gitlab_http_status(200) end - it 'does not update a public deploy key as non admin' do - expect do - put api("/projects/#{project.id}/deploy_keys/#{deploy_key.id}", user), params: { title: 'new title' } - end.not_to change(deploy_key, :title) + it "does not update a public deploy key as non admin" do + expect { + put api("/projects/#{project.id}/deploy_keys/#{deploy_key.id}", user), params: {title: "new title"} + }.not_to change(deploy_key, :title) expect(response).to have_gitlab_http_status(404) end - it 'does not update a private key with invalid title' do + it "does not update a private key with invalid title" do project_private_deploy_key - expect do - put api("/projects/#{project.id}/deploy_keys/#{private_deploy_key.id}", admin), params: { title: '' } - end.not_to change(deploy_key, :title) + expect { + put api("/projects/#{project.id}/deploy_keys/#{private_deploy_key.id}", admin), params: {title: ""} + }.not_to change(deploy_key, :title) expect(response).to have_gitlab_http_status(400) end - it 'updates a private ssh key with correct attributes' do + it "updates a private ssh key with correct attributes" do project_private_deploy_key - put api("/projects/#{project.id}/deploy_keys/#{private_deploy_key.id}", admin), params: { title: 'new title', can_push: true } + put api("/projects/#{project.id}/deploy_keys/#{private_deploy_key.id}", admin), params: {title: "new title", can_push: true} - expect(json_response['id']).to eq(private_deploy_key.id) - expect(json_response['title']).to eq('new title') - expect(json_response['can_push']).to eq(true) + expect(json_response["id"]).to eq(private_deploy_key.id) + expect(json_response["title"]).to eq("new title") + expect(json_response["can_push"]).to eq(true) end end - describe 'DELETE /projects/:id/deploy_keys/:key_id' do + describe "DELETE /projects/:id/deploy_keys/:key_id" do before do deploy_key end - it 'removes existing key from project' do - expect do + it "removes existing key from project" do + expect { delete api("/projects/#{project.id}/deploy_keys/#{deploy_key.id}", admin) expect(response).to have_gitlab_http_status(204) - end.to change { project.deploy_keys.count }.by(-1) + }.to change { project.deploy_keys.count }.by(-1) end - context 'when the deploy key is public' do - it 'does not delete the deploy key' do - expect do + context "when the deploy key is public" do + it "does not delete the deploy key" do + expect { delete api("/projects/#{project.id}/deploy_keys/#{deploy_key.id}", admin) expect(response).to have_gitlab_http_status(204) - end.not_to change { DeployKey.count } + }.not_to change { DeployKey.count } end end - context 'when the deploy key is not public' do + context "when the deploy key is not public" do let!(:deploy_key) { create(:deploy_key, public: false) } - context 'when the deploy key is only used by this project' do - it 'deletes the deploy key' do - expect do + context "when the deploy key is only used by this project" do + it "deletes the deploy key" do + expect { delete api("/projects/#{project.id}/deploy_keys/#{deploy_key.id}", admin) expect(response).to have_gitlab_http_status(204) - end.to change { DeployKey.count }.by(-1) + }.to change { DeployKey.count }.by(-1) end end - context 'when the deploy key is used by other projects' do + context "when the deploy key is used by other projects" do before do create(:deploy_keys_project, project: project2, deploy_key: deploy_key) end - it 'does not delete the deploy key' do - expect do + it "does not delete the deploy key" do + expect { delete api("/projects/#{project.id}/deploy_keys/#{deploy_key.id}", admin) expect(response).to have_gitlab_http_status(204) - end.not_to change { DeployKey.count } + }.not_to change { DeployKey.count } end end end - it 'returns 404 Not Found with invalid ID' do + it "returns 404 Not Found with invalid ID" do delete api("/projects/#{project.id}/deploy_keys/404", admin) expect(response).to have_gitlab_http_status(404) end - it_behaves_like '412 response' do + it_behaves_like "412 response" do let(:request) { api("/projects/#{project.id}/deploy_keys/#{deploy_key.id}", admin) } end end - describe 'POST /projects/:id/deploy_keys/:key_id/enable' do + describe "POST /projects/:id/deploy_keys/:key_id/enable" do let(:project2) { create(:project) } - context 'when the user can admin the project' do - it 'enables the key' do - expect do + context "when the user can admin the project" do + it "enables the key" do + expect { post api("/projects/#{project2.id}/deploy_keys/#{deploy_key.id}/enable", admin) - end.to change { project2.deploy_keys.count }.from(0).to(1) + }.to change { project2.deploy_keys.count }.from(0).to(1) expect(response).to have_gitlab_http_status(201) - expect(json_response['id']).to eq(deploy_key.id) + expect(json_response["id"]).to eq(deploy_key.id) end end - context 'when authenticated as non-admin user' do - it 'returns a 404 error' do + context "when authenticated as non-admin user" do + it "returns a 404 error" do post api("/projects/#{project2.id}/deploy_keys/#{deploy_key.id}/enable", user) expect(response).to have_gitlab_http_status(404) diff --git a/spec/requests/api/deployments_spec.rb b/spec/requests/api/deployments_spec.rb index 3dac7225b7a..d774e008292 100644 --- a/spec/requests/api/deployments_spec.rb +++ b/spec/requests/api/deployments_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe API::Deployments do let(:user) { create(:user) } @@ -8,27 +8,27 @@ describe API::Deployments do project.add_maintainer(user) end - describe 'GET /projects/:id/deployments' do + describe "GET /projects/:id/deployments" do let(:project) { create(:project) } - let!(:deployment_1) { create(:deployment, :success, project: project, iid: 11, ref: 'master', created_at: Time.now) } - let!(:deployment_2) { create(:deployment, :success, project: project, iid: 12, ref: 'feature', created_at: 1.day.ago) } - let!(:deployment_3) { create(:deployment, :success, project: project, iid: 8, ref: 'patch', created_at: 2.days.ago) } + let!(:deployment_1) { create(:deployment, :success, project: project, iid: 11, ref: "master", created_at: Time.now) } + let!(:deployment_2) { create(:deployment, :success, project: project, iid: 12, ref: "feature", created_at: 1.day.ago) } + let!(:deployment_3) { create(:deployment, :success, project: project, iid: 8, ref: "patch", created_at: 2.days.ago) } - context 'as member of the project' do - it 'returns projects deployments sorted by id asc' do + context "as member of the project" do + it "returns projects deployments sorted by id asc" do get api("/projects/#{project.id}/deployments", user) expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response).to be_an Array expect(json_response.size).to eq(3) - expect(json_response.first['iid']).to eq(deployment_1.iid) - expect(json_response.first['sha']).to match /\A\h{40}\z/ - expect(json_response.second['iid']).to eq(deployment_2.iid) - expect(json_response.last['iid']).to eq(deployment_3.iid) + expect(json_response.first["iid"]).to eq(deployment_1.iid) + expect(json_response.first["sha"]).to match /\A\h{40}\z/ + expect(json_response.second["iid"]).to eq(deployment_2.iid) + expect(json_response.last["iid"]).to eq(deployment_3.iid) end - describe 'ordering' do + describe "ordering" do using RSpec::Parameterized::TableSyntax let(:order_by) { nil } @@ -38,7 +38,7 @@ describe API::Deployments do def expect_deployments(ordered_deployments) json_response.each_with_index do |deployment_json, index| - expect(deployment_json['id']).to eq(public_send(ordered_deployments[index]).id) + expect(deployment_json["id"]).to eq(public_send(ordered_deployments[index]).id) end end @@ -47,26 +47,26 @@ describe API::Deployments do end where(:order_by, :sort, :ordered_deployments) do - 'created_at' | 'asc' | [:deployment_3, :deployment_2, :deployment_1] - 'created_at' | 'desc' | [:deployment_1, :deployment_2, :deployment_3] - 'id' | 'asc' | [:deployment_1, :deployment_2, :deployment_3] - 'id' | 'desc' | [:deployment_3, :deployment_2, :deployment_1] - 'iid' | 'asc' | [:deployment_3, :deployment_1, :deployment_2] - 'iid' | 'desc' | [:deployment_2, :deployment_1, :deployment_3] - 'ref' | 'asc' | [:deployment_2, :deployment_1, :deployment_3] - 'ref' | 'desc' | [:deployment_3, :deployment_1, :deployment_2] + "created_at" | "asc" | [:deployment_3, :deployment_2, :deployment_1] + "created_at" | "desc" | [:deployment_1, :deployment_2, :deployment_3] + "id" | "asc" | [:deployment_1, :deployment_2, :deployment_3] + "id" | "desc" | [:deployment_3, :deployment_2, :deployment_1] + "iid" | "asc" | [:deployment_3, :deployment_1, :deployment_2] + "iid" | "desc" | [:deployment_2, :deployment_1, :deployment_3] + "ref" | "asc" | [:deployment_2, :deployment_1, :deployment_3] + "ref" | "desc" | [:deployment_3, :deployment_1, :deployment_2] end with_them do - it 'returns the deployments ordered' do + it "returns the deployments ordered" do expect_deployments(ordered_deployments) end end end end - context 'as non member' do - it 'returns a 404 status code' do + context "as non member" do + it "returns a 404 status code" do get api("/projects/#{project.id}/deployments", non_member) expect(response).to have_gitlab_http_status(404) @@ -74,22 +74,22 @@ describe API::Deployments do end end - describe 'GET /projects/:id/deployments/:deployment_id' do + describe "GET /projects/:id/deployments/:deployment_id" do let(:project) { deployment.environment.project } let!(:deployment) { create(:deployment, :success) } - context 'as a member of the project' do - it 'returns the projects deployment' do + context "as a member of the project" do + it "returns the projects deployment" do get api("/projects/#{project.id}/deployments/#{deployment.id}", user) expect(response).to have_gitlab_http_status(200) - expect(json_response['sha']).to match /\A\h{40}\z/ - expect(json_response['id']).to eq(deployment.id) + expect(json_response["sha"]).to match /\A\h{40}\z/ + expect(json_response["id"]).to eq(deployment.id) end end - context 'as non member' do - it 'returns a 404 status code' do + context "as non member" do + it "returns a 404 status code" do get api("/projects/#{project.id}/deployments/#{deployment.id}", non_member) expect(response).to have_gitlab_http_status(404) diff --git a/spec/requests/api/discussions_spec.rb b/spec/requests/api/discussions_spec.rb index 35c448d187d..2d853e841d0 100644 --- a/spec/requests/api/discussions_spec.rb +++ b/spec/requests/api/discussions_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe API::Discussions do let(:user) { create(:user) } @@ -9,46 +9,46 @@ describe API::Discussions do project.add_developer(user) end - context 'when noteable is an Issue' do + context "when noteable is an Issue" do let!(:issue) { create(:issue, project: project, author: user) } let!(:issue_note) { create(:discussion_note_on_issue, noteable: issue, project: project, author: user) } - it_behaves_like 'discussions API', 'projects', 'issues', 'iid' do + it_behaves_like "discussions API", "projects", "issues", "iid" do let(:parent) { project } let(:noteable) { issue } let(:note) { issue_note } end end - context 'when noteable is a Snippet' do + context "when noteable is a Snippet" do let!(:snippet) { create(:project_snippet, project: project, author: user) } let!(:snippet_note) { create(:discussion_note_on_snippet, noteable: snippet, project: project, author: user) } - it_behaves_like 'discussions API', 'projects', 'snippets', 'id' do + it_behaves_like "discussions API", "projects", "snippets", "id" do let(:parent) { project } let(:noteable) { snippet } let(:note) { snippet_note } end end - context 'when noteable is a Merge Request' do + context "when noteable is a Merge Request" do let!(:noteable) { create(:merge_request_with_diffs, source_project: project, target_project: project, author: user) } let!(:note) { create(:discussion_note_on_merge_request, noteable: noteable, project: project, author: user) } let!(:diff_note) { create(:diff_note_on_merge_request, noteable: noteable, project: project, author: user) } let(:parent) { project } - it_behaves_like 'discussions API', 'projects', 'merge_requests', 'iid' - it_behaves_like 'diff discussions API', 'projects', 'merge_requests', 'iid' - it_behaves_like 'resolvable discussions API', 'projects', 'merge_requests', 'iid' + it_behaves_like "discussions API", "projects", "merge_requests", "iid" + it_behaves_like "diff discussions API", "projects", "merge_requests", "iid" + it_behaves_like "resolvable discussions API", "projects", "merge_requests", "iid" end - context 'when noteable is a Commit' do + context "when noteable is a Commit" do let!(:noteable) { create(:commit, project: project, author: user) } let!(:note) { create(:discussion_note_on_commit, commit_id: noteable.id, project: project, author: user) } let!(:diff_note) { create(:diff_note_on_commit, commit_id: noteable.id, project: project, author: user) } let(:parent) { project } - it_behaves_like 'discussions API', 'projects', 'repository/commits', 'id' - it_behaves_like 'diff discussions API', 'projects', 'repository/commits', 'id' + it_behaves_like "discussions API", "projects", "repository/commits", "id" + it_behaves_like "diff discussions API", "projects", "repository/commits", "id" end end diff --git a/spec/requests/api/doorkeeper_access_spec.rb b/spec/requests/api/doorkeeper_access_spec.rb index d74484c8d29..52ec87d15bf 100644 --- a/spec/requests/api/doorkeeper_access_spec.rb +++ b/spec/requests/api/doorkeeper_access_spec.rb @@ -1,26 +1,26 @@ -require 'spec_helper' +require "spec_helper" -describe 'doorkeeper access' do +describe "doorkeeper access" do let!(:user) { create(:user) } let!(:application) { Doorkeeper::Application.create!(name: "MyApp", redirect_uri: "https://app.com", owner: user) } let!(:token) { Doorkeeper::AccessToken.create! application_id: application.id, resource_owner_id: user.id, scopes: "api" } describe "unauthenticated" do it "returns authentication success" do - get api("/user"), params: { access_token: token.token } + get api("/user"), params: {access_token: token.token} expect(response).to have_gitlab_http_status(200) end - include_examples 'user login request with unique ip limit' do + include_examples "user login request with unique ip limit" do def request - get api('/user'), params: { access_token: token.token } + get api("/user"), params: {access_token: token.token} end end end describe "when token invalid" do it "returns authentication error" do - get api("/user"), params: { access_token: "123a" } + get api("/user"), params: {access_token: "123a"} expect(response).to have_gitlab_http_status(401) end end @@ -31,9 +31,9 @@ describe 'doorkeeper access' do expect(response).to have_gitlab_http_status(200) end - include_examples 'user login request with unique ip limit' do + include_examples "user login request with unique ip limit" do def request - get api('/user', user) + get api("/user", user) end end end @@ -41,7 +41,7 @@ describe 'doorkeeper access' do describe "when user is blocked" do it "returns authorization error" do user.block - get api("/user"), params: { access_token: token.token } + get api("/user"), params: {access_token: token.token} expect(response).to have_gitlab_http_status(403) end @@ -50,7 +50,7 @@ describe 'doorkeeper access' do describe "when user is ldap_blocked" do it "returns authorization error" do user.ldap_block - get api("/user"), params: { access_token: token.token } + get api("/user"), params: {access_token: token.token} expect(response).to have_gitlab_http_status(403) end diff --git a/spec/requests/api/environments_spec.rb b/spec/requests/api/environments_spec.rb index 493d3642255..711f8b97304 100644 --- a/spec/requests/api/environments_spec.rb +++ b/spec/requests/api/environments_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe API::Environments do let(:user) { create(:user) } @@ -10,10 +10,10 @@ describe API::Environments do project.add_maintainer(user) end - describe 'GET /projects/:id/environments' do - context 'as member of the project' do - it 'returns project environments' do - project_data_keys = %w( + describe "GET /projects/:id/environments" do + context "as member of the project" do + it "returns project environments" do + project_data_keys = %w[ id description default_branch tag_list ssh_url_to_repo http_url_to_repo web_url readme_url name name_with_namespace @@ -21,7 +21,7 @@ describe API::Environments do star_count forks_count created_at last_activity_at avatar_url namespace - ) + ] get api("/projects/#{project.id}/environments", user) @@ -29,14 +29,14 @@ describe API::Environments do expect(response).to include_pagination_headers expect(json_response).to be_an Array expect(json_response.size).to eq(1) - expect(json_response.first['name']).to eq(environment.name) - expect(json_response.first['external_url']).to eq(environment.external_url) - expect(json_response.first['project'].keys).to contain_exactly(*project_data_keys) + expect(json_response.first["name"]).to eq(environment.name) + expect(json_response.first["external_url"]).to eq(environment.external_url) + expect(json_response.first["project"].keys).to contain_exactly(*project_data_keys) end end - context 'as non member' do - it 'returns a 404 status code' do + context "as non member" do + it "returns a 404 status code" do get api("/projects/#{project.id}/environments", non_member) expect(response).to have_gitlab_http_status(404) @@ -44,65 +44,65 @@ describe API::Environments do end end - describe 'POST /projects/:id/environments' do - context 'as a member' do - it 'creates a environment with valid params' do - post api("/projects/#{project.id}/environments", user), params: { name: "mepmep" } + describe "POST /projects/:id/environments" do + context "as a member" do + it "creates a environment with valid params" do + post api("/projects/#{project.id}/environments", user), params: {name: "mepmep"} expect(response).to have_gitlab_http_status(201) - expect(json_response['name']).to eq('mepmep') - expect(json_response['slug']).to eq('mepmep') - expect(json_response['external']).to be nil + expect(json_response["name"]).to eq("mepmep") + expect(json_response["slug"]).to eq("mepmep") + expect(json_response["external"]).to be nil end - it 'requires name to be passed' do - post api("/projects/#{project.id}/environments", user), params: { external_url: 'test.gitlab.com' } + it "requires name to be passed" do + post api("/projects/#{project.id}/environments", user), params: {external_url: "test.gitlab.com"} expect(response).to have_gitlab_http_status(400) end - it 'returns a 400 if environment already exists' do - post api("/projects/#{project.id}/environments", user), params: { name: environment.name } + it "returns a 400 if environment already exists" do + post api("/projects/#{project.id}/environments", user), params: {name: environment.name} expect(response).to have_gitlab_http_status(400) end - it 'returns a 400 if slug is specified' do - post api("/projects/#{project.id}/environments", user), params: { name: "foo", slug: "foo" } + it "returns a 400 if slug is specified" do + post api("/projects/#{project.id}/environments", user), params: {name: "foo", slug: "foo"} expect(response).to have_gitlab_http_status(400) expect(json_response["error"]).to eq("slug is automatically generated and cannot be changed") end end - context 'a non member' do - it 'rejects the request' do - post api("/projects/#{project.id}/environments", non_member), params: { name: 'gitlab.com' } + context "a non member" do + it "rejects the request" do + post api("/projects/#{project.id}/environments", non_member), params: {name: "gitlab.com"} expect(response).to have_gitlab_http_status(404) end - it 'returns a 400 when the required params are missing' do - post api("/projects/12345/environments", non_member), params: { external_url: 'http://env.git.com' } + it "returns a 400 when the required params are missing" do + post api("/projects/12345/environments", non_member), params: {external_url: "http://env.git.com"} end end end - describe 'PUT /projects/:id/environments/:environment_id' do - it 'returns a 200 if name and external_url are changed' do - url = 'https://mepmep.whatever.ninja' + describe "PUT /projects/:id/environments/:environment_id" do + it "returns a 200 if name and external_url are changed" do + url = "https://mepmep.whatever.ninja" put api("/projects/#{project.id}/environments/#{environment.id}", user), - params: { name: 'Mepmep', external_url: url } + params: {name: "Mepmep", external_url: url} expect(response).to have_gitlab_http_status(200) - expect(json_response['name']).to eq('Mepmep') - expect(json_response['external_url']).to eq(url) + expect(json_response["name"]).to eq("Mepmep") + expect(json_response["external_url"]).to eq(url) end it "won't allow slug to be changed" do slug = environment.slug api_url = api("/projects/#{project.id}/environments/#{environment.id}", user) - put api_url, params: { slug: slug + "-foo" } + put api_url, params: {slug: slug + "-foo"} expect(response).to have_gitlab_http_status(400) expect(json_response["error"]).to eq("slug is automatically generated and cannot be changed") @@ -111,42 +111,42 @@ describe API::Environments do it "won't update the external_url if only the name is passed" do url = environment.external_url put api("/projects/#{project.id}/environments/#{environment.id}", user), - params: { name: 'Mepmep' } + params: {name: "Mepmep"} expect(response).to have_gitlab_http_status(200) - expect(json_response['name']).to eq('Mepmep') - expect(json_response['external_url']).to eq(url) + expect(json_response["name"]).to eq("Mepmep") + expect(json_response["external_url"]).to eq(url) end - it 'returns a 404 if the environment does not exist' do + it "returns a 404 if the environment does not exist" do put api("/projects/#{project.id}/environments/12345", user) expect(response).to have_gitlab_http_status(404) end end - describe 'DELETE /projects/:id/environments/:environment_id' do - context 'as a maintainer' do - it 'returns a 200 for an existing environment' do + describe "DELETE /projects/:id/environments/:environment_id" do + context "as a maintainer" do + it "returns a 200 for an existing environment" do delete api("/projects/#{project.id}/environments/#{environment.id}", user) expect(response).to have_gitlab_http_status(204) end - it 'returns a 404 for non existing id' do + it "returns a 404 for non existing id" do delete api("/projects/#{project.id}/environments/12345", user) expect(response).to have_gitlab_http_status(404) - expect(json_response['message']).to eq('404 Not found') + expect(json_response["message"]).to eq("404 Not found") end - it_behaves_like '412 response' do + it_behaves_like "412 response" do let(:request) { api("/projects/#{project.id}/environments/#{environment.id}", user) } end end - context 'a non member' do - it 'rejects the request' do + context "a non member" do + it "rejects the request" do delete api("/projects/#{project.id}/environments/#{environment.id}", non_member) expect(response).to have_gitlab_http_status(404) @@ -154,34 +154,34 @@ describe API::Environments do end end - describe 'POST /projects/:id/environments/:environment_id/stop' do - context 'as a maintainer' do - context 'with a stoppable environment' do + describe "POST /projects/:id/environments/:environment_id/stop" do + context "as a maintainer" do + context "with a stoppable environment" do before do environment.update(state: :available) post api("/projects/#{project.id}/environments/#{environment.id}/stop", user) end - it 'returns a 200' do + it "returns a 200" do expect(response).to have_gitlab_http_status(200) end - it 'actually stops the environment' do + it "actually stops the environment" do expect(environment.reload).to be_stopped end end - it 'returns a 404 for non existing id' do + it "returns a 404 for non existing id" do post api("/projects/#{project.id}/environments/12345/stop", user) expect(response).to have_gitlab_http_status(404) - expect(json_response['message']).to eq('404 Not found') + expect(json_response["message"]).to eq("404 Not found") end end - context 'a non member' do - it 'rejects the request' do + context "a non member" do + it "rejects the request" do post api("/projects/#{project.id}/environments/#{environment.id}/stop", non_member) expect(response).to have_gitlab_http_status(404) diff --git a/spec/requests/api/events_spec.rb b/spec/requests/api/events_spec.rb index 0ac23505de7..5eefa0e1bda 100644 --- a/spec/requests/api/events_spec.rb +++ b/spec/requests/api/events_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe API::Events do include ApiHelpers @@ -9,18 +9,18 @@ describe API::Events do let(:closed_issue) { create(:closed_issue, project: private_project, author: user) } let!(:closed_issue_event) { create(:event, project: private_project, author: user, target: closed_issue, action: Event::CLOSED, created_at: Date.new(2016, 12, 30)) } - describe 'GET /events' do - context 'when unauthenticated' do - it 'returns authentication error' do - get api('/events') + describe "GET /events" do + context "when unauthenticated" do + it "returns authentication error" do + get api("/events") expect(response).to have_gitlab_http_status(401) end end - context 'when authenticated' do - it 'returns users events' do - get api('/events?action=closed&target_type=issue&after=2016-12-1&before=2016-12-31', user) + context "when authenticated" do + it "returns users events" do + get api("/events?action=closed&target_type=issue&after=2016-12-1&before=2016-12-31", user) expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers @@ -30,10 +30,10 @@ describe API::Events do end context 'when the requesting token has "read_user" scope' do - let(:token) { create(:personal_access_token, scopes: ['read_user'], user: user) } + let(:token) { create(:personal_access_token, scopes: ["read_user"], user: user) } - it 'returns users events' do - get api('/events?action=closed&target_type=issue&after=2016-12-1&before=2016-12-31', personal_access_token: token) + it "returns users events" do + get api("/events?action=closed&target_type=issue&after=2016-12-1&before=2016-12-31", personal_access_token: token) expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers @@ -43,17 +43,17 @@ describe API::Events do end context 'when the requesting token does not have "read_user" or "api" scope' do - let(:token_without_scopes) { create(:personal_access_token, scopes: ['read_repository'], user: user) } + let(:token_without_scopes) { create(:personal_access_token, scopes: ["read_repository"], user: user) } it 'returns a "403" response' do - get api('/events', personal_access_token: token_without_scopes) + get api("/events", personal_access_token: token_without_scopes) expect(response).to have_gitlab_http_status(403) end end end - describe 'GET /users/:id/events' do + describe "GET /users/:id/events" do context "as a user that cannot see another user" do it 'returns a "404" response' do allow(Ability).to receive(:allowed?).and_call_original @@ -67,7 +67,7 @@ describe API::Events do end context "as a user token that cannot see another user" do - let(:non_member_token) { create(:personal_access_token, scopes: ['read_user'], user: non_member) } + let(:non_member_token) { create(:personal_access_token, scopes: ["read_user"], user: non_member) } it 'returns a "404" response' do allow(Ability).to receive(:allowed?).and_call_original @@ -81,7 +81,7 @@ describe API::Events do end context "as a user that can see the event's project" do - it 'accepts a username' do + it "accepts a username" do get api("/users/#{user.username}/events", user) expect(response).to have_gitlab_http_status(200) @@ -90,7 +90,7 @@ describe API::Events do expect(json_response.size).to eq(1) end - it 'returns the events' do + it "returns the events" do get api("/users/#{user.id}/events", user) expect(response).to have_gitlab_http_status(200) @@ -99,35 +99,35 @@ describe API::Events do expect(json_response.size).to eq(1) end - context 'when the list of events includes push events' do + context "when the list of events includes push events" do let(:event) do create(:push_event, author: user, project: private_project) end let!(:payload) { create(:push_event_payload, event: event) } - let(:payload_hash) { json_response[0]['push_data'] } + let(:payload_hash) { json_response[0]["push_data"] } before do get api("/users/#{user.id}/events?action=pushed", user) end - it 'responds with HTTP 200 OK' do + it "responds with HTTP 200 OK" do expect(response).to have_gitlab_http_status(200) end - it 'includes the push payload as a Hash' do + it "includes the push payload as a Hash" do expect(payload_hash).to be_an_instance_of(Hash) end - it 'includes the push payload details' do - expect(payload_hash['commit_count']).to eq(payload.commit_count) - expect(payload_hash['action']).to eq(payload.action) - expect(payload_hash['ref_type']).to eq(payload.ref_type) - expect(payload_hash['commit_to']).to eq(payload.commit_to) + it "includes the push payload details" do + expect(payload_hash["commit_count"]).to eq(payload.commit_count) + expect(payload_hash["action"]).to eq(payload.action) + expect(payload_hash["ref_type"]).to eq(payload.ref_type) + expect(payload_hash["commit_to"]).to eq(payload.commit_to) end end - context 'when there are multiple events from different projects' do + context "when there are multiple events from different projects" do let(:second_note) { create(:note_on_issue, project: create(:project)) } before do @@ -138,42 +138,42 @@ describe API::Events do end end - it 'returns events in the correct order (from newest to oldest)' do + it "returns events in the correct order (from newest to oldest)" do get api("/users/#{user.id}/events", user) - comment_events = json_response.select { |e| e['action_name'] == 'commented on' } - close_events = json_response.select { |e| e['action_name'] == 'closed' } + comment_events = json_response.select { |e| e["action_name"] == "commented on" } + close_events = json_response.select { |e| e["action_name"] == "closed" } - expect(comment_events[0]['target_id']).to eq(second_note.id) - expect(close_events[0]['target_id']).to eq(closed_issue.id) + expect(comment_events[0]["target_id"]).to eq(second_note.id) + expect(close_events[0]["target_id"]).to eq(closed_issue.id) end - it 'accepts filter parameters' do + it "accepts filter parameters" do get api("/users/#{user.id}/events?action=closed&target_type=issue&after=2016-12-1&before=2016-12-31", user) expect(json_response.size).to eq(1) - expect(json_response[0]['target_id']).to eq(closed_issue.id) + expect(json_response[0]["target_id"]).to eq(closed_issue.id) end end end - it 'returns a 404 error if not found' do - get api('/users/42/events', user) + it "returns a 404 error if not found" do + get api("/users/42/events", user) expect(response).to have_gitlab_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 - describe 'GET /projects/:id/events' do - context 'when unauthenticated ' do - it 'returns 404 for private project' do + describe "GET /projects/:id/events" do + context "when unauthenticated " do + it "returns 404 for private project" do get api("/projects/#{private_project.id}/events") expect(response).to have_gitlab_http_status(404) end - it 'returns 200 status for a public project' do + it "returns 200 status for a public project" do public_project = create(:project, :public) get api("/projects/#{public_project.id}/events") @@ -182,21 +182,21 @@ describe API::Events do end end - context 'with inaccessible events' do + context "with inaccessible events" do let(:public_project) { create(:project, :public, creator_id: user.id, namespace: user.namespace) } let(:confidential_issue) { create(:closed_issue, confidential: true, project: public_project, author: user) } let!(:confidential_event) { create(:event, project: public_project, author: user, target: confidential_issue, action: Event::CLOSED) } let(:public_issue) { create(:closed_issue, project: public_project, author: user) } let!(:public_event) { create(:event, project: public_project, author: user, target: public_issue, action: Event::CLOSED) } - it 'returns only accessible events' do + it "returns only accessible events" do get api("/projects/#{public_project.id}/events", non_member) expect(response).to have_gitlab_http_status(200) expect(json_response.size).to eq(1) end - it 'returns all events when the user has access' do + it "returns all events when the user has access" do get api("/projects/#{public_project.id}/events", user) expect(response).to have_gitlab_http_status(200) @@ -204,56 +204,56 @@ describe API::Events do end end - context 'pagination' do + context "pagination" do let(:public_project) { create(:project, :public) } before do create(:event, - project: public_project, - target: create(:issue, project: public_project, title: 'Issue 1'), - action: Event::CLOSED, - created_at: Date.parse('2018-12-10')) + project: public_project, + target: create(:issue, project: public_project, title: "Issue 1"), + action: Event::CLOSED, + created_at: Date.parse("2018-12-10")) create(:event, - project: public_project, - target: create(:issue, confidential: true, project: public_project, title: 'Confidential event'), - action: Event::CLOSED, - created_at: Date.parse('2018-12-11')) + project: public_project, + target: create(:issue, confidential: true, project: public_project, title: "Confidential event"), + action: Event::CLOSED, + created_at: Date.parse("2018-12-11")) create(:event, - project: public_project, - target: create(:issue, project: public_project, title: 'Issue 2'), - action: Event::CLOSED, - created_at: Date.parse('2018-12-12')) + project: public_project, + target: create(:issue, project: public_project, title: "Issue 2"), + action: Event::CLOSED, + created_at: Date.parse("2018-12-12")) end - it 'correctly returns the second page without inaccessible events' do - get api("/projects/#{public_project.id}/events", user), params: { per_page: 2, page: 2 } + it "correctly returns the second page without inaccessible events" do + get api("/projects/#{public_project.id}/events", user), params: {per_page: 2, page: 2} - titles = json_response.map { |event| event['target_title'] } + titles = json_response.map { |event| event["target_title"] } - expect(titles.first).to eq('Issue 1') - expect(titles).not_to include('Confidential event') + expect(titles.first).to eq("Issue 1") + expect(titles).not_to include("Confidential event") end - it 'correctly returns the first page without inaccessible events' do - get api("/projects/#{public_project.id}/events", user), params: { per_page: 2, page: 1 } + it "correctly returns the first page without inaccessible events" do + get api("/projects/#{public_project.id}/events", user), params: {per_page: 2, page: 1} - titles = json_response.map { |event| event['target_title'] } + titles = json_response.map { |event| event["target_title"] } - expect(titles.first).to eq('Issue 2') - expect(titles).not_to include('Confidential event') + expect(titles.first).to eq("Issue 2") + expect(titles).not_to include("Confidential event") end end - context 'when not permitted to read' do - it 'returns 404' do + context "when not permitted to read" do + it "returns 404" do get api("/projects/#{private_project.id}/events", non_member) expect(response).to have_gitlab_http_status(404) end end - context 'when authenticated' do - it 'returns project events' do + context "when authenticated" do + it "returns project events" do get api("/projects/#{private_project.id}/events?action=closed&target_type=issue&after=2016-12-1&before=2016-12-31", user) expect(response).to have_gitlab_http_status(200) @@ -262,36 +262,36 @@ describe API::Events do expect(json_response.size).to eq(1) end - it 'returns 404 if project does not exist' do + it "returns 404 if project does not exist" do get api("/projects/1234/events", user) expect(response).to have_gitlab_http_status(404) end end - context 'when exists some events' do - let(:merge_request1) { create(:merge_request, :closed, author: user, assignee: user, source_project: private_project, title: 'Test') } - let(:merge_request2) { create(:merge_request, :closed, author: user, assignee: user, source_project: private_project, title: 'Test') } + context "when exists some events" do + let(:merge_request1) { create(:merge_request, :closed, author: user, assignee: user, source_project: private_project, title: "Test") } + let(:merge_request2) { create(:merge_request, :closed, author: user, assignee: user, source_project: private_project, title: "Test") } before do create_event(merge_request1) end - it 'avoids N+1 queries' do - control_count = ActiveRecord::QueryRecorder.new(skip_cached: false) do - get api("/projects/#{private_project.id}/events", user), params: { target_type: :merge_request } - end.count + it "avoids N+1 queries" do + control_count = ActiveRecord::QueryRecorder.new(skip_cached: false) { + get api("/projects/#{private_project.id}/events", user), params: {target_type: :merge_request} + }.count create_event(merge_request2) - expect do - get api("/projects/#{private_project.id}/events", user), params: { target_type: :merge_request } - end.not_to exceed_all_query_limit(control_count) + expect { + get api("/projects/#{private_project.id}/events", user), params: {target_type: :merge_request} + }.not_to exceed_all_query_limit(control_count) expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response.size).to eq(2) - expect(json_response.map { |r| r['target_id'] }).to match_array([merge_request1.id, merge_request2.id]) + expect(json_response.map { |r| r["target_id"] }).to match_array([merge_request1.id, merge_request2.id]) end def create_event(target) diff --git a/spec/requests/api/features_spec.rb b/spec/requests/api/features_spec.rb index 57a57e69a00..51ef549f531 100644 --- a/spec/requests/api/features_spec.rb +++ b/spec/requests/api/features_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe API::Features do set(:user) { create(:user) } @@ -11,343 +11,357 @@ describe API::Features do end end - describe 'GET /features' do + describe "GET /features" do let(:expected_features) do [ { - 'name' => 'feature_1', - 'state' => 'on', - 'gates' => [{ 'key' => 'boolean', 'value' => true }] + "name" => "feature_1", + "state" => "on", + "gates" => [{"key" => "boolean", "value" => true}], }, { - 'name' => 'feature_2', - 'state' => 'off', - 'gates' => [{ 'key' => 'boolean', 'value' => false }] + "name" => "feature_2", + "state" => "off", + "gates" => [{"key" => "boolean", "value" => false}], }, { - 'name' => 'feature_3', - 'state' => 'conditional', - 'gates' => [ - { 'key' => 'boolean', 'value' => false }, - { 'key' => 'groups', 'value' => ['perf_team'] } - ] - } + "name" => "feature_3", + "state" => "conditional", + "gates" => [ + {"key" => "boolean", "value" => false}, + {"key" => "groups", "value" => ["perf_team"]}, + ], + }, ] end before do - Feature.get('feature_1').enable - Feature.get('feature_2').disable - Feature.get('feature_3').enable Feature.group(:perf_team) + Feature.get("feature_1").enable + Feature.get("feature_2").disable + Feature.get("feature_3").enable Feature.group(:perf_team) end - it 'returns a 401 for anonymous users' do - get api('/features') + it "returns a 401 for anonymous users" do + get api("/features") expect(response).to have_gitlab_http_status(401) end - it 'returns a 403 for users' do - get api('/features', user) + it "returns a 403 for users" do + get api("/features", user) expect(response).to have_gitlab_http_status(403) end - it 'returns the feature list for admins' do - get api('/features', admin) + it "returns the feature list for admins" do + get api("/features", admin) expect(response).to have_gitlab_http_status(200) expect(json_response).to match_array(expected_features) end end - describe 'POST /feature' do - let(:feature_name) { 'my_feature' } + describe "POST /feature" do + let(:feature_name) { "my_feature" } - context 'when the feature does not exist' do - it 'returns a 401 for anonymous users' do + context "when the feature does not exist" do + it "returns a 401 for anonymous users" do post api("/features/#{feature_name}") expect(response).to have_gitlab_http_status(401) end - it 'returns a 403 for users' do + it "returns a 403 for users" do post api("/features/#{feature_name}", user) expect(response).to have_gitlab_http_status(403) end - context 'when passed value=true' do - it 'creates an enabled feature' do - post api("/features/#{feature_name}", admin), params: { value: 'true' } + context "when passed value=true" do + it "creates an enabled feature" do + post api("/features/#{feature_name}", admin), params: {value: "true"} expect(response).to have_gitlab_http_status(201) expect(json_response).to eq( - 'name' => 'my_feature', - 'state' => 'on', - 'gates' => [{ 'key' => 'boolean', 'value' => true }]) + "name" => "my_feature", + "state" => "on", + "gates" => [{"key" => "boolean", "value" => true}] + ) end - it 'creates an enabled feature for the given Flipper group when passed feature_group=perf_team' do - post api("/features/#{feature_name}", admin), params: { value: 'true', feature_group: 'perf_team' } + it "creates an enabled feature for the given Flipper group when passed feature_group=perf_team" do + post api("/features/#{feature_name}", admin), params: {value: "true", feature_group: "perf_team"} expect(response).to have_gitlab_http_status(201) expect(json_response).to eq( - 'name' => 'my_feature', - 'state' => 'conditional', - 'gates' => [ - { 'key' => 'boolean', 'value' => false }, - { 'key' => 'groups', 'value' => ['perf_team'] } - ]) + "name" => "my_feature", + "state" => "conditional", + "gates" => [ + {"key" => "boolean", "value" => false}, + {"key" => "groups", "value" => ["perf_team"]}, + ] + ) end - it 'creates an enabled feature for the given user when passed user=username' do - post api("/features/#{feature_name}", admin), params: { value: 'true', user: user.username } + it "creates an enabled feature for the given user when passed user=username" do + post api("/features/#{feature_name}", admin), params: {value: "true", user: user.username} expect(response).to have_gitlab_http_status(201) expect(json_response).to eq( - 'name' => 'my_feature', - 'state' => 'conditional', - 'gates' => [ - { 'key' => 'boolean', 'value' => false }, - { 'key' => 'actors', 'value' => ["User:#{user.id}"] } - ]) + "name" => "my_feature", + "state" => "conditional", + "gates" => [ + {"key" => "boolean", "value" => false}, + {"key" => "actors", "value" => ["User:#{user.id}"]}, + ] + ) end - it 'creates an enabled feature for the given user and feature group when passed user=username and feature_group=perf_team' do - post api("/features/#{feature_name}", admin), params: { value: 'true', user: user.username, feature_group: 'perf_team' } + it "creates an enabled feature for the given user and feature group when passed user=username and feature_group=perf_team" do + post api("/features/#{feature_name}", admin), params: {value: "true", user: user.username, feature_group: "perf_team"} expect(response).to have_gitlab_http_status(201) expect(json_response).to eq( - 'name' => 'my_feature', - 'state' => 'conditional', - 'gates' => [ - { 'key' => 'boolean', 'value' => false }, - { 'key' => 'groups', 'value' => ['perf_team'] }, - { 'key' => 'actors', 'value' => ["User:#{user.id}"] } - ]) + "name" => "my_feature", + "state" => "conditional", + "gates" => [ + {"key" => "boolean", "value" => false}, + {"key" => "groups", "value" => ["perf_team"]}, + {"key" => "actors", "value" => ["User:#{user.id}"]}, + ] + ) end end - context 'when enabling for a project by path' do - context 'when the project exists' do + context "when enabling for a project by path" do + context "when the project exists" do let!(:project) { create(:project) } - it 'sets the feature gate' do - post api("/features/#{feature_name}", admin), params: { value: 'true', project: project.full_path } + it "sets the feature gate" do + post api("/features/#{feature_name}", admin), params: {value: "true", project: project.full_path} expect(response).to have_gitlab_http_status(201) expect(json_response).to eq( - 'name' => 'my_feature', - 'state' => 'conditional', - 'gates' => [ - { 'key' => 'boolean', 'value' => false }, - { 'key' => 'actors', 'value' => ["Project:#{project.id}"] } - ]) + "name" => "my_feature", + "state" => "conditional", + "gates" => [ + {"key" => "boolean", "value" => false}, + {"key" => "actors", "value" => ["Project:#{project.id}"]}, + ] + ) end end - context 'when the project does not exist' do - it 'sets no new values' do - post api("/features/#{feature_name}", admin), params: { value: 'true', project: 'mep/to/the/mep/mep' } + context "when the project does not exist" do + it "sets no new values" do + post api("/features/#{feature_name}", admin), params: {value: "true", project: "mep/to/the/mep/mep"} expect(response).to have_gitlab_http_status(201) expect(json_response).to eq( "name" => "my_feature", "state" => "off", "gates" => [ - { "key" => "boolean", "value" => false } + {"key" => "boolean", "value" => false}, ] ) end end end - context 'when enabling for a group by path' do - context 'when the group exists' do - it 'sets the feature gate' do + context "when enabling for a group by path" do + context "when the group exists" do + it "sets the feature gate" do group = create(:group) - post api("/features/#{feature_name}", admin), params: { value: 'true', group: group.full_path } + post api("/features/#{feature_name}", admin), params: {value: "true", group: group.full_path} expect(response).to have_gitlab_http_status(201) expect(json_response).to eq( - 'name' => 'my_feature', - 'state' => 'conditional', - 'gates' => [ - { 'key' => 'boolean', 'value' => false }, - { 'key' => 'actors', 'value' => ["Group:#{group.id}"] } - ]) + "name" => "my_feature", + "state" => "conditional", + "gates" => [ + {"key" => "boolean", "value" => false}, + {"key" => "actors", "value" => ["Group:#{group.id}"]}, + ] + ) end end - context 'when the group does not exist' do - it 'sets no new values and keeps the feature disabled' do - post api("/features/#{feature_name}", admin), params: { value: 'true', group: 'not/a/group' } + context "when the group does not exist" do + it "sets no new values and keeps the feature disabled" do + post api("/features/#{feature_name}", admin), params: {value: "true", group: "not/a/group"} expect(response).to have_gitlab_http_status(201) expect(json_response).to eq( "name" => "my_feature", "state" => "off", "gates" => [ - { "key" => "boolean", "value" => false } + {"key" => "boolean", "value" => false}, ] ) end end end - it 'creates a feature with the given percentage if passed an integer' do - post api("/features/#{feature_name}", admin), params: { value: '50' } + it "creates a feature with the given percentage if passed an integer" do + post api("/features/#{feature_name}", admin), params: {value: "50"} expect(response).to have_gitlab_http_status(201) expect(json_response).to eq( - 'name' => 'my_feature', - 'state' => 'conditional', - 'gates' => [ - { 'key' => 'boolean', 'value' => false }, - { 'key' => 'percentage_of_time', 'value' => 50 } - ]) + "name" => "my_feature", + "state" => "conditional", + "gates" => [ + {"key" => "boolean", "value" => false}, + {"key" => "percentage_of_time", "value" => 50}, + ] + ) end end - context 'when the feature exists' do + context "when the feature exists" do let(:feature) { Feature.get(feature_name) } before do feature.disable # This also persists the feature on the DB end - context 'when passed value=true' do - it 'enables the feature' do - post api("/features/#{feature_name}", admin), params: { value: 'true' } + context "when passed value=true" do + it "enables the feature" do + post api("/features/#{feature_name}", admin), params: {value: "true"} expect(response).to have_gitlab_http_status(201) expect(json_response).to eq( - 'name' => 'my_feature', - 'state' => 'on', - 'gates' => [{ 'key' => 'boolean', 'value' => true }]) + "name" => "my_feature", + "state" => "on", + "gates" => [{"key" => "boolean", "value" => true}] + ) end - it 'enables the feature for the given Flipper group when passed feature_group=perf_team' do - post api("/features/#{feature_name}", admin), params: { value: 'true', feature_group: 'perf_team' } + it "enables the feature for the given Flipper group when passed feature_group=perf_team" do + post api("/features/#{feature_name}", admin), params: {value: "true", feature_group: "perf_team"} expect(response).to have_gitlab_http_status(201) expect(json_response).to eq( - 'name' => 'my_feature', - 'state' => 'conditional', - 'gates' => [ - { 'key' => 'boolean', 'value' => false }, - { 'key' => 'groups', 'value' => ['perf_team'] } - ]) + "name" => "my_feature", + "state" => "conditional", + "gates" => [ + {"key" => "boolean", "value" => false}, + {"key" => "groups", "value" => ["perf_team"]}, + ] + ) end - it 'enables the feature for the given user when passed user=username' do - post api("/features/#{feature_name}", admin), params: { value: 'true', user: user.username } + it "enables the feature for the given user when passed user=username" do + post api("/features/#{feature_name}", admin), params: {value: "true", user: user.username} expect(response).to have_gitlab_http_status(201) expect(json_response).to eq( - 'name' => 'my_feature', - 'state' => 'conditional', - 'gates' => [ - { 'key' => 'boolean', 'value' => false }, - { 'key' => 'actors', 'value' => ["User:#{user.id}"] } - ]) + "name" => "my_feature", + "state" => "conditional", + "gates" => [ + {"key" => "boolean", "value" => false}, + {"key" => "actors", "value" => ["User:#{user.id}"]}, + ] + ) end end - context 'when feature is enabled and value=false is passed' do - it 'disables the feature' do + context "when feature is enabled and value=false is passed" do + it "disables the feature" do feature.enable expect(feature).to be_enabled - post api("/features/#{feature_name}", admin), params: { value: 'false' } + post api("/features/#{feature_name}", admin), params: {value: "false"} expect(response).to have_gitlab_http_status(201) expect(json_response).to eq( - 'name' => 'my_feature', - 'state' => 'off', - 'gates' => [{ 'key' => 'boolean', 'value' => false }]) + "name" => "my_feature", + "state" => "off", + "gates" => [{"key" => "boolean", "value" => false}] + ) end - it 'disables the feature for the given Flipper group when passed feature_group=perf_team' do + it "disables the feature for the given Flipper group when passed feature_group=perf_team" do feature.enable(Feature.group(:perf_team)) expect(Feature.get(feature_name).enabled?(admin)).to be_truthy - post api("/features/#{feature_name}", admin), params: { value: 'false', feature_group: 'perf_team' } + post api("/features/#{feature_name}", admin), params: {value: "false", feature_group: "perf_team"} expect(response).to have_gitlab_http_status(201) expect(json_response).to eq( - 'name' => 'my_feature', - 'state' => 'off', - 'gates' => [{ 'key' => 'boolean', 'value' => false }]) + "name" => "my_feature", + "state" => "off", + "gates" => [{"key" => "boolean", "value" => false}] + ) end - it 'disables the feature for the given user when passed user=username' do + it "disables the feature for the given user when passed user=username" do feature.enable(user) expect(Feature.get(feature_name).enabled?(user)).to be_truthy - post api("/features/#{feature_name}", admin), params: { value: 'false', user: user.username } + post api("/features/#{feature_name}", admin), params: {value: "false", user: user.username} expect(response).to have_gitlab_http_status(201) expect(json_response).to eq( - 'name' => 'my_feature', - 'state' => 'off', - 'gates' => [{ 'key' => 'boolean', 'value' => false }]) + "name" => "my_feature", + "state" => "off", + "gates" => [{"key" => "boolean", "value" => false}] + ) end end - context 'with a pre-existing percentage value' do + context "with a pre-existing percentage value" do before do feature.enable_percentage_of_time(50) end - it 'updates the percentage of time if passed an integer' do - post api("/features/#{feature_name}", admin), params: { value: '30' } + it "updates the percentage of time if passed an integer" do + post api("/features/#{feature_name}", admin), params: {value: "30"} expect(response).to have_gitlab_http_status(201) expect(json_response).to eq( - 'name' => 'my_feature', - 'state' => 'conditional', - 'gates' => [ - { 'key' => 'boolean', 'value' => false }, - { 'key' => 'percentage_of_time', 'value' => 30 } - ]) + "name" => "my_feature", + "state" => "conditional", + "gates" => [ + {"key" => "boolean", "value" => false}, + {"key" => "percentage_of_time", "value" => 30}, + ] + ) end end end end - describe 'DELETE /feature/:name' do - let(:feature_name) { 'my_feature' } + describe "DELETE /feature/:name" do + let(:feature_name) { "my_feature" } - context 'when the user has no access' do - it 'returns a 401 for anonymous users' do + context "when the user has no access" do + it "returns a 401 for anonymous users" do delete api("/features/#{feature_name}") expect(response).to have_gitlab_http_status(401) end - it 'returns a 403 for users' do + it "returns a 403 for users" do delete api("/features/#{feature_name}", user) expect(response).to have_gitlab_http_status(403) end end - context 'when the user has access' do - it 'returns 204 when the value is not set' do + context "when the user has access" do + it "returns 204 when the value is not set" do delete api("/features/#{feature_name}", admin) expect(response).to have_gitlab_http_status(204) end - context 'when the gate value was set' do + context "when the gate value was set" do before do Feature.get(feature_name).enable end - it 'deletes an enabled feature' do + it "deletes an enabled feature" do delete api("/features/#{feature_name}", admin) expect(response).to have_gitlab_http_status(204) diff --git a/spec/requests/api/files_spec.rb b/spec/requests/api/files_spec.rb index 1ad536258ba..c328593e820 100644 --- a/spec/requests/api/files_spec.rb +++ b/spec/requests/api/files_spec.rb @@ -1,20 +1,20 @@ -require 'spec_helper' +require "spec_helper" describe API::Files do let(:user) { create(:user) } - let!(:project) { create(:project, :repository, namespace: user.namespace ) } + let!(:project) { create(:project, :repository, namespace: user.namespace) } let(:guest) { create(:user) { |u| project.add_guest(u) } } let(:file_path) { "files%2Fruby%2Fpopen%2Erb" } let(:params) do { - ref: 'master' + ref: "master", } end - let(:author_email) { 'user@example.org' } - let(:author_name) { 'John Doe' } + let(:author_email) { "user@example.org" } + let(:author_name) { "John Doe" } let(:helper) do - fake_class = Class.new do + fake_class = Class.new { include ::API::Helpers::HeadersHelpers attr_reader :headers @@ -26,7 +26,7 @@ describe API::Files do def header(key, value) @headers[key] = value end - end + } fake_class.new end @@ -39,31 +39,31 @@ describe API::Files do "/projects/#{project.id}/repository/files/#{file_path}" end - context 'http headers' do - it 'converts value into string' do + context "http headers" do + it "converts value into string" do helper.set_http_headers(test: 1) - expect(helper.headers).to eq({ 'X-Gitlab-Test' => '1' }) + expect(helper.headers).to eq({"X-Gitlab-Test" => "1"}) end - it 'raises exception if value is an Enumerable' do + it "raises exception if value is an Enumerable" do expect { helper.set_http_headers(test: [1]) }.to raise_error(ArgumentError) end end describe "HEAD /projects/:id/repository/files/:file_path" do - shared_examples_for 'repository files' do - it 'returns file attributes in headers' do + shared_examples_for "repository files" do + it "returns file attributes in headers" do head api(route(file_path), current_user), params: params expect(response).to have_gitlab_http_status(200) - expect(response.headers['X-Gitlab-File-Path']).to eq(CGI.unescape(file_path)) - expect(response.headers['X-Gitlab-File-Name']).to eq('popen.rb') - expect(response.headers['X-Gitlab-Last-Commit-Id']).to eq('570e7b2abdd848b95f2f578043fc23bd6f6fd24d') - expect(response.headers['X-Gitlab-Content-Sha256']).to eq('c440cd09bae50c4632cc58638ad33c6aa375b6109d811e76a9cc3a613c1e8887') + expect(response.headers["X-Gitlab-File-Path"]).to eq(CGI.unescape(file_path)) + expect(response.headers["X-Gitlab-File-Name"]).to eq("popen.rb") + expect(response.headers["X-Gitlab-Last-Commit-Id"]).to eq("570e7b2abdd848b95f2f578043fc23bd6f6fd24d") + expect(response.headers["X-Gitlab-Content-Sha256"]).to eq("c440cd09bae50c4632cc58638ad33c6aa375b6109d811e76a9cc3a613c1e8887") end - it 'returns file by commit sha' do + it "returns file by commit sha" do # This file is deleted on HEAD file_path = "files%2Fjs%2Fcommit%2Ejs%2Ecoffee" params[:ref] = "6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9" @@ -71,11 +71,11 @@ describe API::Files do head api(route(file_path), current_user), params: params expect(response).to have_gitlab_http_status(200) - expect(response.headers['X-Gitlab-File-Name']).to eq('commit.js.coffee') - expect(response.headers['X-Gitlab-Content-Sha256']).to eq('08785f04375b47f81f46e68cc125d5ef368aa20576ddb53f91f4d83f1d04b929') + expect(response.headers["X-Gitlab-File-Name"]).to eq("commit.js.coffee") + expect(response.headers["X-Gitlab-Content-Sha256"]).to eq("08785f04375b47f81f46e68cc125d5ef368aa20576ddb53f91f4d83f1d04b929") end - context 'when mandatory params are not given' do + context "when mandatory params are not given" do it "responds with a 400 status" do head api(route("any%2Ffile"), current_user) @@ -83,18 +83,18 @@ describe API::Files do end end - context 'when file_path does not exist' do + context "when file_path does not exist" do it "responds with a 404 status" do - params[:ref] = 'master' + params[:ref] = "master" - head api(route('app%2Fmodels%2Fapplication%2Erb'), current_user), params: params + head api(route("app%2Fmodels%2Fapplication%2Erb"), current_user), params: params expect(response).to have_gitlab_http_status(404) end end - context 'when file_path does not exist' do - include_context 'disabled repository' + context "when file_path does not exist" do + include_context "disabled repository" it "responds with a 403 status" do head api(route(file_path), current_user), params: params @@ -104,14 +104,14 @@ describe API::Files do end end - context 'when unauthenticated', 'and project is public' do - it_behaves_like 'repository files' do + context "when unauthenticated", "and project is public" do + it_behaves_like "repository files" do let(:project) { create(:project, :public, :repository) } let(:current_user) { nil } end end - context 'when unauthenticated', 'and project is private' do + context "when unauthenticated", "and project is private" do it "responds with a 404 status" do current_user = nil @@ -121,49 +121,49 @@ describe API::Files do end end - context 'when PATs are used' do - it_behaves_like 'repository files' do - let(:token) { create(:personal_access_token, scopes: ['read_repository'], user: user) } - let(:current_user) { { personal_access_token: token } } + context "when PATs are used" do + it_behaves_like "repository files" do + let(:token) { create(:personal_access_token, scopes: ["read_repository"], user: user) } + let(:current_user) { {personal_access_token: token} } end end - context 'when authenticated', 'as a developer' do - it_behaves_like 'repository files' do + context "when authenticated", "as a developer" do + it_behaves_like "repository files" do let(:current_user) { user } end end - context 'when authenticated', 'as a guest' do - it_behaves_like '403 response' do + context "when authenticated", "as a guest" do + it_behaves_like "403 response" do let(:request) { head api(route(file_path), guest), params: params } end end end describe "GET /projects/:id/repository/files/:file_path" do - shared_examples_for 'repository files' do - it 'returns file attributes as json' do + shared_examples_for "repository files" do + it "returns file attributes as json" do get api(route(file_path), current_user), params: params expect(response).to have_gitlab_http_status(200) - expect(json_response['file_path']).to eq(CGI.unescape(file_path)) - expect(json_response['file_name']).to eq('popen.rb') - expect(json_response['last_commit_id']).to eq('570e7b2abdd848b95f2f578043fc23bd6f6fd24d') - expect(json_response['content_sha256']).to eq('c440cd09bae50c4632cc58638ad33c6aa375b6109d811e76a9cc3a613c1e8887') - expect(Base64.decode64(json_response['content']).lines.first).to eq("require 'fileutils'\n") + expect(json_response["file_path"]).to eq(CGI.unescape(file_path)) + expect(json_response["file_name"]).to eq("popen.rb") + expect(json_response["last_commit_id"]).to eq("570e7b2abdd848b95f2f578043fc23bd6f6fd24d") + expect(json_response["content_sha256"]).to eq("c440cd09bae50c4632cc58638ad33c6aa375b6109d811e76a9cc3a613c1e8887") + expect(Base64.decode64(json_response["content"]).lines.first).to eq("require 'fileutils'\n") end - it 'returns json when file has txt extension' do + it "returns json when file has txt extension" do file_path = "bar%2Fbranch-test.txt" get api(route(file_path), current_user), params: params expect(response).to have_gitlab_http_status(200) - expect(response.content_type).to eq('application/json') + expect(response.content_type).to eq("application/json") end - it 'returns file by commit sha' do + it "returns file by commit sha" do # This file is deleted on HEAD file_path = "files%2Fjs%2Fcommit%2Ejs%2Ecoffee" params[:ref] = "6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9" @@ -171,12 +171,12 @@ describe API::Files do get api(route(file_path), current_user), params: params expect(response).to have_gitlab_http_status(200) - expect(json_response['file_name']).to eq('commit.js.coffee') - expect(json_response['content_sha256']).to eq('08785f04375b47f81f46e68cc125d5ef368aa20576ddb53f91f4d83f1d04b929') - expect(Base64.decode64(json_response['content']).lines.first).to eq("class Commit\n") + expect(json_response["file_name"]).to eq("commit.js.coffee") + expect(json_response["content_sha256"]).to eq("08785f04375b47f81f46e68cc125d5ef368aa20576ddb53f91f4d83f1d04b929") + expect(Base64.decode64(json_response["content"]).lines.first).to eq("class Commit\n") end - it 'returns raw file info' do + it "returns raw file info" do url = route(file_path) + "/raw" expect(Gitlab::Workhorse).to receive(:send_git_blob) @@ -186,75 +186,75 @@ describe API::Files do expect(headers[Gitlab::Workhorse::DETECT_HEADER]).to eq "true" end - it 'sets inline content disposition by default' do + it "sets inline content disposition by default" do url = route(file_path) + "/raw" get api(url, current_user), params: params - expect(headers['Content-Disposition']).to eq(%q(inline; filename="popen.rb"; filename*=UTF-8''popen.rb)) + expect(headers["Content-Disposition"]).to eq(%q(inline; filename="popen.rb"; filename*=UTF-8''popen.rb)) end - context 'when mandatory params are not given' do - it_behaves_like '400 response' do + context "when mandatory params are not given" do + it_behaves_like "400 response" do let(:request) { get api(route("any%2Ffile"), current_user) } end end - context 'when file_path does not exist' do - let(:params) { { ref: 'master' } } + context "when file_path does not exist" do + let(:params) { {ref: "master"} } - it_behaves_like '404 response' do - let(:request) { get api(route('app%2Fmodels%2Fapplication%2Erb'), current_user), params: params } - let(:message) { '404 File Not Found' } + it_behaves_like "404 response" do + let(:request) { get api(route("app%2Fmodels%2Fapplication%2Erb"), current_user), params: params } + let(:message) { "404 File Not Found" } end end - context 'when repository is disabled' do - include_context 'disabled repository' + context "when repository is disabled" do + include_context "disabled repository" - it_behaves_like '403 response' do + it_behaves_like "403 response" do let(:request) { get api(route(file_path), current_user), params: params } end end end - context 'when unauthenticated', 'and project is public' do - it_behaves_like 'repository files' do + context "when unauthenticated", "and project is public" do + it_behaves_like "repository files" do let(:project) { create(:project, :public, :repository) } let(:current_user) { nil } end end - context 'when PATs are used' do - it_behaves_like 'repository files' do - let(:token) { create(:personal_access_token, scopes: ['read_repository'], user: user) } - let(:current_user) { { personal_access_token: token } } + context "when PATs are used" do + it_behaves_like "repository files" do + let(:token) { create(:personal_access_token, scopes: ["read_repository"], user: user) } + let(:current_user) { {personal_access_token: token} } end end - context 'when unauthenticated', 'and project is private' do - it_behaves_like '404 response' do + context "when unauthenticated", "and project is private" do + it_behaves_like "404 response" do let(:request) { get api(route(file_path)), params: params } - let(:message) { '404 Project Not Found' } + let(:message) { "404 Project Not Found" } end end - context 'when authenticated', 'as a developer' do - it_behaves_like 'repository files' do + context "when authenticated", "as a developer" do + it_behaves_like "repository files" do let(:current_user) { user } end end - context 'when authenticated', 'as a guest' do - it_behaves_like '403 response' do + context "when authenticated", "as a guest" do + it_behaves_like "403 response" do let(:request) { get api(route(file_path), guest), params: params } end end end describe "GET /projects/:id/repository/files/:file_path/raw" do - shared_examples_for 'repository raw files' do - it 'returns raw file info' do + shared_examples_for "repository raw files" do + it "returns raw file info" do url = route(file_path) + "/raw" expect(Gitlab::Workhorse).to receive(:send_git_blob) @@ -263,8 +263,8 @@ describe API::Files do expect(response).to have_gitlab_http_status(200) end - it 'returns raw file info for files with dots' do - url = route('.gitignore') + "/raw" + it "returns raw file info for files with dots" do + url = route(".gitignore") + "/raw" expect(Gitlab::Workhorse).to receive(:send_git_blob) get api(url, current_user), params: params @@ -272,7 +272,7 @@ describe API::Files do expect(response).to have_gitlab_http_status(200) end - it 'returns file by commit sha' do + it "returns file by commit sha" do # This file is deleted on HEAD file_path = "files%2Fjs%2Fcommit%2Ejs%2Ecoffee" params[:ref] = "6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9" @@ -283,59 +283,59 @@ describe API::Files do expect(response).to have_gitlab_http_status(200) end - context 'when mandatory params are not given' do - it_behaves_like '400 response' do + context "when mandatory params are not given" do + it_behaves_like "400 response" do let(:request) { get api(route("any%2Ffile"), current_user) } end end - context 'when file_path does not exist' do - let(:params) { { ref: 'master' } } + context "when file_path does not exist" do + let(:params) { {ref: "master"} } - it_behaves_like '404 response' do - let(:request) { get api(route('app%2Fmodels%2Fapplication%2Erb'), current_user), params: params } - let(:message) { '404 File Not Found' } + it_behaves_like "404 response" do + let(:request) { get api(route("app%2Fmodels%2Fapplication%2Erb"), current_user), params: params } + let(:message) { "404 File Not Found" } end end - context 'when repository is disabled' do - include_context 'disabled repository' + context "when repository is disabled" do + include_context "disabled repository" - it_behaves_like '403 response' do + it_behaves_like "403 response" do let(:request) { get api(route(file_path), current_user), params: params } end end end - context 'when unauthenticated', 'and project is public' do - it_behaves_like 'repository raw files' do + context "when unauthenticated", "and project is public" do + it_behaves_like "repository raw files" do let(:project) { create(:project, :public, :repository) } let(:current_user) { nil } end end - context 'when unauthenticated', 'and project is private' do - it_behaves_like '404 response' do + context "when unauthenticated", "and project is private" do + it_behaves_like "404 response" do let(:request) { get api(route(file_path)), params: params } - let(:message) { '404 Project Not Found' } + let(:message) { "404 Project Not Found" } end end - context 'when authenticated', 'as a developer' do - it_behaves_like 'repository raw files' do + context "when authenticated", "as a developer" do + it_behaves_like "repository raw files" do let(:current_user) { user } end end - context 'when authenticated', 'as a guest' do - it_behaves_like '403 response' do + context "when authenticated", "as a guest" do + it_behaves_like "403 response" do let(:request) { get api(route(file_path), guest), params: params } end end - context 'when PATs are used' do - it 'returns file by commit sha' do - token = create(:personal_access_token, scopes: ['read_repository'], user: user) + context "when PATs are used" do + it "returns file by commit sha" do + token = create(:personal_access_token, scopes: ["read_repository"], user: user) # This file is deleted on HEAD file_path = "files%2Fjs%2Fcommit%2Ejs%2Ecoffee" @@ -355,7 +355,7 @@ describe API::Files do { branch: "master", content: "puts 8", - commit_message: "Added newfile" + commit_message: "Added newfile", } end @@ -375,8 +375,8 @@ describe API::Files do expect(response).to have_gitlab_http_status(400) end - it 'returns a 400 bad request if the commit message is empty' do - params[:commit_message] = '' + it "returns a 400 bad request if the commit message is empty" do + params[:commit_message] = "" post api(route(file_path), user), params: params @@ -385,24 +385,24 @@ describe API::Files do it "returns a 400 if editor fails to create file" do allow_any_instance_of(Repository).to receive(:create_file) - .and_raise(Gitlab::Git::CommitError, 'Cannot create file') + .and_raise(Gitlab::Git::CommitError, "Cannot create file") post api(route("any%2Etxt"), user), params: params expect(response).to have_gitlab_http_status(400) end - context 'with PATs' do - it 'returns 403 with `read_repository` scope' do - token = create(:personal_access_token, scopes: ['read_repository'], user: user) + context "with PATs" do + it "returns 403 with `read_repository` scope" do + token = create(:personal_access_token, scopes: ["read_repository"], user: user) post api(route(file_path), personal_access_token: token), params: params expect(response).to have_gitlab_http_status(403) end - it 'returns 201 with `api` scope' do - token = create(:personal_access_token, scopes: ['api'], user: user) + it "returns 201 with `api` scope" do + token = create(:personal_access_token, scopes: ["api"], user: user) post api(route(file_path), personal_access_token: token), params: params @@ -417,21 +417,21 @@ describe API::Files do post api(route("new_file_with_author%2Etxt"), user), params: params expect(response).to have_gitlab_http_status(201) - expect(response.content_type).to eq('application/json') + expect(response.content_type).to eq("application/json") last_commit = project.repository.commit.raw expect(last_commit.author_email).to eq(author_email) expect(last_commit.author_name).to eq(author_name) end end - context 'when the repo is empty' do - let!(:project) { create(:project_empty_repo, namespace: user.namespace ) } + context "when the repo is empty" do + let!(:project) { create(:project_empty_repo, namespace: user.namespace) } it "creates a new file in project repo" do post api(route("newfile%2Erb"), user), params: params expect(response).to have_gitlab_http_status(201) - expect(json_response['file_path']).to eq('newfile.rb') + expect(json_response["file_path"]).to eq("newfile.rb") last_commit = project.repository.commit.raw expect(last_commit.author_email).to eq(user.email) expect(last_commit.author_name).to eq(user.name) @@ -442,9 +442,9 @@ describe API::Files do describe "PUT /projects/:id/repository/files" do let(:params) do { - branch: 'master', - content: 'puts 8', - commit_message: 'Changed file' + branch: "master", + content: "puts 8", + commit_message: "Changed file", } end @@ -452,14 +452,14 @@ describe API::Files do put api(route(file_path), user), params: params expect(response).to have_gitlab_http_status(200) - expect(json_response['file_path']).to eq(CGI.unescape(file_path)) + expect(json_response["file_path"]).to eq(CGI.unescape(file_path)) last_commit = project.repository.commit.raw expect(last_commit.author_email).to eq(user.email) expect(last_commit.author_name).to eq(user.name) end - it 'returns a 400 bad request if the commit message is empty' do - params[:commit_message] = '' + it "returns a 400 bad request if the commit message is empty" do + params[:commit_message] = "" put api(route(file_path), user), params: params @@ -467,17 +467,17 @@ describe API::Files do end it "returns a 400 bad request if update existing file with stale last commit id" do - params_with_stale_id = params.merge(last_commit_id: 'stale') + params_with_stale_id = params.merge(last_commit_id: "stale") put api(route(file_path), user), params: params_with_stale_id expect(response).to have_gitlab_http_status(400) - expect(json_response['message']).to eq('You are attempting to update a file that has changed since you started editing it.') + expect(json_response["message"]).to eq("You are attempting to update a file that has changed since you started editing it.") end it "updates existing file in project repo with accepts correct last commit id" do last_commit = Gitlab::Git::Commit - .last_for_path(project.repository, 'master', URI.unescape(file_path)) + .last_for_path(project.repository, "master", URI.unescape(file_path)) params_with_correct_id = params.merge(last_commit_id: last_commit.id) put api(route(file_path), user), params: params_with_correct_id @@ -508,8 +508,8 @@ describe API::Files do describe "DELETE /projects/:id/repository/files" do let(:params) do { - branch: 'master', - commit_message: 'Changed file' + branch: "master", + commit_message: "Changed file", } end @@ -525,8 +525,8 @@ describe API::Files do expect(response).to have_gitlab_http_status(400) end - it 'returns a 400 bad request if the commit message is empty' do - params[:commit_message] = '' + it "returns a 400 bad request if the commit message is empty" do + params[:commit_message] = "" delete api(route(file_path), user), params: params @@ -534,7 +534,7 @@ describe API::Files do end it "returns a 400 if fails to delete file" do - allow_any_instance_of(Repository).to receive(:delete_file).and_raise(Gitlab::Git::CommitError, 'Cannot delete file') + allow_any_instance_of(Repository).to receive(:delete_file).and_raise(Gitlab::Git::CommitError, "Cannot delete file") delete api(route(file_path), user), params: params @@ -553,18 +553,18 @@ describe API::Files do end describe "POST /projects/:id/repository/files with binary file" do - let(:file_path) { 'test%2Ebin' } + let(:file_path) { "test%2Ebin" } let(:put_params) do { - branch: 'master', - content: 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAAACnej3aAAAAAXRSTlMAQObYZgAAAApJREFUCNdjYAAAAAIAAeIhvDMAAAAASUVORK5CYII=', + branch: "master", + content: "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAAACnej3aAAAAAXRSTlMAQObYZgAAAApJREFUCNdjYAAAAAIAAeIhvDMAAAAASUVORK5CYII=", commit_message: 'Binary file with a \n should not be touched', - encoding: 'base64' + encoding: "base64", } end let(:get_params) do { - ref: 'master' + ref: "master", } end @@ -576,9 +576,9 @@ describe API::Files do get api(route(file_path), user), params: get_params expect(response).to have_gitlab_http_status(200) - expect(json_response['file_path']).to eq(CGI.unescape(file_path)) - expect(json_response['file_name']).to eq(CGI.unescape(file_path)) - expect(json_response['content']).to eq(put_params[:content]) + expect(json_response["file_path"]).to eq(CGI.unescape(file_path)) + expect(json_response["file_name"]).to eq(CGI.unescape(file_path)) + expect(json_response["content"]).to eq(put_params[:content]) end end end diff --git a/spec/requests/api/graphql/mutations/merge_requests/set_wip_spec.rb b/spec/requests/api/graphql/mutations/merge_requests/set_wip_spec.rb index 8f427d71a32..4b4fda22721 100644 --- a/spec/requests/api/graphql/mutations/merge_requests/set_wip_spec.rb +++ b/spec/requests/api/graphql/mutations/merge_requests/set_wip_spec.rb @@ -1,17 +1,17 @@ -require 'spec_helper' +require "spec_helper" -describe 'Setting WIP status of a merge request' do +describe "Setting WIP status of a merge request" do include GraphqlHelpers let(:current_user) { create(:user) } let(:merge_request) { create(:merge_request) } let(:project) { merge_request.project } - let(:input) { { wip: true } } + let(:input) { {wip: true} } let(:mutation) do variables = { project_path: project.full_path, - iid: merge_request.iid + iid: merge_request.iid, } graphql_mutation(:merge_request_set_wip, variables.merge(input)) end @@ -24,45 +24,45 @@ describe 'Setting WIP status of a merge request' do project.add_developer(current_user) end - it 'returns an error if the user is not allowed to update the merge request' do + it "returns an error if the user is not allowed to update the merge request" do post_graphql_mutation(mutation, current_user: create(:user)) expect(graphql_errors).not_to be_empty end - it 'marks the merge request as WIP' do + it "marks the merge request as WIP" do post_graphql_mutation(mutation, current_user: current_user) expect(response).to have_gitlab_http_status(:success) - expect(mutation_response['mergeRequest']['title']).to start_with('WIP:') + expect(mutation_response["mergeRequest"]["title"]).to start_with("WIP:") end - it 'does not do anything if the merge request was already marked `WIP`' do - merge_request.update!(title: 'wip: hello world') + it "does not do anything if the merge request was already marked `WIP`" do + merge_request.update!(title: "wip: hello world") post_graphql_mutation(mutation, current_user: current_user) expect(response).to have_gitlab_http_status(:success) - expect(mutation_response['mergeRequest']['title']).to start_with('wip:') + expect(mutation_response["mergeRequest"]["title"]).to start_with("wip:") end - context 'when passing WIP false as input' do - let(:input) { { wip: false } } + context "when passing WIP false as input" do + let(:input) { {wip: false} } - it 'does not do anything if the merge reqeust was not marked wip' do + it "does not do anything if the merge reqeust was not marked wip" do post_graphql_mutation(mutation, current_user: current_user) expect(response).to have_gitlab_http_status(:success) - expect(mutation_response['mergeRequest']['title']).not_to start_with(/wip\:/) + expect(mutation_response["mergeRequest"]["title"]).not_to start_with(/wip\:/) end - it 'unmarks the merge request as `WIP`' do - merge_request.update!(title: 'wip: hello world') + it "unmarks the merge request as `WIP`" do + merge_request.update!(title: "wip: hello world") post_graphql_mutation(mutation, current_user: current_user) expect(response).to have_gitlab_http_status(:success) - expect(mutation_response['mergeRequest']['title']).not_to start_with('/wip\:/') + expect(mutation_response["mergeRequest"]["title"]).not_to start_with('/wip\:/') end end end diff --git a/spec/requests/api/graphql/project/issues_spec.rb b/spec/requests/api/graphql/project/issues_spec.rb index c2934430821..3493fa00509 100644 --- a/spec/requests/api/graphql/project/issues_spec.rb +++ b/spec/requests/api/graphql/project/issues_spec.rb @@ -1,54 +1,54 @@ -require 'spec_helper' +require "spec_helper" -describe 'getting an issue list for a project' do +describe "getting an issue list for a project" do include GraphqlHelpers let(:project) { create(:project, :repository, :public) } let(:current_user) { create(:user) } - let(:issues_data) { graphql_data['project']['issues']['edges'] } + let(:issues_data) { graphql_data["project"]["issues"]["edges"] } let!(:issues) do create(:issue, project: project, discussion_locked: true) create(:issue, project: project) end let(:fields) do <<~QUERY - edges { - node { - #{all_graphql_fields_for('issues'.classify)} + edges { + node { + #{all_graphql_fields_for("issues".classify)} + } } - } QUERY end let(:query) do graphql_query_for( - 'project', - { 'fullPath' => project.full_path }, - query_graphql_field('issues', {}, fields) + "project", + {"fullPath" => project.full_path}, + query_graphql_field("issues", {}, fields) ) end - it_behaves_like 'a working graphql query' do + it_behaves_like "a working graphql query" do before do post_graphql(query, current_user: current_user) end end - it 'includes a web_url' do + it "includes a web_url" do post_graphql(query, current_user: current_user) - expect(issues_data[0]['node']['webUrl']).to be_present + expect(issues_data[0]["node"]["webUrl"]).to be_present end - it 'includes discussion locked' do + it "includes discussion locked" do post_graphql(query, current_user: current_user) - expect(issues_data[0]['node']['discussionLocked']).to eq false - expect(issues_data[1]['node']['discussionLocked']).to eq true + expect(issues_data[0]["node"]["discussionLocked"]).to eq false + expect(issues_data[1]["node"]["discussionLocked"]).to eq true end - context 'when the user does not have access to the issue' do - it 'returns nil' do + context "when the user does not have access to the issue" do + it "returns nil" do project.project_feature.update!(issues_access_level: ProjectFeature::PRIVATE) post_graphql(query) @@ -57,34 +57,34 @@ describe 'getting an issue list for a project' do end end - context 'when there is a confidential issue' do + context "when there is a confidential issue" do let!(:confidential_issue) do create(:issue, :confidential, project: project) end - context 'when the user cannot see confidential issues' do - it 'returns issues without confidential issues' do + context "when the user cannot see confidential issues" do + it "returns issues without confidential issues" do post_graphql(query, current_user: current_user) expect(issues_data.size).to eq(2) issues_data.each do |issue| - expect(issue.dig('node', 'confidential')).to eq(false) + expect(issue.dig("node", "confidential")).to eq(false) end end end - context 'when the user can see confidential issues' do - it 'returns issues with confidential issues' do + context "when the user can see confidential issues" do + it "returns issues with confidential issues" do project.add_developer(current_user) post_graphql(query, current_user: current_user) expect(issues_data.size).to eq(3) - confidentials = issues_data.map do |issue| - issue.dig('node', 'confidential') - end + confidentials = issues_data.map { |issue| + issue.dig("node", "confidential") + } expect(confidentials).to eq([true, false, false]) end diff --git a/spec/requests/api/graphql/project/merge_request_spec.rb b/spec/requests/api/graphql/project/merge_request_spec.rb index deb6abbc026..b45f32eefbb 100644 --- a/spec/requests/api/graphql/project/merge_request_spec.rb +++ b/spec/requests/api/graphql/project/merge_request_spec.rb @@ -1,65 +1,65 @@ -require 'spec_helper' +require "spec_helper" -describe 'getting merge request information nested in a project' do +describe "getting merge request information nested in a project" do include GraphqlHelpers let(:project) { create(:project, :repository, :public) } let(:current_user) { create(:user) } - let(:merge_request_graphql_data) { graphql_data['project']['mergeRequest'] } + let(:merge_request_graphql_data) { graphql_data["project"]["mergeRequest"] } let!(:merge_request) { create(:merge_request, source_project: project) } let(:query) do graphql_query_for( - 'project', - { 'fullPath' => project.full_path }, - query_graphql_field('mergeRequest', iid: merge_request.iid) + "project", + {"fullPath" => project.full_path}, + query_graphql_field("mergeRequest", iid: merge_request.iid) ) end - it_behaves_like 'a working graphql query' do + it_behaves_like "a working graphql query" do before do post_graphql(query, current_user: current_user) end end - it 'contains merge request information' do + it "contains merge request information" do post_graphql(query, current_user: current_user) expect(merge_request_graphql_data).not_to be_nil end # This is a field coming from the `MergeRequestPresenter` - it 'includes a web_url' do + it "includes a web_url" do post_graphql(query, current_user: current_user) - expect(merge_request_graphql_data['webUrl']).to be_present + expect(merge_request_graphql_data["webUrl"]).to be_present end - context 'permissions on the merge request' do - it 'includes the permissions for the current user on a public project' do + context "permissions on the merge request" do + it "includes the permissions for the current user on a public project" do expected_permissions = { - 'readMergeRequest' => true, - 'adminMergeRequest' => false, - 'createNote' => true, - 'pushToSourceBranch' => false, - 'removeSourceBranch' => false, - 'cherryPickOnCurrentMergeRequest' => false, - 'revertOnCurrentMergeRequest' => false, - 'updateMergeRequest' => false + "readMergeRequest" => true, + "adminMergeRequest" => false, + "createNote" => true, + "pushToSourceBranch" => false, + "removeSourceBranch" => false, + "cherryPickOnCurrentMergeRequest" => false, + "revertOnCurrentMergeRequest" => false, + "updateMergeRequest" => false, } post_graphql(query, current_user: current_user) - permission_data = merge_request_graphql_data['userPermissions'] + permission_data = merge_request_graphql_data["userPermissions"] expect(permission_data).to be_present expect(permission_data).to eq(expected_permissions) end end - context 'when the user does not have access to the merge request' do + context "when the user does not have access to the merge request" do let(:project) { create(:project, :public, :repository) } - it 'returns nil' do + it "returns nil" do project.project_feature.update!(merge_requests_access_level: ProjectFeature::PRIVATE) post_graphql(query) @@ -68,7 +68,7 @@ describe 'getting merge request information nested in a project' do end end - context 'when there are pipelines' do + context "when there are pipelines" do before do pipeline = create( :ci_pipeline, @@ -79,16 +79,16 @@ describe 'getting merge request information nested in a project' do merge_request.update!(head_pipeline: pipeline) end - it 'has a head pipeline' do + it "has a head pipeline" do post_graphql(query, current_user: current_user) - expect(merge_request_graphql_data['headPipeline']).to be_present + expect(merge_request_graphql_data["headPipeline"]).to be_present end - it 'has pipeline connections' do + it "has pipeline connections" do post_graphql(query, current_user: current_user) - expect(merge_request_graphql_data['pipelines']['edges'].size).to eq(1) + expect(merge_request_graphql_data["pipelines"]["edges"].size).to eq(1) end end end diff --git a/spec/requests/api/graphql/project_query_spec.rb b/spec/requests/api/graphql/project_query_spec.rb index 0727ada4691..523efe365e3 100644 --- a/spec/requests/api/graphql/project_query_spec.rb +++ b/spec/requests/api/graphql/project_query_spec.rb @@ -1,53 +1,53 @@ -require 'spec_helper' +require "spec_helper" -describe 'getting project information' do +describe "getting project information" do include GraphqlHelpers let(:project) { create(:project, :repository) } let(:current_user) { create(:user) } let(:query) do - graphql_query_for('project', 'fullPath' => project.full_path) + graphql_query_for("project", "fullPath" => project.full_path) end - context 'when the user has access to the project' do + context "when the user has access to the project" do before do project.add_developer(current_user) end - it 'includes the project' do + it "includes the project" do post_graphql(query, current_user: current_user) - expect(graphql_data['project']).not_to be_nil + expect(graphql_data["project"]).not_to be_nil end - it_behaves_like 'a working graphql query' do + it_behaves_like "a working graphql query" do before do post_graphql(query, current_user: current_user) end end - context 'when there are pipelines present' do + context "when there are pipelines present" do before do create(:ci_pipeline, project: project) end - it 'is included in the pipelines connection' do + it "is included in the pipelines connection" do post_graphql(query, current_user: current_user) - expect(graphql_data['project']['pipelines']['edges'].size).to eq(1) + expect(graphql_data["project"]["pipelines"]["edges"].size).to eq(1) end end end - context 'when the user does not have access to the project' do - it 'returns an empty field' do + context "when the user does not have access to the project" do + it "returns an empty field" do post_graphql(query, current_user: current_user) - expect(graphql_data['project']).to be_nil + expect(graphql_data["project"]).to be_nil end - it_behaves_like 'a working graphql query' do + it_behaves_like "a working graphql query" do before do post_graphql(query, current_user: current_user) end diff --git a/spec/requests/api/group_boards_spec.rb b/spec/requests/api/group_boards_spec.rb index b400a7f55ef..7629f7a197e 100644 --- a/spec/requests/api/group_boards_spec.rb +++ b/spec/requests/api/group_boards_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe API::GroupBoards do set(:user) { create(:user) } @@ -11,18 +11,18 @@ describe API::GroupBoards do board_parent.add_owner(user) end - set(:project) { create(:project, :public, namespace: board_parent ) } + set(:project) { create(:project, :public, namespace: board_parent) } set(:dev_label) do - create(:group_label, title: 'Development', color: '#FFAABB', group: board_parent) + create(:group_label, title: "Development", color: "#FFAABB", group: board_parent) end set(:test_label) do - create(:group_label, title: 'Testing', color: '#FFAACC', group: board_parent) + create(:group_label, title: "Testing", color: "#FFAACC", group: board_parent) end set(:ux_label) do - create(:group_label, title: 'UX', color: '#FF0000', group: board_parent) + create(:group_label, title: "UX", color: "#FF0000", group: board_parent) end set(:dev_list) do @@ -38,15 +38,15 @@ describe API::GroupBoards do set(:board) { create(:board, group: board_parent, lists: [dev_list, test_list]) } - it_behaves_like 'group and project boards', "/groups/:id/boards", false + it_behaves_like "group and project boards", "/groups/:id/boards", false - describe 'POST /groups/:id/boards/lists' do + describe "POST /groups/:id/boards/lists" do let(:url) { "/groups/#{board_parent.id}/boards/#{board.id}/lists" } - it 'does not create lists for child project labels' do + it "does not create lists for child project labels" do project_label = create(:label, project: project) - post api(url, user), params: { label_id: project_label.id } + post api(url, user), params: {label_id: project_label.id} expect(response).to have_gitlab_http_status(400) end diff --git a/spec/requests/api/group_labels_spec.rb b/spec/requests/api/group_labels_spec.rb index 3769f8b78e4..6c5087b6318 100644 --- a/spec/requests/api/group_labels_spec.rb +++ b/spec/requests/api/group_labels_spec.rb @@ -1,94 +1,94 @@ # frozen_string_literal: true -require 'spec_helper' +require "spec_helper" describe API::GroupLabels do let(:user) { create(:user) } let(:group) { create(:group) } let!(:group_member) { create(:group_member, group: group, user: user) } - let!(:label1) { create(:group_label, title: 'feature', group: group) } - let!(:label2) { create(:group_label, title: 'bug', group: group) } + let!(:label1) { create(:group_label, title: "feature", group: group) } + let!(:label2) { create(:group_label, title: "bug", group: group) } - describe 'GET :id/labels' do - it 'returns all available labels for the group' do + describe "GET :id/labels" do + it "returns all available labels for the group" do get api("/groups/#{group.id}/labels", user) expect(response).to have_gitlab_http_status(200) - expect(response).to match_response_schema('public_api/v4/group_labels') + expect(response).to match_response_schema("public_api/v4/group_labels") expect(response).to include_pagination_headers expect(json_response).to be_an Array expect(json_response.size).to eq(2) - expect(json_response.map {|r| r['name'] }).to contain_exactly('feature', 'bug') + expect(json_response.map {|r| r["name"] }).to contain_exactly("feature", "bug") end end - describe 'POST /groups/:id/labels' do - it 'returns created label when all params are given' do + describe "POST /groups/:id/labels" do + it "returns created label when all params are given" do post api("/groups/#{group.id}/labels", user), - params: { - name: 'Foo', - color: '#FFAABB', - description: 'test' - } + params: { + name: "Foo", + color: "#FFAABB", + description: "test", + } expect(response).to have_gitlab_http_status(201) - expect(json_response['name']).to eq('Foo') - expect(json_response['color']).to eq('#FFAABB') - expect(json_response['description']).to eq('test') + expect(json_response["name"]).to eq("Foo") + expect(json_response["color"]).to eq("#FFAABB") + expect(json_response["description"]).to eq("test") end - it 'returns created label when only required params are given' do + it "returns created label when only required params are given" do post api("/groups/#{group.id}/labels", user), - params: { - name: 'Foo & Bar', - color: '#FFAABB' - } + params: { + name: "Foo & Bar", + color: "#FFAABB", + } expect(response.status).to eq(201) - expect(json_response['name']).to eq('Foo & Bar') - expect(json_response['color']).to eq('#FFAABB') - expect(json_response['description']).to be_nil + expect(json_response["name"]).to eq("Foo & Bar") + expect(json_response["color"]).to eq("#FFAABB") + expect(json_response["description"]).to be_nil end - it 'returns a 400 bad request if name not given' do - post api("/groups/#{group.id}/labels", user), params: { color: '#FFAABB' } + it "returns a 400 bad request if name not given" do + post api("/groups/#{group.id}/labels", user), params: {color: "#FFAABB"} expect(response).to have_gitlab_http_status(400) end - it 'returns a 400 bad request if color is not given' do - post api("/groups/#{group.id}/labels", user), params: { name: 'Foobar' } + it "returns a 400 bad request if color is not given" do + post api("/groups/#{group.id}/labels", user), params: {name: "Foobar"} expect(response).to have_gitlab_http_status(400) end - it 'returns 409 if label already exists' do + it "returns 409 if label already exists" do post api("/groups/#{group.id}/labels", user), - params: { - name: label1.name, - color: '#FFAABB' - } + params: { + name: label1.name, + color: "#FFAABB", + } expect(response).to have_gitlab_http_status(409) - expect(json_response['message']).to eq('Label already exists') + expect(json_response["message"]).to eq("Label already exists") end end - describe 'DELETE /groups/:id/labels' do - it 'returns 204 for existing label' do - delete api("/groups/#{group.id}/labels", user), params: { name: label1.name } + describe "DELETE /groups/:id/labels" do + it "returns 204 for existing label" do + delete api("/groups/#{group.id}/labels", user), params: {name: label1.name} expect(response).to have_gitlab_http_status(204) end - it 'returns 404 for non existing label' do - delete api("/groups/#{group.id}/labels", user), params: { name: 'label2' } + it "returns 404 for non existing label" do + delete api("/groups/#{group.id}/labels", user), params: {name: "label2"} expect(response).to have_gitlab_http_status(404) - expect(json_response['message']).to eq('404 Label Not Found') + expect(json_response["message"]).to eq("404 Label Not Found") end - it 'returns 400 for wrong parameters' do + it "returns 400 for wrong parameters" do delete api("/groups/#{group.id}/labels", user) expect(response).to have_gitlab_http_status(400) @@ -96,113 +96,113 @@ describe API::GroupLabels do it "does not delete parent's group labels", :nested_groups do subgroup = create(:group, parent: group) - subgroup_label = create(:group_label, title: 'feature', group: subgroup) + subgroup_label = create(:group_label, title: "feature", group: subgroup) - delete api("/groups/#{subgroup.id}/labels", user), params: { name: subgroup_label.name } + delete api("/groups/#{subgroup.id}/labels", user), params: {name: subgroup_label.name} expect(response).to have_gitlab_http_status(204) expect(subgroup.labels.size).to eq(0) expect(group.labels).to include(label1) end - it_behaves_like '412 response' do + it_behaves_like "412 response" do let(:request) { api("/groups/#{group.id}/labels", user) } - let(:params) { { name: label1.name } } + let(:params) { {name: label1.name} } end end - describe 'PUT /groups/:id/labels' do - it 'returns 200 if name and colors and description are changed' do + describe "PUT /groups/:id/labels" do + it "returns 200 if name and colors and description are changed" do put api("/groups/#{group.id}/labels", user), - params: { - name: label1.name, - new_name: 'New Label', - color: '#FFFFFF', - description: 'test' - } + params: { + name: label1.name, + new_name: "New Label", + color: "#FFFFFF", + description: "test", + } expect(response).to have_gitlab_http_status(200) - expect(json_response['name']).to eq('New Label') - expect(json_response['color']).to eq('#FFFFFF') - expect(json_response['description']).to eq('test') + expect(json_response["name"]).to eq("New Label") + expect(json_response["color"]).to eq("#FFFFFF") + expect(json_response["description"]).to eq("test") end it "does not update parent's group label", :nested_groups do subgroup = create(:group, parent: group) - subgroup_label = create(:group_label, title: 'feature', group: subgroup) + subgroup_label = create(:group_label, title: "feature", group: subgroup) put api("/groups/#{subgroup.id}/labels", user), - params: { - name: subgroup_label.name, - new_name: 'New Label' - } + params: { + name: subgroup_label.name, + new_name: "New Label", + } expect(response).to have_gitlab_http_status(200) - expect(subgroup.labels[0].name).to eq('New Label') - expect(label1.name).to eq('feature') + expect(subgroup.labels[0].name).to eq("New Label") + expect(label1.name).to eq("feature") end - it 'returns 404 if label does not exist' do + it "returns 404 if label does not exist" do put api("/groups/#{group.id}/labels", user), - params: { - name: 'label2', - new_name: 'label3' - } + params: { + name: "label2", + new_name: "label3", + } expect(response).to have_gitlab_http_status(404) end - it 'returns 400 if no label name given' do - put api("/groups/#{group.id}/labels", user), params: { new_name: label1.name } + it "returns 400 if no label name given" do + put api("/groups/#{group.id}/labels", user), params: {new_name: label1.name} expect(response).to have_gitlab_http_status(400) - expect(json_response['error']).to eq('name is missing') + expect(json_response["error"]).to eq("name is missing") end - it 'returns 400 if no new parameters given' do - put api("/groups/#{group.id}/labels", user), params: { name: label1.name } + it "returns 400 if no new parameters given" do + put api("/groups/#{group.id}/labels", user), params: {name: label1.name} expect(response).to have_gitlab_http_status(400) - expect(json_response['error']).to eq('new_name, color, description are missing, '\ - 'at least one parameter must be provided') + expect(json_response["error"]).to eq("new_name, color, description are missing, "\ + "at least one parameter must be provided") end end - describe 'POST /groups/:id/labels/:label_id/subscribe' do - context 'when label_id is a label title' do - it 'subscribes to the label' do + describe "POST /groups/:id/labels/:label_id/subscribe" do + context "when label_id is a label title" do + it "subscribes to the label" do post api("/groups/#{group.id}/labels/#{label1.title}/subscribe", user) expect(response).to have_gitlab_http_status(201) - expect(json_response['name']).to eq(label1.title) - expect(json_response['subscribed']).to be_truthy + expect(json_response["name"]).to eq(label1.title) + expect(json_response["subscribed"]).to be_truthy end end - context 'when label_id is a label ID' do - it 'subscribes to the label' do + context "when label_id is a label ID" do + it "subscribes to the label" do post api("/groups/#{group.id}/labels/#{label1.id}/subscribe", user) expect(response).to have_gitlab_http_status(201) - expect(json_response['name']).to eq(label1.title) - expect(json_response['subscribed']).to be_truthy + expect(json_response["name"]).to eq(label1.title) + expect(json_response["subscribed"]).to be_truthy end end - context 'when user is already subscribed to label' do + context "when user is already subscribed to label" do before do label1.subscribe(user) end - it 'returns 304' do + it "returns 304" do post api("/groups/#{group.id}/labels/#{label1.id}/subscribe", user) expect(response).to have_gitlab_http_status(304) end end - context 'when label ID is not found' do - it 'returns 404 error' do + context "when label ID is not found" do + it "returns 404 error" do post api("/groups/#{group.id}/labels/1234/subscribe", user) expect(response).to have_gitlab_http_status(404) @@ -210,45 +210,45 @@ describe API::GroupLabels do end end - describe 'POST /groups/:id/labels/:label_id/unsubscribe' do + describe "POST /groups/:id/labels/:label_id/unsubscribe" do before do label1.subscribe(user) end - context 'when label_id is a label title' do - it 'unsubscribes from the label' do + context "when label_id is a label title" do + it "unsubscribes from the label" do post api("/groups/#{group.id}/labels/#{label1.title}/unsubscribe", user) expect(response).to have_gitlab_http_status(201) - expect(json_response['name']).to eq(label1.title) - expect(json_response['subscribed']).to be_falsey + expect(json_response["name"]).to eq(label1.title) + expect(json_response["subscribed"]).to be_falsey end end - context 'when label_id is a label ID' do - it 'unsubscribes from the label' do + context "when label_id is a label ID" do + it "unsubscribes from the label" do post api("/groups/#{group.id}/labels/#{label1.id}/unsubscribe", user) expect(response).to have_gitlab_http_status(201) - expect(json_response['name']).to eq(label1.title) - expect(json_response['subscribed']).to be_falsey + expect(json_response["name"]).to eq(label1.title) + expect(json_response["subscribed"]).to be_falsey end end - context 'when user is already unsubscribed from label' do + context "when user is already unsubscribed from label" do before do label1.unsubscribe(user) end - it 'returns 304' do + it "returns 304" do post api("/groups/#{group.id}/labels/#{label1.id}/unsubscribe", user) expect(response).to have_gitlab_http_status(304) end end - context 'when label ID is not found' do - it 'returns 404 error' do + context "when label ID is not found" do + it "returns 404 error" do post api("/groups/#{group.id}/labels/1234/unsubscribe", user) expect(response).to have_gitlab_http_status(404) diff --git a/spec/requests/api/group_milestones_spec.rb b/spec/requests/api/group_milestones_spec.rb index 6980eb7f55d..329679bf51b 100644 --- a/spec/requests/api/group_milestones_spec.rb +++ b/spec/requests/api/group_milestones_spec.rb @@ -1,14 +1,14 @@ -require 'spec_helper' +require "spec_helper" describe API::GroupMilestones do let(:user) { create(:user) } let(:group) { create(:group, :private) } let(:project) { create(:project, namespace: group) } let!(:group_member) { create(:group_member, group: group, user: user) } - let!(:closed_milestone) { create(:closed_milestone, group: group, title: 'version1', description: 'closed milestone') } - let!(:milestone) { create(:milestone, group: group, title: 'version2', description: 'open milestone') } + let!(:closed_milestone) { create(:closed_milestone, group: group, title: "version1", description: "closed milestone") } + let!(:milestone) { create(:milestone, group: group, title: "version2", description: "open milestone") } - it_behaves_like 'group and project milestones', "/groups/:id/milestones" do + it_behaves_like "group and project milestones", "/groups/:id/milestones" do let(:route) { "/groups/#{group.id}/milestones" } end diff --git a/spec/requests/api/group_variables_spec.rb b/spec/requests/api/group_variables_spec.rb index 66b9aae4b58..19c9cb5bb59 100644 --- a/spec/requests/api/group_variables_spec.rb +++ b/spec/requests/api/group_variables_spec.rb @@ -1,18 +1,18 @@ -require 'spec_helper' +require "spec_helper" describe API::GroupVariables do let(:group) { create(:group) } let(:user) { create(:user) } - describe 'GET /groups/:id/variables' do + describe "GET /groups/:id/variables" do let!(:variable) { create(:ci_group_variable, group: group) } - context 'authorized user with proper permissions' do + context "authorized user with proper permissions" do before do group.add_maintainer(user) end - it 'returns group variables' do + it "returns group variables" do get api("/groups/#{group.id}/variables", user) expect(response).to have_gitlab_http_status(200) @@ -20,16 +20,16 @@ describe API::GroupVariables do end end - context 'authorized user with invalid permissions' do - it 'does not return group variables' do + context "authorized user with invalid permissions" do + it "does not return group variables" do get api("/groups/#{group.id}/variables", user) expect(response).to have_gitlab_http_status(403) end end - context 'unauthorized user' do - it 'does not return group variables' do + context "unauthorized user" do + it "does not return group variables" do get api("/groups/#{group.id}/variables") expect(response).to have_gitlab_http_status(401) @@ -37,39 +37,39 @@ describe API::GroupVariables do end end - describe 'GET /groups/:id/variables/:key' do + describe "GET /groups/:id/variables/:key" do let!(:variable) { create(:ci_group_variable, group: group) } - context 'authorized user with proper permissions' do + context "authorized user with proper permissions" do before do group.add_maintainer(user) end - it 'returns group variable details' do + it "returns group variable details" do get api("/groups/#{group.id}/variables/#{variable.key}", user) expect(response).to have_gitlab_http_status(200) - expect(json_response['value']).to eq(variable.value) - expect(json_response['protected']).to eq(variable.protected?) + expect(json_response["value"]).to eq(variable.value) + expect(json_response["protected"]).to eq(variable.protected?) end - it 'responds with 404 Not Found if requesting non-existing variable' do + it "responds with 404 Not Found if requesting non-existing variable" do get api("/groups/#{group.id}/variables/non_existing_variable", user) expect(response).to have_gitlab_http_status(404) end end - context 'authorized user with invalid permissions' do - it 'does not return group variable details' do + context "authorized user with invalid permissions" do + it "does not return group variable details" do get api("/groups/#{group.id}/variables/#{variable.key}", user) expect(response).to have_gitlab_http_status(403) end end - context 'unauthorized user' do - it 'does not return group variable details' do + context "unauthorized user" do + it "does not return group variable details" do get api("/groups/#{group.id}/variables/#{variable.key}") expect(response).to have_gitlab_http_status(401) @@ -77,55 +77,55 @@ describe API::GroupVariables do end end - describe 'POST /groups/:id/variables' do - context 'authorized user with proper permissions' do + describe "POST /groups/:id/variables" do + context "authorized user with proper permissions" do let!(:variable) { create(:ci_group_variable, group: group) } before do group.add_maintainer(user) end - it 'creates variable' do - expect do - post api("/groups/#{group.id}/variables", user), params: { key: 'TEST_VARIABLE_2', value: 'PROTECTED_VALUE_2', protected: true } - end.to change {group.variables.count}.by(1) + it "creates variable" do + expect { + post api("/groups/#{group.id}/variables", user), params: {key: "TEST_VARIABLE_2", value: "PROTECTED_VALUE_2", protected: true} + }.to change {group.variables.count}.by(1) expect(response).to have_gitlab_http_status(201) - expect(json_response['key']).to eq('TEST_VARIABLE_2') - expect(json_response['value']).to eq('PROTECTED_VALUE_2') - expect(json_response['protected']).to be_truthy + expect(json_response["key"]).to eq("TEST_VARIABLE_2") + expect(json_response["value"]).to eq("PROTECTED_VALUE_2") + expect(json_response["protected"]).to be_truthy end - it 'creates variable with optional attributes' do - expect do - post api("/groups/#{group.id}/variables", user), params: { key: 'TEST_VARIABLE_2', value: 'VALUE_2' } - end.to change {group.variables.count}.by(1) + it "creates variable with optional attributes" do + expect { + post api("/groups/#{group.id}/variables", user), params: {key: "TEST_VARIABLE_2", value: "VALUE_2"} + }.to change {group.variables.count}.by(1) expect(response).to have_gitlab_http_status(201) - expect(json_response['key']).to eq('TEST_VARIABLE_2') - expect(json_response['value']).to eq('VALUE_2') - expect(json_response['protected']).to be_falsey + expect(json_response["key"]).to eq("TEST_VARIABLE_2") + expect(json_response["value"]).to eq("VALUE_2") + expect(json_response["protected"]).to be_falsey end - it 'does not allow to duplicate variable key' do - expect do - post api("/groups/#{group.id}/variables", user), params: { key: variable.key, value: 'VALUE_2' } - end.to change {group.variables.count}.by(0) + it "does not allow to duplicate variable key" do + expect { + post api("/groups/#{group.id}/variables", user), params: {key: variable.key, value: "VALUE_2"} + }.to change {group.variables.count}.by(0) expect(response).to have_gitlab_http_status(400) end end - context 'authorized user with invalid permissions' do - it 'does not create variable' do + context "authorized user with invalid permissions" do + it "does not create variable" do post api("/groups/#{group.id}/variables", user) expect(response).to have_gitlab_http_status(403) end end - context 'unauthorized user' do - it 'does not create variable' do + context "unauthorized user" do + it "does not create variable" do post api("/groups/#{group.id}/variables") expect(response).to have_gitlab_http_status(401) @@ -133,45 +133,45 @@ describe API::GroupVariables do end end - describe 'PUT /groups/:id/variables/:key' do + describe "PUT /groups/:id/variables/:key" do let!(:variable) { create(:ci_group_variable, group: group) } - context 'authorized user with proper permissions' do + context "authorized user with proper permissions" do before do group.add_maintainer(user) end - it 'updates variable data' do + it "updates variable data" do initial_variable = group.variables.reload.first value_before = initial_variable.value - put api("/groups/#{group.id}/variables/#{variable.key}", user), params: { value: 'VALUE_1_UP', protected: true } + put api("/groups/#{group.id}/variables/#{variable.key}", user), params: {value: "VALUE_1_UP", protected: true} updated_variable = group.variables.reload.first expect(response).to have_gitlab_http_status(200) 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") expect(updated_variable).to be_protected end - it 'responds with 404 Not Found if requesting non-existing variable' do + it "responds with 404 Not Found if requesting non-existing variable" do put api("/groups/#{group.id}/variables/non_existing_variable", user) expect(response).to have_gitlab_http_status(404) end end - context 'authorized user with invalid permissions' do - it 'does not update variable' do + context "authorized user with invalid permissions" do + it "does not update variable" do put api("/groups/#{group.id}/variables/#{variable.key}", user) expect(response).to have_gitlab_http_status(403) end end - context 'unauthorized user' do - it 'does not update variable' do + context "unauthorized user" do + it "does not update variable" do put api("/groups/#{group.id}/variables/#{variable.key}") expect(response).to have_gitlab_http_status(401) @@ -179,43 +179,43 @@ describe API::GroupVariables do end end - describe 'DELETE /groups/:id/variables/:key' do + describe "DELETE /groups/:id/variables/:key" do let!(:variable) { create(:ci_group_variable, group: group) } - context 'authorized user with proper permissions' do + context "authorized user with proper permissions" do before do group.add_maintainer(user) end - it 'deletes variable' do - expect do + it "deletes variable" do + expect { delete api("/groups/#{group.id}/variables/#{variable.key}", user) expect(response).to have_gitlab_http_status(204) - end.to change {group.variables.count}.by(-1) + }.to change {group.variables.count}.by(-1) end - it 'responds with 404 Not Found if requesting non-existing variable' do + it "responds with 404 Not Found if requesting non-existing variable" do delete api("/groups/#{group.id}/variables/non_existing_variable", user) expect(response).to have_gitlab_http_status(404) end - it_behaves_like '412 response' do + it_behaves_like "412 response" do let(:request) { api("/groups/#{group.id}/variables/#{variable.key}", user) } end end - context 'authorized user with invalid permissions' do - it 'does not delete variable' do + context "authorized user with invalid permissions" do + it "does not delete variable" do delete api("/groups/#{group.id}/variables/#{variable.key}", user) expect(response).to have_gitlab_http_status(403) end end - context 'unauthorized user' do - it 'does not delete variable' do + context "unauthorized user" do + it "does not delete variable" do delete api("/groups/#{group.id}/variables/#{variable.key}") expect(response).to have_gitlab_http_status(401) diff --git a/spec/requests/api/groups_spec.rb b/spec/requests/api/groups_spec.rb index 7176bc23e34..aa2aa59688b 100644 --- a/spec/requests/api/groups_spec.rb +++ b/spec/requests/api/groups_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe API::Groups do include UploadHelpers @@ -11,7 +11,7 @@ describe API::Groups do let!(:group2) { create(:group, :private) } let!(:project1) { create(:project, namespace: group1) } let!(:project2) { create(:project, namespace: group2) } - let!(:project3) { create(:project, namespace: group1, path: 'test', visibility_level: Gitlab::VisibilityLevel::PRIVATE) } + let!(:project3) { create(:project, namespace: group1, path: "test", visibility_level: Gitlab::VisibilityLevel::PRIVATE) } before do group1.add_owner(user1) @@ -28,22 +28,22 @@ describe API::Groups do expect(json_response).to be_an Array expect(json_response.length).to eq(1) expect(json_response) - .to satisfy_one { |group| group['name'] == group1.name } + .to satisfy_one { |group| group["name"] == group1.name } end - it 'avoids N+1 queries' do + it "avoids N+1 queries" do # Establish baseline get api("/groups", admin) - control = ActiveRecord::QueryRecorder.new do + control = ActiveRecord::QueryRecorder.new { get api("/groups", admin) - end + } create(:group) - expect do + expect { get api("/groups", admin) - end.not_to exceed_query_limit(control) + }.not_to exceed_query_limit(control) end end @@ -56,16 +56,16 @@ describe API::Groups do expect(json_response).to be_an Array expect(json_response.length).to eq(1) expect(json_response) - .to satisfy_one { |group| group['name'] == group1.name } + .to satisfy_one { |group| group["name"] == group1.name } end it "does not include statistics" do - get api("/groups", user1), params: { statistics: true } + get api("/groups", user1), params: {statistics: true} expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response).to be_an Array - expect(json_response.first).not_to include 'statistics' + expect(json_response.first).not_to include "statistics" end end @@ -85,7 +85,7 @@ describe API::Groups do expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response).to be_an Array - expect(json_response.first).not_to include('statistics') + expect(json_response.first).not_to include("statistics") end it "includes statistics if requested" do @@ -93,26 +93,26 @@ describe API::Groups do storage_size: 702, repository_size: 123, lfs_objects_size: 234, - build_artifacts_size: 345 + build_artifacts_size: 345, }.stringify_keys exposed_attributes = attributes.dup - exposed_attributes['job_artifacts_size'] = exposed_attributes.delete('build_artifacts_size') + exposed_attributes["job_artifacts_size"] = exposed_attributes.delete("build_artifacts_size") project1.statistics.update!(attributes) - get api("/groups", admin), params: { statistics: true } + get api("/groups", admin), params: {statistics: true} expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response).to be_an Array expect(json_response) - .to satisfy_one { |group| group['statistics'] == exposed_attributes } + .to satisfy_one { |group| group["statistics"] == exposed_attributes } end end context "when using skip_groups in request" do it "returns all groups excluding skipped groups" do - get api("/groups", admin), params: { skip_groups: [group2.id] } + get api("/groups", admin), params: {skip_groups: [group2.id]} expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers @@ -122,12 +122,12 @@ describe API::Groups do end context "when using all_available in request" do - let(:response_groups) { json_response.map { |group| group['name'] } } + let(:response_groups) { json_response.map { |group| group["name"] } } it "returns all groups you have access to" do public_group = create :group, :public - get api("/groups", user1), params: { all_available: true } + get api("/groups", user1), params: {all_available: true} expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers @@ -140,8 +140,8 @@ describe API::Groups do let(:group3) { create(:group, name: "a#{group1.name}", path: "z#{group1.path}") } let(:group4) { create(:group, name: "same-name", path: "y#{group1.path}") } let(:group5) { create(:group, name: "same-name") } - let(:response_groups) { json_response.map { |group| group['name'] } } - let(:response_groups_ids) { json_response.map { |group| group['id'] } } + let(:response_groups) { json_response.map { |group| group["name"] } } + let(:response_groups_ids) { json_response.map { |group| group["id"] } } before do group3.add_owner(user1) @@ -159,7 +159,7 @@ describe API::Groups do end it "sorts in descending order when passed" do - get api("/groups", user1), params: { sort: "desc" } + get api("/groups", user1), params: {sort: "desc"} expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers @@ -168,7 +168,7 @@ describe API::Groups do end it "sorts by path in order_by param" do - get api("/groups", user1), params: { order_by: "path" } + get api("/groups", user1), params: {order_by: "path"} expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers @@ -177,7 +177,7 @@ describe API::Groups do end it "sorts by id in the order_by param" do - get api("/groups", user1), params: { order_by: "id" } + get api("/groups", user1), params: {order_by: "id"} expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers @@ -186,7 +186,7 @@ describe API::Groups do end it "sorts also by descending id with pagination fix" do - get api("/groups", user1), params: { order_by: "id", sort: "desc" } + get api("/groups", user1), params: {order_by: "id", sort: "desc"} expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers @@ -195,21 +195,21 @@ describe API::Groups do end it "sorts identical keys by id for good pagination" do - get api("/groups", user1), params: { search: "same-name", order_by: "name" } + get api("/groups", user1), params: {search: "same-name", order_by: "name"} expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response).to be_an Array - expect(response_groups_ids).to eq(Group.select { |group| group['name'] == 'same-name' }.map { |group| group['id'] }.sort) + expect(response_groups_ids).to eq(Group.select { |group| group["name"] == "same-name" }.map { |group| group["id"] }.sort) end it "sorts descending identical keys by id for good pagination" do - get api("/groups", user1), params: { search: "same-name", order_by: "name", sort: "desc" } + get api("/groups", user1), params: {search: "same-name", order_by: "name", sort: "desc"} expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response).to be_an Array - expect(response_groups_ids).to eq(Group.select { |group| group['name'] == 'same-name' }.map { |group| group['id'] }.sort) + expect(response_groups_ids).to eq(Group.select { |group| group["name"] == "same-name" }.map { |group| group["id"] }.sort) end def groups_visible_to_user(user) @@ -217,31 +217,31 @@ describe API::Groups do end end - context 'when using owned in the request' do - it 'returns an array of groups the user owns' do + context "when using owned in the request" do + it "returns an array of groups the user owns" do group1.add_maintainer(user2) - get api('/groups', user2), params: { owned: true } + get api("/groups", user2), params: {owned: true} expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response).to be_an Array expect(json_response.length).to eq(1) - expect(json_response.first['name']).to eq(group2.name) + expect(json_response.first["name"]).to eq(group2.name) end end - context 'when using min_access_level in the request' do + context "when using min_access_level in the request" do let!(:group3) { create(:group, :private) } - let(:response_groups) { json_response.map { |group| group['id'] } } + let(:response_groups) { json_response.map { |group| group["id"] } } before do group1.add_developer(user2) group3.add_master(user2) end - it 'returns an array of groups the user has at least master access' do - get api('/groups', user2), params: { min_access_level: 40 } + it "returns an array of groups the user has at least master access" do + get api("/groups", user2), params: {min_access_level: 40} expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers @@ -260,9 +260,9 @@ describe API::Groups do # Returns a Hash of visibility_level => Project pairs def add_projects_to_group(group, share_with: nil) projects = { - public: create(:project, :public, namespace: group), + public: create(:project, :public, namespace: group), internal: create(:project, :internal, namespace: group), - private: create(:project, :private, namespace: group) + private: create(:project, :private, namespace: group), } if share_with @@ -276,79 +276,79 @@ describe API::Groups do def response_project_ids(json_response, key) json_response[key].map do |project| - project['id'].to_i + project["id"].to_i end end - context 'when unauthenticated' do - it 'returns 404 for a private group' do + context "when unauthenticated" do + it "returns 404 for a private group" do get api("/groups/#{group2.id}") expect(response).to have_gitlab_http_status(404) end - it 'returns 200 for a public group' do + it "returns 200 for a public group" do get api("/groups/#{group1.id}") expect(response).to have_gitlab_http_status(200) end - it 'returns only public projects in the group' do + it "returns only public projects in the group" do public_group = create(:group, :public) projects = add_projects_to_group(public_group) get api("/groups/#{public_group.id}") - expect(response_project_ids(json_response, 'projects')) + expect(response_project_ids(json_response, "projects")) .to contain_exactly(projects[:public].id) end - it 'returns only public projects shared with the group' do + it "returns only public projects shared with the group" do public_group = create(:group, :public) projects = add_projects_to_group(public_group, share_with: group1) get api("/groups/#{group1.id}") - expect(response_project_ids(json_response, 'shared_projects')) + expect(response_project_ids(json_response, "shared_projects")) .to contain_exactly(projects[:public].id) end end context "when authenticated as user" do it "returns one of user1's groups" do - project = create(:project, namespace: group2, path: 'Foo') + project = create(:project, namespace: group2, path: "Foo") create(:project_group_link, project: project, group: group1) get api("/groups/#{group1.id}", user1) expect(response).to have_gitlab_http_status(200) - expect(json_response['id']).to eq(group1.id) - expect(json_response['name']).to eq(group1.name) - expect(json_response['path']).to eq(group1.path) - expect(json_response['description']).to eq(group1.description) - expect(json_response['visibility']).to eq(Gitlab::VisibilityLevel.string_level(group1.visibility_level)) - expect(json_response['avatar_url']).to eq(group1.avatar_url(only_path: false)) - expect(json_response['web_url']).to eq(group1.web_url) - expect(json_response['request_access_enabled']).to eq(group1.request_access_enabled) - expect(json_response['full_name']).to eq(group1.full_name) - expect(json_response['full_path']).to eq(group1.full_path) - expect(json_response['parent_id']).to eq(group1.parent_id) - expect(json_response['projects']).to be_an Array - expect(json_response['projects'].length).to eq(2) - expect(json_response['shared_projects']).to be_an Array - expect(json_response['shared_projects'].length).to eq(1) - expect(json_response['shared_projects'][0]['id']).to eq(project.id) + expect(json_response["id"]).to eq(group1.id) + expect(json_response["name"]).to eq(group1.name) + expect(json_response["path"]).to eq(group1.path) + expect(json_response["description"]).to eq(group1.description) + expect(json_response["visibility"]).to eq(Gitlab::VisibilityLevel.string_level(group1.visibility_level)) + expect(json_response["avatar_url"]).to eq(group1.avatar_url(only_path: false)) + expect(json_response["web_url"]).to eq(group1.web_url) + expect(json_response["request_access_enabled"]).to eq(group1.request_access_enabled) + expect(json_response["full_name"]).to eq(group1.full_name) + expect(json_response["full_path"]).to eq(group1.full_path) + expect(json_response["parent_id"]).to eq(group1.parent_id) + expect(json_response["projects"]).to be_an Array + expect(json_response["projects"].length).to eq(2) + expect(json_response["shared_projects"]).to be_an Array + expect(json_response["shared_projects"].length).to eq(1) + expect(json_response["shared_projects"][0]["id"]).to eq(project.id) end it "returns one of user1's groups without projects when with_projects option is set to false" do - project = create(:project, namespace: group2, path: 'Foo') + project = create(:project, namespace: group2, path: "Foo") create(:project_group_link, project: project, group: group1) - get api("/groups/#{group1.id}", user1), params: { with_projects: false } + get api("/groups/#{group1.id}", user1), params: {with_projects: false} expect(response).to have_gitlab_http_status(200) - expect(json_response['projects']).to be_nil - expect(json_response['shared_projects']).to be_nil + expect(json_response["projects"]).to be_nil + expect(json_response["shared_projects"]).to be_nil end it "does not return a non existing group" do @@ -363,38 +363,38 @@ describe API::Groups do expect(response).to have_gitlab_http_status(404) end - it 'returns only public and internal projects in the group' do + it "returns only public and internal projects in the group" do public_group = create(:group, :public) projects = add_projects_to_group(public_group) get api("/groups/#{public_group.id}", user2) - expect(response_project_ids(json_response, 'projects')) + expect(response_project_ids(json_response, "projects")) .to contain_exactly(projects[:public].id, projects[:internal].id) end - it 'returns only public and internal projects shared with the group' do + it "returns only public and internal projects shared with the group" do public_group = create(:group, :public) projects = add_projects_to_group(public_group, share_with: group1) get api("/groups/#{group1.id}", user2) - expect(response_project_ids(json_response, 'shared_projects')) + expect(response_project_ids(json_response, "shared_projects")) .to contain_exactly(projects[:public].id, projects[:internal].id) end - it 'avoids N+1 queries' do + it "avoids N+1 queries" do get api("/groups/#{group1.id}", admin) - control_count = ActiveRecord::QueryRecorder.new do + control_count = ActiveRecord::QueryRecorder.new { get api("/groups/#{group1.id}", admin) - end.count + }.count create(:project, namespace: group1) - expect do + expect { get api("/groups/#{group1.id}", admin) - end.not_to exceed_query_limit(control_count) + }.not_to exceed_query_limit(control_count) end end @@ -403,7 +403,7 @@ describe API::Groups do get api("/groups/#{group2.id}", admin) expect(response).to have_gitlab_http_status(200) - expect(json_response['name']).to eq(group2.name) + expect(json_response["name"]).to eq(group2.name) end it "does not return a non existing group" do @@ -413,21 +413,21 @@ describe API::Groups do end end - context 'when using group path in URL' do - it 'returns any existing group' do + context "when using group path in URL" do + it "returns any existing group" do get api("/groups/#{group1.path}", admin) expect(response).to have_gitlab_http_status(200) - expect(json_response['name']).to eq(group1.name) + expect(json_response["name"]).to eq(group1.name) end - it 'does not return a non existing group' do - get api('/groups/unknown', admin) + it "does not return a non existing group" do + get api("/groups/unknown", admin) expect(response).to have_gitlab_http_status(404) end - it 'does not return a group not attached to user1' do + it "does not return a group not attached to user1" do get api("/groups/#{group2.path}", user1) expect(response).to have_gitlab_http_status(404) @@ -435,45 +435,45 @@ describe API::Groups do end end - describe 'PUT /groups/:id' do - let(:new_group_name) { 'New Group'} + describe "PUT /groups/:id" do + let(:new_group_name) { "New Group"} - context 'when authenticated as the group owner' do - it 'updates the group' do - put api("/groups/#{group1.id}", user1), params: { name: new_group_name, request_access_enabled: true } + context "when authenticated as the group owner" do + it "updates the group" do + put api("/groups/#{group1.id}", user1), params: {name: new_group_name, request_access_enabled: true} expect(response).to have_gitlab_http_status(200) - expect(json_response['name']).to eq(new_group_name) - expect(json_response['request_access_enabled']).to eq(true) + expect(json_response["name"]).to eq(new_group_name) + expect(json_response["request_access_enabled"]).to eq(true) end - it 'returns 404 for a non existing group' do - put api('/groups/1328', user1), params: { name: new_group_name } + it "returns 404 for a non existing group" do + put api("/groups/1328", user1), params: {name: new_group_name} expect(response).to have_gitlab_http_status(404) end end - context 'when authenticated as the admin' do - it 'updates the group' do - put api("/groups/#{group1.id}", admin), params: { name: new_group_name } + context "when authenticated as the admin" do + it "updates the group" do + put api("/groups/#{group1.id}", admin), params: {name: new_group_name} expect(response).to have_gitlab_http_status(200) - expect(json_response['name']).to eq(new_group_name) + expect(json_response["name"]).to eq(new_group_name) end end - context 'when authenticated as an user that can see the group' do - it 'does not updates the group' do - put api("/groups/#{group1.id}", user2), params: { name: new_group_name } + context "when authenticated as an user that can see the group" do + it "does not updates the group" do + put api("/groups/#{group1.id}", user2), params: {name: new_group_name} expect(response).to have_gitlab_http_status(403) end end - context 'when authenticated as an user that cannot see the group' do - it 'returns 404 when trying to update the group' do - put api("/groups/#{group2.id}", user1), params: { name: new_group_name } + context "when authenticated as an user that cannot see the group" do + it "returns 404 when trying to update the group" do + put api("/groups/#{group2.id}", user1), params: {name: new_group_name} expect(response).to have_gitlab_http_status(404) end @@ -488,32 +488,32 @@ describe API::Groups do expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers 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(json_response.first['visibility']).to be_present + expect(json_response.first["visibility"]).to be_present end it "returns the group's projects with simple representation" do - get api("/groups/#{group1.id}/projects", user1), params: { simple: true } + get api("/groups/#{group1.id}/projects", user1), params: {simple: true} expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers 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(json_response.first['visibility']).not_to be_present + expect(json_response.first["visibility"]).not_to be_present end it "filters the groups projects" do - public_project = create(:project, :public, path: 'test1', group: group1) + public_project = create(:project, :public, path: "test1", group: group1) - get api("/groups/#{group1.id}/projects", user1), params: { visibility: 'public' } + get api("/groups/#{group1.id}/projects", user1), params: {visibility: "public"} expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response).to be_an(Array) expect(json_response.length).to eq(1) - expect(json_response.first['name']).to eq(public_project.name) + expect(json_response.first["name"]).to eq(public_project.name) end it "returns projects excluding shared" do @@ -521,7 +521,7 @@ describe API::Groups do create(:project_group_link, project: create(:project), group: group1) create(:project_group_link, project: create(:project), group: group1) - get api("/groups/#{group1.id}/projects", user1), params: { with_shared: false } + get api("/groups/#{group1.id}/projects", user1), params: {with_shared: false} expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers @@ -534,7 +534,7 @@ describe API::Groups do create(:project, group: subgroup) create(:project, group: subgroup) - get api("/groups/#{group1.id}/projects", user1), params: { include_subgroups: true } + get api("/groups/#{group1.id}/projects", user1), params: {include_subgroups: true} expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers @@ -562,27 +562,27 @@ describe API::Groups do expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers 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 - it 'only returns the projects owned by user' do + it "only returns the projects owned by user" do project2.group.add_owner(user3) - get api("/groups/#{project2.group.id}/projects", user3), params: { owned: true } + get api("/groups/#{project2.group.id}/projects", user3), params: {owned: true} expect(response).to have_gitlab_http_status(200) 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 - it 'only returns the projects starred by user' do + it "only returns the projects starred by user" do user1.starred_projects = [project1] - get api("/groups/#{group1.id}/projects", user1), params: { starred: true } + get api("/groups/#{group1.id}/projects", user1), params: {starred: true} expect(response).to have_gitlab_http_status(200) expect(json_response.length).to eq(1) - expect(json_response.first['name']).to eq(project1.name) + expect(json_response.first["name"]).to eq(project1.name) end end @@ -593,7 +593,7 @@ describe API::Groups do expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers 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 it "does not return a non existing group" do @@ -602,38 +602,38 @@ describe API::Groups do expect(response).to have_gitlab_http_status(404) end - it 'avoids N+1 queries' do + it "avoids N+1 queries" do get api("/groups/#{group1.id}/projects", admin) - control_count = ActiveRecord::QueryRecorder.new do + control_count = ActiveRecord::QueryRecorder.new { get api("/groups/#{group1.id}/projects", admin) - end.count + }.count create(:project, namespace: group1) - expect do + expect { get api("/groups/#{group1.id}/projects", admin) - end.not_to exceed_query_limit(control_count) + }.not_to exceed_query_limit(control_count) end end - context 'when using group path in URL' do - it 'returns any existing group' do + context "when using group path in URL" do + it "returns any existing group" do get api("/groups/#{group1.path}/projects", admin) expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers - 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]) end - it 'does not return a non existing group' do - get api('/groups/unknown/projects', admin) + it "does not return a non existing group" do + get api("/groups/unknown/projects", admin) expect(response).to have_gitlab_http_status(404) end - it 'does not return a group not attached to user1' do + it "does not return a group not attached to user1" do get api("/groups/#{group2.path}/projects", user1) expect(response).to have_gitlab_http_status(404) @@ -641,33 +641,33 @@ describe API::Groups do end end - describe 'GET /groups/:id/subgroups', :nested_groups do + describe "GET /groups/:id/subgroups", :nested_groups do let!(:subgroup1) { create(:group, parent: group1) } let!(:subgroup2) { create(:group, :private, parent: group1) } let!(:subgroup3) { create(:group, :private, parent: group2) } - context 'when unauthenticated' do - it 'returns only public subgroups' do + context "when unauthenticated" do + it "returns only public subgroups" do get api("/groups/#{group1.id}/subgroups") expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response).to be_an Array expect(json_response.length).to eq(1) - expect(json_response.first['id']).to eq(subgroup1.id) - expect(json_response.first['parent_id']).to eq(group1.id) + expect(json_response.first["id"]).to eq(subgroup1.id) + expect(json_response.first["parent_id"]).to eq(group1.id) end - it 'returns 404 for a private group' do + it "returns 404 for a private group" do get api("/groups/#{group2.id}/subgroups") expect(response).to have_gitlab_http_status(404) end end - context 'when authenticated as user' do - context 'when user is not member of a public group' do - it 'returns no subgroups for the public group' do + context "when authenticated as user" do + context "when user is not member of a public group" do + it "returns no subgroups for the public group" do get api("/groups/#{group1.id}/subgroups", user2) expect(response).to have_gitlab_http_status(200) @@ -675,75 +675,75 @@ describe API::Groups do expect(json_response.length).to eq(0) end - context 'when using all_available in request' do - it 'returns public subgroups' do - get api("/groups/#{group1.id}/subgroups", user2), params: { all_available: true } + context "when using all_available in request" do + it "returns public subgroups" do + get api("/groups/#{group1.id}/subgroups", user2), params: {all_available: true} expect(response).to have_gitlab_http_status(200) expect(json_response).to be_an Array expect(json_response.length).to eq(1) - expect(json_response[0]['id']).to eq(subgroup1.id) - expect(json_response[0]['parent_id']).to eq(group1.id) + expect(json_response[0]["id"]).to eq(subgroup1.id) + expect(json_response[0]["parent_id"]).to eq(group1.id) end end end - context 'when user is not member of a private group' do - it 'returns 404 for the private group' do + context "when user is not member of a private group" do + it "returns 404 for the private group" do get api("/groups/#{group2.id}/subgroups", user1) expect(response).to have_gitlab_http_status(404) end end - context 'when user is member of public group' do + context "when user is member of public group" do before do group1.add_guest(user2) end - it 'returns private subgroups' do + it "returns private subgroups" do get api("/groups/#{group1.id}/subgroups", user2) expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response).to be_an Array expect(json_response.length).to eq(2) - private_subgroups = json_response.select { |group| group['visibility'] == 'private' } + private_subgroups = json_response.select { |group| group["visibility"] == "private" } expect(private_subgroups.length).to eq(1) - expect(private_subgroups.first['id']).to eq(subgroup2.id) - expect(private_subgroups.first['parent_id']).to eq(group1.id) + expect(private_subgroups.first["id"]).to eq(subgroup2.id) + expect(private_subgroups.first["parent_id"]).to eq(group1.id) end - context 'when using statistics in request' do - it 'does not include statistics' do - get api("/groups/#{group1.id}/subgroups", user2), params: { statistics: true } + context "when using statistics in request" do + it "does not include statistics" do + get api("/groups/#{group1.id}/subgroups", user2), params: {statistics: true} expect(response).to have_gitlab_http_status(200) expect(json_response).to be_an Array - expect(json_response.first).not_to include 'statistics' + expect(json_response.first).not_to include "statistics" end end end - context 'when user is member of private group' do + context "when user is member of private group" do before do group2.add_guest(user1) end - it 'returns subgroups' do + it "returns subgroups" do get api("/groups/#{group2.id}/subgroups", user1) expect(response).to have_gitlab_http_status(200) expect(json_response).to be_an Array expect(json_response.length).to eq(1) - expect(json_response.first['id']).to eq(subgroup3.id) - expect(json_response.first['parent_id']).to eq(group2.id) + expect(json_response.first["id"]).to eq(subgroup3.id) + expect(json_response.first["parent_id"]).to eq(group2.id) end end end - context 'when authenticated as admin' do - it 'returns private subgroups of a public group' do + context "when authenticated as admin" do + it "returns private subgroups of a public group" do get api("/groups/#{group1.id}/subgroups", admin) expect(response).to have_gitlab_http_status(200) @@ -751,7 +751,7 @@ describe API::Groups do expect(json_response.length).to eq(2) end - it 'returns subgroups of a private group' do + it "returns subgroups of a private group" do get api("/groups/#{group2.id}/subgroups", admin) expect(response).to have_gitlab_http_status(200) @@ -759,20 +759,20 @@ describe API::Groups do expect(json_response.length).to eq(1) end - it 'does not include statistics by default' do + it "does not include statistics by default" do get api("/groups/#{group1.id}/subgroups", admin) expect(response).to have_gitlab_http_status(200) expect(json_response).to be_an Array - expect(json_response.first).not_to include('statistics') + expect(json_response.first).not_to include("statistics") end - it 'includes statistics if requested' do - get api("/groups/#{group1.id}/subgroups", admin), params: { statistics: true } + it "includes statistics if requested" do + get api("/groups/#{group1.id}/subgroups", admin), params: {statistics: true} expect(response).to have_gitlab_http_status(200) expect(json_response).to be_an Array - expect(json_response.first).to include('statistics') + expect(json_response.first).to include("statistics") end end end @@ -785,25 +785,25 @@ describe API::Groups do expect(response).to have_gitlab_http_status(403) end - context 'as owner', :nested_groups do + context "as owner", :nested_groups do before do group2.add_owner(user1) end - it 'can create subgroups' do - post api("/groups", user1), params: { parent_id: group2.id, name: 'foo', path: 'foo' } + it "can create subgroups" do + post api("/groups", user1), params: {parent_id: group2.id, name: "foo", path: "foo"} expect(response).to have_gitlab_http_status(201) end end - context 'as maintainer', :nested_groups do + context "as maintainer", :nested_groups do before do group2.add_maintainer(user1) end - it 'cannot create subgroups' do - post api("/groups", user1), params: { parent_id: group2.id, name: 'foo', path: 'foo' } + it "cannot create subgroups" do + post api("/groups", user1), params: {parent_id: group2.id, name: "foo", path: "foo"} expect(response).to have_gitlab_http_status(403) end @@ -812,7 +812,7 @@ describe API::Groups do context "when authenticated as user with group permissions" do it "creates group" do - group = attributes_for(:group, { request_access_enabled: false }) + group = attributes_for(:group, {request_access_enabled: false}) post api("/groups", user3), params: group @@ -827,7 +827,7 @@ describe API::Groups do it "creates a nested group", :nested_groups do parent = create(:group) parent.add_owner(user3) - group = attributes_for(:group, { parent_id: parent.id }) + group = attributes_for(:group, {parent_id: parent.id}) post api("/groups", user3), params: group @@ -838,20 +838,20 @@ describe API::Groups do end it "does not create group, duplicate" do - post api("/groups", user3), params: { name: 'Duplicate Test', path: group2.path } + post api("/groups", user3), params: {name: "Duplicate Test", path: group2.path} expect(response).to have_gitlab_http_status(400) expect(response.message).to eq("Bad Request") end it "returns 400 bad request error if name not given" do - post api("/groups", user3), params: { path: group2.path } + post api("/groups", user3), params: {path: group2.path} expect(response).to have_gitlab_http_status(400) end it "returns 400 bad request error if path not given" do - post api("/groups", user3), params: { name: 'test' } + post api("/groups", user3), params: {name: "test"} expect(response).to have_gitlab_http_status(400) end @@ -868,7 +868,7 @@ describe API::Groups do expect(response).to have_gitlab_http_status(202) end - it_behaves_like '412 response' do + it_behaves_like "412 response" do let(:request) { api("/groups/#{group1.id}", user1) } let(:success_status) { 202 } end @@ -934,8 +934,8 @@ describe API::Groups do expect(response).to have_gitlab_http_status(201) end - context 'when using project path in URL' do - context 'with a valid project path' do + context "when using project path in URL" do + context "with a valid project path" do it "transfers project to group" do post api("/groups/#{group1.id}/projects/#{project_path}", admin) @@ -943,7 +943,7 @@ describe API::Groups do end end - context 'with a non-existent project path' do + context "with a non-existent project path" do it "does not transfer project to group" do post api("/groups/#{group1.id}/projects/nogroup%2Fnoproject", admin) @@ -952,8 +952,8 @@ describe API::Groups do end end - context 'when using a group path in URL' do - context 'with a valid group path' do + context "when using a group path in URL" do + context "with a valid group path" do it "transfers project to group" do post api("/groups/#{group1.path}/projects/#{project_path}", admin) @@ -961,7 +961,7 @@ describe API::Groups do end end - context 'with a non-existent group path' do + context "with a non-existent group path" do it "does not transfer project to group" do post api("/groups/noexist/projects/#{project_path}", admin) @@ -972,7 +972,7 @@ describe API::Groups do end end - it_behaves_like 'custom attributes endpoints', 'groups' do + it_behaves_like "custom attributes endpoints", "groups" do let(:attributable) { group1 } let(:other_attributable) { group2 } let(:user) { user1 } diff --git a/spec/requests/api/helpers_spec.rb b/spec/requests/api/helpers_spec.rb index a0c64d295c0..0b2d29f98e6 100644 --- a/spec/requests/api/helpers_spec.rb +++ b/spec/requests/api/helpers_spec.rb @@ -1,6 +1,6 @@ -require 'spec_helper' -require 'raven/transports/dummy' -require_relative '../../../config/initializers/sentry' +require "spec_helper" +require "raven/transports/dummy" +require_relative "../../../config/initializers/sentry" describe API::Helpers do include API::APIGuard::HelperMethods @@ -14,12 +14,12 @@ describe API::Helpers do let(:csrf_token) { SecureRandom.base64(ActionController::RequestForgeryProtection::AUTHENTICITY_TOKEN_LENGTH) } let(:env) do { - 'rack.input' => '', - 'rack.session' => { - _csrf_token: csrf_token + "rack.input" => "", + "rack.session" => { + _csrf_token: csrf_token, }, - 'REQUEST_METHOD' => 'GET', - 'CONTENT_TYPE' => 'text/plain;charset=utf-8' + "REQUEST_METHOD" => "GET", + "CONTENT_TYPE" => "text/plain;charset=utf-8", } end let(:header) { } @@ -32,7 +32,7 @@ describe API::Helpers do def warden_authenticate_returns(value) warden = double("warden", authenticate: value) - env['warden'] = warden + env["warden"] = warden end def error!(message, status, header) @@ -50,7 +50,7 @@ describe API::Helpers do context "with invalid credentials" do context "GET request" do before do - env['REQUEST_METHOD'] = 'GET' + env["REQUEST_METHOD"] = "GET" end it { is_expected.to be_nil } @@ -64,21 +64,21 @@ describe API::Helpers do context "GET request" do before do - env['REQUEST_METHOD'] = 'GET' + env["REQUEST_METHOD"] = "GET" end it { is_expected.to eq(user) } - it 'sets the environment with data of the current user' do + it "sets the environment with data of the current user" do subject - expect(env[API::Helpers::API_USER_ENV]).to eq({ user_id: subject.id, username: subject.username }) + expect(env[API::Helpers::API_USER_ENV]).to eq({user_id: subject.id, username: subject.username}) end end context "HEAD request" do before do - env['REQUEST_METHOD'] = 'HEAD' + env["REQUEST_METHOD"] = "HEAD" end it { is_expected.to eq(user) } @@ -86,16 +86,16 @@ describe API::Helpers do context "PUT request" do before do - env['REQUEST_METHOD'] = 'PUT' + env["REQUEST_METHOD"] = "PUT" end - context 'without CSRF token' do + context "without CSRF token" do it { is_expected.to be_nil } end - context 'with CSRF token' do + context "with CSRF token" do before do - env['HTTP_X_CSRF_TOKEN'] = csrf_token + env["HTTP_X_CSRF_TOKEN"] = csrf_token end it { is_expected.to eq(user) } @@ -104,16 +104,16 @@ describe API::Helpers do context "POST request" do before do - env['REQUEST_METHOD'] = 'POST' + env["REQUEST_METHOD"] = "POST" end - context 'without CSRF token' do + context "without CSRF token" do it { is_expected.to be_nil } end - context 'with CSRF token' do + context "with CSRF token" do before do - env['HTTP_X_CSRF_TOKEN'] = csrf_token + env["HTTP_X_CSRF_TOKEN"] = csrf_token end it { is_expected.to eq(user) } @@ -122,16 +122,16 @@ describe API::Helpers do context "DELETE request" do before do - env['REQUEST_METHOD'] = 'DELETE' + env["REQUEST_METHOD"] = "DELETE" end - context 'without CSRF token' do + context "without CSRF token" do it { is_expected.to be_nil } end - context 'with CSRF token' do + context "with CSRF token" do before do - env['HTTP_X_CSRF_TOKEN'] = csrf_token + env["HTTP_X_CSRF_TOKEN"] = csrf_token end it { is_expected.to eq(user) } @@ -144,7 +144,7 @@ describe API::Helpers do let(:personal_access_token) { create(:personal_access_token, user: user) } it "returns a 401 response for an invalid token" do - env[Gitlab::Auth::UserAuthFinders::PRIVATE_TOKEN_HEADER] = 'invalid token' + env[Gitlab::Auth::UserAuthFinders::PRIVATE_TOKEN_HEADER] = "invalid token" expect { current_user }.to raise_error /401/ end @@ -156,24 +156,24 @@ describe API::Helpers do expect { current_user }.to raise_error /403/ end - it 'returns a 403 response for a user who is blocked' do + it "returns a 403 response for a user who is blocked" do user.block! env[Gitlab::Auth::UserAuthFinders::PRIVATE_TOKEN_HEADER] = personal_access_token.token expect { current_user }.to raise_error /403/ end - context 'when terms are enforced' do + context "when terms are enforced" do before do enforce_terms env[Gitlab::Auth::UserAuthFinders::PRIVATE_TOKEN_HEADER] = personal_access_token.token end - it 'returns a 403 when a user has not accepted the terms' do + it "returns a 403 when a user has not accepted the terms" do expect { current_user }.to raise_error /must accept the Terms of Service/ end - it 'sets the current user when the user accepted the terms' do + it "sets the current user when the user accepted the terms" do accept_terms(user) expect(current_user).to eq(user) @@ -186,27 +186,27 @@ describe API::Helpers do end it "does not allow tokens without the appropriate scope" do - personal_access_token = create(:personal_access_token, user: user, scopes: ['read_user']) + personal_access_token = create(:personal_access_token, user: user, scopes: ["read_user"]) env[Gitlab::Auth::UserAuthFinders::PRIVATE_TOKEN_HEADER] = personal_access_token.token expect { current_user }.to raise_error Gitlab::Auth::InsufficientScopeError end - it 'does not allow revoked tokens' do + it "does not allow revoked tokens" do personal_access_token.revoke! env[Gitlab::Auth::UserAuthFinders::PRIVATE_TOKEN_HEADER] = personal_access_token.token expect { current_user }.to raise_error Gitlab::Auth::RevokedError end - it 'does not allow expired tokens' do + it "does not allow expired tokens" do personal_access_token.update!(expires_at: 1.day.ago) env[Gitlab::Auth::UserAuthFinders::PRIVATE_TOKEN_HEADER] = personal_access_token.token expect { current_user }.to raise_error Gitlab::Auth::ExpiredError end - context 'when impersonation is disabled' do + context "when impersonation is disabled" do let(:personal_access_token) { create(:personal_access_token, :impersonation, user: user) } before do @@ -214,14 +214,14 @@ describe API::Helpers do env[Gitlab::Auth::UserAuthFinders::PRIVATE_TOKEN_HEADER] = personal_access_token.token end - it 'does not allow impersonation tokens' do + it "does not allow impersonation tokens" do expect { current_user }.to raise_error Gitlab::Auth::ImpersonationDisabled end end end end - describe '.handle_api_exception' do + describe ".handle_api_exception" do before do allow_any_instance_of(self.class).to receive(:rack_response) allow(Gitlab::Sentry).to receive(:enabled?).and_return(true) @@ -231,11 +231,11 @@ describe API::Helpers do sentry_dsn: "dummy://12345:67890@sentry.localdomain/sentry/42" ) configure_sentry - Raven.client.configuration.encoding = 'json' + Raven.client.configuration.encoding = "json" end - it 'does not report a MethodNotAllowed exception to Sentry' do - exception = Grape::Exceptions::MethodNotAllowed.new({ 'X-GitLab-Test' => '1' }) + it "does not report a MethodNotAllowed exception to Sentry" do + exception = Grape::Exceptions::MethodNotAllowed.new({"X-GitLab-Test" => "1"}) allow(exception).to receive(:backtrace).and_return(caller) expect(Raven).not_to receive(:capture_exception).with(exception) @@ -243,62 +243,62 @@ describe API::Helpers do handle_api_exception(exception) end - it 'does report RuntimeError to Sentry' do - exception = RuntimeError.new('test error') + it "does report RuntimeError to Sentry" do + exception = RuntimeError.new("test error") allow(exception).to receive(:backtrace).and_return(caller) expect(Raven).to receive(:capture_exception).with(exception, tags: { - correlation_id: 'new-correlation-id' + correlation_id: "new-correlation-id", }, extra: {}) - Gitlab::CorrelationId.use_id('new-correlation-id') do + Gitlab::CorrelationId.use_id("new-correlation-id") do handle_api_exception(exception) end end - context 'with a personal access token given' do - let(:token) { create(:personal_access_token, scopes: ['api'], user: user) } + context "with a personal access token given" do + let(:token) { create(:personal_access_token, scopes: ["api"], user: user) } # Regression test for https://gitlab.com/gitlab-org/gitlab-ce/issues/38571 - it 'does not raise an additional exception because of missing `request`' do + it "does not raise an additional exception because of missing `request`" do # We need to stub at a lower level than #sentry_enabled? otherwise # Sentry is not enabled when the request below is made, and the test # would pass even without the fix - expect(ProjectsFinder).to receive(:new).and_raise('Runtime Error!') + expect(ProjectsFinder).to receive(:new).and_raise("Runtime Error!") - get api('/projects', personal_access_token: token) + get api("/projects", personal_access_token: token) # The 500 status is expected as we're testing a case where an exception # is raised, but Grape shouldn't raise an additional exception expect(response).to have_gitlab_http_status(500) - expect(json_response['message']).not_to include("undefined local variable or method `request'") - expect(json_response['message']).to start_with("\nRuntimeError (Runtime Error!):") + expect(json_response["message"]).not_to include("undefined local variable or method `request'") + expect(json_response["message"]).to start_with("\nRuntimeError (Runtime Error!):") end end - context 'extra information' do + context "extra information" do # Sentry events are an array of the form [auth_header, data, options] let(:event_data) { Raven.client.transport.events.first[1] } - it 'sends the params, excluding confidential values' do - expect(ProjectsFinder).to receive(:new).and_raise('Runtime Error!') + it "sends the params, excluding confidential values" do + expect(ProjectsFinder).to receive(:new).and_raise("Runtime Error!") - get api('/projects', user), params: { password: 'dont_send_this', other_param: 'send_this' } + get api("/projects", user), params: {password: "dont_send_this", other_param: "send_this"} - expect(event_data).to include('other_param=send_this') - expect(event_data).to include('password=********') + expect(event_data).to include("other_param=send_this") + expect(event_data).to include("password=********") end end end - describe '.authenticate_non_get!' do + describe ".authenticate_non_get!" do %w[HEAD GET].each do |method_name| context "method is #{method_name}" do before do expect_any_instance_of(self.class).to receive(:route).and_return(double(request_method: method_name)) end - it 'does not raise an error' do + it "does not raise an error" do expect_any_instance_of(self.class).not_to receive(:authenticate!) expect { authenticate_non_get! }.not_to raise_error @@ -312,7 +312,7 @@ describe API::Helpers do expect_any_instance_of(self.class).to receive(:route).and_return(double(request_method: method_name)) end - it 'calls authenticate!' do + it "calls authenticate!" do expect_any_instance_of(self.class).to receive(:authenticate!) authenticate_non_get! @@ -321,120 +321,120 @@ describe API::Helpers do end end - describe '.authenticate!' do - context 'current_user is nil' do + describe ".authenticate!" do + context "current_user is nil" do before do expect_any_instance_of(self.class).to receive(:current_user).and_return(nil) end - it 'returns a 401 response' do + it "returns a 401 response" do expect { authenticate! }.to raise_error /401/ end end - context 'current_user is present' do + context "current_user is present" do let(:user) { build(:user) } before do expect_any_instance_of(self.class).to receive(:current_user).and_return(user) end - it 'does not raise an error' do + it "does not raise an error" do expect { authenticate! }.not_to raise_error end end end - context 'sudo' do - shared_examples 'successful sudo' do - it 'sets current_user' do + context "sudo" do + shared_examples "successful sudo" do + it "sets current_user" do expect(current_user).to eq(user) end - it 'sets sudo?' do + it "sets sudo?" do expect(sudo?).to be_truthy end end - shared_examples 'sudo' do - context 'when admin' do + shared_examples "sudo" do + context "when admin" do before do token.user = admin token.save! end - context 'when token has sudo scope' do + context "when token has sudo scope" do before do token.scopes = %w[sudo] token.save! end - context 'when user exists' do - context 'when using header' do - context 'when providing username' do + context "when user exists" do + context "when using header" do + context "when providing username" do before do env[API::Helpers::SUDO_HEADER] = user.username end - it_behaves_like 'successful sudo' + it_behaves_like "successful sudo" end - context 'when providing username (case insensitive)' do + context "when providing username (case insensitive)" do before do env[API::Helpers::SUDO_HEADER] = user.username.upcase end - it_behaves_like 'successful sudo' + it_behaves_like "successful sudo" end - context 'when providing user ID' do + context "when providing user ID" do before do env[API::Helpers::SUDO_HEADER] = user.id.to_s end - it_behaves_like 'successful sudo' + it_behaves_like "successful sudo" end end - context 'when using param' do - context 'when providing username' do + context "when using param" do + context "when providing username" do before do set_param(API::Helpers::SUDO_PARAM, user.username) end - it_behaves_like 'successful sudo' + it_behaves_like "successful sudo" end - context 'when providing username (case insensitive)' do + context "when providing username (case insensitive)" do before do set_param(API::Helpers::SUDO_PARAM, user.username.upcase) end - it_behaves_like 'successful sudo' + it_behaves_like "successful sudo" end - context 'when providing user ID' do + context "when providing user ID" do before do set_param(API::Helpers::SUDO_PARAM, user.id.to_s) end - it_behaves_like 'successful sudo' + it_behaves_like "successful sudo" end end end - context 'when user does not exist' do + context "when user does not exist" do before do - set_param(API::Helpers::SUDO_PARAM, 'nonexistent') + set_param(API::Helpers::SUDO_PARAM, "nonexistent") end - it 'raises an error' do + it "raises an error" do expect { current_user }.to raise_error /User with ID or username 'nonexistent' Not Found/ end end end - context 'when token does not have sudo scope' do + context "when token does not have sudo scope" do before do token.scopes = %w[api] token.save! @@ -442,13 +442,13 @@ describe API::Helpers do set_param(API::Helpers::SUDO_PARAM, user.id.to_s) end - it 'raises an error' do + it "raises an error" do expect { current_user }.to raise_error Gitlab::Auth::InsufficientScopeError end end end - context 'when not admin' do + context "when not admin" do before do token.user = user token.save! @@ -456,49 +456,49 @@ describe API::Helpers do set_param(API::Helpers::SUDO_PARAM, user.id.to_s) end - it 'raises an error' do + it "raises an error" do expect { current_user }.to raise_error /Must be admin to use sudo/ end end end - context 'using an OAuth token' do + context "using an OAuth token" do let(:token) { create(:oauth_access_token) } before do - env['HTTP_AUTHORIZATION'] = "Bearer #{token.token}" + env["HTTP_AUTHORIZATION"] = "Bearer #{token.token}" end - it_behaves_like 'sudo' + it_behaves_like "sudo" end - context 'using a personal access token' do + context "using a personal access token" do let(:token) { create(:personal_access_token) } - context 'passed as param' do + context "passed as param" do before do set_param(Gitlab::Auth::UserAuthFinders::PRIVATE_TOKEN_PARAM, token.token) end - it_behaves_like 'sudo' + it_behaves_like "sudo" end - context 'passed as header' do + context "passed as header" do before do env[Gitlab::Auth::UserAuthFinders::PRIVATE_TOKEN_HEADER] = token.token end - it_behaves_like 'sudo' + it_behaves_like "sudo" end end - context 'using warden authentication' do + context "using warden authentication" do before do warden_authenticate_returns admin env[API::Helpers::SUDO_HEADER] = user.username end - it 'raises an error' do + it "raises an error" do expect { current_user }.to raise_error /Must be authenticated using an OAuth or Personal Access Token to use sudo/ end end diff --git a/spec/requests/api/import_github_spec.rb b/spec/requests/api/import_github_spec.rb index aceff9b4aa6..8c87bf3ca25 100644 --- a/spec/requests/api/import_github_spec.rb +++ b/spec/requests/api/import_github_spec.rb @@ -1,11 +1,11 @@ -require 'spec_helper' +require "spec_helper" describe API::ImportGithub do include ApiHelpers let(:token) { "asdasd12345" } let(:provider) { :github } - let(:access_params) { { github_access_token: token } } + let(:access_params) { {github_access_token: token} } describe "POST /import/github" do let(:user) { create(:user) } @@ -14,7 +14,7 @@ describe API::ImportGithub do let(:provider_user) { OpenStruct.new(login: provider_username) } let(:provider_repo) do OpenStruct.new( - name: 'vim', + name: "vim", full_name: "#{provider_username}/vim", owner: OpenStruct.new(login: provider_username) ) @@ -22,32 +22,32 @@ describe API::ImportGithub do before do Grape::Endpoint.before_each do |endpoint| - allow(endpoint).to receive(:client).and_return(double('client', user: provider_user, repo: provider_repo).as_null_object) + allow(endpoint).to receive(:client).and_return(double("client", user: provider_user, repo: provider_repo).as_null_object) end end - it 'returns 201 response when the project is imported successfully' do + it "returns 201 response when the project is imported successfully" do allow(Gitlab::LegacyGithubImport::ProjectCreator) .to receive(:new).with(provider_repo, provider_repo.name, user.namespace, user, access_params, type: provider) - .and_return(double(execute: project)) + .and_return(double(execute: project)) post api("/import/github", user), params: { target_namespace: user.namespace_path, personal_access_token: token, - repo_id: 1234 + repo_id: 1234, } expect(response).to have_gitlab_http_status(201) expect(json_response).to be_a Hash - expect(json_response['name']).to eq(project.name) + expect(json_response["name"]).to eq(project.name) end - it 'returns 422 response when user can not create projects in the chosen namespace' do - other_namespace = create(:group, name: 'other_namespace') + it "returns 422 response when user can not create projects in the chosen namespace" do + other_namespace = create(:group, name: "other_namespace") post api("/import/github", user), params: { target_namespace: other_namespace.name, personal_access_token: token, - repo_id: 1234 + repo_id: 1234, } expect(response).to have_gitlab_http_status(422) diff --git a/spec/requests/api/internal_spec.rb b/spec/requests/api/internal_spec.rb index cd85151ec1b..4b272380d40 100644 --- a/spec/requests/api/internal_spec.rb +++ b/spec/requests/api/internal_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe API::Internal do set(:user) { create(:user) } @@ -6,54 +6,54 @@ describe API::Internal do set(:project) { create(:project, :repository, :wiki_repo) } let(:secret_token) { Gitlab::Shell.secret_token } let(:gl_repository) { "project-#{project.id}" } - let(:reference_counter) { double('ReferenceCounter') } + let(:reference_counter) { double("ReferenceCounter") } describe "GET /internal/check" do it do - expect_any_instance_of(Redis).to receive(:ping).and_return('PONG') + expect_any_instance_of(Redis).to receive(:ping).and_return("PONG") - get api("/internal/check"), params: { secret_token: secret_token } + get api("/internal/check"), params: {secret_token: secret_token} expect(response).to have_gitlab_http_status(200) - expect(json_response['api_version']).to eq(API::API.version) - expect(json_response['redis']).to be(true) + expect(json_response["api_version"]).to eq(API::API.version) + expect(json_response["redis"]).to be(true) end - it 'returns false for field `redis` when redis is unavailable' do + it "returns false for field `redis` when redis is unavailable" do expect_any_instance_of(Redis).to receive(:ping).and_raise(Errno::ENOENT) - get api("/internal/check"), params: { secret_token: secret_token } + get api("/internal/check"), params: {secret_token: secret_token} - expect(json_response['redis']).to be(false) + expect(json_response["redis"]).to be(false) end end - describe 'GET /internal/broadcast_message' do - context 'broadcast message exists' do - let!(:broadcast_message) { create(:broadcast_message, starts_at: 1.day.ago, ends_at: 1.day.from_now ) } + describe "GET /internal/broadcast_message" do + context "broadcast message exists" do + let!(:broadcast_message) { create(:broadcast_message, starts_at: 1.day.ago, ends_at: 1.day.from_now) } - it 'returns one broadcast message' do - get api('/internal/broadcast_message'), params: { secret_token: secret_token } + it "returns one broadcast message" do + get api("/internal/broadcast_message"), params: {secret_token: secret_token} expect(response).to have_gitlab_http_status(200) - expect(json_response['message']).to eq(broadcast_message.message) + expect(json_response["message"]).to eq(broadcast_message.message) end end - context 'broadcast message does not exist' do - it 'returns nothing' do - get api('/internal/broadcast_message'), params: { secret_token: secret_token } + context "broadcast message does not exist" do + it "returns nothing" do + get api("/internal/broadcast_message"), params: {secret_token: secret_token} expect(response).to have_gitlab_http_status(200) expect(json_response).to be_empty end end - context 'nil broadcast message' do - it 'returns nothing' do + context "nil broadcast message" do + it "returns nothing" do allow(BroadcastMessage).to receive(:current).and_return(nil) - get api('/internal/broadcast_message'), params: { secret_token: secret_token } + get api("/internal/broadcast_message"), params: {secret_token: secret_token} expect(response).to have_gitlab_http_status(200) expect(json_response).to be_empty @@ -61,21 +61,21 @@ describe API::Internal do end end - describe 'GET /internal/broadcast_messages' do - context 'broadcast message(s) exist' do - let!(:broadcast_message) { create(:broadcast_message, starts_at: 1.day.ago, ends_at: 1.day.from_now ) } + describe "GET /internal/broadcast_messages" do + context "broadcast message(s) exist" do + let!(:broadcast_message) { create(:broadcast_message, starts_at: 1.day.ago, ends_at: 1.day.from_now) } - it 'returns active broadcast message(s)' do - get api('/internal/broadcast_messages'), params: { secret_token: secret_token } + it "returns active broadcast message(s)" do + get api("/internal/broadcast_messages"), params: {secret_token: secret_token} expect(response).to have_gitlab_http_status(200) - expect(json_response[0]['message']).to eq(broadcast_message.message) + expect(json_response[0]["message"]).to eq(broadcast_message.message) end end - context 'broadcast message does not exist' do - it 'returns nothing' do - get api('/internal/broadcast_messages'), params: { secret_token: secret_token } + context "broadcast message does not exist" do + it "returns nothing" do + get api("/internal/broadcast_messages"), params: {secret_token: secret_token} expect(response).to have_gitlab_http_status(200) expect(json_response).to be_empty @@ -83,74 +83,74 @@ describe API::Internal do end end - describe 'GET /internal/two_factor_recovery_codes' do - it 'returns an error message when the key does not exist' do - post api('/internal/two_factor_recovery_codes'), - params: { - secret_token: secret_token, - key_id: 12345 - } + describe "GET /internal/two_factor_recovery_codes" do + it "returns an error message when the key does not exist" do + post api("/internal/two_factor_recovery_codes"), + params: { + secret_token: secret_token, + key_id: 12345, + } - expect(json_response['success']).to be_falsey - expect(json_response['message']).to eq('Could not find the given key') + expect(json_response["success"]).to be_falsey + expect(json_response["message"]).to eq("Could not find the given key") end - it 'returns an error message when the key is a deploy key' do + it "returns an error message when the key is a deploy key" do deploy_key = create(:deploy_key) - post api('/internal/two_factor_recovery_codes'), - params: { - secret_token: secret_token, - key_id: deploy_key.id - } + post api("/internal/two_factor_recovery_codes"), + params: { + secret_token: secret_token, + key_id: deploy_key.id, + } - expect(json_response['success']).to be_falsey - expect(json_response['message']).to eq('Deploy keys cannot be used to retrieve recovery codes') + expect(json_response["success"]).to be_falsey + expect(json_response["message"]).to eq("Deploy keys cannot be used to retrieve recovery codes") end - it 'returns an error message when the user does not exist' do + it "returns an error message when the user does not exist" do key_without_user = create(:key, user: nil) - post api('/internal/two_factor_recovery_codes'), - params: { - secret_token: secret_token, - key_id: key_without_user.id - } + post api("/internal/two_factor_recovery_codes"), + params: { + secret_token: secret_token, + key_id: key_without_user.id, + } - expect(json_response['success']).to be_falsey - expect(json_response['message']).to eq('Could not find a user for the given key') - expect(json_response['recovery_codes']).to be_nil + expect(json_response["success"]).to be_falsey + expect(json_response["message"]).to eq("Could not find a user for the given key") + expect(json_response["recovery_codes"]).to be_nil end - context 'when two-factor is enabled' do - it 'returns new recovery codes when the user exists' do + context "when two-factor is enabled" do + it "returns new recovery codes when the user exists" do allow_any_instance_of(User).to receive(:two_factor_enabled?).and_return(true) allow_any_instance_of(User) - .to receive(:generate_otp_backup_codes!).and_return(%w(119135e5a3ebce8e 34bd7b74adbc8861)) + .to receive(:generate_otp_backup_codes!).and_return(%w[119135e5a3ebce8e 34bd7b74adbc8861]) - post api('/internal/two_factor_recovery_codes'), - params: { - secret_token: secret_token, - key_id: key.id - } + post api("/internal/two_factor_recovery_codes"), + params: { + secret_token: secret_token, + key_id: key.id, + } - expect(json_response['success']).to be_truthy - expect(json_response['recovery_codes']).to match_array(%w(119135e5a3ebce8e 34bd7b74adbc8861)) + expect(json_response["success"]).to be_truthy + expect(json_response["recovery_codes"]).to match_array(%w[119135e5a3ebce8e 34bd7b74adbc8861]) end end - context 'when two-factor is not enabled' do - it 'returns an error message' do + context "when two-factor is not enabled" do + it "returns an error message" do allow_any_instance_of(User).to receive(:two_factor_enabled?).and_return(false) - post api('/internal/two_factor_recovery_codes'), - params: { - secret_token: secret_token, - key_id: key.id - } + post api("/internal/two_factor_recovery_codes"), + params: { + secret_token: secret_token, + key_id: key.id, + } - expect(json_response['success']).to be_falsey - expect(json_response['recovery_codes']).to be_nil + expect(json_response["success"]).to be_falsey + expect(json_response["recovery_codes"]).to be_nil end end end @@ -160,89 +160,89 @@ describe API::Internal do project.add_developer(user) end - context 'user key' do - it 'returns the correct information about the key' do + context "user key" do + it "returns the correct information about the key" do lfs_auth_key(key.id, project) expect(response).to have_gitlab_http_status(200) - expect(json_response['username']).to eq(user.username) - expect(json_response['repository_http_path']).to eq(project.http_url_to_repo) - expect(json_response['expires_in']).to eq(Gitlab::LfsToken::DEFAULT_EXPIRE_TIME) - expect(Gitlab::LfsToken.new(key).token_valid?(json_response['lfs_token'])).to be_truthy + expect(json_response["username"]).to eq(user.username) + expect(json_response["repository_http_path"]).to eq(project.http_url_to_repo) + expect(json_response["expires_in"]).to eq(Gitlab::LfsToken::DEFAULT_EXPIRE_TIME) + expect(Gitlab::LfsToken.new(key).token_valid?(json_response["lfs_token"])).to be_truthy end - it 'returns the correct information about the user' do + it "returns the correct information about the user" do lfs_auth_user(user.id, project) expect(response).to have_gitlab_http_status(200) - expect(json_response['username']).to eq(user.username) - expect(json_response['repository_http_path']).to eq(project.http_url_to_repo) - expect(Gitlab::LfsToken.new(user).token_valid?(json_response['lfs_token'])).to be_truthy + expect(json_response["username"]).to eq(user.username) + expect(json_response["repository_http_path"]).to eq(project.http_url_to_repo) + expect(Gitlab::LfsToken.new(user).token_valid?(json_response["lfs_token"])).to be_truthy end - it 'returns a 404 when no key or user is provided' do + it "returns a 404 when no key or user is provided" do lfs_auth_project(project) expect(response).to have_gitlab_http_status(404) end - it 'returns a 404 when the wrong key is provided' do + it "returns a 404 when the wrong key is provided" do lfs_auth_key(key.id + 12345, project) expect(response).to have_gitlab_http_status(404) end - it 'returns a 404 when the wrong user is provided' do + it "returns a 404 when the wrong user is provided" do lfs_auth_user(user.id + 12345, project) expect(response).to have_gitlab_http_status(404) end end - context 'deploy key' do + context "deploy key" do let(:key) { create(:deploy_key) } - it 'returns the correct information about the key' do + it "returns the correct information about the key" do lfs_auth_key(key.id, project) expect(response).to have_gitlab_http_status(200) - expect(json_response['username']).to eq("lfs+deploy-key-#{key.id}") - expect(json_response['repository_http_path']).to eq(project.http_url_to_repo) - expect(Gitlab::LfsToken.new(key).token_valid?(json_response['lfs_token'])).to be_truthy + expect(json_response["username"]).to eq("lfs+deploy-key-#{key.id}") + expect(json_response["repository_http_path"]).to eq(project.http_url_to_repo) + expect(Gitlab::LfsToken.new(key).token_valid?(json_response["lfs_token"])).to be_truthy end end end describe "GET /internal/discover" do it "finds a user by key id" do - get(api("/internal/discover"), params: { key_id: key.id, secret_token: secret_token }) + get(api("/internal/discover"), params: {key_id: key.id, secret_token: secret_token}) expect(response).to have_gitlab_http_status(200) - expect(json_response['name']).to eq(user.name) + expect(json_response["name"]).to eq(user.name) end it "finds a user by user id" do - get(api("/internal/discover"), params: { user_id: user.id, secret_token: secret_token }) + get(api("/internal/discover"), params: {user_id: user.id, secret_token: secret_token}) expect(response).to have_gitlab_http_status(200) - expect(json_response['name']).to eq(user.name) + expect(json_response["name"]).to eq(user.name) end it "finds a user by username" do - get(api("/internal/discover"), params: { username: user.username, secret_token: secret_token }) + get(api("/internal/discover"), params: {username: user.username, secret_token: secret_token}) expect(response).to have_gitlab_http_status(200) - expect(json_response['name']).to eq(user.name) + expect(json_response["name"]).to eq(user.name) end end describe "GET /internal/authorized_keys" do context "using an existing key's fingerprint" do it "finds the key" do - get(api('/internal/authorized_keys'), params: { fingerprint: key.fingerprint, secret_token: secret_token }) + get(api("/internal/authorized_keys"), params: {fingerprint: key.fingerprint, secret_token: secret_token}) expect(response.status).to eq(200) expect(json_response["key"]).to eq(key.key) @@ -251,7 +251,7 @@ describe API::Internal do context "non existing key's fingerprint" do it "returns 404" do - get(api('/internal/authorized_keys'), params: { fingerprint: "no:t-:va:li:d0", secret_token: secret_token }) + get(api("/internal/authorized_keys"), params: {fingerprint: "no:t-:va:li:d0", secret_token: secret_token}) expect(response.status).to eq(404) end @@ -259,7 +259,7 @@ describe API::Internal do context "using a partial fingerprint" do it "returns 404" do - get(api('/internal/authorized_keys'), params: { fingerprint: "#{key.fingerprint[0..5]}%", secret_token: secret_token }) + get(api("/internal/authorized_keys"), params: {fingerprint: "#{key.fingerprint[0..5]}%", secret_token: secret_token}) expect(response.status).to eq(404) end @@ -267,20 +267,20 @@ describe API::Internal do context "sending the key" do it "finds the key" do - get(api('/internal/authorized_keys'), params: { key: key.key.split[1], secret_token: secret_token }) + get(api("/internal/authorized_keys"), params: {key: key.key.split[1], secret_token: secret_token}) expect(response.status).to eq(200) expect(json_response["key"]).to eq(key.key) end it "returns 404 with a partial key" do - get(api('/internal/authorized_keys'), params: { key: key.key.split[1][0...-3], secret_token: secret_token }) + get(api("/internal/authorized_keys"), params: {key: key.key.split[1][0...-3], secret_token: secret_token}) expect(response.status).to eq(404) end it "returns 404 with an not valid base64 string" do - get(api('/internal/authorized_keys'), params: { key: "whatever!", secret_token: secret_token }) + get(api("/internal/authorized_keys"), params: {key: "whatever!", secret_token: secret_token}) expect(response.status).to eq(404) end @@ -297,21 +297,21 @@ describe API::Internal do project.add_developer(user) end - context 'with env passed as a JSON' do + context "with env passed as a JSON" do let(:gl_repository) { project.gl_repository(is_wiki: true) } - it 'sets env in RequestStore' do - obj_dir_relative = './objects' - alt_obj_dirs_relative = ['./alt-objects-1', './alt-objects-2'] + it "sets env in RequestStore" do + obj_dir_relative = "./objects" + alt_obj_dirs_relative = ["./alt-objects-1", "./alt-objects-2"] expect(Gitlab::Git::HookEnv).to receive(:set).with(gl_repository, { - 'GIT_OBJECT_DIRECTORY_RELATIVE' => obj_dir_relative, - 'GIT_ALTERNATE_OBJECT_DIRECTORIES_RELATIVE' => alt_obj_dirs_relative + "GIT_OBJECT_DIRECTORY_RELATIVE" => obj_dir_relative, + "GIT_ALTERNATE_OBJECT_DIRECTORIES_RELATIVE" => alt_obj_dirs_relative, }) push(key, project.wiki, env: { GIT_OBJECT_DIRECTORY_RELATIVE: obj_dir_relative, - GIT_ALTERNATE_OBJECT_DIRECTORIES_RELATIVE: alt_obj_dirs_relative + GIT_ALTERNATE_OBJECT_DIRECTORIES_RELATIVE: alt_obj_dirs_relative, }.to_json) expect(response).to have_gitlab_http_status(200) @@ -319,12 +319,12 @@ describe API::Internal do end context "git push with project.wiki" do - it 'responds with success' do + it "responds with success" do push(key, project.wiki) expect(response).to have_gitlab_http_status(200) expect(json_response["status"]).to be_truthy - expect(json_response["repository_path"]).to eq('/') + expect(json_response["repository_path"]).to eq("/") expect(json_response["gl_project_path"]).to eq(project.wiki.full_path) expect(json_response["gl_repository"]).to eq("wiki-#{project.id}") expect(user.reload.last_activity_on).to be_nil @@ -332,12 +332,12 @@ describe API::Internal do end context "git pull with project.wiki" do - it 'responds with success' do + it "responds with success" do pull(key, project.wiki) expect(response).to have_gitlab_http_status(200) expect(json_response["status"]).to be_truthy - expect(json_response["repository_path"]).to eq('/') + expect(json_response["repository_path"]).to eq("/") expect(json_response["gl_project_path"]).to eq(project.wiki.full_path) expect(json_response["gl_repository"]).to eq("wiki-#{project.id}") expect(user.reload.last_activity_on).to eql(Date.today) @@ -350,7 +350,7 @@ describe API::Internal do expect(response).to have_gitlab_http_status(200) expect(json_response["status"]).to be_truthy - expect(json_response["repository_path"]).to eq('/') + expect(json_response["repository_path"]).to eq("/") expect(json_response["gl_repository"]).to eq("project-#{project.id}") expect(json_response["gl_project_path"]).to eq(project.full_path) expect(json_response["gitaly"]).not_to be_nil @@ -364,13 +364,13 @@ describe API::Internal do end context "git push" do - context 'project as namespace/project' do + context "project as namespace/project" do it do push(key, project) expect(response).to have_gitlab_http_status(200) expect(json_response["status"]).to be_truthy - expect(json_response["repository_path"]).to eq('/') + expect(json_response["repository_path"]).to eq("/") expect(json_response["gl_repository"]).to eq("project-#{project.id}") expect(json_response["gl_project_path"]).to eq(project.full_path) expect(json_response["gitaly"]).not_to be_nil @@ -383,8 +383,8 @@ describe API::Internal do end end - context 'when receive_max_input_size has been updated' do - it 'returns custom git config' do + context "when receive_max_input_size has been updated" do + it "returns custom git config" do allow(Gitlab::CurrentSettings).to receive(:receive_max_input_size) { 1 } push(key, project) @@ -393,8 +393,8 @@ describe API::Internal do end end - context 'when receive_max_input_size is empty' do - it 'returns an empty git config' do + context "when receive_max_input_size is empty" do + it "returns an empty git config" do allow(Gitlab::CurrentSettings).to receive(:receive_max_input_size) { nil } push(key, project) @@ -433,15 +433,15 @@ describe API::Internal do context "custom action" do let(:access_checker) { double(Gitlab::GitAccess) } - let(:message) { 'CustomActionError message' } + let(:message) { "CustomActionError message" } let(:payload) do { - 'action' => 'geo_proxy_to_primary', - 'data' => { - 'api_endpoints' => %w{geo/proxy_git_push_ssh/info_refs geo/proxy_git_push_ssh/push}, - 'gl_username' => 'testuser', - 'primary_repo' => 'http://localhost:3000/testuser/repo.git' - } + "action" => "geo_proxy_to_primary", + "data" => { + "api_endpoints" => %w[geo/proxy_git_push_ssh/info_refs geo/proxy_git_push_ssh/push], + "gl_username" => "testuser", + "primary_repo" => "http://localhost:3000/testuser/repo.git", + }, } end @@ -452,17 +452,17 @@ describe API::Internal do expect(Gitlab::GitAccess).to receive(:new).with( key, project, - 'ssh', + "ssh", { authentication_abilities: [:read_project, :download_code, :push_code], namespace_path: project.namespace.name, project_path: project.path, - redirected_path: nil + redirected_path: nil, } ).and_return(access_checker) expect(access_checker).to receive(:check).with( - 'git-receive-pack', - 'd14d6c0abdd253381df51a723d58691b2ee1ab08 570e7b2abdd848b95f2f578043fc23bd6f6fd24d refs/heads/master' + "git-receive-pack", + "d14d6c0abdd253381df51a723d58691b2ee1ab08 570e7b2abdd848b95f2f578043fc23bd6f6fd24d refs/heads/master" ).and_return(custom_action_result) end @@ -471,9 +471,9 @@ describe API::Internal do push(key, project) expect(response).to have_gitlab_http_status(300) - expect(json_response['status']).to be_truthy - expect(json_response['message']).to eql(message) - expect(json_response['payload']).to eql(payload) + expect(json_response["status"]).to be_truthy + expect(json_response["message"]).to eql(message) + expect(json_response["payload"]).to eql(payload) expect(user.reload.last_activity_on).to be_nil end end @@ -507,9 +507,9 @@ describe API::Internal do end end - context 'request times out' do - context 'git push' do - it 'responds with a gateway timeout' do + context "request times out" do + context "git push" do + it "responds with a gateway timeout" do personal_project = create(:project, namespace: user.namespace) expect_next_instance_of(Gitlab::GitAccess) do |access| @@ -518,8 +518,8 @@ describe API::Internal do push(key, personal_project) expect(response).to have_gitlab_http_status(503) - expect(json_response['status']).to be_falsey - expect(json_response['message']).to eq("Foo") + expect(json_response["status"]).to be_falsey + expect(json_response["message"]).to eq("Foo") expect(user.reload.last_activity_on).to be_nil end end @@ -582,8 +582,8 @@ describe API::Internal do end end - context 'project does not exist' do - it 'returns a 200 response with status: false' do + context "project does not exist" do + it "returns a 200 response with status: false" do project.destroy pull(key, project) @@ -593,7 +593,7 @@ describe API::Internal do end end - context 'user does not exist' do + context "user does not exist" do it do pull(OpenStruct.new(id: 0), project) @@ -602,88 +602,88 @@ describe API::Internal do end end - context 'ssh access has been disabled' do + context "ssh access has been disabled" do before do - stub_application_setting(enabled_git_access_protocol: 'http') + stub_application_setting(enabled_git_access_protocol: "http") end - it 'rejects the SSH push' do + it "rejects the SSH push" do push(key, project) expect(response.status).to eq(401) - expect(json_response['status']).to be_falsey - expect(json_response['message']).to eq 'Git access over SSH is not allowed' + expect(json_response["status"]).to be_falsey + expect(json_response["message"]).to eq "Git access over SSH is not allowed" end - it 'rejects the SSH pull' do + it "rejects the SSH pull" do pull(key, project) expect(response.status).to eq(401) - expect(json_response['status']).to be_falsey - expect(json_response['message']).to eq 'Git access over SSH is not allowed' + expect(json_response["status"]).to be_falsey + expect(json_response["message"]).to eq "Git access over SSH is not allowed" end end - context 'http access has been disabled' do + context "http access has been disabled" do before do - stub_application_setting(enabled_git_access_protocol: 'ssh') + stub_application_setting(enabled_git_access_protocol: "ssh") end - it 'rejects the HTTP push' do - push(key, project, 'http') + it "rejects the HTTP push" do + push(key, project, "http") expect(response.status).to eq(401) - expect(json_response['status']).to be_falsey - expect(json_response['message']).to eq 'Git access over HTTP is not allowed' + expect(json_response["status"]).to be_falsey + expect(json_response["message"]).to eq "Git access over HTTP is not allowed" end - it 'rejects the HTTP pull' do - pull(key, project, 'http') + it "rejects the HTTP pull" do + pull(key, project, "http") expect(response.status).to eq(401) - expect(json_response['status']).to be_falsey - expect(json_response['message']).to eq 'Git access over HTTP is not allowed' + expect(json_response["status"]).to be_falsey + expect(json_response["message"]).to eq "Git access over HTTP is not allowed" end end - context 'web actions are always allowed' do - it 'allows WEB push' do - stub_application_setting(enabled_git_access_protocol: 'ssh') + context "web actions are always allowed" do + it "allows WEB push" do + stub_application_setting(enabled_git_access_protocol: "ssh") project.add_developer(user) - push(key, project, 'web') + push(key, project, "web") expect(response.status).to eq(200) - expect(json_response['status']).to be_truthy + expect(json_response["status"]).to be_truthy end end - context 'the project path was changed' do + context "the project path was changed" do let(:project) { create(:project, :repository, :legacy_storage) } let!(:repository) { project.repository } before do project.add_developer(user) - project.path = 'new_path' + project.path = "new_path" project.save! end - it 'rejects the push' do + it "rejects the push" do push(key, project) expect(response).to have_gitlab_http_status(404) - expect(json_response['status']).to be_falsy + expect(json_response["status"]).to be_falsy end - it 'rejects the SSH pull' do + it "rejects the SSH pull" do pull(key, project) expect(response).to have_gitlab_http_status(404) - expect(json_response['status']).to be_falsy + expect(json_response["status"]).to be_falsy end end end - describe 'GET /internal/merge_request_urls' do + describe "GET /internal/merge_request_urls" do let(:repo_name) { "#{project.namespace.name}/#{project.path}" } let(:changes) { URI.escape("#{Gitlab::Git::BLANK_SHA} 570e7b2abdd848b95f2f578043fc23bd6f6fd24d refs/heads/new_branch") } @@ -691,34 +691,34 @@ describe API::Internal do project.add_developer(user) end - it 'returns link to create new merge request' do - get api("/internal/merge_request_urls?project=#{repo_name}&changes=#{changes}"), params: { secret_token: secret_token } + it "returns link to create new merge request" do + get api("/internal/merge_request_urls?project=#{repo_name}&changes=#{changes}"), params: {secret_token: secret_token} expect(json_response).to match [{ "branch_name" => "new_branch", "url" => "http://#{Gitlab.config.gitlab.host}/#{project.namespace.name}/#{project.path}/merge_requests/new?merge_request%5Bsource_branch%5D=new_branch", - "new_merge_request" => true + "new_merge_request" => true, }] end - it 'returns empty array if printing_merge_request_link_enabled is false' do + it "returns empty array if printing_merge_request_link_enabled is false" do project.update!(printing_merge_request_link_enabled: false) - get api("/internal/merge_request_urls?project=#{repo_name}&changes=#{changes}"), params: { secret_token: secret_token } + get api("/internal/merge_request_urls?project=#{repo_name}&changes=#{changes}"), params: {secret_token: secret_token} expect(json_response).to eq([]) end - context 'with a gl_repository parameter' do + context "with a gl_repository parameter" do let(:gl_repository) { "project-#{project.id}" } - it 'returns link to create new merge request' do - get api("/internal/merge_request_urls?gl_repository=#{gl_repository}&changes=#{changes}"), params: { secret_token: secret_token } + it "returns link to create new merge request" do + get api("/internal/merge_request_urls?gl_repository=#{gl_repository}&changes=#{changes}"), params: {secret_token: secret_token} expect(json_response).to match [{ "branch_name" => "new_branch", "url" => "http://#{Gitlab.config.gitlab.host}/#{project.namespace.name}/#{project.path}/merge_requests/new?merge_request%5Bsource_branch%5D=new_branch", - "new_merge_request" => true + "new_merge_request" => true, }] end end @@ -806,8 +806,8 @@ describe API::Internal do # end # end - describe 'POST /internal/post_receive', :clean_gitlab_redis_shared_state do - let(:identifier) { 'key-123' } + describe "POST /internal/post_receive", :clean_gitlab_redis_shared_state do + let(:identifier) { "key-123" } let(:valid_params) do { @@ -815,7 +815,7 @@ describe API::Internal do secret_token: secret_token, identifier: identifier, changes: changes, - push_options: push_options + push_options: push_options, } end @@ -824,8 +824,8 @@ describe API::Internal do end let(:push_options) do - ['ci.skip', - 'another push option'] + ["ci.skip", + "another push option",] end before do @@ -834,75 +834,75 @@ describe API::Internal do allow_any_instance_of(Gitlab::Identifier).to receive(:identify).and_return(user) end - it 'enqueues a PostReceive worker job' do + it "enqueues a PostReceive worker job" do expect(PostReceive).to receive(:perform_async) .with(gl_repository, identifier, changes, push_options) post api("/internal/post_receive"), params: valid_params end - it 'decreases the reference counter and returns the result' do + it "decreases the reference counter and returns the result" do expect(Gitlab::ReferenceCounter).to receive(:new).with(gl_repository) .and_return(reference_counter) expect(reference_counter).to receive(:decrease).and_return(true) post api("/internal/post_receive"), params: valid_params - expect(json_response['reference_counter_decreased']).to be(true) + expect(json_response["reference_counter_decreased"]).to be(true) end - it 'returns link to create new merge request' do + it "returns link to create new merge request" do post api("/internal/post_receive"), params: valid_params - expect(json_response['merge_request_urls']).to match [{ + expect(json_response["merge_request_urls"]).to match [{ "branch_name" => "new_branch", "url" => "http://#{Gitlab.config.gitlab.host}/#{project.namespace.name}/#{project.path}/merge_requests/new?merge_request%5Bsource_branch%5D=new_branch", - "new_merge_request" => true + "new_merge_request" => true, }] end - it 'returns empty array if printing_merge_request_link_enabled is false' do + it "returns empty array if printing_merge_request_link_enabled is false" do project.update!(printing_merge_request_link_enabled: false) post api("/internal/post_receive"), params: valid_params - expect(json_response['merge_request_urls']).to eq([]) + expect(json_response["merge_request_urls"]).to eq([]) end - context 'broadcast message exists' do - let!(:broadcast_message) { create(:broadcast_message, starts_at: 1.day.ago, ends_at: 1.day.from_now ) } + context "broadcast message exists" do + let!(:broadcast_message) { create(:broadcast_message, starts_at: 1.day.ago, ends_at: 1.day.from_now) } - it 'returns one broadcast message' do + it "returns one broadcast message" do post api("/internal/post_receive"), params: valid_params expect(response).to have_gitlab_http_status(200) - expect(json_response['broadcast_message']).to eq(broadcast_message.message) + expect(json_response["broadcast_message"]).to eq(broadcast_message.message) end end - context 'broadcast message does not exist' do - it 'returns empty string' do + context "broadcast message does not exist" do + it "returns empty string" do post api("/internal/post_receive"), params: valid_params expect(response).to have_gitlab_http_status(200) - expect(json_response['broadcast_message']).to eq(nil) + expect(json_response["broadcast_message"]).to eq(nil) end end - context 'nil broadcast message' do - it 'returns empty string' do + context "nil broadcast message" do + it "returns empty string" do allow(BroadcastMessage).to receive(:current).and_return(nil) post api("/internal/post_receive"), params: valid_params expect(response).to have_gitlab_http_status(200) - expect(json_response['broadcast_message']).to eq(nil) + expect(json_response["broadcast_message"]).to eq(nil) end end - context 'with a redirected data' do - it 'returns redirected message on the response' do - project_moved = Gitlab::Checks::ProjectMoved.new(project, user, 'http', 'foo/baz') + context "with a redirected data" do + it "returns redirected message on the response" do + project_moved = Gitlab::Checks::ProjectMoved.new(project, user, "http", "foo/baz") project_moved.add_message post api("/internal/post_receive"), params: valid_params @@ -913,9 +913,9 @@ describe API::Internal do end end - context 'with new project data' do - it 'returns new project message on the response' do - project_created = Gitlab::Checks::ProjectCreated.new(project, user, 'http') + context "with new project data" do + it "returns new project message on the response" do + project_created = Gitlab::Checks::ProjectCreated.new(project, user, "http") project_created.add_message post api("/internal/post_receive"), params: valid_params @@ -926,8 +926,8 @@ describe API::Internal do end end - context 'with an orphaned write deploy key' do - it 'does not try to notify that project moved' do + context "with an orphaned write deploy key" do + it "does not try to notify that project moved" do allow_any_instance_of(Gitlab::Identifier).to receive(:identify).and_return(nil) post api("/internal/post_receive"), params: valid_params @@ -937,19 +937,19 @@ describe API::Internal do end end - describe 'POST /internal/pre_receive' do + describe "POST /internal/pre_receive" do let(:valid_params) do - { gl_repository: gl_repository, secret_token: secret_token } + {gl_repository: gl_repository, secret_token: secret_token} end - it 'decreases the reference counter and returns the result' do + it "decreases the reference counter and returns the result" do expect(Gitlab::ReferenceCounter).to receive(:new).with(gl_repository) .and_return(reference_counter) expect(reference_counter).to receive(:increase).and_return(true) post api("/internal/pre_receive"), params: valid_params - expect(json_response['reference_counter_increased']).to be(true) + expect(json_response["reference_counter_increased"]).to be(true) end end @@ -959,35 +959,33 @@ describe API::Internal do project_or_wiki.project.gl_repository(is_wiki: true) when Project project_or_wiki.gl_repository(is_wiki: false) - else - nil end end - def pull(key, project, protocol = 'ssh') + def pull(key, project, protocol = "ssh") post( api("/internal/allowed"), params: { key_id: key.id, project: project.full_path, gl_repository: gl_repository_for(project), - action: 'git-upload-pack', + action: "git-upload-pack", secret_token: secret_token, - protocol: protocol + protocol: protocol, } ) end - def push(key, project, protocol = 'ssh', env: nil) + def push(key, project, protocol = "ssh", env: nil) params = { - changes: 'd14d6c0abdd253381df51a723d58691b2ee1ab08 570e7b2abdd848b95f2f578043fc23bd6f6fd24d refs/heads/master', + changes: "d14d6c0abdd253381df51a723d58691b2ee1ab08 570e7b2abdd848b95f2f578043fc23bd6f6fd24d refs/heads/master", key_id: key.id, project: project.full_path, gl_repository: gl_repository_for(project), - action: 'git-receive-pack', + action: "git-receive-pack", secret_token: secret_token, protocol: protocol, - env: env + env: env, } post( @@ -1000,13 +998,13 @@ describe API::Internal do post( api("/internal/allowed"), params: { - ref: 'master', + ref: "master", key_id: key.id, project: project.full_path, gl_repository: gl_repository_for(project), - action: 'git-upload-archive', + action: "git-upload-archive", secret_token: secret_token, - protocol: 'ssh' + protocol: "ssh", } ) end @@ -1016,7 +1014,7 @@ describe API::Internal do api("/internal/lfs_authenticate"), params: { secret_token: secret_token, - project: project.full_path + project: project.full_path, } ) end @@ -1027,7 +1025,7 @@ describe API::Internal do params: { key_id: key_id, secret_token: secret_token, - project: project.full_path + project: project.full_path, } ) end @@ -1038,7 +1036,7 @@ describe API::Internal do params: { user_id: user_id, secret_token: secret_token, - project: project.full_path + project: project.full_path, } ) end diff --git a/spec/requests/api/issues_spec.rb b/spec/requests/api/issues_spec.rb index 01bab2a1361..dbfb1b1c567 100644 --- a/spec/requests/api/issues_spec.rb +++ b/spec/requests/api/issues_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe API::Issues do set(:user) { create(:user) } @@ -12,46 +12,46 @@ describe API::Issues do set(:author) { create(:author) } set(:assignee) { create(:assignee) } let(:admin) { create(:user, :admin) } - let(:issue_title) { 'foo' } - let(:issue_description) { 'closed' } + let(:issue_title) { "foo" } + let(:issue_description) { "closed" } let!(:closed_issue) do create :closed_issue, - author: user, - assignees: [user], - project: project, - state: :closed, - milestone: milestone, - created_at: generate(:past_time), - updated_at: 3.hours.ago, - closed_at: 1.hour.ago + author: user, + assignees: [user], + project: project, + state: :closed, + milestone: milestone, + created_at: generate(:past_time), + updated_at: 3.hours.ago, + closed_at: 1.hour.ago end let!(:confidential_issue) do create :issue, - :confidential, - project: project, - author: author, - assignees: [assignee], - created_at: generate(:past_time), - updated_at: 2.hours.ago + :confidential, + project: project, + author: author, + assignees: [assignee], + created_at: generate(:past_time), + updated_at: 2.hours.ago end let!(:issue) do create :issue, - author: user, - assignees: [user], - project: project, - milestone: milestone, - created_at: generate(:past_time), - updated_at: 1.hour.ago, - title: issue_title, - description: issue_description + author: user, + assignees: [user], + project: project, + milestone: milestone, + created_at: generate(:past_time), + updated_at: 1.hour.ago, + title: issue_title, + description: issue_description end set(:label) do - create(:label, title: 'label', color: '#FFAABB', project: project) + create(:label, title: "label", color: "#FFAABB", project: project) end let!(:label_link) { create(:label_link, label: label, target: issue) } - set(:milestone) { create(:milestone, title: '1.0.0', project: project) } + set(:milestone) { create(:milestone, title: "1.0.0", project: project) } set(:empty_milestone) do - create(:milestone, title: '2.0.0', project: project) + create(:milestone, title: "2.0.0", project: project) end let!(:note) { create(:note_on_issue, author: user, project: project, noteable: issue) } @@ -66,7 +66,7 @@ describe API::Issues do describe "GET /issues" do context "when unauthenticated" do it "returns an array of all issues" do - get api("/issues"), params: { scope: 'all' } + get api("/issues"), params: {scope: "all"} expect(response).to have_http_status(200) expect(json_response).to be_an Array @@ -79,13 +79,13 @@ describe API::Issues do end it "returns authentication error when scope is assigned-to-me" do - get api("/issues"), params: { scope: 'assigned-to-me' } + get api("/issues"), params: {scope: "assigned-to-me"} expect(response).to have_http_status(401) end it "returns authentication error when scope is created-by-me" do - get api("/issues"), params: { scope: 'created-by-me' } + get api("/issues"), params: {scope: "created-by-me"} expect(response).to have_http_status(401) end @@ -96,360 +96,360 @@ describe API::Issues do get api("/issues", user) expect_paginated_array_response([issue.id, closed_issue.id]) - expect(json_response.first['title']).to eq(issue.title) - expect(json_response.last).to have_key('web_url') + expect(json_response.first["title"]).to eq(issue.title) + expect(json_response.last).to have_key("web_url") end - it 'returns an array of closed issues' do - get api('/issues', user), params: { state: :closed } + it "returns an array of closed issues" do + get api("/issues", user), params: {state: :closed} expect_paginated_array_response(closed_issue.id) end - it 'returns an array of opened issues' do - get api('/issues', user), params: { state: :opened } + it "returns an array of opened issues" do + get api("/issues", user), params: {state: :opened} expect_paginated_array_response(issue.id) end - it 'returns an array of all issues' do - get api('/issues', user), params: { state: :all } + it "returns an array of all issues" do + get api("/issues", user), params: {state: :all} expect_paginated_array_response([issue.id, closed_issue.id]) end - it 'returns issues assigned to me' do + it "returns issues assigned to me" do issue2 = create(:issue, assignees: [user2], project: project) - get api('/issues', user2), params: { scope: 'assigned_to_me' } + get api("/issues", user2), params: {scope: "assigned_to_me"} expect_paginated_array_response(issue2.id) end - it 'returns issues assigned to me (kebab-case)' do + it "returns issues assigned to me (kebab-case)" do issue2 = create(:issue, assignees: [user2], project: project) - get api('/issues', user2), params: { scope: 'assigned-to-me' } + get api("/issues", user2), params: {scope: "assigned-to-me"} expect_paginated_array_response(issue2.id) end - it 'returns issues authored by the given author id' do + it "returns issues authored by the given author id" do issue2 = create(:issue, author: user2, project: project) - get api('/issues', user), params: { author_id: user2.id, scope: 'all' } + get api("/issues", user), params: {author_id: user2.id, scope: "all"} expect_paginated_array_response(issue2.id) end - it 'returns issues assigned to the given assignee id' do + it "returns issues assigned to the given assignee id" do issue2 = create(:issue, assignees: [user2], project: project) - get api('/issues', user), params: { assignee_id: user2.id, scope: 'all' } + get api("/issues", user), params: {assignee_id: user2.id, scope: "all"} expect_paginated_array_response(issue2.id) end - it 'returns issues authored by the given author id and assigned to the given assignee id' do + it "returns issues authored by the given author id and assigned to the given assignee id" do issue2 = create(:issue, author: user2, assignees: [user2], project: project) - get api('/issues', user), params: { author_id: user2.id, assignee_id: user2.id, scope: 'all' } + get api("/issues", user), params: {author_id: user2.id, assignee_id: user2.id, scope: "all"} expect_paginated_array_response(issue2.id) end - it 'returns issues with no assignee' do + it "returns issues with no assignee" do issue2 = create(:issue, author: user2, project: project) - get api('/issues', user), params: { assignee_id: 0, scope: 'all' } + get api("/issues", user), params: {assignee_id: 0, scope: "all"} expect_paginated_array_response(issue2.id) end - it 'returns issues with no assignee' do + it "returns issues with no assignee" do issue2 = create(:issue, author: user2, project: project) - get api('/issues', user), params: { assignee_id: 'None', scope: 'all' } + get api("/issues", user), params: {assignee_id: "None", scope: "all"} expect_paginated_array_response(issue2.id) end - it 'returns issues with any assignee' do + it "returns issues with any assignee" do # This issue without assignee should not be returned create(:issue, author: user2, project: project) - get api('/issues', user), params: { assignee_id: 'Any', scope: 'all' } + get api("/issues", user), params: {assignee_id: "Any", scope: "all"} expect_paginated_array_response([issue.id, confidential_issue.id, closed_issue.id]) end - it 'returns only confidential issues' do - get api('/issues', user), params: { confidential: true, scope: 'all' } + it "returns only confidential issues" do + get api("/issues", user), params: {confidential: true, scope: "all"} expect_paginated_array_response(confidential_issue.id) end - it 'returns only public issues' do - get api('/issues', user), params: { confidential: false } + it "returns only public issues" do + get api("/issues", user), params: {confidential: false} expect_paginated_array_response([issue.id, closed_issue.id]) end - it 'returns issues reacted by the authenticated user' do + it "returns issues reacted by the authenticated user" do issue2 = create(:issue, project: project, author: user, assignees: [user]) - create(:award_emoji, awardable: issue2, user: user2, name: 'star') - create(:award_emoji, awardable: issue, user: user2, name: 'thumbsup') + create(:award_emoji, awardable: issue2, user: user2, name: "star") + create(:award_emoji, awardable: issue, user: user2, name: "thumbsup") - get api('/issues', user2), params: { my_reaction_emoji: 'Any', scope: 'all' } + get api("/issues", user2), params: {my_reaction_emoji: "Any", scope: "all"} expect_paginated_array_response([issue2.id, issue.id]) end - it 'returns issues not reacted by the authenticated user' do + it "returns issues not reacted by the authenticated user" do issue2 = create(:issue, project: project, author: user, assignees: [user]) - create(:award_emoji, awardable: issue2, user: user2, name: 'star') + create(:award_emoji, awardable: issue2, user: user2, name: "star") - get api('/issues', user2), params: { my_reaction_emoji: 'None', scope: 'all' } + get api("/issues", user2), params: {my_reaction_emoji: "None", scope: "all"} expect_paginated_array_response([issue.id, closed_issue.id]) end - it 'returns issues matching given search string for title' do - get api("/issues", user), params: { search: issue.title } + it "returns issues matching given search string for title" do + get api("/issues", user), params: {search: issue.title} expect_paginated_array_response(issue.id) end - it 'returns issues matching given search string for title and scoped in title' do - get api("/issues", user), params: { search: issue.title, in: 'title' } + it "returns issues matching given search string for title and scoped in title" do + get api("/issues", user), params: {search: issue.title, in: "title"} expect_paginated_array_response(issue.id) end - it 'returns an empty array if no issue matches given search string for title and scoped in description' do - get api("/issues", user), params: { search: issue.title, in: 'description' } + it "returns an empty array if no issue matches given search string for title and scoped in description" do + get api("/issues", user), params: {search: issue.title, in: "description"} expect_paginated_array_response([]) end - it 'returns issues matching given search string for description' do - get api("/issues", user), params: { search: issue.description } + it "returns issues matching given search string for description" do + get api("/issues", user), params: {search: issue.description} expect_paginated_array_response(issue.id) end - context 'filtering before a specific date' do + context "filtering before a specific date" do let!(:issue2) { create(:issue, project: project, author: user, created_at: Date.new(2000, 1, 1), updated_at: Date.new(2000, 1, 1)) } - it 'returns issues created before a specific date' do - get api('/issues?created_before=2000-01-02T00:00:00.060Z', user) + it "returns issues created before a specific date" do + get api("/issues?created_before=2000-01-02T00:00:00.060Z", user) expect_paginated_array_response(issue2.id) end - it 'returns issues updated before a specific date' do - get api('/issues?updated_before=2000-01-02T00:00:00.060Z', user) + it "returns issues updated before a specific date" do + get api("/issues?updated_before=2000-01-02T00:00:00.060Z", user) expect_paginated_array_response(issue2.id) end end - context 'filtering after a specific date' do + context "filtering after a specific date" do let!(:issue2) { create(:issue, project: project, author: user, created_at: 1.week.from_now, updated_at: 1.week.from_now) } - it 'returns issues created after a specific date' do + it "returns issues created after a specific date" do get api("/issues?created_after=#{issue2.created_at}", user) expect_paginated_array_response(issue2.id) end - it 'returns issues updated after a specific date' do + it "returns issues updated after a specific date" do get api("/issues?updated_after=#{issue2.updated_at}", user) expect_paginated_array_response(issue2.id) end end - it 'returns an array of labeled issues' do - get api("/issues", user), params: { labels: label.title } + it "returns an array of labeled issues" do + get api("/issues", user), params: {labels: label.title} expect_paginated_array_response(issue.id) - expect(json_response.first['labels']).to eq([label.title]) + expect(json_response.first["labels"]).to eq([label.title]) end - it 'returns an array of labeled issues when all labels matches' do - label_b = create(:label, title: 'foo', project: project) - label_c = create(:label, title: 'bar', project: project) + it "returns an array of labeled issues when all labels matches" do + label_b = create(:label, title: "foo", project: project) + label_c = create(:label, title: "bar", project: project) create(:label_link, label: label_b, target: issue) create(:label_link, label: label_c, target: issue) - get api("/issues", user), params: { labels: "#{label.title},#{label_b.title},#{label_c.title}" } + get api("/issues", user), params: {labels: "#{label.title},#{label_b.title},#{label_c.title}"} expect_paginated_array_response(issue.id) - expect(json_response.first['labels']).to eq([label_c.title, label_b.title, label.title]) + expect(json_response.first["labels"]).to eq([label_c.title, label_b.title, label.title]) end - it 'returns an empty array if no issue matches labels' do - get api('/issues', user), params: { labels: 'foo,bar' } + it "returns an empty array if no issue matches labels" do + get api("/issues", user), params: {labels: "foo,bar"} expect_paginated_array_response([]) end - it 'returns an array of labeled issues matching given state' do - get api("/issues", user), params: { labels: label.title, state: :opened } + it "returns an array of labeled issues matching given state" do + get api("/issues", user), params: {labels: label.title, state: :opened} expect_paginated_array_response(issue.id) - expect(json_response.first['labels']).to eq([label.title]) - expect(json_response.first['state']).to eq('opened') + expect(json_response.first["labels"]).to eq([label.title]) + expect(json_response.first["state"]).to eq("opened") end - it 'returns an empty array if no issue matches labels and state filters' do - get api("/issues", user), params: { labels: label.title, state: :closed } + it "returns an empty array if no issue matches labels and state filters" do + get api("/issues", user), params: {labels: label.title, state: :closed} expect_paginated_array_response([]) end - it 'returns an array of issues with any label' do - get api("/issues", user), params: { labels: IssuesFinder::FILTER_ANY } + it "returns an array of issues with any label" do + get api("/issues", user), params: {labels: IssuesFinder::FILTER_ANY} expect_paginated_array_response(issue.id) end - it 'returns an array of issues with no label' do - get api("/issues", user), params: { labels: IssuesFinder::FILTER_NONE } + it "returns an array of issues with no label" do + get api("/issues", user), params: {labels: IssuesFinder::FILTER_NONE} expect_paginated_array_response(closed_issue.id) end - it 'returns an array of issues with no label when using the legacy No+Label filter' do - get api("/issues", user), params: { labels: "No Label" } + it "returns an array of issues with no label when using the legacy No+Label filter" do + get api("/issues", user), params: {labels: "No Label"} expect_paginated_array_response(closed_issue.id) end - it 'returns an empty array if no issue matches milestone' do + it "returns an empty array if no issue matches milestone" do get api("/issues?milestone=#{empty_milestone.title}", user) expect_paginated_array_response([]) end - it 'returns an empty array if milestone does not exist' do + it "returns an empty array if milestone does not exist" do get api("/issues?milestone=foo", user) expect_paginated_array_response([]) end - it 'returns an array of issues in given milestone' do + it "returns an array of issues in given milestone" do get api("/issues?milestone=#{milestone.title}", user) expect_paginated_array_response([issue.id, closed_issue.id]) end - it 'returns an array of issues matching state in milestone' do + it "returns an array of issues matching state in milestone" do get api("/issues?milestone=#{milestone.title}"\ - '&state=closed', user) + "&state=closed", user) expect_paginated_array_response(closed_issue.id) end - it 'returns an array of issues with no milestone' do + it "returns an array of issues with no milestone" do get api("/issues?milestone=#{no_milestone_title}", author) expect_paginated_array_response(confidential_issue.id) end - it 'returns an array of issues found by iids' do - get api('/issues', user), params: { iids: [closed_issue.iid] } + it "returns an array of issues found by iids" do + get api("/issues", user), params: {iids: [closed_issue.iid]} expect_paginated_array_response(closed_issue.id) end - it 'returns an empty array if iid does not exist' do - get api("/issues", user), params: { iids: [0] } + it "returns an empty array if iid does not exist" do + get api("/issues", user), params: {iids: [0]} expect_paginated_array_response([]) end - context 'without sort params' do - it 'sorts by created_at descending by default' do - get api('/issues', user) + context "without sort params" do + it "sorts by created_at descending by default" do + get api("/issues", user) expect_paginated_array_response([issue.id, closed_issue.id]) end - context 'with 2 issues with same created_at' do + context "with 2 issues with same created_at" do let!(:closed_issue2) do create :closed_issue, - author: user, - assignees: [user], - project: project, - milestone: milestone, - created_at: closed_issue.created_at, - updated_at: 1.hour.ago, - title: issue_title, - description: issue_description + author: user, + assignees: [user], + project: project, + milestone: milestone, + created_at: closed_issue.created_at, + updated_at: 1.hour.ago, + title: issue_title, + description: issue_description end - it 'page breaks first page correctly' do - get api('/issues?per_page=2', user) + it "page breaks first page correctly" do + get api("/issues?per_page=2", user) expect_paginated_array_response([issue.id, closed_issue2.id]) end - it 'page breaks second page correctly' do - get api('/issues?per_page=2&page=2', user) + it "page breaks second page correctly" do + get api("/issues?per_page=2&page=2", user) expect_paginated_array_response([closed_issue.id]) end end end - it 'sorts ascending when requested' do - get api('/issues?sort=asc', user) + it "sorts ascending when requested" do + get api("/issues?sort=asc", user) expect_paginated_array_response([closed_issue.id, issue.id]) end - it 'sorts by updated_at descending when requested' do - get api('/issues?order_by=updated_at', user) + it "sorts by updated_at descending when requested" do + get api("/issues?order_by=updated_at", user) issue.touch(:updated_at) expect_paginated_array_response([issue.id, closed_issue.id]) end - it 'sorts by updated_at ascending when requested' do - get api('/issues?order_by=updated_at&sort=asc', user) + it "sorts by updated_at ascending when requested" do + get api("/issues?order_by=updated_at&sort=asc", user) issue.touch(:updated_at) expect_paginated_array_response([closed_issue.id, issue.id]) end - it 'matches V4 response schema' do - get api('/issues', user) + it "matches V4 response schema" do + get api("/issues", user) expect(response).to have_gitlab_http_status(200) - expect(response).to match_response_schema('public_api/v4/issues') + expect(response).to match_response_schema("public_api/v4/issues") end - it 'returns a related merge request count of 0 if there are no related merge requests' do - get api('/issues', user) + it "returns a related merge request count of 0 if there are no related merge requests" do + get api("/issues", user) expect(response).to have_gitlab_http_status(200) - expect(response).to match_response_schema('public_api/v4/issues') - expect(json_response.first).to include('merge_requests_count' => 0) + expect(response).to match_response_schema("public_api/v4/issues") + expect(json_response.first).to include("merge_requests_count" => 0) end - it 'returns a related merge request count > 0 if there are related merge requests' do + it "returns a related merge request count > 0 if there are related merge requests" do create(:merge_requests_closing_issues, issue: issue) - get api('/issues', user) + get api("/issues", user) expect(response).to have_gitlab_http_status(200) - expect(response).to match_response_schema('public_api/v4/issues') - expect(json_response.first).to include('merge_requests_count' => 1) + expect(response).to match_response_schema("public_api/v4/issues") + expect(json_response.first).to include("merge_requests_count" => 1) end end end @@ -459,47 +459,47 @@ describe API::Issues do let!(:group_project) { create(:project, :public, creator_id: user.id, namespace: group) } let!(:group_closed_issue) do create :closed_issue, - author: user, - assignees: [user], - project: group_project, - state: :closed, - milestone: group_milestone, - updated_at: 3.hours.ago, - created_at: 1.day.ago + author: user, + assignees: [user], + project: group_project, + state: :closed, + milestone: group_milestone, + updated_at: 3.hours.ago, + created_at: 1.day.ago end let!(:group_confidential_issue) do create :issue, - :confidential, - project: group_project, - author: author, - assignees: [assignee], - updated_at: 2.hours.ago, - created_at: 2.days.ago + :confidential, + project: group_project, + author: author, + assignees: [assignee], + updated_at: 2.hours.ago, + created_at: 2.days.ago end let!(:group_issue) do create :issue, - author: user, - assignees: [user], - project: group_project, - milestone: group_milestone, - updated_at: 1.hour.ago, - title: issue_title, - description: issue_description, - created_at: 5.days.ago + author: user, + assignees: [user], + project: group_project, + milestone: group_milestone, + updated_at: 1.hour.ago, + title: issue_title, + description: issue_description, + created_at: 5.days.ago end let!(:group_label) do - create(:label, title: 'group_lbl', color: '#FFAABB', project: group_project) + create(:label, title: "group_lbl", color: "#FFAABB", project: group_project) end let!(:group_label_link) { create(:label_link, label: group_label, target: group_issue) } - let!(:group_milestone) { create(:milestone, title: '3.0.0', project: group_project) } + let!(:group_milestone) { create(:milestone, title: "3.0.0", project: group_project) } let!(:group_empty_milestone) do - create(:milestone, title: '4.0.0', project: group_project) + create(:milestone, title: "4.0.0", project: group_project) end let!(:group_note) { create(:note_on_issue, author: user, project: group_project, noteable: group_issue) } let(:base_url) { "/groups/#{group.id}/issues" } - context 'when group has subgroups', :nested_groups do + context "when group has subgroups", :nested_groups do let(:subgroup_1) { create(:group, parent: group) } let(:subgroup_2) { create(:group, parent: subgroup_1) } @@ -513,203 +513,203 @@ describe API::Issues do group.add_developer(user) end - it 'also returns subgroups projects issues' do + it "also returns subgroups projects issues" do get api(base_url, user) expect_paginated_array_response([issue_2.id, issue_1.id, group_closed_issue.id, group_confidential_issue.id, group_issue.id]) end end - context 'when user is unauthenticated' do - it 'lists all issues in public projects' do + context "when user is unauthenticated" do + it "lists all issues in public projects" do get api(base_url) expect_paginated_array_response([group_closed_issue.id, group_issue.id]) end end - context 'when user is a group member' do + context "when user is a group member" do before do group_project.add_reporter(user) end - it 'returns all group issues (including opened and closed)' do + it "returns all group issues (including opened and closed)" do get api(base_url, admin) expect_paginated_array_response([group_closed_issue.id, group_confidential_issue.id, group_issue.id]) end - it 'returns group issues without confidential issues for non project members' do - get api(base_url, non_member), params: { state: :opened } + it "returns group issues without confidential issues for non project members" do + get api(base_url, non_member), params: {state: :opened} expect_paginated_array_response(group_issue.id) end - it 'returns group confidential issues for author' do - get api(base_url, author), params: { state: :opened } + it "returns group confidential issues for author" do + get api(base_url, author), params: {state: :opened} expect_paginated_array_response([group_confidential_issue.id, group_issue.id]) end - it 'returns group confidential issues for assignee' do - get api(base_url, assignee), params: { state: :opened } + it "returns group confidential issues for assignee" do + get api(base_url, assignee), params: {state: :opened} expect_paginated_array_response([group_confidential_issue.id, group_issue.id]) end - it 'returns group issues with confidential issues for project members' do - get api(base_url, user), params: { state: :opened } + it "returns group issues with confidential issues for project members" do + get api(base_url, user), params: {state: :opened} expect_paginated_array_response([group_confidential_issue.id, group_issue.id]) end - it 'returns group confidential issues for admin' do - get api(base_url, admin), params: { state: :opened } + it "returns group confidential issues for admin" do + get api(base_url, admin), params: {state: :opened} expect_paginated_array_response([group_confidential_issue.id, group_issue.id]) end - it 'returns only confidential issues' do - get api(base_url, user), params: { confidential: true } + it "returns only confidential issues" do + get api(base_url, user), params: {confidential: true} expect_paginated_array_response(group_confidential_issue.id) end - it 'returns only public issues' do - get api(base_url, user), params: { confidential: false } + it "returns only public issues" do + get api(base_url, user), params: {confidential: false} expect_paginated_array_response([group_closed_issue.id, group_issue.id]) end - it 'returns an array of labeled group issues' do - get api(base_url, user), params: { labels: group_label.title } + it "returns an array of labeled group issues" do + get api(base_url, user), params: {labels: group_label.title} expect_paginated_array_response(group_issue.id) - expect(json_response.first['labels']).to eq([group_label.title]) + expect(json_response.first["labels"]).to eq([group_label.title]) end - it 'returns an array of labeled group issues where all labels match' do - get api(base_url, user), params: { labels: "#{group_label.title},foo,bar" } + it "returns an array of labeled group issues where all labels match" do + get api(base_url, user), params: {labels: "#{group_label.title},foo,bar"} expect_paginated_array_response([]) end - it 'returns issues matching given search string for title' do - get api(base_url, user), params: { search: group_issue.title } + it "returns issues matching given search string for title" do + get api(base_url, user), params: {search: group_issue.title} expect_paginated_array_response(group_issue.id) end - it 'returns issues matching given search string for description' do - get api(base_url, user), params: { search: group_issue.description } + it "returns issues matching given search string for description" do + get api(base_url, user), params: {search: group_issue.description} expect_paginated_array_response(group_issue.id) end - it 'returns an array of labeled issues when all labels matches' do - label_b = create(:label, title: 'foo', project: group_project) - label_c = create(:label, title: 'bar', project: group_project) + it "returns an array of labeled issues when all labels matches" do + label_b = create(:label, title: "foo", project: group_project) + label_c = create(:label, title: "bar", project: group_project) create(:label_link, label: label_b, target: group_issue) create(:label_link, label: label_c, target: group_issue) - get api(base_url, user), params: { labels: "#{group_label.title},#{label_b.title},#{label_c.title}" } + get api(base_url, user), params: {labels: "#{group_label.title},#{label_b.title},#{label_c.title}"} expect_paginated_array_response(group_issue.id) - expect(json_response.first['labels']).to eq([label_c.title, label_b.title, group_label.title]) + expect(json_response.first["labels"]).to eq([label_c.title, label_b.title, group_label.title]) end - it 'returns an array of issues found by iids' do - get api(base_url, user), params: { iids: [group_issue.iid] } + it "returns an array of issues found by iids" do + get api(base_url, user), params: {iids: [group_issue.iid]} expect_paginated_array_response(group_issue.id) - expect(json_response.first['id']).to eq(group_issue.id) + expect(json_response.first["id"]).to eq(group_issue.id) end - it 'returns an empty array if iid does not exist' do - get api(base_url, user), params: { iids: [0] } + it "returns an empty array if iid does not exist" do + get api(base_url, user), params: {iids: [0]} expect_paginated_array_response([]) end - it 'returns an empty array if no group issue matches labels' do - get api(base_url, user), params: { labels: 'foo,bar' } + it "returns an empty array if no group issue matches labels" do + get api(base_url, user), params: {labels: "foo,bar"} expect_paginated_array_response([]) end - it 'returns an array of group issues with any label' do - get api(base_url, user), params: { labels: IssuesFinder::FILTER_ANY } + it "returns an array of group issues with any label" do + get api(base_url, user), params: {labels: IssuesFinder::FILTER_ANY} expect_paginated_array_response(group_issue.id) - expect(json_response.first['id']).to eq(group_issue.id) + expect(json_response.first["id"]).to eq(group_issue.id) end - it 'returns an array of group issues with no label' do - get api(base_url, user), params: { labels: IssuesFinder::FILTER_NONE } + it "returns an array of group issues with no label" do + get api(base_url, user), params: {labels: IssuesFinder::FILTER_NONE} expect_paginated_array_response([group_closed_issue.id, group_confidential_issue.id]) end - it 'returns an empty array if no issue matches milestone' do - get api(base_url, user), params: { milestone: group_empty_milestone.title } + it "returns an empty array if no issue matches milestone" do + get api(base_url, user), params: {milestone: group_empty_milestone.title} expect_paginated_array_response([]) end - it 'returns an empty array if milestone does not exist' do - get api(base_url, user), params: { milestone: 'foo' } + it "returns an empty array if milestone does not exist" do + get api(base_url, user), params: {milestone: "foo"} expect_paginated_array_response([]) end - it 'returns an array of issues in given milestone' do - get api(base_url, user), params: { state: :opened, milestone: group_milestone.title } + it "returns an array of issues in given milestone" do + get api(base_url, user), params: {state: :opened, milestone: group_milestone.title} expect_paginated_array_response(group_issue.id) end - it 'returns an array of issues matching state in milestone' do - get api(base_url, user), params: { milestone: group_milestone.title, state: :closed } + it "returns an array of issues matching state in milestone" do + get api(base_url, user), params: {milestone: group_milestone.title, state: :closed} expect_paginated_array_response(group_closed_issue.id) end - it 'returns an array of issues with no milestone' do - get api(base_url, user), params: { milestone: no_milestone_title } + it "returns an array of issues with no milestone" do + get api(base_url, user), params: {milestone: no_milestone_title} expect(response).to have_gitlab_http_status(200) expect_paginated_array_response(group_confidential_issue.id) end - context 'without sort params' do - it 'sorts by created_at descending by default' do + context "without sort params" do + it "sorts by created_at descending by default" do get api(base_url, user) expect_paginated_array_response([group_closed_issue.id, group_confidential_issue.id, group_issue.id]) end - context 'with 2 issues with same created_at' do + context "with 2 issues with same created_at" do let!(:group_issue2) do create :issue, - author: user, - assignees: [user], - project: group_project, - milestone: group_milestone, - updated_at: 1.hour.ago, - title: issue_title, - description: issue_description, - created_at: group_issue.created_at + author: user, + assignees: [user], + project: group_project, + milestone: group_milestone, + updated_at: 1.hour.ago, + title: issue_title, + description: issue_description, + created_at: group_issue.created_at end - it 'page breaks first page correctly' do + it "page breaks first page correctly" do get api("#{base_url}?per_page=3", user) expect_paginated_array_response([group_closed_issue.id, group_confidential_issue.id, group_issue2.id]) end - it 'page breaks second page correctly' do + it "page breaks second page correctly" do get api("#{base_url}?per_page=3&page=2", user) expect_paginated_array_response([group_issue.id]) @@ -717,13 +717,13 @@ describe API::Issues do end end - it 'sorts ascending when requested' do + it "sorts ascending when requested" do get api("#{base_url}?sort=asc", user) expect_paginated_array_response([group_issue.id, group_confidential_issue.id, group_closed_issue.id]) end - it 'sorts by updated_at descending when requested' do + it "sorts by updated_at descending when requested" do get api("#{base_url}?order_by=updated_at", user) group_issue.touch(:updated_at) @@ -731,8 +731,8 @@ describe API::Issues do expect_paginated_array_response([group_issue.id, group_confidential_issue.id, group_closed_issue.id]) end - it 'sorts by updated_at ascending when requested' do - get api(base_url, user), params: { order_by: :updated_at, sort: :asc } + it "sorts by updated_at ascending when requested" do + get api(base_url, user), params: {order_by: :updated_at, sort: :asc} expect_paginated_array_response([group_closed_issue.id, group_confidential_issue.id, group_issue.id]) end @@ -742,30 +742,30 @@ describe API::Issues do describe "GET /projects/:id/issues" do let(:base_url) { "/projects/#{project.id}" } - context 'when unauthenticated' do - it 'returns public project issues' do + context "when unauthenticated" do + it "returns public project issues" do get api("/projects/#{project.id}/issues") expect_paginated_array_response([issue.id, closed_issue.id]) end end - it 'avoids N+1 queries' do + it "avoids N+1 queries" do get api("/projects/#{project.id}/issues", user) - control_count = ActiveRecord::QueryRecorder.new(skip_cached: false) do + control_count = ActiveRecord::QueryRecorder.new(skip_cached: false) { get api("/projects/#{project.id}/issues", user) - end.count + }.count create_list(:issue, 3, project: project) - expect do + expect { get api("/projects/#{project.id}/issues", user) - end.not_to exceed_all_query_limit(control_count) + }.not_to exceed_all_query_limit(control_count) end - it 'returns 404 when project does not exist' do - get api('/projects/1000/issues', non_member) + it "returns 404 when project does not exist" do + get api("/projects/1000/issues", non_member) expect(response).to have_gitlab_http_status(404) end @@ -779,7 +779,7 @@ describe API::Issues do expect(response).to have_gitlab_http_status(404) end - it 'returns no issues when user has access to project but not issues' do + it "returns no issues when user has access to project but not issues" do restricted_project = create(:project, :public, :issues_private) create(:issue, project: restricted_project) @@ -788,183 +788,183 @@ describe API::Issues do expect_paginated_array_response([]) end - it 'returns project issues without confidential issues for non project members' do + it "returns project issues without confidential issues for non project members" do get api("#{base_url}/issues", non_member) expect_paginated_array_response([issue.id, closed_issue.id]) end - it 'returns project issues without confidential issues for project members with guest role' do + it "returns project issues without confidential issues for project members with guest role" do get api("#{base_url}/issues", guest) expect_paginated_array_response([issue.id, closed_issue.id]) end - it 'returns project confidential issues for author' do + it "returns project confidential issues for author" do get api("#{base_url}/issues", author) expect_paginated_array_response([issue.id, confidential_issue.id, closed_issue.id]) end - it 'returns only confidential issues' do - get api("#{base_url}/issues", author), params: { confidential: true } + it "returns only confidential issues" do + get api("#{base_url}/issues", author), params: {confidential: true} expect_paginated_array_response(confidential_issue.id) end - it 'returns only public issues' do - get api("#{base_url}/issues", author), params: { confidential: false } + it "returns only public issues" do + get api("#{base_url}/issues", author), params: {confidential: false} expect_paginated_array_response([issue.id, closed_issue.id]) end - it 'returns project confidential issues for assignee' do + it "returns project confidential issues for assignee" do get api("#{base_url}/issues", assignee) expect_paginated_array_response([issue.id, confidential_issue.id, closed_issue.id]) end - it 'returns project issues with confidential issues for project members' do + it "returns project issues with confidential issues for project members" do get api("#{base_url}/issues", user) expect_paginated_array_response([issue.id, confidential_issue.id, closed_issue.id]) end - it 'returns project confidential issues for admin' do + it "returns project confidential issues for admin" do get api("#{base_url}/issues", admin) expect_paginated_array_response([issue.id, confidential_issue.id, closed_issue.id]) end - it 'returns an array of labeled project issues' do - get api("#{base_url}/issues", user), params: { labels: label.title } + it "returns an array of labeled project issues" do + get api("#{base_url}/issues", user), params: {labels: label.title} expect_paginated_array_response(issue.id) end - it 'returns an array of labeled issues when all labels matches' do - label_b = create(:label, title: 'foo', project: project) - label_c = create(:label, title: 'bar', project: project) + it "returns an array of labeled issues when all labels matches" do + label_b = create(:label, title: "foo", project: project) + label_c = create(:label, title: "bar", project: project) create(:label_link, label: label_b, target: issue) create(:label_link, label: label_c, target: issue) - get api("#{base_url}/issues", user), params: { labels: "#{label.title},#{label_b.title},#{label_c.title}" } + get api("#{base_url}/issues", user), params: {labels: "#{label.title},#{label_b.title},#{label_c.title}"} expect_paginated_array_response(issue.id) end - it 'returns issues matching given search string for title' do + it "returns issues matching given search string for title" do get api("#{base_url}/issues?search=#{issue.title}", user) expect_paginated_array_response(issue.id) end - it 'returns issues matching given search string for description' do + it "returns issues matching given search string for description" do get api("#{base_url}/issues?search=#{issue.description}", user) expect_paginated_array_response(issue.id) end - it 'returns an array of issues found by iids' do - get api("#{base_url}/issues", user), params: { iids: [issue.iid] } + it "returns an array of issues found by iids" do + get api("#{base_url}/issues", user), params: {iids: [issue.iid]} expect_paginated_array_response(issue.id) end - it 'returns an empty array if iid does not exist' do - get api("#{base_url}/issues", user), params: { iids: [0] } + it "returns an empty array if iid does not exist" do + get api("#{base_url}/issues", user), params: {iids: [0]} expect_paginated_array_response([]) end - it 'returns an empty array if not all labels matches' do + it "returns an empty array if not all labels matches" do get api("#{base_url}/issues?labels=#{label.title},foo", user) expect_paginated_array_response([]) end - it 'returns an array of project issues with any label' do - get api("#{base_url}/issues", user), params: { labels: IssuesFinder::FILTER_ANY } + it "returns an array of project issues with any label" do + get api("#{base_url}/issues", user), params: {labels: IssuesFinder::FILTER_ANY} expect_paginated_array_response(issue.id) end - it 'returns an array of project issues with no label' do - get api("#{base_url}/issues", user), params: { labels: IssuesFinder::FILTER_NONE } + it "returns an array of project issues with no label" do + get api("#{base_url}/issues", user), params: {labels: IssuesFinder::FILTER_NONE} expect_paginated_array_response([confidential_issue.id, closed_issue.id]) end - it 'returns an empty array if no project issue matches labels' do - get api("#{base_url}/issues", user), params: { labels: 'foo,bar' } + it "returns an empty array if no project issue matches labels" do + get api("#{base_url}/issues", user), params: {labels: "foo,bar"} expect_paginated_array_response([]) end - it 'returns an empty array if no issue matches milestone' do - get api("#{base_url}/issues", user), params: { milestone: empty_milestone.title } + it "returns an empty array if no issue matches milestone" do + get api("#{base_url}/issues", user), params: {milestone: empty_milestone.title} expect_paginated_array_response([]) end - it 'returns an empty array if milestone does not exist' do - get api("#{base_url}/issues", user), params: { milestone: :foo } + it "returns an empty array if milestone does not exist" do + get api("#{base_url}/issues", user), params: {milestone: :foo} expect_paginated_array_response([]) end - it 'returns an array of issues in given milestone' do - get api("#{base_url}/issues", user), params: { milestone: milestone.title } + it "returns an array of issues in given milestone" do + get api("#{base_url}/issues", user), params: {milestone: milestone.title} expect_paginated_array_response([issue.id, closed_issue.id]) end - it 'returns an array of issues matching state in milestone' do - get api("#{base_url}/issues", user), params: { milestone: milestone.title, state: :closed } + it "returns an array of issues matching state in milestone" do + get api("#{base_url}/issues", user), params: {milestone: milestone.title, state: :closed} expect_paginated_array_response(closed_issue.id) end - it 'returns an array of issues with no milestone' do - get api("#{base_url}/issues", user), params: { milestone: no_milestone_title } + it "returns an array of issues with no milestone" do + get api("#{base_url}/issues", user), params: {milestone: no_milestone_title} expect_paginated_array_response(confidential_issue.id) end - it 'returns an array of issues with any milestone' do - get api("#{base_url}/issues", user), params: { milestone: any_milestone_title } + it "returns an array of issues with any milestone" do + get api("#{base_url}/issues", user), params: {milestone: any_milestone_title} expect_paginated_array_response([issue.id, closed_issue.id]) end - context 'without sort params' do - it 'sorts by created_at descending by default' do + context "without sort params" do + it "sorts by created_at descending by default" do get api("#{base_url}/issues", user) expect_paginated_array_response([issue.id, confidential_issue.id, closed_issue.id]) end - context 'with 2 issues with same created_at' do + context "with 2 issues with same created_at" do let!(:closed_issue2) do create :closed_issue, - author: user, - assignees: [user], - project: project, - milestone: milestone, - created_at: closed_issue.created_at, - updated_at: 1.hour.ago, - title: issue_title, - description: issue_description + author: user, + assignees: [user], + project: project, + milestone: milestone, + created_at: closed_issue.created_at, + updated_at: 1.hour.ago, + title: issue_title, + description: issue_description end - it 'page breaks first page correctly' do + it "page breaks first page correctly" do get api("#{base_url}/issues?per_page=3", user) expect_paginated_array_response([issue.id, confidential_issue.id, closed_issue2.id]) end - it 'page breaks second page correctly' do + it "page breaks second page correctly" do get api("#{base_url}/issues?per_page=3&page=2", user) expect_paginated_array_response([closed_issue.id]) @@ -972,74 +972,74 @@ describe API::Issues do end end - it 'sorts ascending when requested' do - get api("#{base_url}/issues", user), params: { sort: :asc } + it "sorts ascending when requested" do + get api("#{base_url}/issues", user), params: {sort: :asc} expect_paginated_array_response([closed_issue.id, confidential_issue.id, issue.id]) end - it 'sorts by updated_at descending when requested' do - get api("#{base_url}/issues", user), params: { order_by: :updated_at } + it "sorts by updated_at descending when requested" do + get api("#{base_url}/issues", user), params: {order_by: :updated_at} issue.touch(:updated_at) expect_paginated_array_response([issue.id, confidential_issue.id, closed_issue.id]) end - it 'sorts by updated_at ascending when requested' do - get api("#{base_url}/issues", user), params: { order_by: :updated_at, sort: :asc } + it "sorts by updated_at ascending when requested" do + get api("#{base_url}/issues", user), params: {order_by: :updated_at, sort: :asc} expect_paginated_array_response([closed_issue.id, confidential_issue.id, issue.id]) end end describe "GET /projects/:id/issues/:issue_iid" do - context 'when unauthenticated' do - it 'returns public issues' do + context "when unauthenticated" do + it "returns public issues" do get api("/projects/#{project.id}/issues/#{issue.iid}") expect(response).to have_gitlab_http_status(200) end end - it 'exposes known attributes' do + it "exposes known attributes" do get api("/projects/#{project.id}/issues/#{issue.iid}", user) expect(response).to have_gitlab_http_status(200) - expect(json_response['id']).to eq(issue.id) - expect(json_response['iid']).to eq(issue.iid) - expect(json_response['project_id']).to eq(issue.project.id) - expect(json_response['title']).to eq(issue.title) - expect(json_response['description']).to eq(issue.description) - expect(json_response['state']).to eq(issue.state) - expect(json_response['closed_at']).to be_falsy - expect(json_response['created_at']).to be_present - expect(json_response['updated_at']).to be_present - expect(json_response['labels']).to eq(issue.label_names) - expect(json_response['milestone']).to be_a Hash - expect(json_response['assignees']).to be_a Array - expect(json_response['assignee']).to be_a Hash - expect(json_response['author']).to be_a Hash - expect(json_response['confidential']).to be_falsy + expect(json_response["id"]).to eq(issue.id) + expect(json_response["iid"]).to eq(issue.iid) + expect(json_response["project_id"]).to eq(issue.project.id) + expect(json_response["title"]).to eq(issue.title) + expect(json_response["description"]).to eq(issue.description) + expect(json_response["state"]).to eq(issue.state) + expect(json_response["closed_at"]).to be_falsy + expect(json_response["created_at"]).to be_present + expect(json_response["updated_at"]).to be_present + expect(json_response["labels"]).to eq(issue.label_names) + expect(json_response["milestone"]).to be_a Hash + expect(json_response["assignees"]).to be_a Array + expect(json_response["assignee"]).to be_a Hash + expect(json_response["author"]).to be_a Hash + expect(json_response["confidential"]).to be_falsy end it "exposes the 'closed_at' attribute" do get api("/projects/#{project.id}/issues/#{closed_issue.iid}", user) expect(response).to have_gitlab_http_status(200) - expect(json_response['closed_at']).to be_present + expect(json_response["closed_at"]).to be_present end - context 'links exposure' do - it 'exposes related resources full URIs' do + context "links exposure" do + it "exposes related resources full URIs" do get api("/projects/#{project.id}/issues/#{issue.iid}", user) - links = json_response['_links'] + links = json_response["_links"] - expect(links['self']).to end_with("/api/v4/projects/#{project.id}/issues/#{issue.iid}") - expect(links['notes']).to end_with("/api/v4/projects/#{project.id}/issues/#{issue.iid}/notes") - expect(links['award_emoji']).to end_with("/api/v4/projects/#{project.id}/issues/#{issue.iid}/award_emoji") - expect(links['project']).to end_with("/api/v4/projects/#{project.id}") + expect(links["self"]).to end_with("/api/v4/projects/#{project.id}/issues/#{issue.iid}") + expect(links["notes"]).to end_with("/api/v4/projects/#{project.id}/issues/#{issue.iid}/notes") + expect(links["award_emoji"]).to end_with("/api/v4/projects/#{project.id}/issues/#{issue.iid}/award_emoji") + expect(links["project"]).to end_with("/api/v4/projects/#{project.id}") end end @@ -1047,8 +1047,8 @@ describe API::Issues do get api("/projects/#{project.id}/issues/#{issue.iid}", user) expect(response).to have_gitlab_http_status(200) - expect(json_response['title']).to eq(issue.title) - expect(json_response['iid']).to eq(issue.iid) + expect(json_response["title"]).to eq(issue.title) + expect(json_response["iid"]).to eq(issue.iid) end it "returns 404 if issue id not found" do @@ -1062,7 +1062,7 @@ describe API::Issues do expect(response).to have_gitlab_http_status(404) end - context 'confidential issues' do + context "confidential issues" do it "returns 404 for non project members" do get api("/projects/#{project.id}/issues/#{confidential_issue.iid}", non_member) @@ -1079,206 +1079,206 @@ describe API::Issues do get api("/projects/#{project.id}/issues/#{confidential_issue.iid}", user) expect(response).to have_gitlab_http_status(200) - expect(json_response['title']).to eq(confidential_issue.title) - expect(json_response['iid']).to eq(confidential_issue.iid) + expect(json_response["title"]).to eq(confidential_issue.title) + expect(json_response["iid"]).to eq(confidential_issue.iid) end it "returns confidential issue for author" do get api("/projects/#{project.id}/issues/#{confidential_issue.iid}", author) expect(response).to have_gitlab_http_status(200) - expect(json_response['title']).to eq(confidential_issue.title) - expect(json_response['iid']).to eq(confidential_issue.iid) + expect(json_response["title"]).to eq(confidential_issue.title) + expect(json_response["iid"]).to eq(confidential_issue.iid) end it "returns confidential issue for assignee" do get api("/projects/#{project.id}/issues/#{confidential_issue.iid}", assignee) expect(response).to have_gitlab_http_status(200) - expect(json_response['title']).to eq(confidential_issue.title) - expect(json_response['iid']).to eq(confidential_issue.iid) + expect(json_response["title"]).to eq(confidential_issue.title) + expect(json_response["iid"]).to eq(confidential_issue.iid) end it "returns confidential issue for admin" do get api("/projects/#{project.id}/issues/#{confidential_issue.iid}", admin) expect(response).to have_gitlab_http_status(200) - expect(json_response['title']).to eq(confidential_issue.title) - expect(json_response['iid']).to eq(confidential_issue.iid) + expect(json_response["title"]).to eq(confidential_issue.title) + expect(json_response["iid"]).to eq(confidential_issue.iid) end end end describe "POST /projects/:id/issues" do - context 'support for deprecated assignee_id' do - it 'creates a new project issue' do + context "support for deprecated assignee_id" do + it "creates a new project issue" do post api("/projects/#{project.id}/issues", user), - params: { title: 'new issue', assignee_id: user2.id } + params: {title: "new issue", assignee_id: user2.id} expect(response).to have_gitlab_http_status(201) - expect(json_response['title']).to eq('new issue') - expect(json_response['assignee']['name']).to eq(user2.name) - expect(json_response['assignees'].first['name']).to eq(user2.name) + expect(json_response["title"]).to eq("new issue") + expect(json_response["assignee"]["name"]).to eq(user2.name) + expect(json_response["assignees"].first["name"]).to eq(user2.name) end - it 'creates a new project issue when assignee_id is empty' do + it "creates a new project issue when assignee_id is empty" do post api("/projects/#{project.id}/issues", user), - params: { title: 'new issue', assignee_id: '' } + params: {title: "new issue", assignee_id: ""} expect(response).to have_gitlab_http_status(201) - expect(json_response['title']).to eq('new issue') - expect(json_response['assignee']).to be_nil + expect(json_response["title"]).to eq("new issue") + expect(json_response["assignee"]).to be_nil end end - context 'single assignee restrictions' do - it 'creates a new project issue with no more than one assignee' do + context "single assignee restrictions" do + it "creates a new project issue with no more than one assignee" do post api("/projects/#{project.id}/issues", user), - params: { title: 'new issue', assignee_ids: [user2.id, guest.id] } + params: {title: "new issue", assignee_ids: [user2.id, guest.id]} expect(response).to have_gitlab_http_status(201) - expect(json_response['title']).to eq('new issue') - expect(json_response['assignees'].count).to eq(1) + expect(json_response["title"]).to eq("new issue") + expect(json_response["assignees"].count).to eq(1) end end - context 'user does not have permissions to create issue' do + context "user does not have permissions to create issue" do let(:not_member) { create(:user) } before do project.project_feature.update(issues_access_level: ProjectFeature::PRIVATE) end - it 'renders 403' do - post api("/projects/#{project.id}/issues", not_member), params: { title: 'new issue' } + it "renders 403" do + post api("/projects/#{project.id}/issues", not_member), params: {title: "new issue"} expect(response).to have_gitlab_http_status(403) end end - context 'an internal ID is provided' do - context 'by an admin' do - it 'sets the internal ID on the new issue' do + context "an internal ID is provided" do + context "by an admin" do + it "sets the internal ID on the new issue" do post api("/projects/#{project.id}/issues", admin), - params: { title: 'new issue', iid: 9001 } + params: {title: "new issue", iid: 9001} expect(response).to have_gitlab_http_status(201) - expect(json_response['iid']).to eq 9001 + expect(json_response["iid"]).to eq 9001 end end - context 'by an owner' do - it 'sets the internal ID on the new issue' do + context "by an owner" do + it "sets the internal ID on the new issue" do post api("/projects/#{project.id}/issues", user), - params: { title: 'new issue', iid: 9001 } + params: {title: "new issue", iid: 9001} expect(response).to have_gitlab_http_status(201) - expect(json_response['iid']).to eq 9001 + expect(json_response["iid"]).to eq 9001 end end - context 'by a group owner' do + context "by a group owner" do let(:group) { create(:group) } let(:group_project) { create(:project, :public, namespace: group) } - it 'sets the internal ID on the new issue' do + it "sets the internal ID on the new issue" do group.add_owner(user2) post api("/projects/#{group_project.id}/issues", user2), - params: { title: 'new issue', iid: 9001 } + params: {title: "new issue", iid: 9001} expect(response).to have_gitlab_http_status(201) - expect(json_response['iid']).to eq 9001 + expect(json_response["iid"]).to eq 9001 end end - context 'by another user' do - it 'ignores the given internal ID' do + context "by another user" do + it "ignores the given internal ID" do post api("/projects/#{project.id}/issues", user2), - params: { title: 'new issue', iid: 9001 } + params: {title: "new issue", iid: 9001} expect(response).to have_gitlab_http_status(201) - expect(json_response['iid']).not_to eq 9001 + expect(json_response["iid"]).not_to eq 9001 end end end - it 'creates a new project issue' do + it "creates a new project issue" do post api("/projects/#{project.id}/issues", user), - params: { title: 'new issue', labels: 'label, label2', weight: 3, assignee_ids: [user2.id] } + params: {title: "new issue", labels: "label, label2", weight: 3, assignee_ids: [user2.id]} expect(response).to have_gitlab_http_status(201) - expect(json_response['title']).to eq('new issue') - expect(json_response['description']).to be_nil - expect(json_response['labels']).to eq(%w(label label2)) - expect(json_response['confidential']).to be_falsy - expect(json_response['assignee']['name']).to eq(user2.name) - expect(json_response['assignees'].first['name']).to eq(user2.name) + expect(json_response["title"]).to eq("new issue") + expect(json_response["description"]).to be_nil + expect(json_response["labels"]).to eq(%w[label label2]) + expect(json_response["confidential"]).to be_falsy + expect(json_response["assignee"]["name"]).to eq(user2.name) + expect(json_response["assignees"].first["name"]).to eq(user2.name) end - it 'creates a new confidential project issue' do + it "creates a new confidential project issue" do post api("/projects/#{project.id}/issues", user), - params: { title: 'new issue', confidential: true } + params: {title: "new issue", confidential: true} expect(response).to have_gitlab_http_status(201) - expect(json_response['title']).to eq('new issue') - expect(json_response['confidential']).to be_truthy + expect(json_response["title"]).to eq("new issue") + expect(json_response["confidential"]).to be_truthy end - it 'creates a new confidential project issue with a different param' do + it "creates a new confidential project issue with a different param" do post api("/projects/#{project.id}/issues", user), - params: { title: 'new issue', confidential: 'y' } + params: {title: "new issue", confidential: "y"} expect(response).to have_gitlab_http_status(201) - expect(json_response['title']).to eq('new issue') - expect(json_response['confidential']).to be_truthy + expect(json_response["title"]).to eq("new issue") + expect(json_response["confidential"]).to be_truthy end - it 'creates a public issue when confidential param is false' do + it "creates a public issue when confidential param is false" do post api("/projects/#{project.id}/issues", user), - params: { title: 'new issue', confidential: false } + params: {title: "new issue", confidential: false} expect(response).to have_gitlab_http_status(201) - expect(json_response['title']).to eq('new issue') - expect(json_response['confidential']).to be_falsy + expect(json_response["title"]).to eq("new issue") + expect(json_response["confidential"]).to be_falsy end - it 'creates a public issue when confidential param is invalid' do + it "creates a public issue when confidential param is invalid" do post api("/projects/#{project.id}/issues", user), - params: { title: 'new issue', confidential: 'foo' } + params: {title: "new issue", confidential: "foo"} expect(response).to have_gitlab_http_status(400) - expect(json_response['error']).to eq('confidential is invalid') + expect(json_response["error"]).to eq("confidential is invalid") end it "returns a 400 bad request if title not given" do - post api("/projects/#{project.id}/issues", user), params: { labels: 'label, label2' } + post api("/projects/#{project.id}/issues", user), params: {labels: "label, label2"} expect(response).to have_gitlab_http_status(400) end - it 'allows special label names' do + it "allows special label names" do post api("/projects/#{project.id}/issues", user), - params: { - title: 'new issue', - labels: 'label, label?, label&foo, ?, &' - } + params: { + title: "new issue", + labels: "label, label?, label&foo, ?, &", + } expect(response.status).to eq(201) - expect(json_response['labels']).to include 'label' - expect(json_response['labels']).to include 'label?' - expect(json_response['labels']).to include 'label&foo' - expect(json_response['labels']).to include '?' - expect(json_response['labels']).to include '&' + expect(json_response["labels"]).to include "label" + expect(json_response["labels"]).to include "label?" + expect(json_response["labels"]).to include "label&foo" + expect(json_response["labels"]).to include "?" + expect(json_response["labels"]).to include "&" end - it 'returns 400 if title is too long' do + it "returns 400 if title is too long" do post api("/projects/#{project.id}/issues", user), - params: { title: 'g' * 256 } + params: {title: "g" * 256} expect(response).to have_gitlab_http_status(400) - expect(json_response['message']['title']).to eq([ - 'is too long (maximum is 255 characters)' + expect(json_response["message"]["title"]).to eq([ + "is too long (maximum is 255 characters)", ]) end - context 'resolving discussions' do + context "resolving discussions" do let(:discussion) { create(:diff_note_on_merge_request).to_discussion } let(:merge_request) { discussion.noteable } let(:project) { merge_request.source_project } @@ -1287,100 +1287,100 @@ describe API::Issues do project.add_maintainer(user) end - context 'resolving all discussions in a merge request' do + context "resolving all discussions in a merge request" do before do post api("/projects/#{project.id}/issues", user), - params: { - title: 'New Issue', - merge_request_to_resolve_discussions_of: merge_request.iid - } + params: { + title: "New Issue", + merge_request_to_resolve_discussions_of: merge_request.iid, + } end - it_behaves_like 'creating an issue resolving discussions through the API' + it_behaves_like "creating an issue resolving discussions through the API" end - context 'resolving a single discussion' do + context "resolving a single discussion" do before do post api("/projects/#{project.id}/issues", user), - params: { - title: 'New Issue', - merge_request_to_resolve_discussions_of: merge_request.iid, - discussion_to_resolve: discussion.id - } + params: { + title: "New Issue", + merge_request_to_resolve_discussions_of: merge_request.iid, + discussion_to_resolve: discussion.id, + } end - it_behaves_like 'creating an issue resolving discussions through the API' + it_behaves_like "creating an issue resolving discussions through the API" end end - context 'with due date' do - it 'creates a new project issue' do - due_date = 2.weeks.from_now.strftime('%Y-%m-%d') + context "with due date" do + it "creates a new project issue" do + due_date = 2.weeks.from_now.strftime("%Y-%m-%d") post api("/projects/#{project.id}/issues", user), - params: { title: 'new issue', due_date: due_date } + params: {title: "new issue", due_date: due_date} expect(response).to have_gitlab_http_status(201) - expect(json_response['title']).to eq('new issue') - expect(json_response['description']).to be_nil - expect(json_response['due_date']).to eq(due_date) + expect(json_response["title"]).to eq("new issue") + expect(json_response["description"]).to be_nil + expect(json_response["due_date"]).to eq(due_date) end end - context 'setting created_at' do + context "setting created_at" do let(:creation_time) { 2.weeks.ago } - let(:params) { { title: 'new issue', labels: 'label, label2', created_at: creation_time } } + let(:params) { {title: "new issue", labels: "label, label2", created_at: creation_time} } - context 'by an admin' do - it 'sets the creation time on the new issue' do + context "by an admin" do + it "sets the creation time on the new issue" do post api("/projects/#{project.id}/issues", admin), params: params expect(response).to have_gitlab_http_status(201) - expect(Time.parse(json_response['created_at'])).to be_like_time(creation_time) + expect(Time.parse(json_response["created_at"])).to be_like_time(creation_time) end end - context 'by a project owner' do - it 'sets the creation time on the new issue' do + context "by a project owner" do + it "sets the creation time on the new issue" do post api("/projects/#{project.id}/issues", user), params: params expect(response).to have_gitlab_http_status(201) - expect(Time.parse(json_response['created_at'])).to be_like_time(creation_time) + expect(Time.parse(json_response["created_at"])).to be_like_time(creation_time) end end - context 'by a group owner' do - it 'sets the creation time on the new issue' do + context "by a group owner" do + it "sets the creation time on the new issue" do group = create(:group) group_project = create(:project, :public, namespace: group) group.add_owner(user2) post api("/projects/#{group_project.id}/issues", user2), params: params expect(response).to have_gitlab_http_status(201) - expect(Time.parse(json_response['created_at'])).to be_like_time(creation_time) + expect(Time.parse(json_response["created_at"])).to be_like_time(creation_time) end end - context 'by another user' do - it 'ignores the given creation time' do + context "by another user" do + it "ignores the given creation time" do post api("/projects/#{project.id}/issues", user2), params: params expect(response).to have_gitlab_http_status(201) - expect(Time.parse(json_response['created_at'])).not_to be_like_time(creation_time) + expect(Time.parse(json_response["created_at"])).not_to be_like_time(creation_time) end end end - context 'the user can only read the issue' do - it 'cannot create new labels' do - expect do - post api("/projects/#{project.id}/issues", non_member), params: { title: 'new issue', labels: 'label, label2' } - end.not_to change { project.labels.count } + context "the user can only read the issue" do + it "cannot create new labels" do + expect { + post api("/projects/#{project.id}/issues", non_member), params: {title: "new issue", labels: "label, label2"} + }.not_to change { project.labels.count } end end end - describe 'POST /projects/:id/issues with spam filtering' do + describe "POST /projects/:id/issues with spam filtering" do before do allow_any_instance_of(SpamService).to receive(:check_for_spam?).and_return(true) allow_any_instance_of(AkismetService).to receive_messages(spam?: true) @@ -1388,128 +1388,128 @@ describe API::Issues do let(:params) do { - title: 'new issue', - description: 'content here', - labels: 'label, label2' + title: "new issue", + description: "content here", + labels: "label, label2", } end it "does not create a new project issue" do expect { post api("/projects/#{project.id}/issues", user), params: params }.not_to change(Issue, :count) expect(response).to have_gitlab_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 expect(spam_logs.count).to eq(1) - expect(spam_logs[0].title).to eq('new issue') - expect(spam_logs[0].description).to eq('content here') + expect(spam_logs[0].title).to eq("new issue") + expect(spam_logs[0].description).to eq("content here") expect(spam_logs[0].user).to eq(user) - expect(spam_logs[0].noteable_type).to eq('Issue') + expect(spam_logs[0].noteable_type).to eq("Issue") end end describe "PUT /projects/:id/issues/:issue_iid to update only title" do it "updates a project issue" do put api("/projects/#{project.id}/issues/#{issue.iid}", user), - params: { title: 'updated title' } + params: {title: "updated title"} expect(response).to have_gitlab_http_status(200) - expect(json_response['title']).to eq('updated title') + expect(json_response["title"]).to eq("updated title") end it "returns 404 error if issue iid not found" do put api("/projects/#{project.id}/issues/44444", user), - params: { title: 'updated title' } + params: {title: "updated title"} expect(response).to have_gitlab_http_status(404) end it "returns 404 error if issue id is used instead of the iid" do put api("/projects/#{project.id}/issues/#{issue.id}", user), - params: { title: 'updated title' } + params: {title: "updated title"} expect(response).to have_gitlab_http_status(404) end - it 'allows special label names' do + it "allows special label names" do put api("/projects/#{project.id}/issues/#{issue.iid}", user), - params: { - title: 'updated title', - labels: 'label, label?, label&foo, ?, &' - } + params: { + title: "updated title", + labels: "label, label?, label&foo, ?, &", + } expect(response.status).to eq(200) - expect(json_response['labels']).to include 'label' - expect(json_response['labels']).to include 'label?' - expect(json_response['labels']).to include 'label&foo' - expect(json_response['labels']).to include '?' - expect(json_response['labels']).to include '&' + expect(json_response["labels"]).to include "label" + expect(json_response["labels"]).to include "label?" + expect(json_response["labels"]).to include "label&foo" + expect(json_response["labels"]).to include "?" + expect(json_response["labels"]).to include "&" end - context 'confidential issues' do + context "confidential issues" do it "returns 403 for non project members" do put api("/projects/#{project.id}/issues/#{confidential_issue.iid}", non_member), - params: { title: 'updated title' } + params: {title: "updated title"} expect(response).to have_gitlab_http_status(403) end it "returns 403 for project members with guest role" do put api("/projects/#{project.id}/issues/#{confidential_issue.iid}", guest), - params: { title: 'updated title' } + params: {title: "updated title"} expect(response).to have_gitlab_http_status(403) end it "updates a confidential issue for project members" do put api("/projects/#{project.id}/issues/#{confidential_issue.iid}", user), - params: { title: 'updated title' } + params: {title: "updated title"} expect(response).to have_gitlab_http_status(200) - expect(json_response['title']).to eq('updated title') + expect(json_response["title"]).to eq("updated title") end it "updates a confidential issue for author" do put api("/projects/#{project.id}/issues/#{confidential_issue.iid}", author), - params: { title: 'updated title' } + params: {title: "updated title"} expect(response).to have_gitlab_http_status(200) - expect(json_response['title']).to eq('updated title') + expect(json_response["title"]).to eq("updated title") end it "updates a confidential issue for admin" do put api("/projects/#{project.id}/issues/#{confidential_issue.iid}", admin), - params: { title: 'updated title' } + params: {title: "updated title"} expect(response).to have_gitlab_http_status(200) - expect(json_response['title']).to eq('updated title') + expect(json_response["title"]).to eq("updated title") end - it 'sets an issue to confidential' do + it "sets an issue to confidential" do put api("/projects/#{project.id}/issues/#{issue.iid}", user), - params: { confidential: true } + params: {confidential: true} expect(response).to have_gitlab_http_status(200) - expect(json_response['confidential']).to be_truthy + expect(json_response["confidential"]).to be_truthy end - it 'makes a confidential issue public' do + it "makes a confidential issue public" do put api("/projects/#{project.id}/issues/#{confidential_issue.iid}", user), - params: { confidential: false } + params: {confidential: false} expect(response).to have_gitlab_http_status(200) - expect(json_response['confidential']).to be_falsy + expect(json_response["confidential"]).to be_falsy end - it 'does not update a confidential issue with wrong confidential flag' do + it "does not update a confidential issue with wrong confidential flag" do put api("/projects/#{project.id}/issues/#{confidential_issue.iid}", user), - params: { confidential: 'foo' } + params: {confidential: "foo"} expect(response).to have_gitlab_http_status(400) - expect(json_response['error']).to eq('confidential is invalid') + expect(json_response["error"]).to eq("confidential is invalid") end end end - describe 'PUT /projects/:id/issues/:issue_iid with spam filtering' do + describe "PUT /projects/:id/issues/:issue_iid with spam filtering" do let(:params) do { - title: 'updated title', - description: 'content here', - labels: 'label, label2' + title: "updated title", + description: "content here", + labels: "label, label2", } end @@ -1520,120 +1520,120 @@ describe API::Issues do put api("/projects/#{project.id}/issues/#{issue.iid}", user), params: params expect(response).to have_gitlab_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 expect(spam_logs.count).to eq(1) - expect(spam_logs[0].title).to eq('updated title') - expect(spam_logs[0].description).to eq('content here') + expect(spam_logs[0].title).to eq("updated title") + expect(spam_logs[0].description).to eq("content here") expect(spam_logs[0].user).to eq(user) - expect(spam_logs[0].noteable_type).to eq('Issue') + expect(spam_logs[0].noteable_type).to eq("Issue") end end - describe 'PUT /projects/:id/issues/:issue_iid to update assignee' do - context 'support for deprecated assignee_id' do - it 'removes assignee' do + describe "PUT /projects/:id/issues/:issue_iid to update assignee" do + context "support for deprecated assignee_id" do + it "removes assignee" do put api("/projects/#{project.id}/issues/#{issue.iid}", user), - params: { assignee_id: 0 } + params: {assignee_id: 0} expect(response).to have_gitlab_http_status(200) - expect(json_response['assignee']).to be_nil + expect(json_response["assignee"]).to be_nil end - it 'updates an issue with new assignee' do + it "updates an issue with new assignee" do put api("/projects/#{project.id}/issues/#{issue.iid}", user), - params: { assignee_id: user2.id } + params: {assignee_id: user2.id} expect(response).to have_gitlab_http_status(200) - expect(json_response['assignee']['name']).to eq(user2.name) + expect(json_response["assignee"]["name"]).to eq(user2.name) end end - it 'removes assignee' do + it "removes assignee" do put api("/projects/#{project.id}/issues/#{issue.iid}", user), - params: { assignee_ids: [0] } + params: {assignee_ids: [0]} expect(response).to have_gitlab_http_status(200) - expect(json_response['assignees']).to be_empty + expect(json_response["assignees"]).to be_empty end - it 'updates an issue with new assignee' do + it "updates an issue with new assignee" do put api("/projects/#{project.id}/issues/#{issue.iid}", user), - params: { assignee_ids: [user2.id] } + params: {assignee_ids: [user2.id]} expect(response).to have_gitlab_http_status(200) - expect(json_response['assignees'].first['name']).to eq(user2.name) + expect(json_response["assignees"].first["name"]).to eq(user2.name) end - context 'single assignee restrictions' do - it 'updates an issue with several assignees but only one has been applied' do + context "single assignee restrictions" do + it "updates an issue with several assignees but only one has been applied" do put api("/projects/#{project.id}/issues/#{issue.iid}", user), - params: { assignee_ids: [user2.id, guest.id] } + params: {assignee_ids: [user2.id, guest.id]} expect(response).to have_gitlab_http_status(200) - expect(json_response['assignees'].size).to eq(1) + expect(json_response["assignees"].size).to eq(1) end end end - describe 'PUT /projects/:id/issues/:issue_iid to update labels' do - let!(:label) { create(:label, title: 'dummy', project: project) } + describe "PUT /projects/:id/issues/:issue_iid to update labels" do + let!(:label) { create(:label, title: "dummy", project: project) } let!(:label_link) { create(:label_link, label: label, target: issue) } - it 'does not update labels if not present' do + it "does not update labels if not present" do put api("/projects/#{project.id}/issues/#{issue.iid}", user), - params: { title: 'updated title' } + params: {title: "updated title"} expect(response).to have_gitlab_http_status(200) - expect(json_response['labels']).to eq([label.title]) + expect(json_response["labels"]).to eq([label.title]) end - it 'removes all labels and touches the record' do + it "removes all labels and touches the record" do Timecop.travel(1.minute.from_now) do - put api("/projects/#{project.id}/issues/#{issue.iid}", user), params: { labels: '' } + put api("/projects/#{project.id}/issues/#{issue.iid}", user), params: {labels: ""} end expect(response).to have_gitlab_http_status(200) - expect(json_response['labels']).to eq([]) - expect(json_response['updated_at']).to be > Time.now + expect(json_response["labels"]).to eq([]) + expect(json_response["updated_at"]).to be > Time.now end - it 'updates labels and touches the record' do + it "updates labels and touches the record" do Timecop.travel(1.minute.from_now) do put api("/projects/#{project.id}/issues/#{issue.iid}", user), - params: { labels: 'foo,bar' } + params: {labels: "foo,bar"} end expect(response).to have_gitlab_http_status(200) - expect(json_response['labels']).to include 'foo' - expect(json_response['labels']).to include 'bar' - expect(json_response['updated_at']).to be > Time.now + expect(json_response["labels"]).to include "foo" + expect(json_response["labels"]).to include "bar" + expect(json_response["updated_at"]).to be > Time.now end - it 'allows special label names' do + it "allows special label names" do put api("/projects/#{project.id}/issues/#{issue.iid}", user), - params: { labels: 'label:foo, label-bar,label_bar,label/bar,label?bar,label&bar,?,&' } + params: {labels: "label:foo, label-bar,label_bar,label/bar,label?bar,label&bar,?,&"} expect(response.status).to eq(200) - 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' - expect(json_response['labels']).to include 'label&bar' - expect(json_response['labels']).to include '?' - expect(json_response['labels']).to include '&' + 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" + expect(json_response["labels"]).to include "label&bar" + expect(json_response["labels"]).to include "?" + expect(json_response["labels"]).to include "&" end - it 'returns 400 if title is too long' do + it "returns 400 if title is too long" do put api("/projects/#{project.id}/issues/#{issue.iid}", user), - params: { title: 'g' * 256 } + params: {title: "g" * 256} expect(response).to have_gitlab_http_status(400) - expect(json_response['message']['title']).to eq([ - 'is too long (maximum is 255 characters)' + expect(json_response["message"]["title"]).to eq([ + "is too long (maximum is 255 characters)", ]) end end @@ -1641,41 +1641,41 @@ describe API::Issues do describe "PUT /projects/:id/issues/:issue_iid to update state and label" do it "updates a project issue" do put api("/projects/#{project.id}/issues/#{issue.iid}", user), - params: { labels: 'label2', state_event: "close" } + params: {labels: "label2", state_event: "close"} expect(response).to have_gitlab_http_status(200) - expect(json_response['labels']).to include 'label2' - expect(json_response['state']).to eq "closed" + expect(json_response["labels"]).to include "label2" + expect(json_response["state"]).to eq "closed" end - it 'reopens a project isssue' do - put api("/projects/#{project.id}/issues/#{closed_issue.iid}", user), params: { state_event: 'reopen' } + it "reopens a project isssue" do + put api("/projects/#{project.id}/issues/#{closed_issue.iid}", user), params: {state_event: "reopen"} expect(response).to have_gitlab_http_status(200) - expect(json_response['state']).to eq 'opened' + expect(json_response["state"]).to eq "opened" end - context 'when an admin or owner makes the request' do - it 'accepts the update date to be set' do + context "when an admin or owner makes the request" do + it "accepts the update date to be set" do update_time = 2.weeks.ago put api("/projects/#{project.id}/issues/#{issue.iid}", user), - params: { labels: 'label3', state_event: 'close', updated_at: update_time } + params: {labels: "label3", state_event: "close", updated_at: update_time} expect(response).to have_gitlab_http_status(200) - expect(json_response['labels']).to include 'label3' - expect(Time.parse(json_response['updated_at'])).to be_like_time(update_time) + expect(json_response["labels"]).to include "label3" + expect(Time.parse(json_response["updated_at"])).to be_like_time(update_time) end end end - describe 'PUT /projects/:id/issues/:issue_iid to update due date' do - it 'creates a new project issue' do - due_date = 2.weeks.from_now.strftime('%Y-%m-%d') + describe "PUT /projects/:id/issues/:issue_iid to update due date" do + it "creates a new project issue" do + due_date = 2.weeks.from_now.strftime("%Y-%m-%d") - put api("/projects/#{project.id}/issues/#{issue.iid}", user), params: { due_date: due_date } + put api("/projects/#{project.id}/issues/#{issue.iid}", user), params: {due_date: due_date} expect(response).to have_gitlab_http_status(200) - expect(json_response['due_date']).to eq(due_date) + expect(json_response["due_date"]).to eq(due_date) end end @@ -1700,208 +1700,208 @@ describe API::Issues do expect(response).to have_gitlab_http_status(204) end - it_behaves_like '412 response' do + it_behaves_like "412 response" do let(:request) { api("/projects/#{project.id}/issues/#{issue.iid}", owner) } end end - context 'when issue does not exist' do - it 'returns 404 when trying to move an issue' do + context "when issue does not exist" do + it "returns 404 when trying to move an issue" do delete api("/projects/#{project.id}/issues/123", user) expect(response).to have_gitlab_http_status(404) end end - it 'returns 404 when using the issue ID instead of IID' do + it "returns 404 when using the issue ID instead of IID" do delete api("/projects/#{project.id}/issues/#{issue.id}", user) expect(response).to have_gitlab_http_status(404) end end - describe '/projects/:id/issues/:issue_iid/move' do - let!(:target_project) { create(:project, creator_id: user.id, namespace: user.namespace ) } - let!(:target_project2) { create(:project, creator_id: non_member.id, namespace: non_member.namespace ) } + describe "/projects/:id/issues/:issue_iid/move" do + let!(:target_project) { create(:project, creator_id: user.id, namespace: user.namespace) } + let!(:target_project2) { create(:project, creator_id: non_member.id, namespace: non_member.namespace) } - it 'moves an issue' do + it "moves an issue" do post api("/projects/#{project.id}/issues/#{issue.iid}/move", user), - params: { to_project_id: target_project.id } + params: {to_project_id: target_project.id} expect(response).to have_gitlab_http_status(201) - expect(json_response['project_id']).to eq(target_project.id) + expect(json_response["project_id"]).to eq(target_project.id) end - context 'when source and target projects are the same' do - it 'returns 400 when trying to move an issue' do + context "when source and target projects are the same" do + it "returns 400 when trying to move an issue" do post api("/projects/#{project.id}/issues/#{issue.iid}/move", user), - params: { to_project_id: project.id } + params: {to_project_id: project.id} expect(response).to have_gitlab_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 - context 'when the user does not have the permission to move issues' do - it 'returns 400 when trying to move an issue' do + context "when the user does not have the permission to move issues" do + it "returns 400 when trying to move an issue" do post api("/projects/#{project.id}/issues/#{issue.iid}/move", user), - params: { to_project_id: target_project2.id } + params: {to_project_id: target_project2.id} expect(response).to have_gitlab_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 - it 'moves the issue to another namespace if I am admin' do + it "moves the issue to another namespace if I am admin" do post api("/projects/#{project.id}/issues/#{issue.iid}/move", admin), - params: { to_project_id: target_project2.id } + params: {to_project_id: target_project2.id} expect(response).to have_gitlab_http_status(201) - expect(json_response['project_id']).to eq(target_project2.id) + expect(json_response["project_id"]).to eq(target_project2.id) end - context 'when using the issue ID instead of iid' do - it 'returns 404 when trying to move an issue' do + context "when using the issue ID instead of iid" do + it "returns 404 when trying to move an issue" do post api("/projects/#{project.id}/issues/#{issue.id}/move", user), - params: { to_project_id: target_project.id } + params: {to_project_id: target_project.id} expect(response).to have_gitlab_http_status(404) - expect(json_response['message']).to eq('404 Issue Not Found') + expect(json_response["message"]).to eq("404 Issue Not Found") end end - context 'when issue does not exist' do - it 'returns 404 when trying to move an issue' do + context "when issue does not exist" do + it "returns 404 when trying to move an issue" do post api("/projects/#{project.id}/issues/123/move", user), - params: { to_project_id: target_project.id } + params: {to_project_id: target_project.id} expect(response).to have_gitlab_http_status(404) - expect(json_response['message']).to eq('404 Issue Not Found') + expect(json_response["message"]).to eq("404 Issue Not Found") end end - context 'when source project does not exist' do - it 'returns 404 when trying to move an issue' do + context "when source project does not exist" do + it "returns 404 when trying to move an issue" do post api("/projects/0/issues/#{issue.iid}/move", user), - params: { to_project_id: target_project.id } + params: {to_project_id: target_project.id} expect(response).to have_gitlab_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 - context 'when target project does not exist' do - it 'returns 404 when trying to move an issue' do + context "when target project does not exist" do + it "returns 404 when trying to move an issue" do post api("/projects/#{project.id}/issues/#{issue.iid}/move", user), - params: { to_project_id: 0 } + params: {to_project_id: 0} expect(response).to have_gitlab_http_status(404) end end end - describe 'POST :id/issues/:issue_iid/subscribe' do - it 'subscribes to an issue' do + describe "POST :id/issues/:issue_iid/subscribe" do + it "subscribes to an issue" do post api("/projects/#{project.id}/issues/#{issue.iid}/subscribe", user2) expect(response).to have_gitlab_http_status(201) - expect(json_response['subscribed']).to eq(true) + expect(json_response["subscribed"]).to eq(true) end - it 'returns 304 if already subscribed' do + it "returns 304 if already subscribed" do post api("/projects/#{project.id}/issues/#{issue.iid}/subscribe", user) expect(response).to have_gitlab_http_status(304) 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/subscribe", user) expect(response).to have_gitlab_http_status(404) end - it 'returns 404 if the issue ID is used instead of the iid' do + it "returns 404 if the issue ID is used instead of the iid" do post api("/projects/#{project.id}/issues/#{issue.id}/subscribe", user) expect(response).to have_gitlab_http_status(404) 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.iid}/subscribe", non_member) expect(response).to have_gitlab_http_status(404) end end - describe 'POST :id/issues/:issue_id/unsubscribe' do - it 'unsubscribes from an issue' do + describe "POST :id/issues/:issue_id/unsubscribe" do + it "unsubscribes from an issue" do post api("/projects/#{project.id}/issues/#{issue.iid}/unsubscribe", user) expect(response).to have_gitlab_http_status(201) - expect(json_response['subscribed']).to eq(false) + expect(json_response["subscribed"]).to eq(false) end - it 'returns 304 if not subscribed' do + it "returns 304 if not subscribed" do post api("/projects/#{project.id}/issues/#{issue.iid}/unsubscribe", user2) expect(response).to have_gitlab_http_status(304) 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/unsubscribe", user) expect(response).to have_gitlab_http_status(404) end - it 'returns 404 if using the issue ID instead of iid' do + it "returns 404 if using the issue ID instead of iid" do post api("/projects/#{project.id}/issues/#{issue.id}/unsubscribe", user) expect(response).to have_gitlab_http_status(404) 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.iid}/unsubscribe", non_member) expect(response).to have_gitlab_http_status(404) end end - describe 'time tracking endpoints' do + describe "time tracking endpoints" do let(:issuable) { issue } - include_examples 'time tracking endpoints', 'issue' + include_examples "time tracking endpoints", "issue" end - describe 'GET :id/issues/:issue_iid/closed_by' do + describe "GET :id/issues/:issue_iid/closed_by" do let(:merge_request) do create(:merge_request, - :simple, - author: user, - source_project: project, - target_project: project, - description: "closes #{issue.to_reference}") + :simple, + author: user, + source_project: project, + target_project: project, + description: "closes #{issue.to_reference}") end before do create(:merge_requests_closing_issues, issue: issue, merge_request: merge_request) end - context 'when unauthenticated' do - it 'return public project issues' do + context "when unauthenticated" do + it "return public project issues" do get api("/projects/#{project.id}/issues/#{issue.iid}/closed_by") expect_paginated_array_response(merge_request.id) end end - it 'returns merge requests that will close issue on merge' do + it "returns merge requests that will close issue on merge" do get api("/projects/#{project.id}/issues/#{issue.iid}/closed_by", user) expect_paginated_array_response(merge_request.id) end - context 'when no merge requests will close issue' do - it 'returns empty array' do + context "when no merge requests will close issue" do + it "returns empty array" do get api("/projects/#{project.id}/issues/#{closed_issue.iid}/closed_by", user) expect_paginated_array_response([]) @@ -1915,7 +1915,7 @@ describe API::Issues do end end - describe 'GET :id/issues/:issue_iid/related_merge_requests' do + describe "GET :id/issues/:issue_iid/related_merge_requests" do def get_related_merge_requests(project_id, issue_iid, user = nil) get api("/projects/#{project_id}/issues/#{issue_iid}/related_merge_requests", user) end @@ -1927,7 +1927,7 @@ describe API::Issues do target_project: project, source_branch: "master", target_branch: "test", - description: "See #{issue.to_reference}" + description: "See #{issue.to_reference}", } create(:merge_request, attributes).tap do |merge_request| create(:note, :system, project: issue.project, noteable: issue, author: user, note: merge_request.to_reference(full: true)) @@ -1936,14 +1936,14 @@ describe API::Issues do let!(:related_mr) { create_referencing_mr(user, project, issue) } - context 'when unauthenticated' do - it 'return list of referenced merge requests from issue' do + context "when unauthenticated" do + it "return list of referenced merge requests from issue" do get_related_merge_requests(project.id, issue.iid) expect_paginated_array_response(related_mr.id) end - it 'renders 404 if project is not visible' do + it "renders 404 if project is not visible" do private_project = create(:project, :private) private_issue = create(:issue, project: private_project) create_referencing_mr(user, private_project, private_issue) @@ -1954,20 +1954,20 @@ describe API::Issues do end end - it 'returns merge requests that mentioned a issue' do + it "returns merge requests that mentioned a issue" do create(:merge_request, - :simple, - author: user, - source_project: project, - target_project: project, - description: "Some description") + :simple, + author: user, + source_project: project, + target_project: project, + description: "Some description") get_related_merge_requests(project.id, issue.iid, user) expect_paginated_array_response(related_mr.id) end - it 'returns merge requests cross-project wide' do + it "returns merge requests cross-project wide" do project2 = create(:project, :public, creator_id: user.id, namespace: user.namespace) merge_request = create_referencing_mr(user, project2, issue) @@ -1976,7 +1976,7 @@ describe API::Issues do expect_paginated_array_response([related_mr.id, merge_request.id]) end - it 'does not generate references to projects with no access' do + it "does not generate references to projects with no access" do private_project = create(:project, :private) create_referencing_mr(private_project.creator, private_project, issue) @@ -1985,8 +1985,8 @@ describe API::Issues do expect_paginated_array_response(related_mr.id) end - context 'no merge request mentioned a issue' do - it 'returns empty array' do + context "no merge request mentioned a issue" do + it "returns empty array" do get_related_merge_requests(project.id, closed_issue.iid, user) expect_paginated_array_response([]) @@ -2003,7 +2003,7 @@ describe API::Issues do describe "GET /projects/:id/issues/:issue_iid/user_agent_detail" do let!(:user_agent_detail) { create(:user_agent_detail, subject: issue) } - context 'when unauthenticated' do + context "when unauthenticated" do it "returns unauthorized" do get api("/projects/#{project.id}/issues/#{issue.iid}/user_agent_detail") @@ -2011,13 +2011,13 @@ describe API::Issues do end end - it 'exposes known attributes' do + it "exposes known attributes" do get api("/projects/#{project.id}/issues/#{issue.iid}/user_agent_detail", admin) expect(response).to have_gitlab_http_status(200) - expect(json_response['user_agent']).to eq(user_agent_detail.user_agent) - expect(json_response['ip_address']).to eq(user_agent_detail.ip_address) - expect(json_response['akismet_submitted']).to eq(user_agent_detail.submitted) + expect(json_response["user_agent"]).to eq(user_agent_detail.user_agent) + expect(json_response["ip_address"]).to eq(user_agent_detail.ip_address) + expect(json_response["akismet_submitted"]).to eq(user_agent_detail.submitted) end it "returns unauthorized for non-admin users" do @@ -2027,12 +2027,12 @@ describe API::Issues do end end - describe 'GET projects/:id/issues/:issue_iid/participants' do - it_behaves_like 'issuable participants endpoint' do + describe "GET projects/:id/issues/:issue_iid/participants" do + it_behaves_like "issuable participants endpoint" do let(:entity) { issue } 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.iid}/participants", non_member) expect(response).to have_gitlab_http_status(404) diff --git a/spec/requests/api/jobs_spec.rb b/spec/requests/api/jobs_spec.rb index 3defe8bbf51..b7d9ac1bf6f 100644 --- a/spec/requests/api/jobs_spec.rb +++ b/spec/requests/api/jobs_spec.rb @@ -1,29 +1,29 @@ -require 'spec_helper' +require "spec_helper" describe API::Jobs do include HttpIOHelpers - shared_examples 'a job with artifacts and trace' do |result_is_array: true| - context 'with artifacts and trace' do + shared_examples "a job with artifacts and trace" do |result_is_array: true| + context "with artifacts and trace" do let!(:second_job) { create(:ci_build, :trace_artifact, :artifacts, :test_reports, pipeline: pipeline) } - it 'returns artifacts and trace data', :skip_before_request do + it "returns artifacts and trace data", :skip_before_request do get api(api_endpoint, api_user) - json_job = result_is_array ? json_response.select { |job| job['id'] == second_job.id }.first : json_response - - expect(json_job['artifacts_file']).not_to be_nil - expect(json_job['artifacts_file']).not_to be_empty - expect(json_job['artifacts_file']['filename']).to eq(second_job.artifacts_file.filename) - expect(json_job['artifacts_file']['size']).to eq(second_job.artifacts_file.size) - expect(json_job['artifacts']).not_to be_nil - expect(json_job['artifacts']).to be_an Array - expect(json_job['artifacts'].size).to eq(second_job.job_artifacts.length) - json_job['artifacts'].each do |artifact| + json_job = result_is_array ? json_response.select { |job| job["id"] == second_job.id }.first : json_response + + expect(json_job["artifacts_file"]).not_to be_nil + expect(json_job["artifacts_file"]).not_to be_empty + expect(json_job["artifacts_file"]["filename"]).to eq(second_job.artifacts_file.filename) + expect(json_job["artifacts_file"]["size"]).to eq(second_job.artifacts_file.size) + expect(json_job["artifacts"]).not_to be_nil + expect(json_job["artifacts"]).to be_an Array + expect(json_job["artifacts"].size).to eq(second_job.job_artifacts.length) + json_job["artifacts"].each do |artifact| expect(artifact).not_to be_nil - file_type = Ci::JobArtifact.file_types[artifact['file_type']] - expect(artifact['size']).to eq(second_job.job_artifacts.where(file_type: file_type).first.size) - expect(artifact['filename']).to eq(second_job.job_artifacts.where(file_type: file_type).first.filename) - expect(artifact['file_format']).to eq(second_job.job_artifacts.where(file_type: file_type).first.file_format) + file_type = Ci::JobArtifact.file_types[artifact["file_type"]] + expect(artifact["size"]).to eq(second_job.job_artifacts.where(file_type: file_type).first.size) + expect(artifact["filename"]).to eq(second_job.job_artifacts.where(file_type: file_type).first.filename) + expect(artifact["file_format"]).to eq(second_job.job_artifacts.where(file_type: file_type).first.file_format) end end end @@ -53,8 +53,8 @@ describe API::Jobs do project.add_developer(user) end - describe 'GET /projects/:id/jobs' do - let(:query) { Hash.new } + describe "GET /projects/:id/jobs" do + let(:query) { {} } before do |example| unless example.metadata[:skip_before_request] @@ -62,44 +62,44 @@ describe API::Jobs do end end - context 'authorized user' do - it 'returns project jobs' do + context "authorized user" do + it "returns project jobs" do expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response).to be_an Array end - it 'returns correct values' do + it "returns correct values" do expect(json_response).not_to be_empty - expect(json_response.first['commit']['id']).to eq project.commit.id - expect(Time.parse(json_response.first['artifacts_expire_at'])).to be_like_time(job.artifacts_expire_at) + expect(json_response.first["commit"]["id"]).to eq project.commit.id + expect(Time.parse(json_response.first["artifacts_expire_at"])).to be_like_time(job.artifacts_expire_at) end - context 'without artifacts and trace' do - it 'returns no artifacts nor trace data' do + context "without artifacts and trace" do + it "returns no artifacts nor trace data" do json_job = json_response.first - expect(json_job['artifacts_file']).to be_nil - expect(json_job['artifacts']).to be_an Array - expect(json_job['artifacts']).to be_empty + expect(json_job["artifacts_file"]).to be_nil + expect(json_job["artifacts"]).to be_an Array + expect(json_job["artifacts"]).to be_empty end end - it_behaves_like 'a job with artifacts and trace' do + it_behaves_like "a job with artifacts and trace" do let(:api_endpoint) { "/projects/#{project.id}/jobs" } end - it 'returns pipeline data' do + it "returns pipeline data" do json_job = json_response.first - expect(json_job['pipeline']).not_to be_empty - expect(json_job['pipeline']['id']).to eq job.pipeline.id - expect(json_job['pipeline']['ref']).to eq job.pipeline.ref - expect(json_job['pipeline']['sha']).to eq job.pipeline.sha - expect(json_job['pipeline']['status']).to eq job.pipeline.status + expect(json_job["pipeline"]).not_to be_empty + expect(json_job["pipeline"]["id"]).to eq job.pipeline.id + expect(json_job["pipeline"]["ref"]).to eq job.pipeline.ref + expect(json_job["pipeline"]["sha"]).to eq job.pipeline.sha + expect(json_job["pipeline"]["status"]).to eq job.pipeline.status end - it 'avoids N+1 queries', :skip_before_request do + it "avoids N+1 queries", :skip_before_request do first_build = create(:ci_build, :trace_artifact, :artifacts, :test_reports, pipeline: pipeline) first_build.runner = create(:ci_runner) first_build.user = create(:user) @@ -116,8 +116,8 @@ describe API::Jobs do expect { go }.not_to exceed_query_limit(control_count) end - context 'filter project with one scope element' do - let(:query) { { 'scope' => 'pending' } } + context "filter project with one scope element" do + let(:query) { {"scope" => "pending"} } it do expect(response).to have_gitlab_http_status(200) @@ -125,8 +125,8 @@ describe API::Jobs do end end - context 'filter project with array of scope elements' do - let(:query) { { scope: %w(pending running) } } + context "filter project with array of scope elements" do + let(:query) { {scope: %w[pending running]} } it do expect(response).to have_gitlab_http_status(200) @@ -134,26 +134,26 @@ describe API::Jobs do end end - context 'respond 400 when scope contains invalid state' do - let(:query) { { scope: %w(unknown running) } } + context "respond 400 when scope contains invalid state" do + let(:query) { {scope: %w[unknown running]} } it { expect(response).to have_gitlab_http_status(400) } end end - context 'unauthorized user' do - context 'when user is not logged in' do + context "unauthorized user" do + context "when user is not logged in" do let(:api_user) { nil } - it 'does not return project jobs' do + it "does not return project jobs" do expect(response).to have_gitlab_http_status(401) end end - context 'when user is guest' do + context "when user is guest" do let(:api_user) { guest } - it 'does not return project jobs' do + it "does not return project jobs" do expect(response).to have_gitlab_http_status(403) end end @@ -164,8 +164,8 @@ describe API::Jobs do end end - describe 'GET /projects/:id/pipelines/:pipeline_id/jobs' do - let(:query) { Hash.new } + describe "GET /projects/:id/pipelines/:pipeline_id/jobs" do + let(:query) { {} } before do |example| unless example.metadata[:skip_before_request] @@ -174,38 +174,38 @@ describe API::Jobs do end end - context 'authorized user' do - it 'returns pipeline jobs' do + context "authorized user" do + it "returns pipeline jobs" do expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response).to be_an Array end - it 'returns correct values' do + it "returns correct values" do expect(json_response).not_to be_empty - expect(json_response.first['commit']['id']).to eq project.commit.id - expect(Time.parse(json_response.first['artifacts_expire_at'])).to be_like_time(job.artifacts_expire_at) - expect(json_response.first['artifacts_file']).to be_nil - expect(json_response.first['artifacts']).to be_an Array - expect(json_response.first['artifacts']).to be_empty + expect(json_response.first["commit"]["id"]).to eq project.commit.id + expect(Time.parse(json_response.first["artifacts_expire_at"])).to be_like_time(job.artifacts_expire_at) + expect(json_response.first["artifacts_file"]).to be_nil + expect(json_response.first["artifacts"]).to be_an Array + expect(json_response.first["artifacts"]).to be_empty end - it_behaves_like 'a job with artifacts and trace' do + it_behaves_like "a job with artifacts and trace" do let(:api_endpoint) { "/projects/#{project.id}/pipelines/#{pipeline.id}/jobs" } end - it 'returns pipeline data' do + it "returns pipeline data" do json_job = json_response.first - expect(json_job['pipeline']).not_to be_empty - expect(json_job['pipeline']['id']).to eq job.pipeline.id - expect(json_job['pipeline']['ref']).to eq job.pipeline.ref - expect(json_job['pipeline']['sha']).to eq job.pipeline.sha - expect(json_job['pipeline']['status']).to eq job.pipeline.status + expect(json_job["pipeline"]).not_to be_empty + expect(json_job["pipeline"]["id"]).to eq job.pipeline.id + expect(json_job["pipeline"]["ref"]).to eq job.pipeline.ref + expect(json_job["pipeline"]["sha"]).to eq job.pipeline.sha + expect(json_job["pipeline"]["status"]).to eq job.pipeline.status end - context 'filter jobs with one scope element' do - let(:query) { { 'scope' => 'pending' } } + context "filter jobs with one scope element" do + let(:query) { {"scope" => "pending"} } it do expect(response).to have_gitlab_http_status(200) @@ -213,8 +213,8 @@ describe API::Jobs do end end - context 'filter jobs with array of scope elements' do - let(:query) { { scope: %w(pending running) } } + context "filter jobs with array of scope elements" do + let(:query) { {scope: %w[pending running]} } it do expect(response).to have_gitlab_http_status(200) @@ -222,120 +222,120 @@ describe API::Jobs do end end - context 'respond 400 when scope contains invalid state' do - let(:query) { { scope: %w(unknown running) } } + context "respond 400 when scope contains invalid state" do + let(:query) { {scope: %w[unknown running]} } it { expect(response).to have_gitlab_http_status(400) } end - context 'jobs in different pipelines' do + context "jobs in different pipelines" do let!(:pipeline2) { create(:ci_empty_pipeline, project: project) } let!(:job2) { create(:ci_build, pipeline: pipeline2) } - it 'excludes jobs from other pipelines' do - json_response.each { |job| expect(job['pipeline']['id']).to eq(pipeline.id) } + it "excludes jobs from other pipelines" do + json_response.each { |job| expect(job["pipeline"]["id"]).to eq(pipeline.id) } end end - it 'avoids N+1 queries' do - control_count = ActiveRecord::QueryRecorder.new(skip_cached: false) do + it "avoids N+1 queries" do + control_count = ActiveRecord::QueryRecorder.new(skip_cached: false) { get api("/projects/#{project.id}/pipelines/#{pipeline.id}/jobs", api_user), params: query - end.count + }.count 3.times { create(:ci_build, :trace_artifact, :artifacts, :test_reports, pipeline: pipeline) } - expect do + expect { get api("/projects/#{project.id}/pipelines/#{pipeline.id}/jobs", api_user), params: query - end.not_to exceed_all_query_limit(control_count) + }.not_to exceed_all_query_limit(control_count) end end - context 'unauthorized user' do - context 'when user is not logged in' do + context "unauthorized user" do + context "when user is not logged in" do let(:api_user) { nil } - it 'does not return jobs' do + it "does not return jobs" do expect(response).to have_gitlab_http_status(401) end end - context 'when user is guest' do + context "when user is guest" do let(:api_user) { guest } - it 'does not return jobs' do + it "does not return jobs" do expect(response).to have_gitlab_http_status(403) end end end end - describe 'GET /projects/:id/jobs/:job_id' do + describe "GET /projects/:id/jobs/:job_id" do before do |example| unless example.metadata[:skip_before_request] get api("/projects/#{project.id}/jobs/#{job.id}", api_user) end end - context 'authorized user' do - it 'returns specific job data' do + context "authorized user" do + it "returns specific job data" do expect(response).to have_gitlab_http_status(200) - expect(json_response['id']).to eq(job.id) - expect(json_response['status']).to eq(job.status) - expect(json_response['stage']).to eq(job.stage) - expect(json_response['name']).to eq(job.name) - expect(json_response['ref']).to eq(job.ref) - expect(json_response['tag']).to eq(job.tag) - expect(json_response['coverage']).to eq(job.coverage) - expect(Time.parse(json_response['created_at'])).to be_like_time(job.created_at) - expect(Time.parse(json_response['started_at'])).to be_like_time(job.started_at) - expect(Time.parse(json_response['finished_at'])).to be_like_time(job.finished_at) - expect(Time.parse(json_response['artifacts_expire_at'])).to be_like_time(job.artifacts_expire_at) - expect(json_response['artifacts_file']).to be_nil - expect(json_response['artifacts']).to be_an Array - expect(json_response['artifacts']).to be_empty - expect(json_response['duration']).to eq(job.duration) - expect(json_response['web_url']).to be_present - end - - it_behaves_like 'a job with artifacts and trace', result_is_array: false do + expect(json_response["id"]).to eq(job.id) + expect(json_response["status"]).to eq(job.status) + expect(json_response["stage"]).to eq(job.stage) + expect(json_response["name"]).to eq(job.name) + expect(json_response["ref"]).to eq(job.ref) + expect(json_response["tag"]).to eq(job.tag) + expect(json_response["coverage"]).to eq(job.coverage) + expect(Time.parse(json_response["created_at"])).to be_like_time(job.created_at) + expect(Time.parse(json_response["started_at"])).to be_like_time(job.started_at) + expect(Time.parse(json_response["finished_at"])).to be_like_time(job.finished_at) + expect(Time.parse(json_response["artifacts_expire_at"])).to be_like_time(job.artifacts_expire_at) + expect(json_response["artifacts_file"]).to be_nil + expect(json_response["artifacts"]).to be_an Array + expect(json_response["artifacts"]).to be_empty + expect(json_response["duration"]).to eq(job.duration) + expect(json_response["web_url"]).to be_present + end + + it_behaves_like "a job with artifacts and trace", result_is_array: false do let(:api_endpoint) { "/projects/#{project.id}/jobs/#{second_job.id}" } end - it 'returns pipeline data' do + it "returns pipeline data" do json_job = json_response - expect(json_job['pipeline']).not_to be_empty - expect(json_job['pipeline']['id']).to eq job.pipeline.id - expect(json_job['pipeline']['ref']).to eq job.pipeline.ref - expect(json_job['pipeline']['sha']).to eq job.pipeline.sha - expect(json_job['pipeline']['status']).to eq job.pipeline.status + expect(json_job["pipeline"]).not_to be_empty + expect(json_job["pipeline"]["id"]).to eq job.pipeline.id + expect(json_job["pipeline"]["ref"]).to eq job.pipeline.ref + expect(json_job["pipeline"]["sha"]).to eq job.pipeline.sha + expect(json_job["pipeline"]["status"]).to eq job.pipeline.status end end - context 'unauthorized user' do + context "unauthorized user" do let(:api_user) { nil } - it 'does not return specific job data' do + it "does not return specific job data" do expect(response).to have_gitlab_http_status(401) end end end - describe 'GET /projects/:id/jobs/:job_id/artifacts/:artifact_path' do - context 'when job has artifacts' do + describe "GET /projects/:id/jobs/:job_id/artifacts/:artifact_path" do + context "when job has artifacts" do let(:job) { create(:ci_build, :artifacts, pipeline: pipeline) } let(:artifact) do - 'other_artifacts_0.1.2/another-subdirectory/banana_sample.gif' + "other_artifacts_0.1.2/another-subdirectory/banana_sample.gif" end - context 'when user is anonymous' do + context "when user is anonymous" do let(:api_user) { nil } - context 'when project is public' do - it 'allows to access artifacts' do + context "when project is public" do + it "allows to access artifacts" do project.update_column(:visibility_level, - Gitlab::VisibilityLevel::PUBLIC) + Gitlab::VisibilityLevel::PUBLIC) project.update_column(:public_builds, true) get_artifact_file(artifact) @@ -344,10 +344,10 @@ describe API::Jobs do end end - context 'when project is public with builds access disabled' do - it 'rejects access to artifacts' do + context "when project is public with builds access disabled" do + it "rejects access to artifacts" do project.update_column(:visibility_level, - Gitlab::VisibilityLevel::PUBLIC) + Gitlab::VisibilityLevel::PUBLIC) project.update_column(:public_builds, false) get_artifact_file(artifact) @@ -356,10 +356,10 @@ describe API::Jobs do end end - context 'when project is private' do - it 'rejects access and hides existence of artifacts' do + context "when project is private" do + it "rejects access and hides existence of artifacts" do project.update_column(:visibility_level, - Gitlab::VisibilityLevel::PRIVATE) + Gitlab::VisibilityLevel::PRIVATE) project.update_column(:public_builds, true) get_artifact_file(artifact) @@ -369,8 +369,8 @@ describe API::Jobs do end end - context 'when user is authorized' do - it 'returns a specific artifact file for a valid path' do + context "when user is authorized" do + it "returns a specific artifact file for a valid path" do expect(Gitlab::Workhorse) .to receive(:send_artifacts_entry) .and_call_original @@ -379,15 +379,15 @@ describe API::Jobs do expect(response).to have_gitlab_http_status(200) expect(response.headers.to_h) - .to include('Content-Type' => 'application/json', - 'Gitlab-Workhorse-Send-Data' => /artifacts-entry/) + .to include("Content-Type" => "application/json", + "Gitlab-Workhorse-Send-Data" => /artifacts-entry/) end end end - context 'when job does not have artifacts' do - it 'does not return job artifact file' do - get_artifact_file('some/artifact') + context "when job does not have artifacts" do + it "does not return job artifact file" do + get_artifact_file("some/artifact") expect(response).to have_gitlab_http_status(404) end @@ -399,43 +399,43 @@ describe API::Jobs do end end - describe 'GET /projects/:id/jobs/:job_id/artifacts' do - shared_examples 'downloads artifact' do + describe "GET /projects/:id/jobs/:job_id/artifacts" do + shared_examples "downloads artifact" do let(:download_headers) do - { 'Content-Transfer-Encoding' => 'binary', - 'Content-Disposition' => %q(attachment; filename="ci_build_artifacts.zip"; filename*=UTF-8''ci_build_artifacts.zip) } + {"Content-Transfer-Encoding" => "binary", + "Content-Disposition" => %q(attachment; filename="ci_build_artifacts.zip"; filename*=UTF-8''ci_build_artifacts.zip),} end - it 'returns specific job artifacts' do + it "returns specific job artifacts" do expect(response).to have_gitlab_http_status(200) expect(response.headers.to_h).to include(download_headers) expect(response.body).to match_file(job.artifacts_file.file.file) end end - context 'normal authentication' do - context 'job with artifacts' do - context 'when artifacts are stored locally' do + context "normal authentication" do + context "job with artifacts" do + context "when artifacts are stored locally" do let(:job) { create(:ci_build, :artifacts, pipeline: pipeline) } before do get api("/projects/#{project.id}/jobs/#{job.id}/artifacts", api_user) end - context 'authorized user' do - it_behaves_like 'downloads artifact' + context "authorized user" do + it_behaves_like "downloads artifact" end - context 'unauthorized user' do + context "unauthorized user" do let(:api_user) { nil } - it 'does not return specific job artifacts' do + it "does not return specific job artifacts" do expect(response).to have_gitlab_http_status(404) end end end - context 'when artifacts are stored remotely' do + context "when artifacts are stored remotely" do let(:proxy_download) { false } before do @@ -451,36 +451,36 @@ describe API::Jobs do get api("/projects/#{project.id}/jobs/#{job.id}/artifacts", api_user) end - context 'when proxy download is enabled' do + context "when proxy download is enabled" do let(:proxy_download) { true } - it 'responds with the workhorse send-url' do + it "responds with the workhorse send-url" do expect(response.headers[Gitlab::Workhorse::SEND_DATA_HEADER]).to start_with("send-url:") end end - context 'when proxy download is disabled' do - it 'returns location redirect' do + context "when proxy download is disabled" do + it "returns location redirect" do expect(response).to have_gitlab_http_status(302) end end - context 'authorized user' do - it 'returns the file remote URL' do + context "authorized user" do + it "returns the file remote URL" do expect(response).to redirect_to(artifact.file.url) end end - context 'unauthorized user' do + context "unauthorized user" do let(:api_user) { nil } - it 'does not return specific job artifacts' do + it "does not return specific job artifacts" do expect(response).to have_gitlab_http_status(404) end end end - it 'does not return job artifacts if not uploaded' do + it "does not return job artifacts if not uploaded" do get api("/projects/#{project.id}/jobs/#{job.id}/artifacts", api_user) expect(response).to have_gitlab_http_status(:not_found) @@ -489,7 +489,7 @@ describe API::Jobs do end end - describe 'GET /projects/:id/artifacts/:ref_name/download?job=name' do + describe "GET /projects/:id/artifacts/:ref_name/download?job=name" do let(:api_user) { reporter } let(:job) { create(:ci_build, :artifacts, pipeline: pipeline, user: api_user) } @@ -499,70 +499,70 @@ describe API::Jobs do end def get_for_ref(ref = pipeline.ref, job_name = job.name) - get api("/projects/#{project.id}/jobs/artifacts/#{ref}/download", api_user), params: { job: job_name } + get api("/projects/#{project.id}/jobs/artifacts/#{ref}/download", api_user), params: {job: job_name} end - context 'when not logged in' do + context "when not logged in" do let(:api_user) { nil } before do get_for_ref end - it 'does not find a resource in a private project' do + it "does not find a resource in a private project" do expect(project).to be_private expect(response).to have_gitlab_http_status(404) end end - context 'when logging as guest' do + context "when logging as guest" do let(:api_user) { guest } before do get_for_ref end - it 'gives 403' do + it "gives 403" do expect(response).to have_gitlab_http_status(403) end end - context 'non-existing job' do - shared_examples 'not found' do + context "non-existing job" do + shared_examples "not found" do it { expect(response).to have_gitlab_http_status(:not_found) } end - context 'has no such ref' do + context "has no such ref" do before do - get_for_ref('TAIL') + get_for_ref("TAIL") end - it_behaves_like 'not found' + it_behaves_like "not found" end - context 'has no such job' do + context "has no such job" do before do - get_for_ref(pipeline.ref, 'NOBUILD') + get_for_ref(pipeline.ref, "NOBUILD") end - it_behaves_like 'not found' + it_behaves_like "not found" end end - context 'find proper job' do - shared_examples 'a valid file' do - context 'when artifacts are stored locally' do + context "find proper job" do + shared_examples "a valid file" do + context "when artifacts are stored locally" do let(:download_headers) do - { 'Content-Transfer-Encoding' => 'binary', - 'Content-Disposition' => - %Q(attachment; filename="#{job.artifacts_file.filename}"; filename*=UTF-8''#{job.artifacts_file.filename}) } + {"Content-Transfer-Encoding" => "binary", + "Content-Disposition" => + %(attachment; filename="#{job.artifacts_file.filename}"; filename*=UTF-8''#{job.artifacts_file.filename}),} end it { expect(response).to have_http_status(:ok) } it { expect(response.headers.to_h).to include(download_headers) } end - context 'when artifacts are stored remotely' do + context "when artifacts are stored remotely" do let(:job) { create(:ci_build, pipeline: pipeline, user: api_user) } let!(:artifact) { create(:ci_job_artifact, :archive, :remote_store, job: job) } @@ -572,44 +572,44 @@ describe API::Jobs do get api("/projects/#{project.id}/jobs/#{job.id}/artifacts", api_user) end - it 'returns location redirect' do + it "returns location redirect" do expect(response).to have_http_status(:found) end end end - context 'with regular branch' do + context "with regular branch" do before do pipeline.reload - pipeline.update(ref: 'master', - sha: project.commit('master').sha) + pipeline.update(ref: "master", + sha: project.commit("master").sha) - get_for_ref('master') + get_for_ref("master") end - it_behaves_like 'a valid file' + it_behaves_like "a valid file" end - context 'with branch name containing slash' do + context "with branch name containing slash" do before do pipeline.reload - pipeline.update(ref: 'improve/awesome', - sha: project.commit('improve/awesome').sha) + pipeline.update(ref: "improve/awesome", + sha: project.commit("improve/awesome").sha) end before do - get_for_ref('improve/awesome') + get_for_ref("improve/awesome") end - it_behaves_like 'a valid file' + it_behaves_like "a valid file" end end end - describe 'GET id/jobs/artifacts/:ref_name/raw/*artifact_path?job=name' do - context 'when job has artifacts' do + describe "GET id/jobs/artifacts/:ref_name/raw/*artifact_path?job=name" do + context "when job has artifacts" do let(:job) { create(:ci_build, :artifacts, pipeline: pipeline, user: api_user) } - let(:artifact) { 'other_artifacts_0.1.2/another-subdirectory/banana_sample.gif' } + let(:artifact) { "other_artifacts_0.1.2/another-subdirectory/banana_sample.gif" } let(:visibility_level) { Gitlab::VisibilityLevel::PUBLIC } let(:public_builds) { true } @@ -623,129 +623,129 @@ describe API::Jobs do get_artifact_file(artifact) end - context 'when user is anonymous' do + context "when user is anonymous" do let(:api_user) { nil } - context 'when project is public' do + context "when project is public" do let(:visibility_level) { Gitlab::VisibilityLevel::PUBLIC } let(:public_builds) { true } - it 'allows to access artifacts' do + it "allows to access artifacts" do expect(response).to have_gitlab_http_status(200) expect(response.headers.to_h) - .to include('Content-Type' => 'application/json', - 'Gitlab-Workhorse-Send-Data' => /artifacts-entry/) + .to include("Content-Type" => "application/json", + "Gitlab-Workhorse-Send-Data" => /artifacts-entry/) end end - context 'when project is public with builds access disabled' do + context "when project is public with builds access disabled" do let(:visibility_level) { Gitlab::VisibilityLevel::PUBLIC } let(:public_builds) { false } - it 'rejects access to artifacts' do + it "rejects access to artifacts" do expect(response).to have_gitlab_http_status(403) - expect(json_response).to have_key('message') + expect(json_response).to have_key("message") expect(response.headers.to_h) - .not_to include('Gitlab-Workhorse-Send-Data' => /artifacts-entry/) + .not_to include("Gitlab-Workhorse-Send-Data" => /artifacts-entry/) end end - context 'when project is private' do + context "when project is private" do let(:visibility_level) { Gitlab::VisibilityLevel::PRIVATE } let(:public_builds) { true } - it 'rejects access and hides existence of artifacts' do + it "rejects access and hides existence of artifacts" do expect(response).to have_gitlab_http_status(404) - expect(json_response).to have_key('message') + expect(json_response).to have_key("message") expect(response.headers.to_h) - .not_to include('Gitlab-Workhorse-Send-Data' => /artifacts-entry/) + .not_to include("Gitlab-Workhorse-Send-Data" => /artifacts-entry/) end end end - context 'when user is authorized' do + context "when user is authorized" do let(:visibility_level) { Gitlab::VisibilityLevel::PRIVATE } let(:public_builds) { true } - it 'returns a specific artifact file for a valid path' do + it "returns a specific artifact file for a valid path" do expect(Gitlab::Workhorse) .to receive(:send_artifacts_entry) - .and_call_original + .and_call_original get_artifact_file(artifact) expect(response).to have_gitlab_http_status(200) expect(response.headers.to_h) - .to include('Content-Type' => 'application/json', - 'Gitlab-Workhorse-Send-Data' => /artifacts-entry/) + .to include("Content-Type" => "application/json", + "Gitlab-Workhorse-Send-Data" => /artifacts-entry/) end end - context 'with branch name containing slash' do + context "with branch name containing slash" do before do pipeline.reload - pipeline.update(ref: 'improve/awesome', - sha: project.commit('improve/awesome').sha) + pipeline.update(ref: "improve/awesome", + sha: project.commit("improve/awesome").sha) end - it 'returns a specific artifact file for a valid path' do - get_artifact_file(artifact, 'improve/awesome') + it "returns a specific artifact file for a valid path" do + get_artifact_file(artifact, "improve/awesome") expect(response).to have_gitlab_http_status(200) expect(response.headers.to_h) - .to include('Content-Type' => 'application/json', - 'Gitlab-Workhorse-Send-Data' => /artifacts-entry/) + .to include("Content-Type" => "application/json", + "Gitlab-Workhorse-Send-Data" => /artifacts-entry/) end end - context 'non-existing job' do - shared_examples 'not found' do + context "non-existing job" do + shared_examples "not found" do it { expect(response).to have_gitlab_http_status(:not_found) } end - context 'has no such ref' do + context "has no such ref" do before do - get_artifact_file('some/artifact', 'wrong-ref') + get_artifact_file("some/artifact", "wrong-ref") end - it_behaves_like 'not found' + it_behaves_like "not found" end - context 'has no such job' do + context "has no such job" do before do - get_artifact_file('some/artifact', pipeline.ref, 'wrong-job-name') + get_artifact_file("some/artifact", pipeline.ref, "wrong-job-name") end - it_behaves_like 'not found' + it_behaves_like "not found" end end end - context 'when job does not have artifacts' do + context "when job does not have artifacts" do let(:job) { create(:ci_build, pipeline: pipeline, user: api_user) } - it 'does not return job artifact file' do - get_artifact_file('some/artifact') + it "does not return job artifact file" do + get_artifact_file("some/artifact") expect(response).to have_gitlab_http_status(404) end end def get_artifact_file(artifact_path, ref = pipeline.ref, job_name = job.name) - get api("/projects/#{project.id}/jobs/artifacts/#{ref}/raw/#{artifact_path}", api_user), params: { job: job_name } + get api("/projects/#{project.id}/jobs/artifacts/#{ref}/raw/#{artifact_path}", api_user), params: {job: job_name} end end - describe 'GET /projects/:id/jobs/:job_id/trace' do + describe "GET /projects/:id/jobs/:job_id/trace" do before do get api("/projects/#{project.id}/jobs/#{job.id}/trace", api_user) end - context 'authorized user' do - context 'when trace is in ObjectStorage' do + context "authorized user" do + context "when trace is in ObjectStorage" do let!(:job) { create(:ci_build, :trace_artifact, pipeline: pipeline) } - let(:url) { 'http://object-storage/trace' } - let(:file_path) { expand_fixture_path('trace/sample_trace') } + let(:url) { "http://object-storage/trace" } + let(:file_path) { expand_fixture_path("trace/sample_trace") } before do stub_remote_url_206(url, file_path) @@ -754,106 +754,106 @@ describe API::Jobs do allow_any_instance_of(JobArtifactUploader).to receive(:size) { File.size(file_path) } end - it 'returns specific job trace' do + it "returns specific job trace" do expect(response).to have_gitlab_http_status(200) expect(response.body).to eq(job.trace.raw) end end - context 'when trace is artifact' do + context "when trace is artifact" do let(:job) { create(:ci_build, :trace_artifact, pipeline: pipeline) } - it 'returns specific job trace' do + it "returns specific job trace" do expect(response).to have_gitlab_http_status(200) expect(response.body).to eq(job.trace.raw) end end - context 'when trace is file' do + context "when trace is file" do let(:job) { create(:ci_build, :trace_live, pipeline: pipeline) } - it 'returns specific job trace' do + it "returns specific job trace" do expect(response).to have_gitlab_http_status(200) expect(response.body).to eq(job.trace.raw) end end end - context 'unauthorized user' do + context "unauthorized user" do let(:api_user) { nil } - it 'does not return specific job trace' do + it "does not return specific job trace" do expect(response).to have_gitlab_http_status(401) end end end - describe 'POST /projects/:id/jobs/:job_id/cancel' do + describe "POST /projects/:id/jobs/:job_id/cancel" do before do post api("/projects/#{project.id}/jobs/#{job.id}/cancel", api_user) end - context 'authorized user' do - context 'user with :update_build persmission' do - it 'cancels running or pending job' do + context "authorized user" do + context "user with :update_build persmission" do + it "cancels running or pending job" do expect(response).to have_gitlab_http_status(201) - expect(project.builds.first.status).to eq('success') + expect(project.builds.first.status).to eq("success") end end - context 'user without :update_build permission' do + context "user without :update_build permission" do let(:api_user) { reporter } - it 'does not cancel job' do + it "does not cancel job" do expect(response).to have_gitlab_http_status(403) end end end - context 'unauthorized user' do + context "unauthorized user" do let(:api_user) { nil } - it 'does not cancel job' do + it "does not cancel job" do expect(response).to have_gitlab_http_status(401) end end end - describe 'POST /projects/:id/jobs/:job_id/retry' do + describe "POST /projects/:id/jobs/:job_id/retry" do let(:job) { create(:ci_build, :canceled, pipeline: pipeline) } before do post api("/projects/#{project.id}/jobs/#{job.id}/retry", api_user) end - context 'authorized user' do - context 'user with :update_build permission' do - it 'retries non-running job' do + context "authorized user" do + context "user with :update_build permission" do + it "retries non-running job" do expect(response).to have_gitlab_http_status(201) - expect(project.builds.first.status).to eq('canceled') - expect(json_response['status']).to eq('pending') + expect(project.builds.first.status).to eq("canceled") + expect(json_response["status"]).to eq("pending") end end - context 'user without :update_build permission' do + context "user without :update_build permission" do let(:api_user) { reporter } - it 'does not retry job' do + it "does not retry job" do expect(response).to have_gitlab_http_status(403) end end end - context 'unauthorized user' do + context "unauthorized user" do let(:api_user) { nil } - it 'does not retry job' do + it "does not retry job" do expect(response).to have_gitlab_http_status(401) end end end - describe 'POST /projects/:id/jobs/:job_id/erase' do + describe "POST /projects/:id/jobs/:job_id/erase" do let(:role) { :maintainer } before do @@ -862,10 +862,10 @@ describe API::Jobs do post api("/projects/#{project.id}/jobs/#{job.id}/erase", user) end - context 'job is erasable' do + context "job is erasable" do let(:job) { create(:ci_build, :trace_artifact, :artifacts, :test_reports, :success, project: project, pipeline: pipeline) } - it 'erases job content' do + it "erases job content" do expect(response).to have_gitlab_http_status(201) expect(job.job_artifacts.count).to eq(0) expect(job.trace.exist?).to be_falsy @@ -874,7 +874,7 @@ describe API::Jobs do expect(job.has_job_artifacts?).to be_falsy end - it 'updates job' do + it "updates job" do job.reload expect(job.erased_at).to be_truthy @@ -882,25 +882,25 @@ describe API::Jobs do end end - context 'job is not erasable' do + context "job is not erasable" do let(:job) { create(:ci_build, :trace_live, project: project, pipeline: pipeline) } - it 'responds with forbidden' do + it "responds with forbidden" do expect(response).to have_gitlab_http_status(403) end end - context 'when a developer erases a build' do + context "when a developer erases a build" do let(:role) { :developer } let(:job) { create(:ci_build, :trace_artifact, :artifacts, :success, project: project, pipeline: pipeline, user: owner) } - context 'when the build was created by the developer' do + context "when the build was created by the developer" do let(:owner) { user } it { expect(response).to have_gitlab_http_status(201) } end - context 'when the build was created by the other' do + context "when the build was created by the other" do let(:owner) { create(:user) } it { expect(response).to have_gitlab_http_status(403) } @@ -908,63 +908,63 @@ describe API::Jobs do end end - describe 'POST /projects/:id/jobs/:job_id/artifacts/keep' do + describe "POST /projects/:id/jobs/:job_id/artifacts/keep" do before do post api("/projects/#{project.id}/jobs/#{job.id}/artifacts/keep", user) end - context 'artifacts did not expire' do + context "artifacts did not expire" do let(:job) do create(:ci_build, :trace_artifact, :artifacts, :success, - project: project, pipeline: pipeline, artifacts_expire_at: Time.now + 7.days) + project: project, pipeline: pipeline, artifacts_expire_at: Time.now + 7.days) end - it 'keeps artifacts' do + it "keeps artifacts" do expect(response).to have_gitlab_http_status(200) expect(job.reload.artifacts_expire_at).to be_nil end end - context 'no artifacts' do + context "no artifacts" do let(:job) { create(:ci_build, project: project, pipeline: pipeline) } - it 'responds with not found' do + it "responds with not found" do expect(response).to have_gitlab_http_status(404) end end end - describe 'POST /projects/:id/jobs/:job_id/play' do + describe "POST /projects/:id/jobs/:job_id/play" do before do post api("/projects/#{project.id}/jobs/#{job.id}/play", api_user) end - context 'on an playable job' do + context "on an playable job" do let(:job) { create(:ci_build, :manual, project: project, pipeline: pipeline) } - context 'when user is authorized to trigger a manual action' do - it 'plays the job' do + context "when user is authorized to trigger a manual action" do + it "plays the job" do expect(response).to have_gitlab_http_status(200) - expect(json_response['user']['id']).to eq(user.id) - expect(json_response['id']).to eq(job.id) + expect(json_response["user"]["id"]).to eq(user.id) + expect(json_response["id"]).to eq(job.id) expect(job.reload).to be_pending end end - context 'when user is not authorized to trigger a manual action' do - context 'when user does not have access to the project' do + context "when user is not authorized to trigger a manual action" do + context "when user does not have access to the project" do let(:api_user) { create(:user) } - it 'does not trigger a manual action' do + it "does not trigger a manual action" do expect(job.reload).to be_manual expect(response).to have_gitlab_http_status(404) end end - context 'when user is not allowed to trigger the manual action' do + context "when user is not allowed to trigger the manual action" do let(:api_user) { reporter } - it 'does not trigger a manual action' do + it "does not trigger a manual action" do expect(job.reload).to be_manual expect(response).to have_gitlab_http_status(403) end @@ -972,8 +972,8 @@ describe API::Jobs do end end - context 'on a non-playable job' do - it 'returns a status code 400, Bad Request' do + context "on a non-playable job" do + it "returns a status code 400, Bad Request" do expect(response).to have_gitlab_http_status 400 expect(response.body).to match("Unplayable Job") end diff --git a/spec/requests/api/keys_spec.rb b/spec/requests/api/keys_spec.rb index f37d84fddef..2b14f157ec1 100644 --- a/spec/requests/api/keys_spec.rb +++ b/spec/requests/api/keys_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe API::Keys do let(:user) { create(:user) } @@ -6,35 +6,35 @@ describe API::Keys do let(:key) { create(:key, user: user) } let(:email) { create(:email, user: user) } - describe 'GET /keys/:uid' do - context 'when unauthenticated' do - it 'returns authentication error' do + describe "GET /keys/:uid" do + context "when unauthenticated" do + it "returns authentication error" do get api("/keys/#{key.id}") expect(response).to have_gitlab_http_status(401) end end - context 'when authenticated' do - it 'returns 404 for non-existing key' do - get api('/keys/0', admin) + context "when authenticated" do + it "returns 404 for non-existing key" do + get api("/keys/0", admin) expect(response).to have_gitlab_http_status(404) - expect(json_response['message']).to eq('404 Not found') + expect(json_response["message"]).to eq("404 Not found") end - it 'returns single ssh key with user information' do + it "returns single ssh key with user information" do user.keys << key user.save get api("/keys/#{key.id}", admin) expect(response).to have_gitlab_http_status(200) - expect(json_response['title']).to eq(key.title) - expect(json_response['user']['id']).to eq(user.id) - expect(json_response['user']['username']).to eq(user.username) + expect(json_response["title"]).to eq(key.title) + expect(json_response["user"]["id"]).to eq(user.id) + expect(json_response["user"]["username"]).to eq(user.username) end it "does not include the user's `is_admin` flag" do get api("/keys/#{key.id}", admin) - expect(json_response['user']['is_admin']).to be_nil + expect(json_response["user"]["is_admin"]).to be_nil end end end diff --git a/spec/requests/api/labels_spec.rb b/spec/requests/api/labels_spec.rb index 518181e4d93..912ac5f9067 100644 --- a/spec/requests/api/labels_spec.rb +++ b/spec/requests/api/labels_spec.rb @@ -1,29 +1,29 @@ -require 'spec_helper' +require "spec_helper" describe API::Labels do let(:user) { create(:user) } let(:project) { create(:project, creator_id: user.id, namespace: user.namespace) } - let!(:label1) { create(:label, title: 'label1', project: project) } - let!(:priority_label) { create(:label, title: 'bug', project: project, priority: 3) } + let!(:label1) { create(:label, title: "label1", project: project) } + let!(:priority_label) { create(:label, title: "bug", project: project, priority: 3) } before do project.add_maintainer(user) end - describe 'GET /projects/:id/labels' do - it 'returns all available labels to the project' do + describe "GET /projects/:id/labels" do + it "returns all available labels to the project" do group = create(:group) - group_label = create(:group_label, title: 'feature', group: group) + group_label = create(:group_label, title: "feature", group: group) project.update(group: group) create(:labeled_issue, project: project, labels: [group_label], author: user) create(:labeled_issue, project: project, labels: [label1], author: user, state: :closed) - create(:labeled_merge_request, labels: [priority_label], author: user, source_project: project ) + create(:labeled_merge_request, labels: [priority_label], author: user, source_project: project) - expected_keys = %w( + expected_keys = %w[ id name color text_color description open_issues_count closed_issues_count open_merge_requests_count subscribed priority is_project_label - ) + ] get api("/projects/#{project.id}/labels", user) @@ -32,339 +32,339 @@ describe API::Labels do expect(json_response).to be_an Array expect(json_response.size).to eq(3) expect(json_response.first.keys).to match_array expected_keys - expect(json_response.map { |l| l['name'] }).to match_array([group_label.name, priority_label.name, label1.name]) - - label1_response = json_response.find { |l| l['name'] == label1.title } - group_label_response = json_response.find { |l| l['name'] == group_label.title } - priority_label_response = json_response.find { |l| l['name'] == priority_label.title } - - expect(label1_response['open_issues_count']).to eq(0) - expect(label1_response['closed_issues_count']).to eq(1) - expect(label1_response['open_merge_requests_count']).to eq(0) - expect(label1_response['name']).to eq(label1.name) - expect(label1_response['color']).to be_present - expect(label1_response['text_color']).to be_present - expect(label1_response['description']).to be_nil - expect(label1_response['priority']).to be_nil - expect(label1_response['subscribed']).to be_falsey - expect(label1_response['is_project_label']).to be_truthy - - expect(group_label_response['open_issues_count']).to eq(1) - expect(group_label_response['closed_issues_count']).to eq(0) - expect(group_label_response['open_merge_requests_count']).to eq(0) - expect(group_label_response['name']).to eq(group_label.name) - expect(group_label_response['color']).to be_present - expect(group_label_response['text_color']).to be_present - expect(group_label_response['description']).to be_nil - expect(group_label_response['priority']).to be_nil - expect(group_label_response['subscribed']).to be_falsey - expect(group_label_response['is_project_label']).to be_falsey - - expect(priority_label_response['open_issues_count']).to eq(0) - expect(priority_label_response['closed_issues_count']).to eq(0) - expect(priority_label_response['open_merge_requests_count']).to eq(1) - expect(priority_label_response['name']).to eq(priority_label.name) - expect(priority_label_response['color']).to be_present - expect(priority_label_response['text_color']).to be_present - expect(priority_label_response['description']).to be_nil - expect(priority_label_response['priority']).to eq(3) - expect(priority_label_response['subscribed']).to be_falsey - expect(priority_label_response['is_project_label']).to be_truthy + expect(json_response.map { |l| l["name"] }).to match_array([group_label.name, priority_label.name, label1.name]) + + label1_response = json_response.find { |l| l["name"] == label1.title } + group_label_response = json_response.find { |l| l["name"] == group_label.title } + priority_label_response = json_response.find { |l| l["name"] == priority_label.title } + + expect(label1_response["open_issues_count"]).to eq(0) + expect(label1_response["closed_issues_count"]).to eq(1) + expect(label1_response["open_merge_requests_count"]).to eq(0) + expect(label1_response["name"]).to eq(label1.name) + expect(label1_response["color"]).to be_present + expect(label1_response["text_color"]).to be_present + expect(label1_response["description"]).to be_nil + expect(label1_response["priority"]).to be_nil + expect(label1_response["subscribed"]).to be_falsey + expect(label1_response["is_project_label"]).to be_truthy + + expect(group_label_response["open_issues_count"]).to eq(1) + expect(group_label_response["closed_issues_count"]).to eq(0) + expect(group_label_response["open_merge_requests_count"]).to eq(0) + expect(group_label_response["name"]).to eq(group_label.name) + expect(group_label_response["color"]).to be_present + expect(group_label_response["text_color"]).to be_present + expect(group_label_response["description"]).to be_nil + expect(group_label_response["priority"]).to be_nil + expect(group_label_response["subscribed"]).to be_falsey + expect(group_label_response["is_project_label"]).to be_falsey + + expect(priority_label_response["open_issues_count"]).to eq(0) + expect(priority_label_response["closed_issues_count"]).to eq(0) + expect(priority_label_response["open_merge_requests_count"]).to eq(1) + expect(priority_label_response["name"]).to eq(priority_label.name) + expect(priority_label_response["color"]).to be_present + expect(priority_label_response["text_color"]).to be_present + expect(priority_label_response["description"]).to be_nil + expect(priority_label_response["priority"]).to eq(3) + expect(priority_label_response["subscribed"]).to be_falsey + expect(priority_label_response["is_project_label"]).to be_truthy end end - describe 'POST /projects/:id/labels' do - it 'returns created label when all params' do + describe "POST /projects/:id/labels" do + it "returns created label when all params" do post api("/projects/#{project.id}/labels", user), - params: { - name: 'Foo', - color: '#FFAABB', - description: 'test', - priority: 2 - } + params: { + name: "Foo", + color: "#FFAABB", + description: "test", + priority: 2, + } expect(response).to have_gitlab_http_status(201) - expect(json_response['name']).to eq('Foo') - expect(json_response['color']).to eq('#FFAABB') - expect(json_response['description']).to eq('test') - expect(json_response['priority']).to eq(2) + expect(json_response["name"]).to eq("Foo") + expect(json_response["color"]).to eq("#FFAABB") + expect(json_response["description"]).to eq("test") + expect(json_response["priority"]).to eq(2) end - it 'returns created label when only required params' do + it "returns created label when only required params" do post api("/projects/#{project.id}/labels", user), - params: { - name: 'Foo & Bar', - color: '#FFAABB' - } + params: { + name: "Foo & Bar", + color: "#FFAABB", + } expect(response.status).to eq(201) - expect(json_response['name']).to eq('Foo & Bar') - expect(json_response['color']).to eq('#FFAABB') - expect(json_response['description']).to be_nil - expect(json_response['priority']).to be_nil + expect(json_response["name"]).to eq("Foo & Bar") + expect(json_response["color"]).to eq("#FFAABB") + expect(json_response["description"]).to be_nil + expect(json_response["priority"]).to be_nil end - it 'creates a prioritized label' do + it "creates a prioritized label" do post api("/projects/#{project.id}/labels", user), - params: { - name: 'Foo & Bar', - color: '#FFAABB', - priority: 3 - } + params: { + name: "Foo & Bar", + color: "#FFAABB", + priority: 3, + } expect(response.status).to eq(201) - expect(json_response['name']).to eq('Foo & Bar') - expect(json_response['color']).to eq('#FFAABB') - expect(json_response['description']).to be_nil - expect(json_response['priority']).to eq(3) + expect(json_response["name"]).to eq("Foo & Bar") + expect(json_response["color"]).to eq("#FFAABB") + expect(json_response["description"]).to be_nil + expect(json_response["priority"]).to eq(3) end - it 'returns a 400 bad request if name not given' do - post api("/projects/#{project.id}/labels", user), params: { color: '#FFAABB' } + it "returns a 400 bad request if name not given" do + post api("/projects/#{project.id}/labels", user), params: {color: "#FFAABB"} expect(response).to have_gitlab_http_status(400) end - it 'returns a 400 bad request if color not given' do - post api("/projects/#{project.id}/labels", user), params: { name: 'Foobar' } + it "returns a 400 bad request if color not given" do + post api("/projects/#{project.id}/labels", user), params: {name: "Foobar"} expect(response).to have_gitlab_http_status(400) end - it 'returns 400 for invalid color' do + it "returns 400 for invalid color" do post api("/projects/#{project.id}/labels", user), - params: { - name: 'Foo', - color: '#FFAA' - } + params: { + name: "Foo", + color: "#FFAA", + } expect(response).to have_gitlab_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 - it 'returns 400 for too long color code' do + it "returns 400 for too long color code" do post api("/projects/#{project.id}/labels", user), - params: { - name: 'Foo', - color: '#FFAAFFFF' - } + params: { + name: "Foo", + color: "#FFAAFFFF", + } expect(response).to have_gitlab_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 - it 'returns 400 for invalid name' do + it "returns 400 for invalid name" do post api("/projects/#{project.id}/labels", user), - params: { - name: ',', - color: '#FFAABB' - } + params: { + name: ",", + color: "#FFAABB", + } expect(response).to have_gitlab_http_status(400) - expect(json_response['message']['title']).to eq(['is invalid']) + expect(json_response["message"]["title"]).to eq(["is invalid"]) end - it 'returns 409 if label already exists in group' do + it "returns 409 if label already exists in group" do group = create(:group) group_label = create(:group_label, group: group) project.update(group: group) post api("/projects/#{project.id}/labels", user), - params: { - name: group_label.name, - color: '#FFAABB' - } + params: { + name: group_label.name, + color: "#FFAABB", + } expect(response).to have_gitlab_http_status(409) - expect(json_response['message']).to eq('Label already exists') + expect(json_response["message"]).to eq("Label already exists") end - it 'returns 400 for invalid priority' do + it "returns 400 for invalid priority" do post api("/projects/#{project.id}/labels", user), - params: { - name: 'Foo', - color: '#FFAAFFFF', - priority: 'foo' - } + params: { + name: "Foo", + color: "#FFAAFFFF", + priority: "foo", + } expect(response).to have_gitlab_http_status(400) end - it 'returns 409 if label already exists in project' do + it "returns 409 if label already exists in project" do post api("/projects/#{project.id}/labels", user), - params: { - name: 'label1', - color: '#FFAABB' - } + params: { + name: "label1", + color: "#FFAABB", + } expect(response).to have_gitlab_http_status(409) - expect(json_response['message']).to eq('Label already exists') + expect(json_response["message"]).to eq("Label already exists") end end - describe 'DELETE /projects/:id/labels' do - it 'returns 204 for existing label' do - delete api("/projects/#{project.id}/labels", user), params: { name: 'label1' } + describe "DELETE /projects/:id/labels" do + it "returns 204 for existing label" do + delete api("/projects/#{project.id}/labels", user), params: {name: "label1"} expect(response).to have_gitlab_http_status(204) end - it 'returns 404 for non existing label' do - delete api("/projects/#{project.id}/labels", user), params: { name: 'label2' } + it "returns 404 for non existing label" do + delete api("/projects/#{project.id}/labels", user), params: {name: "label2"} expect(response).to have_gitlab_http_status(404) - expect(json_response['message']).to eq('404 Label Not Found') + expect(json_response["message"]).to eq("404 Label Not Found") end - it 'returns 400 for wrong parameters' do + it "returns 400 for wrong parameters" do delete api("/projects/#{project.id}/labels", user) expect(response).to have_gitlab_http_status(400) end - it_behaves_like '412 response' do + it_behaves_like "412 response" do let(:request) { api("/projects/#{project.id}/labels", user) } - let(:params) { { name: 'label1' } } + let(:params) { {name: "label1"} } end end - describe 'PUT /projects/:id/labels' do - it 'returns 200 if name and colors and description are changed' do + describe "PUT /projects/:id/labels" do + it "returns 200 if name and colors and description are changed" do put api("/projects/#{project.id}/labels", user), - params: { - name: 'label1', - new_name: 'New Label', - color: '#FFFFFF', - description: 'test' - } + params: { + name: "label1", + new_name: "New Label", + color: "#FFFFFF", + description: "test", + } expect(response).to have_gitlab_http_status(200) - expect(json_response['name']).to eq('New Label') - expect(json_response['color']).to eq('#FFFFFF') - expect(json_response['description']).to eq('test') + expect(json_response["name"]).to eq("New Label") + expect(json_response["color"]).to eq("#FFFFFF") + expect(json_response["description"]).to eq("test") end - it 'returns 200 if name is changed' do + it "returns 200 if name is changed" do put api("/projects/#{project.id}/labels", user), - params: { - name: 'label1', - new_name: 'New Label' - } + params: { + name: "label1", + new_name: "New Label", + } expect(response).to have_gitlab_http_status(200) - expect(json_response['name']).to eq('New Label') - expect(json_response['color']).to eq(label1.color) + expect(json_response["name"]).to eq("New Label") + expect(json_response["color"]).to eq(label1.color) end - it 'returns 200 if colors is changed' do + it "returns 200 if colors is changed" do put api("/projects/#{project.id}/labels", user), - params: { - name: 'label1', - color: '#FFFFFF' - } + params: { + name: "label1", + color: "#FFFFFF", + } expect(response).to have_gitlab_http_status(200) - expect(json_response['name']).to eq(label1.name) - expect(json_response['color']).to eq('#FFFFFF') + expect(json_response["name"]).to eq(label1.name) + expect(json_response["color"]).to eq("#FFFFFF") end - it 'returns 200 if description is changed' do + it "returns 200 if description is changed" do put api("/projects/#{project.id}/labels", user), - params: { - name: 'bug', - description: 'test' - } + params: { + name: "bug", + description: "test", + } expect(response).to have_gitlab_http_status(200) - expect(json_response['name']).to eq(priority_label.name) - expect(json_response['description']).to eq('test') - expect(json_response['priority']).to eq(3) + expect(json_response["name"]).to eq(priority_label.name) + expect(json_response["description"]).to eq("test") + expect(json_response["priority"]).to eq(3) end - it 'returns 200 if priority is changed' do + it "returns 200 if priority is changed" do put api("/projects/#{project.id}/labels", user), - params: { - name: 'bug', - priority: 10 - } + params: { + name: "bug", + priority: 10, + } expect(response.status).to eq(200) - expect(json_response['name']).to eq(priority_label.name) - expect(json_response['priority']).to eq(10) + expect(json_response["name"]).to eq(priority_label.name) + expect(json_response["priority"]).to eq(10) end - it 'returns 200 if a priority is added' do + it "returns 200 if a priority is added" do put api("/projects/#{project.id}/labels", user), - params: { - name: 'label1', - priority: 3 - } + params: { + name: "label1", + priority: 3, + } expect(response.status).to eq(200) - expect(json_response['name']).to eq(label1.name) - expect(json_response['priority']).to eq(3) + expect(json_response["name"]).to eq(label1.name) + expect(json_response["priority"]).to eq(3) end - it 'returns 200 if the priority is removed' do + it "returns 200 if the priority is removed" do put api("/projects/#{project.id}/labels", user), - params: { - name: priority_label.name, - priority: nil - } + params: { + name: priority_label.name, + priority: nil, + } expect(response.status).to eq(200) - expect(json_response['name']).to eq(priority_label.name) - expect(json_response['priority']).to be_nil + expect(json_response["name"]).to eq(priority_label.name) + expect(json_response["priority"]).to be_nil end - it 'returns 404 if label does not exist' do + it "returns 404 if label does not exist" do put api("/projects/#{project.id}/labels", user), - params: { - name: 'label2', - new_name: 'label3' - } + params: { + name: "label2", + new_name: "label3", + } expect(response).to have_gitlab_http_status(404) end - it 'returns 400 if no label name given' do - put api("/projects/#{project.id}/labels", user), params: { new_name: 'label2' } + it "returns 400 if no label name given" do + put api("/projects/#{project.id}/labels", user), params: {new_name: "label2"} expect(response).to have_gitlab_http_status(400) - expect(json_response['error']).to eq('name is missing') + expect(json_response["error"]).to eq("name is missing") end - it 'returns 400 if no new parameters given' do - put api("/projects/#{project.id}/labels", user), params: { name: 'label1' } + it "returns 400 if no new parameters given" do + put api("/projects/#{project.id}/labels", user), params: {name: "label1"} expect(response).to have_gitlab_http_status(400) - expect(json_response['error']).to eq('new_name, color, description, priority are missing, '\ - 'at least one parameter must be provided') + expect(json_response["error"]).to eq("new_name, color, description, priority are missing, "\ + "at least one parameter must be provided") end - it 'returns 400 for invalid name' do + it "returns 400 for invalid name" do put api("/projects/#{project.id}/labels", user), - params: { - name: 'label1', - new_name: ',', - color: '#FFFFFF' - } + params: { + name: "label1", + new_name: ",", + color: "#FFFFFF", + } expect(response).to have_gitlab_http_status(400) - expect(json_response['message']['title']).to eq(['is invalid']) + expect(json_response["message"]["title"]).to eq(["is invalid"]) end - it 'returns 400 when color code is too short' do + it "returns 400 when color code is too short" do put api("/projects/#{project.id}/labels", user), - params: { - name: 'label1', - color: '#FF' - } + params: { + name: "label1", + color: "#FF", + } expect(response).to have_gitlab_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 - it 'returns 400 for too long color code' do + it "returns 400 for too long color code" do put api("/projects/#{project.id}/labels", user), - params: { - name: 'label1', - color: '#FFAAFFFF' - } + params: { + name: "label1", + color: "#FFAAFFFF", + } expect(response).to have_gitlab_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 - it 'returns 400 for invalid priority' do + it "returns 400 for invalid priority" do put api("/projects/#{project.id}/labels", user), - params: { - name: 'label1', - priority: 'foo' - } + params: { + name: "label1", + priority: "foo", + } expect(response).to have_gitlab_http_status(400) end diff --git a/spec/requests/api/lint_spec.rb b/spec/requests/api/lint_spec.rb index f52cdf1c459..1a8267fba1c 100644 --- a/spec/requests/api/lint_spec.rb +++ b/spec/requests/api/lint_spec.rb @@ -1,46 +1,46 @@ -require 'spec_helper' +require "spec_helper" describe API::Lint do - describe 'POST /ci/lint' do - context 'with valid .gitlab-ci.yaml content' do + describe "POST /ci/lint" do + context "with valid .gitlab-ci.yaml content" do let(:yaml_content) do - File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci.yml')) + File.read(Rails.root.join("spec/support/gitlab_stubs/gitlab_ci.yml")) end - it 'passes validation' do - post api('/ci/lint'), params: { content: yaml_content } + it "passes validation" do + post api("/ci/lint"), params: {content: yaml_content} expect(response).to have_gitlab_http_status(200) expect(json_response).to be_an Hash - expect(json_response['status']).to eq('valid') - expect(json_response['errors']).to eq([]) + expect(json_response["status"]).to eq("valid") + expect(json_response["errors"]).to eq([]) end end - context 'with an invalid .gitlab_ci.yml' do - it 'responds with errors about invalid syntax' do - post api('/ci/lint'), params: { content: 'invalid content' } + context "with an invalid .gitlab_ci.yml" do + it "responds with errors about invalid syntax" do + post api("/ci/lint"), params: {content: "invalid content"} expect(response).to have_gitlab_http_status(200) - expect(json_response['status']).to eq('invalid') - expect(json_response['errors']).to eq(['Invalid configuration format']) + expect(json_response["status"]).to eq("invalid") + expect(json_response["errors"]).to eq(["Invalid configuration format"]) end it "responds with errors about invalid configuration" do - post api('/ci/lint'), params: { content: '{ image: "ruby:2.1", services: ["postgres"] }' } + post api("/ci/lint"), params: {content: '{ image: "ruby:2.1", services: ["postgres"] }'} expect(response).to have_gitlab_http_status(200) - expect(json_response['status']).to eq('invalid') - expect(json_response['errors']).to eq(['jobs config should contain at least one visible job']) + expect(json_response["status"]).to eq("invalid") + expect(json_response["errors"]).to eq(["jobs config should contain at least one visible job"]) end end - context 'without the content parameter' do - it 'responds with validation error about missing content' do - post api('/ci/lint') + context "without the content parameter" do + it "responds with validation error about missing content" do + post api("/ci/lint") expect(response).to have_gitlab_http_status(400) - expect(json_response['error']).to eq('content is missing') + expect(json_response["error"]).to eq("content is missing") end end end diff --git a/spec/requests/api/markdown_spec.rb b/spec/requests/api/markdown_spec.rb index 0cf5c5677b9..44b54366bfc 100644 --- a/spec/requests/api/markdown_spec.rb +++ b/spec/requests/api/markdown_spec.rb @@ -43,7 +43,7 @@ describe API::Markdown do end context "when project is not found" do - let(:params) { { text: "Hello world!", gfm: true, project: "Dummy project" } } + let(:params) { {text: "Hello world!", gfm: true, project: "Dummy project"} } it_behaves_like "404 Project Not Found" end @@ -56,13 +56,13 @@ describe API::Markdown do context "when not using gfm" do context "without project" do - let(:params) { { text: text } } + let(:params) { {text: text} } it_behaves_like "rendered markdown text without GFM" end context "with project" do - let(:params) { { text: text, project: project.full_path } } + let(:params) { {text: text, project: project.full_path} } context "when not authorized" do it_behaves_like "404 Project Not Found" @@ -78,23 +78,23 @@ describe API::Markdown do context "when using gfm" do context "without project" do - let(:params) { { text: text, gfm: true } } + let(:params) { {text: text, gfm: true} } it "renders markdown text" do expect(response).to have_http_status(201) expect(response.headers["Content-Type"]).to eq("application/json") expect(json_response).to be_a(Hash) expect(json_response["html"]).to include("Hello world!") - .and include('data-name="tada"') - .and include('data-name="100"') - .and include("#1") - .and exclude("<a href=\"#{IssuesHelper.url_for_issue(issue.iid, project)}\"") - .and exclude("#1</a>") + .and include('data-name="tada"') + .and include('data-name="100"') + .and include("#1") + .and exclude("<a href=\"#{IssuesHelper.url_for_issue(issue.iid, project)}\"") + .and exclude("#1</a>") end end context "with project" do - let(:params) { { text: text, gfm: true, project: project.full_path } } + let(:params) { {text: text, gfm: true, project: project.full_path} } let(:user) { project.owner } it "renders markdown text" do @@ -102,55 +102,55 @@ describe API::Markdown do expect(response.headers["Content-Type"]).to eq("application/json") expect(json_response).to be_a(Hash) expect(json_response["html"]).to include("Hello world!") - .and include('data-name="tada"') - .and include('data-name="100"') - .and include("<a href=\"#{IssuesHelper.url_for_issue(issue.iid, project)}\"") - .and include("#1</a>") + .and include('data-name="tada"') + .and include('data-name="100"') + .and include("<a href=\"#{IssuesHelper.url_for_issue(issue.iid, project)}\"") + .and include("#1</a>") end end - context 'with a public project and confidential issue' do + context "with a public project and confidential issue" do let(:public_project) { create(:project, :public) } - let(:confidential_issue) { create(:issue, :confidential, project: public_project, title: 'Confidential title') } + let(:confidential_issue) { create(:issue, :confidential, project: public_project, title: "Confidential title") } let(:text) { ":tada: Hello world! :100: #{confidential_issue.to_reference}" } - let(:params) { { text: text, gfm: true, project: public_project.full_path } } + let(:params) { {text: text, gfm: true, project: public_project.full_path} } - shared_examples 'user without proper access' do - it 'does not render the title or link' do + shared_examples "user without proper access" do + it "does not render the title or link" do expect(response).to have_http_status(201) - expect(json_response["html"]).not_to include('Confidential title') - expect(json_response["html"]).not_to include('<a href=') - expect(json_response["html"]).to include('Hello world!') - .and include('data-name="tada"') - .and include('data-name="100"') - .and include('#1</p>') + expect(json_response["html"]).not_to include("Confidential title") + expect(json_response["html"]).not_to include("<a href=") + expect(json_response["html"]).to include("Hello world!") + .and include('data-name="tada"') + .and include('data-name="100"') + .and include("#1</p>") end end - context 'when not logged in' do + context "when not logged in" do let(:user) { } - it_behaves_like 'user without proper access' + it_behaves_like "user without proper access" end - context 'when logged in as user without access' do + context "when logged in as user without access" do let(:user) { create(:user) } - it_behaves_like 'user without proper access' + it_behaves_like "user without proper access" end - context 'when logged in as author' do + context "when logged in as author" do let(:user) { confidential_issue.author } - it 'renders the title or link' do + it "renders the title or link" do expect(response).to have_http_status(201) - expect(json_response["html"]).to include('Confidential title') - expect(json_response["html"]).to include('Hello world!') - .and include('data-name="tada"') - .and include('data-name="100"') - .and include("<a href=\"#{IssuesHelper.url_for_issue(confidential_issue.iid, public_project)}\"") - .and include("#1</a>") + expect(json_response["html"]).to include("Confidential title") + expect(json_response["html"]).to include("Hello world!") + .and include('data-name="tada"') + .and include('data-name="100"') + .and include("<a href=\"#{IssuesHelper.url_for_issue(confidential_issue.iid, public_project)}\"") + .and include("#1</a>") end end end diff --git a/spec/requests/api/members_spec.rb b/spec/requests/api/members_spec.rb index 79edbb301f2..92206ac76cc 100644 --- a/spec/requests/api/members_spec.rb +++ b/spec/requests/api/members_spec.rb @@ -1,7 +1,7 @@ -require 'spec_helper' +require "spec_helper" describe API::Members do - let(:maintainer) { create(:user, username: 'maintainer_user') } + let(:maintainer) { create(:user, username: "maintainer_user") } let(:developer) { create(:user) } let(:access_requester) { create(:user) } let(:stranger) { create(:user) } @@ -22,7 +22,7 @@ describe API::Members do end end - shared_examples 'GET /:source_type/:id/members/(all)' do |source_type, all| + shared_examples "GET /:source_type/:id/members/(all)" do |source_type, all| let(:members_url) do "/#{source_type.pluralize}/#{source.id}/members".tap do |url| url << "/all" if all @@ -30,13 +30,13 @@ describe API::Members do end context "with :source_type == #{source_type.pluralize}" do - it_behaves_like 'a 404 response when source is private' do + it_behaves_like "a 404 response when source is private" do let(:route) { get api(members_url, stranger) } end %i[maintainer developer access_requester stranger].each do |type| context "when authenticated as a #{type}" do - it 'returns 200' do + it "returns 200" do user = public_send(type) get api(members_url, user) @@ -45,28 +45,28 @@ describe API::Members do expect(response).to include_pagination_headers expect(json_response).to be_an Array expect(json_response.size).to eq(2) - expect(json_response.map { |u| u['id'] }).to match_array [maintainer.id, developer.id] + expect(json_response.map { |u| u["id"] }).to match_array [maintainer.id, developer.id] end end end - it 'avoids N+1 queries' do + it "avoids N+1 queries" do # Establish baseline get api(members_url, maintainer) - control = ActiveRecord::QueryRecorder.new do + control = ActiveRecord::QueryRecorder.new { get api(members_url, maintainer) - end + } project.add_developer(create(:user)) - expect do + expect { get api(members_url, maintainer) - end.not_to exceed_query_limit(control) + }.not_to exceed_query_limit(control) end - it 'does not return invitees' do - create(:"#{source_type}_member", invite_token: '123', invite_email: 'test@abc.com', source: source, user: nil) + it "does not return invitees" do + create(:"#{source_type}_member", invite_token: "123", invite_email: "test@abc.com", source: source, user: nil) get api(members_url, developer) @@ -74,32 +74,32 @@ describe API::Members do expect(response).to include_pagination_headers expect(json_response).to be_an Array expect(json_response.size).to eq(2) - expect(json_response.map { |u| u['id'] }).to match_array [maintainer.id, developer.id] + expect(json_response.map { |u| u["id"] }).to match_array [maintainer.id, developer.id] end - it 'finds members with query string' do - get api(members_url, developer), params: { query: maintainer.username } + it "finds members with query string" do + get api(members_url, developer), params: {query: maintainer.username} expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response).to be_an Array expect(json_response.count).to eq(1) - expect(json_response.first['username']).to eq(maintainer.username) + expect(json_response.first["username"]).to eq(maintainer.username) end - it 'finds all members with no query specified' do - get api(members_url, developer), params: { query: '' } + it "finds all members with no query specified" do + get api(members_url, developer), params: {query: ""} expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response).to be_an Array expect(json_response.count).to eq(2) - expect(json_response.map { |u| u['id'] }).to match_array [maintainer.id, developer.id] + expect(json_response.map { |u| u["id"] }).to match_array [maintainer.id, developer.id] end end end - describe 'GET /:source_type/:id/members/all', :nested_groups do + describe "GET /:source_type/:id/members/all", :nested_groups do let(:nested_user) { create(:user) } let(:project_user) { create(:user) } let(:linked_group_user) { create(:user) } @@ -123,49 +123,49 @@ describe API::Members do end end - it 'finds all project members including inherited members' do + it "finds all project members including inherited members" do get api("/projects/#{project.id}/members/all", developer) expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response).to be_an Array - expect(json_response.map { |u| u['id'] }).to match_array [maintainer.id, developer.id, nested_user.id, project_user.id, linked_group_user.id] + expect(json_response.map { |u| u["id"] }).to match_array [maintainer.id, developer.id, nested_user.id, project_user.id, linked_group_user.id] end - it 'finds all group members including inherited members' do + it "finds all group members including inherited members" do get api("/groups/#{nested_group.id}/members/all", developer) expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response).to be_an Array - expect(json_response.map { |u| u['id'] }).to match_array [maintainer.id, developer.id, nested_user.id] + expect(json_response.map { |u| u["id"] }).to match_array [maintainer.id, developer.id, nested_user.id] end end - shared_examples 'GET /:source_type/:id/members/:user_id' do |source_type| + shared_examples "GET /:source_type/:id/members/:user_id" do |source_type| context "with :source_type == #{source_type.pluralize}" do - it_behaves_like 'a 404 response when source is private' do + it_behaves_like "a 404 response when source is private" do let(:route) { get api("/#{source_type.pluralize}/#{source.id}/members/#{developer.id}", stranger) } end - context 'when authenticated as a non-member' do + context "when authenticated as a non-member" do %i[access_requester stranger].each do |type| context "as a #{type}" do - it 'returns 200' do + it "returns 200" do user = public_send(type) get api("/#{source_type.pluralize}/#{source.id}/members/#{developer.id}", user) expect(response).to have_gitlab_http_status(200) # User attributes - expect(json_response['id']).to eq(developer.id) - expect(json_response['name']).to eq(developer.name) - expect(json_response['username']).to eq(developer.username) - expect(json_response['state']).to eq(developer.state) - expect(json_response['avatar_url']).to eq(developer.avatar_url) - expect(json_response['web_url']).to eq(Gitlab::Routing.url_helpers.user_url(developer)) + expect(json_response["id"]).to eq(developer.id) + expect(json_response["name"]).to eq(developer.name) + expect(json_response["username"]).to eq(developer.username) + expect(json_response["state"]).to eq(developer.state) + expect(json_response["avatar_url"]).to eq(developer.avatar_url) + expect(json_response["web_url"]).to eq(Gitlab::Routing.url_helpers.user_url(developer)) # Member attributes - expect(json_response['access_level']).to eq(Member::DEVELOPER) + expect(json_response["access_level"]).to eq(Member::DEVELOPER) end end end @@ -173,22 +173,22 @@ describe API::Members do end end - shared_examples 'POST /:source_type/:id/members' do |source_type| + shared_examples "POST /:source_type/:id/members" do |source_type| context "with :source_type == #{source_type.pluralize}" do - it_behaves_like 'a 404 response when source is private' do + it_behaves_like "a 404 response when source is private" do let(:route) do post api("/#{source_type.pluralize}/#{source.id}/members", stranger), - params: { user_id: access_requester.id, access_level: Member::MAINTAINER } + params: {user_id: access_requester.id, access_level: Member::MAINTAINER} end end - context 'when authenticated as a non-member or member with insufficient rights' do + context "when authenticated as a non-member or member with insufficient rights" do %i[access_requester stranger developer].each do |type| context "as a #{type}" do - it 'returns 403' do + it "returns 403" do user = public_send(type) post api("/#{source_type.pluralize}/#{source.id}/members", user), - params: { user_id: access_requester.id, access_level: Member::MAINTAINER } + params: {user_id: access_requester.id, access_level: Member::MAINTAINER} expect(response).to have_gitlab_http_status(403) end @@ -196,36 +196,36 @@ describe API::Members do end end - context 'when authenticated as a maintainer/owner' do - context 'and new member is already a requester' do - it 'transforms the requester into a proper member' do - expect do + context "when authenticated as a maintainer/owner" do + context "and new member is already a requester" do + it "transforms the requester into a proper member" do + expect { post api("/#{source_type.pluralize}/#{source.id}/members", maintainer), - params: { user_id: access_requester.id, access_level: Member::MAINTAINER } + params: {user_id: access_requester.id, access_level: Member::MAINTAINER} expect(response).to have_gitlab_http_status(201) - end.to change { source.members.count }.by(1) + }.to change { source.members.count }.by(1) expect(source.requesters.count).to eq(0) - expect(json_response['id']).to eq(access_requester.id) - expect(json_response['access_level']).to eq(Member::MAINTAINER) + expect(json_response["id"]).to eq(access_requester.id) + expect(json_response["access_level"]).to eq(Member::MAINTAINER) end end - it 'creates a new member' do - expect do + it "creates a new member" do + expect { post api("/#{source_type.pluralize}/#{source.id}/members", maintainer), - params: { user_id: stranger.id, access_level: Member::DEVELOPER, expires_at: '2016-08-05' } + params: {user_id: stranger.id, access_level: Member::DEVELOPER, expires_at: "2016-08-05"} expect(response).to have_gitlab_http_status(201) - end.to change { source.members.count }.by(1) - expect(json_response['id']).to eq(stranger.id) - expect(json_response['access_level']).to eq(Member::DEVELOPER) - expect(json_response['expires_at']).to eq('2016-08-05') + }.to change { source.members.count }.by(1) + expect(json_response["id"]).to eq(stranger.id) + expect(json_response["access_level"]).to eq(Member::DEVELOPER) + expect(json_response["expires_at"]).to eq("2016-08-05") end end - context 'access levels' do - it 'does not create the member if group level is higher', :nested_groups do + context "access levels" do + it "does not create the member if group level is higher", :nested_groups do parent = create(:group) group.update(parent: parent) @@ -233,13 +233,13 @@ describe API::Members do parent.add_developer(stranger) post api("/#{source_type.pluralize}/#{source.id}/members", maintainer), - params: { user_id: stranger.id, access_level: Member::REPORTER } + params: {user_id: stranger.id, access_level: Member::REPORTER} expect(response).to have_gitlab_http_status(400) - expect(json_response['message']['access_level']).to eq(["should be higher than Developer inherited membership from group #{parent.name}"]) + expect(json_response["message"]["access_level"]).to eq(["should be higher than Developer inherited membership from group #{parent.name}"]) end - it 'creates the member if group level is lower', :nested_groups do + it "creates the member if group level is lower", :nested_groups do parent = create(:group) group.update(parent: parent) @@ -247,68 +247,68 @@ describe API::Members do parent.add_developer(stranger) post api("/#{source_type.pluralize}/#{source.id}/members", maintainer), - params: { user_id: stranger.id, access_level: Member::MAINTAINER } + params: {user_id: stranger.id, access_level: Member::MAINTAINER} expect(response).to have_gitlab_http_status(201) - expect(json_response['id']).to eq(stranger.id) - expect(json_response['access_level']).to eq(Member::MAINTAINER) + expect(json_response["id"]).to eq(stranger.id) + expect(json_response["access_level"]).to eq(Member::MAINTAINER) end end it "returns 409 if member already exists" do post api("/#{source_type.pluralize}/#{source.id}/members", maintainer), - params: { user_id: maintainer.id, access_level: Member::MAINTAINER } + params: {user_id: maintainer.id, access_level: Member::MAINTAINER} expect(response).to have_gitlab_http_status(409) end - it 'returns 404 when the user_id is not valid' do + it "returns 404 when the user_id is not valid" do post api("/#{source_type.pluralize}/#{source.id}/members", maintainer), - params: { user_id: 0, access_level: Member::MAINTAINER } + params: {user_id: 0, access_level: Member::MAINTAINER} expect(response).to have_gitlab_http_status(404) - expect(json_response['message']).to eq('404 User Not Found') + expect(json_response["message"]).to eq("404 User Not Found") end - it 'returns 400 when user_id is not given' do + it "returns 400 when user_id is not given" do post api("/#{source_type.pluralize}/#{source.id}/members", maintainer), - params: { access_level: Member::MAINTAINER } + params: {access_level: Member::MAINTAINER} expect(response).to have_gitlab_http_status(400) end - it 'returns 400 when access_level is not given' do + it "returns 400 when access_level is not given" do post api("/#{source_type.pluralize}/#{source.id}/members", maintainer), - params: { user_id: stranger.id } + params: {user_id: stranger.id} expect(response).to have_gitlab_http_status(400) end - it 'returns 400 when access_level is not valid' do + it "returns 400 when access_level is not valid" do post api("/#{source_type.pluralize}/#{source.id}/members", maintainer), - params: { user_id: stranger.id, access_level: 1234 } + params: {user_id: stranger.id, access_level: 1234} expect(response).to have_gitlab_http_status(400) end end end - shared_examples 'PUT /:source_type/:id/members/:user_id' do |source_type| + shared_examples "PUT /:source_type/:id/members/:user_id" do |source_type| context "with :source_type == #{source_type.pluralize}" do - it_behaves_like 'a 404 response when source is private' do + it_behaves_like "a 404 response when source is private" do let(:route) do put api("/#{source_type.pluralize}/#{source.id}/members/#{developer.id}", stranger), - params: { access_level: Member::MAINTAINER } + params: {access_level: Member::MAINTAINER} end end - context 'when authenticated as a non-member or member with insufficient rights' do + context "when authenticated as a non-member or member with insufficient rights" do %i[access_requester stranger developer].each do |type| context "as a #{type}" do - it 'returns 403' do + it "returns 403" do user = public_send(type) put api("/#{source_type.pluralize}/#{source.id}/members/#{developer.id}", user), - params: { access_level: Member::MAINTAINER } + params: {access_level: Member::MAINTAINER} expect(response).to have_gitlab_http_status(403) end @@ -316,50 +316,50 @@ describe API::Members do end end - context 'when authenticated as a maintainer/owner' do - it 'updates the member' do + context "when authenticated as a maintainer/owner" do + it "updates the member" do put api("/#{source_type.pluralize}/#{source.id}/members/#{developer.id}", maintainer), - params: { access_level: Member::MAINTAINER, expires_at: '2016-08-05' } + params: {access_level: Member::MAINTAINER, expires_at: "2016-08-05"} expect(response).to have_gitlab_http_status(200) - expect(json_response['id']).to eq(developer.id) - expect(json_response['access_level']).to eq(Member::MAINTAINER) - expect(json_response['expires_at']).to eq('2016-08-05') + expect(json_response["id"]).to eq(developer.id) + expect(json_response["access_level"]).to eq(Member::MAINTAINER) + expect(json_response["expires_at"]).to eq("2016-08-05") end end - it 'returns 409 if member does not exist' do + it "returns 409 if member does not exist" do put api("/#{source_type.pluralize}/#{source.id}/members/123", maintainer), - params: { access_level: Member::MAINTAINER } + params: {access_level: Member::MAINTAINER} expect(response).to have_gitlab_http_status(404) end - it 'returns 400 when access_level is not given' do + it "returns 400 when access_level is not given" do put api("/#{source_type.pluralize}/#{source.id}/members/#{developer.id}", maintainer) expect(response).to have_gitlab_http_status(400) end - it 'returns 400 when access level is not valid' do + it "returns 400 when access level is not valid" do put api("/#{source_type.pluralize}/#{source.id}/members/#{developer.id}", maintainer), - params: { access_level: 1234 } + params: {access_level: 1234} expect(response).to have_gitlab_http_status(400) end end end - shared_examples 'DELETE /:source_type/:id/members/:user_id' do |source_type| + shared_examples "DELETE /:source_type/:id/members/:user_id" do |source_type| context "with :source_type == #{source_type.pluralize}" do - it_behaves_like 'a 404 response when source is private' do + it_behaves_like "a 404 response when source is private" do let(:route) { delete api("/#{source_type.pluralize}/#{source.id}/members/#{developer.id}", stranger) } end - context 'when authenticated as a non-member or member with insufficient rights' do + context "when authenticated as a non-member or member with insufficient rights" do %i[access_requester stranger].each do |type| context "as a #{type}" do - it 'returns 403' do + it "returns 403" do user = public_send(type) delete api("/#{source_type.pluralize}/#{source.id}/members/#{developer.id}", user) @@ -369,41 +369,41 @@ describe API::Members do end end - context 'when authenticated as a member and deleting themself' do - it 'deletes the member' do - expect do + context "when authenticated as a member and deleting themself" do + it "deletes the member" do + expect { delete api("/#{source_type.pluralize}/#{source.id}/members/#{developer.id}", developer) expect(response).to have_gitlab_http_status(204) - end.to change { source.members.count }.by(-1) + }.to change { source.members.count }.by(-1) end end - context 'when authenticated as a maintainer/owner' do - context 'and member is a requester' do - it 'returns 404' do - expect do + context "when authenticated as a maintainer/owner" do + context "and member is a requester" do + it "returns 404" do + expect { delete api("/#{source_type.pluralize}/#{source.id}/members/#{access_requester.id}", maintainer) expect(response).to have_gitlab_http_status(404) - end.not_to change { source.requesters.count } + }.not_to change { source.requesters.count } end end - it 'deletes the member' do - expect do + it "deletes the member" do + expect { delete api("/#{source_type.pluralize}/#{source.id}/members/#{developer.id}", maintainer) expect(response).to have_gitlab_http_status(204) - end.to change { source.members.count }.by(-1) + }.to change { source.members.count }.by(-1) end - it_behaves_like '412 response' do + it_behaves_like "412 response" do let(:request) { api("/#{source_type.pluralize}/#{source.id}/members/#{developer.id}", maintainer) } end end - it 'returns 404 if member does not exist' do + it "returns 404 if member does not exist" do delete api("/#{source_type.pluralize}/#{source.id}/members/123", maintainer) expect(response).to have_gitlab_http_status(404) @@ -412,55 +412,55 @@ describe API::Members do end [false, true].each do |all| - it_behaves_like 'GET /:source_type/:id/members/(all)', 'project', all do + it_behaves_like "GET /:source_type/:id/members/(all)", "project", all do let(:source) { project } end - it_behaves_like 'GET /:source_type/:id/members/(all)', 'group', all do + it_behaves_like "GET /:source_type/:id/members/(all)", "group", all do let(:source) { group } end end - it_behaves_like 'GET /:source_type/:id/members/:user_id', 'project' do + it_behaves_like "GET /:source_type/:id/members/:user_id", "project" do let(:source) { project } end - it_behaves_like 'GET /:source_type/:id/members/:user_id', 'group' do + it_behaves_like "GET /:source_type/:id/members/:user_id", "group" do let(:source) { group } end - it_behaves_like 'POST /:source_type/:id/members', 'project' do + it_behaves_like "POST /:source_type/:id/members", "project" do let(:source) { project } end - it_behaves_like 'POST /:source_type/:id/members', 'group' do + it_behaves_like "POST /:source_type/:id/members", "group" do let(:source) { group } end - it_behaves_like 'PUT /:source_type/:id/members/:user_id', 'project' do + it_behaves_like "PUT /:source_type/:id/members/:user_id", "project" do let(:source) { project } end - it_behaves_like 'PUT /:source_type/:id/members/:user_id', 'group' do + it_behaves_like "PUT /:source_type/:id/members/:user_id", "group" do let(:source) { group } end - it_behaves_like 'DELETE /:source_type/:id/members/:user_id', 'project' do + it_behaves_like "DELETE /:source_type/:id/members/:user_id", "project" do let(:source) { project } end - it_behaves_like 'DELETE /:source_type/:id/members/:user_id', 'group' do + it_behaves_like "DELETE /:source_type/:id/members/:user_id", "group" do let(:source) { group } end - context 'Adding owner to project' do - it 'returns 403' do - expect do + context "Adding owner to project" do + it "returns 403" do + expect { post api("/projects/#{project.id}/members", maintainer), - params: { user_id: stranger.id, access_level: Member::OWNER } + params: {user_id: stranger.id, access_level: Member::OWNER} expect(response).to have_gitlab_http_status(400) - end.to change { project.members.count }.by(0) + }.to change { project.members.count }.by(0) end end end diff --git a/spec/requests/api/merge_request_diffs_spec.rb b/spec/requests/api/merge_request_diffs_spec.rb index 8a67d98fc4c..806ba6d4d16 100644 --- a/spec/requests/api/merge_request_diffs_spec.rb +++ b/spec/requests/api/merge_request_diffs_spec.rb @@ -1,18 +1,18 @@ require "spec_helper" -describe API::MergeRequestDiffs, 'MergeRequestDiffs' do +describe API::MergeRequestDiffs, "MergeRequestDiffs" do let!(:user) { create(:user) } let!(:merge_request) { create(:merge_request, importing: true) } let!(:project) { merge_request.target_project } before do - merge_request.merge_request_diffs.create(head_commit_sha: '6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9') - merge_request.merge_request_diffs.create(head_commit_sha: '5937ac0a7beb003549fc5fd26fc247adbce4a52e') + merge_request.merge_request_diffs.create(head_commit_sha: "6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9") + merge_request.merge_request_diffs.create(head_commit_sha: "5937ac0a7beb003549fc5fd26fc247adbce4a52e") project.add_maintainer(user) end - describe 'GET /projects/:id/merge_requests/:merge_request_iid/versions' do - it 'returns 200 for a valid merge request' do + describe "GET /projects/:id/merge_requests/:merge_request_iid/versions" do + it "returns 200 for a valid merge request" do get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/versions", user) merge_request_diff = merge_request.merge_request_diffs.last @@ -20,44 +20,44 @@ describe API::MergeRequestDiffs, 'MergeRequestDiffs' do expect(response).to include_pagination_headers expect(json_response).to be_an Array expect(json_response.size).to eq(merge_request.merge_request_diffs.size) - expect(json_response.first['id']).to eq(merge_request_diff.id) - expect(json_response.first['head_commit_sha']).to eq(merge_request_diff.head_commit_sha) + expect(json_response.first["id"]).to eq(merge_request_diff.id) + expect(json_response.first["head_commit_sha"]).to eq(merge_request_diff.head_commit_sha) end - it 'returns a 404 when merge_request id is used instead of the iid' do + it "returns a 404 when merge_request id is used instead of the iid" do get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/versions", user) expect(response).to have_gitlab_http_status(404) end - it 'returns a 404 when merge_request_iid not found' do + it "returns a 404 when merge_request_iid not found" do get api("/projects/#{project.id}/merge_requests/0/versions", user) expect(response).to have_gitlab_http_status(404) end end - describe 'GET /projects/:id/merge_requests/:merge_request_iid/versions/:version_id' do + describe "GET /projects/:id/merge_requests/:merge_request_iid/versions/:version_id" do let(:merge_request_diff) { merge_request.merge_request_diffs.first } - it 'returns a 200 for a valid merge request' do + it "returns a 200 for a valid merge request" do get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/versions/#{merge_request_diff.id}", user) expect(response.status).to eq 200 - expect(json_response['id']).to eq(merge_request_diff.id) - expect(json_response['head_commit_sha']).to eq(merge_request_diff.head_commit_sha) - expect(json_response['diffs'].size).to eq(merge_request_diff.diffs.size) + expect(json_response["id"]).to eq(merge_request_diff.id) + expect(json_response["head_commit_sha"]).to eq(merge_request_diff.head_commit_sha) + expect(json_response["diffs"].size).to eq(merge_request_diff.diffs.size) end - it 'returns a 404 when merge_request id is used instead of the iid' do + it "returns a 404 when merge_request id is used instead of the iid" do get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/versions/#{merge_request_diff.id}", user) expect(response).to have_gitlab_http_status(404) end - it 'returns a 404 when merge_request version_id is not found' do + it "returns a 404 when merge_request version_id is not found" do get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/versions/0", user) expect(response).to have_gitlab_http_status(404) end - it 'returns a 404 when merge_request_iid is not found' do + it "returns a 404 when merge_request_iid is not found" do get api("/projects/#{project.id}/merge_requests/12345/versions/#{merge_request_diff.id}", user) expect(response).to have_gitlab_http_status(404) end diff --git a/spec/requests/api/merge_requests_spec.rb b/spec/requests/api/merge_requests_spec.rb index 6272bb38d59..3c0a6286a5f 100644 --- a/spec/requests/api/merge_requests_spec.rb +++ b/spec/requests/api/merge_requests_spec.rb @@ -8,19 +8,19 @@ describe API::MergeRequests do let(:admin) { create(:user, :admin) } let(:non_member) { create(:user) } let!(:project) { create(:project, :public, :repository, creator: user, namespace: user.namespace, only_allow_merge_if_pipeline_succeeds: false) } - let(:milestone) { create(:milestone, title: '1.0.0', project: project) } + let(:milestone) { create(:milestone, title: "1.0.0", project: project) } let(:pipeline) { create(:ci_empty_pipeline) } - let(:milestone1) { create(:milestone, title: '0.9', project: project) } + let(:milestone1) { create(:milestone, title: "0.9", project: project) } let!(:merge_request) { create(:merge_request, :simple, milestone: milestone1, author: user, assignee: user, source_project: project, target_project: project, title: "Test", created_at: base_time) } let!(:merge_request_closed) { create(:merge_request, state: "closed", milestone: milestone1, author: user, assignee: user, source_project: project, target_project: project, title: "Closed test", created_at: base_time + 1.second) } - let!(:merge_request_merged) { create(:merge_request, state: "merged", author: user, assignee: user, source_project: project, target_project: project, title: "Merged test", created_at: base_time + 2.seconds, merge_commit_sha: '9999999999999999999999999999999999999999') } + let!(:merge_request_merged) { create(:merge_request, state: "merged", author: user, assignee: user, source_project: project, target_project: project, title: "Merged test", created_at: base_time + 2.seconds, merge_commit_sha: "9999999999999999999999999999999999999999") } let!(:merge_request_locked) { create(:merge_request, state: "locked", milestone: milestone1, author: user, assignee: user, source_project: project, target_project: project, title: "Locked test", created_at: base_time + 1.second) } let!(:note) { create(:note_on_merge_request, author: user, project: project, noteable: merge_request, note: "a comment on a MR") } let!(:note2) { create(:note_on_merge_request, author: user, project: project, noteable: merge_request, note: "another comment on a MR") } let!(:label) do - create(:label, title: 'label', color: '#FFAABB', project: project) + create(:label, title: "label", color: "#FFAABB", project: project) end - let!(:label2) { create(:label, title: 'a-test', color: '#FFFFFF', project: project) } + let!(:label2) { create(:label, title: "a-test", color: "#FFFFFF", project: project) } let!(:label_link) { create(:label_link, label: label, target: merge_request) } let!(:label_link2) { create(:label_link, label: label2, target: merge_request) } let!(:downvote) { create(:award_emoji, :downvote, awardable: merge_request) } @@ -30,22 +30,22 @@ describe API::MergeRequests do project.add_reporter(user) end - describe 'route shadowing' do + describe "route shadowing" do include GrapePathHelpers::NamedRouteMatcher - it 'does not occur' do + it "does not occur" do path = api_v4_projects_merge_requests_path(id: 1) - expect(path).to eq('/api/v4/projects/1/merge_requests') + expect(path).to eq("/api/v4/projects/1/merge_requests") path = api_v4_projects_merge_requests_path(id: 1, merge_request_iid: 3) - expect(path).to eq('/api/v4/projects/1/merge_requests/3') + expect(path).to eq("/api/v4/projects/1/merge_requests/3") end end - describe 'GET /merge_requests' do - context 'when unauthenticated' do - it 'returns an array of all merge requests' do - get api('/merge_requests', user), params: { scope: 'all' } + describe "GET /merge_requests" do + context "when unauthenticated" do + it "returns an array of all merge requests" do + get api("/merge_requests", user), params: {scope: "all"} expect_paginated_array_response end @@ -57,41 +57,41 @@ describe API::MergeRequests do end it "returns authentication error when scope is assigned-to-me" do - get api("/merge_requests"), params: { scope: 'assigned-to-me' } + get api("/merge_requests"), params: {scope: "assigned-to-me"} expect(response).to have_gitlab_http_status(401) end it "returns authentication error when scope is assigned_to_me" do - get api("/merge_requests"), params: { scope: 'assigned_to_me' } + get api("/merge_requests"), params: {scope: "assigned_to_me"} expect(response).to have_gitlab_http_status(401) end it "returns authentication error when scope is created-by-me" do - get api("/merge_requests"), params: { scope: 'created-by-me' } + get api("/merge_requests"), params: {scope: "created-by-me"} expect(response).to have_gitlab_http_status(401) end end - context 'when authenticated' do + context "when authenticated" do let!(:project2) { create(:project, :public, namespace: user.namespace) } let!(:merge_request2) { create(:merge_request, :simple, author: user, assignee: user, source_project: project2, target_project: project2) } let(:user2) { create(:user) } - it 'returns an array of all merge requests except unauthorized ones' do - get api('/merge_requests', user), params: { scope: :all } + it "returns an array of all merge requests except unauthorized ones" do + get api("/merge_requests", user), params: {scope: :all} expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response).to be_an Array - expect(json_response.map { |mr| mr['id'] }) + expect(json_response.map { |mr| mr["id"] }) .to contain_exactly(merge_request.id, merge_request_closed.id, merge_request_merged.id, merge_request_locked.id, merge_request2.id) end it "returns an array of no merge_requests when wip=yes" do - get api("/merge_requests", user), params: { wip: 'yes' } + get api("/merge_requests", user), params: {wip: "yes"} expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers @@ -100,188 +100,188 @@ describe API::MergeRequests do end it "returns an array of no merge_requests when wip=no" do - get api("/merge_requests", user), params: { wip: 'no' } + get api("/merge_requests", user), params: {wip: "no"} expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response).to be_an Array - expect(json_response.map { |mr| mr['id'] }) - .to contain_exactly(merge_request.id, merge_request_closed.id, merge_request_merged.id, merge_request_locked.id, merge_request2.id) + expect(json_response.map { |mr| mr["id"] }) + .to contain_exactly(merge_request.id, merge_request_closed.id, merge_request_merged.id, merge_request_locked.id, merge_request2.id) end - it 'does not return unauthorized merge requests' do + it "does not return unauthorized merge requests" do private_project = create(:project, :private) - merge_request3 = create(:merge_request, :simple, source_project: private_project, target_project: private_project, source_branch: 'other-branch') + merge_request3 = create(:merge_request, :simple, source_project: private_project, target_project: private_project, source_branch: "other-branch") - get api('/merge_requests', user), params: { scope: :all } + get api("/merge_requests", user), params: {scope: :all} expect_response_contain_exactly(merge_request2, merge_request_merged, merge_request_closed, merge_request, merge_request_locked) - expect(json_response.map { |mr| mr['id'] }).not_to include(merge_request3.id) + expect(json_response.map { |mr| mr["id"] }).not_to include(merge_request3.id) end - it 'returns an array of merge requests created by current user if no scope is given' do - merge_request3 = create(:merge_request, :simple, author: user2, assignee: user, source_project: project2, target_project: project2, source_branch: 'other-branch') + it "returns an array of merge requests created by current user if no scope is given" do + merge_request3 = create(:merge_request, :simple, author: user2, assignee: user, source_project: project2, target_project: project2, source_branch: "other-branch") - get api('/merge_requests', user2) + get api("/merge_requests", user2) expect_response_ordered_exactly(merge_request3) end - it 'returns an array of merge requests authored by the given user' do - merge_request3 = create(:merge_request, :simple, author: user2, assignee: user, source_project: project2, target_project: project2, source_branch: 'other-branch') + it "returns an array of merge requests authored by the given user" do + merge_request3 = create(:merge_request, :simple, author: user2, assignee: user, source_project: project2, target_project: project2, source_branch: "other-branch") - get api('/merge_requests', user), params: { author_id: user2.id, scope: :all } + get api("/merge_requests", user), params: {author_id: user2.id, scope: :all} expect_response_ordered_exactly(merge_request3) end - it 'returns an array of merge requests assigned to the given user' do - merge_request3 = create(:merge_request, :simple, author: user, assignee: user2, source_project: project2, target_project: project2, source_branch: 'other-branch') + it "returns an array of merge requests assigned to the given user" do + merge_request3 = create(:merge_request, :simple, author: user, assignee: user2, source_project: project2, target_project: project2, source_branch: "other-branch") - get api('/merge_requests', user), params: { assignee_id: user2.id, scope: :all } + get api("/merge_requests", user), params: {assignee_id: user2.id, scope: :all} expect_response_ordered_exactly(merge_request3) end - it 'returns an array of merge requests with no assignee' do - merge_request3 = create(:merge_request, :simple, author: user, source_project: project2, target_project: project2, source_branch: 'other-branch') + it "returns an array of merge requests with no assignee" do + merge_request3 = create(:merge_request, :simple, author: user, source_project: project2, target_project: project2, source_branch: "other-branch") - get api('/merge_requests', user), params: { assignee_id: 'None', scope: :all } + get api("/merge_requests", user), params: {assignee_id: "None", scope: :all} expect_response_ordered_exactly(merge_request3) end - it 'returns an array of merge requests with any assignee' do + it "returns an array of merge requests with any assignee" do # This MR with no assignee should not be returned - create(:merge_request, :simple, author: user, source_project: project2, target_project: project2, source_branch: 'other-branch') + create(:merge_request, :simple, author: user, source_project: project2, target_project: project2, source_branch: "other-branch") - get api('/merge_requests', user), params: { assignee_id: 'Any', scope: :all } + get api("/merge_requests", user), params: {assignee_id: "Any", scope: :all} expect_response_contain_exactly(merge_request, merge_request2, merge_request_closed, merge_request_merged, merge_request_locked) end - it 'returns an array of merge requests assigned to me' do - merge_request3 = create(:merge_request, :simple, author: user, assignee: user2, source_project: project2, target_project: project2, source_branch: 'other-branch') + it "returns an array of merge requests assigned to me" do + merge_request3 = create(:merge_request, :simple, author: user, assignee: user2, source_project: project2, target_project: project2, source_branch: "other-branch") - get api('/merge_requests', user2), params: { scope: 'assigned_to_me' } + get api("/merge_requests", user2), params: {scope: "assigned_to_me"} expect_response_ordered_exactly(merge_request3) end - it 'returns an array of merge requests assigned to me (kebab-case)' do - merge_request3 = create(:merge_request, :simple, author: user, assignee: user2, source_project: project2, target_project: project2, source_branch: 'other-branch') + it "returns an array of merge requests assigned to me (kebab-case)" do + merge_request3 = create(:merge_request, :simple, author: user, assignee: user2, source_project: project2, target_project: project2, source_branch: "other-branch") - get api('/merge_requests', user2), params: { scope: 'assigned-to-me' } + get api("/merge_requests", user2), params: {scope: "assigned-to-me"} expect_response_ordered_exactly(merge_request3) end - it 'returns an array of merge requests created by me' do - merge_request3 = create(:merge_request, :simple, author: user2, assignee: user, source_project: project2, target_project: project2, source_branch: 'other-branch') + it "returns an array of merge requests created by me" do + merge_request3 = create(:merge_request, :simple, author: user2, assignee: user, source_project: project2, target_project: project2, source_branch: "other-branch") - get api('/merge_requests', user2), params: { scope: 'created_by_me' } + get api("/merge_requests", user2), params: {scope: "created_by_me"} expect_response_ordered_exactly(merge_request3) end - it 'returns an array of merge requests created by me (kebab-case)' do - merge_request3 = create(:merge_request, :simple, author: user2, assignee: user, source_project: project2, target_project: project2, source_branch: 'other-branch') + it "returns an array of merge requests created by me (kebab-case)" do + merge_request3 = create(:merge_request, :simple, author: user2, assignee: user, source_project: project2, target_project: project2, source_branch: "other-branch") - get api('/merge_requests', user2), params: { scope: 'created-by-me' } + get api("/merge_requests", user2), params: {scope: "created-by-me"} expect_response_ordered_exactly(merge_request3) end - it 'returns merge requests reacted by the authenticated user by the given emoji' do - merge_request3 = create(:merge_request, :simple, author: user, assignee: user, source_project: project2, target_project: project2, source_branch: 'other-branch') - award_emoji = create(:award_emoji, awardable: merge_request3, user: user2, name: 'star') + it "returns merge requests reacted by the authenticated user by the given emoji" do + merge_request3 = create(:merge_request, :simple, author: user, assignee: user, source_project: project2, target_project: project2, source_branch: "other-branch") + award_emoji = create(:award_emoji, awardable: merge_request3, user: user2, name: "star") - get api('/merge_requests', user2), params: { my_reaction_emoji: award_emoji.name, scope: 'all' } + get api("/merge_requests", user2), params: {my_reaction_emoji: award_emoji.name, scope: "all"} expect_response_ordered_exactly(merge_request3) end - context 'source_branch param' do - it 'returns merge requests with the given source branch' do - get api('/merge_requests', user), params: { source_branch: merge_request_closed.source_branch, state: 'all' } + context "source_branch param" do + it "returns merge requests with the given source branch" do + get api("/merge_requests", user), params: {source_branch: merge_request_closed.source_branch, state: "all"} expect_response_contain_exactly(merge_request_closed, merge_request_merged, merge_request_locked) end end - context 'target_branch param' do - it 'returns merge requests with the given target branch' do - get api('/merge_requests', user), params: { target_branch: merge_request_closed.target_branch, state: 'all' } + context "target_branch param" do + it "returns merge requests with the given target branch" do + get api("/merge_requests", user), params: {target_branch: merge_request_closed.target_branch, state: "all"} expect_response_contain_exactly(merge_request_closed, merge_request_merged, merge_request_locked) end end - it 'returns merge requests created before a specific date' do - merge_request2 = create(:merge_request, :simple, source_project: project, target_project: project, source_branch: 'feature_1', created_at: Date.new(2000, 1, 1)) + it "returns merge requests created before a specific date" do + merge_request2 = create(:merge_request, :simple, source_project: project, target_project: project, source_branch: "feature_1", created_at: Date.new(2000, 1, 1)) - get api('/merge_requests?created_before=2000-01-02T00:00:00.060Z', user) + get api("/merge_requests?created_before=2000-01-02T00:00:00.060Z", user) expect_response_ordered_exactly(merge_request2) end - it 'returns merge requests created after a specific date' do - merge_request2 = create(:merge_request, :simple, source_project: project, target_project: project, source_branch: 'feature_1', created_at: 1.week.from_now) + it "returns merge requests created after a specific date" do + merge_request2 = create(:merge_request, :simple, source_project: project, target_project: project, source_branch: "feature_1", created_at: 1.week.from_now) get api("/merge_requests?created_after=#{merge_request2.created_at}", user) expect_response_ordered_exactly(merge_request2) end - it 'returns merge requests updated before a specific date' do - merge_request2 = create(:merge_request, :simple, source_project: project, target_project: project, source_branch: 'feature_1', updated_at: Date.new(2000, 1, 1)) + it "returns merge requests updated before a specific date" do + merge_request2 = create(:merge_request, :simple, source_project: project, target_project: project, source_branch: "feature_1", updated_at: Date.new(2000, 1, 1)) - get api('/merge_requests?updated_before=2000-01-02T00:00:00.060Z', user) + get api("/merge_requests?updated_before=2000-01-02T00:00:00.060Z", user) expect_response_ordered_exactly(merge_request2) end - it 'returns merge requests updated after a specific date' do - merge_request2 = create(:merge_request, :simple, source_project: project, target_project: project, source_branch: 'feature_1', updated_at: 1.week.from_now) + it "returns merge requests updated after a specific date" do + merge_request2 = create(:merge_request, :simple, source_project: project, target_project: project, source_branch: "feature_1", updated_at: 1.week.from_now) get api("/merge_requests?updated_after=#{merge_request2.updated_at}", user) expect_response_ordered_exactly(merge_request2) end - context 'search params' do + context "search params" do before do - merge_request.update(title: 'Search title', description: 'Search description') + merge_request.update(title: "Search title", description: "Search description") end - it 'returns merge requests matching given search string for title' do - get api("/merge_requests", user), params: { search: merge_request.title } + it "returns merge requests matching given search string for title" do + get api("/merge_requests", user), params: {search: merge_request.title} expect_response_ordered_exactly(merge_request) end - it 'returns merge requests matching given search string for title and scoped in title' do - get api("/merge_requests", user), params: { search: merge_request.title, in: 'title' } + it "returns merge requests matching given search string for title and scoped in title" do + get api("/merge_requests", user), params: {search: merge_request.title, in: "title"} expect_response_ordered_exactly(merge_request) end - it 'returns an empty array if no merge reques matches given search string for description and scoped in title' do - get api("/merge_requests", user), params: { search: merge_request.description, in: 'title' } + it "returns an empty array if no merge reques matches given search string for description and scoped in title" do + get api("/merge_requests", user), params: {search: merge_request.description, in: "title"} expect_response_contain_exactly end - it 'returns merge requests for project matching given search string for description' do - get api("/merge_requests", user), params: { project_id: project.id, search: merge_request.description } + it "returns merge requests for project matching given search string for description" do + get api("/merge_requests", user), params: {project_id: project.id, search: merge_request.description} expect_response_ordered_exactly(merge_request) end end - context 'state param' do - it 'returns merge requests with the given state' do - get api('/merge_requests', user), params: { state: 'locked' } + context "state param" do + it "returns merge requests with the given state" do + get api("/merge_requests", user), params: {state: "locked"} expect_response_contain_exactly(merge_request_locked) end @@ -292,7 +292,7 @@ describe API::MergeRequests do describe "GET /projects/:id/merge_requests" do let(:endpoint_path) { "/projects/#{project.id}/merge_requests" } - it_behaves_like 'merge requests list' + it_behaves_like "merge requests list" it "returns 404 for non public projects" do project = create(:project, :private) @@ -303,7 +303,7 @@ describe API::MergeRequests do end it "returns an array of no merge_requests when wip=yes" do - get api("/projects/#{project.id}/merge_requests", user), params: { wip: 'yes' } + get api("/projects/#{project.id}/merge_requests", user), params: {wip: "yes"} expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers @@ -312,25 +312,25 @@ describe API::MergeRequests do end it 'returns merge_request by "iids" array' do - get api(endpoint_path, user), params: { iids: [merge_request.iid, merge_request_closed.iid] } + get api(endpoint_path, user), params: {iids: [merge_request.iid, merge_request_closed.iid]} expect(response).to have_gitlab_http_status(200) expect(json_response).to be_an Array expect(json_response.length).to eq(2) - expect(json_response.first['title']).to eq merge_request_closed.title - expect(json_response.first['id']).to eq merge_request_closed.id + expect(json_response.first["title"]).to eq merge_request_closed.title + expect(json_response.first["id"]).to eq merge_request_closed.id end - it 'avoids N+1 queries' do - control = ActiveRecord::QueryRecorder.new do + it "avoids N+1 queries" do + control = ActiveRecord::QueryRecorder.new { get api("/projects/#{project.id}/merge_requests", user) - end.count + }.count create(:merge_request, author: user, assignee: user, source_project: project, target_project: project, created_at: base_time) - expect do + expect { get api("/projects/#{project.id}/merge_requests", user) - end.not_to exceed_query_limit(control) + }.not_to exceed_query_limit(control) end end @@ -343,68 +343,68 @@ describe API::MergeRequests do group.add_reporter(user) end - it_behaves_like 'merge requests list' + it_behaves_like "merge requests list" - context 'when have subgroups', :nested_groups do + context "when have subgroups", :nested_groups do let!(:group) { create(:group, :public) } let!(:subgroup) { create(:group, parent: group) } let!(:project) { create(:project, :public, :repository, creator: user, namespace: subgroup, only_allow_merge_if_pipeline_succeeds: false) } - it_behaves_like 'merge requests list' + it_behaves_like "merge requests list" end end describe "GET /projects/:id/merge_requests/:merge_request_iid" do - it 'exposes known attributes' do + it "exposes known attributes" do get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user) expect(response).to have_gitlab_http_status(200) - expect(json_response['id']).to eq(merge_request.id) - expect(json_response['iid']).to eq(merge_request.iid) - expect(json_response['project_id']).to eq(merge_request.project.id) - expect(json_response['title']).to eq(merge_request.title) - expect(json_response['description']).to eq(merge_request.description) - expect(json_response['state']).to eq(merge_request.state) - expect(json_response['created_at']).to be_present - expect(json_response['updated_at']).to be_present - expect(json_response['labels']).to eq(merge_request.label_names) - expect(json_response['milestone']).to be_a Hash - expect(json_response['assignee']).to be_a Hash - expect(json_response['author']).to be_a Hash - expect(json_response['target_branch']).to eq(merge_request.target_branch) - expect(json_response['source_branch']).to eq(merge_request.source_branch) - expect(json_response['upvotes']).to eq(1) - expect(json_response['downvotes']).to eq(1) - expect(json_response['source_project_id']).to eq(merge_request.source_project.id) - expect(json_response['target_project_id']).to eq(merge_request.target_project.id) - expect(json_response['work_in_progress']).to be_falsy - expect(json_response['merge_when_pipeline_succeeds']).to be_falsy - expect(json_response['merge_status']).to eq('can_be_merged') - expect(json_response['should_close_merge_request']).to be_falsy - expect(json_response['force_close_merge_request']).to be_falsy - expect(json_response['changes_count']).to eq(merge_request.merge_request_diff.real_size) - expect(json_response['merge_error']).to eq(merge_request.merge_error) - expect(json_response['user']['can_merge']).to be_truthy - expect(json_response).not_to include('rebase_in_progress') - end - - it 'exposes description and title html when render_html is true' do - get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user), params: { render_html: true } + expect(json_response["id"]).to eq(merge_request.id) + expect(json_response["iid"]).to eq(merge_request.iid) + expect(json_response["project_id"]).to eq(merge_request.project.id) + expect(json_response["title"]).to eq(merge_request.title) + expect(json_response["description"]).to eq(merge_request.description) + expect(json_response["state"]).to eq(merge_request.state) + expect(json_response["created_at"]).to be_present + expect(json_response["updated_at"]).to be_present + expect(json_response["labels"]).to eq(merge_request.label_names) + expect(json_response["milestone"]).to be_a Hash + expect(json_response["assignee"]).to be_a Hash + expect(json_response["author"]).to be_a Hash + expect(json_response["target_branch"]).to eq(merge_request.target_branch) + expect(json_response["source_branch"]).to eq(merge_request.source_branch) + expect(json_response["upvotes"]).to eq(1) + expect(json_response["downvotes"]).to eq(1) + expect(json_response["source_project_id"]).to eq(merge_request.source_project.id) + expect(json_response["target_project_id"]).to eq(merge_request.target_project.id) + expect(json_response["work_in_progress"]).to be_falsy + expect(json_response["merge_when_pipeline_succeeds"]).to be_falsy + expect(json_response["merge_status"]).to eq("can_be_merged") + expect(json_response["should_close_merge_request"]).to be_falsy + expect(json_response["force_close_merge_request"]).to be_falsy + expect(json_response["changes_count"]).to eq(merge_request.merge_request_diff.real_size) + expect(json_response["merge_error"]).to eq(merge_request.merge_error) + expect(json_response["user"]["can_merge"]).to be_truthy + expect(json_response).not_to include("rebase_in_progress") + end + + it "exposes description and title html when render_html is true" do + get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user), params: {render_html: true} expect(response).to have_gitlab_http_status(200) - expect(json_response).to include('title_html', 'description_html') + expect(json_response).to include("title_html", "description_html") end - it 'exposes rebase_in_progress when include_rebase_in_progress is true' do - get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user), params: { include_rebase_in_progress: true } + it "exposes rebase_in_progress when include_rebase_in_progress is true" do + get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user), params: {include_rebase_in_progress: true} expect(response).to have_gitlab_http_status(200) - expect(json_response).to include('rebase_in_progress') + expect(json_response).to include("rebase_in_progress") end - context 'merge_request_metrics' do + context "merge_request_metrics" do before do merge_request.metrics.update!(merged_by: user, latest_closed_by: user, @@ -416,40 +416,40 @@ describe API::MergeRequests do first_deployed_to_production_at: 3.minutes.ago) end - it 'has fields from merge request metrics' do + it "has fields from merge request metrics" do get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user) - expect(json_response).to include('merged_by', - 'merged_at', - 'closed_by', - 'closed_at', - 'latest_build_started_at', - 'latest_build_finished_at', - 'first_deployed_to_production_at', - 'pipeline') + expect(json_response).to include("merged_by", + "merged_at", + "closed_by", + "closed_at", + "latest_build_started_at", + "latest_build_finished_at", + "first_deployed_to_production_at", + "pipeline") end - it 'returns correct values' do + it "returns correct values" do get api("/projects/#{project.id}/merge_requests/#{merge_request.reload.iid}", user) - expect(json_response['merged_by']['id']).to eq(merge_request.metrics.merged_by_id) - expect(Time.parse json_response['merged_at']).to be_like_time(merge_request.metrics.merged_at) - expect(json_response['closed_by']['id']).to eq(merge_request.metrics.latest_closed_by_id) - expect(Time.parse json_response['closed_at']).to be_like_time(merge_request.metrics.latest_closed_at) - expect(json_response['pipeline']['id']).to eq(merge_request.metrics.pipeline_id) - expect(Time.parse json_response['latest_build_started_at']).to be_like_time(merge_request.metrics.latest_build_started_at) - expect(Time.parse json_response['latest_build_finished_at']).to be_like_time(merge_request.metrics.latest_build_finished_at) - expect(Time.parse json_response['first_deployed_to_production_at']).to be_like_time(merge_request.metrics.first_deployed_to_production_at) + expect(json_response["merged_by"]["id"]).to eq(merge_request.metrics.merged_by_id) + expect(Time.parse(json_response["merged_at"])).to be_like_time(merge_request.metrics.merged_at) + expect(json_response["closed_by"]["id"]).to eq(merge_request.metrics.latest_closed_by_id) + expect(Time.parse(json_response["closed_at"])).to be_like_time(merge_request.metrics.latest_closed_at) + expect(json_response["pipeline"]["id"]).to eq(merge_request.metrics.pipeline_id) + expect(Time.parse(json_response["latest_build_started_at"])).to be_like_time(merge_request.metrics.latest_build_started_at) + expect(Time.parse(json_response["latest_build_finished_at"])).to be_like_time(merge_request.metrics.latest_build_finished_at) + expect(Time.parse(json_response["first_deployed_to_production_at"])).to be_like_time(merge_request.metrics.first_deployed_to_production_at) end end - it 'returns the commits behind the target branch when include_diverged_commits_count is present' do + it "returns the commits behind the target branch when include_diverged_commits_count is present" do allow_any_instance_of(merge_request.class).to receive(:diverged_commits_count).and_return(1) - get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user), params: { include_diverged_commits_count: true } + get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user), params: {include_diverged_commits_count: true} expect(response).to have_gitlab_http_status(200) - expect(json_response['diverged_commits_count']).to eq(1) + expect(json_response["diverged_commits_count"]).to eq(1) end it "returns a 404 error if merge_request_iid not found" do @@ -463,74 +463,74 @@ describe API::MergeRequests do expect(response).to have_gitlab_http_status(404) end - context 'Work in Progress' do + context "Work in Progress" do let!(:merge_request_wip) { create(:merge_request, author: user, assignee: user, source_project: project, target_project: project, title: "WIP: Test", created_at: base_time + 1.second) } it "returns merge request" do get api("/projects/#{project.id}/merge_requests/#{merge_request_wip.iid}", user) expect(response).to have_gitlab_http_status(200) - expect(json_response['work_in_progress']).to eq(true) + expect(json_response["work_in_progress"]).to eq(true) end end - context 'when a merge request has more than the changes limit' do + context "when a merge request has more than the changes limit" do it "returns a string indicating that more changes were made" do - stub_const('Commit::DIFF_HARD_LIMIT_FILES', 5) + stub_const("Commit::DIFF_HARD_LIMIT_FILES", 5) merge_request_overflow = create(:merge_request, :simple, - author: user, - assignee: user, - source_project: project, - source_branch: 'expand-collapse-files', - target_project: project, - target_branch: 'master') + author: user, + assignee: user, + source_project: project, + source_branch: "expand-collapse-files", + target_project: project, + target_branch: "master") get api("/projects/#{project.id}/merge_requests/#{merge_request_overflow.iid}", user) expect(response).to have_gitlab_http_status(200) - expect(json_response['changes_count']).to eq('5+') + expect(json_response["changes_count"]).to eq("5+") end end - context 'for forked projects' do + context "for forked projects" do let(:user2) { create(:user) } let(:project) { create(:project, :public, :repository) } let(:forked_project) { fork_project(project, user2, repository: true) } let(:merge_request) do create(:merge_request, - source_project: forked_project, - target_project: project, - source_branch: 'fixes', - allow_collaboration: true) + source_project: forked_project, + target_project: project, + source_branch: "fixes", + allow_collaboration: true) end - it 'includes the `allow_collaboration` field' do + it "includes the `allow_collaboration` field" do get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user) - expect(json_response['allow_collaboration']).to be_truthy - expect(json_response['allow_maintainer_to_push']).to be_truthy + expect(json_response["allow_collaboration"]).to be_truthy + expect(json_response["allow_maintainer_to_push"]).to be_truthy end end - it 'indicates if a user cannot merge the MR' do + it "indicates if a user cannot merge the MR" do user2 = create(:user) project.add_reporter(user2) get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user2) - expect(json_response['user']['can_merge']).to be_falsy + expect(json_response["user"]["can_merge"]).to be_falsy end end - describe 'GET /projects/:id/merge_requests/:merge_request_iid/participants' do - it_behaves_like 'issuable participants endpoint' do + describe "GET /projects/:id/merge_requests/:merge_request_iid/participants" do + it_behaves_like "issuable participants endpoint" do let(:entity) { merge_request } end end - describe 'GET /projects/:id/merge_requests/:merge_request_iid/commits' do - it 'returns a 200 when merge request is valid' do + describe "GET /projects/:id/merge_requests/:merge_request_iid/commits" do + it "returns a 200 when merge request is valid" do get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/commits", user) commit = merge_request.commits.first @@ -538,73 +538,73 @@ describe API::MergeRequests do expect(response).to include_pagination_headers expect(json_response).to be_an Array expect(json_response.size).to eq(merge_request.commits.size) - expect(json_response.first['id']).to eq(commit.id) - expect(json_response.first['title']).to eq(commit.title) + expect(json_response.first["id"]).to eq(commit.id) + expect(json_response.first["title"]).to eq(commit.title) end - it 'returns a 404 when merge_request_iid not found' do + it "returns a 404 when merge_request_iid not found" do get api("/projects/#{project.id}/merge_requests/0/commits", user) expect(response).to have_gitlab_http_status(404) end - it 'returns a 404 when merge_request id is used instead of iid' do + it "returns a 404 when merge_request id is used instead of iid" do get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/commits", user) expect(response).to have_gitlab_http_status(404) end end - describe 'GET /projects/:id/merge_requests/:merge_request_iid/changes' do - it 'returns the change information of the merge_request' do + describe "GET /projects/:id/merge_requests/:merge_request_iid/changes" do + it "returns the change information of the merge_request" do get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/changes", user) expect(response).to have_gitlab_http_status(200) - expect(json_response['changes'].size).to eq(merge_request.diffs.size) + expect(json_response["changes"].size).to eq(merge_request.diffs.size) end - it 'returns a 404 when merge_request_iid not found' do + it "returns a 404 when merge_request_iid not found" do get api("/projects/#{project.id}/merge_requests/0/changes", user) expect(response).to have_gitlab_http_status(404) end - it 'returns a 404 when merge_request id is used instead of iid' do + it "returns a 404 when merge_request id is used instead of iid" do get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/changes", user) expect(response).to have_gitlab_http_status(404) end end - describe 'GET /projects/:id/merge_requests/:merge_request_iid/pipelines' do - context 'when authorized' do + describe "GET /projects/:id/merge_requests/:merge_request_iid/pipelines" do + context "when authorized" do let!(:pipeline) { create(:ci_empty_pipeline, project: project, user: user, ref: merge_request.source_branch, sha: merge_request.diff_head_sha) } let!(:pipeline2) { create(:ci_empty_pipeline, project: project) } - it 'returns a paginated array of corresponding pipelines' do + it "returns a paginated array of corresponding pipelines" do get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/pipelines") expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response).to be_an Array expect(json_response.count).to eq(1) - expect(json_response.first['id']).to eq(pipeline.id) + expect(json_response.first["id"]).to eq(pipeline.id) end - it 'exposes basic attributes' do + it "exposes basic attributes" do get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/pipelines") expect(response).to have_gitlab_http_status(200) - expect(response).to match_response_schema('public_api/v4/pipelines') + expect(response).to match_response_schema("public_api/v4/pipelines") end - it 'returns 404 if MR does not exist' do + it "returns 404 if MR does not exist" do get api("/projects/#{project.id}/merge_requests/777/pipelines") expect(response).to have_gitlab_http_status(404) end end - context 'when unauthorized' do - it 'returns 403' do + context "when unauthorized" do + it "returns 403" do project = create(:project, public_builds: false) merge_request = create(:merge_request, :simple, source_project: project) guest = create(:user) @@ -618,117 +618,117 @@ describe API::MergeRequests do end describe "POST /projects/:id/merge_requests" do - context 'between branches projects' do + context "between branches projects" do it "returns merge_request" do post api("/projects/#{project.id}/merge_requests", user), - params: { - title: 'Test merge_request', - source_branch: 'feature_conflict', - target_branch: 'master', - author: user, - labels: 'label, label2', - milestone_id: milestone.id, - squash: true - } + params: { + title: "Test merge_request", + source_branch: "feature_conflict", + target_branch: "master", + author: user, + labels: "label, label2", + milestone_id: milestone.id, + squash: true, + } expect(response).to have_gitlab_http_status(201) - expect(json_response['title']).to eq('Test merge_request') - expect(json_response['labels']).to eq(%w(label label2)) - expect(json_response['milestone']['id']).to eq(milestone.id) - expect(json_response['squash']).to be_truthy - expect(json_response['force_remove_source_branch']).to be_falsy + expect(json_response["title"]).to eq("Test merge_request") + expect(json_response["labels"]).to eq(%w[label label2]) + expect(json_response["milestone"]["id"]).to eq(milestone.id) + expect(json_response["squash"]).to be_truthy + expect(json_response["force_remove_source_branch"]).to be_falsy end it "returns 422 when source_branch equals target_branch" do post api("/projects/#{project.id}/merge_requests", user), - params: { title: "Test merge_request", source_branch: "master", target_branch: "master", author: user } + params: {title: "Test merge_request", source_branch: "master", target_branch: "master", author: user} expect(response).to have_gitlab_http_status(422) end it "returns 400 when source_branch is missing" do post api("/projects/#{project.id}/merge_requests", user), - params: { title: "Test merge_request", target_branch: "master", author: user } + params: {title: "Test merge_request", target_branch: "master", author: user} expect(response).to have_gitlab_http_status(400) end it "returns 400 when target_branch is missing" do post api("/projects/#{project.id}/merge_requests", user), - params: { title: "Test merge_request", source_branch: "markdown", author: user } + params: {title: "Test merge_request", source_branch: "markdown", author: user} expect(response).to have_gitlab_http_status(400) end it "returns 400 when title is missing" do post api("/projects/#{project.id}/merge_requests", user), - params: { target_branch: 'master', source_branch: 'markdown' } + params: {target_branch: "master", source_branch: "markdown"} expect(response).to have_gitlab_http_status(400) end - it 'allows special label names' do + it "allows special label names" do post api("/projects/#{project.id}/merge_requests", user), - params: { - title: 'Test merge_request', - source_branch: 'markdown', - target_branch: 'master', - author: user, - labels: 'label, label?, label&foo, ?, &' - } + params: { + title: "Test merge_request", + source_branch: "markdown", + target_branch: "master", + author: user, + labels: "label, label?, label&foo, ?, &", + } expect(response).to have_gitlab_http_status(201) - expect(json_response['labels']).to include 'label' - expect(json_response['labels']).to include 'label?' - expect(json_response['labels']).to include 'label&foo' - expect(json_response['labels']).to include '?' - expect(json_response['labels']).to include '&' + expect(json_response["labels"]).to include "label" + expect(json_response["labels"]).to include "label?" + expect(json_response["labels"]).to include "label&foo" + expect(json_response["labels"]).to include "?" + expect(json_response["labels"]).to include "&" end - context 'with existing MR' do + context "with existing MR" do before do post api("/projects/#{project.id}/merge_requests", user), - params: { - title: 'Test merge_request', - source_branch: 'feature_conflict', - target_branch: 'master', - author: user - } + params: { + title: "Test merge_request", + source_branch: "feature_conflict", + target_branch: "master", + author: user, + } @mr = MergeRequest.all.last end - it 'returns 409 when MR already exists for source/target' do - expect do + it "returns 409 when MR already exists for source/target" do + expect { post api("/projects/#{project.id}/merge_requests", user), - params: { - title: 'New test merge_request', - source_branch: 'feature_conflict', - target_branch: 'master', - author: user - } - end.to change { MergeRequest.count }.by(0) + params: { + title: "New test merge_request", + source_branch: "feature_conflict", + target_branch: "master", + author: user, + } + }.to change { MergeRequest.count }.by(0) expect(response).to have_gitlab_http_status(409) end end - context 'accepts remove_source_branch parameter' do + context "accepts remove_source_branch parameter" do let(:params) do - { title: 'Test merge_request', - source_branch: 'markdown', - target_branch: 'master', - author: user } + {title: "Test merge_request", + source_branch: "markdown", + target_branch: "master", + author: user,} end - it 'sets force_remove_source_branch to false' do + it "sets force_remove_source_branch to false" do post api("/projects/#{project.id}/merge_requests", user), params: params.merge(remove_source_branch: false) - expect(json_response['force_remove_source_branch']).to be_falsy + expect(json_response["force_remove_source_branch"]).to be_falsy end - it 'sets force_remove_source_branch to true' do + it "sets force_remove_source_branch to true" do post api("/projects/#{project.id}/merge_requests", user), params: params.merge(remove_source_branch: true) - expect(json_response['force_remove_source_branch']).to be_truthy + expect(json_response["force_remove_source_branch"]).to be_truthy end end end - context 'forked projects' do + context "forked projects" do let!(:user2) { create(:user) } let(:project) { create(:project, :public, :repository) } let!(:forked_project) { fork_project(project, user2, repository: true) } @@ -740,10 +740,10 @@ describe API::MergeRequests do it "returns merge_request" do post api("/projects/#{forked_project.id}/merge_requests", user2), - params: { 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' } + params: {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"} expect(response).to have_gitlab_http_status(201) - expect(json_response['title']).to eq('Test merge_request') - expect(json_response['description']).to eq('Test description for Test merge_request') + expect(json_response["title"]).to eq("Test merge_request") + expect(json_response["description"]).to eq("Test description for Test merge_request") end it "does not return 422 when source_branch equals target_branch" do @@ -751,62 +751,62 @@ describe API::MergeRequests do expect(forked_project.forked?).to be_truthy expect(forked_project.forked_from_project).to eq(project) post api("/projects/#{forked_project.id}/merge_requests", user2), - params: { title: 'Test merge_request', source_branch: "master", target_branch: "master", author: user2, target_project_id: project.id } + params: {title: "Test merge_request", source_branch: "master", target_branch: "master", author: user2, target_project_id: project.id} expect(response).to have_gitlab_http_status(201) - expect(json_response['title']).to eq('Test merge_request') + expect(json_response["title"]).to eq("Test merge_request") end - it 'returns 403 when target project has disabled merge requests' do + it "returns 403 when target project has disabled merge requests" do project.project_feature.update(merge_requests_access_level: 0) post api("/projects/#{forked_project.id}/merge_requests", user2), - params: { - title: 'Test', - target_branch: 'master', - source_branch: 'markdown', - author: user2, - target_project_id: project.id - } + params: { + title: "Test", + target_branch: "master", + source_branch: "markdown", + author: user2, + target_project_id: project.id, + } expect(response).to have_gitlab_http_status(403) end it "returns 400 when source_branch is missing" do post api("/projects/#{forked_project.id}/merge_requests", user2), - params: { title: 'Test merge_request', target_branch: "master", author: user2, target_project_id: project.id } + params: {title: "Test merge_request", target_branch: "master", author: user2, target_project_id: project.id} expect(response).to have_gitlab_http_status(400) end it "returns 400 when target_branch is missing" do post api("/projects/#{forked_project.id}/merge_requests", user2), - params: { title: 'Test merge_request', target_branch: "master", author: user2, target_project_id: project.id } + params: {title: "Test merge_request", target_branch: "master", author: user2, target_project_id: project.id} expect(response).to have_gitlab_http_status(400) end it "returns 400 when title is missing" do post api("/projects/#{forked_project.id}/merge_requests", user2), - params: { target_branch: 'master', source_branch: 'markdown', author: user2, target_project_id: project.id } + params: {target_branch: "master", source_branch: "markdown", author: user2, target_project_id: project.id} expect(response).to have_gitlab_http_status(400) end - it 'allows setting `allow_collaboration`' do + it "allows setting `allow_collaboration`" do post api("/projects/#{forked_project.id}/merge_requests", user2), - params: { title: 'Test merge_request', source_branch: "feature_conflict", target_branch: "master", author: user2, target_project_id: project.id, allow_collaboration: true } + params: {title: "Test merge_request", source_branch: "feature_conflict", target_branch: "master", author: user2, target_project_id: project.id, allow_collaboration: true} expect(response).to have_gitlab_http_status(201) - expect(json_response['allow_collaboration']).to be_truthy - expect(json_response['allow_maintainer_to_push']).to be_truthy + expect(json_response["allow_collaboration"]).to be_truthy + expect(json_response["allow_maintainer_to_push"]).to be_truthy end - context 'when target_branch and target_project_id is specified' do + context "when target_branch and target_project_id is specified" do let(:params) do - { title: 'Test merge_request', - target_branch: 'master', - source_branch: 'markdown', - author: user2, - target_project_id: unrelated_project.id } + {title: "Test merge_request", + target_branch: "master", + source_branch: "markdown", + author: user2, + target_project_id: unrelated_project.id,} end - it 'returns 422 if targeting a different fork' do + it "returns 422 if targeting a different fork" do unrelated_project.add_developer(user2) post api("/projects/#{forked_project.id}/merge_requests", user2), params: params @@ -814,7 +814,7 @@ describe API::MergeRequests do expect(response).to have_gitlab_http_status(422) end - it 'returns 403 if targeting a different fork which user can not access' do + it "returns 403 if targeting a different fork which user can not access" do post api("/projects/#{forked_project.id}/merge_requests", user2), params: params expect(response).to have_gitlab_http_status(403) @@ -823,7 +823,7 @@ describe API::MergeRequests do it "returns 201 when target_branch is specified and for the same project" do post api("/projects/#{forked_project.id}/merge_requests", user2), - params: { title: 'Test merge_request', target_branch: 'master', source_branch: 'markdown', author: user2, target_project_id: forked_project.id } + params: {title: "Test merge_request", target_branch: "master", source_branch: "markdown", author: user2, target_project_id: forked_project.id} expect(response).to have_gitlab_http_status(201) end end @@ -862,7 +862,7 @@ describe API::MergeRequests do expect(response).to have_gitlab_http_status(404) end - it_behaves_like '412 response' do + it_behaves_like "412 response" do let(:request) { api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user) } end end @@ -884,30 +884,30 @@ describe API::MergeRequests do put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/merge", user) expect(response).to have_gitlab_http_status(406) - expect(json_response['message']).to eq('Branch cannot be merged') + expect(json_response["message"]).to eq("Branch cannot be merged") end it "returns 405 if merge_request is not open" do merge_request.close put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/merge", user) expect(response).to have_gitlab_http_status(405) - expect(json_response['message']).to eq('405 Method Not Allowed') + expect(json_response["message"]).to eq("405 Method Not Allowed") end it "returns 405 if merge_request is a work in progress" do merge_request.update_attribute(:title, "WIP: #{merge_request.title}") put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/merge", user) expect(response).to have_gitlab_http_status(405) - expect(json_response['message']).to eq('405 Method Not Allowed') + expect(json_response["message"]).to eq("405 Method Not Allowed") end - it 'returns 405 if the build failed for a merge request that requires success' do + it "returns 405 if the build failed for a merge request that requires success" do allow_any_instance_of(MergeRequest).to receive(:mergeable_ci_state?).and_return(false) put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/merge", user) expect(response).to have_gitlab_http_status(405) - expect(json_response['message']).to eq('405 Method Not Allowed') + expect(json_response["message"]).to eq("405 Method Not Allowed") end it "returns 401 if user has no permissions to merge" do @@ -915,26 +915,26 @@ describe API::MergeRequests do project.add_reporter(user2) put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/merge", user2) expect(response).to have_gitlab_http_status(401) - expect(json_response['message']).to eq('401 Unauthorized') + expect(json_response["message"]).to eq("401 Unauthorized") end it "returns 409 if the SHA parameter doesn't match" do - put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/merge", user), params: { sha: merge_request.diff_head_sha.reverse } + put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/merge", user), params: {sha: merge_request.diff_head_sha.reverse} expect(response).to have_gitlab_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 it "succeeds if the SHA parameter matches" do - put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/merge", user), params: { sha: merge_request.diff_head_sha } + put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/merge", user), params: {sha: merge_request.diff_head_sha} expect(response).to have_gitlab_http_status(200) end it "updates the MR's squash attribute" do - expect do - put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/merge", user), params: { squash: true } - end.to change { merge_request.reload.squash } + expect { + put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/merge", user), params: {squash: true} + }.to change { merge_request.reload.squash } expect(response).to have_gitlab_http_status(200) end @@ -943,11 +943,11 @@ describe API::MergeRequests do allow_any_instance_of(MergeRequest).to receive(:head_pipeline).and_return(pipeline) allow(pipeline).to receive(:active?).and_return(true) - put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/merge", user), params: { merge_when_pipeline_succeeds: true } + put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/merge", user), params: {merge_when_pipeline_succeeds: true} expect(response).to have_gitlab_http_status(200) - expect(json_response['title']).to eq('Test') - expect(json_response['merge_when_pipeline_succeeds']).to eq(true) + expect(json_response["title"]).to eq("Test") + expect(json_response["merge_when_pipeline_succeeds"]).to eq(true) end it "enables merge when pipeline succeeds if the pipeline is active and only_allow_merge_if_pipeline_succeeds is true" do @@ -955,11 +955,11 @@ describe API::MergeRequests do allow(pipeline).to receive(:active?).and_return(true) project.update_attribute(:only_allow_merge_if_pipeline_succeeds, true) - put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/merge", user), params: { merge_when_pipeline_succeeds: true } + put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/merge", user), params: {merge_when_pipeline_succeeds: true} expect(response).to have_gitlab_http_status(200) - expect(json_response['title']).to eq('Test') - expect(json_response['merge_when_pipeline_succeeds']).to eq(true) + expect(json_response["title"]).to eq("Test") + expect(json_response["merge_when_pipeline_succeeds"]).to eq(true) end it "returns 404 for an invalid merge request IID" do @@ -976,22 +976,22 @@ describe API::MergeRequests do describe "the squash_commit_message param" do let(:squash_commit) do - project.repository.commits_between(json_response['diff_refs']['start_sha'], json_response['merge_commit_sha']).first + project.repository.commits_between(json_response["diff_refs"]["start_sha"], json_response["merge_commit_sha"]).first end it "results in a specific squash commit message when set" do - squash_commit_message = 'My custom squash commit message' + squash_commit_message = "My custom squash commit message" put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/merge", user), params: { squash: true, - squash_commit_message: squash_commit_message + squash_commit_message: squash_commit_message, } expect(squash_commit.message.chomp).to eq(squash_commit_message) end it "results in a default squash commit message when not set" do - put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/merge", user), params: { squash: true } + put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/merge", user), params: {squash: true} expect(squash_commit.message).to eq(merge_request.default_squash_commit_message) end @@ -1001,10 +1001,10 @@ describe API::MergeRequests do let(:source_repository) { merge_request.source_project.repository } let(:source_branch) { merge_request.source_branch } - it 'removes the source branch when set' do + it "removes the source branch when set" do put( api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/merge", user), - params: { should_remove_source_branch: true } + params: {should_remove_source_branch: true} ) expect(response).to have_gitlab_http_status(200) @@ -1019,37 +1019,37 @@ describe API::MergeRequests do "/projects/#{project.id}/merge_requests/#{merge_request.iid}/merge_to_ref" end - it 'returns the generated ID from the merge service in case of success' do - put api(url, user), params: { merge_commit_message: 'Custom message' } + it "returns the generated ID from the merge service in case of success" do + put api(url, user), params: {merge_commit_message: "Custom message"} - commit = project.commit(json_response['commit_id']) + commit = project.commit(json_response["commit_id"]) expect(response).to have_gitlab_http_status(200) - expect(json_response['commit_id']).to be_present - expect(commit.message).to eq('Custom message') + expect(json_response["commit_id"]).to be_present + expect(commit.message).to eq("Custom message") end it "returns 400 if branch can't be merged" do - merge_request.update!(state: 'merged') + merge_request.update!(state: "merged") put api(url, user) expect(response).to have_gitlab_http_status(400) - expect(json_response['message']) + expect(json_response["message"]) .to eq("Merge request is not mergeable to #{merge_request.merge_ref_path}") end - it 'returns 403 if user has no permissions to merge to the ref' do + it "returns 403 if user has no permissions to merge to the ref" do user2 = create(:user) project.add_reporter(user2) put api(url, user2) expect(response).to have_gitlab_http_status(403) - expect(json_response['message']).to eq('403 Forbidden') + expect(json_response["message"]).to eq("403 Forbidden") end - it 'returns 404 for an invalid merge request IID' do + it "returns 404 for an invalid merge request IID" do put api("/projects/#{project.id}/merge_requests/12345/merge_to_ref", user) expect(response).to have_gitlab_http_status(404) @@ -1062,112 +1062,112 @@ describe API::MergeRequests do end it "returns 400 when merge method is not supported" do - merge_request.project.update!(merge_method: 'ff') + merge_request.project.update!(merge_method: "ff") put api(url, user) expected_error = - 'Fast-forward to refs/merge-requests/1/merge is currently not supported.' + "Fast-forward to refs/merge-requests/1/merge is currently not supported." expect(response).to have_gitlab_http_status(400) - expect(json_response['message']).to eq(expected_error) + expect(json_response["message"]).to eq(expected_error) end end describe "PUT /projects/:id/merge_requests/:merge_request_iid" do context "to close a MR" do it "returns merge_request" do - put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user), params: { state_event: "close" } + put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user), params: {state_event: "close"} expect(response).to have_gitlab_http_status(200) - expect(json_response['state']).to eq('closed') + expect(json_response["state"]).to eq("closed") end end it "updates title and returns merge_request" do - put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user), params: { title: "New title" } + put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user), params: {title: "New title"} expect(response).to have_gitlab_http_status(200) - expect(json_response['title']).to eq('New title') + expect(json_response["title"]).to eq("New title") end it "updates description and returns merge_request" do - put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user), params: { description: "New description" } + put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user), params: {description: "New description"} expect(response).to have_gitlab_http_status(200) - expect(json_response['description']).to eq('New description') + expect(json_response["description"]).to eq("New description") end it "updates milestone_id and returns merge_request" do - put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user), params: { milestone_id: milestone.id } + put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user), params: {milestone_id: milestone.id} expect(response).to have_gitlab_http_status(200) - expect(json_response['milestone']['id']).to eq(milestone.id) + expect(json_response["milestone"]["id"]).to eq(milestone.id) end it "updates squash and returns merge_request" do - put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user), params: { squash: true } + put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user), params: {squash: true} expect(response).to have_gitlab_http_status(200) - expect(json_response['squash']).to be_truthy + expect(json_response["squash"]).to be_truthy end it "returns merge_request with renamed target_branch" do - put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user), params: { target_branch: "wiki" } + put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user), params: {target_branch: "wiki"} expect(response).to have_gitlab_http_status(200) - expect(json_response['target_branch']).to eq('wiki') + expect(json_response["target_branch"]).to eq("wiki") end it "returns merge_request that removes the source branch" do - put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user), params: { remove_source_branch: true } + put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user), params: {remove_source_branch: true} expect(response).to have_gitlab_http_status(200) - expect(json_response['force_remove_source_branch']).to be_truthy + expect(json_response["force_remove_source_branch"]).to be_truthy end - it 'allows special label names' do + it "allows special label names" do put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user), params: { - title: 'new issue', - labels: 'label, label?, label&foo, ?, &' + title: "new issue", + labels: "label, label?, label&foo, ?, &", } expect(response.status).to eq(200) - expect(json_response['labels']).to include 'label' - expect(json_response['labels']).to include 'label?' - expect(json_response['labels']).to include 'label&foo' - expect(json_response['labels']).to include '?' - expect(json_response['labels']).to include '&' + expect(json_response["labels"]).to include "label" + expect(json_response["labels"]).to include "label?" + expect(json_response["labels"]).to include "label&foo" + expect(json_response["labels"]).to include "?" + expect(json_response["labels"]).to include "&" end - it 'does not update state when title is empty' do - put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user), params: { state_event: 'close', title: nil } + it "does not update state when title is empty" do + put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user), params: {state_event: "close", title: nil} merge_request.reload expect(response).to have_gitlab_http_status(400) - expect(merge_request.state).to eq('opened') + expect(merge_request.state).to eq("opened") end - it 'does not update state when target_branch is empty' do - put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user), params: { state_event: 'close', target_branch: nil } + it "does not update state when target_branch is empty" do + put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user), params: {state_event: "close", target_branch: nil} merge_request.reload expect(response).to have_gitlab_http_status(400) - expect(merge_request.state).to eq('opened') + expect(merge_request.state).to eq("opened") end it "returns 404 for an invalid merge request IID" do - put api("/projects/#{project.id}/merge_requests/12345", user), params: { state_event: "close" } + put api("/projects/#{project.id}/merge_requests/12345", user), params: {state_event: "close"} expect(response).to have_gitlab_http_status(404) end it "returns 404 if the merge request id is used instead of iid" do - put api("/projects/#{project.id}/merge_requests/#{merge_request.id}", user), params: { state_event: "close" } + put api("/projects/#{project.id}/merge_requests/#{merge_request.id}", user), params: {state_event: "close"} expect(response).to have_gitlab_http_status(404) end end - describe 'GET :id/merge_requests/:merge_request_iid/closes_issues' do - it 'returns the issue that will be closed on merge' do + describe "GET :id/merge_requests/:merge_request_iid/closes_issues" do + it "returns the issue that will be closed on merge" do issue = create(:issue, project: project) mr = merge_request.tap do |mr| mr.update_attribute(:description, "Closes #{issue.to_reference(mr.project)}") @@ -1180,10 +1180,10 @@ describe API::MergeRequests do expect(response).to include_pagination_headers expect(json_response).to be_an Array 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) end - 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.iid}/closes_issues", user) expect(response).to have_gitlab_http_status(200) @@ -1192,8 +1192,8 @@ describe API::MergeRequests do expect(json_response.length).to eq(0) end - it 'handles external issues' do - jira_project = create(:jira_project, :public, :repository, name: 'JIR_EXT1') + it "handles external issues" do + jira_project = create(:jira_project, :public, :repository, name: "JIR_EXT1") ext_issue = ExternalIssue.new("#{jira_project.name}-123", jira_project) issue = create(:issue, project: jira_project) description = "Closes #{ext_issue.to_reference(jira_project)}\ncloses #{issue.to_reference}" @@ -1206,15 +1206,15 @@ describe API::MergeRequests do expect(response).to include_pagination_headers expect(json_response).to be_an Array expect(json_response.length).to eq(2) - expect(json_response.second['title']).to eq(ext_issue.title) - expect(json_response.second['id']).to eq(ext_issue.id) - expect(json_response.second['confidential']).to be_nil - expect(json_response.first['title']).to eq(issue.title) - expect(json_response.first['id']).to eq(issue.id) - expect(json_response.first['confidential']).not_to be_nil + expect(json_response.second["title"]).to eq(ext_issue.title) + expect(json_response.second["id"]).to eq(ext_issue.id) + expect(json_response.second["confidential"]).to be_nil + expect(json_response.first["title"]).to eq(issue.title) + expect(json_response.first["id"]).to eq(issue.id) + expect(json_response.first["confidential"]).not_to be_nil end - it 'returns 403 if the user has no access to the merge request' do + it "returns 403 if the user has no access to the merge request" do project = create(:project, :private) merge_request = create(:merge_request, :simple, source_project: project) guest = create(:user) @@ -1238,33 +1238,33 @@ describe API::MergeRequests do end end - describe 'POST :id/merge_requests/:merge_request_iid/subscribe' do - it 'subscribes to a merge request' do + describe "POST :id/merge_requests/:merge_request_iid/subscribe" do + it "subscribes to a merge request" do post api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/subscribe", admin) expect(response).to have_gitlab_http_status(201) - expect(json_response['subscribed']).to eq(true) + expect(json_response["subscribed"]).to eq(true) end - it 'returns 304 if already subscribed' do + it "returns 304 if already subscribed" do post api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/subscribe", user) expect(response).to have_gitlab_http_status(304) 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/subscribe", user) expect(response).to have_gitlab_http_status(404) end - it 'returns 404 if the merge request id is used instead of iid' do + it "returns 404 if the merge request id is used instead of iid" do post api("/projects/#{project.id}/merge_requests/#{merge_request.id}/subscribe", user) expect(response).to have_gitlab_http_status(404) end - it 'returns 403 if user has no access to read code' do + it "returns 403 if user has no access to read code" do guest = create(:user) project.add_guest(guest) @@ -1274,33 +1274,33 @@ describe API::MergeRequests do end end - describe 'POST :id/merge_requests/:merge_request_iid/unsubscribe' do - it 'unsubscribes from a merge request' do + describe "POST :id/merge_requests/:merge_request_iid/unsubscribe" do + it "unsubscribes from a merge request" do post api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/unsubscribe", user) expect(response).to have_gitlab_http_status(201) - expect(json_response['subscribed']).to eq(false) + expect(json_response["subscribed"]).to eq(false) end - it 'returns 304 if not subscribed' do + it "returns 304 if not subscribed" do post api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/unsubscribe", admin) expect(response).to have_gitlab_http_status(304) 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/unsubscribe", user) expect(response).to have_gitlab_http_status(404) end - it 'returns 404 if the merge request id is used instead of iid' do + it "returns 404 if the merge request id is used instead of iid" do post api("/projects/#{project.id}/merge_requests/#{merge_request.id}/unsubscribe", user) expect(response).to have_gitlab_http_status(404) end - it 'returns 403 if user has no access to read code' do + it "returns 403 if user has no access to read code" do guest = create(:user) project.add_guest(guest) @@ -1310,32 +1310,32 @@ describe API::MergeRequests do end end - describe 'POST :id/merge_requests/:merge_request_iid/cancel_merge_when_pipeline_succeeds' do + describe "POST :id/merge_requests/:merge_request_iid/cancel_merge_when_pipeline_succeeds" do before do ::MergeRequests::MergeWhenPipelineSucceedsService.new(merge_request.target_project, user).execute(merge_request) end - it 'removes the merge_when_pipeline_succeeds status' do + it "removes the merge_when_pipeline_succeeds status" do post api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/cancel_merge_when_pipeline_succeeds", user) expect(response).to have_gitlab_http_status(201) 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/cancel_merge_when_pipeline_succeeds", user) expect(response).to have_gitlab_http_status(404) end - it 'returns 404 if the merge request id is used instead of iid' do + it "returns 404 if the merge request id is used instead of iid" do post api("/projects/#{project.id}/merge_requests/#{merge_request.id}/cancel_merge_when_pipeline_succeeds", user) expect(response).to have_gitlab_http_status(404) end end - describe 'PUT :id/merge_requests/:merge_request_iid/rebase' do - it 'enqueues a rebase of the merge request against the target branch' do + describe "PUT :id/merge_requests/:merge_request_iid/rebase" do + it "enqueues a rebase of the merge request against the target branch" do Sidekiq::Testing.fake! do put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/rebase", user) end @@ -1344,7 +1344,7 @@ describe API::MergeRequests do expect(RebaseWorker.jobs.size).to eq(1) end - it 'returns 403 if the user cannot push to the branch' do + it "returns 403 if the user cannot push to the branch" do guest = create(:user) project.add_guest(guest) @@ -1354,10 +1354,10 @@ describe API::MergeRequests do end end - describe 'Time tracking' do + describe "Time tracking" do let(:issuable) { merge_request } - include_examples 'time tracking endpoints', 'merge_request' + include_examples "time tracking endpoints", "merge_request" end def mr_with_later_created_and_updated_at_time @@ -1379,13 +1379,13 @@ describe API::MergeRequests do def expect_response_contain_exactly(*items) expect_paginated_array_response expect(json_response.length).to eq(items.size) - expect(json_response.map { |element| element['id'] }).to contain_exactly(*items.map(&:id)) + expect(json_response.map { |element| element["id"] }).to contain_exactly(*items.map(&:id)) end def expect_response_ordered_exactly(*items) expect_paginated_array_response expect(json_response.length).to eq(items.size) - expect(json_response.map { |element| element['id'] }).to eq(items.map(&:id)) + expect(json_response.map { |element| element["id"] }).to eq(items.map(&:id)) end def expect_paginated_array_response diff --git a/spec/requests/api/namespaces_spec.rb b/spec/requests/api/namespaces_spec.rb index 2e376109b42..64a47f51a92 100644 --- a/spec/requests/api/namespaces_spec.rb +++ b/spec/requests/api/namespaces_spec.rb @@ -1,9 +1,9 @@ -require 'spec_helper' +require "spec_helper" describe API::Namespaces do let(:admin) { create(:admin) } let(:user) { create(:user) } - let!(:group1) { create(:group, name: 'group.one') } + let!(:group1) { create(:group, name: "group.one") } let!(:group2) { create(:group, :nested) } describe "GET /namespaces" do @@ -18,15 +18,15 @@ describe API::Namespaces do it "returns correct attributes" do get api("/namespaces", admin) - group_kind_json_response = json_response.find { |resource| resource['kind'] == 'group' } - user_kind_json_response = json_response.find { |resource| resource['kind'] == 'user' } + group_kind_json_response = json_response.find { |resource| resource["kind"] == "group" } + user_kind_json_response = json_response.find { |resource| resource["kind"] == "user" } expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers - expect(group_kind_json_response.keys).to include('id', 'kind', 'name', 'path', 'full_path', - 'parent_id', 'members_count_with_descendants') + expect(group_kind_json_response.keys).to include("id", "kind", "name", "path", "full_path", + "parent_id", "members_count_with_descendants") - expect(user_kind_json_response.keys).to include('id', 'kind', 'name', 'path', 'full_path', 'parent_id') + expect(user_kind_json_response.keys).to include("id", "kind", "name", "path", "full_path", "parent_id") end it "admin: returns an array of all namespaces" do @@ -45,8 +45,8 @@ describe API::Namespaces do expect(response).to include_pagination_headers expect(json_response).to be_an Array expect(json_response.length).to eq(1) - expect(json_response.last['path']).to eq(group2.path) - expect(json_response.last['full_path']).to eq(group2.full_path) + expect(json_response.last["path"]).to eq(group2.path) + expect(json_response.last["full_path"]).to eq(group2.full_path) end end @@ -56,10 +56,10 @@ describe API::Namespaces do get api("/namespaces", user) - owned_group_response = json_response.find { |resource| resource['id'] == group1.id } + owned_group_response = json_response.find { |resource| resource["id"] == group1.id } - expect(owned_group_response.keys).to include('id', 'kind', 'name', 'path', 'full_path', - 'parent_id', 'members_count_with_descendants') + expect(owned_group_response.keys).to include("id", "kind", "name", "path", "full_path", + "parent_id", "members_count_with_descendants") end it "returns correct attributes when user cannot admin group" do @@ -67,9 +67,9 @@ describe API::Namespaces do get api("/namespaces", user) - guest_group_response = json_response.find { |resource| resource['id'] == group1.id } + guest_group_response = json_response.find { |resource| resource["id"] == group1.id } - expect(guest_group_response.keys).to include('id', 'kind', 'name', 'path', 'full_path', 'parent_id') + expect(guest_group_response.keys).to include("id", "kind", "name", "path", "full_path", "parent_id") end it "user: returns an array of namespaces" do @@ -92,92 +92,92 @@ describe API::Namespaces do end end - describe 'GET /namespaces/:id' do + describe "GET /namespaces/:id" do let(:owned_group) { group1 } let(:user2) { create(:user) } - shared_examples 'can access namespace' do - it 'returns namespace details' do + shared_examples "can access namespace" do + it "returns namespace details" do get api("/namespaces/#{namespace_id}", request_actor) expect(response).to have_gitlab_http_status(200) - expect(json_response['id']).to eq(requested_namespace.id) - expect(json_response['path']).to eq(requested_namespace.path) - expect(json_response['name']).to eq(requested_namespace.name) + expect(json_response["id"]).to eq(requested_namespace.id) + expect(json_response["path"]).to eq(requested_namespace.path) + expect(json_response["name"]).to eq(requested_namespace.name) end end - shared_examples 'namespace reader' do + shared_examples "namespace reader" do let(:requested_namespace) { owned_group } before do owned_group.add_owner(request_actor) end - context 'when namespace exists' do - context 'when requested by ID' do - context 'when requesting group' do + context "when namespace exists" do + context "when requested by ID" do + context "when requesting group" do let(:namespace_id) { owned_group.id } - it_behaves_like 'can access namespace' + it_behaves_like "can access namespace" end - context 'when requesting personal namespace' do + context "when requesting personal namespace" do let(:namespace_id) { request_actor.namespace.id } let(:requested_namespace) { request_actor.namespace } - it_behaves_like 'can access namespace' + it_behaves_like "can access namespace" end end - context 'when requested by path' do - context 'when requesting group' do + context "when requested by path" do + context "when requesting group" do let(:namespace_id) { owned_group.path } - it_behaves_like 'can access namespace' + it_behaves_like "can access namespace" end - context 'when requesting personal namespace' do + context "when requesting personal namespace" do let(:namespace_id) { request_actor.namespace.path } let(:requested_namespace) { request_actor.namespace } - it_behaves_like 'can access namespace' + it_behaves_like "can access namespace" end end end context "when namespace doesn't exist" do - it 'returns not-found' do - get api('/namespaces/0', request_actor) + it "returns not-found" do + get api("/namespaces/0", request_actor) expect(response).to have_gitlab_http_status(404) end end end - context 'when unauthenticated' do - it 'returns authentication error' do + context "when unauthenticated" do + it "returns authentication error" do get api("/namespaces/#{group1.id}") expect(response).to have_gitlab_http_status(401) end end - context 'when authenticated as regular user' do + context "when authenticated as regular user" do let(:request_actor) { user } - context 'when requested namespace is not owned by user' do - context 'when requesting group' do - it 'returns not-found' do + context "when requested namespace is not owned by user" do + context "when requesting group" do + it "returns not-found" do get api("/namespaces/#{group2.id}", request_actor) expect(response).to have_gitlab_http_status(404) end end - context 'when requesting personal namespace' do - it 'returns not-found' do + context "when requesting personal namespace" do + it "returns not-found" do get api("/namespaces/#{user2.namespace.id}", request_actor) expect(response).to have_gitlab_http_status(404) @@ -185,32 +185,32 @@ describe API::Namespaces do end end - context 'when requested namespace is owned by user' do - it_behaves_like 'namespace reader' + context "when requested namespace is owned by user" do + it_behaves_like "namespace reader" end end - context 'when authenticated as admin' do + context "when authenticated as admin" do let(:request_actor) { admin } - context 'when requested namespace is not owned by user' do - context 'when requesting group' do + context "when requested namespace is not owned by user" do + context "when requesting group" do let(:namespace_id) { group2.id } let(:requested_namespace) { group2 } - it_behaves_like 'can access namespace' + it_behaves_like "can access namespace" end - context 'when requesting personal namespace' do + context "when requesting personal namespace" do let(:namespace_id) { user2.namespace.id } let(:requested_namespace) { user2.namespace } - it_behaves_like 'can access namespace' + it_behaves_like "can access namespace" end end - context 'when requested namespace is owned by user' do - it_behaves_like 'namespace reader' + context "when requested namespace is owned by user" do + it_behaves_like "namespace reader" end end end diff --git a/spec/requests/api/notes_spec.rb b/spec/requests/api/notes_spec.rb index 424f0a82e43..f0e45867629 100644 --- a/spec/requests/api/notes_spec.rb +++ b/spec/requests/api/notes_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe API::Notes do let(:user) { create(:user) } @@ -13,13 +13,13 @@ describe API::Notes do let!(:issue) { create(:issue, project: project, author: user) } let!(:issue_note) { create(:note, noteable: issue, project: project, author: user) } - it_behaves_like "noteable API", 'projects', 'issues', 'iid' do + it_behaves_like "noteable API", "projects", "issues", "iid" do let(:parent) { project } let(:noteable) { issue } let(:note) { issue_note } end - context 'when user does not have access to create noteable' do + context "when user does not have access to create noteable" do let(:private_issue) { create(:issue, project: create(:project, :private)) } ## @@ -28,14 +28,14 @@ describe API::Notes do # before do post api("/projects/#{private_issue.project.id}/issues/#{private_issue.iid}/notes", user), - params: { body: 'Hi!' } + params: {body: "Hi!"} end - it 'responds with resource not found error' do + it "responds with resource not found error" do expect(response.status).to eq 404 end - it 'does not create new note' do + it "does not create new note" do expect(private_issue.notes.reload).to be_empty end end @@ -44,7 +44,7 @@ describe API::Notes do # For testing the cross-reference of a private issue in a public project let(:private_project) do create(:project, namespace: private_user.namespace) - .tap { |p| p.add_maintainer(private_user) } + .tap { |p| p.add_maintainer(private_user) } end let(:private_issue) { create(:issue, project: private_project) } @@ -53,9 +53,9 @@ describe API::Notes do let!(:cross_reference_note) do create :note, - noteable: ext_issue, project: ext_proj, - note: "mentioned in issue #{private_issue.to_reference(ext_proj)}", - system: true + noteable: ext_issue, project: ext_proj, + note: "mentioned in issue #{private_issue.to_reference(ext_proj)}", + system: true end describe "GET /projects/:id/noteable/:noteable_id/notes" do @@ -89,7 +89,7 @@ describe API::Notes do expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers 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 end @@ -120,7 +120,7 @@ describe API::Notes do get api("/projects/#{ext_proj.id}/issues/#{ext_issue.iid}/notes/#{cross_reference_note.id}", private_user) expect(response).to have_gitlab_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 @@ -131,7 +131,7 @@ describe API::Notes do let!(:snippet) { create(:project_snippet, project: project, author: user) } let!(:snippet_note) { create(:note, noteable: snippet, project: project, author: user) } - it_behaves_like "noteable API", 'projects', 'snippets', 'id' do + it_behaves_like "noteable API", "projects", "snippets", "id" do let(:parent) { project } let(:noteable) { snippet } let(:note) { snippet_note } @@ -142,41 +142,41 @@ describe API::Notes do let!(:merge_request) { create(:merge_request, source_project: project, target_project: project, author: user) } let!(:merge_request_note) { create(:note, noteable: merge_request, project: project, author: user) } - it_behaves_like "noteable API", 'projects', 'merge_requests', 'iid' do + it_behaves_like "noteable API", "projects", "merge_requests", "iid" do let(:parent) { project } let(:noteable) { merge_request } let(:note) { merge_request_note } end - context 'when the merge request discussion is locked' do + context "when the merge request discussion is locked" do before do merge_request.update_attribute(:discussion_locked, true) end - context 'when a user is a team member' do - subject { post api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/notes", user), params: { body: 'Hi!' } } + context "when a user is a team member" do + subject { post api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/notes", user), params: {body: "Hi!"} } - it 'returns 200 status' do + it "returns 200 status" do subject expect(response).to have_gitlab_http_status(201) end - it 'creates a new note' do + it "creates a new note" do expect { subject }.to change { Note.count }.by(1) end end - context 'when a user is not a team member' do - subject { post api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/notes", private_user), params: { body: 'Hi!' } } + context "when a user is not a team member" do + subject { post api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/notes", private_user), params: {body: "Hi!"} } - it 'returns 403 status' do + it "returns 403 status" do subject expect(response).to have_gitlab_http_status(403) end - it 'does not create a new note' do + it "does not create a new note" do expect { subject }.not_to change { Note.count } end end diff --git a/spec/requests/api/notification_settings_spec.rb b/spec/requests/api/notification_settings_spec.rb index 4ed667ad0dc..0ed4d950014 100644 --- a/spec/requests/api/notification_settings_spec.rb +++ b/spec/requests/api/notification_settings_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe API::NotificationSettings do let(:user) { create(:user) } @@ -11,8 +11,8 @@ describe API::NotificationSettings do expect(response).to have_gitlab_http_status(200) expect(json_response).to be_a Hash - expect(json_response['notification_email']).to eq(user.notification_email) - expect(json_response['level']).to eq(user.global_notification_setting.level) + expect(json_response["notification_email"]).to eq(user.notification_email) + expect(json_response["level"]).to eq(user.global_notification_setting.level) end end @@ -20,18 +20,18 @@ describe API::NotificationSettings do let(:email) { create(:email, user: user) } it "updates global notification settings for the current user" do - put api("/notification_settings", user), params: { level: 'watch', notification_email: email.email } + put api("/notification_settings", user), params: {level: "watch", notification_email: email.email} expect(response).to have_gitlab_http_status(200) - expect(json_response['notification_email']).to eq(email.email) + expect(json_response["notification_email"]).to eq(email.email) expect(user.reload.notification_email).to eq(email.email) - expect(json_response['level']).to eq(user.reload.global_notification_setting.level) + expect(json_response["level"]).to eq(user.reload.global_notification_setting.level) end end describe "PUT /notification_settings" do it "fails on non-user email address" do - put api("/notification_settings", user), params: { notification_email: 'invalid@example.com' } + put api("/notification_settings", user), params: {notification_email: "invalid@example.com"} expect(response).to have_gitlab_http_status(400) end @@ -43,16 +43,16 @@ describe API::NotificationSettings do expect(response).to have_gitlab_http_status(200) expect(json_response).to be_a Hash - expect(json_response['level']).to eq(user.notification_settings_for(group).level) + expect(json_response["level"]).to eq(user.notification_settings_for(group).level) end end describe "PUT /groups/:id/notification_settings" do it "updates group level notification settings for the current user" do - put api("/groups/#{group.id}/notification_settings", user), params: { level: 'watch' } + put api("/groups/#{group.id}/notification_settings", user), params: {level: "watch"} expect(response).to have_gitlab_http_status(200) - expect(json_response['level']).to eq(user.reload.notification_settings_for(group).level) + expect(json_response["level"]).to eq(user.reload.notification_settings_for(group).level) end end @@ -62,24 +62,24 @@ describe API::NotificationSettings do expect(response).to have_gitlab_http_status(200) expect(json_response).to be_a Hash - expect(json_response['level']).to eq(user.notification_settings_for(project).level) + expect(json_response["level"]).to eq(user.notification_settings_for(project).level) end end describe "PUT /projects/:id/notification_settings" do it "updates project level notification settings for the current user" do - put api("/projects/#{project.id}/notification_settings", user), params: { level: 'custom', new_note: true } + put api("/projects/#{project.id}/notification_settings", user), params: {level: "custom", new_note: true} expect(response).to have_gitlab_http_status(200) - expect(json_response['level']).to eq(user.reload.notification_settings_for(project).level) - expect(json_response['events']['new_note']).to be_truthy - expect(json_response['events']['new_issue']).to be_falsey + expect(json_response["level"]).to eq(user.reload.notification_settings_for(project).level) + expect(json_response["events"]["new_note"]).to be_truthy + expect(json_response["events"]["new_issue"]).to be_falsey end end describe "PUT /projects/:id/notification_settings" do it "fails on invalid level" do - put api("/projects/#{project.id}/notification_settings", user), params: { level: 'invalid' } + put api("/projects/#{project.id}/notification_settings", user), params: {level: "invalid"} expect(response).to have_gitlab_http_status(400) end diff --git a/spec/requests/api/oauth_tokens_spec.rb b/spec/requests/api/oauth_tokens_spec.rb index 3811ec751de..b3806a220ae 100644 --- a/spec/requests/api/oauth_tokens_spec.rb +++ b/spec/requests/api/oauth_tokens_spec.rb @@ -1,30 +1,30 @@ -require 'spec_helper' +require "spec_helper" -describe 'OAuth tokens' do - context 'Resource Owner Password Credentials' do +describe "OAuth tokens" do + context "Resource Owner Password Credentials" do def request_oauth_token(user) - post '/oauth/token', params: { username: user.username, password: user.password, grant_type: 'password' } + post "/oauth/token", params: {username: user.username, password: user.password, grant_type: "password"} end - context 'when user has 2FA enabled' do - it 'does not create an access token' do + context "when user has 2FA enabled" do + it "does not create an access token" do user = create(:user, :two_factor) request_oauth_token(user) expect(response).to have_gitlab_http_status(401) - expect(json_response['error']).to eq('invalid_grant') + expect(json_response["error"]).to eq("invalid_grant") end end - context 'when user does not have 2FA enabled' do - it 'creates an access token' do + context "when user does not have 2FA enabled" do + it "creates an access token" do user = create(:user) request_oauth_token(user) expect(response).to have_gitlab_http_status(200) - expect(json_response['access_token']).not_to be_nil + expect(json_response["access_token"]).not_to be_nil end end diff --git a/spec/requests/api/pages/internal_access_spec.rb b/spec/requests/api/pages/internal_access_spec.rb index c41eabe0a48..4a57fc83711 100644 --- a/spec/requests/api/pages/internal_access_spec.rb +++ b/spec/requests/api/pages/internal_access_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe "Internal Project Pages Access" do using RSpec::Parameterized::TableSyntax @@ -25,14 +25,14 @@ describe "Internal Project Pages Access" do end describe "Project should be internal" do - describe '#internal?' do + describe "#internal?" do subject { project.internal? } it { is_expected.to be_truthy } end end describe "GET /projects/:id/pages_access" do - context 'access depends on the level' do + context "access depends on the level" do where(:pages_access_level, :with_user, :expected_result) do ProjectFeature::DISABLED | "admin" | 403 ProjectFeature::DISABLED | "owner" | 403 diff --git a/spec/requests/api/pages/private_access_spec.rb b/spec/requests/api/pages/private_access_spec.rb index c647537038e..baad0c267e9 100644 --- a/spec/requests/api/pages/private_access_spec.rb +++ b/spec/requests/api/pages/private_access_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe "Private Project Pages Access" do using RSpec::Parameterized::TableSyntax @@ -25,14 +25,14 @@ describe "Private Project Pages Access" do end describe "Project should be private" do - describe '#private?' do + describe "#private?" do subject { project.private? } it { is_expected.to be_truthy } end end describe "GET /projects/:id/pages_access" do - context 'access depends on the level' do + context "access depends on the level" do where(:pages_access_level, :with_user, :expected_result) do ProjectFeature::DISABLED | "admin" | 403 ProjectFeature::DISABLED | "owner" | 403 diff --git a/spec/requests/api/pages/public_access_spec.rb b/spec/requests/api/pages/public_access_spec.rb index 16cc5697f30..8b177cd4159 100644 --- a/spec/requests/api/pages/public_access_spec.rb +++ b/spec/requests/api/pages/public_access_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe "Public Project Pages Access" do using RSpec::Parameterized::TableSyntax @@ -25,14 +25,14 @@ describe "Public Project Pages Access" do end describe "Project should be public" do - describe '#public?' do + describe "#public?" do subject { project.public? } it { is_expected.to be_truthy } end end describe "GET /projects/:id/pages_access" do - context 'access depends on the level' do + context "access depends on the level" do where(:pages_access_level, :with_user, :expected_result) do ProjectFeature::DISABLED | "admin" | 403 ProjectFeature::DISABLED | "owner" | 403 diff --git a/spec/requests/api/pages_domains_spec.rb b/spec/requests/api/pages_domains_spec.rb index 3eb68a6abb6..3189b5a221b 100644 --- a/spec/requests/api/pages_domains_spec.rb +++ b/spec/requests/api/pages_domains_spec.rb @@ -1,22 +1,22 @@ -require 'rails_helper' +require "rails_helper" describe API::PagesDomains do - set(:project) { create(:project, path: 'my.project', pages_https_only: false) } + set(:project) { create(:project, path: "my.project", pages_https_only: false) } set(:user) { create(:user) } set(:admin) { create(:admin) } - set(:pages_domain) { create(:pages_domain, :without_key, :without_certificate, domain: 'www.domain.test', project: project) } - set(:pages_domain_secure) { create(:pages_domain, domain: 'ssl.domain.test', project: project) } - set(:pages_domain_expired) { create(:pages_domain, :with_expired_certificate, domain: 'expired.domain.test', project: project) } + set(:pages_domain) { create(:pages_domain, :without_key, :without_certificate, domain: "www.domain.test", project: project) } + set(:pages_domain_secure) { create(:pages_domain, domain: "ssl.domain.test", project: project) } + set(:pages_domain_expired) { create(:pages_domain, :with_expired_certificate, domain: "expired.domain.test", project: project) } - let(:pages_domain_params) { build(:pages_domain, :without_key, :without_certificate, domain: 'www.other-domain.test').slice(:domain) } - let(:pages_domain_secure_params) { build(:pages_domain, domain: 'ssl.other-domain.test', project: project).slice(:domain, :certificate, :key) } + let(:pages_domain_params) { build(:pages_domain, :without_key, :without_certificate, domain: "www.other-domain.test").slice(:domain) } + let(:pages_domain_secure_params) { build(:pages_domain, domain: "ssl.other-domain.test", project: project).slice(:domain, :certificate, :key) } let(:pages_domain_secure_key_missmatch_params) {build(:pages_domain, :with_trusted_chain, project: project).slice(:domain, :certificate, :key) } let(:pages_domain_secure_missing_chain_params) {build(:pages_domain, :with_missing_chain, project: project).slice(:certificate) } let(:route) { "/projects/#{project.id}/pages/domains" } let(:route_domain) { "/projects/#{project.id}/pages/domains/#{pages_domain.domain}" } - let(:route_domain_path) { "/projects/#{project.full_path.gsub('/', '%2F')}/pages/domains/#{pages_domain.domain}" } + let(:route_domain_path) { "/projects/#{project.full_path.gsub("/", "%2F")}/pages/domains/#{pages_domain.domain}" } let(:route_secure_domain) { "/projects/#{project.id}/pages/domains/#{pages_domain_secure.domain}" } let(:route_expired_domain) { "/projects/#{project.id}/pages/domains/#{pages_domain_expired.domain}" } let(:route_vacant_domain) { "/projects/#{project.id}/pages/domains/www.vacant-domain.test" } @@ -25,473 +25,473 @@ describe API::PagesDomains do allow(Gitlab.config.pages).to receive(:enabled).and_return(true) end - describe 'GET /pages/domains' do - context 'when pages is disabled' do + describe "GET /pages/domains" do + context "when pages is disabled" do before do allow(Gitlab.config.pages).to receive(:enabled).and_return(false) end - it_behaves_like '404 response' do - let(:request) { get api('/pages/domains', admin) } + it_behaves_like "404 response" do + let(:request) { get api("/pages/domains", admin) } end end - context 'when pages is enabled' do - context 'when authenticated as an admin' do - it 'returns paginated all pages domains' do - get api('/pages/domains', admin) + context "when pages is enabled" do + context "when authenticated as an admin" do + it "returns paginated all pages domains" do + get api("/pages/domains", admin) expect(response).to have_gitlab_http_status(200) - expect(response).to match_response_schema('public_api/v4/pages_domain_basics') + expect(response).to match_response_schema("public_api/v4/pages_domain_basics") expect(response).to include_pagination_headers expect(json_response).to be_an Array expect(json_response.size).to eq(3) - expect(json_response.last).to have_key('domain') - expect(json_response.last).to have_key('project_id') - expect(json_response.last).to have_key('certificate_expiration') - expect(json_response.last['certificate_expiration']['expired']).to be true - expect(json_response.first).not_to have_key('certificate_expiration') + expect(json_response.last).to have_key("domain") + expect(json_response.last).to have_key("project_id") + expect(json_response.last).to have_key("certificate_expiration") + expect(json_response.last["certificate_expiration"]["expired"]).to be true + expect(json_response.first).not_to have_key("certificate_expiration") end end - context 'when authenticated as a non-member' do - it_behaves_like '403 response' do - let(:request) { get api('/pages/domains', user) } + context "when authenticated as a non-member" do + it_behaves_like "403 response" do + let(:request) { get api("/pages/domains", user) } end end end end - describe 'GET /projects/:project_id/pages/domains' do - shared_examples_for 'get pages domains' do - it 'returns paginated pages domains' do + describe "GET /projects/:project_id/pages/domains" do + shared_examples_for "get pages domains" do + it "returns paginated pages domains" do get api(route, user) expect(response).to have_gitlab_http_status(200) - expect(response).to match_response_schema('public_api/v4/pages_domains') + expect(response).to match_response_schema("public_api/v4/pages_domains") expect(response).to include_pagination_headers expect(json_response).to be_an Array expect(json_response.size).to eq(3) - expect(json_response.map { |pages_domain| pages_domain['domain'] }).to include(pages_domain.domain) - expect(json_response.last).to have_key('domain') + expect(json_response.map { |pages_domain| pages_domain["domain"] }).to include(pages_domain.domain) + expect(json_response.last).to have_key("domain") end end - context 'when pages is disabled' do + context "when pages is disabled" do before do allow(Gitlab.config.pages).to receive(:enabled).and_return(false) project.add_maintainer(user) end - it_behaves_like '404 response' do + it_behaves_like "404 response" do let(:request) { get api(route, user) } end end - context 'when user is a maintainer' do + context "when user is a maintainer" do before do project.add_maintainer(user) end - it_behaves_like 'get pages domains' + it_behaves_like "get pages domains" end - context 'when user is a developer' do + context "when user is a developer" do before do project.add_developer(user) end - it_behaves_like '403 response' do + it_behaves_like "403 response" do let(:request) { get api(route, user) } end end - context 'when user is a reporter' do + context "when user is a reporter" do before do project.add_reporter(user) end - it_behaves_like '403 response' do + it_behaves_like "403 response" do let(:request) { get api(route, user) } end end - context 'when user is a guest' do + context "when user is a guest" do before do project.add_guest(user) end - it_behaves_like '403 response' do + it_behaves_like "403 response" do let(:request) { get api(route, user) } end end - context 'when user is not a member' do - it_behaves_like '404 response' do + context "when user is not a member" do + it_behaves_like "404 response" do let(:request) { get api(route, user) } end end end - describe 'GET /projects/:project_id/pages/domains/:domain' do - shared_examples_for 'get pages domain' do - it 'returns pages domain' do + describe "GET /projects/:project_id/pages/domains/:domain" do + shared_examples_for "get pages domain" do + it "returns pages domain" do get api(route_domain, user) expect(response).to have_gitlab_http_status(200) - expect(response).to match_response_schema('public_api/v4/pages_domain/detail') - expect(json_response['domain']).to eq(pages_domain.domain) - expect(json_response['url']).to eq(pages_domain.url) - expect(json_response['certificate']).to be_nil + expect(response).to match_response_schema("public_api/v4/pages_domain/detail") + expect(json_response["domain"]).to eq(pages_domain.domain) + expect(json_response["url"]).to eq(pages_domain.url) + expect(json_response["certificate"]).to be_nil end - it 'returns pages domain with project path' do + it "returns pages domain with project path" do get api(route_domain_path, user) expect(response).to have_gitlab_http_status(200) - expect(response).to match_response_schema('public_api/v4/pages_domain/detail') - expect(json_response['domain']).to eq(pages_domain.domain) - expect(json_response['url']).to eq(pages_domain.url) - expect(json_response['certificate']).to be_nil + expect(response).to match_response_schema("public_api/v4/pages_domain/detail") + expect(json_response["domain"]).to eq(pages_domain.domain) + expect(json_response["url"]).to eq(pages_domain.url) + expect(json_response["certificate"]).to be_nil end - it 'returns pages domain with a certificate' do + it "returns pages domain with a certificate" do get api(route_secure_domain, user) expect(response).to have_gitlab_http_status(200) - expect(response).to match_response_schema('public_api/v4/pages_domain/detail') - expect(json_response['domain']).to eq(pages_domain_secure.domain) - expect(json_response['url']).to eq(pages_domain_secure.url) - expect(json_response['certificate']['subject']).to eq(pages_domain_secure.subject) - expect(json_response['certificate']['expired']).to be false + expect(response).to match_response_schema("public_api/v4/pages_domain/detail") + expect(json_response["domain"]).to eq(pages_domain_secure.domain) + expect(json_response["url"]).to eq(pages_domain_secure.url) + expect(json_response["certificate"]["subject"]).to eq(pages_domain_secure.subject) + expect(json_response["certificate"]["expired"]).to be false end - it 'returns pages domain with an expired certificate' do + it "returns pages domain with an expired certificate" do get api(route_expired_domain, user) expect(response).to have_gitlab_http_status(200) - expect(response).to match_response_schema('public_api/v4/pages_domain/detail') - expect(json_response['certificate']['expired']).to be true + expect(response).to match_response_schema("public_api/v4/pages_domain/detail") + expect(json_response["certificate"]["expired"]).to be true end end - context 'when domain is vacant' do + context "when domain is vacant" do before do project.add_maintainer(user) end - it_behaves_like '404 response' do + it_behaves_like "404 response" do let(:request) { get api(route_vacant_domain, user) } end end - context 'when user is a maintainer' do + context "when user is a maintainer" do before do project.add_maintainer(user) end - it_behaves_like 'get pages domain' + it_behaves_like "get pages domain" end - context 'when user is a developer' do + context "when user is a developer" do before do project.add_developer(user) end - it_behaves_like '403 response' do + it_behaves_like "403 response" do let(:request) { get api(route, user) } end end - context 'when user is a reporter' do + context "when user is a reporter" do before do project.add_reporter(user) end - it_behaves_like '403 response' do + it_behaves_like "403 response" do let(:request) { get api(route, user) } end end - context 'when user is a guest' do + context "when user is a guest" do before do project.add_guest(user) end - it_behaves_like '403 response' do + it_behaves_like "403 response" do let(:request) { get api(route, user) } end end - context 'when user is not a member' do - it_behaves_like '404 response' do + context "when user is not a member" do + it_behaves_like "404 response" do let(:request) { get api(route, user) } end end end - describe 'POST /projects/:project_id/pages/domains' do + describe "POST /projects/:project_id/pages/domains" do let(:params) { pages_domain_params.slice(:domain) } let(:params_secure) { pages_domain_secure_params.slice(:domain, :certificate, :key) } - shared_examples_for 'post pages domains' do - it 'creates a new pages domain' do + shared_examples_for "post pages domains" do + it "creates a new pages domain" do post api(route, user), params: params - pages_domain = PagesDomain.find_by(domain: json_response['domain']) + pages_domain = PagesDomain.find_by(domain: json_response["domain"]) expect(response).to have_gitlab_http_status(201) - expect(response).to match_response_schema('public_api/v4/pages_domain/detail') + expect(response).to match_response_schema("public_api/v4/pages_domain/detail") expect(pages_domain.domain).to eq(params[:domain]) expect(pages_domain.certificate).to be_nil expect(pages_domain.key).to be_nil end - it 'creates a new secure pages domain' do + it "creates a new secure pages domain" do post api(route, user), params: params_secure - pages_domain = PagesDomain.find_by(domain: json_response['domain']) + pages_domain = PagesDomain.find_by(domain: json_response["domain"]) expect(response).to have_gitlab_http_status(201) - expect(response).to match_response_schema('public_api/v4/pages_domain/detail') + expect(response).to match_response_schema("public_api/v4/pages_domain/detail") expect(pages_domain.domain).to eq(params_secure[:domain]) expect(pages_domain.certificate).to eq(params_secure[:certificate]) expect(pages_domain.key).to eq(params_secure[:key]) end - it 'fails to create pages domain without key' do + it "fails to create pages domain without key" do post api(route, user), params: pages_domain_secure_params.slice(:domain, :certificate) expect(response).to have_gitlab_http_status(400) end - it 'fails to create pages domain with key missmatch' do + it "fails to create pages domain with key missmatch" do post api(route, user), params: pages_domain_secure_key_missmatch_params.slice(:domain, :certificate, :key) expect(response).to have_gitlab_http_status(400) end end - context 'when user is a maintainer' do + context "when user is a maintainer" do before do project.add_maintainer(user) end - it_behaves_like 'post pages domains' + it_behaves_like "post pages domains" end - context 'when user is a developer' do + context "when user is a developer" do before do project.add_developer(user) end - it_behaves_like '403 response' do + it_behaves_like "403 response" do let(:request) { post api(route, user), params: params } end end - context 'when user is a reporter' do + context "when user is a reporter" do before do project.add_reporter(user) end - it_behaves_like '403 response' do + it_behaves_like "403 response" do let(:request) { post api(route, user), params: params } end end - context 'when user is a guest' do + context "when user is a guest" do before do project.add_guest(user) end - it_behaves_like '403 response' do + it_behaves_like "403 response" do let(:request) { post api(route, user), params: params } end end - context 'when user is not a member' do - it_behaves_like '404 response' do + context "when user is not a member" do + it_behaves_like "404 response" do let(:request) { post api(route, user), params: params } end end end - describe 'PUT /projects/:project_id/pages/domains/:domain' do + describe "PUT /projects/:project_id/pages/domains/:domain" do let(:params_secure) { pages_domain_secure_params.slice(:certificate, :key) } let(:params_secure_nokey) { pages_domain_secure_params.slice(:certificate) } - shared_examples_for 'put pages domain' do - it 'updates pages domain removing certificate' do + shared_examples_for "put pages domain" do + it "updates pages domain removing certificate" do put api(route_secure_domain, user) pages_domain_secure.reload expect(response).to have_gitlab_http_status(200) - expect(response).to match_response_schema('public_api/v4/pages_domain/detail') + expect(response).to match_response_schema("public_api/v4/pages_domain/detail") expect(pages_domain_secure.certificate).to be_nil expect(pages_domain_secure.key).to be_nil end - it 'updates pages domain adding certificate' do + it "updates pages domain adding certificate" do put api(route_domain, user), params: params_secure pages_domain.reload expect(response).to have_gitlab_http_status(200) - expect(response).to match_response_schema('public_api/v4/pages_domain/detail') + expect(response).to match_response_schema("public_api/v4/pages_domain/detail") expect(pages_domain.certificate).to eq(params_secure[:certificate]) expect(pages_domain.key).to eq(params_secure[:key]) end - it 'updates pages domain with expired certificate' do + it "updates pages domain with expired certificate" do put api(route_expired_domain, user), params: params_secure pages_domain_expired.reload expect(response).to have_gitlab_http_status(200) - expect(response).to match_response_schema('public_api/v4/pages_domain/detail') + expect(response).to match_response_schema("public_api/v4/pages_domain/detail") expect(pages_domain_expired.certificate).to eq(params_secure[:certificate]) expect(pages_domain_expired.key).to eq(params_secure[:key]) end - it 'updates pages domain with expired certificate not updating key' do + it "updates pages domain with expired certificate not updating key" do put api(route_secure_domain, user), params: params_secure_nokey pages_domain_secure.reload expect(response).to have_gitlab_http_status(200) - expect(response).to match_response_schema('public_api/v4/pages_domain/detail') + expect(response).to match_response_schema("public_api/v4/pages_domain/detail") expect(pages_domain_secure.certificate).to eq(params_secure_nokey[:certificate]) end - it 'fails to update pages domain adding certificate without key' do + it "fails to update pages domain adding certificate without key" do put api(route_domain, user), params: params_secure_nokey expect(response).to have_gitlab_http_status(400) end - it 'fails to update pages domain adding certificate with missing chain' do + it "fails to update pages domain adding certificate with missing chain" do put api(route_domain, user), params: pages_domain_secure_missing_chain_params.slice(:certificate) expect(response).to have_gitlab_http_status(400) end - it 'fails to update pages domain with key missmatch' do + it "fails to update pages domain with key missmatch" do put api(route_secure_domain, user), params: pages_domain_secure_key_missmatch_params.slice(:certificate, :key) expect(response).to have_gitlab_http_status(400) end end - context 'when domain is vacant' do + context "when domain is vacant" do before do project.add_maintainer(user) end - it_behaves_like '404 response' do + it_behaves_like "404 response" do let(:request) { put api(route_vacant_domain, user) } end end - context 'when user is a maintainer' do + context "when user is a maintainer" do before do project.add_maintainer(user) end - it_behaves_like 'put pages domain' + it_behaves_like "put pages domain" end - context 'when user is a developer' do + context "when user is a developer" do before do project.add_developer(user) end - it_behaves_like '403 response' do + it_behaves_like "403 response" do let(:request) { put api(route_domain, user) } end end - context 'when user is a reporter' do + context "when user is a reporter" do before do project.add_reporter(user) end - it_behaves_like '403 response' do + it_behaves_like "403 response" do let(:request) { put api(route_domain, user) } end end - context 'when user is a guest' do + context "when user is a guest" do before do project.add_guest(user) end - it_behaves_like '403 response' do + it_behaves_like "403 response" do let(:request) { put api(route_domain, user) } end end - context 'when user is not a member' do - it_behaves_like '404 response' do + context "when user is not a member" do + it_behaves_like "404 response" do let(:request) { put api(route_domain, user) } end end end - describe 'DELETE /projects/:project_id/pages/domains/:domain' do - shared_examples_for 'delete pages domain' do - it 'deletes a pages domain' do + describe "DELETE /projects/:project_id/pages/domains/:domain" do + shared_examples_for "delete pages domain" do + it "deletes a pages domain" do delete api(route_domain, user) expect(response).to have_gitlab_http_status(204) end end - context 'when domain is vacant' do + context "when domain is vacant" do before do project.add_maintainer(user) end - it_behaves_like '404 response' do + it_behaves_like "404 response" do let(:request) { delete api(route_vacant_domain, user) } end end - context 'when user is a maintainer' do + context "when user is a maintainer" do before do project.add_maintainer(user) end - it_behaves_like 'delete pages domain' + it_behaves_like "delete pages domain" end - context 'when user is a developer' do + context "when user is a developer" do before do project.add_developer(user) end - it_behaves_like '403 response' do + it_behaves_like "403 response" do let(:request) { delete api(route_domain, user) } end end - context 'when user is a reporter' do + context "when user is a reporter" do before do project.add_reporter(user) end - it_behaves_like '403 response' do + it_behaves_like "403 response" do let(:request) { delete api(route_domain, user) } end end - context 'when user is a guest' do + context "when user is a guest" do before do project.add_guest(user) end - it_behaves_like '403 response' do + it_behaves_like "403 response" do let(:request) { delete api(route_domain, user) } end end - context 'when user is not a member' do - it_behaves_like '404 response' do + context "when user is not a member" do + it_behaves_like "404 response" do let(:request) { delete api(route_domain, user) } end end diff --git a/spec/requests/api/pipeline_schedules_spec.rb b/spec/requests/api/pipeline_schedules_spec.rb index 870ef34437f..aa3d88dbf7b 100644 --- a/spec/requests/api/pipeline_schedules_spec.rb +++ b/spec/requests/api/pipeline_schedules_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe API::PipelineSchedules do set(:developer) { create(:user) } @@ -9,8 +9,8 @@ describe API::PipelineSchedules do project.add_developer(developer) end - describe 'GET /projects/:id/pipeline_schedules' do - context 'authenticated user with valid permissions' do + describe "GET /projects/:id/pipeline_schedules" do + context "authenticated user with valid permissions" do let(:pipeline_schedule) { create(:ci_pipeline_schedule, project: project, owner: developer) } before do @@ -28,27 +28,27 @@ describe API::PipelineSchedules do end end - it 'returns list of pipeline_schedules' do + it "returns list of pipeline_schedules" do get api("/projects/#{project.id}/pipeline_schedules", developer) expect(response).to have_gitlab_http_status(:ok) expect(response).to include_pagination_headers - expect(response).to match_response_schema('pipeline_schedules') + expect(response).to match_response_schema("pipeline_schedules") end - it 'avoids N + 1 queries' do + it "avoids N + 1 queries" do # We need at least two users to trigger a preload for that relation. create_pipeline_schedules(1) - control_count = ActiveRecord::QueryRecorder.new do + control_count = ActiveRecord::QueryRecorder.new { get api("/projects/#{project.id}/pipeline_schedules", developer) - end.count + }.count create_pipeline_schedules(10) - expect do + expect { get api("/projects/#{project.id}/pipeline_schedules", developer) - end.not_to exceed_query_limit(control_count) + }.not_to exceed_query_limit(control_count) end %w[active inactive].each do |target| @@ -57,29 +57,29 @@ describe API::PipelineSchedules do create(:ci_pipeline_schedule, project: project, active: active?(target)) end - it 'returns matched pipeline schedules' do - get api("/projects/#{project.id}/pipeline_schedules", developer), params: { scope: target } + it "returns matched pipeline schedules" do + get api("/projects/#{project.id}/pipeline_schedules", developer), params: {scope: target} - expect(json_response.map { |r| r['active'] }).to all(eq(active?(target))) + expect(json_response.map { |r| r["active"] }).to all(eq(active?(target))) end end def active?(str) - (str == 'active') ? true : false + str == "active" end end end - context 'authenticated user with invalid permissions' do - it 'does not return pipeline_schedules list' do + context "authenticated user with invalid permissions" do + it "does not return pipeline_schedules list" do get api("/projects/#{project.id}/pipeline_schedules", user) expect(response).to have_gitlab_http_status(:not_found) end end - context 'unauthenticated user' do - it 'does not return pipeline_schedules list' do + context "unauthenticated user" do + it "does not return pipeline_schedules list" do get api("/projects/#{project.id}/pipeline_schedules") expect(response).to have_gitlab_http_status(:unauthorized) @@ -87,50 +87,50 @@ describe API::PipelineSchedules do end end - describe 'GET /projects/:id/pipeline_schedules/:pipeline_schedule_id' do + describe "GET /projects/:id/pipeline_schedules/:pipeline_schedule_id" do let(:pipeline_schedule) { create(:ci_pipeline_schedule, project: project, owner: developer) } before do pipeline_schedule.pipelines << build(:ci_pipeline, project: project) end - context 'authenticated user with valid permissions' do - it 'returns pipeline_schedule details' do + context "authenticated user with valid permissions" do + it "returns pipeline_schedule details" do get api("/projects/#{project.id}/pipeline_schedules/#{pipeline_schedule.id}", developer) expect(response).to have_gitlab_http_status(:ok) - expect(response).to match_response_schema('pipeline_schedule') + expect(response).to match_response_schema("pipeline_schedule") end - it 'responds with 404 Not Found if requesting non-existing pipeline_schedule' do + it "responds with 404 Not Found if requesting non-existing pipeline_schedule" do get api("/projects/#{project.id}/pipeline_schedules/-5", developer) expect(response).to have_gitlab_http_status(:not_found) end end - context 'authenticated user with invalid permissions' do - it 'does not return pipeline_schedules list' do + context "authenticated user with invalid permissions" do + it "does not return pipeline_schedules list" do get api("/projects/#{project.id}/pipeline_schedules/#{pipeline_schedule.id}", user) expect(response).to have_gitlab_http_status(:not_found) end end - context 'authenticated user with insufficient permissions' do + context "authenticated user with insufficient permissions" do before do project.add_guest(user) end - it 'does not return pipeline_schedules list' do + it "does not return pipeline_schedules list" do get api("/projects/#{project.id}/pipeline_schedules/#{pipeline_schedule.id}", user) expect(response).to have_gitlab_http_status(:not_found) end end - context 'unauthenticated user' do - it 'does not return pipeline_schedules list' do + context "unauthenticated user" do + it "does not return pipeline_schedules list" do get api("/projects/#{project.id}/pipeline_schedules/#{pipeline_schedule.id}") expect(response).to have_gitlab_http_status(:unauthorized) @@ -138,56 +138,56 @@ describe API::PipelineSchedules do end end - describe 'POST /projects/:id/pipeline_schedules' do + describe "POST /projects/:id/pipeline_schedules" do let(:params) { attributes_for(:ci_pipeline_schedule) } - context 'authenticated user with valid permissions' do - context 'with required parameters' do - it 'creates pipeline_schedule' do - expect do + context "authenticated user with valid permissions" do + context "with required parameters" do + it "creates pipeline_schedule" do + expect { post api("/projects/#{project.id}/pipeline_schedules", developer), params: params - end.to change { project.pipeline_schedules.count }.by(1) + }.to change { project.pipeline_schedules.count }.by(1) expect(response).to have_gitlab_http_status(:created) - expect(response).to match_response_schema('pipeline_schedule') - expect(json_response['description']).to eq(params[:description]) - expect(json_response['ref']).to eq(params[:ref]) - expect(json_response['cron']).to eq(params[:cron]) - expect(json_response['cron_timezone']).to eq(params[:cron_timezone]) - expect(json_response['owner']['id']).to eq(developer.id) + expect(response).to match_response_schema("pipeline_schedule") + expect(json_response["description"]).to eq(params[:description]) + expect(json_response["ref"]).to eq(params[:ref]) + expect(json_response["cron"]).to eq(params[:cron]) + expect(json_response["cron_timezone"]).to eq(params[:cron_timezone]) + expect(json_response["owner"]["id"]).to eq(developer.id) end end - context 'without required parameters' do - it 'does not create pipeline_schedule' do + context "without required parameters" do + it "does not create pipeline_schedule" do post api("/projects/#{project.id}/pipeline_schedules", developer) expect(response).to have_gitlab_http_status(:bad_request) end end - context 'when cron has validation error' do - it 'does not create pipeline_schedule' do + context "when cron has validation error" do + it "does not create pipeline_schedule" do post api("/projects/#{project.id}/pipeline_schedules", developer), - params: params.merge('cron' => 'invalid-cron') + params: params.merge("cron" => "invalid-cron") expect(response).to have_gitlab_http_status(:bad_request) - expect(json_response['message']).to have_key('cron') + expect(json_response["message"]).to have_key("cron") end end end - context 'authenticated user with invalid permissions' do - it 'does not create pipeline_schedule' do + context "authenticated user with invalid permissions" do + it "does not create pipeline_schedule" do post api("/projects/#{project.id}/pipeline_schedules", user), params: params expect(response).to have_gitlab_http_status(:not_found) end end - context 'unauthenticated user' do - it 'does not create pipeline_schedule' do + context "unauthenticated user" do + it "does not create pipeline_schedule" do post api("/projects/#{project.id}/pipeline_schedules"), params: params expect(response).to have_gitlab_http_status(:unauthorized) @@ -195,42 +195,42 @@ describe API::PipelineSchedules do end end - describe 'PUT /projects/:id/pipeline_schedules/:pipeline_schedule_id' do + describe "PUT /projects/:id/pipeline_schedules/:pipeline_schedule_id" do let(:pipeline_schedule) do create(:ci_pipeline_schedule, project: project, owner: developer) end - context 'authenticated user with valid permissions' do - it 'updates cron' do + context "authenticated user with valid permissions" do + it "updates cron" do put api("/projects/#{project.id}/pipeline_schedules/#{pipeline_schedule.id}", developer), - params: { cron: '1 2 3 4 *' } + params: {cron: "1 2 3 4 *"} expect(response).to have_gitlab_http_status(:ok) - expect(response).to match_response_schema('pipeline_schedule') - expect(json_response['cron']).to eq('1 2 3 4 *') + expect(response).to match_response_schema("pipeline_schedule") + expect(json_response["cron"]).to eq("1 2 3 4 *") end - context 'when cron has validation error' do - it 'does not update pipeline_schedule' do + context "when cron has validation error" do + it "does not update pipeline_schedule" do put api("/projects/#{project.id}/pipeline_schedules/#{pipeline_schedule.id}", developer), - params: { cron: 'invalid-cron' } + params: {cron: "invalid-cron"} expect(response).to have_gitlab_http_status(:bad_request) - expect(json_response['message']).to have_key('cron') + expect(json_response["message"]).to have_key("cron") end end end - context 'authenticated user with invalid permissions' do - it 'does not update pipeline_schedule' do + context "authenticated user with invalid permissions" do + it "does not update pipeline_schedule" do put api("/projects/#{project.id}/pipeline_schedules/#{pipeline_schedule.id}", user) expect(response).to have_gitlab_http_status(:not_found) end end - context 'unauthenticated user' do - it 'does not update pipeline_schedule' do + context "unauthenticated user" do + it "does not update pipeline_schedule" do put api("/projects/#{project.id}/pipeline_schedules/#{pipeline_schedule.id}") expect(response).to have_gitlab_http_status(:unauthorized) @@ -238,30 +238,30 @@ describe API::PipelineSchedules do end end - describe 'POST /projects/:id/pipeline_schedules/:pipeline_schedule_id/take_ownership' do + describe "POST /projects/:id/pipeline_schedules/:pipeline_schedule_id/take_ownership" do let(:pipeline_schedule) do create(:ci_pipeline_schedule, project: project, owner: developer) end - context 'authenticated user with valid permissions' do - it 'updates owner' do + context "authenticated user with valid permissions" do + it "updates owner" do post api("/projects/#{project.id}/pipeline_schedules/#{pipeline_schedule.id}/take_ownership", developer) expect(response).to have_gitlab_http_status(:created) - expect(response).to match_response_schema('pipeline_schedule') + expect(response).to match_response_schema("pipeline_schedule") end end - context 'authenticated user with invalid permissions' do - it 'does not update owner' do + context "authenticated user with invalid permissions" do + it "does not update owner" do post api("/projects/#{project.id}/pipeline_schedules/#{pipeline_schedule.id}/take_ownership", user) expect(response).to have_gitlab_http_status(:not_found) end end - context 'unauthenticated user' do - it 'does not update owner' do + context "unauthenticated user" do + it "does not update owner" do post api("/projects/#{project.id}/pipeline_schedules/#{pipeline_schedule.id}/take_ownership") expect(response).to have_gitlab_http_status(:unauthorized) @@ -269,7 +269,7 @@ describe API::PipelineSchedules do end end - describe 'DELETE /projects/:id/pipeline_schedules/:pipeline_schedule_id' do + describe "DELETE /projects/:id/pipeline_schedules/:pipeline_schedule_id" do let(:maintainer) { create(:user) } let!(:pipeline_schedule) do @@ -280,38 +280,38 @@ describe API::PipelineSchedules do project.add_maintainer(maintainer) end - context 'authenticated user with valid permissions' do - it 'deletes pipeline_schedule' do - expect do + context "authenticated user with valid permissions" do + it "deletes pipeline_schedule" do + expect { delete api("/projects/#{project.id}/pipeline_schedules/#{pipeline_schedule.id}", maintainer) - end.to change { project.pipeline_schedules.count }.by(-1) + }.to change { project.pipeline_schedules.count }.by(-1) expect(response).to have_gitlab_http_status(204) end - it 'responds with 404 Not Found if requesting non-existing pipeline_schedule' do + it "responds with 404 Not Found if requesting non-existing pipeline_schedule" do delete api("/projects/#{project.id}/pipeline_schedules/-5", maintainer) expect(response).to have_gitlab_http_status(:not_found) end - it_behaves_like '412 response' do + it_behaves_like "412 response" do let(:request) { api("/projects/#{project.id}/pipeline_schedules/#{pipeline_schedule.id}", maintainer) } end end - context 'authenticated user with invalid permissions' do + context "authenticated user with invalid permissions" do let!(:pipeline_schedule) { create(:ci_pipeline_schedule, project: project, owner: maintainer) } - it 'does not delete pipeline_schedule' do + it "does not delete pipeline_schedule" do delete api("/projects/#{project.id}/pipeline_schedules/#{pipeline_schedule.id}", developer) expect(response).to have_gitlab_http_status(:forbidden) end end - context 'unauthenticated user' do - it 'does not delete pipeline_schedule' do + context "unauthenticated user" do + it "does not delete pipeline_schedule" do delete api("/projects/#{project.id}/pipeline_schedules/#{pipeline_schedule.id}") expect(response).to have_gitlab_http_status(:unauthorized) @@ -319,57 +319,57 @@ describe API::PipelineSchedules do end end - describe 'POST /projects/:id/pipeline_schedules/:pipeline_schedule_id/variables' do + describe "POST /projects/:id/pipeline_schedules/:pipeline_schedule_id/variables" do let(:params) { attributes_for(:ci_pipeline_schedule_variable) } set(:pipeline_schedule) do create(:ci_pipeline_schedule, project: project, owner: developer) end - context 'authenticated user with valid permissions' do - context 'with required parameters' do - it 'creates pipeline_schedule_variable' do - expect do + context "authenticated user with valid permissions" do + context "with required parameters" do + it "creates pipeline_schedule_variable" do + expect { post api("/projects/#{project.id}/pipeline_schedules/#{pipeline_schedule.id}/variables", developer), params: params - end.to change { pipeline_schedule.variables.count }.by(1) + }.to change { pipeline_schedule.variables.count }.by(1) expect(response).to have_gitlab_http_status(:created) - expect(response).to match_response_schema('pipeline_schedule_variable') - expect(json_response['key']).to eq(params[:key]) - expect(json_response['value']).to eq(params[:value]) + expect(response).to match_response_schema("pipeline_schedule_variable") + expect(json_response["key"]).to eq(params[:key]) + expect(json_response["value"]).to eq(params[:value]) end end - context 'without required parameters' do - it 'does not create pipeline_schedule_variable' do + context "without required parameters" do + it "does not create pipeline_schedule_variable" do post api("/projects/#{project.id}/pipeline_schedules/#{pipeline_schedule.id}/variables", developer) expect(response).to have_gitlab_http_status(:bad_request) end end - context 'when key has validation error' do - it 'does not create pipeline_schedule_variable' do + context "when key has validation error" do + it "does not create pipeline_schedule_variable" do post api("/projects/#{project.id}/pipeline_schedules/#{pipeline_schedule.id}/variables", developer), - params: params.merge('key' => '!?!?') + params: params.merge("key" => "!?!?") expect(response).to have_gitlab_http_status(:bad_request) - expect(json_response['message']).to have_key('key') + expect(json_response["message"]).to have_key("key") end end end - context 'authenticated user with invalid permissions' do - it 'does not create pipeline_schedule_variable' do + context "authenticated user with invalid permissions" do + it "does not create pipeline_schedule_variable" do post api("/projects/#{project.id}/pipeline_schedules/#{pipeline_schedule.id}/variables", user), params: params expect(response).to have_gitlab_http_status(:not_found) end end - context 'unauthenticated user' do - it 'does not create pipeline_schedule_variable' do + context "unauthenticated user" do + it "does not create pipeline_schedule_variable" do post api("/projects/#{project.id}/pipeline_schedules/#{pipeline_schedule.id}/variables"), params: params expect(response).to have_gitlab_http_status(:unauthorized) @@ -377,7 +377,7 @@ describe API::PipelineSchedules do end end - describe 'PUT /projects/:id/pipeline_schedules/:pipeline_schedule_id/variables/:key' do + describe "PUT /projects/:id/pipeline_schedules/:pipeline_schedule_id/variables/:key" do set(:pipeline_schedule) do create(:ci_pipeline_schedule, project: project, owner: developer) end @@ -386,27 +386,27 @@ describe API::PipelineSchedules do create(:ci_pipeline_schedule_variable, pipeline_schedule: pipeline_schedule) end - context 'authenticated user with valid permissions' do - it 'updates pipeline_schedule_variable' do + context "authenticated user with valid permissions" do + it "updates pipeline_schedule_variable" do put api("/projects/#{project.id}/pipeline_schedules/#{pipeline_schedule.id}/variables/#{pipeline_schedule_variable.key}", developer), - params: { value: 'updated_value' } + params: {value: "updated_value"} expect(response).to have_gitlab_http_status(:ok) - expect(response).to match_response_schema('pipeline_schedule_variable') - expect(json_response['value']).to eq('updated_value') + expect(response).to match_response_schema("pipeline_schedule_variable") + expect(json_response["value"]).to eq("updated_value") end end - context 'authenticated user with invalid permissions' do - it 'does not update pipeline_schedule_variable' do + context "authenticated user with invalid permissions" do + it "does not update pipeline_schedule_variable" do put api("/projects/#{project.id}/pipeline_schedules/#{pipeline_schedule.id}/variables/#{pipeline_schedule_variable.key}", user) expect(response).to have_gitlab_http_status(:not_found) end end - context 'unauthenticated user' do - it 'does not update pipeline_schedule_variable' do + context "unauthenticated user" do + it "does not update pipeline_schedule_variable" do put api("/projects/#{project.id}/pipeline_schedules/#{pipeline_schedule.id}/variables/#{pipeline_schedule_variable.key}") expect(response).to have_gitlab_http_status(:unauthorized) @@ -414,7 +414,7 @@ describe API::PipelineSchedules do end end - describe 'DELETE /projects/:id/pipeline_schedules/:pipeline_schedule_id/variables/:key' do + describe "DELETE /projects/:id/pipeline_schedules/:pipeline_schedule_id/variables/:key" do let(:maintainer) { create(:user) } set(:pipeline_schedule) do @@ -429,35 +429,35 @@ describe API::PipelineSchedules do project.add_maintainer(maintainer) end - context 'authenticated user with valid permissions' do - it 'deletes pipeline_schedule_variable' do - expect do + context "authenticated user with valid permissions" do + it "deletes pipeline_schedule_variable" do + expect { delete api("/projects/#{project.id}/pipeline_schedules/#{pipeline_schedule.id}/variables/#{pipeline_schedule_variable.key}", maintainer) - end.to change { Ci::PipelineScheduleVariable.count }.by(-1) + }.to change { Ci::PipelineScheduleVariable.count }.by(-1) expect(response).to have_gitlab_http_status(:accepted) - expect(response).to match_response_schema('pipeline_schedule_variable') + expect(response).to match_response_schema("pipeline_schedule_variable") end - it 'responds with 404 Not Found if requesting non-existing pipeline_schedule_variable' do + it "responds with 404 Not Found if requesting non-existing pipeline_schedule_variable" do delete api("/projects/#{project.id}/pipeline_schedules/#{pipeline_schedule.id}/variables/____", maintainer) expect(response).to have_gitlab_http_status(:not_found) end end - context 'authenticated user with invalid permissions' do + context "authenticated user with invalid permissions" do let!(:pipeline_schedule) { create(:ci_pipeline_schedule, project: project, owner: maintainer) } - it 'does not delete pipeline_schedule_variable' do + it "does not delete pipeline_schedule_variable" do delete api("/projects/#{project.id}/pipeline_schedules/#{pipeline_schedule.id}/variables/#{pipeline_schedule_variable.key}", developer) expect(response).to have_gitlab_http_status(:forbidden) end end - context 'unauthenticated user' do - it 'does not delete pipeline_schedule_variable' do + context "unauthenticated user" do + it "does not delete pipeline_schedule_variable" do delete api("/projects/#{project.id}/pipeline_schedules/#{pipeline_schedule.id}/variables/#{pipeline_schedule_variable.key}") expect(response).to have_gitlab_http_status(:unauthorized) diff --git a/spec/requests/api/pipelines_spec.rb b/spec/requests/api/pipelines_spec.rb index 52599db9a9e..21ca3624ada 100644 --- a/spec/requests/api/pipelines_spec.rb +++ b/spec/requests/api/pipelines_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe API::Pipelines do let(:user) { create(:user) } @@ -14,85 +14,85 @@ describe API::Pipelines do project.add_maintainer(user) end - describe 'GET /projects/:id/pipelines ' do - context 'authorized user' do - it 'returns project pipelines' do + describe "GET /projects/:id/pipelines " do + context "authorized user" do + it "returns project pipelines" do get api("/projects/#{project.id}/pipelines", user) expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response).to be_an Array - expect(json_response.first['sha']).to match /\A\h{40}\z/ - expect(json_response.first['id']).to eq pipeline.id - expect(json_response.first['web_url']).to be_present - expect(json_response.first.keys).to contain_exactly(*%w[id sha ref status web_url]) + expect(json_response.first["sha"]).to match /\A\h{40}\z/ + expect(json_response.first["id"]).to eq pipeline.id + expect(json_response.first["web_url"]).to be_present + expect(json_response.first.keys).to contain_exactly("id", "sha", "ref", "status", "web_url") end - context 'when parameter is passed' do + context "when parameter is passed" do %w[running pending].each do |target| context "when scope is #{target}" do before do create(:ci_pipeline, project: project, status: target) end - it 'returns matched pipelines' do - get api("/projects/#{project.id}/pipelines", user), params: { scope: target } + it "returns matched pipelines" do + get api("/projects/#{project.id}/pipelines", user), params: {scope: target} expect(response).to have_gitlab_http_status(:ok) expect(response).to include_pagination_headers expect(json_response).not_to be_empty - json_response.each { |r| expect(r['status']).to eq(target) } + json_response.each { |r| expect(r["status"]).to eq(target) } end end end - context 'when scope is finished' do + context "when scope is finished" do before do - create(:ci_pipeline, project: project, status: 'success') - create(:ci_pipeline, project: project, status: 'failed') - create(:ci_pipeline, project: project, status: 'canceled') + create(:ci_pipeline, project: project, status: "success") + create(:ci_pipeline, project: project, status: "failed") + create(:ci_pipeline, project: project, status: "canceled") end - it 'returns matched pipelines' do - get api("/projects/#{project.id}/pipelines", user), params: { scope: 'finished' } + it "returns matched pipelines" do + get api("/projects/#{project.id}/pipelines", user), params: {scope: "finished"} expect(response).to have_gitlab_http_status(:ok) expect(response).to include_pagination_headers expect(json_response).not_to be_empty - json_response.each { |r| expect(r['status']).to be_in(%w[success failed canceled]) } + json_response.each { |r| expect(r["status"]).to be_in(%w[success failed canceled]) } end end - context 'when scope is branches or tags' do + context "when scope is branches or tags" do let!(:pipeline_branch) { create(:ci_pipeline, project: project) } - let!(:pipeline_tag) { create(:ci_pipeline, project: project, ref: 'v1.0.0', tag: true) } + let!(:pipeline_tag) { create(:ci_pipeline, project: project, ref: "v1.0.0", tag: true) } - context 'when scope is branches' do - it 'returns matched pipelines' do - get api("/projects/#{project.id}/pipelines", user), params: { scope: 'branches' } + context "when scope is branches" do + it "returns matched pipelines" do + get api("/projects/#{project.id}/pipelines", user), params: {scope: "branches"} expect(response).to have_gitlab_http_status(:ok) expect(response).to include_pagination_headers expect(json_response).not_to be_empty - expect(json_response.last['id']).to eq(pipeline_branch.id) + expect(json_response.last["id"]).to eq(pipeline_branch.id) end end - context 'when scope is tags' do - it 'returns matched pipelines' do - get api("/projects/#{project.id}/pipelines", user), params: { scope: 'tags' } + context "when scope is tags" do + it "returns matched pipelines" do + get api("/projects/#{project.id}/pipelines", user), params: {scope: "tags"} expect(response).to have_gitlab_http_status(:ok) expect(response).to include_pagination_headers expect(json_response).not_to be_empty - expect(json_response.last['id']).to eq(pipeline_tag.id) + expect(json_response.last["id"]).to eq(pipeline_tag.id) end end end - context 'when scope is invalid' do - it 'returns bad_request' do - get api("/projects/#{project.id}/pipelines", user), params: { scope: 'invalid-scope' } + context "when scope is invalid" do + it "returns bad_request" do + get api("/projects/#{project.id}/pipelines", user), params: {scope: "invalid-scope"} expect(response).to have_gitlab_http_status(:bad_request) end @@ -106,44 +106,44 @@ describe API::Pipelines do create(:ci_pipeline, project: project, status: exception_status.sample) end - it 'returns matched pipelines' do - get api("/projects/#{project.id}/pipelines", user), params: { status: target } + it "returns matched pipelines" do + get api("/projects/#{project.id}/pipelines", user), params: {status: target} expect(response).to have_gitlab_http_status(:ok) expect(response).to include_pagination_headers expect(json_response).not_to be_empty - json_response.each { |r| expect(r['status']).to eq(target) } + json_response.each { |r| expect(r["status"]).to eq(target) } end end end - context 'when status is invalid' do - it 'returns bad_request' do - get api("/projects/#{project.id}/pipelines", user), params: { status: 'invalid-status' } + context "when status is invalid" do + it "returns bad_request" do + get api("/projects/#{project.id}/pipelines", user), params: {status: "invalid-status"} expect(response).to have_gitlab_http_status(:bad_request) end end - context 'when ref is specified' do + context "when ref is specified" do before do create(:ci_pipeline, project: project) end - context 'when ref exists' do - it 'returns matched pipelines' do - get api("/projects/#{project.id}/pipelines", user), params: { ref: 'master' } + context "when ref exists" do + it "returns matched pipelines" do + get api("/projects/#{project.id}/pipelines", user), params: {ref: "master"} expect(response).to have_gitlab_http_status(:ok) expect(response).to include_pagination_headers expect(json_response).not_to be_empty - json_response.each { |r| expect(r['ref']).to eq('master') } + json_response.each { |r| expect(r["ref"]).to eq("master") } end end - context 'when ref does not exist' do - it 'returns empty' do - get api("/projects/#{project.id}/pipelines", user), params: { ref: 'invalid-ref' } + context "when ref does not exist" do + it "returns empty" do + get api("/projects/#{project.id}/pipelines", user), params: {ref: "invalid-ref"} expect(response).to have_gitlab_http_status(:ok) expect(response).to include_pagination_headers @@ -152,22 +152,22 @@ describe API::Pipelines do end end - context 'when name is specified' do + context "when name is specified" do let!(:pipeline) { create(:ci_pipeline, project: project, user: user) } - context 'when name exists' do - it 'returns matched pipelines' do - get api("/projects/#{project.id}/pipelines", user), params: { name: user.name } + context "when name exists" do + it "returns matched pipelines" do + get api("/projects/#{project.id}/pipelines", user), params: {name: user.name} expect(response).to have_gitlab_http_status(:ok) expect(response).to include_pagination_headers - expect(json_response.first['id']).to eq(pipeline.id) + expect(json_response.first["id"]).to eq(pipeline.id) end end - context 'when name does not exist' do - it 'returns empty' do - get api("/projects/#{project.id}/pipelines", user), params: { name: 'invalid-name' } + context "when name does not exist" do + it "returns empty" do + get api("/projects/#{project.id}/pipelines", user), params: {name: "invalid-name"} expect(response).to have_gitlab_http_status(:ok) expect(response).to include_pagination_headers @@ -176,22 +176,22 @@ describe API::Pipelines do end end - context 'when username is specified' do + context "when username is specified" do let!(:pipeline) { create(:ci_pipeline, project: project, user: user) } - context 'when username exists' do - it 'returns matched pipelines' do - get api("/projects/#{project.id}/pipelines", user), params: { username: user.username } + context "when username exists" do + it "returns matched pipelines" do + get api("/projects/#{project.id}/pipelines", user), params: {username: user.username} expect(response).to have_gitlab_http_status(:ok) expect(response).to include_pagination_headers - expect(json_response.first['id']).to eq(pipeline.id) + expect(json_response.first["id"]).to eq(pipeline.id) end end - context 'when username does not exist' do - it 'returns empty' do - get api("/projects/#{project.id}/pipelines", user), params: { username: 'invalid-username' } + context "when username does not exist" do + it "returns empty" do + get api("/projects/#{project.id}/pipelines", user), params: {username: "invalid-username"} expect(response).to have_gitlab_http_status(:ok) expect(response).to include_pagination_headers @@ -200,72 +200,72 @@ describe API::Pipelines do end end - context 'when yaml_errors is specified' do - let!(:pipeline1) { create(:ci_pipeline, project: project, yaml_errors: 'Syntax error') } + context "when yaml_errors is specified" do + let!(:pipeline1) { create(:ci_pipeline, project: project, yaml_errors: "Syntax error") } let!(:pipeline2) { create(:ci_pipeline, project: project) } - context 'when yaml_errors is true' do - it 'returns matched pipelines' do - get api("/projects/#{project.id}/pipelines", user), params: { yaml_errors: true } + context "when yaml_errors is true" do + it "returns matched pipelines" do + get api("/projects/#{project.id}/pipelines", user), params: {yaml_errors: true} expect(response).to have_gitlab_http_status(:ok) expect(response).to include_pagination_headers - expect(json_response.first['id']).to eq(pipeline1.id) + expect(json_response.first["id"]).to eq(pipeline1.id) end end - context 'when yaml_errors is false' do - it 'returns matched pipelines' do - get api("/projects/#{project.id}/pipelines", user), params: { yaml_errors: false } + context "when yaml_errors is false" do + it "returns matched pipelines" do + get api("/projects/#{project.id}/pipelines", user), params: {yaml_errors: false} expect(response).to have_gitlab_http_status(:ok) expect(response).to include_pagination_headers - expect(json_response.first['id']).to eq(pipeline2.id) + expect(json_response.first["id"]).to eq(pipeline2.id) end end - context 'when yaml_errors is invalid' do - it 'returns bad_request' do - get api("/projects/#{project.id}/pipelines", user), params: { yaml_errors: 'invalid-yaml_errors' } + context "when yaml_errors is invalid" do + it "returns bad_request" do + get api("/projects/#{project.id}/pipelines", user), params: {yaml_errors: "invalid-yaml_errors"} expect(response).to have_gitlab_http_status(:bad_request) end end end - context 'when order_by and sort are specified' do - context 'when order_by user_id' do + context "when order_by and sort are specified" do + context "when order_by user_id" do before do 3.times do create(:ci_pipeline, project: project, user: create(:user)) end end - context 'when sort parameter is valid' do - it 'sorts as user_id: :desc' do - get api("/projects/#{project.id}/pipelines", user), params: { order_by: 'user_id', sort: 'desc' } + context "when sort parameter is valid" do + it "sorts as user_id: :desc" do + get api("/projects/#{project.id}/pipelines", user), params: {order_by: "user_id", sort: "desc"} expect(response).to have_gitlab_http_status(:ok) expect(response).to include_pagination_headers expect(json_response).not_to be_empty pipeline_ids = Ci::Pipeline.all.order(user_id: :desc).pluck(:id) - expect(json_response.map { |r| r['id'] }).to eq(pipeline_ids) + expect(json_response.map { |r| r["id"] }).to eq(pipeline_ids) end end - context 'when sort parameter is invalid' do - it 'returns bad_request' do - get api("/projects/#{project.id}/pipelines", user), params: { order_by: 'user_id', sort: 'invalid_sort' } + context "when sort parameter is invalid" do + it "returns bad_request" do + get api("/projects/#{project.id}/pipelines", user), params: {order_by: "user_id", sort: "invalid_sort"} expect(response).to have_gitlab_http_status(:bad_request) end end end - context 'when order_by is invalid' do - it 'returns bad_request' do - get api("/projects/#{project.id}/pipelines", user), params: { order_by: 'lock_version', sort: 'asc' } + context "when order_by is invalid" do + it "returns bad_request" do + get api("/projects/#{project.id}/pipelines", user), params: {order_by: "lock_version", sort: "asc"} expect(response).to have_gitlab_http_status(:bad_request) end @@ -274,152 +274,152 @@ describe API::Pipelines do end end - context 'unauthorized user' do - it 'does not return project pipelines' do + context "unauthorized user" do + it "does not return project pipelines" do get api("/projects/#{project.id}/pipelines", non_member) expect(response).to have_gitlab_http_status(404) - expect(json_response['message']).to eq '404 Project Not Found' + expect(json_response["message"]).to eq "404 Project Not Found" expect(json_response).not_to be_an Array end end end - describe 'POST /projects/:id/pipeline ' do + describe "POST /projects/:id/pipeline " do def expect_variables(variables, expected_variables) variables.each_with_index do |variable, index| expected_variable = expected_variables[index] - expect(variable.key).to eq(expected_variable['key']) - expect(variable.value).to eq(expected_variable['value']) + expect(variable.key).to eq(expected_variable["key"]) + expect(variable.value).to eq(expected_variable["value"]) end end - context 'authorized user' do - context 'with gitlab-ci.yml' do + context "authorized user" do + context "with gitlab-ci.yml" do before do stub_ci_pipeline_to_return_yaml_file end - it 'creates and returns a new pipeline' do - expect do - post api("/projects/#{project.id}/pipeline", user), params: { ref: project.default_branch } - end.to change { project.ci_pipelines.count }.by(1) + it "creates and returns a new pipeline" do + expect { + post api("/projects/#{project.id}/pipeline", user), params: {ref: project.default_branch} + }.to change { project.ci_pipelines.count }.by(1) expect(response).to have_gitlab_http_status(201) expect(json_response).to be_a Hash - expect(json_response['sha']).to eq project.commit.id + expect(json_response["sha"]).to eq project.commit.id end - context 'variables given' do - let(:variables) { [{ 'key' => 'UPLOAD_TO_S3', 'value' => 'true' }] } + context "variables given" do + let(:variables) { [{"key" => "UPLOAD_TO_S3", "value" => "true"}] } - it 'creates and returns a new pipeline using the given variables' do - expect do - post api("/projects/#{project.id}/pipeline", user), params: { ref: project.default_branch, variables: variables } - end.to change { project.ci_pipelines.count }.by(1) + it "creates and returns a new pipeline using the given variables" do + expect { + post api("/projects/#{project.id}/pipeline", user), params: {ref: project.default_branch, variables: variables} + }.to change { project.ci_pipelines.count }.by(1) expect_variables(project.ci_pipelines.last.variables, variables) expect(response).to have_gitlab_http_status(201) expect(json_response).to be_a Hash - expect(json_response['sha']).to eq project.commit.id - expect(json_response).not_to have_key('variables') + expect(json_response["sha"]).to eq project.commit.id + expect(json_response).not_to have_key("variables") end end - describe 'using variables conditions' do - let(:variables) { [{ 'key' => 'STAGING', 'value' => 'true' }] } + describe "using variables conditions" do + let(:variables) { [{"key" => "STAGING", "value" => "true"}] } before do - config = YAML.dump(test: { script: 'test', only: { variables: ['$STAGING'] } }) + config = YAML.dump(test: {script: "test", only: {variables: ["$STAGING"]}}) stub_ci_pipeline_yaml_file(config) end - it 'creates and returns a new pipeline using the given variables' do - expect do - post api("/projects/#{project.id}/pipeline", user), params: { ref: project.default_branch, variables: variables } - end.to change { project.ci_pipelines.count }.by(1) + it "creates and returns a new pipeline using the given variables" do + expect { + post api("/projects/#{project.id}/pipeline", user), params: {ref: project.default_branch, variables: variables} + }.to change { project.ci_pipelines.count }.by(1) expect_variables(project.ci_pipelines.last.variables, variables) expect(response).to have_gitlab_http_status(201) expect(json_response).to be_a Hash - expect(json_response['sha']).to eq project.commit.id - expect(json_response).not_to have_key('variables') + expect(json_response["sha"]).to eq project.commit.id + expect(json_response).not_to have_key("variables") end - context 'condition unmatch' do - let(:variables) { [{ 'key' => 'STAGING', 'value' => 'false' }] } + context "condition unmatch" do + let(:variables) { [{"key" => "STAGING", "value" => "false"}] } it "doesn't create a job" do - expect do - post api("/projects/#{project.id}/pipeline", user), params: { ref: project.default_branch } - end.not_to change { project.ci_pipelines.count } + expect { + post api("/projects/#{project.id}/pipeline", user), params: {ref: project.default_branch} + }.not_to change { project.ci_pipelines.count } expect(response).to have_gitlab_http_status(400) end end end - it 'fails when using an invalid ref' do - post api("/projects/#{project.id}/pipeline", user), params: { ref: 'invalid_ref' } + it "fails when using an invalid ref" do + post api("/projects/#{project.id}/pipeline", user), params: {ref: "invalid_ref"} expect(response).to have_gitlab_http_status(400) - expect(json_response['message']['base'].first).to eq 'Reference not found' + expect(json_response["message"]["base"].first).to eq "Reference not found" expect(json_response).not_to be_an Array end end - context 'without gitlab-ci.yml' do - context 'without auto devops enabled' do + context "without gitlab-ci.yml" do + context "without auto devops enabled" do before do - project.update!(auto_devops_attributes: { enabled: false }) + project.update!(auto_devops_attributes: {enabled: false}) end - it 'fails to create pipeline' do - post api("/projects/#{project.id}/pipeline", user), params: { ref: project.default_branch } + it "fails to create pipeline" do + post api("/projects/#{project.id}/pipeline", user), params: {ref: project.default_branch} expect(response).to have_gitlab_http_status(400) - expect(json_response['message']['base'].first).to eq 'Missing .gitlab-ci.yml file' + expect(json_response["message"]["base"].first).to eq "Missing .gitlab-ci.yml file" expect(json_response).not_to be_an Array end end end end - context 'unauthorized user' do - it 'does not create pipeline' do - post api("/projects/#{project.id}/pipeline", non_member), params: { ref: project.default_branch } + context "unauthorized user" do + it "does not create pipeline" do + post api("/projects/#{project.id}/pipeline", non_member), params: {ref: project.default_branch} expect(response).to have_gitlab_http_status(404) - expect(json_response['message']).to eq '404 Project Not Found' + expect(json_response["message"]).to eq "404 Project Not Found" expect(json_response).not_to be_an Array end end end - describe 'GET /projects/:id/pipelines/:pipeline_id' do - context 'authorized user' do - it 'returns project pipelines' do + describe "GET /projects/:id/pipelines/:pipeline_id" do + context "authorized user" do + it "returns project pipelines" do get api("/projects/#{project.id}/pipelines/#{pipeline.id}", user) expect(response).to have_gitlab_http_status(200) - expect(json_response['sha']).to match /\A\h{40}\z/ + expect(json_response["sha"]).to match /\A\h{40}\z/ end - it 'returns 404 when it does not exist' do + it "returns 404 when it does not exist" do get api("/projects/#{project.id}/pipelines/123456", user) expect(response).to have_gitlab_http_status(404) - expect(json_response['message']).to eq '404 Not found' - expect(json_response['id']).to be nil + expect(json_response["message"]).to eq "404 Not found" + expect(json_response["id"]).to be nil end - context 'with coverage' do + context "with coverage" do before do create(:ci_build, coverage: 30, pipeline: pipeline) end - it 'exposes the coverage' do + it "exposes the coverage" do get api("/projects/#{project.id}/pipelines/#{pipeline.id}", user) expect(json_response["coverage"].to_i).to eq(30) @@ -427,43 +427,43 @@ describe API::Pipelines do end end - context 'unauthorized user' do - it 'should not return a project pipeline' do + context "unauthorized user" do + it "should not return a project pipeline" do get api("/projects/#{project.id}/pipelines/#{pipeline.id}", non_member) expect(response).to have_gitlab_http_status(404) - expect(json_response['message']).to eq '404 Project Not Found' - expect(json_response['id']).to be nil + expect(json_response["message"]).to eq "404 Project Not Found" + expect(json_response["id"]).to be nil end end end - describe 'DELETE /projects/:id/pipelines/:pipeline_id' do - context 'authorized user' do + describe "DELETE /projects/:id/pipelines/:pipeline_id" do + context "authorized user" do let(:owner) { project.owner } - it 'destroys the pipeline' do + it "destroys the pipeline" do delete api("/projects/#{project.id}/pipelines/#{pipeline.id}", owner) expect(response).to have_gitlab_http_status(204) expect { pipeline.reload }.to raise_error(ActiveRecord::RecordNotFound) end - it 'returns 404 when it does not exist' do + it "returns 404 when it does not exist" do delete api("/projects/#{project.id}/pipelines/123456", owner) expect(response).to have_gitlab_http_status(404) - expect(json_response['message']).to eq '404 Not found' + expect(json_response["message"]).to eq "404 Not found" end - it 'does not log an audit event' do + it "does not log an audit event" do expect { delete api("/projects/#{project.id}/pipelines/#{pipeline.id}", owner) }.not_to change { SecurityEvent.count } end - context 'when the pipeline has jobs' do + context "when the pipeline has jobs" do let!(:build) { create(:ci_build, project: project, pipeline: pipeline) } - it 'destroys associated jobs' do + it "destroys associated jobs" do delete api("/projects/#{project.id}/pipelines/#{pipeline.id}", owner) expect(response).to have_gitlab_http_status(204) @@ -472,35 +472,35 @@ describe API::Pipelines do end end - context 'unauthorized user' do - context 'when user is not member' do - it 'should return a 404' do + context "unauthorized user" do + context "when user is not member" do + it "should return a 404" do delete api("/projects/#{project.id}/pipelines/#{pipeline.id}", non_member) expect(response).to have_gitlab_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 - context 'when user is developer' do + context "when user is developer" do let(:developer) { create(:user) } before do project.add_developer(developer) end - it 'should return a 403' do + it "should return a 403" do delete api("/projects/#{project.id}/pipelines/#{pipeline.id}", developer) expect(response).to have_gitlab_http_status(403) - expect(json_response['message']).to eq '403 Forbidden' + expect(json_response["message"]).to eq "403 Forbidden" end end end end - describe 'POST /projects/:id/pipelines/:pipeline_id/retry' do - context 'authorized user' do + describe "POST /projects/:id/pipelines/:pipeline_id/retry" do + context "authorized user" do let!(:pipeline) do create(:ci_pipeline, project: project, sha: project.commit.id, ref: project.default_branch) @@ -508,28 +508,28 @@ describe API::Pipelines do let!(:build) { create(:ci_build, :failed, pipeline: pipeline) } - it 'retries failed builds' do - expect do + it "retries failed builds" do + expect { post api("/projects/#{project.id}/pipelines/#{pipeline.id}/retry", user) - end.to change { pipeline.builds.count }.from(1).to(2) + }.to change { pipeline.builds.count }.from(1).to(2) expect(response).to have_gitlab_http_status(201) expect(build.reload.retried?).to be true end end - context 'unauthorized user' do - it 'should not return a project pipeline' do + context "unauthorized user" do + it "should not return a project pipeline" do post api("/projects/#{project.id}/pipelines/#{pipeline.id}/retry", non_member) expect(response).to have_gitlab_http_status(404) - expect(json_response['message']).to eq '404 Project Not Found' - expect(json_response['id']).to be nil + expect(json_response["message"]).to eq "404 Project Not Found" + expect(json_response["id"]).to be nil end end end - describe 'POST /projects/:id/pipelines/:pipeline_id/cancel' do + describe "POST /projects/:id/pipelines/:pipeline_id/cancel" do let!(:pipeline) do create(:ci_empty_pipeline, project: project, sha: project.commit.id, ref: project.default_branch) @@ -537,27 +537,27 @@ describe API::Pipelines do let!(:build) { create(:ci_build, :running, pipeline: pipeline) } - context 'authorized user' do - it 'retries failed builds' do + context "authorized user" do + it "retries failed builds" do post api("/projects/#{project.id}/pipelines/#{pipeline.id}/cancel", user) expect(response).to have_gitlab_http_status(200) - expect(json_response['status']).to eq('canceled') + expect(json_response["status"]).to eq("canceled") end end - context 'user without proper access rights' do + context "user without proper access rights" do let!(:reporter) { create(:user) } before do project.add_reporter(reporter) end - it 'rejects the action' do + it "rejects the action" do post api("/projects/#{project.id}/pipelines/#{pipeline.id}/cancel", reporter) expect(response).to have_gitlab_http_status(403) - expect(pipeline.reload.status).to eq('pending') + expect(pipeline.reload.status).to eq("pending") end end end diff --git a/spec/requests/api/project_clusters_spec.rb b/spec/requests/api/project_clusters_spec.rb index 9bab1f95150..83578eb13cf 100644 --- a/spec/requests/api/project_clusters_spec.rb +++ b/spec/requests/api/project_clusters_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'spec_helper' +require "spec_helper" describe API::ProjectClusters do include KubernetesHelpers @@ -13,37 +13,37 @@ describe API::ProjectClusters do project.add_maintainer(current_user) end - describe 'GET /projects/:id/clusters' do + describe "GET /projects/:id/clusters" do let!(:extra_cluster) { create(:cluster, :provided_by_gcp, :project) } let!(:clusters) do create_list(:cluster, 5, :provided_by_gcp, :project, :production_environment, - projects: [project]) + projects: [project]) end - context 'non-authorized user' do - it 'should respond with 404' do + context "non-authorized user" do + it "should respond with 404" do get api("/projects/#{project.id}/clusters", non_member) expect(response).to have_gitlab_http_status(404) end end - context 'authorized user' do + context "authorized user" do before do get api("/projects/#{project.id}/clusters", current_user) end - it 'should respond with 200' do + it "should respond with 200" do expect(response).to have_gitlab_http_status(200) end - it 'should include pagination headers' do + it "should include pagination headers" do expect(response).to include_pagination_headers end - it 'should only include authorized clusters' do - cluster_ids = json_response.map { |cluster| cluster['id'] } + it "should only include authorized clusters" do + cluster_ids = json_response.map { |cluster| cluster["id"] } expect(cluster_ids).to match_array(clusters.pluck(:id)) expect(cluster_ids).not_to include(extra_cluster.id) @@ -51,102 +51,102 @@ describe API::ProjectClusters do end end - describe 'GET /projects/:id/clusters/:cluster_id' do + describe "GET /projects/:id/clusters/:cluster_id" do let(:cluster_id) { cluster.id } let(:platform_kubernetes) do create(:cluster_platform_kubernetes, :configured, - namespace: 'project-namespace') + namespace: "project-namespace") end let(:cluster) do create(:cluster, :project, :provided_by_gcp, - platform_kubernetes: platform_kubernetes, - user: current_user, - projects: [project]) + platform_kubernetes: platform_kubernetes, + user: current_user, + projects: [project]) end - context 'non-authorized user' do - it 'should respond with 404' do + context "non-authorized user" do + it "should respond with 404" do get api("/projects/#{project.id}/clusters/#{cluster_id}", non_member) expect(response).to have_gitlab_http_status(404) end end - context 'authorized user' do + context "authorized user" do before do get api("/projects/#{project.id}/clusters/#{cluster_id}", current_user) end - it 'returns specific cluster' do - expect(json_response['id']).to eq(cluster.id) + it "returns specific cluster" do + expect(json_response["id"]).to eq(cluster.id) end - it 'returns cluster information' do - expect(json_response['provider_type']).to eq('gcp') - expect(json_response['platform_type']).to eq('kubernetes') - expect(json_response['environment_scope']).to eq('*') - expect(json_response['cluster_type']).to eq('project_type') + it "returns cluster information" do + expect(json_response["provider_type"]).to eq("gcp") + expect(json_response["platform_type"]).to eq("kubernetes") + expect(json_response["environment_scope"]).to eq("*") + expect(json_response["cluster_type"]).to eq("project_type") end - it 'returns project information' do - cluster_project = json_response['project'] + it "returns project information" do + cluster_project = json_response["project"] - expect(cluster_project['id']).to eq(project.id) - expect(cluster_project['name']).to eq(project.name) - expect(cluster_project['path']).to eq(project.path) + expect(cluster_project["id"]).to eq(project.id) + expect(cluster_project["name"]).to eq(project.name) + expect(cluster_project["path"]).to eq(project.path) end - it 'returns kubernetes platform information' do - platform = json_response['platform_kubernetes'] + it "returns kubernetes platform information" do + platform = json_response["platform_kubernetes"] - expect(platform['api_url']).to eq('https://kubernetes.example.com') - expect(platform['namespace']).to eq('project-namespace') - expect(platform['ca_cert']).to be_present + expect(platform["api_url"]).to eq("https://kubernetes.example.com") + expect(platform["namespace"]).to eq("project-namespace") + expect(platform["ca_cert"]).to be_present end - it 'returns user information' do - user = json_response['user'] + it "returns user information" do + user = json_response["user"] - expect(user['id']).to eq(current_user.id) - expect(user['username']).to eq(current_user.username) + expect(user["id"]).to eq(current_user.id) + expect(user["username"]).to eq(current_user.username) end - it 'returns GCP provider information' do - gcp_provider = json_response['provider_gcp'] + it "returns GCP provider information" do + gcp_provider = json_response["provider_gcp"] - expect(gcp_provider['cluster_id']).to eq(cluster.id) - expect(gcp_provider['status_name']).to eq('created') - expect(gcp_provider['gcp_project_id']).to eq('test-gcp-project') - expect(gcp_provider['zone']).to eq('us-central1-a') - expect(gcp_provider['machine_type']).to eq('n1-standard-2') - expect(gcp_provider['num_nodes']).to eq(3) - expect(gcp_provider['endpoint']).to eq('111.111.111.111') + expect(gcp_provider["cluster_id"]).to eq(cluster.id) + expect(gcp_provider["status_name"]).to eq("created") + expect(gcp_provider["gcp_project_id"]).to eq("test-gcp-project") + expect(gcp_provider["zone"]).to eq("us-central1-a") + expect(gcp_provider["machine_type"]).to eq("n1-standard-2") + expect(gcp_provider["num_nodes"]).to eq(3) + expect(gcp_provider["endpoint"]).to eq("111.111.111.111") end - context 'when cluster has no provider' do + context "when cluster has no provider" do let(:cluster) do create(:cluster, :project, :provided_by_user, - projects: [project]) + projects: [project]) end - it 'should not include GCP provider info' do - expect(json_response['provider_gcp']).not_to be_present + it "should not include GCP provider info" do + expect(json_response["provider_gcp"]).not_to be_present end end - context 'with non-existing cluster' do + context "with non-existing cluster" do let(:cluster_id) { 123 } - it 'returns 404' do + it "returns 404" do expect(response).to have_gitlab_http_status(404) end end end end - shared_context 'kubernetes calls stubbed' do + shared_context "kubernetes calls stubbed" do before do stub_kubeclient_discover(api_url) stub_kubeclient_get_namespace(api_url, namespace: namespace) @@ -157,8 +157,8 @@ describe API::ProjectClusters do api_url, { metadata_name: "#{namespace}-token", - token: Base64.encode64('sample-token'), - namespace: namespace + token: Base64.encode64("sample-token"), + namespace: namespace, } ) @@ -168,297 +168,297 @@ describe API::ProjectClusters do end end - describe 'POST /projects/:id/clusters/user' do - include_context 'kubernetes calls stubbed' + describe "POST /projects/:id/clusters/user" do + include_context "kubernetes calls stubbed" - let(:api_url) { 'https://kubernetes.example.com' } + let(:api_url) { "https://kubernetes.example.com" } let(:namespace) { project.path } - let(:authorization_type) { 'rbac' } + let(:authorization_type) { "rbac" } let(:platform_kubernetes_attributes) do { api_url: api_url, - token: 'sample-token', + token: "sample-token", namespace: namespace, - authorization_type: authorization_type + authorization_type: authorization_type, } end let(:cluster_params) do { - name: 'test-cluster', - platform_kubernetes_attributes: platform_kubernetes_attributes + name: "test-cluster", + platform_kubernetes_attributes: platform_kubernetes_attributes, } end - context 'non-authorized user' do - it 'should respond with 404' do + context "non-authorized user" do + it "should respond with 404" do post api("/projects/#{project.id}/clusters/user", non_member), params: cluster_params expect(response).to have_gitlab_http_status(404) end end - context 'authorized user' do + context "authorized user" do before do post api("/projects/#{project.id}/clusters/user", current_user), params: cluster_params end - context 'with valid params' do - it 'should respond with 201' do + context "with valid params" do + it "should respond with 201" do expect(response).to have_gitlab_http_status(201) end - it 'should create a new Cluster::Cluster' do + it "should create a new Cluster::Cluster" do cluster_result = Clusters::Cluster.find(json_response["id"]) platform_kubernetes = cluster_result.platform expect(cluster_result).to be_user expect(cluster_result).to be_kubernetes expect(cluster_result.project).to eq(project) - expect(cluster_result.name).to eq('test-cluster') + expect(cluster_result.name).to eq("test-cluster") expect(platform_kubernetes.rbac?).to be_truthy expect(platform_kubernetes.api_url).to eq(api_url) expect(platform_kubernetes.namespace).to eq(namespace) - expect(platform_kubernetes.token).to eq('sample-token') + expect(platform_kubernetes.token).to eq("sample-token") end end - context 'when user does not indicate authorization type' do + context "when user does not indicate authorization type" do let(:platform_kubernetes_attributes) do { api_url: api_url, - token: 'sample-token', - namespace: namespace + token: "sample-token", + namespace: namespace, } end - it 'defaults to RBAC' do - cluster_result = Clusters::Cluster.find(json_response['id']) + it "defaults to RBAC" do + cluster_result = Clusters::Cluster.find(json_response["id"]) expect(cluster_result.platform_kubernetes.rbac?).to be_truthy end end - context 'when user sets authorization type as ABAC' do - let(:authorization_type) { 'abac' } + context "when user sets authorization type as ABAC" do + let(:authorization_type) { "abac" } - it 'should create an ABAC cluster' do - cluster_result = Clusters::Cluster.find(json_response['id']) + it "should create an ABAC cluster" do + cluster_result = Clusters::Cluster.find(json_response["id"]) expect(cluster_result.platform.abac?).to be_truthy end end - context 'with invalid params' do - let(:namespace) { 'invalid_namespace' } + context "with invalid params" do + let(:namespace) { "invalid_namespace" } - it 'should respond with 400' do + it "should respond with 400" do expect(response).to have_gitlab_http_status(400) end - it 'should not create a new Clusters::Cluster' do + it "should not create a new Clusters::Cluster" do expect(project.reload.clusters).to be_empty end - it 'should return validation errors' do - expect(json_response['message']['platform_kubernetes.namespace'].first).to be_present + it "should return validation errors" do + expect(json_response["message"]["platform_kubernetes.namespace"].first).to be_present end end end - context 'when user tries to add multiple clusters' do + context "when user tries to add multiple clusters" do before do create(:cluster, :provided_by_gcp, :project, - projects: [project]) + projects: [project]) post api("/projects/#{project.id}/clusters/user", current_user), params: cluster_params end - it 'should respond with 403' do + it "should respond with 403" do expect(response).to have_gitlab_http_status(403) end - it 'should return an appropriate message' do - expect(json_response['message']).to include('Instance does not support multiple Kubernetes clusters') + it "should return an appropriate message" do + expect(json_response["message"]).to include("Instance does not support multiple Kubernetes clusters") end end end - describe 'PUT /projects/:id/clusters/:cluster_id' do - include_context 'kubernetes calls stubbed' + describe "PUT /projects/:id/clusters/:cluster_id" do + include_context "kubernetes calls stubbed" - let(:api_url) { 'https://kubernetes.example.com' } - let(:namespace) { 'new-namespace' } - let(:platform_kubernetes_attributes) { { namespace: namespace } } + let(:api_url) { "https://kubernetes.example.com" } + let(:namespace) { "new-namespace" } + let(:platform_kubernetes_attributes) { {namespace: namespace} } let(:update_params) do { - platform_kubernetes_attributes: platform_kubernetes_attributes + platform_kubernetes_attributes: platform_kubernetes_attributes, } end let!(:kubernetes_namespace) do create(:cluster_kubernetes_namespace, - cluster: cluster, - project: project) + cluster: cluster, + project: project) end let(:cluster) do create(:cluster, :project, :provided_by_gcp, - projects: [project]) + projects: [project]) end - context 'non-authorized user' do - it 'should respond with 404' do + context "non-authorized user" do + it "should respond with 404" do put api("/projects/#{project.id}/clusters/#{cluster.id}", non_member), params: update_params expect(response).to have_gitlab_http_status(404) end end - context 'authorized user' do + context "authorized user" do before do put api("/projects/#{project.id}/clusters/#{cluster.id}", current_user), params: update_params cluster.reload end - context 'with valid params' do - it 'should respond with 200' do + context "with valid params" do + it "should respond with 200" do expect(response).to have_gitlab_http_status(200) end - it 'should update cluster attributes' do - expect(cluster.platform_kubernetes.namespace).to eq('new-namespace') - expect(cluster.kubernetes_namespace.namespace).to eq('new-namespace') + it "should update cluster attributes" do + expect(cluster.platform_kubernetes.namespace).to eq("new-namespace") + expect(cluster.kubernetes_namespace.namespace).to eq("new-namespace") end end - context 'with invalid params' do - let(:namespace) { 'invalid_namespace' } + context "with invalid params" do + let(:namespace) { "invalid_namespace" } - it 'should respond with 400' do + it "should respond with 400" do expect(response).to have_gitlab_http_status(400) end - it 'should not update cluster attributes' do - expect(cluster.platform_kubernetes.namespace).not_to eq('invalid_namespace') - expect(cluster.kubernetes_namespace.namespace).not_to eq('invalid_namespace') + it "should not update cluster attributes" do + expect(cluster.platform_kubernetes.namespace).not_to eq("invalid_namespace") + expect(cluster.kubernetes_namespace.namespace).not_to eq("invalid_namespace") end - it 'should return validation errors' do - expect(json_response['message']['platform_kubernetes.namespace'].first).to match('can contain only lowercase letters') + it "should return validation errors" do + expect(json_response["message"]["platform_kubernetes.namespace"].first).to match("can contain only lowercase letters") end end - context 'with a GCP cluster' do - context 'when user tries to change GCP specific fields' do + context "with a GCP cluster" do + context "when user tries to change GCP specific fields" do let(:platform_kubernetes_attributes) do { - api_url: 'https://new-api-url.com', - token: 'new-sample-token' + api_url: "https://new-api-url.com", + token: "new-sample-token", } end - it 'should respond with 400' do + it "should respond with 400" do expect(response).to have_gitlab_http_status(400) end - it 'should return validation error' do - expect(json_response['message']['platform_kubernetes.base'].first).to eq('Cannot modify managed Kubernetes cluster') + it "should return validation error" do + expect(json_response["message"]["platform_kubernetes.base"].first).to eq("Cannot modify managed Kubernetes cluster") end end - context 'when user tries to change namespace' do - let(:namespace) { 'new-namespace' } + context "when user tries to change namespace" do + let(:namespace) { "new-namespace" } - it 'should respond with 200' do + it "should respond with 200" do expect(response).to have_gitlab_http_status(200) end end end - context 'with an user cluster' do - let(:api_url) { 'https://new-api-url.com' } + context "with an user cluster" do + let(:api_url) { "https://new-api-url.com" } let(:cluster) do create(:cluster, :project, :provided_by_user, - projects: [project]) + projects: [project]) end let(:platform_kubernetes_attributes) do { api_url: api_url, - namespace: 'new-namespace', - token: 'new-sample-token' + namespace: "new-namespace", + token: "new-sample-token", } end let(:update_params) do { - name: 'new-name', - platform_kubernetes_attributes: platform_kubernetes_attributes + name: "new-name", + platform_kubernetes_attributes: platform_kubernetes_attributes, } end - it 'should respond with 200' do + it "should respond with 200" do expect(response).to have_gitlab_http_status(200) end - it 'should update platform kubernetes attributes' do + it "should update platform kubernetes attributes" do platform_kubernetes = cluster.platform_kubernetes - expect(cluster.name).to eq('new-name') - expect(platform_kubernetes.namespace).to eq('new-namespace') - expect(platform_kubernetes.api_url).to eq('https://new-api-url.com') - expect(platform_kubernetes.token).to eq('new-sample-token') + expect(cluster.name).to eq("new-name") + expect(platform_kubernetes.namespace).to eq("new-namespace") + expect(platform_kubernetes.api_url).to eq("https://new-api-url.com") + expect(platform_kubernetes.token).to eq("new-sample-token") end end - context 'with a cluster that does not belong to user' do + context "with a cluster that does not belong to user" do let(:cluster) { create(:cluster, :project, :provided_by_user) } - it 'should respond with 404' do + it "should respond with 404" do expect(response).to have_gitlab_http_status(404) end end end end - describe 'DELETE /projects/:id/clusters/:cluster_id' do - let(:cluster_params) { { cluster_id: cluster.id } } + describe "DELETE /projects/:id/clusters/:cluster_id" do + let(:cluster_params) { {cluster_id: cluster.id} } let(:cluster) do create(:cluster, :project, :provided_by_gcp, - projects: [project]) + projects: [project]) end - context 'non-authorized user' do - it 'should respond with 404' do + context "non-authorized user" do + it "should respond with 404" do delete api("/projects/#{project.id}/clusters/#{cluster.id}", non_member), params: cluster_params expect(response).to have_gitlab_http_status(404) end end - context 'authorized user' do + context "authorized user" do before do delete api("/projects/#{project.id}/clusters/#{cluster.id}", current_user), params: cluster_params end - it 'should respond with 204' do + it "should respond with 204" do expect(response).to have_gitlab_http_status(204) end - it 'should delete the cluster' do + it "should delete the cluster" do expect(Clusters::Cluster.exists?(id: cluster.id)).to be_falsy end - context 'with a cluster that does not belong to user' do + context "with a cluster that does not belong to user" do let(:cluster) { create(:cluster, :project, :provided_by_user) } - it 'should respond with 404' do + it "should respond with 404" do expect(response).to have_gitlab_http_status(404) end end diff --git a/spec/requests/api/project_export_spec.rb b/spec/requests/api/project_export_spec.rb index 1d2f81a397d..4356cd20b44 100644 --- a/spec/requests/api/project_export_spec.rb +++ b/spec/requests/api/project_export_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe API::ProjectExport do set(:project) { create(:project) } @@ -27,7 +27,7 @@ describe API::ProjectExport do allow_any_instance_of(Gitlab::ImportExport).to receive(:storage_path).and_return(export_path) # simulate exporting work directory - FileUtils.mkdir_p File.join(project_started.export_path, 'securerandom-hex') + FileUtils.mkdir_p File.join(project_started.export_path, "securerandom-hex") # simulate in after export action FileUtils.touch Gitlab::ImportExport::AfterExportStrategies::BaseAfterExportStrategy.lock_file_path(project_after_export) @@ -37,73 +37,73 @@ describe API::ProjectExport do FileUtils.rm_rf(export_path, secure: true) end - shared_examples_for 'when project export is disabled' do + shared_examples_for "when project export is disabled" do before do stub_application_setting(project_export_enabled?: false) end - it_behaves_like '404 response' + it_behaves_like "404 response" end - describe 'GET /projects/:project_id/export' do - shared_examples_for 'get project export status not found' do - it_behaves_like '404 response' do + describe "GET /projects/:project_id/export" do + shared_examples_for "get project export status not found" do + it_behaves_like "404 response" do let(:request) { get api(path, user) } end end - shared_examples_for 'get project export status denied' do - it_behaves_like '403 response' do + shared_examples_for "get project export status denied" do + it_behaves_like "403 response" do let(:request) { get api(path, user) } end end - shared_examples_for 'get project export status ok' do - it 'is none' do + shared_examples_for "get project export status ok" do + it "is none" do get api(path_none, user) expect(response).to have_gitlab_http_status(200) - expect(response).to match_response_schema('public_api/v4/project/export_status') - expect(json_response['export_status']).to eq('none') + expect(response).to match_response_schema("public_api/v4/project/export_status") + expect(json_response["export_status"]).to eq("none") end - it 'is started' do + it "is started" do get api(path_started, user) expect(response).to have_gitlab_http_status(200) - expect(response).to match_response_schema('public_api/v4/project/export_status') - expect(json_response['export_status']).to eq('started') + expect(response).to match_response_schema("public_api/v4/project/export_status") + expect(json_response["export_status"]).to eq("started") end - it 'is after_export' do + it "is after_export" do get api(path_after_export, user) expect(response).to have_gitlab_http_status(200) - expect(response).to match_response_schema('public_api/v4/project/export_status') - expect(json_response['export_status']).to eq('after_export_action') + expect(response).to match_response_schema("public_api/v4/project/export_status") + expect(json_response["export_status"]).to eq("after_export_action") end - it 'is finished' do + it "is finished" do get api(path_finished, user) expect(response).to have_gitlab_http_status(200) - expect(response).to match_response_schema('public_api/v4/project/export_status') - expect(json_response['export_status']).to eq('finished') + expect(response).to match_response_schema("public_api/v4/project/export_status") + expect(json_response["export_status"]).to eq("finished") end end - it_behaves_like 'when project export is disabled' do + it_behaves_like "when project export is disabled" do let(:request) { get api(path, admin) } end - context 'when project export is enabled' do - context 'when user is an admin' do + context "when project export is enabled" do + context "when user is an admin" do let(:user) { admin } - it_behaves_like 'get project export status ok' + it_behaves_like "get project export status ok" end - context 'when user is a maintainer' do + context "when user is a maintainer" do before do project.add_maintainer(user) project_none.add_maintainer(user) @@ -112,114 +112,114 @@ describe API::ProjectExport do project_after_export.add_maintainer(user) end - it_behaves_like 'get project export status ok' + it_behaves_like "get project export status ok" end - context 'when user is a developer' do + context "when user is a developer" do before do project.add_developer(user) end - it_behaves_like 'get project export status denied' + it_behaves_like "get project export status denied" end - context 'when user is a reporter' do + context "when user is a reporter" do before do project.add_reporter(user) end - it_behaves_like 'get project export status denied' + it_behaves_like "get project export status denied" end - context 'when user is a guest' do + context "when user is a guest" do before do project.add_guest(user) end - it_behaves_like 'get project export status denied' + it_behaves_like "get project export status denied" end - context 'when user is not a member' do - it_behaves_like 'get project export status not found' + context "when user is not a member" do + it_behaves_like "get project export status not found" end end end - describe 'GET /projects/:project_id/export/download' do - shared_examples_for 'get project export download not found' do - it_behaves_like '404 response' do + describe "GET /projects/:project_id/export/download" do + shared_examples_for "get project export download not found" do + it_behaves_like "404 response" do let(:request) { get api(download_path, user) } end end - shared_examples_for 'get project export download denied' do - it_behaves_like '403 response' do + shared_examples_for "get project export download denied" do + it_behaves_like "403 response" do let(:request) { get api(download_path, user) } end end - shared_examples_for 'get project export download' do - it_behaves_like '404 response' do + shared_examples_for "get project export download" do + it_behaves_like "404 response" do let(:request) { get api(download_path_none, user) } end - it_behaves_like '404 response' do + it_behaves_like "404 response" do let(:request) { get api(download_path_started, user) } end - it 'downloads' do + it "downloads" do get api(download_path_finished, user) expect(response).to have_gitlab_http_status(200) end end - shared_examples_for 'get project export upload after action' do - context 'and is uploading' do - it 'downloads' do + shared_examples_for "get project export upload after action" do + context "and is uploading" do + it "downloads" do get api(download_path_export_action, user) expect(response).to have_gitlab_http_status(200) end end - context 'when upload complete' do + context "when upload complete" do before do project_after_export.remove_exports end - it 'has removed the export' do + it "has removed the export" do expect(project_after_export.export_file_exists?).to be_falsey end - it_behaves_like '404 response' do + it_behaves_like "404 response" do let(:request) { get api(download_path_export_action, user) } end end end - shared_examples_for 'get project download by strategy' do - context 'when upload strategy set' do - it_behaves_like 'get project export upload after action' + shared_examples_for "get project download by strategy" do + context "when upload strategy set" do + it_behaves_like "get project export upload after action" end - context 'when download strategy set' do - it_behaves_like 'get project export download' + context "when download strategy set" do + it_behaves_like "get project export download" end end - it_behaves_like 'when project export is disabled' do + it_behaves_like "when project export is disabled" do let(:request) { get api(download_path, admin) } end - context 'when project export is enabled' do - context 'when user is an admin' do + context "when project export is enabled" do + context "when user is an admin" do let(:user) { admin } - it_behaves_like 'get project download by strategy' + it_behaves_like "get project download by strategy" end - context 'when user is a maintainer' do + context "when user is a maintainer" do before do project.add_maintainer(user) project_none.add_maintainer(user) @@ -228,39 +228,39 @@ describe API::ProjectExport do project_after_export.add_maintainer(user) end - it_behaves_like 'get project download by strategy' + it_behaves_like "get project download by strategy" end - context 'when user is a developer' do + context "when user is a developer" do before do project.add_developer(user) end - it_behaves_like 'get project export download denied' + it_behaves_like "get project export download denied" end - context 'when user is a reporter' do + context "when user is a reporter" do before do project.add_reporter(user) end - it_behaves_like 'get project export download denied' + it_behaves_like "get project export download denied" end - context 'when user is a guest' do + context "when user is a guest" do before do project.add_guest(user) end - it_behaves_like 'get project export download denied' + it_behaves_like "get project export download denied" end - context 'when user is not a member' do - it_behaves_like 'get project export download not found' + context "when user is not a member" do + it_behaves_like "get project export download not found" end end - context 'when an uploader is used' do + context "when an uploader is used" do before do stub_uploads_object_storage(ImportExportUploader) @@ -269,46 +269,46 @@ describe API::ProjectExport do project_after_export.add_maintainer(user) upload = ImportExportUpload.new(project: project) - upload.export_file = fixture_file_upload('spec/fixtures/project_export.tar.gz', "`/tar.gz") + upload.export_file = fixture_file_upload("spec/fixtures/project_export.tar.gz", "`/tar.gz") upload.save! end - it_behaves_like 'get project download by strategy' + it_behaves_like "get project download by strategy" end end - describe 'POST /projects/:project_id/export' do - shared_examples_for 'post project export start not found' do - it_behaves_like '404 response' do + describe "POST /projects/:project_id/export" do + shared_examples_for "post project export start not found" do + it_behaves_like "404 response" do let(:request) { post api(path, user) } end end - shared_examples_for 'post project export start denied' do - it_behaves_like '403 response' do + shared_examples_for "post project export start denied" do + it_behaves_like "403 response" do let(:request) { post api(path, user) } end end - shared_examples_for 'post project export start' do - context 'with upload strategy' do - context 'when params invalid' do - it_behaves_like '400 response' do - let(:request) { post(api(path, user), params: { 'upload[url]' => 'whatever' }) } + shared_examples_for "post project export start" do + context "with upload strategy" do + context "when params invalid" do + it_behaves_like "400 response" do + let(:request) { post(api(path, user), params: {"upload[url]" => "whatever"}) } end end - it 'starts' do + it "starts" do allow_any_instance_of(Gitlab::ImportExport::AfterExportStrategies::WebUploadStrategy).to receive(:send_file) - post(api(path, user), params: { 'upload[url]' => 'http://gitlab.com' }) + post(api(path, user), params: {"upload[url]" => "http://gitlab.com"}) expect(response).to have_gitlab_http_status(202) end end - context 'with download strategy' do - it 'starts' do + context "with download strategy" do + it "starts" do expect_any_instance_of(Gitlab::ImportExport::AfterExportStrategies::WebUploadStrategy).not_to receive(:send_file) post api(path, user) @@ -318,18 +318,18 @@ describe API::ProjectExport do end end - it_behaves_like 'when project export is disabled' do + it_behaves_like "when project export is disabled" do let(:request) { post api(path, admin) } end - context 'when project export is enabled' do - context 'when user is an admin' do + context "when project export is enabled" do + context "when user is an admin" do let(:user) { admin } - it_behaves_like 'post project export start' + it_behaves_like "post project export start" end - context 'when user is a maintainer' do + context "when user is a maintainer" do before do project.add_maintainer(user) project_none.add_maintainer(user) @@ -338,40 +338,40 @@ describe API::ProjectExport do project_after_export.add_maintainer(user) end - it_behaves_like 'post project export start' + it_behaves_like "post project export start" end - context 'when user is a developer' do + context "when user is a developer" do before do project.add_developer(user) end - it_behaves_like 'post project export start denied' + it_behaves_like "post project export start denied" end - context 'when user is a reporter' do + context "when user is a reporter" do before do project.add_reporter(user) end - it_behaves_like 'post project export start denied' + it_behaves_like "post project export start denied" end - context 'when user is a guest' do + context "when user is a guest" do before do project.add_guest(user) end - it_behaves_like 'post project export start denied' + it_behaves_like "post project export start denied" end - context 'when user is not a member' do - it_behaves_like 'post project export start not found' + context "when user is not a member" do + it_behaves_like "post project export start not found" end - context 'when overriding description' do - it 'starts' do - params = { description: "Foo" } + context "when overriding description" do + it "starts" do + params = {description: "Foo"} expect_any_instance_of(Projects::ImportExport::ExportService).to receive(:execute) post api(path, project.owner), params: params diff --git a/spec/requests/api/project_hooks_spec.rb b/spec/requests/api/project_hooks_spec.rb index b88a8b95201..51a64195e52 100644 --- a/spec/requests/api/project_hooks_spec.rb +++ b/spec/requests/api/project_hooks_spec.rb @@ -1,16 +1,16 @@ -require 'spec_helper' +require "spec_helper" -describe API::ProjectHooks, 'ProjectHooks' do +describe API::ProjectHooks, "ProjectHooks" do let(:user) { create(:user) } let(:user3) { create(:user) } let!(:project) { create(:project, creator_id: user.id, namespace: user.namespace) } let!(:hook) do create(:project_hook, - :all_events_enabled, - project: project, - url: 'http://example.com', - enable_ssl_verification: true, - push_events_branch_filter: 'master') + :all_events_enabled, + project: project, + url: "http://example.com", + enable_ssl_verification: true, + push_events_branch_filter: "master") end before do @@ -27,19 +27,19 @@ describe API::ProjectHooks, 'ProjectHooks' do expect(json_response).to be_an Array expect(response).to include_pagination_headers expect(json_response.count).to eq(1) - expect(json_response.first['url']).to eq("http://example.com") - expect(json_response.first['issues_events']).to eq(true) - expect(json_response.first['confidential_issues_events']).to eq(true) - expect(json_response.first['push_events']).to eq(true) - expect(json_response.first['merge_requests_events']).to eq(true) - expect(json_response.first['tag_push_events']).to eq(true) - expect(json_response.first['note_events']).to eq(true) - expect(json_response.first['confidential_note_events']).to eq(true) - expect(json_response.first['job_events']).to eq(true) - expect(json_response.first['pipeline_events']).to eq(true) - expect(json_response.first['wiki_page_events']).to eq(true) - expect(json_response.first['enable_ssl_verification']).to eq(true) - expect(json_response.first['push_events_branch_filter']).to eq('master') + expect(json_response.first["url"]).to eq("http://example.com") + expect(json_response.first["issues_events"]).to eq(true) + expect(json_response.first["confidential_issues_events"]).to eq(true) + expect(json_response.first["push_events"]).to eq(true) + expect(json_response.first["merge_requests_events"]).to eq(true) + expect(json_response.first["tag_push_events"]).to eq(true) + expect(json_response.first["note_events"]).to eq(true) + expect(json_response.first["confidential_note_events"]).to eq(true) + expect(json_response.first["job_events"]).to eq(true) + expect(json_response.first["pipeline_events"]).to eq(true) + expect(json_response.first["wiki_page_events"]).to eq(true) + expect(json_response.first["enable_ssl_verification"]).to eq(true) + expect(json_response.first["push_events_branch_filter"]).to eq("master") end end @@ -58,18 +58,18 @@ describe API::ProjectHooks, 'ProjectHooks' do get api("/projects/#{project.id}/hooks/#{hook.id}", user) expect(response).to have_gitlab_http_status(200) - expect(json_response['url']).to eq(hook.url) - expect(json_response['issues_events']).to eq(hook.issues_events) - expect(json_response['confidential_issues_events']).to eq(hook.confidential_issues_events) - expect(json_response['push_events']).to eq(hook.push_events) - expect(json_response['merge_requests_events']).to eq(hook.merge_requests_events) - expect(json_response['tag_push_events']).to eq(hook.tag_push_events) - expect(json_response['note_events']).to eq(hook.note_events) - expect(json_response['confidential_note_events']).to eq(hook.confidential_note_events) - expect(json_response['job_events']).to eq(hook.job_events) - expect(json_response['pipeline_events']).to eq(hook.pipeline_events) - expect(json_response['wiki_page_events']).to eq(hook.wiki_page_events) - expect(json_response['enable_ssl_verification']).to eq(hook.enable_ssl_verification) + expect(json_response["url"]).to eq(hook.url) + expect(json_response["issues_events"]).to eq(hook.issues_events) + expect(json_response["confidential_issues_events"]).to eq(hook.confidential_issues_events) + expect(json_response["push_events"]).to eq(hook.push_events) + expect(json_response["merge_requests_events"]).to eq(hook.merge_requests_events) + expect(json_response["tag_push_events"]).to eq(hook.tag_push_events) + expect(json_response["note_events"]).to eq(hook.note_events) + expect(json_response["confidential_note_events"]).to eq(hook.confidential_note_events) + expect(json_response["job_events"]).to eq(hook.job_events) + expect(json_response["pipeline_events"]).to eq(hook.pipeline_events) + expect(json_response["wiki_page_events"]).to eq(hook.wiki_page_events) + expect(json_response["enable_ssl_verification"]).to eq(hook.enable_ssl_verification) end it "returns a 404 error if hook id is not available" do @@ -89,34 +89,34 @@ describe API::ProjectHooks, 'ProjectHooks' do describe "POST /projects/:id/hooks" do it "adds hook to project" do - expect do + expect { post api("/projects/#{project.id}/hooks", user), - params: { url: "http://example.com", issues_events: true, confidential_issues_events: true, wiki_page_events: true, job_events: true, push_events_branch_filter: 'some-feature-branch' } - end.to change {project.hooks.count}.by(1) + params: {url: "http://example.com", issues_events: true, confidential_issues_events: true, wiki_page_events: true, job_events: true, push_events_branch_filter: "some-feature-branch"} + }.to change {project.hooks.count}.by(1) expect(response).to have_gitlab_http_status(201) - expect(json_response['url']).to eq('http://example.com') - expect(json_response['issues_events']).to eq(true) - expect(json_response['confidential_issues_events']).to eq(true) - expect(json_response['push_events']).to eq(true) - expect(json_response['merge_requests_events']).to eq(false) - expect(json_response['tag_push_events']).to eq(false) - expect(json_response['note_events']).to eq(false) - expect(json_response['confidential_note_events']).to eq(nil) - expect(json_response['job_events']).to eq(true) - expect(json_response['pipeline_events']).to eq(false) - expect(json_response['wiki_page_events']).to eq(true) - expect(json_response['enable_ssl_verification']).to eq(true) - expect(json_response['push_events_branch_filter']).to eq('some-feature-branch') - expect(json_response).not_to include('token') + expect(json_response["url"]).to eq("http://example.com") + expect(json_response["issues_events"]).to eq(true) + expect(json_response["confidential_issues_events"]).to eq(true) + expect(json_response["push_events"]).to eq(true) + expect(json_response["merge_requests_events"]).to eq(false) + expect(json_response["tag_push_events"]).to eq(false) + expect(json_response["note_events"]).to eq(false) + expect(json_response["confidential_note_events"]).to eq(nil) + expect(json_response["job_events"]).to eq(true) + expect(json_response["pipeline_events"]).to eq(false) + expect(json_response["wiki_page_events"]).to eq(true) + expect(json_response["enable_ssl_verification"]).to eq(true) + expect(json_response["push_events_branch_filter"]).to eq("some-feature-branch") + expect(json_response).not_to include("token") end it "adds the token without including it in the response" do token = "secret token" - expect do - post api("/projects/#{project.id}/hooks", user), params: { url: "http://example.com", token: token } - end.to change {project.hooks.count}.by(1) + expect { + post api("/projects/#{project.id}/hooks", user), params: {url: "http://example.com", token: token} + }.to change {project.hooks.count}.by(1) expect(response).to have_gitlab_http_status(201) expect(json_response["url"]).to eq("http://example.com") @@ -134,12 +134,12 @@ describe API::ProjectHooks, 'ProjectHooks' do end it "returns a 422 error if url not valid" do - post api("/projects/#{project.id}/hooks", user), params: { url: "ftp://example.com" } + post api("/projects/#{project.id}/hooks", user), params: {url: "ftp://example.com"} expect(response).to have_gitlab_http_status(422) end it "returns a 422 error if branch filter is not valid" do - post api("/projects/#{project.id}/hooks", user), params: { url: "http://example.com", push_events_branch_filter: '~badbranchname/' } + post api("/projects/#{project.id}/hooks", user), params: {url: "http://example.com", push_events_branch_filter: "~badbranchname/"} expect(response).to have_gitlab_http_status(422) end end @@ -147,27 +147,27 @@ describe API::ProjectHooks, 'ProjectHooks' do describe "PUT /projects/:id/hooks/:hook_id" do it "updates an existing project hook" do put api("/projects/#{project.id}/hooks/#{hook.id}", user), - params: { url: 'http://example.org', push_events: false, job_events: true } + params: {url: "http://example.org", push_events: false, job_events: true} expect(response).to have_gitlab_http_status(200) - expect(json_response['url']).to eq('http://example.org') - expect(json_response['issues_events']).to eq(hook.issues_events) - expect(json_response['confidential_issues_events']).to eq(hook.confidential_issues_events) - expect(json_response['push_events']).to eq(false) - expect(json_response['merge_requests_events']).to eq(hook.merge_requests_events) - expect(json_response['tag_push_events']).to eq(hook.tag_push_events) - expect(json_response['note_events']).to eq(hook.note_events) - expect(json_response['confidential_note_events']).to eq(hook.confidential_note_events) - expect(json_response['job_events']).to eq(hook.job_events) - expect(json_response['pipeline_events']).to eq(hook.pipeline_events) - expect(json_response['wiki_page_events']).to eq(hook.wiki_page_events) - expect(json_response['enable_ssl_verification']).to eq(hook.enable_ssl_verification) + expect(json_response["url"]).to eq("http://example.org") + expect(json_response["issues_events"]).to eq(hook.issues_events) + expect(json_response["confidential_issues_events"]).to eq(hook.confidential_issues_events) + expect(json_response["push_events"]).to eq(false) + expect(json_response["merge_requests_events"]).to eq(hook.merge_requests_events) + expect(json_response["tag_push_events"]).to eq(hook.tag_push_events) + expect(json_response["note_events"]).to eq(hook.note_events) + expect(json_response["confidential_note_events"]).to eq(hook.confidential_note_events) + expect(json_response["job_events"]).to eq(hook.job_events) + expect(json_response["pipeline_events"]).to eq(hook.pipeline_events) + expect(json_response["wiki_page_events"]).to eq(hook.wiki_page_events) + expect(json_response["enable_ssl_verification"]).to eq(hook.enable_ssl_verification) end it "adds the token without including it in the response" do token = "secret token" - put api("/projects/#{project.id}/hooks/#{hook.id}", user), params: { url: "http://example.org", token: token } + put api("/projects/#{project.id}/hooks/#{hook.id}", user), params: {url: "http://example.org", token: token} expect(response).to have_gitlab_http_status(200) expect(json_response["url"]).to eq("http://example.org") @@ -178,7 +178,7 @@ describe API::ProjectHooks, 'ProjectHooks' do end it "returns 404 error if hook id not found" do - put api("/projects/#{project.id}/hooks/1234", user), params: { url: 'http://example.org' } + put api("/projects/#{project.id}/hooks/1234", user), params: {url: "http://example.org"} expect(response).to have_gitlab_http_status(404) end @@ -188,18 +188,18 @@ describe API::ProjectHooks, 'ProjectHooks' do end it "returns a 422 error if url is not valid" do - put api("/projects/#{project.id}/hooks/#{hook.id}", user), params: { url: 'ftp://example.com' } + put api("/projects/#{project.id}/hooks/#{hook.id}", user), params: {url: "ftp://example.com"} expect(response).to have_gitlab_http_status(422) end end describe "DELETE /projects/:id/hooks/:hook_id" do it "deletes hook from project" do - expect do + expect { delete api("/projects/#{project.id}/hooks/#{hook.id}", user) expect(response).to have_gitlab_http_status(204) - end.to change {project.hooks.count}.by(-1) + }.to change {project.hooks.count}.by(-1) end it "returns a 404 error when deleting non existent hook" do @@ -223,7 +223,7 @@ describe API::ProjectHooks, 'ProjectHooks' do expect(WebHook.exists?(hook.id)).to be_truthy end - it_behaves_like '412 response' do + it_behaves_like "412 response" do let(:request) { api("/projects/#{project.id}/hooks/#{hook.id}", user) } end end diff --git a/spec/requests/api/project_import_spec.rb b/spec/requests/api/project_import_spec.rb index 594b42bb6c0..e2bbbc6bc79 100644 --- a/spec/requests/api/project_import_spec.rb +++ b/spec/requests/api/project_import_spec.rb @@ -1,9 +1,9 @@ -require 'spec_helper' +require "spec_helper" describe API::ProjectImport do let(:export_path) { "#{Dir.tmpdir}/project_export_spec" } let(:user) { create(:user) } - let(:file) { File.join('spec', 'features', 'projects', 'import_export', 'test_project_export.tar.gz') } + let(:file) { File.join("spec", "features", "projects", "import_export", "test_project_export.tar.gz") } let(:namespace) { create(:group) } before do allow_any_instance_of(Gitlab::ImportExport).to receive(:storage_path).and_return(export_path) @@ -16,130 +16,130 @@ describe API::ProjectImport do FileUtils.rm_rf(export_path, secure: true) end - describe 'POST /projects/import' do - it 'schedules an import using a namespace' do + describe "POST /projects/import" do + it "schedules an import using a namespace" do stub_import(namespace) - post api('/projects/import', user), params: { path: 'test-import', file: fixture_file_upload(file), namespace: namespace.id } + post api("/projects/import", user), params: {path: "test-import", file: fixture_file_upload(file), namespace: namespace.id} expect(response).to have_gitlab_http_status(201) end - it 'schedules an import using the namespace path' do + it "schedules an import using the namespace path" do stub_import(namespace) - post api('/projects/import', user), params: { path: 'test-import', file: fixture_file_upload(file), namespace: namespace.full_path } + post api("/projects/import", user), params: {path: "test-import", file: fixture_file_upload(file), namespace: namespace.full_path} expect(response).to have_gitlab_http_status(201) end - it 'schedules an import at the user namespace level' do + it "schedules an import at the user namespace level" do stub_import(user.namespace) - post api('/projects/import', user), params: { path: 'test-import2', file: fixture_file_upload(file) } + post api("/projects/import", user), params: {path: "test-import2", file: fixture_file_upload(file)} expect(response).to have_gitlab_http_status(201) end - it 'does not schedule an import for a namespace that does not exist' do + it "does not schedule an import for a namespace that does not exist" do expect_any_instance_of(ProjectImportState).not_to receive(:schedule) expect(::Projects::CreateService).not_to receive(:new) - post api('/projects/import', user), params: { namespace: 'nonexistent', path: 'test-import2', file: fixture_file_upload(file) } + post api("/projects/import", user), params: {namespace: "nonexistent", path: "test-import2", file: fixture_file_upload(file)} expect(response).to have_gitlab_http_status(404) - expect(json_response['message']).to eq('404 Namespace Not Found') + expect(json_response["message"]).to eq("404 Namespace Not Found") end - it 'does not schedule an import if the user has no permission to the namespace' do + it "does not schedule an import if the user has no permission to the namespace" do expect_any_instance_of(ProjectImportState).not_to receive(:schedule) - post(api('/projects/import', create(:user)), - params: { - path: 'test-import3', - file: fixture_file_upload(file), - namespace: namespace.full_path - }) + post(api("/projects/import", create(:user)), + params: { + path: "test-import3", + file: fixture_file_upload(file), + namespace: namespace.full_path, + }) expect(response).to have_gitlab_http_status(404) - expect(json_response['message']).to eq('404 Namespace Not Found') + expect(json_response["message"]).to eq("404 Namespace Not Found") end - it 'does not schedule an import if the user uploads no valid file' do + it "does not schedule an import if the user uploads no valid file" do expect_any_instance_of(ProjectImportState).not_to receive(:schedule) - post api('/projects/import', user), params: { path: 'test-import3', file: './random/test' } + post api("/projects/import", user), params: {path: "test-import3", file: "./random/test"} expect(response).to have_gitlab_http_status(400) - expect(json_response['error']).to eq('file is invalid') + expect(json_response["error"]).to eq("file is invalid") end - it 'stores params that can be overridden' do + it "stores params that can be overridden" do stub_import(namespace) - override_params = { 'description' => 'Hello world' } - - post api('/projects/import', user), - params: { - path: 'test-import', - file: fixture_file_upload(file), - namespace: namespace.id, - override_params: override_params - } - import_project = Project.find(json_response['id']) - - expect(import_project.import_data.data['override_params']).to eq(override_params) + override_params = {"description" => "Hello world"} + + post api("/projects/import", user), + params: { + path: "test-import", + file: fixture_file_upload(file), + namespace: namespace.id, + override_params: override_params, + } + import_project = Project.find(json_response["id"]) + + expect(import_project.import_data.data["override_params"]).to eq(override_params) end - it 'does not store params that are not allowed' do + it "does not store params that are not allowed" do stub_import(namespace) - override_params = { 'not_allowed' => 'Hello world' } - - post api('/projects/import', user), - params: { - path: 'test-import', - file: fixture_file_upload(file), - namespace: namespace.id, - override_params: override_params - } - import_project = Project.find(json_response['id']) - - expect(import_project.import_data.data['override_params']).to be_empty + override_params = {"not_allowed" => "Hello world"} + + post api("/projects/import", user), + params: { + path: "test-import", + file: fixture_file_upload(file), + namespace: namespace.id, + override_params: override_params, + } + import_project = Project.find(json_response["id"]) + + expect(import_project.import_data.data["override_params"]).to be_empty end - it 'correctly overrides params during the import' do - override_params = { 'description' => 'Hello world' } + it "correctly overrides params during the import" do + override_params = {"description" => "Hello world"} perform_enqueued_jobs do - post api('/projects/import', user), - params: { - path: 'test-import', - file: fixture_file_upload(file), - namespace: namespace.id, - override_params: override_params - } + post api("/projects/import", user), + params: { + path: "test-import", + file: fixture_file_upload(file), + namespace: namespace.id, + override_params: override_params, + } end - import_project = Project.find(json_response['id']) + import_project = Project.find(json_response["id"]) - expect(import_project.description).to eq('Hello world') + expect(import_project.description).to eq("Hello world") end - context 'when target path already exists in namespace' do + context "when target path already exists in namespace" do let(:existing_project) { create(:project, namespace: user.namespace) } - it 'does not schedule an import' do + it "does not schedule an import" do expect_any_instance_of(ProjectImportState).not_to receive(:schedule) - post api('/projects/import', user), params: { path: existing_project.path, file: fixture_file_upload(file) } + post api("/projects/import", user), params: {path: existing_project.path, file: fixture_file_upload(file)} expect(response).to have_gitlab_http_status(400) - expect(json_response['message']).to eq('Name has already been taken') + expect(json_response["message"]).to eq("Name has already been taken") end - context 'when param overwrite is true' do - it 'schedules an import' do + context "when param overwrite is true" do + it "schedules an import" do stub_import(user.namespace) - post api('/projects/import', user), params: { path: existing_project.path, file: fixture_file_upload(file), overwrite: true } + post api("/projects/import", user), params: {path: existing_project.path, file: fixture_file_upload(file), overwrite: true} expect(response).to have_gitlab_http_status(201) end @@ -152,27 +152,27 @@ describe API::ProjectImport do end end - describe 'GET /projects/:id/import' do - it 'returns the import status' do + describe "GET /projects/:id/import" do + it "returns the import status" do project = create(:project, :import_started) project.add_maintainer(user) get api("/projects/#{project.id}/import", user) expect(response).to have_gitlab_http_status(200) - expect(json_response).to include('import_status' => 'started') + expect(json_response).to include("import_status" => "started") end - it 'returns the import status and the error if failed' do + it "returns the import status and the error if failed" do project = create(:project, :import_failed) project.add_maintainer(user) - project.import_state.update(last_error: 'error') + project.import_state.update(last_error: "error") get api("/projects/#{project.id}/import", user) expect(response).to have_gitlab_http_status(200) - expect(json_response).to include('import_status' => 'failed', - 'import_error' => 'error') + expect(json_response).to include("import_status" => "failed", + "import_error" => "error") end end end diff --git a/spec/requests/api/project_milestones_spec.rb b/spec/requests/api/project_milestones_spec.rb index 895f05a98e8..4b20c82688d 100644 --- a/spec/requests/api/project_milestones_spec.rb +++ b/spec/requests/api/project_milestones_spec.rb @@ -1,20 +1,20 @@ -require 'spec_helper' +require "spec_helper" describe API::ProjectMilestones do let(:user) { create(:user) } - let!(:project) { create(:project, namespace: user.namespace ) } - let!(:closed_milestone) { create(:closed_milestone, project: project, title: 'version1', description: 'closed milestone') } - let!(:milestone) { create(:milestone, project: project, title: 'version2', description: 'open milestone') } + let!(:project) { create(:project, namespace: user.namespace) } + let!(:closed_milestone) { create(:closed_milestone, project: project, title: "version1", description: "closed milestone") } + let!(:milestone) { create(:milestone, project: project, title: "version2", description: "open milestone") } before do project.add_developer(user) end - it_behaves_like 'group and project milestones', "/projects/:id/milestones" do + it_behaves_like "group and project milestones", "/projects/:id/milestones" do let(:route) { "/projects/#{project.id}/milestones" } end - describe 'DELETE /projects/:id/milestones/:milestone_id' do + describe "DELETE /projects/:id/milestones/:milestone_id" do let(:guest) { create(:user) } let(:reporter) { create(:user) } @@ -22,13 +22,13 @@ describe API::ProjectMilestones do project.add_reporter(reporter) end - it 'returns 404 response when the project does not exists' do + it "returns 404 response when the project does not exists" do delete api("/projects/0/milestones/#{milestone.id}", user) expect(response).to have_gitlab_http_status(404) end - it 'returns 404 response when the milestone does not exists' do + it "returns 404 response when the milestone does not exists" do delete api("/projects/#{project.id}/milestones/0", user) expect(response).to have_gitlab_http_status(404) @@ -41,47 +41,47 @@ describe API::ProjectMilestones do end end - describe 'PUT /projects/:id/milestones/:milestone_id to test observer on close' do - it 'creates an activity event when an milestone is closed' do + describe "PUT /projects/:id/milestones/:milestone_id to test observer on close" do + it "creates an activity event when an milestone is closed" do expect(Event).to receive(:create!) put api("/projects/#{project.id}/milestones/#{milestone.id}", user), - params: { state_event: 'close' } + params: {state_event: "close"} end end - describe 'POST /projects/:id/milestones/:milestone_id/promote' do + describe "POST /projects/:id/milestones/:milestone_id/promote" do let(:group) { create(:group) } before do project.update(namespace: group) end - context 'when user does not have permission to promote milestone' do + context "when user does not have permission to promote milestone" do before do group.add_guest(user) end - it 'returns 403' do + it "returns 403" do post api("/projects/#{project.id}/milestones/#{milestone.id}/promote", user) expect(response).to have_gitlab_http_status(403) end end - context 'when user has permission' do + context "when user has permission" do before do group.add_developer(user) end - it 'returns 200' do + it "returns 200" do post api("/projects/#{project.id}/milestones/#{milestone.id}/promote", user) expect(response).to have_gitlab_http_status(200) expect(group.milestones.first.title).to eq(milestone.title) end - it 'returns 200 for closed milestone' do + it "returns 200 for closed milestone" do post api("/projects/#{project.id}/milestones/#{closed_milestone.id}/promote", user) expect(response).to have_gitlab_http_status(200) @@ -89,30 +89,30 @@ describe API::ProjectMilestones do end end - context 'when no such resources' do + context "when no such resources" do before do group.add_developer(user) end - it 'returns 404 response when the project does not exist' do + it "returns 404 response when the project does not exist" do post api("/projects/0/milestones/#{milestone.id}/promote", user) expect(response).to have_gitlab_http_status(404) end - it 'returns 404 response when the milestone does not exist' do + it "returns 404 response when the milestone does not exist" do post api("/projects/#{project.id}/milestones/0/promote", user) expect(response).to have_gitlab_http_status(404) end end - context 'when project does not belong to group' do + context "when project does not belong to group" do before do project.update(namespace: user.namespace) end - it 'returns 403' do + it "returns 403" do post api("/projects/#{project.id}/milestones/#{milestone.id}/promote", user) expect(response).to have_gitlab_http_status(403) diff --git a/spec/requests/api/project_snapshots_spec.rb b/spec/requests/api/project_snapshots_spec.rb index 44b5ee1f130..b5f065c6a28 100644 --- a/spec/requests/api/project_snapshots_spec.rb +++ b/spec/requests/api/project_snapshots_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe API::ProjectSnapshots do include WorkhorseHelpers @@ -6,43 +6,43 @@ describe API::ProjectSnapshots do let(:project) { create(:project) } let(:admin) { create(:admin) } - describe 'GET /projects/:id/snapshot' do + describe "GET /projects/:id/snapshot" do def expect_snapshot_response_for(repository) type, params = workhorse_send_data - expect(type).to eq('git-snapshot') + expect(type).to eq("git-snapshot") expect(params).to eq( - 'GitalyServer' => { - 'address' => Gitlab::GitalyClient.address(repository.project.repository_storage), - 'token' => Gitlab::GitalyClient.token(repository.project.repository_storage) + "GitalyServer" => { + "address" => Gitlab::GitalyClient.address(repository.project.repository_storage), + "token" => Gitlab::GitalyClient.token(repository.project.repository_storage), }, - 'GetSnapshotRequest' => Gitaly::GetSnapshotRequest.new( + "GetSnapshotRequest" => Gitaly::GetSnapshotRequest.new( repository: repository.gitaly_repository ).to_json ) end - it 'returns authentication error as project owner' do + it "returns authentication error as project owner" do get api("/projects/#{project.id}/snapshot", project.owner) expect(response).to have_gitlab_http_status(403) end - it 'returns authentication error as unauthenticated user' do + it "returns authentication error as unauthenticated user" do get api("/projects/#{project.id}/snapshot", nil) expect(response).to have_gitlab_http_status(401) end - it 'requests project repository raw archive as administrator' do - get api("/projects/#{project.id}/snapshot", admin), params: { wiki: '0' } + it "requests project repository raw archive as administrator" do + get api("/projects/#{project.id}/snapshot", admin), params: {wiki: "0"} expect(response).to have_gitlab_http_status(200) expect_snapshot_response_for(project.repository) end - it 'requests wiki repository raw archive as administrator' do - get api("/projects/#{project.id}/snapshot", admin), params: { wiki: '1' } + it "requests wiki repository raw archive as administrator" do + get api("/projects/#{project.id}/snapshot", admin), params: {wiki: "1"} expect(response).to have_gitlab_http_status(200) expect_snapshot_response_for(project.wiki.repository) diff --git a/spec/requests/api/project_snippets_spec.rb b/spec/requests/api/project_snippets_spec.rb index 29f69b6ce20..13c7ee3322a 100644 --- a/spec/requests/api/project_snippets_spec.rb +++ b/spec/requests/api/project_snippets_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require "rails_helper" describe API::ProjectSnippets do set(:project) { create(:project, :public) } @@ -9,16 +9,16 @@ describe API::ProjectSnippets do let(:snippet) { create(:project_snippet, :public, project: project) } let!(:user_agent_detail) { create(:user_agent_detail, subject: snippet) } - it 'exposes known attributes' do + it "exposes known attributes" do get api("/projects/#{project.id}/snippets/#{snippet.id}/user_agent_detail", admin) expect(response).to have_gitlab_http_status(200) - expect(json_response['user_agent']).to eq(user_agent_detail.user_agent) - expect(json_response['ip_address']).to eq(user_agent_detail.ip_address) - expect(json_response['akismet_submitted']).to eq(user_agent_detail.submitted) + expect(json_response["user_agent"]).to eq(user_agent_detail.user_agent) + expect(json_response["ip_address"]).to eq(user_agent_detail.ip_address) + expect(json_response["akismet_submitted"]).to eq(user_agent_detail.submitted) end - it 'respects project scoping' do + it "respects project scoping" do other_project = create(:project) get api("/projects/#{other_project.id}/snippets/#{snippet.id}/user_agent_detail", admin) @@ -32,10 +32,10 @@ describe API::ProjectSnippets do end end - describe 'GET /projects/:project_id/snippets/' do + describe "GET /projects/:project_id/snippets/" do let(:user) { create(:user) } - it 'returns all snippets available to team member' do + it "returns all snippets available to team member" do project.add_developer(user) public_snippet = create(:project_snippet, :public, project: project) internal_snippet = create(:project_snippet, :internal, project: project) @@ -47,11 +47,11 @@ describe API::ProjectSnippets do expect(response).to include_pagination_headers expect(json_response).to be_an Array 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.last).to have_key('web_url') + expect(json_response.map { |snippet| snippet["id"] }).to include(public_snippet.id, internal_snippet.id, private_snippet.id) + expect(json_response.last).to have_key("web_url") end - it 'hides private snippets from regular user' do + it "hides private snippets from regular user" do create(:project_snippet, :private, project: project) get api("/projects/#{project.id}/snippets/", user) @@ -63,44 +63,44 @@ describe API::ProjectSnippets do end end - describe 'GET /projects/:project_id/snippets/:id' do + describe "GET /projects/:project_id/snippets/:id" do let(:user) { create(:user) } let(:snippet) { create(:project_snippet, :public, project: project) } - it 'returns snippet json' do + it "returns snippet json" do get api("/projects/#{project.id}/snippets/#{snippet.id}", user) expect(response).to have_gitlab_http_status(200) - expect(json_response['title']).to eq(snippet.title) - expect(json_response['description']).to eq(snippet.description) - expect(json_response['file_name']).to eq(snippet.file_name) + expect(json_response["title"]).to eq(snippet.title) + expect(json_response["description"]).to eq(snippet.description) + expect(json_response["file_name"]).to eq(snippet.file_name) end - it 'returns 404 for invalid snippet id' do + it "returns 404 for invalid snippet id" do get api("/projects/#{project.id}/snippets/1234", user) expect(response).to have_gitlab_http_status(404) - expect(json_response['message']).to eq('404 Not found') + expect(json_response["message"]).to eq("404 Not found") end end - describe 'POST /projects/:project_id/snippets/' do + describe "POST /projects/:project_id/snippets/" do let(:params) do { - title: 'Test Title', - file_name: 'test.rb', - description: 'test description', + title: "Test Title", + file_name: "test.rb", + description: "test description", code: 'puts "hello world"', - visibility: 'public' + visibility: "public", } end - it 'creates a new snippet' do + it "creates a new snippet" do post api("/projects/#{project.id}/snippets/", admin), params: params expect(response).to have_gitlab_http_status(201) - snippet = ProjectSnippet.find(json_response['id']) + snippet = ProjectSnippet.find(json_response["id"]) expect(snippet.content).to eq(params[:code]) expect(snippet.description).to eq(params[:description]) expect(snippet.title).to eq(params[:title]) @@ -108,7 +108,7 @@ describe API::ProjectSnippets do expect(snippet.visibility_level).to eq(Snippet::PUBLIC) end - it 'returns 400 for missing parameters' do + it "returns 400 for missing parameters" do params.delete(:title) post api("/projects/#{project.id}/snippets/", admin), params: params @@ -116,15 +116,15 @@ describe API::ProjectSnippets do expect(response).to have_gitlab_http_status(400) end - it 'returns 400 for empty code field' do - params[:code] = '' + it "returns 400 for empty code field" do + params[:code] = "" post api("/projects/#{project.id}/snippets/", admin), params: params expect(response).to have_gitlab_http_status(400) end - context 'when the snippet is spam' do + context "when the snippet is spam" do def create_snippet(project, snippet_params = {}) project.add_developer(user) @@ -135,39 +135,39 @@ describe API::ProjectSnippets do allow_any_instance_of(AkismetService).to receive(:spam?).and_return(true) end - context 'when the snippet is private' do - it 'creates the snippet' do - expect { create_snippet(project, visibility: 'private') } + context "when the snippet is private" do + it "creates the snippet" do + expect { create_snippet(project, visibility: "private") } .to change { Snippet.count }.by(1) end end - context 'when the snippet is public' do - it 'rejects the snippet' do - expect { create_snippet(project, visibility: 'public') } + context "when the snippet is public" do + it "rejects the snippet" do + expect { create_snippet(project, visibility: "public") } .not_to change { Snippet.count } expect(response).to have_gitlab_http_status(400) - expect(json_response['message']).to eq({ "error" => "Spam detected" }) + expect(json_response["message"]).to eq({"error" => "Spam detected"}) end - it 'creates a spam log' do - expect { create_snippet(project, visibility: 'public') } + it "creates a spam log" do + expect { create_snippet(project, visibility: "public") } .to change { SpamLog.count }.by(1) end end end end - describe 'PUT /projects/:project_id/snippets/:id/' do + describe "PUT /projects/:project_id/snippets/:id/" do let(:visibility_level) { Snippet::PUBLIC } let(:snippet) { create(:project_snippet, author: admin, visibility_level: visibility_level) } - it 'updates snippet' do - new_content = 'New content' - new_description = 'New description' + it "updates snippet" do + new_content = "New content" + new_description = "New description" - put api("/projects/#{snippet.project.id}/snippets/#{snippet.id}/", admin), params: { code: new_content, description: new_description } + put api("/projects/#{snippet.project.id}/snippets/#{snippet.id}/", admin), params: {code: new_content, description: new_description} expect(response).to have_gitlab_http_status(200) snippet.reload @@ -175,28 +175,28 @@ describe API::ProjectSnippets do expect(snippet.description).to eq(new_description) end - it 'returns 404 for invalid snippet id' do - put api("/projects/#{snippet.project.id}/snippets/1234", admin), params: { title: 'foo' } + it "returns 404 for invalid snippet id" do + put api("/projects/#{snippet.project.id}/snippets/1234", admin), params: {title: "foo"} expect(response).to have_gitlab_http_status(404) - expect(json_response['message']).to eq('404 Snippet Not Found') + expect(json_response["message"]).to eq("404 Snippet Not Found") end - it 'returns 400 for missing parameters' do + it "returns 400 for missing parameters" do put api("/projects/#{project.id}/snippets/1234", admin) expect(response).to have_gitlab_http_status(400) end - it 'returns 400 for empty code field' do - new_content = '' + it "returns 400 for empty code field" do + new_content = "" - put api("/projects/#{snippet.project.id}/snippets/#{snippet.id}/", admin), params: { code: new_content } + put api("/projects/#{snippet.project.id}/snippets/#{snippet.id}/", admin), params: {code: new_content} expect(response).to have_gitlab_http_status(400) end - context 'when the snippet is spam' do + context "when the snippet is spam" do def update_snippet(snippet_params = {}) put api("/projects/#{snippet.project.id}/snippets/#{snippet.id}", admin), params: snippet_params end @@ -205,85 +205,85 @@ describe API::ProjectSnippets do allow_any_instance_of(AkismetService).to receive(:spam?).and_return(true) end - context 'when the snippet is private' do + context "when the snippet is private" do let(:visibility_level) { Snippet::PRIVATE } - it 'creates the snippet' do - expect { update_snippet(title: 'Foo') } - .to change { snippet.reload.title }.to('Foo') + it "creates the snippet" do + expect { update_snippet(title: "Foo") } + .to change { snippet.reload.title }.to("Foo") end end - context 'when the snippet is public' do + context "when the snippet is public" do let(:visibility_level) { Snippet::PUBLIC } - it 'rejects the snippet' do - expect { update_snippet(title: 'Foo') } + it "rejects the snippet" do + expect { update_snippet(title: "Foo") } .not_to change { snippet.reload.title } end - it 'creates a spam log' do - expect { update_snippet(title: 'Foo') } + it "creates a spam log" do + expect { update_snippet(title: "Foo") } .to change { SpamLog.count }.by(1) end end - context 'when the private snippet is made public' do + context "when the private snippet is made public" do let(:visibility_level) { Snippet::PRIVATE } - it 'rejects the snippet' do - expect { update_snippet(title: 'Foo', visibility: 'public') } + it "rejects the snippet" do + expect { update_snippet(title: "Foo", visibility: "public") } .not_to change { snippet.reload.title } expect(response).to have_gitlab_http_status(400) - expect(json_response['message']).to eq({ "error" => "Spam detected" }) + expect(json_response["message"]).to eq({"error" => "Spam detected"}) end - it 'creates a spam log' do - expect { update_snippet(title: 'Foo', visibility: 'public') } + it "creates a spam log" do + expect { update_snippet(title: "Foo", visibility: "public") } .to change { SpamLog.count }.by(1) end end end end - describe 'DELETE /projects/:project_id/snippets/:id/' do + describe "DELETE /projects/:project_id/snippets/:id/" do let(:snippet) { create(:project_snippet, author: admin) } - it 'deletes snippet' do + it "deletes snippet" do delete api("/projects/#{snippet.project.id}/snippets/#{snippet.id}/", admin) expect(response).to have_gitlab_http_status(204) end - it 'returns 404 for invalid snippet id' do + it "returns 404 for invalid snippet id" do delete api("/projects/#{snippet.project.id}/snippets/1234", admin) expect(response).to have_gitlab_http_status(404) - expect(json_response['message']).to eq('404 Snippet Not Found') + expect(json_response["message"]).to eq("404 Snippet Not Found") end - it_behaves_like '412 response' do + it_behaves_like "412 response" do let(:request) { api("/projects/#{snippet.project.id}/snippets/#{snippet.id}/", admin) } end end - describe 'GET /projects/:project_id/snippets/:id/raw' do + describe "GET /projects/:project_id/snippets/:id/raw" do let(:snippet) { create(:project_snippet, author: admin) } - it 'returns raw text' do + it "returns raw text" do get api("/projects/#{snippet.project.id}/snippets/#{snippet.id}/raw", admin) expect(response).to have_gitlab_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) end - it 'returns 404 for invalid snippet id' do + it "returns 404 for invalid snippet id" do get api("/projects/#{snippet.project.id}/snippets/1234/raw", admin) expect(response).to have_gitlab_http_status(404) - expect(json_response['message']).to eq('404 Snippet Not Found') + expect(json_response["message"]).to eq("404 Snippet Not Found") end end end diff --git a/spec/requests/api/project_statistics_spec.rb b/spec/requests/api/project_statistics_spec.rb index 184d0a72c37..9d2c4ac4821 100644 --- a/spec/requests/api/project_statistics_spec.rb +++ b/spec/requests/api/project_statistics_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'spec_helper' +require "spec_helper" describe API::ProjectStatistics do let(:maintainer) { create(:user) } @@ -10,7 +10,7 @@ describe API::ProjectStatistics do public_project.add_maintainer(maintainer) end - describe 'GET /projects/:id/statistics' do + describe "GET /projects/:id/statistics" do let!(:fetch_statistics1) { create(:project_daily_statistic, project: public_project, fetch_count: 30, date: 29.days.ago) } let!(:fetch_statistics2) { create(:project_daily_statistic, project: public_project, fetch_count: 4, date: 3.days.ago) } let!(:fetch_statistics3) { create(:project_daily_statistic, project: public_project, fetch_count: 3, date: 2.days.ago) } @@ -18,41 +18,41 @@ describe API::ProjectStatistics do let!(:fetch_statistics5) { create(:project_daily_statistic, project: public_project, fetch_count: 1, date: Date.today) } let!(:fetch_statistics_other_project) { create(:project_daily_statistic, project: create(:project), fetch_count: 29, date: 29.days.ago) } - it 'returns the fetch statistics of the last 30 days' do + it "returns the fetch statistics of the last 30 days" do get api("/projects/#{public_project.id}/statistics", maintainer) expect(response).to have_gitlab_http_status(200) - fetches = json_response['fetches'] - expect(fetches['total']).to eq(40) - expect(fetches['days'].length).to eq(5) - expect(fetches['days'].first).to eq({ 'count' => fetch_statistics5.fetch_count, 'date' => fetch_statistics5.date.to_s }) - expect(fetches['days'].last).to eq({ 'count' => fetch_statistics1.fetch_count, 'date' => fetch_statistics1.date.to_s }) + fetches = json_response["fetches"] + expect(fetches["total"]).to eq(40) + expect(fetches["days"].length).to eq(5) + expect(fetches["days"].first).to eq({"count" => fetch_statistics5.fetch_count, "date" => fetch_statistics5.date.to_s}) + expect(fetches["days"].last).to eq({"count" => fetch_statistics1.fetch_count, "date" => fetch_statistics1.date.to_s}) end - it 'excludes the fetch statistics older than 30 days' do + it "excludes the fetch statistics older than 30 days" do create(:project_daily_statistic, fetch_count: 31, project: public_project, date: 30.days.ago) get api("/projects/#{public_project.id}/statistics", maintainer) expect(response).to have_gitlab_http_status(200) - fetches = json_response['fetches'] - expect(fetches['total']).to eq(40) - expect(fetches['days'].length).to eq(5) - expect(fetches['days'].last).to eq({ 'count' => fetch_statistics1.fetch_count, 'date' => fetch_statistics1.date.to_s }) + fetches = json_response["fetches"] + expect(fetches["total"]).to eq(40) + expect(fetches["days"].length).to eq(5) + expect(fetches["days"].last).to eq({"count" => fetch_statistics1.fetch_count, "date" => fetch_statistics1.date.to_s}) end - it 'responds with 403 when the user is not a maintainer of the repository' do + it "responds with 403 when the user is not a maintainer of the repository" do developer = create(:user) public_project.add_developer(developer) get api("/projects/#{public_project.id}/statistics", developer) expect(response).to have_gitlab_http_status(403) - expect(json_response['message']).to eq('403 Forbidden') + expect(json_response["message"]).to eq("403 Forbidden") end - it 'responds with 404 when daily_statistics_enabled? is false' do - stub_feature_flags(project_daily_statistics: { thing: public_project, enabled: false }) + it "responds with 404 when daily_statistics_enabled? is false" do + stub_feature_flags(project_daily_statistics: {thing: public_project, enabled: false}) get api("/projects/#{public_project.id}/statistics", maintainer) diff --git a/spec/requests/api/project_templates_spec.rb b/spec/requests/api/project_templates_spec.rb index 80e5033dab4..978ce568e94 100644 --- a/spec/requests/api/project_templates_spec.rb +++ b/spec/requests/api/project_templates_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe API::ProjectTemplates do let(:public_project) { create(:project, :public) } @@ -9,141 +9,141 @@ describe API::ProjectTemplates do private_project.add_developer(developer) end - describe 'GET /projects/:id/templates/:type' do - it 'returns dockerfiles' do + describe "GET /projects/:id/templates/:type" do + it "returns dockerfiles" do get api("/projects/#{public_project.id}/templates/dockerfiles") expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers - expect(response).to match_response_schema('public_api/v4/template_list') - expect(json_response).to satisfy_one { |template| template['key'] == 'Binary' } + expect(response).to match_response_schema("public_api/v4/template_list") + expect(json_response).to satisfy_one { |template| template["key"] == "Binary" } end - it 'returns gitignores' do + it "returns gitignores" do get api("/projects/#{public_project.id}/templates/gitignores") expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers - expect(response).to match_response_schema('public_api/v4/template_list') - expect(json_response).to satisfy_one { |template| template['key'] == 'Actionscript' } + expect(response).to match_response_schema("public_api/v4/template_list") + expect(json_response).to satisfy_one { |template| template["key"] == "Actionscript" } end - it 'returns gitlab_ci_ymls' do + it "returns gitlab_ci_ymls" do get api("/projects/#{public_project.id}/templates/gitlab_ci_ymls") expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers - expect(response).to match_response_schema('public_api/v4/template_list') - expect(json_response).to satisfy_one { |template| template['key'] == 'Android' } + expect(response).to match_response_schema("public_api/v4/template_list") + expect(json_response).to satisfy_one { |template| template["key"] == "Android" } end - it 'returns licenses' do + it "returns licenses" do get api("/projects/#{public_project.id}/templates/licenses") expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers - expect(response).to match_response_schema('public_api/v4/template_list') - expect(json_response).to satisfy_one { |template| template['key'] == 'mit' } + expect(response).to match_response_schema("public_api/v4/template_list") + expect(json_response).to satisfy_one { |template| template["key"] == "mit" } end - it 'returns 400 for an unknown template type' do + it "returns 400 for an unknown template type" do get api("/projects/#{public_project.id}/templates/unknown") expect(response).to have_gitlab_http_status(400) end - it 'denies access to an anonymous user on a private project' do + it "denies access to an anonymous user on a private project" do get api("/projects/#{private_project.id}/templates/licenses") expect(response).to have_gitlab_http_status(404) end - it 'permits access to a developer on a private project' do + it "permits access to a developer on a private project" do get api("/projects/#{private_project.id}/templates/licenses", developer) expect(response).to have_gitlab_http_status(200) - expect(response).to match_response_schema('public_api/v4/template_list') + expect(response).to match_response_schema("public_api/v4/template_list") end end - describe 'GET /projects/:id/templates/licenses' do - it 'returns key and name for the listed licenses' do + describe "GET /projects/:id/templates/licenses" do + it "returns key and name for the listed licenses" do get api("/projects/#{public_project.id}/templates/licenses") expect(response).to have_gitlab_http_status(200) - expect(response).to match_response_schema('public_api/v4/template_list') + expect(response).to match_response_schema("public_api/v4/template_list") end end - describe 'GET /projects/:id/templates/:type/:key' do - it 'returns a specific dockerfile' do + describe "GET /projects/:id/templates/:type/:key" do + it "returns a specific dockerfile" do get api("/projects/#{public_project.id}/templates/dockerfiles/Binary") expect(response).to have_gitlab_http_status(200) - expect(response).to match_response_schema('public_api/v4/template') - expect(json_response['name']).to eq('Binary') + expect(response).to match_response_schema("public_api/v4/template") + expect(json_response["name"]).to eq("Binary") end - it 'returns a specific gitignore' do + it "returns a specific gitignore" do get api("/projects/#{public_project.id}/templates/gitignores/Actionscript") expect(response).to have_gitlab_http_status(200) - expect(response).to match_response_schema('public_api/v4/template') - expect(json_response['name']).to eq('Actionscript') + expect(response).to match_response_schema("public_api/v4/template") + expect(json_response["name"]).to eq("Actionscript") end - it 'returns C++ gitignore' do + it "returns C++ gitignore" do get api("/projects/#{public_project.id}/templates/gitignores/C++") expect(response).to have_gitlab_http_status(200) - expect(response).to match_response_schema('public_api/v4/template') - expect(json_response['name']).to eq('C++') + expect(response).to match_response_schema("public_api/v4/template") + expect(json_response["name"]).to eq("C++") end - it 'returns C++ gitignore for URL-encoded names' do + it "returns C++ gitignore for URL-encoded names" do get api("/projects/#{public_project.id}/templates/gitignores/C%2B%2B") expect(response).to have_gitlab_http_status(200) - expect(response).to match_response_schema('public_api/v4/template') - expect(json_response['name']).to eq('C++') + expect(response).to match_response_schema("public_api/v4/template") + expect(json_response["name"]).to eq("C++") end - it 'returns a specific gitlab_ci_yml' do + it "returns a specific gitlab_ci_yml" do get api("/projects/#{public_project.id}/templates/gitlab_ci_ymls/Android") expect(response).to have_gitlab_http_status(200) - expect(response).to match_response_schema('public_api/v4/template') - expect(json_response['name']).to eq('Android') + expect(response).to match_response_schema("public_api/v4/template") + expect(json_response["name"]).to eq("Android") end - it 'returns a specific license' do + it "returns a specific license" do get api("/projects/#{public_project.id}/templates/licenses/mit") expect(response).to have_gitlab_http_status(200) - expect(response).to match_response_schema('public_api/v4/license') + expect(response).to match_response_schema("public_api/v4/license") end - it 'returns 404 for an unknown specific template' do + it "returns 404 for an unknown specific template" do get api("/projects/#{public_project.id}/templates/licenses/unknown") expect(response).to have_gitlab_http_status(404) end - it 'denies access to an anonymous user on a private project' do + it "denies access to an anonymous user on a private project" do get api("/projects/#{private_project.id}/templates/licenses/mit") expect(response).to have_gitlab_http_status(404) end - it 'permits access to a developer on a private project' do + it "permits access to a developer on a private project" do get api("/projects/#{private_project.id}/templates/licenses/mit", developer) expect(response).to have_gitlab_http_status(200) - expect(response).to match_response_schema('public_api/v4/license') + expect(response).to match_response_schema("public_api/v4/license") end - shared_examples 'path traversal attempt' do |template_type| - it 'rejects invalid filenames' do + shared_examples "path traversal attempt" do |template_type| + it "rejects invalid filenames" do get api("/projects/#{public_project.id}/templates/#{template_type}/%2e%2e%2fPython%2ea") expect(response).to have_gitlab_http_status(500) @@ -151,24 +151,24 @@ describe API::ProjectTemplates do end TemplateFinder::VENDORED_TEMPLATES.each do |template_type, _| - it_behaves_like 'path traversal attempt', template_type + it_behaves_like "path traversal attempt", template_type end end - describe 'GET /projects/:id/templates/licenses/:key' do - it 'fills placeholders in the license' do + describe "GET /projects/:id/templates/licenses/:key" do + it "fills placeholders in the license" do get api("/projects/#{public_project.id}/templates/licenses/agpl-3.0"), - params: { - project: 'Project Placeholder', - fullname: 'Fullname Placeholder' - } + params: { + project: "Project Placeholder", + fullname: "Fullname Placeholder", + } expect(response).to have_gitlab_http_status(200) - expect(response).to match_response_schema('public_api/v4/license') + expect(response).to match_response_schema("public_api/v4/license") - content = json_response['content'] + content = json_response["content"] - expect(content).to include('Project Placeholder') + expect(content).to include("Project Placeholder") expect(content).to include("Copyright (C) #{Time.now.year} Fullname Placeholder") end end diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb index 856fe1bbe89..3be8b890780 100644 --- a/spec/requests/api/projects_spec.rb +++ b/spec/requests/api/projects_spec.rb @@ -1,19 +1,18 @@ -# -*- coding: utf-8 -*- -require 'spec_helper' +require "spec_helper" -shared_examples 'languages and percentages JSON response' do +shared_examples "languages and percentages JSON response" do let(:expected_languages) { project.repository.languages.map { |language| language.values_at(:label, :value)}.to_h } before do allow(project.repository).to receive(:languages).and_return( - [{ value: 66.69, label: "Ruby", color: "#701516", highlight: "#701516" }, - { value: 22.98, label: "JavaScript", color: "#f1e05a", highlight: "#f1e05a" }, - { value: 7.91, label: "HTML", color: "#e34c26", highlight: "#e34c26" }, - { value: 2.42, label: "CoffeeScript", color: "#244776", highlight: "#244776" }] + [{value: 66.69, label: "Ruby", color: "#701516", highlight: "#701516"}, + {value: 22.98, label: "JavaScript", color: "#f1e05a", highlight: "#f1e05a"}, + {value: 7.91, label: "HTML", color: "#e34c26", highlight: "#e34c26"}, + {value: 2.42, label: "CoffeeScript", color: "#244776", highlight: "#244776"},] ) end - it 'returns expected language values' do + it "returns expected language values" do get api("/projects/#{project.id}/languages", user) expect(response).to have_gitlab_http_status(:ok) @@ -21,12 +20,12 @@ shared_examples 'languages and percentages JSON response' do expect(json_response.count).to be > 1 end - context 'when the languages were detected before' do + context "when the languages were detected before" do before do Projects::DetectRepositoryLanguagesService.new(project, project.owner).execute end - it 'returns the detection from the database' do + it "returns the detection from the database" do # Allow this to happen once, so the expected languages can be determined expect(project.repository).to receive(:languages).once @@ -47,43 +46,43 @@ describe API::Projects do let(:project) { create(:project, :repository, namespace: user.namespace) } let(:project2) { create(:project, namespace: user.namespace) } let(:project_member) { create(:project_member, :developer, user: user3, project: project) } - let(:user4) { create(:user, username: 'user.with.dot') } + let(:user4) { create(:user, username: "user.with.dot") } let(:project3) do create(:project, - :private, - :repository, - name: 'second_project', - path: 'second_project', - creator_id: user.id, - namespace: user.namespace, - merge_requests_enabled: false, - issues_enabled: false, wiki_enabled: false, - builds_enabled: false, - snippets_enabled: false) + :private, + :repository, + name: "second_project", + path: "second_project", + creator_id: user.id, + namespace: user.namespace, + merge_requests_enabled: false, + issues_enabled: false, wiki_enabled: false, + builds_enabled: false, + snippets_enabled: false) end let(:project_member2) do create(:project_member, - user: user4, - project: project3, - access_level: ProjectMember::MAINTAINER) + user: user4, + project: project3, + access_level: ProjectMember::MAINTAINER) end let(:project4) do create(:project, - name: 'third_project', - path: 'third_project', - creator_id: user4.id, - namespace: user4.namespace) + name: "third_project", + path: "third_project", + creator_id: user4.id, + namespace: user4.namespace) end - shared_context 'with language detection' do - let(:ruby) { create(:programming_language, name: 'Ruby') } - let(:javascript) { create(:programming_language, name: 'JavaScript') } - let(:html) { create(:programming_language, name: 'HTML') } + shared_context "with language detection" do + let(:ruby) { create(:programming_language, name: "Ruby") } + let(:javascript) { create(:programming_language, name: "JavaScript") } + let(:html) { create(:programming_language, name: "HTML") } let(:mock_repo_languages) do { - project => { ruby => 0.5, html => 0.5 }, - project3 => { html => 0.7, javascript => 0.3 } + project => {ruby => 0.5, html => 0.5}, + project3 => {html => 0.7, javascript => 0.3}, } end @@ -96,29 +95,29 @@ describe API::Projects do end end - describe 'GET /projects' do - shared_examples_for 'projects response' do - it 'returns an array of projects' do - get api('/projects', current_user), params: filter + describe "GET /projects" do + shared_examples_for "projects response" do + it "returns an array of projects" do + get api("/projects", current_user), params: filter expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response).to be_an Array - expect(json_response.map { |p| p['id'] }).to contain_exactly(*projects.map(&:id)) + expect(json_response.map { |p| p["id"] }).to contain_exactly(*projects.map(&:id)) end - it 'returns the proper security headers' do - get api('/projects', current_user), params: filter + it "returns the proper security headers" do + get api("/projects", current_user), params: filter expect(response).to include_security_headers end end - shared_examples_for 'projects response without N + 1 queries' do - it 'avoids N + 1 queries' do - control = ActiveRecord::QueryRecorder.new do - get api('/projects', current_user) - end + shared_examples_for "projects response without N + 1 queries" do + it "avoids N + 1 queries" do + control = ActiveRecord::QueryRecorder.new { + get api("/projects", current_user) + } if defined?(additional_project) additional_project @@ -129,13 +128,13 @@ describe API::Projects do # TODO: We're currently querying to detect if a project is a fork # in 2 ways. Lower this back to 8 when `ForkedProjectLink` relation is # removed - expect do - get api('/projects', current_user) - end.not_to exceed_query_limit(control).with_threshold(9) + expect { + get api("/projects", current_user) + }.not_to exceed_query_limit(control).with_threshold(9) end end - let!(:public_project) { create(:project, :public, name: 'public_project') } + let!(:public_project) { create(:project, :public, name: "public_project") } before do project project2 @@ -143,156 +142,156 @@ describe API::Projects do project4 end - context 'when unauthenticated' do - it_behaves_like 'projects response' do - let(:filter) { { search: project.name } } + context "when unauthenticated" do + it_behaves_like "projects response" do + let(:filter) { {search: project.name} } let(:current_user) { user } let(:projects) { [project] } end - it_behaves_like 'projects response without N + 1 queries' do + it_behaves_like "projects response without N + 1 queries" do let(:current_user) { nil } end end - context 'when authenticated as regular user' do - it_behaves_like 'projects response' do + context "when authenticated as regular user" do + it_behaves_like "projects response" do let(:filter) { {} } let(:current_user) { user } let(:projects) { [public_project, project, project2, project3] } end - it_behaves_like 'projects response without N + 1 queries' do + it_behaves_like "projects response without N + 1 queries" do let(:current_user) { user } end - context 'when some projects are in a group' do + context "when some projects are in a group" do before do create(:project, :public, group: create(:group)) end - it_behaves_like 'projects response without N + 1 queries' do + it_behaves_like "projects response without N + 1 queries" do let(:current_user) { user } let(:additional_project) { create(:project, :public, group: create(:group)) } end end - it 'includes the project labels as the tag_list' do - get api('/projects', user) + it "includes the project labels as the tag_list" do + get api("/projects", user) expect(response.status).to eq 200 expect(response).to include_pagination_headers expect(json_response).to be_an Array - expect(json_response.first.keys).to include('tag_list') + expect(json_response.first.keys).to include("tag_list") end - it 'includes open_issues_count' do - get api('/projects', user) + it "includes open_issues_count" do + get api("/projects", user) expect(response.status).to eq 200 expect(response).to include_pagination_headers expect(json_response).to be_an Array - expect(json_response.first.keys).to include('open_issues_count') + expect(json_response.first.keys).to include("open_issues_count") end - it 'does not include projects marked for deletion' do + it "does not include projects marked for deletion" do project.update(pending_delete: true) - get api('/projects', user) + get api("/projects", user) expect(response).to have_gitlab_http_status(200) expect(json_response).to be_an Array - expect(json_response.map { |p| p['id'] }).not_to include(project.id) + expect(json_response.map { |p| p["id"] }).not_to include(project.id) end - it 'does not include open_issues_count if issues are disabled' do + it "does not include open_issues_count if issues are disabled" do project.project_feature.update_attribute(:issues_access_level, ProjectFeature::DISABLED) - get api('/projects', user) + get api("/projects", user) expect(response.status).to eq 200 expect(response).to include_pagination_headers expect(json_response).to be_an Array - expect(json_response.find { |hash| hash['id'] == project.id }.keys).not_to include('open_issues_count') + expect(json_response.find { |hash| hash["id"] == project.id }.keys).not_to include("open_issues_count") end - context 'and with_issues_enabled=true' do - it 'only returns projects with issues enabled' do + context "and with_issues_enabled=true" do + it "only returns projects with issues enabled" do project.project_feature.update_attribute(:issues_access_level, ProjectFeature::DISABLED) - get api('/projects?with_issues_enabled=true', user) + get api("/projects?with_issues_enabled=true", user) expect(response.status).to eq 200 expect(response).to include_pagination_headers expect(json_response).to be_an Array - expect(json_response.map { |p| p['id'] }).not_to include(project.id) + expect(json_response.map { |p| p["id"] }).not_to include(project.id) end end it "does not include statistics by default" do - get api('/projects', user) + get api("/projects", user) expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response).to be_an Array - expect(json_response.first).not_to include('statistics') + expect(json_response.first).not_to include("statistics") end it "includes statistics if requested" do - get api('/projects', user), params: { statistics: true } + get api("/projects", user), params: {statistics: true} expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response).to be_an Array - expect(json_response.first).to include 'statistics' + expect(json_response.first).to include "statistics" end it "does not include license by default" do - get api('/projects', user) + get api("/projects", user) expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response).to be_an Array - expect(json_response.first).not_to include('license', 'license_url') + expect(json_response.first).not_to include("license", "license_url") end it "does not include license if requested" do - get api('/projects', user), params: { license: true } + get api("/projects", user), params: {license: true} expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response).to be_an Array - expect(json_response.first).not_to include('license', 'license_url') + expect(json_response.first).not_to include("license", "license_url") end - context 'when external issue tracker is enabled' do + context "when external issue tracker is enabled" do let!(:jira_service) { create(:jira_service, project: project) } - it 'includes open_issues_count' do - get api('/projects', user) + it "includes open_issues_count" do + get api("/projects", user) expect(response.status).to eq 200 expect(response).to include_pagination_headers expect(json_response).to be_an Array - expect(json_response.first.keys).to include('open_issues_count') - expect(json_response.find { |hash| hash['id'] == project.id }.keys).to include('open_issues_count') + expect(json_response.first.keys).to include("open_issues_count") + expect(json_response.find { |hash| hash["id"] == project.id }.keys).to include("open_issues_count") end - it 'does not include open_issues_count if issues are disabled' do + it "does not include open_issues_count if issues are disabled" do project.project_feature.update_attribute(:issues_access_level, ProjectFeature::DISABLED) - get api('/projects', user) + get api("/projects", user) expect(response.status).to eq 200 expect(response).to include_pagination_headers expect(json_response).to be_an Array - expect(json_response.find { |hash| hash['id'] == project.id }.keys).not_to include('open_issues_count') + expect(json_response.find { |hash| hash["id"] == project.id }.keys).not_to include("open_issues_count") end end - context 'and with simple=true' do - it 'returns a simplified version of all the projects' do - expected_keys = %w( + context "and with simple=true" do + it "returns a simplified version of all the projects" do + expected_keys = %w[ id description default_branch tag_list ssh_url_to_repo http_url_to_repo web_url readme_url name name_with_namespace @@ -300,9 +299,9 @@ describe API::Projects do star_count forks_count created_at last_activity_at avatar_url namespace - ) + ] - get api('/projects?simple=true', user) + get api("/projects?simple=true", user) expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers @@ -311,123 +310,123 @@ describe API::Projects do end end - context 'and using archived' do + context "and using archived" do let!(:archived_project) { create(:project, creator_id: user.id, namespace: user.namespace, archived: true) } - it 'returns archived projects' do - get api('/projects?archived=true', user) + it "returns archived projects" do + get api("/projects?archived=true", user) expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response).to be_an Array expect(json_response.length).to eq(Project.public_or_visible_to_user(user).where(archived: true).size) - expect(json_response.map { |project| project['id'] }).to include(archived_project.id) + expect(json_response.map { |project| project["id"] }).to include(archived_project.id) end - it 'returns non-archived projects' do - get api('/projects?archived=false', user) + it "returns non-archived projects" do + get api("/projects?archived=false", user) expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response).to be_an Array expect(json_response.length).to eq(Project.public_or_visible_to_user(user).where(archived: false).size) - expect(json_response.map { |project| project['id'] }).not_to include(archived_project.id) + expect(json_response.map { |project| project["id"] }).not_to include(archived_project.id) end - it 'returns every project' do - get api('/projects', user) + it "returns every project" do + get api("/projects", user) expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response).to be_an Array - expect(json_response.map { |project| project['id'] }).to contain_exactly(*Project.public_or_visible_to_user(user).pluck(:id)) + expect(json_response.map { |project| project["id"] }).to contain_exactly(*Project.public_or_visible_to_user(user).pluck(:id)) end end - context 'and using search' do - it_behaves_like 'projects response' do - let(:filter) { { search: project.name } } + context "and using search" do + it_behaves_like "projects response" do + let(:filter) { {search: project.name} } let(:current_user) { user } let(:projects) { [project] } end end - context 'and membership=true' do - it_behaves_like 'projects response' do - let(:filter) { { membership: true } } + context "and membership=true" do + it_behaves_like "projects response" do + let(:filter) { {membership: true} } let(:current_user) { user } let(:projects) { [project, project2, project3] } end end - context 'and using the visibility filter' do - it 'filters based on private visibility param' do - get api('/projects', user), params: { visibility: 'private' } + context "and using the visibility filter" do + it "filters based on private visibility param" do + get api("/projects", user), params: {visibility: "private"} expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response).to be_an Array - expect(json_response.map { |p| p['id'] }).to contain_exactly(project.id, project2.id, project3.id) + expect(json_response.map { |p| p["id"] }).to contain_exactly(project.id, project2.id, project3.id) end - it 'filters based on internal visibility param' do + it "filters based on internal visibility param" do project2.update_attribute(:visibility_level, Gitlab::VisibilityLevel::INTERNAL) - get api('/projects', user), params: { visibility: 'internal' } + get api("/projects", user), params: {visibility: "internal"} expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response).to be_an Array - expect(json_response.map { |p| p['id'] }).to contain_exactly(project2.id) + expect(json_response.map { |p| p["id"] }).to contain_exactly(project2.id) end - it 'filters based on public visibility param' do - get api('/projects', user), params: { visibility: 'public' } + it "filters based on public visibility param" do + get api("/projects", user), params: {visibility: "public"} expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response).to be_an Array - expect(json_response.map { |p| p['id'] }).to contain_exactly(public_project.id) + expect(json_response.map { |p| p["id"] }).to contain_exactly(public_project.id) end end - context 'and using the programming language filter' do - include_context 'with language detection' + context "and using the programming language filter" do + include_context "with language detection" - it 'filters case-insensitively by programming language' do - get api('/projects', user), params: { with_programming_language: 'javascript' } + it "filters case-insensitively by programming language" do + get api("/projects", user), params: {with_programming_language: "javascript"} expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response).to be_an Array - expect(json_response.map { |p| p['id'] }).to contain_exactly(project3.id) + expect(json_response.map { |p| p["id"] }).to contain_exactly(project3.id) end end - context 'and using sorting' do - it 'returns the correct order when sorted by id' do - get api('/projects', user), params: { order_by: 'id', sort: 'desc' } + context "and using sorting" do + it "returns the correct order when sorted by id" do + get api("/projects", user), params: {order_by: "id", sort: "desc"} expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers 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 - context 'and with owned=true' do - it 'returns an array of projects the user owns' do - get api('/projects', user4), params: { owned: true } + context "and with owned=true" do + it "returns an array of projects the user owns" do + get api("/projects", user4), params: {owned: true} expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response).to be_an Array - expect(json_response.first['name']).to eq(project4.name) - expect(json_response.first['owner']['username']).to eq(user4.username) + expect(json_response.first["name"]).to eq(project4.name) + expect(json_response.first["owner"]["username"]).to eq(user4.username) end end - context 'and with starred=true' do + context "and with starred=true" do let(:public_project) { create(:project, :public) } before do @@ -435,99 +434,99 @@ describe API::Projects do user3.update(starred_projects: [project, project2, project3, public_project]) end - it 'returns the starred projects viewable by the user' do - get api('/projects', user3), params: { starred: true } + it "returns the starred projects viewable by the user" do + get api("/projects", user3), params: {starred: true} expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers 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 - context 'and with all query parameters' do - let!(:project5) { create(:project, :public, path: 'gitlab5', namespace: create(:namespace)) } + context "and with all query parameters" do + let!(:project5) { create(:project, :public, path: "gitlab5", namespace: create(:namespace)) } let!(:project6) { create(:project, :public, namespace: user.namespace) } - let!(:project7) { create(:project, :public, path: 'gitlab7', namespace: user.namespace) } - let!(:project8) { create(:project, path: 'gitlab8', namespace: user.namespace) } - let!(:project9) { create(:project, :public, path: 'gitlab9') } + let!(:project7) { create(:project, :public, path: "gitlab7", namespace: user.namespace) } + let!(:project8) { create(:project, path: "gitlab8", namespace: user.namespace) } + let!(:project9) { create(:project, :public, path: "gitlab9") } before do user.update(starred_projects: [project5, project7, project8, project9]) end - context 'including owned filter' do - it 'returns only projects that satisfy all query parameters' do - get api('/projects', user), params: { visibility: 'public', owned: true, starred: true, search: 'gitlab' } + context "including owned filter" do + it "returns only projects that satisfy all query parameters" do + get api("/projects", user), params: {visibility: "public", owned: true, starred: true, search: "gitlab"} expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response).to be_an Array expect(json_response.size).to eq(1) - expect(json_response.first['id']).to eq(project7.id) + expect(json_response.first["id"]).to eq(project7.id) end end - context 'including membership filter' do + context "including membership filter" do before do create(:project_member, - user: user, - project: project5, - access_level: ProjectMember::MAINTAINER) + user: user, + project: project5, + access_level: ProjectMember::MAINTAINER) end - it 'returns only projects that satisfy all query parameters' do - get api('/projects', user), params: { visibility: 'public', membership: true, starred: true, search: 'gitlab' } + it "returns only projects that satisfy all query parameters" do + get api("/projects", user), params: {visibility: "public", membership: true, starred: true, search: "gitlab"} expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response).to be_an Array expect(json_response.size).to eq(2) - expect(json_response.map { |project| project['id'] }).to contain_exactly(project5.id, project7.id) + expect(json_response.map { |project| project["id"] }).to contain_exactly(project5.id, project7.id) end end end - context 'and with min_access_level' do + context "and with min_access_level" do before do project2.add_maintainer(user2) project3.add_developer(user2) project4.add_reporter(user2) end - it 'returns an array of groups the user has at least developer access' do - get api('/projects', user2), params: { min_access_level: 30 } + it "returns an array of groups the user has at least developer access" do + get api("/projects", user2), params: {min_access_level: 30} expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response).to be_an Array - expect(json_response.map { |project| project['id'] }).to contain_exactly(project2.id, project3.id) + expect(json_response.map { |project| project["id"] }).to contain_exactly(project2.id, project3.id) end end end - context 'when authenticated as a different user' do - it_behaves_like 'projects response' do + context "when authenticated as a different user" do + it_behaves_like "projects response" do let(:filter) { {} } let(:current_user) { user2 } let(:projects) { [public_project] } end - context 'and with_issues_enabled=true' do - it 'does not return private issue projects' do + context "and with_issues_enabled=true" do + it "does not return private issue projects" do project.project_feature.update_attribute(:issues_access_level, ProjectFeature::PRIVATE) - get api('/projects?with_issues_enabled=true', user2) + get api("/projects?with_issues_enabled=true", user2) expect(response.status).to eq 200 expect(response).to include_pagination_headers expect(json_response).to be_an Array - expect(json_response.map { |p| p['id'] }).not_to include(project.id) + expect(json_response.map { |p| p["id"] }).not_to include(project.id) end end end - context 'when authenticated as admin' do - it_behaves_like 'projects response' do + context "when authenticated as admin" do + it_behaves_like "projects response" do let(:filter) { {} } let(:current_user) { admin } let(:projects) { Project.all } @@ -535,63 +534,63 @@ describe API::Projects do end end - describe 'POST /projects' do - context 'maximum number of projects reached' do - it 'does not create new project and respond with 403' do + describe "POST /projects" do + context "maximum number of projects reached" do + it "does not create new project and respond with 403" do allow_any_instance_of(User).to receive(:projects_limit_left).and_return(0) - expect { post api('/projects', user2), params: { name: 'foo' } } + expect { post api("/projects", user2), params: {name: "foo"} } .to change {Project.count}.by(0) expect(response).to have_gitlab_http_status(403) end end - it 'creates new project without path but with name and returns 201' do - expect { post api('/projects', user), params: { name: 'Foo Project' } } + it "creates new project without path but with name and returns 201" do + expect { post api("/projects", user), params: {name: "Foo Project"} } .to change { Project.count }.by(1) expect(response).to have_gitlab_http_status(201) project = Project.first - expect(project.name).to eq('Foo Project') - expect(project.path).to eq('foo-project') + expect(project.name).to eq("Foo Project") + expect(project.path).to eq("foo-project") end - it 'creates new project without name but with path and returns 201' do - expect { post api('/projects', user), params: { path: 'foo_project' } } + it "creates new project without name but with path and returns 201" do + expect { post api("/projects", user), params: {path: "foo_project"} } .to change { Project.count }.by(1) expect(response).to have_gitlab_http_status(201) project = Project.first - expect(project.name).to eq('foo_project') - expect(project.path).to eq('foo_project') + expect(project.name).to eq("foo_project") + expect(project.path).to eq("foo_project") end - it 'creates new project with name and path and returns 201' do - expect { post api('/projects', user), params: { path: 'path-project-Foo', name: 'Foo Project' } } + it "creates new project with name and path and returns 201" do + expect { post api("/projects", user), params: {path: "path-project-Foo", name: "Foo Project"} } .to change { Project.count }.by(1) expect(response).to have_gitlab_http_status(201) project = Project.first - expect(project.name).to eq('Foo Project') - expect(project.path).to eq('path-project-Foo') + expect(project.name).to eq("Foo Project") + expect(project.path).to eq("path-project-Foo") end - it 'creates last project before reaching project limit' do + it "creates last project before reaching project limit" do allow_any_instance_of(User).to receive(:projects_limit_left).and_return(1) - post api('/projects', user2), params: { name: 'foo' } + post api("/projects", user2), params: {name: "foo"} expect(response).to have_gitlab_http_status(201) end - it 'does not create new project without name or path and returns 400' do - expect { post api('/projects', user) }.not_to change { Project.count } + it "does not create new project without name or path and returns 400" do + expect { post api("/projects", user) }.not_to change { Project.count } expect(response).to have_gitlab_http_status(400) end it "assigns attributes to project" do project = attributes_for(:project, { - path: 'camelCasePath', + path: "camelCasePath", issues_enabled: false, jobs_enabled: false, merge_requests_enabled: false, @@ -600,11 +599,11 @@ describe API::Projects do only_allow_merge_if_pipeline_succeeds: false, request_access_enabled: true, only_allow_merge_if_all_discussions_are_resolved: false, - ci_config_path: 'a/custom/path', - merge_method: 'ff' + ci_config_path: "a/custom/path", + merge_method: "ff", }) - post api('/projects', user), params: project + post api("/projects", user), params: project expect(response).to have_gitlab_http_status(201) @@ -621,252 +620,252 @@ describe API::Projects do expect(project.project_feature.wiki_access_level).to eq(ProjectFeature::DISABLED) end - it 'sets a project as public' do - project = attributes_for(:project, visibility: 'public') + it "sets a project as public" do + project = attributes_for(:project, visibility: "public") - post api('/projects', user), params: project + post api("/projects", user), params: project - expect(json_response['visibility']).to eq('public') + expect(json_response["visibility"]).to eq("public") end - it 'sets a project as internal' do - project = attributes_for(:project, visibility: 'internal') + it "sets a project as internal" do + project = attributes_for(:project, visibility: "internal") - post api('/projects', user), params: project + post api("/projects", user), params: project - expect(json_response['visibility']).to eq('internal') + expect(json_response["visibility"]).to eq("internal") end - it 'sets a project as private' do - project = attributes_for(:project, visibility: 'private') + it "sets a project as private" do + project = attributes_for(:project, visibility: "private") - post api('/projects', user), params: project + post api("/projects", user), params: project - expect(json_response['visibility']).to eq('private') + expect(json_response["visibility"]).to eq("private") end - it 'creates a new project initialized with a README.md' do - project = attributes_for(:project, initialize_with_readme: 1, name: 'somewhere') + it "creates a new project initialized with a README.md" do + project = attributes_for(:project, initialize_with_readme: 1, name: "somewhere") - post api('/projects', user), params: project + post api("/projects", user), params: project - expect(json_response['readme_url']).to eql("#{Gitlab.config.gitlab.url}/#{json_response['namespace']['full_path']}/somewhere/blob/master/README.md") + expect(json_response["readme_url"]).to eql("#{Gitlab.config.gitlab.url}/#{json_response["namespace"]["full_path"]}/somewhere/blob/master/README.md") end - it 'sets tag list to a project' do + it "sets tag list to a project" do project = attributes_for(:project, tag_list: %w[tagFirst tagSecond]) - post api('/projects', user), params: project + post api("/projects", user), params: project - expect(json_response['tag_list']).to eq(%w[tagFirst tagSecond]) + expect(json_response["tag_list"]).to eq(%w[tagFirst tagSecond]) end - it 'uploads avatar for project a project' do - project = attributes_for(:project, avatar: fixture_file_upload('spec/fixtures/banana_sample.gif', 'image/gif')) + it "uploads avatar for project a project" do + project = attributes_for(:project, avatar: fixture_file_upload("spec/fixtures/banana_sample.gif", "image/gif")) - post api('/projects', user), params: project + post api("/projects", user), params: project - project_id = json_response['id'] - expect(json_response['avatar_url']).to eq("http://localhost/uploads/-/system/project/avatar/#{project_id}/banana_sample.gif") + project_id = json_response["id"] + expect(json_response["avatar_url"]).to eq("http://localhost/uploads/-/system/project/avatar/#{project_id}/banana_sample.gif") end - it 'sets a project as not allowing outdated diff discussions to automatically resolve' do + it "sets a project as not allowing outdated diff discussions to automatically resolve" do project = attributes_for(:project, resolve_outdated_diff_discussions: false) - post api('/projects', user), params: project + post api("/projects", user), params: project - expect(json_response['resolve_outdated_diff_discussions']).to be_falsey + expect(json_response["resolve_outdated_diff_discussions"]).to be_falsey end - it 'sets a project as allowing outdated diff discussions to automatically resolve' do + it "sets a project as allowing outdated diff discussions to automatically resolve" do project = attributes_for(:project, resolve_outdated_diff_discussions: true) - post api('/projects', user), params: project + post api("/projects", user), params: project - expect(json_response['resolve_outdated_diff_discussions']).to be_truthy + expect(json_response["resolve_outdated_diff_discussions"]).to be_truthy end - it 'sets a project as allowing merge even if build fails' do + it "sets a project as allowing merge even if build fails" do project = attributes_for(:project, only_allow_merge_if_pipeline_succeeds: false) - post api('/projects', user), params: project + post api("/projects", user), params: project - expect(json_response['only_allow_merge_if_pipeline_succeeds']).to be_falsey + expect(json_response["only_allow_merge_if_pipeline_succeeds"]).to be_falsey end - it 'sets a project as allowing merge only if merge_when_pipeline_succeeds' do + it "sets a project as allowing merge only if merge_when_pipeline_succeeds" do project = attributes_for(:project, only_allow_merge_if_pipeline_succeeds: true) - post api('/projects', user), params: project + post api("/projects", user), params: project - expect(json_response['only_allow_merge_if_pipeline_succeeds']).to be_truthy + expect(json_response["only_allow_merge_if_pipeline_succeeds"]).to be_truthy end - it 'sets a project as allowing merge even if discussions are unresolved' do + it "sets a project as allowing merge even if discussions are unresolved" do project = attributes_for(:project, only_allow_merge_if_all_discussions_are_resolved: false) - post api('/projects', user), params: project + post api("/projects", user), params: project - expect(json_response['only_allow_merge_if_all_discussions_are_resolved']).to be_falsey + expect(json_response["only_allow_merge_if_all_discussions_are_resolved"]).to be_falsey end - it 'sets a project as allowing merge if only_allow_merge_if_all_discussions_are_resolved is nil' do + it "sets a project as allowing merge if only_allow_merge_if_all_discussions_are_resolved is nil" do project = attributes_for(:project, only_allow_merge_if_all_discussions_are_resolved: nil) - post api('/projects', user), params: project + post api("/projects", user), params: project - expect(json_response['only_allow_merge_if_all_discussions_are_resolved']).to be_falsey + expect(json_response["only_allow_merge_if_all_discussions_are_resolved"]).to be_falsey end - it 'sets a project as allowing merge only if all discussions are resolved' do + it "sets a project as allowing merge only if all discussions are resolved" do project = attributes_for(:project, only_allow_merge_if_all_discussions_are_resolved: true) - post api('/projects', user), params: project + post api("/projects", user), params: project - expect(json_response['only_allow_merge_if_all_discussions_are_resolved']).to be_truthy + expect(json_response["only_allow_merge_if_all_discussions_are_resolved"]).to be_truthy end - it 'sets the merge method of a project to rebase merge' do - project = attributes_for(:project, merge_method: 'rebase_merge') + it "sets the merge method of a project to rebase merge" do + project = attributes_for(:project, merge_method: "rebase_merge") - post api('/projects', user), params: project + post api("/projects", user), params: project - expect(json_response['merge_method']).to eq('rebase_merge') + expect(json_response["merge_method"]).to eq("rebase_merge") end - it 'rejects invalid values for merge_method' do - project = attributes_for(:project, merge_method: 'totally_not_valid_method') + it "rejects invalid values for merge_method" do + project = attributes_for(:project, merge_method: "totally_not_valid_method") - post api('/projects', user), params: project + post api("/projects", user), params: project expect(response).to have_gitlab_http_status(400) end - it 'ignores import_url when it is nil' do + it "ignores import_url when it is nil" do project = attributes_for(:project, import_url: nil) - post api('/projects', user), params: project + post api("/projects", user), params: project expect(response).to have_gitlab_http_status(201) end - context 'when a visibility level is restricted' do - let(:project_param) { attributes_for(:project, visibility: 'public') } + context "when a visibility level is restricted" do + let(:project_param) { attributes_for(:project, visibility: "public") } before do stub_application_setting(restricted_visibility_levels: [Gitlab::VisibilityLevel::PUBLIC]) end - it 'does not allow a non-admin to use a restricted visibility level' do - post api('/projects', user), params: project_param + it "does not allow a non-admin to use a restricted visibility level" do + post api("/projects", user), params: project_param expect(response).to have_gitlab_http_status(400) - expect(json_response['message']['visibility_level'].first).to( - match('restricted by your GitLab administrator') + expect(json_response["message"]["visibility_level"].first).to( + match("restricted by your GitLab administrator") ) end - it 'allows an admin to override restricted visibility settings' do - post api('/projects', admin), params: project_param + it "allows an admin to override restricted visibility settings" do + post api("/projects", admin), params: project_param - expect(json_response['visibility']).to eq('public') + expect(json_response["visibility"]).to eq("public") end end end - describe 'GET /users/:user_id/projects/' do - let!(:public_project) { create(:project, :public, name: 'public_project', creator_id: user4.id, namespace: user4.namespace) } + describe "GET /users/:user_id/projects/" do + let!(:public_project) { create(:project, :public, name: "public_project", creator_id: user4.id, namespace: user4.namespace) } - it 'returns error when user not found' do - get api('/users/0/projects/') + it "returns error when user not found" do + get api("/users/0/projects/") expect(response).to have_gitlab_http_status(404) - expect(json_response['message']).to eq('404 User Not Found') + expect(json_response["message"]).to eq("404 User Not Found") end - it 'returns projects filtered by user id' do + it "returns projects filtered by user id" do get api("/users/#{user4.id}/projects/", user) expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response).to be_an Array - expect(json_response.map { |project| project['id'] }).to contain_exactly(public_project.id) + expect(json_response.map { |project| project["id"] }).to contain_exactly(public_project.id) end - it 'returns projects filtered by username' do + it "returns projects filtered by username" do get api("/users/#{user4.username}/projects/", user) expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response).to be_an Array - expect(json_response.map { |project| project['id'] }).to contain_exactly(public_project.id) + expect(json_response.map { |project| project["id"] }).to contain_exactly(public_project.id) end - it 'returns projects filtered by minimal access level' do - private_project1 = create(:project, :private, name: 'private_project1', creator_id: user4.id, namespace: user4.namespace) - private_project2 = create(:project, :private, name: 'private_project2', creator_id: user4.id, namespace: user4.namespace) + it "returns projects filtered by minimal access level" do + private_project1 = create(:project, :private, name: "private_project1", creator_id: user4.id, namespace: user4.namespace) + private_project2 = create(:project, :private, name: "private_project2", creator_id: user4.id, namespace: user4.namespace) private_project1.add_developer(user2) private_project2.add_reporter(user2) - get api("/users/#{user4.id}/projects/", user2), params: { min_access_level: 30 } + get api("/users/#{user4.id}/projects/", user2), params: {min_access_level: 30} expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response).to be_an Array - expect(json_response.map { |project| project['id'] }).to contain_exactly(private_project1.id) + expect(json_response.map { |project| project["id"] }).to contain_exactly(private_project1.id) end - context 'and using the programming language filter' do - include_context 'with language detection' + context "and using the programming language filter" do + include_context "with language detection" - it 'filters case-insensitively by programming language' do - get api('/projects', user), params: { with_programming_language: 'ruby' } + it "filters case-insensitively by programming language" do + get api("/projects", user), params: {with_programming_language: "ruby"} expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response).to be_an Array - expect(json_response.map { |p| p['id'] }).to contain_exactly(project.id) + expect(json_response.map { |p| p["id"] }).to contain_exactly(project.id) end end end - describe 'POST /projects/user/:id' do - it 'creates new project without path but with name and return 201' do - expect { post api("/projects/user/#{user.id}", admin), params: { name: 'Foo Project' } }.to change { Project.count }.by(1) + describe "POST /projects/user/:id" do + it "creates new project without path but with name and return 201" do + expect { post api("/projects/user/#{user.id}", admin), params: {name: "Foo Project"} }.to change { Project.count }.by(1) expect(response).to have_gitlab_http_status(201) project = Project.last - expect(project.name).to eq('Foo Project') - expect(project.path).to eq('foo-project') + expect(project.name).to eq("Foo Project") + expect(project.path).to eq("foo-project") end - it 'creates new project with name and path and returns 201' do - expect { post api("/projects/user/#{user.id}", admin), params: { path: 'path-project-Foo', name: 'Foo Project' } } + it "creates new project with name and path and returns 201" do + expect { post api("/projects/user/#{user.id}", admin), params: {path: "path-project-Foo", name: "Foo Project"} } .to change { Project.count }.by(1) expect(response).to have_gitlab_http_status(201) project = Project.last - expect(project.name).to eq('Foo Project') - expect(project.path).to eq('path-project-Foo') + expect(project.name).to eq("Foo Project") + expect(project.path).to eq("path-project-Foo") end - it 'responds with 400 on failure and not project' do + it "responds with 400 on failure and not project" do expect { post api("/projects/user/#{user.id}", admin) } .not_to change { Project.count } expect(response).to have_gitlab_http_status(400) - expect(json_response['error']).to eq('name is missing') + expect(json_response["error"]).to eq("name is missing") end - it 'assigns attributes to project' do + it "assigns attributes to project" do project = attributes_for(:project, { issues_enabled: false, merge_requests_enabled: false, wiki_enabled: false, request_access_enabled: true, - jobs_enabled: true + jobs_enabled: true, }) post api("/projects/user/#{user.id}", admin), params: project @@ -880,74 +879,74 @@ describe API::Projects do end end - it 'sets a project as public' do - project = attributes_for(:project, visibility: 'public') + it "sets a project as public" do + project = attributes_for(:project, visibility: "public") post api("/projects/user/#{user.id}", admin), params: project expect(response).to have_gitlab_http_status(201) - expect(json_response['visibility']).to eq('public') + expect(json_response["visibility"]).to eq("public") end - it 'sets a project as internal' do - project = attributes_for(:project, visibility: 'internal') + it "sets a project as internal" do + project = attributes_for(:project, visibility: "internal") post api("/projects/user/#{user.id}", admin), params: project expect(response).to have_gitlab_http_status(201) - expect(json_response['visibility']).to eq('internal') + expect(json_response["visibility"]).to eq("internal") end - it 'sets a project as private' do - project = attributes_for(:project, visibility: 'private') + it "sets a project as private" do + project = attributes_for(:project, visibility: "private") post api("/projects/user/#{user.id}", admin), params: project - expect(json_response['visibility']).to eq('private') + expect(json_response["visibility"]).to eq("private") end - it 'sets a project as not allowing outdated diff discussions to automatically resolve' do + it "sets a project as not allowing outdated diff discussions to automatically resolve" do project = attributes_for(:project, resolve_outdated_diff_discussions: false) post api("/projects/user/#{user.id}", admin), params: project - expect(json_response['resolve_outdated_diff_discussions']).to be_falsey + expect(json_response["resolve_outdated_diff_discussions"]).to be_falsey end - it 'sets a project as allowing outdated diff discussions to automatically resolve' do + it "sets a project as allowing outdated diff discussions to automatically resolve" do project = attributes_for(:project, resolve_outdated_diff_discussions: true) post api("/projects/user/#{user.id}", admin), params: project - expect(json_response['resolve_outdated_diff_discussions']).to be_truthy + expect(json_response["resolve_outdated_diff_discussions"]).to be_truthy end - it 'sets a project as allowing merge even if build fails' do + it "sets a project as allowing merge even if build fails" do project = attributes_for(:project, only_allow_merge_if_pipeline_succeeds: false) post api("/projects/user/#{user.id}", admin), params: project - expect(json_response['only_allow_merge_if_pipeline_succeeds']).to be_falsey + expect(json_response["only_allow_merge_if_pipeline_succeeds"]).to be_falsey end - it 'sets a project as allowing merge only if pipeline succeeds' do + it "sets a project as allowing merge only if pipeline succeeds" do project = attributes_for(:project, only_allow_merge_if_pipeline_succeeds: true) post api("/projects/user/#{user.id}", admin), params: project - expect(json_response['only_allow_merge_if_pipeline_succeeds']).to be_truthy + expect(json_response["only_allow_merge_if_pipeline_succeeds"]).to be_truthy end - it 'sets a project as allowing merge even if discussions are unresolved' do + it "sets a project as allowing merge even if discussions are unresolved" do project = attributes_for(:project, only_allow_merge_if_all_discussions_are_resolved: false) post api("/projects/user/#{user.id}", admin), params: project - expect(json_response['only_allow_merge_if_all_discussions_are_resolved']).to be_falsey + expect(json_response["only_allow_merge_if_all_discussions_are_resolved"]).to be_falsey end - it 'sets a project as allowing merge only if all discussions are resolved' do + it "sets a project as allowing merge only if all discussions are resolved" do project = attributes_for(:project, only_allow_merge_if_all_discussions_are_resolved: true) post api("/projects/user/#{user.id}", admin), params: project - expect(json_response['only_allow_merge_if_all_discussions_are_resolved']).to be_truthy + expect(json_response["only_allow_merge_if_all_discussions_are_resolved"]).to be_truthy end end @@ -957,142 +956,142 @@ describe API::Projects do end it "uploads the file and returns its info" do - post api("/projects/#{project.id}/uploads", user), params: { file: fixture_file_upload("spec/fixtures/dk.png", "image/png") } + post api("/projects/#{project.id}/uploads", user), params: {file: fixture_file_upload("spec/fixtures/dk.png", "image/png")} expect(response).to have_gitlab_http_status(201) - expect(json_response['alt']).to eq("dk") - expect(json_response['url']).to start_with("/uploads/") - expect(json_response['url']).to end_with("/dk.png") + expect(json_response["alt"]).to eq("dk") + expect(json_response["url"]).to start_with("/uploads/") + expect(json_response["url"]).to end_with("/dk.png") end end - describe 'GET /projects/:id' do - context 'when unauthenticated' do - it 'returns the public projects' do + describe "GET /projects/:id" do + context "when unauthenticated" do + it "returns the public projects" do public_project = create(:project, :public) get api("/projects/#{public_project.id}") expect(response).to have_gitlab_http_status(200) - expect(json_response['id']).to eq(public_project.id) - expect(json_response['description']).to eq(public_project.description) - expect(json_response['default_branch']).to eq(public_project.default_branch) - expect(json_response.keys).not_to include('permissions') + expect(json_response["id"]).to eq(public_project.id) + expect(json_response["description"]).to eq(public_project.description) + expect(json_response["default_branch"]).to eq(public_project.default_branch) + expect(json_response.keys).not_to include("permissions") end end - context 'when authenticated' do + context "when authenticated" do before do project project_member end - it 'returns a project by id' do + it "returns a project by id" do group = create(:group) link = create(:project_group_link, project: project, group: group) get api("/projects/#{project.id}", user) expect(response).to have_gitlab_http_status(200) - expect(json_response['id']).to eq(project.id) - expect(json_response['description']).to eq(project.description) - expect(json_response['default_branch']).to eq(project.default_branch) - expect(json_response['tag_list']).to be_an Array - expect(json_response['archived']).to be_falsey - expect(json_response['visibility']).to be_present - expect(json_response['ssh_url_to_repo']).to be_present - expect(json_response['http_url_to_repo']).to be_present - expect(json_response['web_url']).to be_present - expect(json_response['owner']).to be_a Hash - expect(json_response['owner']).to be_a Hash - expect(json_response['name']).to eq(project.name) - expect(json_response['path']).to be_present - expect(json_response['issues_enabled']).to be_present - expect(json_response['merge_requests_enabled']).to be_present - expect(json_response['wiki_enabled']).to be_present - expect(json_response['jobs_enabled']).to be_present - expect(json_response['snippets_enabled']).to be_present - expect(json_response['resolve_outdated_diff_discussions']).to eq(project.resolve_outdated_diff_discussions) - expect(json_response['container_registry_enabled']).to be_present - expect(json_response['created_at']).to be_present - expect(json_response['last_activity_at']).to be_present - expect(json_response['shared_runners_enabled']).to be_present - expect(json_response['creator_id']).to be_present - expect(json_response['namespace']).to be_present - expect(json_response['import_status']).to be_present + expect(json_response["id"]).to eq(project.id) + expect(json_response["description"]).to eq(project.description) + expect(json_response["default_branch"]).to eq(project.default_branch) + expect(json_response["tag_list"]).to be_an Array + expect(json_response["archived"]).to be_falsey + expect(json_response["visibility"]).to be_present + expect(json_response["ssh_url_to_repo"]).to be_present + expect(json_response["http_url_to_repo"]).to be_present + expect(json_response["web_url"]).to be_present + expect(json_response["owner"]).to be_a Hash + expect(json_response["owner"]).to be_a Hash + expect(json_response["name"]).to eq(project.name) + expect(json_response["path"]).to be_present + expect(json_response["issues_enabled"]).to be_present + expect(json_response["merge_requests_enabled"]).to be_present + expect(json_response["wiki_enabled"]).to be_present + expect(json_response["jobs_enabled"]).to be_present + expect(json_response["snippets_enabled"]).to be_present + expect(json_response["resolve_outdated_diff_discussions"]).to eq(project.resolve_outdated_diff_discussions) + expect(json_response["container_registry_enabled"]).to be_present + expect(json_response["created_at"]).to be_present + expect(json_response["last_activity_at"]).to be_present + expect(json_response["shared_runners_enabled"]).to be_present + expect(json_response["creator_id"]).to be_present + expect(json_response["namespace"]).to be_present + expect(json_response["import_status"]).to be_present expect(json_response).to include("import_error") - expect(json_response['avatar_url']).to be_nil - expect(json_response['star_count']).to be_present - expect(json_response['forks_count']).to be_present - expect(json_response['public_jobs']).to be_present - expect(json_response['ci_config_path']).to be_nil - expect(json_response['shared_with_groups']).to be_an Array - expect(json_response['shared_with_groups'].length).to eq(1) - expect(json_response['shared_with_groups'][0]['group_id']).to eq(group.id) - expect(json_response['shared_with_groups'][0]['group_name']).to eq(group.name) - expect(json_response['shared_with_groups'][0]['group_full_path']).to eq(group.full_path) - expect(json_response['shared_with_groups'][0]['group_access_level']).to eq(link.group_access) - expect(json_response['shared_with_groups'][0]['expires_at']).to be_nil - expect(json_response['only_allow_merge_if_pipeline_succeeds']).to eq(project.only_allow_merge_if_pipeline_succeeds) - expect(json_response['only_allow_merge_if_all_discussions_are_resolved']).to eq(project.only_allow_merge_if_all_discussions_are_resolved) - expect(json_response['merge_method']).to eq(project.merge_method.to_s) - expect(json_response['readme_url']).to eq(project.readme_url) - end - - it 'returns a group link with expiration date' do + expect(json_response["avatar_url"]).to be_nil + expect(json_response["star_count"]).to be_present + expect(json_response["forks_count"]).to be_present + expect(json_response["public_jobs"]).to be_present + expect(json_response["ci_config_path"]).to be_nil + expect(json_response["shared_with_groups"]).to be_an Array + expect(json_response["shared_with_groups"].length).to eq(1) + expect(json_response["shared_with_groups"][0]["group_id"]).to eq(group.id) + expect(json_response["shared_with_groups"][0]["group_name"]).to eq(group.name) + expect(json_response["shared_with_groups"][0]["group_full_path"]).to eq(group.full_path) + expect(json_response["shared_with_groups"][0]["group_access_level"]).to eq(link.group_access) + expect(json_response["shared_with_groups"][0]["expires_at"]).to be_nil + expect(json_response["only_allow_merge_if_pipeline_succeeds"]).to eq(project.only_allow_merge_if_pipeline_succeeds) + expect(json_response["only_allow_merge_if_all_discussions_are_resolved"]).to eq(project.only_allow_merge_if_all_discussions_are_resolved) + expect(json_response["merge_method"]).to eq(project.merge_method.to_s) + expect(json_response["readme_url"]).to eq(project.readme_url) + end + + it "returns a group link with expiration date" do group = create(:group) expires_at = 5.days.from_now.to_date link = create(:project_group_link, project: project, group: group, expires_at: expires_at) get api("/projects/#{project.id}", user) - expect(json_response['shared_with_groups']).to be_an Array - expect(json_response['shared_with_groups'].length).to eq(1) - expect(json_response['shared_with_groups'][0]['group_id']).to eq(group.id) - expect(json_response['shared_with_groups'][0]['group_name']).to eq(group.name) - expect(json_response['shared_with_groups'][0]['group_full_path']).to eq(group.full_path) - expect(json_response['shared_with_groups'][0]['group_access_level']).to eq(link.group_access) - expect(json_response['shared_with_groups'][0]['expires_at']).to eq(expires_at.to_s) + expect(json_response["shared_with_groups"]).to be_an Array + expect(json_response["shared_with_groups"].length).to eq(1) + expect(json_response["shared_with_groups"][0]["group_id"]).to eq(group.id) + expect(json_response["shared_with_groups"][0]["group_name"]).to eq(group.name) + expect(json_response["shared_with_groups"][0]["group_full_path"]).to eq(group.full_path) + expect(json_response["shared_with_groups"][0]["group_access_level"]).to eq(link.group_access) + expect(json_response["shared_with_groups"][0]["expires_at"]).to eq(expires_at.to_s) end - it 'returns a project by path name' do + it "returns a project by path name" do get api("/projects/#{project.id}", user) expect(response).to have_gitlab_http_status(200) - expect(json_response['name']).to eq(project.name) + expect(json_response["name"]).to eq(project.name) end - it 'returns a 404 error if not found' do - get api('/projects/42', user) + it "returns a 404 error if not found" do + get api("/projects/42", user) expect(response).to have_gitlab_http_status(404) - expect(json_response['message']).to eq('404 Project Not Found') + expect(json_response["message"]).to eq("404 Project Not Found") end - it 'returns a 404 error if user is not a member' do + it "returns a 404 error if user is not a member" do other_user = create(:user) get api("/projects/#{project.id}", other_user) expect(response).to have_gitlab_http_status(404) end - it 'handles users with dots' do - dot_user = create(:user, username: 'dot.user') + it "handles users with dots" do + dot_user = create(:user, username: "dot.user") project = create(:project, creator_id: dot_user.id, namespace: dot_user.namespace) get api("/projects/#{CGI.escape(project.full_path)}", dot_user) expect(response).to have_gitlab_http_status(200) - expect(json_response['name']).to eq(project.name) + expect(json_response["name"]).to eq(project.name) end - it 'exposes namespace fields' do + it "exposes namespace fields" do get api("/projects/#{project.id}", user) expect(response).to have_gitlab_http_status(200) - expect(json_response['namespace']).to eq({ - 'id' => user.namespace.id, - 'name' => user.namespace.name, - 'path' => user.namespace.path, - 'kind' => user.namespace.kind, - 'full_path' => user.namespace.full_path, - 'parent_id' => nil + expect(json_response["namespace"]).to eq({ + "id" => user.namespace.id, + "name" => user.namespace.name, + "path" => user.namespace.path, + "kind" => user.namespace.kind, + "full_path" => user.namespace.full_path, + "parent_id" => nil, }) end @@ -1100,19 +1099,19 @@ describe API::Projects do get api("/projects/#{project.id}", user) expect(response).to have_gitlab_http_status(200) - expect(json_response).not_to include('license', 'license_url') + expect(json_response).not_to include("license", "license_url") end - it 'includes license fields when requested' do - get api("/projects/#{project.id}", user), params: { license: true } + it "includes license fields when requested" do + get api("/projects/#{project.id}", user), params: {license: true} expect(response).to have_gitlab_http_status(200) - expect(json_response['license']).to eq({ - 'key' => project.repository.license.key, - 'name' => project.repository.license.name, - 'nickname' => project.repository.license.nickname, - 'html_url' => project.repository.license.url, - 'source_url' => project.repository.license.meta['source'] + expect(json_response["license"]).to eq({ + "key" => project.repository.license.key, + "name" => project.repository.license.name, + "nickname" => project.repository.license.nickname, + "html_url" => project.repository.license.url, + "source_url" => project.repository.license.meta["source"], }) end @@ -1120,14 +1119,14 @@ describe API::Projects do get api("/projects/#{project.id}", user) expect(response).to have_gitlab_http_status(200) - expect(json_response).not_to include 'statistics' + expect(json_response).not_to include "statistics" end it "includes statistics if requested" do - get api("/projects/#{project.id}", user), params: { statistics: true } + get api("/projects/#{project.id}", user), params: {statistics: true} expect(response).to have_gitlab_http_status(200) - expect(json_response).to include 'statistics' + expect(json_response).to include "statistics" end it "includes import_error if user can admin project" do @@ -1144,93 +1143,93 @@ describe API::Projects do expect(json_response).not_to include("import_error") end - it 'returns 404 when project is marked for deletion' do + it "returns 404 when project is marked for deletion" do project.update(pending_delete: true) get api("/projects/#{project.id}", user) expect(response).to have_gitlab_http_status(404) - expect(json_response['message']).to eq('404 Project Not Found') + expect(json_response["message"]).to eq("404 Project Not Found") end - context 'links exposure' do - it 'exposes related resources full URIs' do + context "links exposure" do + it "exposes related resources full URIs" do get api("/projects/#{project.id}", user) - links = json_response['_links'] + links = json_response["_links"] - expect(links['self']).to end_with("/api/v4/projects/#{project.id}") - expect(links['issues']).to end_with("/api/v4/projects/#{project.id}/issues") - expect(links['merge_requests']).to end_with("/api/v4/projects/#{project.id}/merge_requests") - expect(links['repo_branches']).to end_with("/api/v4/projects/#{project.id}/repository/branches") - expect(links['labels']).to end_with("/api/v4/projects/#{project.id}/labels") - expect(links['events']).to end_with("/api/v4/projects/#{project.id}/events") - expect(links['members']).to end_with("/api/v4/projects/#{project.id}/members") + expect(links["self"]).to end_with("/api/v4/projects/#{project.id}") + expect(links["issues"]).to end_with("/api/v4/projects/#{project.id}/issues") + expect(links["merge_requests"]).to end_with("/api/v4/projects/#{project.id}/merge_requests") + expect(links["repo_branches"]).to end_with("/api/v4/projects/#{project.id}/repository/branches") + expect(links["labels"]).to end_with("/api/v4/projects/#{project.id}/labels") + expect(links["events"]).to end_with("/api/v4/projects/#{project.id}/events") + expect(links["members"]).to end_with("/api/v4/projects/#{project.id}/members") end - it 'filters related URIs when their feature is not enabled' do + it "filters related URIs when their feature is not enabled" do project = create(:project, :public, - :merge_requests_disabled, - :issues_disabled, - creator_id: user.id, - namespace: user.namespace) + :merge_requests_disabled, + :issues_disabled, + creator_id: user.id, + namespace: user.namespace) get api("/projects/#{project.id}", user) - links = json_response['_links'] + links = json_response["_links"] - expect(links.has_key?('merge_requests')).to be_falsy - expect(links.has_key?('issues')).to be_falsy - expect(links['self']).to end_with("/api/v4/projects/#{project.id}") + expect(links.key?("merge_requests")).to be_falsy + expect(links.key?("issues")).to be_falsy + expect(links["self"]).to end_with("/api/v4/projects/#{project.id}") end end - describe 'permissions' do - context 'all projects' do + describe "permissions" do + context "all projects" do before do project.add_maintainer(user) end - it 'contains permission information' do + it "contains permission information" do get api("/projects", user) expect(response).to have_gitlab_http_status(200) - expect(json_response.first['permissions']['project_access']['access_level']) - .to eq(Gitlab::Access::MAINTAINER) - expect(json_response.first['permissions']['group_access']).to be_nil + expect(json_response.first["permissions"]["project_access"]["access_level"]) + .to eq(Gitlab::Access::MAINTAINER) + expect(json_response.first["permissions"]["group_access"]).to be_nil end end - context 'personal project' do - it 'sets project access and returns 200' do + context "personal project" do + it "sets project access and returns 200" do project.add_maintainer(user) get api("/projects/#{project.id}", user) expect(response).to have_gitlab_http_status(200) - expect(json_response['permissions']['project_access']['access_level']) - .to eq(Gitlab::Access::MAINTAINER) - expect(json_response['permissions']['group_access']).to be_nil + expect(json_response["permissions"]["project_access"]["access_level"]) + .to eq(Gitlab::Access::MAINTAINER) + expect(json_response["permissions"]["group_access"]).to be_nil end end - context 'group project' do + context "group project" do let(:project2) { create(:project, group: create(:group)) } before do project2.group.add_owner(user) end - it 'sets the owner and return 200' do + it "sets the owner and return 200" do get api("/projects/#{project2.id}", user) expect(response).to have_gitlab_http_status(200) - expect(json_response['permissions']['project_access']).to be_nil - expect(json_response['permissions']['group_access']['access_level']) - .to eq(Gitlab::Access::OWNER) + expect(json_response["permissions"]["project_access"]).to be_nil + expect(json_response["permissions"]["group_access"]["access_level"]) + .to eq(Gitlab::Access::OWNER) end end - context 'nested group project', :nested_groups do + context "nested group project", :nested_groups do let(:group) { create(:group) } let(:nested_group) { create(:group, parent: group) } let(:project2) { create(:project, group: nested_group) } @@ -1239,27 +1238,27 @@ describe API::Projects do project2.group.parent.add_owner(user) end - it 'sets group access and return 200' do + it "sets group access and return 200" do get api("/projects/#{project2.id}", user) expect(response).to have_gitlab_http_status(200) - expect(json_response['permissions']['project_access']).to be_nil - expect(json_response['permissions']['group_access']['access_level']) - .to eq(Gitlab::Access::OWNER) + expect(json_response["permissions"]["project_access"]).to be_nil + expect(json_response["permissions"]["group_access"]["access_level"]) + .to eq(Gitlab::Access::OWNER) end - context 'with various access levels across nested groups' do + context "with various access levels across nested groups" do before do project2.group.add_maintainer(user) end - it 'sets the maximum group access and return 200' do + it "sets the maximum group access and return 200" do get api("/projects/#{project2.id}", user) expect(response).to have_gitlab_http_status(200) - expect(json_response['permissions']['project_access']).to be_nil - expect(json_response['permissions']['group_access']['access_level']) - .to eq(Gitlab::Access::OWNER) + expect(json_response["permissions"]["project_access"]).to be_nil + expect(json_response["permissions"]["group_access"]["access_level"]) + .to eq(Gitlab::Access::OWNER) end end end @@ -1267,9 +1266,9 @@ describe API::Projects do end end - describe 'GET /projects/:id/users' do - shared_examples_for 'project users response' do - it 'returns the project users' do + describe "GET /projects/:id/users" do + shared_examples_for "project users response" do + it "returns the project users" do get api("/projects/#{project.id}/users", current_user) user = project.namespace.owner @@ -1280,34 +1279,34 @@ describe API::Projects do expect(json_response.size).to eq(1) first_user = json_response.first - expect(first_user['username']).to eq(user.username) - expect(first_user['name']).to eq(user.name) - expect(first_user.keys).to contain_exactly(*%w[name username id state avatar_url web_url]) + expect(first_user["username"]).to eq(user.username) + expect(first_user["name"]).to eq(user.name) + expect(first_user.keys).to contain_exactly("name", "username", "id", "state", "avatar_url", "web_url") end end - context 'when unauthenticated' do - it_behaves_like 'project users response' do + context "when unauthenticated" do + it_behaves_like "project users response" do let(:project) { create(:project, :public) } let(:current_user) { nil } end end - context 'when authenticated' do - context 'valid request' do - it_behaves_like 'project users response' do + context "when authenticated" do + context "valid request" do + it_behaves_like "project users response" do let(:current_user) { user } end end - it 'returns a 404 error if not found' do - get api('/projects/42/users', user) + it "returns a 404 error if not found" do + get api("/projects/42/users", user) expect(response).to have_gitlab_http_status(404) - expect(json_response['message']).to eq('404 Project Not Found') + expect(json_response["message"]).to eq("404 Project Not Found") end - it 'returns a 404 error if user is not a member' do + it "returns a 404 error if user is not a member" do other_user = create(:user) get api("/projects/#{project.id}/users", other_user) @@ -1317,34 +1316,34 @@ describe API::Projects do end end - describe 'fork management' do + describe "fork management" do let(:project_fork_target) { create(:project) } let(:project_fork_source) { create(:project, :public) } let(:private_project_fork_source) { create(:project, :private) } - describe 'POST /projects/:id/fork/:forked_from_id' do - context 'user is a developer' do + describe "POST /projects/:id/fork/:forked_from_id" do + context "user is a developer" do before do project_fork_target.add_developer(user) end - it 'denies project to be forked from an existing project' do + it "denies project to be forked from an existing project" do post api("/projects/#{project_fork_target.id}/fork/#{project_fork_source.id}", user) expect(response).to have_gitlab_http_status(403) end end - it 'refreshes the forks count cache' do + it "refreshes the forks count cache" do expect(project_fork_source.forks_count).to be_zero end - context 'user is maintainer' do + context "user is maintainer" do before do project_fork_target.add_maintainer(user) end - it 'allows project to be forked from an existing project' do + it "allows project to be forked from an existing project" do expect(project_fork_target).not_to be_forked post api("/projects/#{project_fork_target.id}/fork/#{project_fork_source.id}", user) @@ -1356,15 +1355,15 @@ describe API::Projects do expect(project_fork_target).to be_forked end - it 'denies project to be forked from a private project' do + it "denies project to be forked from a private project" do post api("/projects/#{project_fork_target.id}/fork/#{private_project_fork_source.id}", user) expect(response).to have_gitlab_http_status(404) end end - context 'user is admin' do - it 'allows project to be forked from an existing project' do + context "user is admin" do + it "allows project to be forked from an existing project" do expect(project_fork_target).not_to be_forked post api("/projects/#{project_fork_target.id}/fork/#{project_fork_source.id}", admin) @@ -1372,24 +1371,24 @@ describe API::Projects do expect(response).to have_gitlab_http_status(201) end - it 'allows project to be forked from a private project' do + it "allows project to be forked from a private project" do post api("/projects/#{project_fork_target.id}/fork/#{private_project_fork_source.id}", admin) expect(response).to have_gitlab_http_status(201) end - it 'refreshes the forks count cachce' do - expect do + it "refreshes the forks count cachce" do + expect { post api("/projects/#{project_fork_target.id}/fork/#{project_fork_source.id}", admin) - end.to change(project_fork_source, :forks_count).by(1) + }.to change(project_fork_source, :forks_count).by(1) end - it 'fails if forked_from project which does not exist' do + it "fails if forked_from project which does not exist" do post api("/projects/#{project_fork_target.id}/fork/0", admin) expect(response).to have_gitlab_http_status(404) end - it 'fails with 409 if already forked' do + it "fails with 409 if already forked" do other_project_fork_source = create(:project, :public) Projects::ForkService.new(project_fork_source, admin).execute(project_fork_target) @@ -1404,13 +1403,13 @@ describe API::Projects do end end - describe 'DELETE /projects/:id/fork' do + describe "DELETE /projects/:id/fork" do it "is not visible to users outside group" do delete api("/projects/#{project_fork_target.id}/fork", user) expect(response).to have_gitlab_http_status(404) end - context 'when users belong to project group' do + context "when users belong to project group" do let(:project_fork_target) { create(:project, group: create(:group)) } before do @@ -1418,7 +1417,7 @@ describe API::Projects do project_fork_target.group.add_developer user2 end - context 'for a forked project' do + context "for a forked project" do before do post api("/projects/#{project_fork_target.id}/fork/#{project_fork_source.id}", admin) project_fork_target.reload @@ -1426,7 +1425,7 @@ describe API::Projects do expect(project_fork_target).to be_forked end - it 'makes forked project unforked' do + it "makes forked project unforked" do delete api("/projects/#{project_fork_target.id}/fork", admin) expect(response).to have_gitlab_http_status(204) @@ -1435,17 +1434,17 @@ describe API::Projects do expect(project_fork_target).not_to be_forked end - it_behaves_like '412 response' do + it_behaves_like "412 response" do let(:request) { api("/projects/#{project_fork_target.id}/fork", admin) } end end - it 'is forbidden to non-owner users' do + it "is forbidden to non-owner users" do delete api("/projects/#{project_fork_target.id}/fork", user2) expect(response).to have_gitlab_http_status(403) end - it 'is idempotent if not forked' do + it "is idempotent if not forked" do expect(project_fork_target.forked_from_project).to be_nil delete api("/projects/#{project_fork_target.id}/fork", admin) expect(response).to have_gitlab_http_status(304) @@ -1454,7 +1453,7 @@ describe API::Projects do end end - describe 'GET /projects/:id/forks' do + describe "GET /projects/:id/forks" do let(:private_fork) { create(:project, :private, :empty_repo) } let(:member) { create(:user) } let(:non_member) { create(:user) } @@ -1463,7 +1462,7 @@ describe API::Projects do private_fork.add_developer(member) end - context 'for a forked project' do + context "for a forked project" do before do post api("/projects/#{private_fork.id}/fork/#{project_fork_source.id}", admin) private_fork.reload @@ -1474,19 +1473,19 @@ describe API::Projects do expect(project_fork_source.forks).to include(private_fork) end - context 'for a user that can access the forks' do - it 'returns the forks' do + context "for a user that can access the forks" do + it "returns the forks" do get api("/projects/#{project_fork_source.id}/forks", member) expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response.length).to eq(1) - expect(json_response[0]['name']).to eq(private_fork.name) + expect(json_response[0]["name"]).to eq(private_fork.name) end end - context 'for a user that cannot access the forks' do - it 'returns an empty array' do + context "for a user that cannot access the forks" do + it "returns an empty array" do get api("/projects/#{project_fork_source.id}/forks", non_member) expect(response).to have_gitlab_http_status(200) @@ -1496,8 +1495,8 @@ describe API::Projects do end end - context 'for a non-forked project' do - it 'returns an empty array' do + context "for a non-forked project" do + it "returns an empty array" do get api("/projects/#{project_fork_source.id}/forks") expect(response).to have_gitlab_http_status(200) @@ -1514,94 +1513,94 @@ describe API::Projects do it "shares project with group" do expires_at = 10.days.from_now.to_date - expect do - post api("/projects/#{project.id}/share", user), params: { group_id: group.id, group_access: Gitlab::Access::DEVELOPER, expires_at: expires_at } - end.to change { ProjectGroupLink.count }.by(1) + expect { + post api("/projects/#{project.id}/share", user), params: {group_id: group.id, group_access: Gitlab::Access::DEVELOPER, expires_at: expires_at} + }.to change { ProjectGroupLink.count }.by(1) expect(response).to have_gitlab_http_status(201) - expect(json_response['group_id']).to eq(group.id) - expect(json_response['group_access']).to eq(Gitlab::Access::DEVELOPER) - expect(json_response['expires_at']).to eq(expires_at.to_s) + expect(json_response["group_id"]).to eq(group.id) + expect(json_response["group_access"]).to eq(Gitlab::Access::DEVELOPER) + expect(json_response["expires_at"]).to eq(expires_at.to_s) end it "returns a 400 error when group id is not given" do - post api("/projects/#{project.id}/share", user), params: { group_access: Gitlab::Access::DEVELOPER } + post api("/projects/#{project.id}/share", user), params: {group_access: Gitlab::Access::DEVELOPER} expect(response).to have_gitlab_http_status(400) end it "returns a 400 error when access level is not given" do - post api("/projects/#{project.id}/share", user), params: { group_id: group.id } + post api("/projects/#{project.id}/share", user), params: {group_id: group.id} expect(response).to have_gitlab_http_status(400) end it "returns a 400 error when sharing is disabled" do project.namespace.update(share_with_group_lock: true) - post api("/projects/#{project.id}/share", user), params: { group_id: group.id, group_access: Gitlab::Access::DEVELOPER } + post api("/projects/#{project.id}/share", user), params: {group_id: group.id, group_access: Gitlab::Access::DEVELOPER} expect(response).to have_gitlab_http_status(400) end - it 'returns a 404 error when user cannot read group' do + it "returns a 404 error when user cannot read group" do private_group = create(:group, :private) - post api("/projects/#{project.id}/share", user), params: { group_id: private_group.id, group_access: Gitlab::Access::DEVELOPER } + post api("/projects/#{project.id}/share", user), params: {group_id: private_group.id, group_access: Gitlab::Access::DEVELOPER} expect(response).to have_gitlab_http_status(404) end - it 'returns a 404 error when group does not exist' do - post api("/projects/#{project.id}/share", user), params: { group_id: 1234, group_access: Gitlab::Access::DEVELOPER } + it "returns a 404 error when group does not exist" do + post api("/projects/#{project.id}/share", user), params: {group_id: 1234, group_access: Gitlab::Access::DEVELOPER} expect(response).to have_gitlab_http_status(404) end it "returns a 400 error when wrong params passed" do - post api("/projects/#{project.id}/share", user), params: { group_id: group.id, group_access: 1234 } + post api("/projects/#{project.id}/share", user), params: {group_id: group.id, group_access: 1234} expect(response).to have_gitlab_http_status(400) - expect(json_response['error']).to eq 'group_access does not have a valid value' + expect(json_response["error"]).to eq "group_access does not have a valid value" end end - describe 'DELETE /projects/:id/share/:group_id' do - context 'for a valid group' do + describe "DELETE /projects/:id/share/:group_id" do + context "for a valid group" do let(:group) { create(:group, :public) } before do create(:project_group_link, group: group, project: project) end - it 'returns 204 when deleting a group share' do + it "returns 204 when deleting a group share" do delete api("/projects/#{project.id}/share/#{group.id}", user) expect(response).to have_gitlab_http_status(204) expect(project.project_group_links).to be_empty end - it_behaves_like '412 response' do + it_behaves_like "412 response" do let(:request) { api("/projects/#{project.id}/share/#{group.id}", user) } end end - it 'returns a 400 when group id is not an integer' do + it "returns a 400 when group id is not an integer" do delete api("/projects/#{project.id}/share/foo", user) expect(response).to have_gitlab_http_status(400) end - it 'returns a 404 error when group link does not exist' do + it "returns a 404 error when group link does not exist" do delete api("/projects/#{project.id}/share/1234", user) expect(response).to have_gitlab_http_status(404) end - it 'returns a 404 error when project does not exist' do + it "returns a 404 error when project does not exist" do delete api("/projects/123/share/1234", user) expect(response).to have_gitlab_http_status(404) end end - describe 'PUT /projects/:id' do + describe "PUT /projects/:id" do before do expect(project).to be_persisted expect(user).to be_persisted @@ -1613,18 +1612,18 @@ describe API::Projects do expect(project_member).to be_persisted end - it 'returns 400 when nothing sent' do + it "returns 400 when nothing sent" do project_param = {} put api("/projects/#{project.id}", user), params: project_param expect(response).to have_gitlab_http_status(400) - expect(json_response['error']).to match('at least one parameter must be provided') + expect(json_response["error"]).to match("at least one parameter must be provided") end - context 'when unauthenticated' do - it 'returns authentication error' do - project_param = { name: 'bar' } + context "when unauthenticated" do + it "returns authentication error" do + project_param = {name: "bar"} put api("/projects/#{project.id}"), params: project_param @@ -1632,9 +1631,9 @@ describe API::Projects do end end - context 'when authenticated as project owner' do - it 'updates name' do - project_param = { name: 'bar' } + context "when authenticated as project owner" do + it "updates name" do + project_param = {name: "bar"} put api("/projects/#{project.id}", user), params: project_param @@ -1645,8 +1644,8 @@ describe API::Projects do end end - it 'updates visibility_level' do - project_param = { visibility: 'public' } + it "updates visibility_level" do + project_param = {visibility: "public"} put api("/projects/#{project3.id}", user), params: project_param @@ -1657,9 +1656,9 @@ describe API::Projects do end end - it 'updates visibility_level from public to private' do - project3.update({ visibility_level: Gitlab::VisibilityLevel::PUBLIC }) - project_param = { visibility: 'private' } + it "updates visibility_level from public to private" do + project3.update({visibility_level: Gitlab::VisibilityLevel::PUBLIC}) + project_param = {visibility: "private"} put api("/projects/#{project3.id}", user), params: project_param @@ -1669,29 +1668,29 @@ describe API::Projects do expect(json_response[k.to_s]).to eq(v) end - expect(json_response['visibility']).to eq('private') + expect(json_response["visibility"]).to eq("private") end - it 'does not update name to existing name' do - project_param = { name: project3.name } + it "does not update name to existing name" do + project_param = {name: project3.name} put api("/projects/#{project.id}", user), params: project_param expect(response).to have_gitlab_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 - it 'updates request_access_enabled' do - project_param = { request_access_enabled: false } + it "updates request_access_enabled" do + project_param = {request_access_enabled: false} put api("/projects/#{project.id}", user), params: project_param expect(response).to have_gitlab_http_status(200) - expect(json_response['request_access_enabled']).to eq(false) + expect(json_response["request_access_enabled"]).to eq(false) end - it 'updates path & name to existing path & name in different namespace' do - project_param = { path: project4.path, name: project4.name } + it "updates path & name to existing path & name in different namespace" do + project_param = {path: project4.path, name: project4.name} put api("/projects/#{project3.id}", user), params: project_param @@ -1702,8 +1701,8 @@ describe API::Projects do end end - it 'updates jobs_enabled' do - project_param = { jobs_enabled: true } + it "updates jobs_enabled" do + project_param = {jobs_enabled: true} put api("/projects/#{project3.id}", user), params: project_param @@ -1714,8 +1713,8 @@ describe API::Projects do end end - it 'updates merge_method' do - project_param = { merge_method: 'ff' } + it "updates merge_method" do + project_param = {merge_method: "ff"} put api("/projects/#{project3.id}", user), params: project_param @@ -1726,32 +1725,32 @@ describe API::Projects do end end - it 'rejects to update merge_method when merge_method is invalid' do - project_param = { merge_method: 'invalid' } + it "rejects to update merge_method when merge_method is invalid" do + project_param = {merge_method: "invalid"} put api("/projects/#{project3.id}", user), params: project_param expect(response).to have_gitlab_http_status(400) end - it 'updates avatar' do + it "updates avatar" do project_param = { - avatar: fixture_file_upload('spec/fixtures/banana_sample.gif', - 'image/gif') + avatar: fixture_file_upload("spec/fixtures/banana_sample.gif", + "image/gif"), } put api("/projects/#{project3.id}", user), params: project_param expect(response).to have_gitlab_http_status(200) - expect(json_response['avatar_url']).to eq('http://localhost/uploads/'\ - '-/system/project/avatar/'\ + expect(json_response["avatar_url"]).to eq("http://localhost/uploads/"\ + "-/system/project/avatar/"\ "#{project3.id}/banana_sample.gif") end end - context 'when authenticated as project maintainer' do - it 'updates path' do - project_param = { path: 'bar' } + context "when authenticated as project maintainer" do + it "updates path" do + project_param = {path: "bar"} put api("/projects/#{project3.id}", user4), params: project_param expect(response).to have_gitlab_http_status(200) project_param.each_pair do |k, v| @@ -1759,13 +1758,13 @@ describe API::Projects do end end - it 'updates other attributes' do - project_param = { issues_enabled: true, - wiki_enabled: true, - snippets_enabled: true, - merge_requests_enabled: true, - merge_method: 'ff', - description: 'new description' } + it "updates other attributes" do + project_param = {issues_enabled: true, + wiki_enabled: true, + snippets_enabled: true, + merge_requests_enabled: true, + merge_method: "ff", + description: "new description",} put api("/projects/#{project3.id}", user4), params: project_param expect(response).to have_gitlab_http_status(200) @@ -1774,70 +1773,70 @@ describe API::Projects do end end - it 'does not update path to existing path' do - project_param = { path: project.path } + it "does not update path to existing path" do + project_param = {path: project.path} put api("/projects/#{project3.id}", user4), params: project_param expect(response).to have_gitlab_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 - it 'does not update name' do - project_param = { name: 'bar' } + it "does not update name" do + project_param = {name: "bar"} put api("/projects/#{project3.id}", user4), params: project_param expect(response).to have_gitlab_http_status(403) end - it 'does not update visibility_level' do - project_param = { visibility: 'public' } + it "does not update visibility_level" do + project_param = {visibility: "public"} put api("/projects/#{project3.id}", user4), params: project_param expect(response).to have_gitlab_http_status(403) end end - context 'when authenticated as project developer' do - it 'does not update other attributes' do - project_param = { path: 'bar', - issues_enabled: true, - wiki_enabled: true, - snippets_enabled: true, - merge_requests_enabled: true, - description: 'new description', - request_access_enabled: true } + context "when authenticated as project developer" do + it "does not update other attributes" do + project_param = {path: "bar", + issues_enabled: true, + wiki_enabled: true, + snippets_enabled: true, + merge_requests_enabled: true, + description: "new description", + request_access_enabled: true,} put api("/projects/#{project.id}", user3), params: project_param expect(response).to have_gitlab_http_status(403) end end end - describe 'POST /projects/:id/archive' do - context 'on an unarchived project' do - it 'archives the project' do + describe "POST /projects/:id/archive" do + context "on an unarchived project" do + it "archives the project" do post api("/projects/#{project.id}/archive", user) expect(response).to have_gitlab_http_status(201) - expect(json_response['archived']).to be_truthy + expect(json_response["archived"]).to be_truthy end end - context 'on an archived project' do + context "on an archived project" do before do ::Projects::UpdateService.new(project, user, archived: true).execute end - it 'remains archived' do + it "remains archived" do post api("/projects/#{project.id}/archive", user) expect(response).to have_gitlab_http_status(201) - expect(json_response['archived']).to be_truthy + expect(json_response["archived"]).to be_truthy end end - context 'user without archiving rights to the project' do + context "user without archiving rights to the project" do before do project.add_developer(user3) end - it 'rejects the action' do + it "rejects the action" do post api("/projects/#{project.id}/archive", user3) expect(response).to have_gitlab_http_status(403) @@ -1845,35 +1844,35 @@ describe API::Projects do end end - describe 'POST /projects/:id/unarchive' do - context 'on an unarchived project' do - it 'remains unarchived' do + describe "POST /projects/:id/unarchive" do + context "on an unarchived project" do + it "remains unarchived" do post api("/projects/#{project.id}/unarchive", user) expect(response).to have_gitlab_http_status(201) - expect(json_response['archived']).to be_falsey + expect(json_response["archived"]).to be_falsey end end - context 'on an archived project' do + context "on an archived project" do before do ::Projects::UpdateService.new(project, user, archived: true).execute end - it 'unarchives the project' do + it "unarchives the project" do post api("/projects/#{project.id}/unarchive", user) expect(response).to have_gitlab_http_status(201) - expect(json_response['archived']).to be_falsey + expect(json_response["archived"]).to be_falsey end end - context 'user without archiving rights to the project' do + context "user without archiving rights to the project" do before do project.add_developer(user3) end - it 'rejects the action' do + it "rejects the action" do post api("/projects/#{project.id}/unarchive", user3) expect(response).to have_gitlab_http_status(403) @@ -1881,23 +1880,23 @@ describe API::Projects do end end - describe 'POST /projects/:id/star' do - context 'on an unstarred project' do - it 'stars the project' do + describe "POST /projects/:id/star" do + context "on an unstarred project" do + it "stars the project" do expect { post api("/projects/#{project.id}/star", user) }.to change { project.reload.star_count }.by(1) expect(response).to have_gitlab_http_status(201) - expect(json_response['star_count']).to eq(1) + expect(json_response["star_count"]).to eq(1) end end - context 'on a starred project' do + context "on a starred project" do before do user.toggle_star(project) project.reload end - 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(response).to have_gitlab_http_status(304) @@ -1905,23 +1904,23 @@ describe API::Projects do end end - describe 'POST /projects/:id/unstar' do - context 'on a starred project' do + describe "POST /projects/:id/unstar" do + context "on a starred project" do before do user.toggle_star(project) project.reload end - it 'unstars the project' do + it "unstars the project" do expect { post api("/projects/#{project.id}/unstar", user) }.to change { project.reload.star_count }.by(-1) expect(response).to have_gitlab_http_status(201) - expect(json_response['star_count']).to eq(0) + expect(json_response["star_count"]).to eq(0) end end - context 'on an unstarred project' do - it 'does not modify the star count' do + context "on an unstarred project" do + it "does not modify the star count" do expect { post api("/projects/#{project.id}/unstar", user) }.not_to change { project.reload.star_count } expect(response).to have_gitlab_http_status(304) @@ -1929,35 +1928,35 @@ describe API::Projects do end end - describe 'GET /projects/:id/languages' do - context 'with an authorized user' do - it_behaves_like 'languages and percentages JSON response' do + describe "GET /projects/:id/languages" do + context "with an authorized user" do + it_behaves_like "languages and percentages JSON response" do let(:project) { project3 } end - it 'returns not_found(404) for not existing project' do + it "returns not_found(404) for not existing project" do get api("/projects/0/languages", user) expect(response).to have_gitlab_http_status(:not_found) end end - context 'with not authorized user' do - it 'returns not_found for existing but unauthorized project' do + context "with not authorized user" do + it "returns not_found for existing but unauthorized project" do get api("/projects/#{project3.id}/languages", user3) expect(response).to have_gitlab_http_status(:not_found) end end - context 'without user' do + context "without user" do let(:project_public) { create(:project, :public, :repository) } - it_behaves_like 'languages and percentages JSON response' do + it_behaves_like "languages and percentages JSON response" do let(:project) { project_public } end - it 'returns not_found for existing but unauthorized project' do + it "returns not_found for existing but unauthorized project" do get api("/projects/#{project3.id}/languages", nil) expect(response).to have_gitlab_http_status(:not_found) @@ -1965,59 +1964,59 @@ describe API::Projects do end end - describe 'DELETE /projects/:id' do - context 'when authenticated as user' do - it 'removes project' do + describe "DELETE /projects/:id" do + context "when authenticated as user" do + it "removes project" do delete api("/projects/#{project.id}", user) expect(response).to have_gitlab_http_status(202) - expect(json_response['message']).to eql('202 Accepted') + expect(json_response["message"]).to eql("202 Accepted") end - it_behaves_like '412 response' do + it_behaves_like "412 response" do let(:success_status) { 202 } let(:request) { api("/projects/#{project.id}", user) } end - it 'does not remove a project if not an owner' do + it "does not remove a project if not an owner" do user3 = create(:user) project.add_developer(user3) delete api("/projects/#{project.id}", user3) expect(response).to have_gitlab_http_status(403) end - it 'does not remove a non existing project' do - delete api('/projects/1328', user) + it "does not remove a non existing project" do + delete api("/projects/1328", user) expect(response).to have_gitlab_http_status(404) end - it 'does not remove a project not attached to user' do + it "does not remove a project not attached to user" do delete api("/projects/#{project.id}", user2) expect(response).to have_gitlab_http_status(404) end end - context 'when authenticated as admin' do - it 'removes any existing project' do + context "when authenticated as admin" do + it "removes any existing project" do delete api("/projects/#{project.id}", admin) expect(response).to have_gitlab_http_status(202) - expect(json_response['message']).to eql('202 Accepted') + expect(json_response["message"]).to eql("202 Accepted") end - it 'does not remove a non existing project' do - delete api('/projects/1328', admin) + it "does not remove a non existing project" do + delete api("/projects/1328", admin) expect(response).to have_gitlab_http_status(404) end - it_behaves_like '412 response' do + it_behaves_like "412 response" do let(:success_status) { 202 } let(:request) { api("/projects/#{project.id}", admin) } end end end - describe 'POST /projects/:id/fork' do + describe "POST /projects/:id/fork" do let(:project) do create(:project, :repository, creator: user, namespace: user.namespace) end @@ -2028,13 +2027,13 @@ describe API::Projects do let(:group) { create(:group) } let(:group2) do - group = create(:group, name: 'group2_name') + group = create(:group, name: "group2_name") group.add_maintainer(user2) group end let(:group3) do - group = create(:group, name: 'group3_name', parent: group2) + group = create(:group, name: "group3_name", parent: group2) group.add_owner(user2) group end @@ -2044,181 +2043,181 @@ describe API::Projects do project2.add_reporter(user2) end - context 'when authenticated' do - it 'forks if user has sufficient access to project' do + context "when authenticated" do + it "forks if user has sufficient access to project" do post api("/projects/#{project.id}/fork", user2) expect(response).to have_gitlab_http_status(201) - expect(json_response['name']).to eq(project.name) - expect(json_response['path']).to eq(project.path) - expect(json_response['owner']['id']).to eq(user2.id) - expect(json_response['namespace']['id']).to eq(user2.namespace.id) - expect(json_response['forked_from_project']['id']).to eq(project.id) - expect(json_response['import_status']).to eq('scheduled') + expect(json_response["name"]).to eq(project.name) + expect(json_response["path"]).to eq(project.path) + expect(json_response["owner"]["id"]).to eq(user2.id) + expect(json_response["namespace"]["id"]).to eq(user2.namespace.id) + expect(json_response["forked_from_project"]["id"]).to eq(project.id) + expect(json_response["import_status"]).to eq("scheduled") expect(json_response).to include("import_error") end - it 'forks if user is admin' do + it "forks if user is admin" do post api("/projects/#{project.id}/fork", admin) expect(response).to have_gitlab_http_status(201) - expect(json_response['name']).to eq(project.name) - expect(json_response['path']).to eq(project.path) - expect(json_response['owner']['id']).to eq(admin.id) - expect(json_response['namespace']['id']).to eq(admin.namespace.id) - expect(json_response['forked_from_project']['id']).to eq(project.id) - expect(json_response['import_status']).to eq('scheduled') + expect(json_response["name"]).to eq(project.name) + expect(json_response["path"]).to eq(project.path) + expect(json_response["owner"]["id"]).to eq(admin.id) + expect(json_response["namespace"]["id"]).to eq(admin.namespace.id) + expect(json_response["forked_from_project"]["id"]).to eq(project.id) + expect(json_response["import_status"]).to eq("scheduled") expect(json_response).to include("import_error") end - it 'fails on missing project access for the project to fork' do + it "fails on missing project access for the project to fork" do new_user = create(:user) post api("/projects/#{project.id}/fork", new_user) expect(response).to have_gitlab_http_status(404) - expect(json_response['message']).to eq('404 Project Not Found') + expect(json_response["message"]).to eq("404 Project Not Found") end - it 'fails if forked project exists in the user namespace' do + it "fails if forked project exists in the user namespace" do post api("/projects/#{project.id}/fork", user) expect(response).to have_gitlab_http_status(409) - 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"]["name"]).to eq(["has already been taken"]) + expect(json_response["message"]["path"]).to eq(["has already been taken"]) end - it 'fails if project to fork from does not exist' do - post api('/projects/424242/fork', user) + it "fails if project to fork from does not exist" do + post api("/projects/424242/fork", user) expect(response).to have_gitlab_http_status(404) - expect(json_response['message']).to eq('404 Project Not Found') + expect(json_response["message"]).to eq("404 Project Not Found") end - it 'forks with explicit own user namespace id' do - post api("/projects/#{project.id}/fork", user2), params: { namespace: user2.namespace.id } + it "forks with explicit own user namespace id" do + post api("/projects/#{project.id}/fork", user2), params: {namespace: user2.namespace.id} expect(response).to have_gitlab_http_status(201) - expect(json_response['owner']['id']).to eq(user2.id) + expect(json_response["owner"]["id"]).to eq(user2.id) end - it 'forks with explicit own user name as namespace' do - post api("/projects/#{project.id}/fork", user2), params: { namespace: user2.username } + it "forks with explicit own user name as namespace" do + post api("/projects/#{project.id}/fork", user2), params: {namespace: user2.username} expect(response).to have_gitlab_http_status(201) - expect(json_response['owner']['id']).to eq(user2.id) + expect(json_response["owner"]["id"]).to eq(user2.id) end - it 'forks to another user when admin' do - post api("/projects/#{project.id}/fork", admin), params: { namespace: user2.username } + it "forks to another user when admin" do + post api("/projects/#{project.id}/fork", admin), params: {namespace: user2.username} expect(response).to have_gitlab_http_status(201) - expect(json_response['owner']['id']).to eq(user2.id) + expect(json_response["owner"]["id"]).to eq(user2.id) end - it 'fails if trying to fork to another user when not admin' do - post api("/projects/#{project.id}/fork", user2), params: { namespace: admin.namespace.id } + it "fails if trying to fork to another user when not admin" do + post api("/projects/#{project.id}/fork", user2), params: {namespace: admin.namespace.id} expect(response).to have_gitlab_http_status(404) end - it 'fails if trying to fork to non-existent namespace' do - post api("/projects/#{project.id}/fork", user2), params: { namespace: 42424242 } + it "fails if trying to fork to non-existent namespace" do + post api("/projects/#{project.id}/fork", user2), params: {namespace: 42424242} expect(response).to have_gitlab_http_status(404) - expect(json_response['message']).to eq('404 Target Namespace Not Found') + expect(json_response["message"]).to eq("404 Target Namespace Not Found") end - it 'forks to owned group' do - post api("/projects/#{project.id}/fork", user2), params: { namespace: group2.name } + it "forks to owned group" do + post api("/projects/#{project.id}/fork", user2), params: {namespace: group2.name} expect(response).to have_gitlab_http_status(201) - expect(json_response['namespace']['name']).to eq(group2.name) + expect(json_response["namespace"]["name"]).to eq(group2.name) end - it 'forks to owned subgroup' do + it "forks to owned subgroup" do full_path = "#{group2.path}/#{group3.path}" - post api("/projects/#{project.id}/fork", user2), params: { namespace: full_path } + post api("/projects/#{project.id}/fork", user2), params: {namespace: full_path} expect(response).to have_gitlab_http_status(201) - expect(json_response['namespace']['name']).to eq(group3.name) - expect(json_response['namespace']['full_path']).to eq(full_path) + expect(json_response["namespace"]["name"]).to eq(group3.name) + expect(json_response["namespace"]["full_path"]).to eq(full_path) end - it 'fails to fork to not owned group' do - post api("/projects/#{project.id}/fork", user2), params: { namespace: group.name } + it "fails to fork to not owned group" do + post api("/projects/#{project.id}/fork", user2), params: {namespace: group.name} expect(response).to have_gitlab_http_status(404) end - it 'forks to not owned group when admin' do - post api("/projects/#{project.id}/fork", admin), params: { namespace: group.name } + it "forks to not owned group when admin" do + post api("/projects/#{project.id}/fork", admin), params: {namespace: group.name} expect(response).to have_gitlab_http_status(201) - expect(json_response['namespace']['name']).to eq(group.name) + expect(json_response["namespace"]["name"]).to eq(group.name) end - it 'accepts a path for the target project' do - post api("/projects/#{project.id}/fork", user2), params: { path: 'foobar' } + it "accepts a path for the target project" do + post api("/projects/#{project.id}/fork", user2), params: {path: "foobar"} expect(response).to have_gitlab_http_status(201) - expect(json_response['name']).to eq(project.name) - expect(json_response['path']).to eq('foobar') - expect(json_response['owner']['id']).to eq(user2.id) - expect(json_response['namespace']['id']).to eq(user2.namespace.id) - expect(json_response['forked_from_project']['id']).to eq(project.id) - expect(json_response['import_status']).to eq('scheduled') + expect(json_response["name"]).to eq(project.name) + expect(json_response["path"]).to eq("foobar") + expect(json_response["owner"]["id"]).to eq(user2.id) + expect(json_response["namespace"]["id"]).to eq(user2.namespace.id) + expect(json_response["forked_from_project"]["id"]).to eq(project.id) + expect(json_response["import_status"]).to eq("scheduled") expect(json_response).to include("import_error") end - it 'fails to fork if path is already taken' do - post api("/projects/#{project.id}/fork", user2), params: { path: 'foobar' } - post api("/projects/#{project2.id}/fork", user2), params: { path: 'foobar' } + it "fails to fork if path is already taken" do + post api("/projects/#{project.id}/fork", user2), params: {path: "foobar"} + post api("/projects/#{project2.id}/fork", user2), params: {path: "foobar"} expect(response).to have_gitlab_http_status(409) - expect(json_response['message']['path']).to eq(['has already been taken']) + expect(json_response["message"]["path"]).to eq(["has already been taken"]) end - it 'accepts a name for the target project' do - post api("/projects/#{project.id}/fork", user2), params: { name: 'My Random Project' } + it "accepts a name for the target project" do + post api("/projects/#{project.id}/fork", user2), params: {name: "My Random Project"} expect(response).to have_gitlab_http_status(201) - expect(json_response['name']).to eq('My Random Project') - expect(json_response['path']).to eq(project.path) - expect(json_response['owner']['id']).to eq(user2.id) - expect(json_response['namespace']['id']).to eq(user2.namespace.id) - expect(json_response['forked_from_project']['id']).to eq(project.id) - expect(json_response['import_status']).to eq('scheduled') + expect(json_response["name"]).to eq("My Random Project") + expect(json_response["path"]).to eq(project.path) + expect(json_response["owner"]["id"]).to eq(user2.id) + expect(json_response["namespace"]["id"]).to eq(user2.namespace.id) + expect(json_response["forked_from_project"]["id"]).to eq(project.id) + expect(json_response["import_status"]).to eq("scheduled") expect(json_response).to include("import_error") end - it 'fails to fork if name is already taken' do - post api("/projects/#{project.id}/fork", user2), params: { name: 'My Random Project' } - post api("/projects/#{project2.id}/fork", user2), params: { name: 'My Random Project' } + it "fails to fork if name is already taken" do + post api("/projects/#{project.id}/fork", user2), params: {name: "My Random Project"} + post api("/projects/#{project2.id}/fork", user2), params: {name: "My Random Project"} expect(response).to have_gitlab_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"]) end end - context 'when unauthenticated' do - it 'returns authentication error' do + context "when unauthenticated" do + it "returns authentication error" do post api("/projects/#{project.id}/fork") expect(response).to have_gitlab_http_status(401) - expect(json_response['message']).to eq('401 Unauthorized') + expect(json_response["message"]).to eq("401 Unauthorized") end end end - describe 'POST /projects/:id/housekeeping' do + describe "POST /projects/:id/housekeeping" do let(:housekeeping) { Projects::HousekeepingService.new(project) } before do allow(Projects::HousekeepingService).to receive(:new).with(project).and_return(housekeeping) end - context 'when authenticated as owner' do - it 'starts the housekeeping process' do + context "when authenticated as owner" do + it "starts the housekeeping process" do expect(housekeeping).to receive(:execute).once post api("/projects/#{project.id}/housekeeping", user) @@ -2226,32 +2225,32 @@ describe API::Projects do expect(response).to have_gitlab_http_status(201) end - context 'when housekeeping lease is taken' do - it 'returns conflict' do + context "when housekeeping lease is taken" do + it "returns conflict" do expect(housekeeping).to receive(:execute).once.and_raise(Projects::HousekeepingService::LeaseTaken) post api("/projects/#{project.id}/housekeeping", user) expect(response).to have_gitlab_http_status(409) - expect(json_response['message']).to match(/Somebody already triggered housekeeping for this project/) + expect(json_response["message"]).to match(/Somebody already triggered housekeeping for this project/) end end end - context 'when authenticated as developer' do + context "when authenticated as developer" do before do project_member end - it 'returns forbidden error' do + it "returns forbidden error" do post api("/projects/#{project.id}/housekeeping", user3) expect(response).to have_gitlab_http_status(403) end end - context 'when unauthenticated' do - it 'returns authentication error' do + context "when unauthenticated" do + it "returns authentication error" do post api("/projects/#{project.id}/housekeeping") expect(response).to have_gitlab_http_status(401) @@ -2259,31 +2258,31 @@ describe API::Projects do end end - describe 'PUT /projects/:id/transfer' do - context 'when authenticated as owner' do + describe "PUT /projects/:id/transfer" do + context "when authenticated as owner" do let(:group) { create :group } - it 'transfers the project to the new namespace' do + it "transfers the project to the new namespace" do group.add_owner(user) - put api("/projects/#{project.id}/transfer", user), params: { namespace: group.id } + put api("/projects/#{project.id}/transfer", user), params: {namespace: group.id} expect(response).to have_gitlab_http_status(200) end - it 'fails when transferring to a non owned namespace' do - put api("/projects/#{project.id}/transfer", user), params: { namespace: group.id } + it "fails when transferring to a non owned namespace" do + put api("/projects/#{project.id}/transfer", user), params: {namespace: group.id} expect(response).to have_gitlab_http_status(404) end - it 'fails when transferring to an unknown namespace' do - put api("/projects/#{project.id}/transfer", user), params: { namespace: 'unknown' } + it "fails when transferring to an unknown namespace" do + put api("/projects/#{project.id}/transfer", user), params: {namespace: "unknown"} expect(response).to have_gitlab_http_status(404) end - it 'fails on missing namespace' do + it "fails on missing namespace" do put api("/projects/#{project.id}/transfer", user) expect(response).to have_gitlab_http_status(400) @@ -2291,7 +2290,7 @@ describe API::Projects do end end - it_behaves_like 'custom attributes endpoints', 'projects' do + it_behaves_like "custom attributes endpoints", "projects" do let(:attributable) { project } let(:other_attributable) { project2 } end diff --git a/spec/requests/api/protected_branches_spec.rb b/spec/requests/api/protected_branches_spec.rb index f90558d77a9..21f7417f33a 100644 --- a/spec/requests/api/protected_branches_spec.rb +++ b/spec/requests/api/protected_branches_spec.rb @@ -1,9 +1,9 @@ -require 'spec_helper' +require "spec_helper" describe API::ProtectedBranches do let(:user) { create(:user) } let!(:project) { create(:project, :repository) } - let(:protected_name) { 'feature' } + let(:protected_name) { "feature" } let(:branch_name) { protected_name } let!(:protected_branch) do create(:protected_branch, project: project, name: protected_name) @@ -12,34 +12,34 @@ describe API::ProtectedBranches do describe "GET /projects/:id/protected_branches" do let(:route) { "/projects/#{project.id}/protected_branches" } - shared_examples_for 'protected branches' do - it 'returns the protected branches' do - get api(route, user), params: { per_page: 100 } + shared_examples_for "protected branches" do + it "returns the protected branches" do + get api(route, user), params: {per_page: 100} expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response).to be_an Array - protected_branch_names = json_response.map { |x| x['name'] } - expected_branch_names = project.protected_branches.map { |x| x['name'] } + protected_branch_names = json_response.map { |x| x["name"] } + expected_branch_names = project.protected_branches.map { |x| x["name"] } expect(protected_branch_names).to match_array(expected_branch_names) end end - context 'when authenticated as a maintainer' do + context "when authenticated as a maintainer" do before do project.add_maintainer(user) end - it_behaves_like 'protected branches' + it_behaves_like "protected branches" end - context 'when authenticated as a guest' do + context "when authenticated as a guest" do before do project.add_guest(user) end - it_behaves_like '403 response' do + it_behaves_like "403 response" do let(:request) { get api(route, user) } end end @@ -48,173 +48,173 @@ describe API::ProtectedBranches do describe "GET /projects/:id/protected_branches/:branch" do let(:route) { "/projects/#{project.id}/protected_branches/#{branch_name}" } - shared_examples_for 'protected branch' do - it 'returns the protected branch' do + shared_examples_for "protected branch" do + it "returns the protected branch" do get api(route, user) expect(response).to have_gitlab_http_status(200) - expect(json_response['name']).to eq(branch_name) - expect(json_response['push_access_levels'][0]['access_level']).to eq(::Gitlab::Access::MAINTAINER) - expect(json_response['merge_access_levels'][0]['access_level']).to eq(::Gitlab::Access::MAINTAINER) + expect(json_response["name"]).to eq(branch_name) + expect(json_response["push_access_levels"][0]["access_level"]).to eq(::Gitlab::Access::MAINTAINER) + expect(json_response["merge_access_levels"][0]["access_level"]).to eq(::Gitlab::Access::MAINTAINER) end - context 'when protected branch does not exist' do - let(:branch_name) { 'unknown' } + context "when protected branch does not exist" do + let(:branch_name) { "unknown" } - it_behaves_like '404 response' do + it_behaves_like "404 response" do let(:request) { get api(route, user) } - let(:message) { '404 Not found' } + let(:message) { "404 Not found" } end end end - context 'when authenticated as a maintainer' do + context "when authenticated as a maintainer" do before do project.add_maintainer(user) end - it_behaves_like 'protected branch' + it_behaves_like "protected branch" - context 'when protected branch contains a wildcard' do - let(:protected_name) { 'feature*' } + context "when protected branch contains a wildcard" do + let(:protected_name) { "feature*" } - it_behaves_like 'protected branch' + it_behaves_like "protected branch" end - context 'when protected branch contains a period' do - let(:protected_name) { 'my.feature' } + context "when protected branch contains a period" do + let(:protected_name) { "my.feature" } - it_behaves_like 'protected branch' + it_behaves_like "protected branch" end end - context 'when authenticated as a guest' do + context "when authenticated as a guest" do before do project.add_guest(user) end - it_behaves_like '403 response' do + it_behaves_like "403 response" do let(:request) { get api(route, user) } end end end - describe 'POST /projects/:id/protected_branches' do - let(:branch_name) { 'new_branch' } + describe "POST /projects/:id/protected_branches" do + let(:branch_name) { "new_branch" } let(:post_endpoint) { api("/projects/#{project.id}/protected_branches", user) } def expect_protection_to_be_successful expect(response).to have_gitlab_http_status(201) - expect(json_response['name']).to eq(branch_name) + expect(json_response["name"]).to eq(branch_name) end - context 'when authenticated as a maintainer' do + context "when authenticated as a maintainer" do before do project.add_maintainer(user) end - it 'protects a single branch' do - post post_endpoint, params: { name: branch_name } + it "protects a single branch" do + post post_endpoint, params: {name: branch_name} expect(response).to have_gitlab_http_status(201) - expect(json_response['name']).to eq(branch_name) - expect(json_response['push_access_levels'][0]['access_level']).to eq(Gitlab::Access::MAINTAINER) - expect(json_response['merge_access_levels'][0]['access_level']).to eq(Gitlab::Access::MAINTAINER) + expect(json_response["name"]).to eq(branch_name) + expect(json_response["push_access_levels"][0]["access_level"]).to eq(Gitlab::Access::MAINTAINER) + expect(json_response["merge_access_levels"][0]["access_level"]).to eq(Gitlab::Access::MAINTAINER) end - it 'protects a single branch and developers can push' do - post post_endpoint, params: { name: branch_name, push_access_level: 30 } + it "protects a single branch and developers can push" do + post post_endpoint, params: {name: branch_name, push_access_level: 30} expect(response).to have_gitlab_http_status(201) - expect(json_response['name']).to eq(branch_name) - expect(json_response['push_access_levels'][0]['access_level']).to eq(Gitlab::Access::DEVELOPER) - expect(json_response['merge_access_levels'][0]['access_level']).to eq(Gitlab::Access::MAINTAINER) + expect(json_response["name"]).to eq(branch_name) + expect(json_response["push_access_levels"][0]["access_level"]).to eq(Gitlab::Access::DEVELOPER) + expect(json_response["merge_access_levels"][0]["access_level"]).to eq(Gitlab::Access::MAINTAINER) end - it 'protects a single branch and developers can merge' do - post post_endpoint, params: { name: branch_name, merge_access_level: 30 } + it "protects a single branch and developers can merge" do + post post_endpoint, params: {name: branch_name, merge_access_level: 30} expect(response).to have_gitlab_http_status(201) - expect(json_response['name']).to eq(branch_name) - expect(json_response['push_access_levels'][0]['access_level']).to eq(Gitlab::Access::MAINTAINER) - expect(json_response['merge_access_levels'][0]['access_level']).to eq(Gitlab::Access::DEVELOPER) + expect(json_response["name"]).to eq(branch_name) + expect(json_response["push_access_levels"][0]["access_level"]).to eq(Gitlab::Access::MAINTAINER) + expect(json_response["merge_access_levels"][0]["access_level"]).to eq(Gitlab::Access::DEVELOPER) end - it 'protects a single branch and developers can push and merge' do - post post_endpoint, params: { name: branch_name, push_access_level: 30, merge_access_level: 30 } + it "protects a single branch and developers can push and merge" do + post post_endpoint, params: {name: branch_name, push_access_level: 30, merge_access_level: 30} expect(response).to have_gitlab_http_status(201) - expect(json_response['name']).to eq(branch_name) - expect(json_response['push_access_levels'][0]['access_level']).to eq(Gitlab::Access::DEVELOPER) - expect(json_response['merge_access_levels'][0]['access_level']).to eq(Gitlab::Access::DEVELOPER) + expect(json_response["name"]).to eq(branch_name) + expect(json_response["push_access_levels"][0]["access_level"]).to eq(Gitlab::Access::DEVELOPER) + expect(json_response["merge_access_levels"][0]["access_level"]).to eq(Gitlab::Access::DEVELOPER) end - it 'protects a single branch and no one can push' do - post post_endpoint, params: { name: branch_name, push_access_level: 0 } + it "protects a single branch and no one can push" do + post post_endpoint, params: {name: branch_name, push_access_level: 0} expect(response).to have_gitlab_http_status(201) - expect(json_response['name']).to eq(branch_name) - expect(json_response['push_access_levels'][0]['access_level']).to eq(Gitlab::Access::NO_ACCESS) - expect(json_response['merge_access_levels'][0]['access_level']).to eq(Gitlab::Access::MAINTAINER) + expect(json_response["name"]).to eq(branch_name) + expect(json_response["push_access_levels"][0]["access_level"]).to eq(Gitlab::Access::NO_ACCESS) + expect(json_response["merge_access_levels"][0]["access_level"]).to eq(Gitlab::Access::MAINTAINER) end - it 'protects a single branch and no one can merge' do - post post_endpoint, params: { name: branch_name, merge_access_level: 0 } + it "protects a single branch and no one can merge" do + post post_endpoint, params: {name: branch_name, merge_access_level: 0} expect(response).to have_gitlab_http_status(201) - expect(json_response['name']).to eq(branch_name) - expect(json_response['push_access_levels'][0]['access_level']).to eq(Gitlab::Access::MAINTAINER) - expect(json_response['merge_access_levels'][0]['access_level']).to eq(Gitlab::Access::NO_ACCESS) + expect(json_response["name"]).to eq(branch_name) + expect(json_response["push_access_levels"][0]["access_level"]).to eq(Gitlab::Access::MAINTAINER) + expect(json_response["merge_access_levels"][0]["access_level"]).to eq(Gitlab::Access::NO_ACCESS) end - it 'protects a single branch and no one can push or merge' do - post post_endpoint, params: { name: branch_name, push_access_level: 0, merge_access_level: 0 } + it "protects a single branch and no one can push or merge" do + post post_endpoint, params: {name: branch_name, push_access_level: 0, merge_access_level: 0} expect(response).to have_gitlab_http_status(201) - expect(json_response['name']).to eq(branch_name) - expect(json_response['push_access_levels'][0]['access_level']).to eq(Gitlab::Access::NO_ACCESS) - expect(json_response['merge_access_levels'][0]['access_level']).to eq(Gitlab::Access::NO_ACCESS) + expect(json_response["name"]).to eq(branch_name) + expect(json_response["push_access_levels"][0]["access_level"]).to eq(Gitlab::Access::NO_ACCESS) + expect(json_response["merge_access_levels"][0]["access_level"]).to eq(Gitlab::Access::NO_ACCESS) end - it 'returns a 409 error if the same branch is protected twice' do - post post_endpoint, params: { name: protected_name } + it "returns a 409 error if the same branch is protected twice" do + post post_endpoint, params: {name: protected_name} expect(response).to have_gitlab_http_status(409) end - context 'when branch has a wildcard in its name' do - let(:branch_name) { 'feature/*' } + context "when branch has a wildcard in its name" do + let(:branch_name) { "feature/*" } it "protects multiple branches with a wildcard in the name" do - post post_endpoint, params: { name: branch_name } + post post_endpoint, params: {name: branch_name} expect_protection_to_be_successful - expect(json_response['push_access_levels'][0]['access_level']).to eq(Gitlab::Access::MAINTAINER) - expect(json_response['merge_access_levels'][0]['access_level']).to eq(Gitlab::Access::MAINTAINER) + expect(json_response["push_access_levels"][0]["access_level"]).to eq(Gitlab::Access::MAINTAINER) + expect(json_response["merge_access_levels"][0]["access_level"]).to eq(Gitlab::Access::MAINTAINER) end end - context 'when a policy restricts rule deletion' do + context "when a policy restricts rule deletion" do before do policy = instance_double(ProtectedBranchPolicy, can?: false) expect(ProtectedBranchPolicy).to receive(:new).and_return(policy) end it "prevents deletion of the protected branch rule" do - post post_endpoint, params: { name: branch_name } + post post_endpoint, params: {name: branch_name} expect(response).to have_gitlab_http_status(403) end end end - context 'when authenticated as a guest' do + context "when authenticated as a guest" do before do project.add_guest(user) end it "returns a 403 error if guest" do - post post_endpoint, params: { name: branch_name } + post post_endpoint, params: {name: branch_name} expect(response).to have_gitlab_http_status(403) end @@ -234,7 +234,7 @@ describe API::ProtectedBranches do expect(response).to have_gitlab_http_status(204) end - it_behaves_like '412 response' do + it_behaves_like "412 response" do let(:request) { delete_endpoint } end @@ -244,7 +244,7 @@ describe API::ProtectedBranches do expect(response).to have_gitlab_http_status(404) end - context 'when a policy restricts rule deletion' do + context "when a policy restricts rule deletion" do before do policy = instance_double(ProtectedBranchPolicy, can?: false) expect(ProtectedBranchPolicy).to receive(:new).and_return(policy) @@ -257,8 +257,8 @@ describe API::ProtectedBranches do end end - context 'when branch has a wildcard in its name' do - let(:protected_name) { 'feature*' } + context "when branch has a wildcard in its name" do + let(:protected_name) { "feature*" } it "unprotects a wildcard branch" do delete delete_endpoint diff --git a/spec/requests/api/protected_tags_spec.rb b/spec/requests/api/protected_tags_spec.rb index 41363dcc1c3..cb647e2e281 100644 --- a/spec/requests/api/protected_tags_spec.rb +++ b/spec/requests/api/protected_tags_spec.rb @@ -1,185 +1,185 @@ -require 'spec_helper' +require "spec_helper" describe API::ProtectedTags do let(:user) { create(:user) } let!(:project) { create(:project, :repository) } - let(:project2) { create(:project, path: 'project2', namespace: user.namespace) } - let(:protected_name) { 'feature' } + let(:project2) { create(:project, path: "project2", namespace: user.namespace) } + let(:protected_name) { "feature" } let(:tag_name) { protected_name } let!(:protected_tag) do create(:protected_tag, project: project, name: protected_name) end - describe 'GET /projects/:id/protected_tags' do + describe "GET /projects/:id/protected_tags" do let(:route) { "/projects/#{project.id}/protected_tags" } - shared_examples_for 'protected tags' do - it 'returns the protected tags' do - get api(route, user), params: { per_page: 100 } + shared_examples_for "protected tags" do + it "returns the protected tags" do + get api(route, user), params: {per_page: 100} expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response).to be_an Array - protected_tag_names = json_response.map { |x| x['name'] } - expected_tags_names = project.protected_tags.map { |x| x['name'] } + protected_tag_names = json_response.map { |x| x["name"] } + expected_tags_names = project.protected_tags.map { |x| x["name"] } expect(protected_tag_names).to match_array(expected_tags_names) end end - context 'when authenticated as a maintainer' do + context "when authenticated as a maintainer" do before do project.add_maintainer(user) end - it_behaves_like 'protected tags' + it_behaves_like "protected tags" end - context 'when authenticated as a guest' do + context "when authenticated as a guest" do before do project.add_guest(user) end - it_behaves_like '403 response' do + it_behaves_like "403 response" do let(:request) { get api(route, user) } end end end - describe 'GET /projects/:id/protected_tags/:tag' do + describe "GET /projects/:id/protected_tags/:tag" do let(:route) { "/projects/#{project.id}/protected_tags/#{tag_name}" } - shared_examples_for 'protected tag' do - it 'returns the protected tag' do + shared_examples_for "protected tag" do + it "returns the protected tag" do get api(route, user) expect(response).to have_gitlab_http_status(200) - expect(json_response['name']).to eq(tag_name) - expect(json_response['create_access_levels'][0]['access_level']).to eq(::Gitlab::Access::MAINTAINER) + expect(json_response["name"]).to eq(tag_name) + expect(json_response["create_access_levels"][0]["access_level"]).to eq(::Gitlab::Access::MAINTAINER) end - context 'when protected tag does not exist' do - let(:tag_name) { 'unknown' } + context "when protected tag does not exist" do + let(:tag_name) { "unknown" } - it_behaves_like '404 response' do + it_behaves_like "404 response" do let(:request) { get api(route, user) } - let(:message) { '404 Not found' } + let(:message) { "404 Not found" } end end end - context 'when authenticated as a maintainer' do + context "when authenticated as a maintainer" do before do project.add_maintainer(user) end - it_behaves_like 'protected tag' + it_behaves_like "protected tag" - context 'when protected tag contains a wildcard' do - let(:protected_name) { 'feature*' } + context "when protected tag contains a wildcard" do + let(:protected_name) { "feature*" } - it_behaves_like 'protected tag' + it_behaves_like "protected tag" end end - context 'when authenticated as a guest' do + context "when authenticated as a guest" do before do project.add_guest(user) end - it_behaves_like '403 response' do + it_behaves_like "403 response" do let(:request) { get api(route, user) } end end end - describe 'POST /projects/:id/protected_tags' do - let(:tag_name) { 'new_tag' } + describe "POST /projects/:id/protected_tags" do + let(:tag_name) { "new_tag" } - context 'when authenticated as a maintainer' do + context "when authenticated as a maintainer" do before do project.add_maintainer(user) end - it 'protects a single tag with maintainers can create tags' do - post api("/projects/#{project.id}/protected_tags", user), params: { name: tag_name } + it "protects a single tag with maintainers can create tags" do + post api("/projects/#{project.id}/protected_tags", user), params: {name: tag_name} expect(response).to have_gitlab_http_status(201) - expect(json_response['name']).to eq(tag_name) - expect(json_response['create_access_levels'][0]['access_level']).to eq(Gitlab::Access::MAINTAINER) + expect(json_response["name"]).to eq(tag_name) + expect(json_response["create_access_levels"][0]["access_level"]).to eq(Gitlab::Access::MAINTAINER) end - it 'protects a single tag with developers can create tags' do + it "protects a single tag with developers can create tags" do post api("/projects/#{project.id}/protected_tags", user), - params: { name: tag_name, create_access_level: 30 } + params: {name: tag_name, create_access_level: 30} expect(response).to have_gitlab_http_status(201) - expect(json_response['name']).to eq(tag_name) - expect(json_response['create_access_levels'][0]['access_level']).to eq(Gitlab::Access::DEVELOPER) + expect(json_response["name"]).to eq(tag_name) + expect(json_response["create_access_levels"][0]["access_level"]).to eq(Gitlab::Access::DEVELOPER) end - it 'protects a single tag with no one can create tags' do + it "protects a single tag with no one can create tags" do post api("/projects/#{project.id}/protected_tags", user), - params: { name: tag_name, create_access_level: 0 } + params: {name: tag_name, create_access_level: 0} expect(response).to have_gitlab_http_status(201) - expect(json_response['name']).to eq(tag_name) - expect(json_response['create_access_levels'][0]['access_level']).to eq(Gitlab::Access::NO_ACCESS) + expect(json_response["name"]).to eq(tag_name) + expect(json_response["create_access_levels"][0]["access_level"]).to eq(Gitlab::Access::NO_ACCESS) end - it 'returns a 422 error if the same tag is protected twice' do - post api("/projects/#{project.id}/protected_tags", user), params: { name: protected_name } + it "returns a 422 error if the same tag is protected twice" do + post api("/projects/#{project.id}/protected_tags", user), params: {name: protected_name} expect(response).to have_gitlab_http_status(422) - expect(json_response['message'][0]).to eq('Name has already been taken') + expect(json_response["message"][0]).to eq("Name has already been taken") end - it 'returns 201 if the same tag is proteted on different projects' do - post api("/projects/#{project.id}/protected_tags", user), params: { name: protected_name } - post api("/projects/#{project2.id}/protected_tags", user), params: { name: protected_name } + it "returns 201 if the same tag is proteted on different projects" do + post api("/projects/#{project.id}/protected_tags", user), params: {name: protected_name} + post api("/projects/#{project2.id}/protected_tags", user), params: {name: protected_name} expect(response).to have_gitlab_http_status(201) - expect(json_response['name']).to eq(protected_name) + expect(json_response["name"]).to eq(protected_name) end - context 'when tag has a wildcard in its name' do - let(:tag_name) { 'feature/*' } + context "when tag has a wildcard in its name" do + let(:tag_name) { "feature/*" } - it 'protects multiple tags with a wildcard in the name' do - post api("/projects/#{project.id}/protected_tags", user), params: { name: tag_name } + it "protects multiple tags with a wildcard in the name" do + post api("/projects/#{project.id}/protected_tags", user), params: {name: tag_name} expect(response).to have_gitlab_http_status(201) - expect(json_response['name']).to eq(tag_name) - expect(json_response['create_access_levels'][0]['access_level']).to eq(Gitlab::Access::MAINTAINER) + expect(json_response["name"]).to eq(tag_name) + expect(json_response["create_access_levels"][0]["access_level"]).to eq(Gitlab::Access::MAINTAINER) end end end - context 'when authenticated as a guest' do + context "when authenticated as a guest" do before do project.add_guest(user) end - it 'returns a 403 error if guest' do - post api("/projects/#{project.id}/protected_tags/", user), params: { name: tag_name } + it "returns a 403 error if guest" do + post api("/projects/#{project.id}/protected_tags/", user), params: {name: tag_name} expect(response).to have_gitlab_http_status(403) end end end - describe 'DELETE /projects/:id/protected_tags/unprotect/:tag' do + describe "DELETE /projects/:id/protected_tags/unprotect/:tag" do before do project.add_maintainer(user) end - it 'unprotects a single tag' do + it "unprotects a single tag" do delete api("/projects/#{project.id}/protected_tags/#{tag_name}", user) expect(response).to have_gitlab_http_status(204) end - it_behaves_like '412 response' do + it_behaves_like "412 response" do let(:request) { api("/projects/#{project.id}/protected_tags/#{tag_name}", user) } end @@ -189,10 +189,10 @@ describe API::ProtectedTags do expect(response).to have_gitlab_http_status(404) end - context 'when tag has a wildcard in its name' do - let(:protected_name) { 'feature*' } + context "when tag has a wildcard in its name" do + let(:protected_name) { "feature*" } - it 'unprotects a wildcard tag' do + it "unprotects a wildcard tag" do delete api("/projects/#{project.id}/protected_tags/#{tag_name}", user) expect(response).to have_gitlab_http_status(204) diff --git a/spec/requests/api/release/links_spec.rb b/spec/requests/api/release/links_spec.rb index ba948e37e2f..6341b6cbfc9 100644 --- a/spec/requests/api/release/links_spec.rb +++ b/spec/requests/api/release/links_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'spec_helper' +require "spec_helper" describe API::Release::Links do let(:project) { create(:project, :repository, :private) } @@ -11,63 +11,63 @@ describe API::Release::Links do let!(:release) do create(:release, - project: project, - tag: 'v0.1', - author: maintainer) + project: project, + tag: "v0.1", + author: maintainer) end before do project.add_maintainer(maintainer) project.add_reporter(reporter) - project.repository.add_tag(maintainer, 'v0.1', commit.id) + project.repository.add_tag(maintainer, "v0.1", commit.id) end - describe 'GET /projects/:id/releases/:tag_name/assets/links' do - context 'when there are two release links' do + describe "GET /projects/:id/releases/:tag_name/assets/links" do + context "when there are two release links" do let!(:release_link_1) { create(:release_link, release: release, created_at: 2.days.ago) } let!(:release_link_2) { create(:release_link, release: release, created_at: 1.day.ago) } - it 'returns 200 HTTP status' do + it "returns 200 HTTP status" do get api("/projects/#{project.id}/releases/v0.1/assets/links", maintainer) expect(response).to have_gitlab_http_status(:ok) end - it 'returns release links ordered by created_at' do + it "returns release links ordered by created_at" do get api("/projects/#{project.id}/releases/v0.1/assets/links", maintainer) expect(json_response.count).to eq(2) - expect(json_response.first['name']).to eq(release_link_2.name) - expect(json_response.second['name']).to eq(release_link_1.name) + expect(json_response.first["name"]).to eq(release_link_2.name) + expect(json_response.second["name"]).to eq(release_link_1.name) end - it 'matches response schema' do + it "matches response schema" do get api("/projects/#{project.id}/releases/v0.1/assets/links", maintainer) - expect(response).to match_response_schema('release/links') + expect(response).to match_response_schema("release/links") end end - context 'when release does not exist' do + context "when release does not exist" do let!(:release) { } - it_behaves_like '404 response' do + it_behaves_like "404 response" do let(:request) { get api("/projects/#{project.id}/releases/v0.1/assets/links", maintainer) } - let(:message) { '404 Not found' } + let(:message) { "404 Not found" } end end - context 'when user is not a project member' do - it_behaves_like '404 response' do + context "when user is not a project member" do + it_behaves_like "404 response" do let(:request) { get api("/projects/#{project.id}/releases/v0.1/assets/links", non_project_member) } - let(:message) { '404 Project Not Found' } + let(:message) { "404 Project Not Found" } end - context 'when project is public' do + context "when project is public" do let(:project) { create(:project, :repository, :public) } - it 'allows the request' do + it "allows the request" do get api("/projects/#{project.id}/releases/v0.1/assets/links", non_project_member) expect(response).to have_gitlab_http_status(:ok) @@ -76,43 +76,43 @@ describe API::Release::Links do end end - describe 'GET /projects/:id/releases/:tag_name/assets/links/:link_id' do + describe "GET /projects/:id/releases/:tag_name/assets/links/:link_id" do let!(:release_link) { create(:release_link, release: release) } - it 'returns 200 HTTP status' do + it "returns 200 HTTP status" do get api("/projects/#{project.id}/releases/v0.1/assets/links/#{release_link.id}", maintainer) expect(response).to have_gitlab_http_status(:ok) end - it 'returns a link entry' do + it "returns a link entry" do get api("/projects/#{project.id}/releases/v0.1/assets/links/#{release_link.id}", maintainer) - expect(json_response['name']).to eq(release_link.name) - expect(json_response['url']).to eq(release_link.url) + expect(json_response["name"]).to eq(release_link.name) + expect(json_response["url"]).to eq(release_link.url) end - it 'matches response schema' do + it "matches response schema" do get api("/projects/#{project.id}/releases/v0.1/assets/links/#{release_link.id}", maintainer) - expect(response).to match_response_schema('release/link') + expect(response).to match_response_schema("release/link") end - context 'when specified tag is not found in the project' do - it_behaves_like '404 response' do + context "when specified tag is not found in the project" do + it_behaves_like "404 response" do let(:request) { get api("/projects/#{project.id}/releases/non_existing_tag/assets/links/#{release_link.id}", maintainer) } end end - context 'when user is not a project member' do - it_behaves_like '404 response' do + context "when user is not a project member" do + it_behaves_like "404 response" do let(:request) { get api("/projects/#{project.id}/releases/non_existing_tag/assets/links/#{release_link.id}", non_project_member) } end - context 'when project is public' do + context "when project is public" do let(:project) { create(:project, :repository, :public) } - it 'allows the request' do + it "allows the request" do get api("/projects/#{project.id}/releases/v0.1/assets/links/#{release_link.id}", non_project_member) expect(response).to have_gitlab_http_status(:ok) @@ -121,234 +121,234 @@ describe API::Release::Links do end end - describe 'POST /projects/:id/releases/:tag_name/assets/links' do + describe "POST /projects/:id/releases/:tag_name/assets/links" do let(:params) do { - name: 'awesome-app.dmg', - url: 'https://example.com/download/awesome-app.dmg' + name: "awesome-app.dmg", + url: "https://example.com/download/awesome-app.dmg", } end - it 'accepts the request' do + it "accepts the request" do post api("/projects/#{project.id}/releases/v0.1/assets/links", maintainer), params: params expect(response).to have_gitlab_http_status(:created) end - it 'creates a new release' do - expect do + it "creates a new release" do + expect { post api("/projects/#{project.id}/releases/v0.1/assets/links", maintainer), params: params - end.to change { Releases::Link.count }.by(1) + }.to change { Releases::Link.count }.by(1) release.reload - expect(release.links.last.name).to eq('awesome-app.dmg') - expect(release.links.last.url).to eq('https://example.com/download/awesome-app.dmg') + expect(release.links.last.name).to eq("awesome-app.dmg") + expect(release.links.last.url).to eq("https://example.com/download/awesome-app.dmg") end - it 'matches response schema' do + it "matches response schema" do post api("/projects/#{project.id}/releases/v0.1/assets/links", maintainer), params: params - expect(response).to match_response_schema('release/link') + expect(response).to match_response_schema("release/link") end - context 'when name is empty' do + context "when name is empty" do let(:params) do { - name: '', - url: 'https://example.com/download/awesome-app.dmg' + name: "", + url: "https://example.com/download/awesome-app.dmg", } end - it_behaves_like '400 response' do + it_behaves_like "400 response" do let(:request) do post api("/projects/#{project.id}/releases/v0.1/assets/links", maintainer), - params: params + params: params end end end - context 'when user is a reporter' do - it_behaves_like '403 response' do + context "when user is a reporter" do + it_behaves_like "403 response" do let(:request) do post api("/projects/#{project.id}/releases/v0.1/assets/links", reporter), - params: params + params: params end end end - context 'when user is not a project member' do - it 'forbids the request' do + context "when user is not a project member" do + it "forbids the request" do post api("/projects/#{project.id}/releases/v0.1/assets/links", non_project_member), - params: params + params: params expect(response).to have_gitlab_http_status(:not_found) end - context 'when project is public' do + context "when project is public" do let(:project) { create(:project, :repository, :public) } - it 'forbids the request' do + it "forbids the request" do post api("/projects/#{project.id}/releases/v0.1/assets/links", non_project_member), - params: params + params: params expect(response).to have_gitlab_http_status(:forbidden) end end end - context 'when the same link already exists' do + context "when the same link already exists" do before do create(:release_link, - release: release, - name: 'awesome-app.dmg', - url: 'https://example.com/download/awesome-app.dmg') + release: release, + name: "awesome-app.dmg", + url: "https://example.com/download/awesome-app.dmg") end - it_behaves_like '400 response' do + it_behaves_like "400 response" do let(:request) do post api("/projects/#{project.id}/releases/v0.1/assets/links", maintainer), - params: params + params: params end end end end - describe 'PUT /projects/:id/releases/:tag_name/assets/links/:link_id' do - let(:params) { { name: 'awesome-app.msi' } } + describe "PUT /projects/:id/releases/:tag_name/assets/links/:link_id" do + let(:params) { {name: "awesome-app.msi"} } let!(:release_link) { create(:release_link, release: release) } - it 'accepts the request' do + it "accepts the request" do put api("/projects/#{project.id}/releases/v0.1/assets/links/#{release_link.id}", maintainer), - params: params + params: params expect(response).to have_gitlab_http_status(:ok) end - it 'updates the name' do + it "updates the name" do put api("/projects/#{project.id}/releases/v0.1/assets/links/#{release_link.id}", maintainer), - params: params + params: params - expect(json_response['name']).to eq('awesome-app.msi') + expect(json_response["name"]).to eq("awesome-app.msi") end - it 'does not update the url' do + it "does not update the url" do put api("/projects/#{project.id}/releases/v0.1/assets/links/#{release_link.id}", maintainer), - params: params + params: params - expect(json_response['url']).to eq(release_link.url) + expect(json_response["url"]).to eq(release_link.url) end - it 'matches response schema' do + it "matches response schema" do put api("/projects/#{project.id}/releases/v0.1/assets/links/#{release_link.id}", maintainer), - params: params + params: params - expect(response).to match_response_schema('release/link') + expect(response).to match_response_schema("release/link") end - context 'when params is empty' do + context "when params is empty" do let(:params) { {} } - it 'does not allow the request' do + it "does not allow the request" do put api("/projects/#{project.id}/releases/v0.1/assets/links/#{release_link.id}", maintainer), - params: params + params: params expect(response).to have_gitlab_http_status(:bad_request) end end - context 'when there are no corresponding release link' do + context "when there are no corresponding release link" do let!(:release_link) { } - it_behaves_like '404 response' do + it_behaves_like "404 response" do let(:request) do put api("/projects/#{project.id}/releases/v0.1/assets/links/1", maintainer), - params: params + params: params end end end - context 'when user is a reporter' do - it_behaves_like '403 response' do + context "when user is a reporter" do + it_behaves_like "403 response" do let(:request) do put api("/projects/#{project.id}/releases/v0.1/assets/links/#{release_link.id}", reporter), - params: params + params: params end end end - context 'when user is not a project member' do - it_behaves_like '404 response' do + context "when user is not a project member" do + it_behaves_like "404 response" do let(:request) do put api("/projects/#{project.id}/releases/v0.1/assets/links/#{release_link.id}", non_project_member), - params: params + params: params end end - context 'when project is public' do + context "when project is public" do let(:project) { create(:project, :repository, :public) } - it_behaves_like '403 response' do + it_behaves_like "403 response" do let(:request) do put api("/projects/#{project.id}/releases/v0.1/assets/links/#{release_link.id}", non_project_member), - params: params + params: params end end end end end - describe 'DELETE /projects/:id/releases/:tag_name/assets/links/:link_id' do + describe "DELETE /projects/:id/releases/:tag_name/assets/links/:link_id" do let!(:release_link) do create(:release_link, release: release) end - it 'accepts the request' do + it "accepts the request" do delete api("/projects/#{project.id}/releases/v0.1/assets/links/#{release_link.id}", maintainer) expect(response).to have_gitlab_http_status(:ok) end - it 'destroys the release link' do - expect do + it "destroys the release link" do + expect { delete api("/projects/#{project.id}/releases/v0.1/assets/links/#{release_link.id}", maintainer) - end.to change { Releases::Link.count }.by(-1) + }.to change { Releases::Link.count }.by(-1) end - it 'matches response schema' do + it "matches response schema" do delete api("/projects/#{project.id}/releases/v0.1/assets/links/#{release_link.id}", maintainer) - expect(response).to match_response_schema('release/link') + expect(response).to match_response_schema("release/link") end - context 'when there are no corresponding release link' do + context "when there are no corresponding release link" do let!(:release_link) { } - it_behaves_like '404 response' do + it_behaves_like "404 response" do let(:request) do delete api("/projects/#{project.id}/releases/v0.1/assets/links/1", maintainer) end end end - context 'when user is a reporter' do - it_behaves_like '403 response' do + context "when user is a reporter" do + it_behaves_like "403 response" do let(:request) do delete api("/projects/#{project.id}/releases/v0.1/assets/links/#{release_link.id}", reporter) end end end - context 'when user is not a project member' do - it_behaves_like '404 response' do + context "when user is not a project member" do + it_behaves_like "404 response" do let(:request) do delete api("/projects/#{project.id}/releases/v0.1/assets/links/#{release_link.id}", non_project_member) end end - context 'when project is public' do + context "when project is public" do let(:project) { create(:project, :repository, :public) } - it_behaves_like '403 response' do + it_behaves_like "403 response" do let(:request) do delete api("/projects/#{project.id}/releases/v0.1/assets/links/#{release_link.id}", non_project_member) end diff --git a/spec/requests/api/releases_spec.rb b/spec/requests/api/releases_spec.rb index 1f317971a66..8bd96c5be42 100644 --- a/spec/requests/api/releases_spec.rb +++ b/spec/requests/api/releases_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe API::Releases do let(:project) { create(:project, :repository, :private) } @@ -11,72 +11,72 @@ describe API::Releases do project.add_maintainer(maintainer) project.add_reporter(reporter) - project.repository.add_tag(maintainer, 'v0.1', commit.id) - project.repository.add_tag(maintainer, 'v0.2', commit.id) + project.repository.add_tag(maintainer, "v0.1", commit.id) + project.repository.add_tag(maintainer, "v0.2", commit.id) end - describe 'GET /projects/:id/releases' do - context 'when there are two releases' do + describe "GET /projects/:id/releases" do + context "when there are two releases" do let!(:release_1) do create(:release, - project: project, - tag: 'v0.1', - author: maintainer, - created_at: 2.days.ago) + project: project, + tag: "v0.1", + author: maintainer, + created_at: 2.days.ago) end let!(:release_2) do create(:release, - project: project, - tag: 'v0.2', - author: maintainer, - created_at: 1.day.ago) + project: project, + tag: "v0.2", + author: maintainer, + created_at: 1.day.ago) end - it 'returns 200 HTTP status' do + it "returns 200 HTTP status" do get api("/projects/#{project.id}/releases", maintainer) expect(response).to have_gitlab_http_status(:ok) end - it 'returns releases ordered by created_at' do + it "returns releases ordered by created_at" do get api("/projects/#{project.id}/releases", maintainer) expect(json_response.count).to eq(2) - expect(json_response.first['tag_name']).to eq(release_2.tag) - expect(json_response.second['tag_name']).to eq(release_1.tag) + expect(json_response.first["tag_name"]).to eq(release_2.tag) + expect(json_response.second["tag_name"]).to eq(release_1.tag) end - it 'matches response schema' do + it "matches response schema" do get api("/projects/#{project.id}/releases", maintainer) - expect(response).to match_response_schema('releases') + expect(response).to match_response_schema("releases") end end - context 'when tag does not exist in git repository' do - let!(:release) { create(:release, project: project, tag: 'v1.1.5') } + context "when tag does not exist in git repository" do + let!(:release) { create(:release, project: project, tag: "v1.1.5") } - it 'returns the tag' do + it "returns the tag" do get api("/projects/#{project.id}/releases", maintainer) expect(json_response.count).to eq(1) - expect(json_response.first['tag_name']).to eq('v1.1.5') + expect(json_response.first["tag_name"]).to eq("v1.1.5") expect(release).to be_tag_missing end end - context 'when user is not a project member' do - it 'cannot find the project' do + context "when user is not a project member" do + it "cannot find the project" do get api("/projects/#{project.id}/releases", non_project_member) expect(response).to have_gitlab_http_status(:not_found) end - context 'when project is public' do + context "when project is public" do let(:project) { create(:project, :repository, :public) } - it 'allows the request' do + it "allows the request" do get api("/projects/#{project.id}/releases", non_project_member) expect(response).to have_gitlab_http_status(:ok) @@ -85,133 +85,133 @@ describe API::Releases do end end - describe 'GET /projects/:id/releases/:tag_name' do - context 'when there is a release' do + describe "GET /projects/:id/releases/:tag_name" do + context "when there is a release" do let!(:release) do create(:release, - project: project, - tag: 'v0.1', - sha: commit.id, - author: maintainer, - description: 'This is v0.1') + project: project, + tag: "v0.1", + sha: commit.id, + author: maintainer, + description: "This is v0.1") end - it 'returns 200 HTTP status' do + it "returns 200 HTTP status" do get api("/projects/#{project.id}/releases/v0.1", maintainer) expect(response).to have_gitlab_http_status(:ok) end - it 'returns a release entry' do + it "returns a release entry" do get api("/projects/#{project.id}/releases/v0.1", maintainer) - expect(json_response['tag_name']).to eq(release.tag) - expect(json_response['description']).to eq('This is v0.1') - expect(json_response['author']['name']).to eq(maintainer.name) - expect(json_response['commit']['id']).to eq(commit.id) - expect(json_response['assets']['count']).to eq(4) + expect(json_response["tag_name"]).to eq(release.tag) + expect(json_response["description"]).to eq("This is v0.1") + expect(json_response["author"]["name"]).to eq(maintainer.name) + expect(json_response["commit"]["id"]).to eq(commit.id) + expect(json_response["assets"]["count"]).to eq(4) end - it 'matches response schema' do + it "matches response schema" do get api("/projects/#{project.id}/releases/v0.1", maintainer) - expect(response).to match_response_schema('release') + expect(response).to match_response_schema("release") end - it 'contains source information as assets' do + it "contains source information as assets" do get api("/projects/#{project.id}/releases/v0.1", maintainer) - expect(json_response['assets']['sources'].map { |h| h['format'] }) + expect(json_response["assets"]["sources"].map { |h| h["format"] }) .to match_array(release.sources.map(&:format)) - expect(json_response['assets']['sources'].map { |h| h['url'] }) + expect(json_response["assets"]["sources"].map { |h| h["url"] }) .to match_array(release.sources.map(&:url)) end context "when release description contains confidential issue's link" do let(:confidential_issue) do create(:issue, - :confidential, - project: project, - title: 'A vulnerability') + :confidential, + project: project, + title: "A vulnerability") end let!(:release) do create(:release, - project: project, - tag: 'v0.1', - sha: commit.id, - author: maintainer, - description: "This is confidential #{confidential_issue.to_reference}") + project: project, + tag: "v0.1", + sha: commit.id, + author: maintainer, + description: "This is confidential #{confidential_issue.to_reference}") end it "does not expose confidential issue's title" do get api("/projects/#{project.id}/releases/v0.1", maintainer) - expect(json_response['description_html']).to include(confidential_issue.to_reference) - expect(json_response['description_html']).not_to include('A vulnerability') + expect(json_response["description_html"]).to include(confidential_issue.to_reference) + expect(json_response["description_html"]).not_to include("A vulnerability") end end - context 'when release has link asset' do + context "when release has link asset" do let!(:link) do create(:release_link, - release: release, - name: 'release-18.04.dmg', - url: url) + release: release, + name: "release-18.04.dmg", + url: url) end - let(:url) { 'https://my-external-hosting.example.com/scrambled-url/app.zip' } + let(:url) { "https://my-external-hosting.example.com/scrambled-url/app.zip" } - it 'contains link information as assets' do + it "contains link information as assets" do get api("/projects/#{project.id}/releases/v0.1", maintainer) - expect(json_response['assets']['links'].count).to eq(1) - expect(json_response['assets']['links'].first['id']).to eq(link.id) - expect(json_response['assets']['links'].first['name']) - .to eq('release-18.04.dmg') - expect(json_response['assets']['links'].first['url']) - .to eq('https://my-external-hosting.example.com/scrambled-url/app.zip') - expect(json_response['assets']['links'].first['external']) + expect(json_response["assets"]["links"].count).to eq(1) + expect(json_response["assets"]["links"].first["id"]).to eq(link.id) + expect(json_response["assets"]["links"].first["name"]) + .to eq("release-18.04.dmg") + expect(json_response["assets"]["links"].first["url"]) + .to eq("https://my-external-hosting.example.com/scrambled-url/app.zip") + expect(json_response["assets"]["links"].first["external"]) .to be_truthy end - context 'when link is internal' do + context "when link is internal" do let(:url) do "#{project.web_url}/-/jobs/artifacts/v11.6.0-rc4/download?" \ "job=rspec-mysql+41%2F50" end - it 'has external false' do + it "has external false" do get api("/projects/#{project.id}/releases/v0.1", maintainer) - expect(json_response['assets']['links'].first['external']) + expect(json_response["assets"]["links"].first["external"]) .to be_falsy end end end end - context 'when specified tag is not found in the project' do - it 'cannot find the release entry' do + context "when specified tag is not found in the project" do + it "cannot find the release entry" do get api("/projects/#{project.id}/releases/non_exist_tag", maintainer) expect(response).to have_gitlab_http_status(:forbidden) end end - context 'when user is not a project member' do - let!(:release) { create(:release, tag: 'v0.1', project: project) } + context "when user is not a project member" do + let!(:release) { create(:release, tag: "v0.1", project: project) } - it 'cannot find the project' do + it "cannot find the project" do get api("/projects/#{project.id}/releases/v0.1", non_project_member) expect(response).to have_gitlab_http_status(:not_found) end - context 'when project is public' do + context "when project is public" do let(:project) { create(:project, :repository, :public) } - it 'allows the request' do + it "allows the request" do get api("/projects/#{project.id}/releases/v0.1", non_project_member) expect(response).to have_gitlab_http_status(:ok) @@ -220,166 +220,166 @@ describe API::Releases do end end - describe 'POST /projects/:id/releases' do + describe "POST /projects/:id/releases" do let(:params) do { - name: 'New release', - tag_name: 'v0.1', - description: 'Super nice release' + name: "New release", + tag_name: "v0.1", + description: "Super nice release", } end - it 'accepts the request' do + it "accepts the request" do post api("/projects/#{project.id}/releases", maintainer), params: params expect(response).to have_gitlab_http_status(:created) end - it 'creates a new release' do - expect do + it "creates a new release" do + expect { post api("/projects/#{project.id}/releases", maintainer), params: params - end.to change { Release.count }.by(1) + }.to change { Release.count }.by(1) - expect(project.releases.last.name).to eq('New release') - expect(project.releases.last.tag).to eq('v0.1') - expect(project.releases.last.description).to eq('Super nice release') + expect(project.releases.last.name).to eq("New release") + expect(project.releases.last.tag).to eq("v0.1") + expect(project.releases.last.description).to eq("Super nice release") end - context 'when description is empty' do + context "when description is empty" do let(:params) do { - name: 'New release', - tag_name: 'v0.1', - description: '' + name: "New release", + tag_name: "v0.1", + description: "", } end - it 'returns an error as validation failure' do - expect do + it "returns an error as validation failure" do + expect { post api("/projects/#{project.id}/releases", maintainer), params: params - end.not_to change { Release.count } + }.not_to change { Release.count } expect(response).to have_gitlab_http_status(:bad_request) - expect(json_response['message']) + expect(json_response["message"]) .to eq("Validation failed: Description can't be blank") end end - it 'matches response schema' do + it "matches response schema" do post api("/projects/#{project.id}/releases", maintainer), params: params - expect(response).to match_response_schema('release') + expect(response).to match_response_schema("release") end - it 'does not create a new tag' do - expect do + it "does not create a new tag" do + expect { post api("/projects/#{project.id}/releases", maintainer), params: params - end.not_to change { Project.find_by_id(project.id).repository.tag_count } + }.not_to change { Project.find_by_id(project.id).repository.tag_count } end - context 'when user is a reporter' do - it 'forbids the request' do + context "when user is a reporter" do + it "forbids the request" do post api("/projects/#{project.id}/releases", reporter), params: params expect(response).to have_gitlab_http_status(:forbidden) end end - context 'when user is not a project member' do - it 'forbids the request' do + context "when user is not a project member" do + it "forbids the request" do post api("/projects/#{project.id}/releases", non_project_member), - params: params + params: params expect(response).to have_gitlab_http_status(:not_found) end - context 'when project is public' do + context "when project is public" do let(:project) { create(:project, :repository, :public) } - it 'forbids the request' do + it "forbids the request" do post api("/projects/#{project.id}/releases", non_project_member), - params: params + params: params expect(response).to have_gitlab_http_status(:forbidden) end end - context 'when create assets altogether' do + context "when create assets altogether" do let(:base_params) do { - name: 'New release', - tag_name: 'v0.1', - description: 'Super nice release' + name: "New release", + tag_name: "v0.1", + description: "Super nice release", } end - context 'when create one asset' do + context "when create one asset" do let(:params) do base_params.merge({ assets: { - links: [{ name: 'beta', url: 'https://dosuken.example.com/inspection.exe' }] - } + links: [{name: "beta", url: "https://dosuken.example.com/inspection.exe"}], + }, }) end - it 'accepts the request' do + it "accepts the request" do post api("/projects/#{project.id}/releases", maintainer), params: params expect(response).to have_gitlab_http_status(:created) end - it 'creates an asset with specified parameters' do + it "creates an asset with specified parameters" do post api("/projects/#{project.id}/releases", maintainer), params: params - expect(json_response['assets']['links'].count).to eq(1) - expect(json_response['assets']['links'].first['name']).to eq('beta') - expect(json_response['assets']['links'].first['url']) - .to eq('https://dosuken.example.com/inspection.exe') + expect(json_response["assets"]["links"].count).to eq(1) + expect(json_response["assets"]["links"].first["name"]).to eq("beta") + expect(json_response["assets"]["links"].first["url"]) + .to eq("https://dosuken.example.com/inspection.exe") end - it 'matches response schema' do + it "matches response schema" do post api("/projects/#{project.id}/releases", maintainer), params: params - expect(response).to match_response_schema('release') + expect(response).to match_response_schema("release") end end - context 'when create two assets' do + context "when create two assets" do let(:params) do base_params.merge({ assets: { links: [ - { name: 'alpha', url: 'https://dosuken.example.com/alpha.exe' }, - { name: 'beta', url: 'https://dosuken.example.com/beta.exe' } - ] - } + {name: "alpha", url: "https://dosuken.example.com/alpha.exe"}, + {name: "beta", url: "https://dosuken.example.com/beta.exe"}, + ], + }, }) end - it 'creates two assets with specified parameters' do + it "creates two assets with specified parameters" do post api("/projects/#{project.id}/releases", maintainer), params: params - expect(json_response['assets']['links'].count).to eq(2) - expect(json_response['assets']['links'].map { |h| h['name'] }) + expect(json_response["assets"]["links"].count).to eq(2) + expect(json_response["assets"]["links"].map { |h| h["name"] }) .to match_array(%w[alpha beta]) - expect(json_response['assets']['links'].map { |h| h['url'] }) + expect(json_response["assets"]["links"].map { |h| h["url"] }) .to match_array(%w[https://dosuken.example.com/alpha.exe https://dosuken.example.com/beta.exe]) end - context 'when link names are duplicates' do + context "when link names are duplicates" do let(:params) do base_params.merge({ assets: { links: [ - { name: 'alpha', url: 'https://dosuken.example.com/alpha.exe' }, - { name: 'alpha', url: 'https://dosuken.example.com/beta.exe' } - ] - } + {name: "alpha", url: "https://dosuken.example.com/alpha.exe"}, + {name: "alpha", url: "https://dosuken.example.com/beta.exe"}, + ], + }, }) end - it 'recognizes as a bad request' do + it "recognizes as a bad request" do post api("/projects/#{project.id}/releases", maintainer), params: params expect(response).to have_gitlab_http_status(:bad_request) @@ -389,71 +389,72 @@ describe API::Releases do end end - context 'when tag does not exist in git repository' do + context "when tag does not exist in git repository" do let(:params) do { - name: 'Android ~ Ice Cream Sandwich ~', + name: "Android ~ Ice Cream Sandwich ~", tag_name: tag_name, description: 'Android 4.0–4.0.4 "Ice Cream Sandwich" is the ninth' \ - 'version of the Android mobile operating system developed' \ - 'by Google.', - ref: 'master' + "version of the Android mobile operating system developed" \ + "by Google.", + ref: "master", } end - let(:tag_name) { 'v4.0' } + let(:tag_name) { "v4.0" } - it 'creates a new tag' do - expect do + it "creates a new tag" do + expect { post api("/projects/#{project.id}/releases", maintainer), params: params - end.to change { Project.find_by_id(project.id).repository.tag_count }.by(1) + }.to change { Project.find_by_id(project.id).repository.tag_count }.by(1) - expect(project.repository.find_tag('v4.0').dereferenced_target.id) - .to eq(project.repository.commit('master').id) + expect(project.repository.find_tag("v4.0").dereferenced_target.id) + .to eq(project.repository.commit("master").id) end - it 'creates a new release' do - expect do + it "creates a new release" do + expect { post api("/projects/#{project.id}/releases", maintainer), params: params - end.to change { Release.count }.by(1) + }.to change { Release.count }.by(1) - expect(project.releases.last.name).to eq('Android ~ Ice Cream Sandwich ~') - expect(project.releases.last.tag).to eq('v4.0') + expect(project.releases.last.name).to eq("Android ~ Ice Cream Sandwich ~") + expect(project.releases.last.tag).to eq("v4.0") expect(project.releases.last.description).to eq( 'Android 4.0–4.0.4 "Ice Cream Sandwich" is the ninth' \ - 'version of the Android mobile operating system developed' \ - 'by Google.') + "version of the Android mobile operating system developed" \ + "by Google." + ) end - context 'when tag name is HEAD' do - let(:tag_name) { 'HEAD' } + context "when tag name is HEAD" do + let(:tag_name) { "HEAD" } - it 'returns an error as failure on tag creation' do + it "returns an error as failure on tag creation" do post api("/projects/#{project.id}/releases", maintainer), params: params expect(response).to have_gitlab_http_status(:internal_server_error) - expect(json_response['message']).to eq('Tag name invalid') + expect(json_response["message"]).to eq("Tag name invalid") end end - context 'when tag name is empty' do - let(:tag_name) { '' } + context "when tag name is empty" do + let(:tag_name) { "" } - it 'returns an error as failure on tag creation' do + it "returns an error as failure on tag creation" do post api("/projects/#{project.id}/releases", maintainer), params: params expect(response).to have_gitlab_http_status(:internal_server_error) - expect(json_response['message']).to eq('Tag name invalid') + expect(json_response["message"]).to eq("Tag name invalid") end end end - context 'when release already exists' do + context "when release already exists" do before do - create(:release, project: project, tag: 'v0.1', name: 'New release') + create(:release, project: project, tag: "v0.1", name: "New release") end - it 'returns an error as conflicted request' do + it "returns an error as conflicted request" do post api("/projects/#{project.id}/releases", maintainer), params: params expect(response).to have_gitlab_http_status(:conflict) @@ -461,94 +462,94 @@ describe API::Releases do end end - describe 'PUT /projects/:id/releases/:tag_name' do - let(:params) { { description: 'Best release ever!' } } + describe "PUT /projects/:id/releases/:tag_name" do + let(:params) { {description: "Best release ever!"} } let!(:release) do create(:release, - project: project, - tag: 'v0.1', - name: 'New release', - description: 'Super nice release') + project: project, + tag: "v0.1", + name: "New release", + description: "Super nice release") end - it 'accepts the request' do + it "accepts the request" do put api("/projects/#{project.id}/releases/v0.1", maintainer), params: params expect(response).to have_gitlab_http_status(:ok) end - it 'updates the description' do + it "updates the description" do put api("/projects/#{project.id}/releases/v0.1", maintainer), params: params - expect(project.releases.last.description).to eq('Best release ever!') + expect(project.releases.last.description).to eq("Best release ever!") end - it 'does not change other attributes' do + it "does not change other attributes" do put api("/projects/#{project.id}/releases/v0.1", maintainer), params: params - expect(project.releases.last.tag).to eq('v0.1') - expect(project.releases.last.name).to eq('New release') + expect(project.releases.last.tag).to eq("v0.1") + expect(project.releases.last.name).to eq("New release") end - it 'matches response schema' do + it "matches response schema" do put api("/projects/#{project.id}/releases/v0.1", maintainer), params: params - expect(response).to match_response_schema('release') + expect(response).to match_response_schema("release") end - context 'when user tries to update sha' do - let(:params) { { sha: 'xxx' } } + context "when user tries to update sha" do + let(:params) { {sha: "xxx"} } - it 'does not allow the request' do + it "does not allow the request" do put api("/projects/#{project.id}/releases/v0.1", maintainer), params: params expect(response).to have_gitlab_http_status(:bad_request) end end - context 'when params is empty' do + context "when params is empty" do let(:params) { {} } - it 'does not allow the request' do + it "does not allow the request" do put api("/projects/#{project.id}/releases/v0.1", maintainer), params: params expect(response).to have_gitlab_http_status(:bad_request) end end - context 'when there are no corresponding releases' do + context "when there are no corresponding releases" do let!(:release) { } - it 'forbids the request' do + it "forbids the request" do put api("/projects/#{project.id}/releases/v0.1", maintainer), params: params expect(response).to have_gitlab_http_status(:forbidden) end end - context 'when user is a reporter' do - it 'forbids the request' do + context "when user is a reporter" do + it "forbids the request" do put api("/projects/#{project.id}/releases/v0.1", reporter), params: params expect(response).to have_gitlab_http_status(:forbidden) end end - context 'when user is not a project member' do - it 'forbids the request' do + context "when user is not a project member" do + it "forbids the request" do put api("/projects/#{project.id}/releases/v0.1", non_project_member), - params: params + params: params expect(response).to have_gitlab_http_status(:not_found) end - context 'when project is public' do + context "when project is public" do let(:project) { create(:project, :repository, :public) } - it 'forbids the request' do + it "forbids the request" do put api("/projects/#{project.id}/releases/v0.1", non_project_member), - params: params + params: params expect(response).to have_gitlab_http_status(:forbidden) end @@ -556,68 +557,68 @@ describe API::Releases do end end - describe 'DELETE /projects/:id/releases/:tag_name' do + describe "DELETE /projects/:id/releases/:tag_name" do let!(:release) do create(:release, - project: project, - tag: 'v0.1', - name: 'New release', - description: 'Super nice release') + project: project, + tag: "v0.1", + name: "New release", + description: "Super nice release") end - it 'accepts the request' do + it "accepts the request" do delete api("/projects/#{project.id}/releases/v0.1", maintainer) expect(response).to have_gitlab_http_status(:ok) end - it 'destroys the release' do - expect do + it "destroys the release" do + expect { delete api("/projects/#{project.id}/releases/v0.1", maintainer) - end.to change { Release.count }.by(-1) + }.to change { Release.count }.by(-1) end - it 'does not remove a tag in repository' do - expect do + it "does not remove a tag in repository" do + expect { delete api("/projects/#{project.id}/releases/v0.1", maintainer) - end.not_to change { Project.find_by_id(project.id).repository.tag_count } + }.not_to change { Project.find_by_id(project.id).repository.tag_count } end - it 'matches response schema' do + it "matches response schema" do delete api("/projects/#{project.id}/releases/v0.1", maintainer) - expect(response).to match_response_schema('release') + expect(response).to match_response_schema("release") end - context 'when there are no corresponding releases' do + context "when there are no corresponding releases" do let!(:release) { } - it 'forbids the request' do + it "forbids the request" do delete api("/projects/#{project.id}/releases/v0.1", maintainer) expect(response).to have_gitlab_http_status(:forbidden) end end - context 'when user is a reporter' do - it 'forbids the request' do + context "when user is a reporter" do + it "forbids the request" do delete api("/projects/#{project.id}/releases/v0.1", reporter) expect(response).to have_gitlab_http_status(:forbidden) end end - context 'when user is not a project member' do - it 'forbids the request' do + context "when user is not a project member" do + it "forbids the request" do delete api("/projects/#{project.id}/releases/v0.1", non_project_member) expect(response).to have_gitlab_http_status(:not_found) end - context 'when project is public' do + context "when project is public" do let(:project) { create(:project, :repository, :public) } - it 'forbids the request' do + it "forbids the request" do delete api("/projects/#{project.id}/releases/v0.1", non_project_member) expect(response).to have_gitlab_http_status(:forbidden) diff --git a/spec/requests/api/repositories_spec.rb b/spec/requests/api/repositories_spec.rb index 0adc95cfbeb..0bb0af3f8b3 100644 --- a/spec/requests/api/repositories_spec.rb +++ b/spec/requests/api/repositories_spec.rb @@ -1,5 +1,5 @@ -require 'spec_helper' -require 'mime/types' +require "spec_helper" +require "mime/types" describe API::Repositories do include RepoHelpers @@ -13,8 +13,8 @@ describe API::Repositories do describe "GET /projects/:id/repository/tree" do let(:route) { "/projects/#{project.id}/repository/tree" } - shared_examples_for 'repository tree' do - it 'returns the repository tree' do + shared_examples_for "repository tree" do + it "returns the repository tree" do get api(route, current_user) expect(response).to have_gitlab_http_status(200) @@ -22,78 +22,78 @@ describe API::Repositories do expect(json_response).to be_an Array first_commit = json_response.first - expect(first_commit['name']).to eq('bar') - expect(first_commit['type']).to eq('tree') - expect(first_commit['mode']).to eq('040000') + expect(first_commit["name"]).to eq("bar") + expect(first_commit["type"]).to eq("tree") + expect(first_commit["mode"]).to eq("040000") end - context 'when ref does not exist' do - it_behaves_like '404 response' do + context "when ref does not exist" do + it_behaves_like "404 response" do let(:request) { get api("#{route}?ref=foo", current_user) } - let(:message) { '404 Tree Not Found' } + let(:message) { "404 Tree Not Found" } end end - context 'when repository is disabled' do - include_context 'disabled repository' + context "when repository is disabled" do + include_context "disabled repository" - it_behaves_like '403 response' do + it_behaves_like "403 response" do let(:request) { get api(route, current_user) } end end - context 'with recursive=1' do - it 'returns recursive project paths tree' do + context "with recursive=1" do + it "returns recursive project paths tree" do get api("#{route}?recursive=1", current_user) expect(response.status).to eq(200) expect(json_response).to be_an Array expect(response).to include_pagination_headers - expect(json_response[4]['name']).to eq('html') - expect(json_response[4]['path']).to eq('files/html') - expect(json_response[4]['type']).to eq('tree') - expect(json_response[4]['mode']).to eq('040000') + expect(json_response[4]["name"]).to eq("html") + expect(json_response[4]["path"]).to eq("files/html") + expect(json_response[4]["type"]).to eq("tree") + expect(json_response[4]["mode"]).to eq("040000") end - context 'when repository is disabled' do - include_context 'disabled repository' + context "when repository is disabled" do + include_context "disabled repository" - it_behaves_like '403 response' do + it_behaves_like "403 response" do let(:request) { get api(route, current_user) } end end - context 'when ref does not exist' do - it_behaves_like '404 response' do + context "when ref does not exist" do + it_behaves_like "404 response" do let(:request) { get api("#{route}?recursive=1&ref=foo", current_user) } - let(:message) { '404 Tree Not Found' } + let(:message) { "404 Tree Not Found" } end end end end - context 'when unauthenticated', 'and project is public' do - it_behaves_like 'repository tree' do + context "when unauthenticated", "and project is public" do + it_behaves_like "repository tree" do let(:project) { create(:project, :public, :repository) } let(:current_user) { nil } end end - context 'when unauthenticated', 'and project is private' do - it_behaves_like '404 response' do + context "when unauthenticated", "and project is private" do + it_behaves_like "404 response" do let(:request) { get api(route) } - let(:message) { '404 Project Not Found' } + let(:message) { "404 Project Not Found" } end end - context 'when authenticated', 'as a developer' do - it_behaves_like 'repository tree' do + context "when authenticated", "as a developer" do + it_behaves_like "repository tree" do let(:current_user) { user } end end - context 'when authenticated', 'as a guest' do - it_behaves_like '403 response' do + context "when authenticated", "as a guest" do + it_behaves_like "403 response" do let(:request) { get api(route, guest) } end end @@ -102,55 +102,55 @@ describe API::Repositories do describe "GET /projects/:id/repository/blobs/:sha" do let(:route) { "/projects/#{project.id}/repository/blobs/#{sample_blob.oid}" } - shared_examples_for 'repository blob' do - it 'returns blob attributes as json' do + shared_examples_for "repository blob" do + it "returns blob attributes as json" do get api(route, current_user) expect(response).to have_gitlab_http_status(200) - expect(json_response['size']).to eq(111) - expect(json_response['encoding']).to eq("base64") - expect(Base64.decode64(json_response['content']).lines.first).to eq("class Commit\n") - expect(json_response['sha']).to eq(sample_blob.oid) + expect(json_response["size"]).to eq(111) + expect(json_response["encoding"]).to eq("base64") + expect(Base64.decode64(json_response["content"]).lines.first).to eq("class Commit\n") + expect(json_response["sha"]).to eq(sample_blob.oid) end - context 'when sha does not exist' do - it_behaves_like '404 response' do - let(:request) { get api(route.sub(sample_blob.oid, '123456'), current_user) } - let(:message) { '404 Blob Not Found' } + context "when sha does not exist" do + it_behaves_like "404 response" do + let(:request) { get api(route.sub(sample_blob.oid, "123456"), current_user) } + let(:message) { "404 Blob Not Found" } end end - context 'when repository is disabled' do - include_context 'disabled repository' + context "when repository is disabled" do + include_context "disabled repository" - it_behaves_like '403 response' do + it_behaves_like "403 response" do let(:request) { get api(route, current_user) } end end end - context 'when unauthenticated', 'and project is public' do - it_behaves_like 'repository blob' do + context "when unauthenticated", "and project is public" do + it_behaves_like "repository blob" do let(:project) { create(:project, :public, :repository) } let(:current_user) { nil } end end - context 'when unauthenticated', 'and project is private' do - it_behaves_like '404 response' do + context "when unauthenticated", "and project is private" do + it_behaves_like "404 response" do let(:request) { get api(route) } - let(:message) { '404 Project Not Found' } + let(:message) { "404 Project Not Found" } end end - context 'when authenticated', 'as a developer' do - it_behaves_like 'repository blob' do + context "when authenticated", "as a developer" do + it_behaves_like "repository blob" do let(:current_user) { user } end end - context 'when authenticated', 'as a guest' do - it_behaves_like '403 response' do + context "when authenticated", "as a guest" do + it_behaves_like "403 response" do let(:request) { get api(route, guest) } end end @@ -159,8 +159,8 @@ describe API::Repositories do describe "GET /projects/:id/repository/blobs/:sha/raw" do let(:route) { "/projects/#{project.id}/repository/blobs/#{sample_blob.oid}/raw" } - shared_examples_for 'repository raw blob' do - it 'returns the repository raw blob' do + shared_examples_for "repository raw blob" do + it "returns the repository raw blob" do expect(Gitlab::Workhorse).to receive(:send_git_blob) get api(route, current_user) @@ -169,50 +169,50 @@ describe API::Repositories do expect(headers[Gitlab::Workhorse::DETECT_HEADER]).to eq "true" end - it 'sets inline content disposition by default' do + it "sets inline content disposition by default" do get api(route, current_user) - expect(headers['Content-Disposition']).to eq 'inline' + expect(headers["Content-Disposition"]).to eq "inline" end - context 'when sha does not exist' do - it_behaves_like '404 response' do - let(:request) { get api(route.sub(sample_blob.oid, '123456'), current_user) } - let(:message) { '404 Blob Not Found' } + context "when sha does not exist" do + it_behaves_like "404 response" do + let(:request) { get api(route.sub(sample_blob.oid, "123456"), current_user) } + let(:message) { "404 Blob Not Found" } end end - context 'when repository is disabled' do - include_context 'disabled repository' + context "when repository is disabled" do + include_context "disabled repository" - it_behaves_like '403 response' do + it_behaves_like "403 response" do let(:request) { get api(route, current_user) } end end end - context 'when unauthenticated', 'and project is public' do - it_behaves_like 'repository raw blob' do + context "when unauthenticated", "and project is public" do + it_behaves_like "repository raw blob" do let(:project) { create(:project, :public, :repository) } let(:current_user) { nil } end end - context 'when unauthenticated', 'and project is private' do - it_behaves_like '404 response' do + context "when unauthenticated", "and project is private" do + it_behaves_like "404 response" do let(:request) { get api(route) } - let(:message) { '404 Project Not Found' } + let(:message) { "404 Project Not Found" } end end - context 'when authenticated', 'as a developer' do - it_behaves_like 'repository raw blob' do + context "when authenticated", "as a developer" do + it_behaves_like "repository raw blob" do let(:current_user) { user } end end - context 'when authenticated', 'as a guest' do - it_behaves_like '403 response' do + context "when authenticated", "as a guest" do + it_behaves_like "403 response" do let(:request) { get api(route, guest) } end end @@ -221,179 +221,179 @@ describe API::Repositories do describe "GET /projects/:id/repository/archive(.:format)?:sha" do let(:route) { "/projects/#{project.id}/repository/archive" } - shared_examples_for 'repository archive' do - it 'returns the repository archive' do + shared_examples_for "repository archive" do + it "returns the repository archive" do get api(route, current_user) expect(response).to have_gitlab_http_status(200) type, params = workhorse_send_data - expect(type).to eq('git-archive') - expect(params['ArchivePath']).to match(/#{project.path}\-[^\.]+\.tar.gz/) + expect(type).to eq("git-archive") + expect(params["ArchivePath"]).to match(/#{project.path}\-[^\.]+\.tar.gz/) end - it 'returns the repository archive archive.zip' do + it "returns the repository archive archive.zip" do get api("/projects/#{project.id}/repository/archive.zip", user) expect(response).to have_gitlab_http_status(200) type, params = workhorse_send_data - expect(type).to eq('git-archive') - expect(params['ArchivePath']).to match(/#{project.path}\-[^\.]+\.zip/) + expect(type).to eq("git-archive") + expect(params["ArchivePath"]).to match(/#{project.path}\-[^\.]+\.zip/) end - it 'returns the repository archive archive.tar.bz2' do + it "returns the repository archive archive.tar.bz2" do get api("/projects/#{project.id}/repository/archive.tar.bz2", user) expect(response).to have_gitlab_http_status(200) type, params = workhorse_send_data - expect(type).to eq('git-archive') - expect(params['ArchivePath']).to match(/#{project.path}\-[^\.]+\.tar.bz2/) + expect(type).to eq("git-archive") + expect(params["ArchivePath"]).to match(/#{project.path}\-[^\.]+\.tar.bz2/) end - context 'when sha does not exist' do - it_behaves_like '404 response' do + context "when sha does not exist" do + it_behaves_like "404 response" do let(:request) { get api("#{route}?sha=xxx", current_user) } - let(:message) { '404 File Not Found' } + let(:message) { "404 File Not Found" } end end end - context 'when unauthenticated', 'and project is public' do - it_behaves_like 'repository archive' do + context "when unauthenticated", "and project is public" do + it_behaves_like "repository archive" do let(:project) { create(:project, :public, :repository) } let(:current_user) { nil } end end - context 'when unauthenticated', 'and project is private' do - it_behaves_like '404 response' do + context "when unauthenticated", "and project is private" do + it_behaves_like "404 response" do let(:request) { get api(route) } - let(:message) { '404 Project Not Found' } + let(:message) { "404 Project Not Found" } end end - context 'when authenticated', 'as a developer' do - it_behaves_like 'repository archive' do + context "when authenticated", "as a developer" do + it_behaves_like "repository archive" do let(:current_user) { user } end end - context 'when authenticated', 'as a guest' do - it_behaves_like '403 response' do + context "when authenticated", "as a guest" do + it_behaves_like "403 response" do let(:request) { get api(route, guest) } end end end - describe 'GET /projects/:id/repository/compare' do + describe "GET /projects/:id/repository/compare" do let(:route) { "/projects/#{project.id}/repository/compare" } - shared_examples_for 'repository compare' do + shared_examples_for "repository compare" do it "compares branches" do expect(::Gitlab::Git::Compare).to receive(:new).with(anything, anything, anything, { - straight: false + straight: false, }).and_call_original - get api(route, current_user), params: { from: 'master', to: 'feature' } + get api(route, current_user), params: {from: "master", to: "feature"} expect(response).to have_gitlab_http_status(200) - expect(json_response['commits']).to be_present - expect(json_response['diffs']).to be_present + expect(json_response["commits"]).to be_present + expect(json_response["diffs"]).to be_present end it "compares branches with explicit merge-base mode" do expect(::Gitlab::Git::Compare).to receive(:new).with(anything, anything, anything, { - straight: false + straight: false, }).and_call_original - get api(route, current_user), params: { from: 'master', to: 'feature', straight: false } + get api(route, current_user), params: {from: "master", to: "feature", straight: false} expect(response).to have_gitlab_http_status(200) - expect(json_response['commits']).to be_present - expect(json_response['diffs']).to be_present + expect(json_response["commits"]).to be_present + expect(json_response["diffs"]).to be_present end it "compares branches with explicit straight mode" do expect(::Gitlab::Git::Compare).to receive(:new).with(anything, anything, anything, { - straight: true + straight: true, }).and_call_original - get api(route, current_user), params: { from: 'master', to: 'feature', straight: true } + get api(route, current_user), params: {from: "master", to: "feature", straight: true} expect(response).to have_gitlab_http_status(200) - expect(json_response['commits']).to be_present - expect(json_response['diffs']).to be_present + expect(json_response["commits"]).to be_present + expect(json_response["diffs"]).to be_present end it "compares tags" do - get api(route, current_user), params: { from: 'v1.0.0', to: 'v1.1.0' } + get api(route, current_user), params: {from: "v1.0.0", to: "v1.1.0"} expect(response).to have_gitlab_http_status(200) - expect(json_response['commits']).to be_present - expect(json_response['diffs']).to be_present + expect(json_response["commits"]).to be_present + expect(json_response["diffs"]).to be_present end it "compares commits" do - get api(route, current_user), params: { from: sample_commit.id, to: sample_commit.parent_id } + get api(route, current_user), params: {from: sample_commit.id, to: sample_commit.parent_id} expect(response).to have_gitlab_http_status(200) - expect(json_response['commits']).to be_empty - expect(json_response['diffs']).to be_empty - expect(json_response['compare_same_ref']).to be_falsey + expect(json_response["commits"]).to be_empty + expect(json_response["diffs"]).to be_empty + expect(json_response["compare_same_ref"]).to be_falsey end it "compares commits in reverse order" do - get api(route, current_user), params: { from: sample_commit.parent_id, to: sample_commit.id } + get api(route, current_user), params: {from: sample_commit.parent_id, to: sample_commit.id} expect(response).to have_gitlab_http_status(200) - expect(json_response['commits']).to be_present - expect(json_response['diffs']).to be_present + expect(json_response["commits"]).to be_present + expect(json_response["diffs"]).to be_present end it "compares same refs" do - get api(route, current_user), params: { from: 'master', to: 'master' } + get api(route, current_user), params: {from: "master", to: "master"} expect(response).to have_gitlab_http_status(200) - expect(json_response['commits']).to be_empty - expect(json_response['diffs']).to be_empty - expect(json_response['compare_same_ref']).to be_truthy + expect(json_response["commits"]).to be_empty + expect(json_response["diffs"]).to be_empty + expect(json_response["compare_same_ref"]).to be_truthy end end - context 'when unauthenticated', 'and project is public' do - it_behaves_like 'repository compare' do + context "when unauthenticated", "and project is public" do + it_behaves_like "repository compare" do let(:project) { create(:project, :public, :repository) } let(:current_user) { nil } end end - context 'when unauthenticated', 'and project is private' do - it_behaves_like '404 response' do + context "when unauthenticated", "and project is private" do + it_behaves_like "404 response" do let(:request) { get api(route) } - let(:message) { '404 Project Not Found' } + let(:message) { "404 Project Not Found" } end end - context 'when authenticated', 'as a developer' do - it_behaves_like 'repository compare' do + context "when authenticated", "as a developer" do + it_behaves_like "repository compare" do let(:current_user) { user } end end - context 'when authenticated', 'as a guest' do - it_behaves_like '403 response' do + context "when authenticated", "as a guest" do + it_behaves_like "403 response" do let(:request) { get api(route, guest) } end end end - describe 'GET /projects/:id/repository/contributors' do + describe "GET /projects/:id/repository/contributors" do let(:route) { "/projects/#{project.id}/repository/contributors" } - shared_examples_for 'repository contributors' do - it 'returns valid data' do + shared_examples_for "repository contributors" do + it "returns valid data" do get api(route, current_user) expect(response).to have_gitlab_http_status(200) @@ -401,147 +401,147 @@ describe API::Repositories do expect(json_response).to be_an Array first_contributor = json_response.first - expect(first_contributor['email']).to eq('tiagonbotelho@hotmail.com') - expect(first_contributor['name']).to eq('tiagonbotelho') - expect(first_contributor['commits']).to eq(1) - expect(first_contributor['additions']).to eq(0) - expect(first_contributor['deletions']).to eq(0) + expect(first_contributor["email"]).to eq("tiagonbotelho@hotmail.com") + expect(first_contributor["name"]).to eq("tiagonbotelho") + expect(first_contributor["commits"]).to eq(1) + expect(first_contributor["additions"]).to eq(0) + expect(first_contributor["deletions"]).to eq(0) end - context 'using sorting' do - context 'by commits desc' do - it 'returns the repository contribuors sorted by commits desc' do - get api(route, current_user), params: { order_by: 'commits', sort: 'desc' } + context "using sorting" do + context "by commits desc" do + it "returns the repository contribuors sorted by commits desc" do + get api(route, current_user), params: {order_by: "commits", sort: "desc"} expect(response).to have_gitlab_http_status(200) - expect(response).to match_response_schema('contributors') - expect(json_response.first['commits']).to be > json_response.last['commits'] + expect(response).to match_response_schema("contributors") + expect(json_response.first["commits"]).to be > json_response.last["commits"] end end - context 'by name desc' do - it 'returns the repository contribuors sorted by name asc case insensitive' do - get api(route, current_user), params: { order_by: 'name', sort: 'asc' } + context "by name desc" do + it "returns the repository contribuors sorted by name asc case insensitive" do + get api(route, current_user), params: {order_by: "name", sort: "asc"} expect(response).to have_gitlab_http_status(200) - expect(response).to match_response_schema('contributors') - expect(json_response.first['name'].downcase).to be < json_response.last['name'].downcase + expect(response).to match_response_schema("contributors") + expect(json_response.first["name"].downcase).to be < json_response.last["name"].downcase end end end end - context 'when unauthenticated', 'and project is public' do - it_behaves_like 'repository contributors' do + context "when unauthenticated", "and project is public" do + it_behaves_like "repository contributors" do let(:project) { create(:project, :public, :repository) } let(:current_user) { nil } end end - context 'when unauthenticated', 'and project is private' do - it_behaves_like '404 response' do + context "when unauthenticated", "and project is private" do + it_behaves_like "404 response" do let(:request) { get api(route) } - let(:message) { '404 Project Not Found' } + let(:message) { "404 Project Not Found" } end end - context 'when authenticated', 'as a developer' do - it_behaves_like 'repository contributors' do + context "when authenticated", "as a developer" do + it_behaves_like "repository contributors" do let(:current_user) { user } end end - context 'when authenticated', 'as a guest' do - it_behaves_like '403 response' do + context "when authenticated", "as a guest" do + it_behaves_like "403 response" do let(:request) { get api(route, guest) } end end # Regression: https://gitlab.com/gitlab-org/gitlab-ce/issues/45363 - describe 'Links header contains working URLs when no `order_by` nor `sort` is given' do + describe "Links header contains working URLs when no `order_by` nor `sort` is given" do let(:project) { create(:project, :public, :repository) } let(:current_user) { nil } - it 'returns `Link` header that includes URLs with default value for `order_by` & `sort`' do + it "returns `Link` header that includes URLs with default value for `order_by` & `sort`" do get api(route, current_user) - first_link_url = response.headers['Link'].split(';').first + first_link_url = response.headers["Link"].split(";").first - expect(first_link_url).to include('order_by=commits') - expect(first_link_url).to include('sort=asc') + expect(first_link_url).to include("order_by=commits") + expect(first_link_url).to include("sort=asc") end end end - describe 'GET :id/repository/merge_base' do + describe "GET :id/repository/merge_base" do let(:refs) do - %w(304d257dcb821665ab5110318fc58a007bd104ed 0031876facac3f2b2702a0e53a26e89939a42209 570e7b2abdd848b95f2f578043fc23bd6f6fd24d) + %w[304d257dcb821665ab5110318fc58a007bd104ed 0031876facac3f2b2702a0e53a26e89939a42209 570e7b2abdd848b95f2f578043fc23bd6f6fd24d] end subject(:request) do - get(api("/projects/#{project.id}/repository/merge_base", current_user), params: { refs: refs }) + get(api("/projects/#{project.id}/repository/merge_base", current_user), params: {refs: refs}) end - shared_examples 'merge base' do - it 'returns the common ancestor' do + shared_examples "merge base" do + it "returns the common ancestor" do request expect(response).to have_gitlab_http_status(:success) - expect(json_response['id']).to be_present + expect(json_response["id"]).to be_present end end - context 'when unauthenticated', 'and project is public' do - it_behaves_like 'merge base' do + context "when unauthenticated", "and project is public" do + it_behaves_like "merge base" do let(:project) { create(:project, :public, :repository) } let(:current_user) { nil } end end - context 'when unauthenticated', 'and project is private' do - it_behaves_like '404 response' do + context "when unauthenticated", "and project is private" do + it_behaves_like "404 response" do let(:current_user) { nil } - let(:message) { '404 Project Not Found' } + let(:message) { "404 Project Not Found" } end end - context 'when authenticated', 'as a developer' do - it_behaves_like 'merge base' do + context "when authenticated", "as a developer" do + it_behaves_like "merge base" do let(:current_user) { user } end end - context 'when authenticated', 'as a guest' do - it_behaves_like '403 response' do + context "when authenticated", "as a guest" do + it_behaves_like "403 response" do let(:current_user) { guest } end end - context 'when passing refs that do not exist' do - it_behaves_like '400 response' do - let(:refs) { %w(304d257dcb821665ab5110318fc58a007bd104ed missing) } + context "when passing refs that do not exist" do + it_behaves_like "400 response" do + let(:refs) { %w[304d257dcb821665ab5110318fc58a007bd104ed missing] } let(:current_user) { user } - let(:message) { 'Could not find ref: missing' } + let(:message) { "Could not find ref: missing" } end end - context 'when passing refs that do not have a merge base' do - it_behaves_like '404 response' do - let(:refs) { ['304d257dcb821665ab5110318fc58a007bd104ed', TestEnv::BRANCH_SHA['orphaned-branch']] } + context "when passing refs that do not have a merge base" do + it_behaves_like "404 response" do + let(:refs) { ["304d257dcb821665ab5110318fc58a007bd104ed", TestEnv::BRANCH_SHA["orphaned-branch"]] } let(:current_user) { user } - let(:message) { '404 Merge Base Not Found' } + let(:message) { "404 Merge Base Not Found" } end end - context 'when not enough refs are passed' do - let(:refs) { %w(only-one) } + context "when not enough refs are passed" do + let(:refs) { %w[only-one] } let(:current_user) { user } - it 'renders a bad request error' do + it "renders a bad request error" do request expect(response).to have_gitlab_http_status(:bad_request) - expect(json_response['message']).to eq('Provide at least 2 refs') + expect(json_response["message"]).to eq("Provide at least 2 refs") end end end diff --git a/spec/requests/api/resource_label_events_spec.rb b/spec/requests/api/resource_label_events_spec.rb index 37b46eaeb86..4c8ae3cf6a9 100644 --- a/spec/requests/api/resource_label_events_spec.rb +++ b/spec/requests/api/resource_label_events_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'spec_helper' +require "spec_helper" describe API::ResourceLabelEvents do set(:user) { create(:user) } @@ -11,7 +11,7 @@ describe API::ResourceLabelEvents do project.add_developer(user) end - shared_examples 'resource_label_events API' do |parent_type, eventable_type, id_name| + shared_examples "resource_label_events API" do |parent_type, eventable_type, id_name| describe "GET /#{parent_type}/:id/#{eventable_type}/:noteable_id/resource_label_events" do it "returns an array of resource label events" do get api("/#{parent_type}/#{parent.id}/#{eventable_type}/#{eventable[id_name]}/resource_label_events", user) @@ -19,7 +19,7 @@ describe API::ResourceLabelEvents do expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response).to be_an Array - expect(json_response.first['id']).to eq(event.id) + expect(json_response.first["id"]).to eq(event.id) end it "returns a 404 error when eventable id not found" do @@ -42,7 +42,7 @@ describe API::ResourceLabelEvents do get api("/#{parent_type}/#{parent.id}/#{eventable_type}/#{eventable[id_name]}/resource_label_events/#{event.id}", user) expect(response).to have_gitlab_http_status(200) - expect(json_response['id']).to eq(event.id) + expect(json_response["id"]).to eq(event.id) end it "returns a 404 error if resource label event not found" do @@ -53,20 +53,20 @@ describe API::ResourceLabelEvents do end end - context 'when eventable is an Issue' do + context "when eventable is an Issue" do let(:issue) { create(:issue, project: project, author: user) } - it_behaves_like 'resource_label_events API', 'projects', 'issues', 'iid' do + it_behaves_like "resource_label_events API", "projects", "issues", "iid" do let(:parent) { project } let(:eventable) { issue } let!(:event) { create(:resource_label_event, issue: issue) } end end - context 'when eventable is a Merge Request' do + context "when eventable is a Merge Request" do let(:merge_request) { create(:merge_request, source_project: project, target_project: project, author: user) } - it_behaves_like 'resource_label_events API', 'projects', 'merge_requests', 'iid' do + it_behaves_like "resource_label_events API", "projects", "merge_requests", "iid" do let(:parent) { project } let(:eventable) { merge_request } let!(:event) { create(:resource_label_event, merge_request: merge_request) } diff --git a/spec/requests/api/runner_spec.rb b/spec/requests/api/runner_spec.rb index 43c06f7c973..7f87a1a4f60 100644 --- a/spec/requests/api/runner_spec.rb +++ b/spec/requests/api/runner_spec.rb @@ -1,10 +1,10 @@ -require 'spec_helper' +require "spec_helper" describe API::Runner, :clean_gitlab_redis_shared_state do include StubGitlabCalls include RedisHelpers - let(:registration_token) { 'abcdefg123456' } + let(:registration_token) { "abcdefg123456" } before do stub_feature_flags(ci_enable_live_trace: true) @@ -13,44 +13,44 @@ describe API::Runner, :clean_gitlab_redis_shared_state do allow_any_instance_of(Ci::Runner).to receive(:cache_attributes) end - describe '/api/v4/runners' do - describe 'POST /api/v4/runners' do - context 'when no token is provided' do - it 'returns 400 error' do - post api('/runners') + describe "/api/v4/runners" do + describe "POST /api/v4/runners" do + context "when no token is provided" do + it "returns 400 error" do + post api("/runners") expect(response).to have_gitlab_http_status 400 end end - context 'when invalid token is provided' do - it 'returns 403 error' do - post api('/runners'), params: { token: 'invalid' } + context "when invalid token is provided" do + it "returns 403 error" do + post api("/runners"), params: {token: "invalid"} expect(response).to have_gitlab_http_status 403 end end - context 'when valid token is provided' do - it 'creates runner with default values' do - post api('/runners'), params: { token: registration_token } + context "when valid token is provided" do + it "creates runner with default values" do + post api("/runners"), params: {token: registration_token} runner = Ci::Runner.first expect(response).to have_gitlab_http_status 201 - expect(json_response['id']).to eq(runner.id) - expect(json_response['token']).to eq(runner.token) + expect(json_response["id"]).to eq(runner.id) + expect(json_response["token"]).to eq(runner.token) expect(runner.run_untagged).to be true expect(runner.active).to be true expect(runner.token).not_to eq(registration_token) expect(runner).to be_instance_type end - context 'when project token is used' do + context "when project token is used" do let(:project) { create(:project) } - it 'creates project runner' do - post api('/runners'), params: { token: project.runners_token } + it "creates project runner" do + post api("/runners"), params: {token: project.runners_token} expect(response).to have_gitlab_http_status 201 expect(project.runners.size).to eq(1) @@ -61,11 +61,11 @@ describe API::Runner, :clean_gitlab_redis_shared_state do end end - context 'when group token is used' do + context "when group token is used" do let(:group) { create(:group) } - it 'creates a group runner' do - post api('/runners'), params: { token: group.runners_token } + it "creates a group runner" do + post api("/runners"), params: {token: group.runners_token} expect(response).to have_http_status 201 expect(group.runners.size).to eq(1) @@ -77,90 +77,91 @@ describe API::Runner, :clean_gitlab_redis_shared_state do end end - context 'when runner description is provided' do - it 'creates runner' do - post api('/runners'), params: { - token: registration_token, - description: 'server.hostname' - } + context "when runner description is provided" do + it "creates runner" do + post api("/runners"), params: { + token: registration_token, + description: "server.hostname", + } expect(response).to have_gitlab_http_status 201 - expect(Ci::Runner.first.description).to eq('server.hostname') + expect(Ci::Runner.first.description).to eq("server.hostname") end end - context 'when runner tags are provided' do - it 'creates runner' do - post api('/runners'), params: { - token: registration_token, - tag_list: 'tag1, tag2' - } + context "when runner tags are provided" do + it "creates runner" do + post api("/runners"), params: { + token: registration_token, + tag_list: "tag1, tag2", + } expect(response).to have_gitlab_http_status 201 - expect(Ci::Runner.first.tag_list.sort).to eq(%w(tag1 tag2)) + expect(Ci::Runner.first.tag_list.sort).to eq(%w[tag1 tag2]) end end - context 'when option for running untagged jobs is provided' do - context 'when tags are provided' do - it 'creates runner' do - post api('/runners'), params: { - token: registration_token, - run_untagged: false, - tag_list: ['tag'] - } + context "when option for running untagged jobs is provided" do + context "when tags are provided" do + it "creates runner" do + post api("/runners"), params: { + token: registration_token, + run_untagged: false, + tag_list: ["tag"], + } expect(response).to have_gitlab_http_status 201 expect(Ci::Runner.first.run_untagged).to be false - expect(Ci::Runner.first.tag_list.sort).to eq(['tag']) + expect(Ci::Runner.first.tag_list.sort).to eq(["tag"]) end end - context 'when tags are not provided' do - it 'returns 400 error' do - post api('/runners'), params: { - token: registration_token, - run_untagged: false - } + context "when tags are not provided" do + it "returns 400 error" do + post api("/runners"), params: { + token: registration_token, + run_untagged: false, + } expect(response).to have_gitlab_http_status 400 - expect(json_response['message']).to include( - 'tags_list' => ['can not be empty when runner is not allowed to pick untagged jobs']) + expect(json_response["message"]).to include( + "tags_list" => ["can not be empty when runner is not allowed to pick untagged jobs"] + ) end end end - context 'when option for locking Runner is provided' do - it 'creates runner' do - post api('/runners'), params: { - token: registration_token, - locked: true - } + context "when option for locking Runner is provided" do + it "creates runner" do + post api("/runners"), params: { + token: registration_token, + locked: true, + } expect(response).to have_gitlab_http_status 201 expect(Ci::Runner.first.locked).to be true end end - context 'when option for activating a Runner is provided' do - context 'when active is set to true' do - it 'creates runner' do - post api('/runners'), params: { - token: registration_token, - active: true - } + context "when option for activating a Runner is provided" do + context "when active is set to true" do + it "creates runner" do + post api("/runners"), params: { + token: registration_token, + active: true, + } expect(response).to have_gitlab_http_status 201 expect(Ci::Runner.first.active).to be true end end - context 'when active is set to false' do - it 'creates runner' do - post api('/runners'), params: { - token: registration_token, - active: false - } + context "when active is set to false" do + it "creates runner" do + post api("/runners"), params: { + token: registration_token, + active: false, + } expect(response).to have_gitlab_http_status 201 expect(Ci::Runner.first.active).to be false @@ -168,23 +169,23 @@ describe API::Runner, :clean_gitlab_redis_shared_state do end end - context 'when maximum job timeout is specified' do - it 'creates runner' do - post api('/runners'), params: { - token: registration_token, - maximum_timeout: 9000 - } + context "when maximum job timeout is specified" do + it "creates runner" do + post api("/runners"), params: { + token: registration_token, + maximum_timeout: 9000, + } expect(response).to have_gitlab_http_status 201 expect(Ci::Runner.first.maximum_timeout).to eq(9000) end - context 'when maximum job timeout is empty' do - it 'creates runner' do - post api('/runners'), params: { - token: registration_token, - maximum_timeout: '' - } + context "when maximum job timeout is empty" do + it "creates runner" do + post api("/runners"), params: { + token: registration_token, + maximum_timeout: "", + } expect(response).to have_gitlab_http_status 201 expect(Ci::Runner.first.maximum_timeout).to be_nil @@ -192,15 +193,15 @@ describe API::Runner, :clean_gitlab_redis_shared_state do end end - %w(name version revision platform architecture).each do |param| + %w[name version revision platform architecture].each do |param| context "when info parameter '#{param}' info is present" do let(:value) { "#{param}_value" } it "updates provided Runner's parameter" do - post api('/runners'), params: { - token: registration_token, - info: { param => value } - } + post api("/runners"), params: { + token: registration_token, + info: {param => value}, + } expect(response).to have_gitlab_http_status 201 expect(Ci::Runner.first.read_attribute(param.to_sym)).to eq(value) @@ -209,71 +210,71 @@ describe API::Runner, :clean_gitlab_redis_shared_state do end it "sets the runner's ip_address" do - post api('/runners'), - params: { token: registration_token }, - headers: { 'X-Forwarded-For' => '123.111.123.111' } + post api("/runners"), + params: {token: registration_token}, + headers: {"X-Forwarded-For" => "123.111.123.111"} expect(response).to have_gitlab_http_status 201 - expect(Ci::Runner.first.ip_address).to eq('123.111.123.111') + expect(Ci::Runner.first.ip_address).to eq("123.111.123.111") end end - describe 'DELETE /api/v4/runners' do - context 'when no token is provided' do - it 'returns 400 error' do - delete api('/runners') + describe "DELETE /api/v4/runners" do + context "when no token is provided" do + it "returns 400 error" do + delete api("/runners") expect(response).to have_gitlab_http_status 400 end end - context 'when invalid token is provided' do - it 'returns 403 error' do - delete api('/runners'), params: { token: 'invalid' } + context "when invalid token is provided" do + it "returns 403 error" do + delete api("/runners"), params: {token: "invalid"} expect(response).to have_gitlab_http_status 403 end end - context 'when valid token is provided' do + context "when valid token is provided" do let(:runner) { create(:ci_runner) } - it 'deletes Runner' do - delete api('/runners'), params: { token: runner.token } + it "deletes Runner" do + delete api("/runners"), params: {token: runner.token} expect(response).to have_gitlab_http_status 204 expect(Ci::Runner.count).to eq(0) end - it_behaves_like '412 response' do - let(:request) { api('/runners') } - let(:params) { { token: runner.token } } + it_behaves_like "412 response" do + let(:request) { api("/runners") } + let(:params) { {token: runner.token} } end end end - describe 'POST /api/v4/runners/verify' do + describe "POST /api/v4/runners/verify" do let(:runner) { create(:ci_runner) } - context 'when no token is provided' do - it 'returns 400 error' do - post api('/runners/verify') + context "when no token is provided" do + it "returns 400 error" do + post api("/runners/verify") expect(response).to have_gitlab_http_status :bad_request end end - context 'when invalid token is provided' do - it 'returns 403 error' do - post api('/runners/verify'), params: { token: 'invalid-token' } + context "when invalid token is provided" do + it "returns 403 error" do + post api("/runners/verify"), params: {token: "invalid-token"} expect(response).to have_gitlab_http_status 403 end end - context 'when valid token is provided' do - it 'verifies Runner credentials' do - post api('/runners/verify'), params: { token: runner.token } + context "when valid token is provided" do + it "verifies Runner credentials" do + post api("/runners/verify"), params: {token: runner.token} expect(response).to have_gitlab_http_status 200 end @@ -281,309 +282,309 @@ describe API::Runner, :clean_gitlab_redis_shared_state do end end - describe '/api/v4/jobs' do + describe "/api/v4/jobs" do let(:project) { create(:project, shared_runners_enabled: false) } - let(:pipeline) { create(:ci_pipeline_without_jobs, project: project, ref: 'master') } + let(:pipeline) { create(:ci_pipeline_without_jobs, project: project, ref: "master") } let(:runner) { create(:ci_runner, :project, projects: [project]) } let(:job) do create(:ci_build, :artifacts, :extended_options, - pipeline: pipeline, name: 'spinach', stage: 'test', stage_idx: 0) + pipeline: pipeline, name: "spinach", stage: "test", stage_idx: 0) end - describe 'POST /api/v4/jobs/request' do + describe "POST /api/v4/jobs/request" do let!(:last_update) {} let!(:new_update) { } - let(:user_agent) { 'gitlab-runner 9.0.0 (9-0-stable; go1.7.4; linux/amd64)' } + let(:user_agent) { "gitlab-runner 9.0.0 (9-0-stable; go1.7.4; linux/amd64)" } before do job stub_container_registry_config(enabled: false) end - shared_examples 'no jobs available' do + shared_examples "no jobs available" do before do request_job end - context 'when runner sends version in User-Agent' do - context 'for stable version' do - it 'gives 204 and set X-GitLab-Last-Update' do + context "when runner sends version in User-Agent" do + context "for stable version" do + it "gives 204 and set X-GitLab-Last-Update" do expect(response).to have_gitlab_http_status(204) - expect(response.header).to have_key('X-GitLab-Last-Update') + expect(response.header).to have_key("X-GitLab-Last-Update") end end - context 'when last_update is up-to-date' do + context "when last_update is up-to-date" do let(:last_update) { runner.ensure_runner_queue_value } - it 'gives 204 and set the same X-GitLab-Last-Update' do + it "gives 204 and set the same X-GitLab-Last-Update" do expect(response).to have_gitlab_http_status(204) - expect(response.header['X-GitLab-Last-Update']).to eq(last_update) + expect(response.header["X-GitLab-Last-Update"]).to eq(last_update) end end - context 'when last_update is outdated' do + context "when last_update is outdated" do let(:last_update) { runner.ensure_runner_queue_value } let(:new_update) { runner.tick_runner_queue } - it 'gives 204 and set a new X-GitLab-Last-Update' do + it "gives 204 and set a new X-GitLab-Last-Update" do expect(response).to have_gitlab_http_status(204) - expect(response.header['X-GitLab-Last-Update']).to eq(new_update) + expect(response.header["X-GitLab-Last-Update"]).to eq(new_update) end end - context 'when beta version is sent' do - let(:user_agent) { 'gitlab-runner 9.0.0~beta.167.g2b2bacc (master; go1.7.4; linux/amd64)' } + context "when beta version is sent" do + let(:user_agent) { "gitlab-runner 9.0.0~beta.167.g2b2bacc (master; go1.7.4; linux/amd64)" } it { expect(response).to have_gitlab_http_status(204) } end - context 'when pre-9-0 version is sent' do - let(:user_agent) { 'gitlab-ci-multi-runner 1.6.0 (1-6-stable; go1.6.3; linux/amd64)' } + context "when pre-9-0 version is sent" do + let(:user_agent) { "gitlab-ci-multi-runner 1.6.0 (1-6-stable; go1.6.3; linux/amd64)" } it { expect(response).to have_gitlab_http_status(204) } end - context 'when pre-9-0 beta version is sent' do - let(:user_agent) { 'gitlab-ci-multi-runner 1.6.0~beta.167.g2b2bacc (master; go1.6.3; linux/amd64)' } + context "when pre-9-0 beta version is sent" do + let(:user_agent) { "gitlab-ci-multi-runner 1.6.0~beta.167.g2b2bacc (master; go1.6.3; linux/amd64)" } it { expect(response).to have_gitlab_http_status(204) } end end end - context 'when no token is provided' do - it 'returns 400 error' do - post api('/jobs/request') + context "when no token is provided" do + it "returns 400 error" do + post api("/jobs/request") expect(response).to have_gitlab_http_status 400 end end - context 'when invalid token is provided' do - it 'returns 403 error' do - post api('/jobs/request'), params: { token: 'invalid' } + context "when invalid token is provided" do + it "returns 403 error" do + post api("/jobs/request"), params: {token: "invalid"} expect(response).to have_gitlab_http_status 403 end end - context 'when valid token is provided' do - context 'when Runner is not active' do + context "when valid token is provided" do + context "when Runner is not active" do let(:runner) { create(:ci_runner, :inactive) } let(:update_value) { runner.ensure_runner_queue_value } - it 'returns 204 error' do + it "returns 204 error" do request_job expect(response).to have_gitlab_http_status(204) - expect(response.header['X-GitLab-Last-Update']).to eq(update_value) + expect(response.header["X-GitLab-Last-Update"]).to eq(update_value) end end - context 'when jobs are finished' do + context "when jobs are finished" do before do job.success end - it_behaves_like 'no jobs available' + it_behaves_like "no jobs available" end - context 'when other projects have pending jobs' do + context "when other projects have pending jobs" do before do job.success create(:ci_build, :pending) end - it_behaves_like 'no jobs available' + it_behaves_like "no jobs available" end - context 'when shared runner requests job for project without shared_runners_enabled' do + context "when shared runner requests job for project without shared_runners_enabled" do let(:runner) { create(:ci_runner, :instance) } - it_behaves_like 'no jobs available' + it_behaves_like "no jobs available" end - context 'when there is a pending job' do + context "when there is a pending job" do let(:expected_job_info) do - { 'name' => job.name, - 'stage' => job.stage, - 'project_id' => job.project.id, - 'project_name' => job.project.name } + {"name" => job.name, + "stage" => job.stage, + "project_id" => job.project.id, + "project_name" => job.project.name,} end let(:expected_git_info) do - { 'repo_url' => job.repo_url, - 'ref' => job.ref, - 'sha' => job.sha, - 'before_sha' => job.before_sha, - 'ref_type' => 'branch', - 'refspecs' => %w[+refs/heads/*:refs/remotes/origin/* +refs/tags/*:refs/tags/*], - 'depth' => 0 } + {"repo_url" => job.repo_url, + "ref" => job.ref, + "sha" => job.sha, + "before_sha" => job.before_sha, + "ref_type" => "branch", + "refspecs" => %w[+refs/heads/*:refs/remotes/origin/* +refs/tags/*:refs/tags/*], + "depth" => 0,} end let(:expected_steps) do - [{ 'name' => 'script', - 'script' => %w(echo), - 'timeout' => job.metadata_timeout, - 'when' => 'on_success', - 'allow_failure' => false }, - { 'name' => 'after_script', - 'script' => %w(ls date), - 'timeout' => job.metadata_timeout, - 'when' => 'always', - 'allow_failure' => true }] + [{"name" => "script", + "script" => %w[echo], + "timeout" => job.metadata_timeout, + "when" => "on_success", + "allow_failure" => false,}, + {"name" => "after_script", + "script" => %w[ls date], + "timeout" => job.metadata_timeout, + "when" => "always", + "allow_failure" => true,},] end let(:expected_variables) do - [{ 'key' => 'CI_JOB_NAME', 'value' => 'spinach', 'public' => true, 'masked' => false }, - { 'key' => 'CI_JOB_STAGE', 'value' => 'test', 'public' => true, 'masked' => false }, - { 'key' => 'DB_NAME', 'value' => 'postgres', 'public' => true, 'masked' => false }] + [{"key" => "CI_JOB_NAME", "value" => "spinach", "public" => true, "masked" => false}, + {"key" => "CI_JOB_STAGE", "value" => "test", "public" => true, "masked" => false}, + {"key" => "DB_NAME", "value" => "postgres", "public" => true, "masked" => false},] end let(:expected_artifacts) do - [{ 'name' => 'artifacts_file', - 'untracked' => false, - 'paths' => %w(out/), - 'when' => 'always', - 'expire_in' => '7d', - "artifact_type" => "archive", - "artifact_format" => "zip" }] + [{"name" => "artifacts_file", + "untracked" => false, + "paths" => %w[out/], + "when" => "always", + "expire_in" => "7d", + "artifact_type" => "archive", + "artifact_format" => "zip",}] end let(:expected_cache) do - [{ 'key' => 'cache_key', - 'untracked' => false, - 'paths' => ['vendor/*'], - 'policy' => 'pull-push' }] + [{"key" => "cache_key", + "untracked" => false, + "paths" => ["vendor/*"], + "policy" => "pull-push",}] end - let(:expected_features) { { 'trace_sections' => true } } + let(:expected_features) { {"trace_sections" => true} } - it 'picks a job' do - request_job info: { platform: :darwin } + it "picks a job" do + request_job info: {platform: :darwin} expect(response).to have_gitlab_http_status(201) - expect(response.headers).not_to have_key('X-GitLab-Last-Update') - expect(runner.reload.platform).to eq('darwin') - expect(json_response['id']).to eq(job.id) - expect(json_response['token']).to eq(job.token) - expect(json_response['job_info']).to eq(expected_job_info) - expect(json_response['git_info']).to eq(expected_git_info) - expect(json_response['image']).to eq({ 'name' => 'ruby:2.1', 'entrypoint' => '/bin/sh' }) - expect(json_response['services']).to eq([{ 'name' => 'postgres', 'entrypoint' => nil, - 'alias' => nil, 'command' => nil }, - { 'name' => 'docker:stable-dind', 'entrypoint' => '/bin/sh', - 'alias' => 'docker', 'command' => 'sleep 30' }]) - expect(json_response['steps']).to eq(expected_steps) - expect(json_response['artifacts']).to eq(expected_artifacts) - expect(json_response['cache']).to eq(expected_cache) - expect(json_response['variables']).to include(*expected_variables) - expect(json_response['features']).to eq(expected_features) - end - - context 'when job is made for tag' do - let!(:job) { create(:ci_build, :tag, pipeline: pipeline, name: 'spinach', stage: 'test', stage_idx: 0) } - - it 'sets branch as ref_type' do + expect(response.headers).not_to have_key("X-GitLab-Last-Update") + expect(runner.reload.platform).to eq("darwin") + expect(json_response["id"]).to eq(job.id) + expect(json_response["token"]).to eq(job.token) + expect(json_response["job_info"]).to eq(expected_job_info) + expect(json_response["git_info"]).to eq(expected_git_info) + expect(json_response["image"]).to eq({"name" => "ruby:2.1", "entrypoint" => "/bin/sh"}) + expect(json_response["services"]).to eq([{"name" => "postgres", "entrypoint" => nil, + "alias" => nil, "command" => nil,}, + {"name" => "docker:stable-dind", "entrypoint" => "/bin/sh", + "alias" => "docker", "command" => "sleep 30",},]) + expect(json_response["steps"]).to eq(expected_steps) + expect(json_response["artifacts"]).to eq(expected_artifacts) + expect(json_response["cache"]).to eq(expected_cache) + expect(json_response["variables"]).to include(*expected_variables) + expect(json_response["features"]).to eq(expected_features) + end + + context "when job is made for tag" do + let!(:job) { create(:ci_build, :tag, pipeline: pipeline, name: "spinach", stage: "test", stage_idx: 0) } + + it "sets branch as ref_type" do request_job expect(response).to have_gitlab_http_status(201) - expect(json_response['git_info']['ref_type']).to eq('tag') + expect(json_response["git_info"]["ref_type"]).to eq("tag") end - context 'when GIT_DEPTH is specified' do + context "when GIT_DEPTH is specified" do before do - create(:ci_pipeline_variable, key: 'GIT_DEPTH', value: 1, pipeline: pipeline) + create(:ci_pipeline_variable, key: "GIT_DEPTH", value: 1, pipeline: pipeline) end - it 'specifies refspecs' do + it "specifies refspecs" do request_job expect(response).to have_gitlab_http_status(201) - expect(json_response['git_info']['refspecs']).to include("+refs/tags/#{job.ref}:refs/tags/#{job.ref}") + expect(json_response["git_info"]["refspecs"]).to include("+refs/tags/#{job.ref}:refs/tags/#{job.ref}") end end - context 'when GIT_DEPTH is not specified' do - it 'specifies refspecs' do + context "when GIT_DEPTH is not specified" do + it "specifies refspecs" do request_job expect(response).to have_gitlab_http_status(201) - expect(json_response['git_info']['refspecs']) - .to contain_exactly('+refs/tags/*:refs/tags/*', '+refs/heads/*:refs/remotes/origin/*') + expect(json_response["git_info"]["refspecs"]) + .to contain_exactly("+refs/tags/*:refs/tags/*", "+refs/heads/*:refs/remotes/origin/*") end end end - context 'when job is made for branch' do - it 'sets tag as ref_type' do + context "when job is made for branch" do + it "sets tag as ref_type" do request_job expect(response).to have_gitlab_http_status(201) - expect(json_response['git_info']['ref_type']).to eq('branch') + expect(json_response["git_info"]["ref_type"]).to eq("branch") end - context 'when GIT_DEPTH is specified' do + context "when GIT_DEPTH is specified" do before do - create(:ci_pipeline_variable, key: 'GIT_DEPTH', value: 1, pipeline: pipeline) + create(:ci_pipeline_variable, key: "GIT_DEPTH", value: 1, pipeline: pipeline) end - it 'specifies refspecs' do + it "specifies refspecs" do request_job expect(response).to have_gitlab_http_status(201) - expect(json_response['git_info']['refspecs']).to include("+refs/heads/#{job.ref}:refs/remotes/origin/#{job.ref}") + expect(json_response["git_info"]["refspecs"]).to include("+refs/heads/#{job.ref}:refs/remotes/origin/#{job.ref}") end end - context 'when GIT_DEPTH is not specified' do - it 'specifies refspecs' do + context "when GIT_DEPTH is not specified" do + it "specifies refspecs" do request_job expect(response).to have_gitlab_http_status(201) - expect(json_response['git_info']['refspecs']) - .to contain_exactly('+refs/tags/*:refs/tags/*', '+refs/heads/*:refs/remotes/origin/*') + expect(json_response["git_info"]["refspecs"]) + .to contain_exactly("+refs/tags/*:refs/tags/*", "+refs/heads/*:refs/remotes/origin/*") end end end - context 'when job is made for merge request' do - let(:pipeline) { create(:ci_pipeline_without_jobs, source: :merge_request, project: project, ref: 'feature', merge_request: merge_request) } - let!(:job) { create(:ci_build, pipeline: pipeline, name: 'spinach', ref: 'feature', stage: 'test', stage_idx: 0) } + context "when job is made for merge request" do + let(:pipeline) { create(:ci_pipeline_without_jobs, source: :merge_request, project: project, ref: "feature", merge_request: merge_request) } + let!(:job) { create(:ci_build, pipeline: pipeline, name: "spinach", ref: "feature", stage: "test", stage_idx: 0) } let(:merge_request) { create(:merge_request) } - it 'sets branch as ref_type' do + it "sets branch as ref_type" do request_job expect(response).to have_gitlab_http_status(201) - expect(json_response['git_info']['ref_type']).to eq('branch') + expect(json_response["git_info"]["ref_type"]).to eq("branch") end - context 'when GIT_DEPTH is specified' do + context "when GIT_DEPTH is specified" do before do - create(:ci_pipeline_variable, key: 'GIT_DEPTH', value: 1, pipeline: pipeline) + create(:ci_pipeline_variable, key: "GIT_DEPTH", value: 1, pipeline: pipeline) end - it 'returns the overwritten git depth for merge request refspecs' do + it "returns the overwritten git depth for merge request refspecs" do request_job expect(response).to have_gitlab_http_status(201) - expect(json_response['git_info']['depth']).to eq(1) + expect(json_response["git_info"]["depth"]).to eq(1) end end end - it 'updates runner info' do + it "updates runner info" do expect { request_job }.to change { runner.reload.contacted_at } end - %w(version revision platform architecture).each do |param| + %w[version revision platform architecture].each do |param| context "when info parameter '#{param}' is present" do let(:value) { "#{param}_value" } it "updates provided Runner's parameter" do - request_job info: { param => value } + request_job info: {param => value} expect(response).to have_gitlab_http_status(201) expect(runner.reload.read_attribute(param.to_sym)).to eq(value) @@ -592,86 +593,88 @@ describe API::Runner, :clean_gitlab_redis_shared_state do end it "sets the runner's ip_address" do - post api('/jobs/request'), - params: { token: runner.token }, - headers: { 'User-Agent' => user_agent, 'X-Forwarded-For' => '123.222.123.222' } + post api("/jobs/request"), + params: {token: runner.token}, + headers: {"User-Agent" => user_agent, "X-Forwarded-For" => "123.222.123.222"} expect(response).to have_gitlab_http_status 201 - expect(runner.reload.ip_address).to eq('123.222.123.222') + expect(runner.reload.ip_address).to eq("123.222.123.222") end it "handles multiple X-Forwarded-For addresses" do - post api('/jobs/request'), - params: { token: runner.token }, - headers: { 'User-Agent' => user_agent, 'X-Forwarded-For' => '123.222.123.222, 127.0.0.1' } + post api("/jobs/request"), + params: {token: runner.token}, + headers: {"User-Agent" => user_agent, "X-Forwarded-For" => "123.222.123.222, 127.0.0.1"} expect(response).to have_gitlab_http_status 201 - expect(runner.reload.ip_address).to eq('123.222.123.222') + expect(runner.reload.ip_address).to eq("123.222.123.222") end - context 'when concurrently updating a job' do + context "when concurrently updating a job" do before do expect_any_instance_of(Ci::Build).to receive(:run!) - .and_raise(ActiveRecord::StaleObjectError.new(nil, nil)) + .and_raise(ActiveRecord::StaleObjectError.new(nil, nil)) end - it 'returns a conflict' do + it "returns a conflict" do request_job expect(response).to have_gitlab_http_status(409) - expect(response.headers).not_to have_key('X-GitLab-Last-Update') + expect(response.headers).not_to have_key("X-GitLab-Last-Update") end end - context 'when project and pipeline have multiple jobs' do - let!(:job) { create(:ci_build, :tag, pipeline: pipeline, name: 'spinach', stage: 'test', stage_idx: 0) } - let!(:job2) { create(:ci_build, :tag, pipeline: pipeline, name: 'rubocop', stage: 'test', stage_idx: 0) } - let!(:test_job) { create(:ci_build, pipeline: pipeline, name: 'deploy', stage: 'deploy', stage_idx: 1) } + context "when project and pipeline have multiple jobs" do + let!(:job) { create(:ci_build, :tag, pipeline: pipeline, name: "spinach", stage: "test", stage_idx: 0) } + let!(:job2) { create(:ci_build, :tag, pipeline: pipeline, name: "rubocop", stage: "test", stage_idx: 0) } + let!(:test_job) { create(:ci_build, pipeline: pipeline, name: "deploy", stage: "deploy", stage_idx: 1) } before do job.success job2.success end - it 'returns dependent jobs' do + it "returns dependent jobs" do request_job expect(response).to have_gitlab_http_status(201) - expect(json_response['id']).to eq(test_job.id) - expect(json_response['dependencies'].count).to eq(2) - expect(json_response['dependencies']).to include( - { 'id' => job.id, 'name' => job.name, 'token' => job.token }, - { 'id' => job2.id, 'name' => job2.name, 'token' => job2.token }) + expect(json_response["id"]).to eq(test_job.id) + expect(json_response["dependencies"].count).to eq(2) + expect(json_response["dependencies"]).to include( + {"id" => job.id, "name" => job.name, "token" => job.token}, + {"id" => job2.id, "name" => job2.name, "token" => job2.token} + ) end end - context 'when pipeline have jobs with artifacts' do - let!(:job) { create(:ci_build, :tag, :artifacts, pipeline: pipeline, name: 'spinach', stage: 'test', stage_idx: 0) } - let!(:test_job) { create(:ci_build, pipeline: pipeline, name: 'deploy', stage: 'deploy', stage_idx: 1) } + context "when pipeline have jobs with artifacts" do + let!(:job) { create(:ci_build, :tag, :artifacts, pipeline: pipeline, name: "spinach", stage: "test", stage_idx: 0) } + let!(:test_job) { create(:ci_build, pipeline: pipeline, name: "deploy", stage: "deploy", stage_idx: 1) } before do job.success end - it 'returns dependent jobs' do + it "returns dependent jobs" do request_job expect(response).to have_gitlab_http_status(201) - expect(json_response['id']).to eq(test_job.id) - expect(json_response['dependencies'].count).to eq(1) - expect(json_response['dependencies']).to include( - { 'id' => job.id, 'name' => job.name, 'token' => job.token, - 'artifacts_file' => { 'filename' => 'ci_build_artifacts.zip', 'size' => 106365 } }) + expect(json_response["id"]).to eq(test_job.id) + expect(json_response["dependencies"].count).to eq(1) + expect(json_response["dependencies"]).to include( + {"id" => job.id, "name" => job.name, "token" => job.token, + "artifacts_file" => {"filename" => "ci_build_artifacts.zip", "size" => 106365},} + ) end end - context 'when explicit dependencies are defined' do - let!(:job) { create(:ci_build, :tag, pipeline: pipeline, name: 'spinach', stage: 'test', stage_idx: 0) } - let!(:job2) { create(:ci_build, :tag, pipeline: pipeline, name: 'rubocop', stage: 'test', stage_idx: 0) } + context "when explicit dependencies are defined" do + let!(:job) { create(:ci_build, :tag, pipeline: pipeline, name: "spinach", stage: "test", stage_idx: 0) } + let!(:job2) { create(:ci_build, :tag, pipeline: pipeline, name: "rubocop", stage: "test", stage_idx: 0) } let!(:test_job) do - create(:ci_build, pipeline: pipeline, token: 'test-job-token', name: 'deploy', - stage: 'deploy', stage_idx: 1, - options: { script: ['bash'], dependencies: [job2.name] }) + create(:ci_build, pipeline: pipeline, token: "test-job-token", name: "deploy", + stage: "deploy", stage_idx: 1, + options: {script: ["bash"], dependencies: [job2.name]}) end before do @@ -679,23 +682,23 @@ describe API::Runner, :clean_gitlab_redis_shared_state do job2.success end - it 'returns dependent jobs' do + it "returns dependent jobs" do request_job expect(response).to have_gitlab_http_status(201) - expect(json_response['id']).to eq(test_job.id) - expect(json_response['dependencies'].count).to eq(1) - expect(json_response['dependencies'][0]).to include('id' => job2.id, 'name' => job2.name, 'token' => job2.token) + expect(json_response["id"]).to eq(test_job.id) + expect(json_response["dependencies"].count).to eq(1) + expect(json_response["dependencies"][0]).to include("id" => job2.id, "name" => job2.name, "token" => job2.token) end end - context 'when dependencies is an empty array' do - let!(:job) { create(:ci_build, :tag, pipeline: pipeline, name: 'spinach', stage: 'test', stage_idx: 0) } - let!(:job2) { create(:ci_build, :tag, pipeline: pipeline, name: 'rubocop', stage: 'test', stage_idx: 0) } + context "when dependencies is an empty array" do + let!(:job) { create(:ci_build, :tag, pipeline: pipeline, name: "spinach", stage: "test", stage_idx: 0) } + let!(:job2) { create(:ci_build, :tag, pipeline: pipeline, name: "rubocop", stage: "test", stage_idx: 0) } let!(:empty_dependencies_job) do - create(:ci_build, pipeline: pipeline, token: 'test-job-token', name: 'empty_dependencies_job', - stage: 'deploy', stage_idx: 1, - options: { script: ['bash'], dependencies: [] }) + create(:ci_build, pipeline: pipeline, token: "test-job-token", name: "empty_dependencies_job", + stage: "deploy", stage_idx: 1, + options: {script: ["bash"], dependencies: []}) end before do @@ -703,150 +706,150 @@ describe API::Runner, :clean_gitlab_redis_shared_state do job2.success end - it 'returns an empty array' do + it "returns an empty array" do request_job expect(response).to have_gitlab_http_status(201) - expect(json_response['id']).to eq(empty_dependencies_job.id) - expect(json_response['dependencies'].count).to eq(0) + expect(json_response["id"]).to eq(empty_dependencies_job.id) + expect(json_response["dependencies"].count).to eq(0) end end - context 'when job has no tags' do + context "when job has no tags" do before do job.update(tags: []) end - context 'when runner is allowed to pick untagged jobs' do + context "when runner is allowed to pick untagged jobs" do before do runner.update_column(:run_untagged, true) end - it 'picks job' do + it "picks job" do request_job expect(response).to have_gitlab_http_status 201 end end - context 'when runner is not allowed to pick untagged jobs' do + context "when runner is not allowed to pick untagged jobs" do before do runner.update_column(:run_untagged, false) end - it_behaves_like 'no jobs available' + it_behaves_like "no jobs available" end end - context 'when triggered job is available' do + context "when triggered job is available" do let(:expected_variables) do - [{ 'key' => 'CI_JOB_NAME', 'value' => 'spinach', 'public' => true, 'masked' => false }, - { 'key' => 'CI_JOB_STAGE', 'value' => 'test', 'public' => true, 'masked' => false }, - { 'key' => 'CI_PIPELINE_TRIGGERED', 'value' => 'true', 'public' => true, 'masked' => false }, - { 'key' => 'DB_NAME', 'value' => 'postgres', 'public' => true, 'masked' => false }, - { 'key' => 'SECRET_KEY', 'value' => 'secret_value', 'public' => false, 'masked' => false }, - { 'key' => 'TRIGGER_KEY_1', 'value' => 'TRIGGER_VALUE_1', 'public' => false, 'masked' => false }] + [{"key" => "CI_JOB_NAME", "value" => "spinach", "public" => true, "masked" => false}, + {"key" => "CI_JOB_STAGE", "value" => "test", "public" => true, "masked" => false}, + {"key" => "CI_PIPELINE_TRIGGERED", "value" => "true", "public" => true, "masked" => false}, + {"key" => "DB_NAME", "value" => "postgres", "public" => true, "masked" => false}, + {"key" => "SECRET_KEY", "value" => "secret_value", "public" => false, "masked" => false}, + {"key" => "TRIGGER_KEY_1", "value" => "TRIGGER_VALUE_1", "public" => false, "masked" => false},] end let(:trigger) { create(:ci_trigger, project: project) } let!(:trigger_request) { create(:ci_trigger_request, pipeline: pipeline, builds: [job], trigger: trigger) } before do - project.variables << Ci::Variable.new(key: 'SECRET_KEY', value: 'secret_value') + project.variables << Ci::Variable.new(key: "SECRET_KEY", value: "secret_value") end - shared_examples 'expected variables behavior' do - it 'returns variables for triggers' do + shared_examples "expected variables behavior" do + it "returns variables for triggers" do request_job expect(response).to have_gitlab_http_status(201) - expect(json_response['variables']).to include(*expected_variables) + expect(json_response["variables"]).to include(*expected_variables) end end - context 'when variables are stored in trigger_request' do + context "when variables are stored in trigger_request" do before do - trigger_request.update_attribute(:variables, { TRIGGER_KEY_1: 'TRIGGER_VALUE_1' } ) + trigger_request.update_attribute(:variables, {TRIGGER_KEY_1: "TRIGGER_VALUE_1"}) end - it_behaves_like 'expected variables behavior' + it_behaves_like "expected variables behavior" end - context 'when variables are stored in pipeline_variables' do + context "when variables are stored in pipeline_variables" do before do - create(:ci_pipeline_variable, pipeline: pipeline, key: :TRIGGER_KEY_1, value: 'TRIGGER_VALUE_1') + create(:ci_pipeline_variable, pipeline: pipeline, key: :TRIGGER_KEY_1, value: "TRIGGER_VALUE_1") end - it_behaves_like 'expected variables behavior' + it_behaves_like "expected variables behavior" end end - describe 'registry credentials support' do - let(:registry_url) { 'registry.example.com:5005' } + describe "registry credentials support" do + let(:registry_url) { "registry.example.com:5005" } let(:registry_credentials) do - { 'type' => 'registry', - 'url' => registry_url, - 'username' => 'gitlab-ci-token', - 'password' => job.token } + {"type" => "registry", + "url" => registry_url, + "username" => "gitlab-ci-token", + "password" => job.token,} end - context 'when registry is enabled' do + context "when registry is enabled" do before do stub_container_registry_config(enabled: true, host_port: registry_url) end - it 'sends registry credentials key' do + it "sends registry credentials key" do request_job - expect(json_response).to have_key('credentials') - expect(json_response['credentials']).to include(registry_credentials) + expect(json_response).to have_key("credentials") + expect(json_response["credentials"]).to include(registry_credentials) end end - context 'when registry is disabled' do + context "when registry is disabled" do before do stub_container_registry_config(enabled: false, host_port: registry_url) end - it 'does not send registry credentials' do + it "does not send registry credentials" do request_job - expect(json_response).to have_key('credentials') - expect(json_response['credentials']).not_to include(registry_credentials) + expect(json_response).to have_key("credentials") + expect(json_response["credentials"]).not_to include(registry_credentials) end end end - describe 'timeout support' do - context 'when project specifies job timeout' do + describe "timeout support" do + context "when project specifies job timeout" do let(:project) { create(:project, shared_runners_enabled: false, build_timeout: 1234) } - it 'contains info about timeout taken from project' do + it "contains info about timeout taken from project" do request_job expect(response).to have_gitlab_http_status(201) - expect(json_response['runner_info']).to include({ 'timeout' => 1234 }) + expect(json_response["runner_info"]).to include({"timeout" => 1234}) end - context 'when runner specifies lower timeout' do + context "when runner specifies lower timeout" do let(:runner) { create(:ci_runner, :project, maximum_timeout: 1000, projects: [project]) } - it 'contains info about timeout overridden by runner' do + it "contains info about timeout overridden by runner" do request_job expect(response).to have_gitlab_http_status(201) - expect(json_response['runner_info']).to include({ 'timeout' => 1000 }) + expect(json_response["runner_info"]).to include({"timeout" => 1000}) end end - context 'when runner specifies bigger timeout' do + context "when runner specifies bigger timeout" do let(:runner) { create(:ci_runner, :project, maximum_timeout: 2000, projects: [project]) } - it 'contains info about timeout not overridden by runner' do + it "contains info about timeout not overridden by runner" do request_job expect(response).to have_gitlab_http_status(201) - expect(json_response['runner_info']).to include({ 'timeout' => 1234 }) + expect(json_response["runner_info"]).to include({"timeout" => 1234}) end end end @@ -855,64 +858,64 @@ describe API::Runner, :clean_gitlab_redis_shared_state do def request_job(token = runner.token, **params) new_params = params.merge(token: token, last_update: last_update) - post api('/jobs/request'), params: new_params, headers: { 'User-Agent' => user_agent } + post api("/jobs/request"), params: new_params, headers: {"User-Agent" => user_agent} end end end - describe 'PUT /api/v4/jobs/:id' do + describe "PUT /api/v4/jobs/:id" do let(:job) { create(:ci_build, :pending, :trace_live, pipeline: pipeline, runner_id: runner.id) } before do job.run! end - context 'when status is given' do - it 'mark job as succeeded' do - update_job(state: 'success') + context "when status is given" do + it "mark job as succeeded" do + update_job(state: "success") job.reload expect(job).to be_success end - it 'mark job as failed' do - update_job(state: 'failed') + it "mark job as failed" do + update_job(state: "failed") job.reload expect(job).to be_failed expect(job).to be_unknown_failure end - context 'when failure_reason is script_failure' do + context "when failure_reason is script_failure" do before do - update_job(state: 'failed', failure_reason: 'script_failure') + update_job(state: "failed", failure_reason: "script_failure") job.reload end it { expect(job).to be_script_failure } end - context 'when failure_reason is runner_system_failure' do + context "when failure_reason is runner_system_failure" do before do - update_job(state: 'failed', failure_reason: 'runner_system_failure') + update_job(state: "failed", failure_reason: "runner_system_failure") job.reload end it { expect(job).to be_runner_system_failure } end - context 'when failure_reason is unrecognized value' do + context "when failure_reason is unrecognized value" do before do - update_job(state: 'failed', failure_reason: 'what_is_this') + update_job(state: "failed", failure_reason: "what_is_this") job.reload end it { expect(job).to be_unknown_failure } end - context 'when failure_reason is job_execution_timeout' do + context "when failure_reason is job_execution_timeout" do before do - update_job(state: 'failed', failure_reason: 'job_execution_timeout') + update_job(state: "failed", failure_reason: "job_execution_timeout") job.reload end @@ -920,76 +923,76 @@ describe API::Runner, :clean_gitlab_redis_shared_state do end end - context 'when trace is given' do - it 'creates a trace artifact' do + context "when trace is given" do + it "creates a trace artifact" do allow(BuildFinishedWorker).to receive(:perform_async).with(job.id) do ArchiveTraceWorker.new.perform(job.id) end - update_job(state: 'success', trace: 'BUILD TRACE UPDATED') + update_job(state: "success", trace: "BUILD TRACE UPDATED") job.reload expect(response).to have_gitlab_http_status(200) - expect(job.trace.raw).to eq 'BUILD TRACE UPDATED' - expect(job.job_artifacts_trace.open.read).to eq 'BUILD TRACE UPDATED' + expect(job.trace.raw).to eq "BUILD TRACE UPDATED" + expect(job.job_artifacts_trace.open.read).to eq "BUILD TRACE UPDATED" end - context 'when concurrent update of trace is happening' do + context "when concurrent update of trace is happening" do before do - job.trace.write('wb') do - update_job(state: 'success', trace: 'BUILD TRACE UPDATED') + job.trace.write("wb") do + update_job(state: "success", trace: "BUILD TRACE UPDATED") end end - it 'returns that operation conflicts' do + it "returns that operation conflicts" do expect(response.status).to eq(409) end end end - context 'when no trace is given' do - it 'does not override trace information' do + context "when no trace is given" do + it "does not override trace information" do update_job - expect(job.reload.trace.raw).to eq 'BUILD TRACE' + expect(job.reload.trace.raw).to eq "BUILD TRACE" end - context 'when running state is sent' do - it 'updates update_at value' do + context "when running state is sent" do + it "updates update_at value" do expect { update_job_after_time }.to change { job.reload.updated_at } end end - context 'when other state is sent' do + context "when other state is sent" do it "doesn't update update_at value" do - expect { update_job_after_time(20.minutes, state: 'success') }.not_to change { job.reload.updated_at } + expect { update_job_after_time(20.minutes, state: "success") }.not_to change { job.reload.updated_at } end end end - context 'when job has been erased' do + context "when job has been erased" do let(:job) { create(:ci_build, runner_id: runner.id, erased_at: Time.now) } - it 'responds with forbidden' do + it "responds with forbidden" do update_job expect(response).to have_gitlab_http_status(403) end end - context 'when job has already been finished' do + context "when job has already been finished" do before do - job.trace.set('Job failed') + job.trace.set("Job failed") job.drop!(:script_failure) end - it 'does not update job status and job trace' do - update_job(state: 'success', trace: 'BUILD TRACE UPDATED') + it "does not update job status and job trace" do + update_job(state: "success", trace: "BUILD TRACE UPDATED") job.reload expect(response).to have_gitlab_http_status(403) - expect(response.header['Job-Status']).to eq 'failed' - expect(job.trace.raw).to eq 'Job failed' + expect(response.header["Job-Status"]).to eq "failed" + expect(job.trace.raw).to eq "Job failed" expect(job).to be_failed end end @@ -999,219 +1002,219 @@ describe API::Runner, :clean_gitlab_redis_shared_state do put api("/jobs/#{job.id}"), params: new_params end - def update_job_after_time(update_interval = 20.minutes, state = 'running') + def update_job_after_time(update_interval = 20.minutes, state = "running") Timecop.travel(job.updated_at + update_interval) do update_job(job.token, state: state) end end end - describe 'PATCH /api/v4/jobs/:id/trace' do + describe "PATCH /api/v4/jobs/:id/trace" do let(:job) { create(:ci_build, :running, :trace_live, runner_id: runner.id, pipeline: pipeline) } - let(:headers) { { API::Helpers::Runner::JOB_TOKEN_HEADER => job.token, 'Content-Type' => 'text/plain' } } - let(:headers_with_range) { headers.merge({ 'Content-Range' => '11-20' }) } + let(:headers) { {API::Helpers::Runner::JOB_TOKEN_HEADER => job.token, "Content-Type" => "text/plain"} } + let(:headers_with_range) { headers.merge({"Content-Range" => "11-20"}) } let(:update_interval) { 10.seconds.to_i } before do initial_patch_the_trace end - context 'when request is valid' do - it 'gets correct response' do + context "when request is valid" do + it "gets correct response" do expect(response.status).to eq 202 - expect(job.reload.trace.raw).to eq 'BUILD TRACE appended' - expect(response.header).to have_key 'Range' - expect(response.header).to have_key 'Job-Status' + expect(job.reload.trace.raw).to eq "BUILD TRACE appended" + expect(response.header).to have_key "Range" + expect(response.header).to have_key "Job-Status" end - context 'when job has been updated recently' do + context "when job has been updated recently" do it { expect { patch_the_trace }.not_to change { job.updated_at }} it "changes the job's trace" do patch_the_trace - expect(job.reload.trace.raw).to eq 'BUILD TRACE appended appended' + expect(job.reload.trace.raw).to eq "BUILD TRACE appended appended" end - context 'when Runner makes a force-patch' do + context "when Runner makes a force-patch" do it { expect { force_patch_the_trace }.not_to change { job.updated_at }} it "doesn't change the build.trace" do force_patch_the_trace - expect(job.reload.trace.raw).to eq 'BUILD TRACE appended' + expect(job.reload.trace.raw).to eq "BUILD TRACE appended" end end end - context 'when job was not updated recently' do + context "when job was not updated recently" do let(:update_interval) { 15.minutes.to_i } it { expect { patch_the_trace }.to change { job.updated_at } } - it 'changes the job.trace' do + it "changes the job.trace" do patch_the_trace - expect(job.reload.trace.raw).to eq 'BUILD TRACE appended appended' + expect(job.reload.trace.raw).to eq "BUILD TRACE appended appended" end - context 'when Runner makes a force-patch' do + context "when Runner makes a force-patch" do it { expect { force_patch_the_trace }.to change { job.updated_at } } it "doesn't change the job.trace" do force_patch_the_trace - expect(job.reload.trace.raw).to eq 'BUILD TRACE appended' + expect(job.reload.trace.raw).to eq "BUILD TRACE appended" end end end - context 'when project for the build has been deleted' do + context "when project for the build has been deleted" do let(:job) do create(:ci_build, :running, :trace_live, runner_id: runner.id, pipeline: pipeline) do |job| job.project.update(pending_delete: true) end end - it 'responds with forbidden' do + it "responds with forbidden" do expect(response.status).to eq(403) end end - context 'when trace is patched' do + context "when trace is patched" do before do patch_the_trace end - it 'has valid trace' do + it "has valid trace" do expect(response.status).to eq(202) - expect(job.reload.trace.raw).to eq 'BUILD TRACE appended appended' + expect(job.reload.trace.raw).to eq "BUILD TRACE appended appended" end - context 'when job is cancelled' do + context "when job is cancelled" do before do job.cancel end - context 'when trace is patched' do + context "when trace is patched" do before do patch_the_trace end - it 'returns Forbidden ' do + it "returns Forbidden " do expect(response.status).to eq(403) end end end - context 'when redis data are flushed' do + context "when redis data are flushed" do before do redis_shared_state_cleanup! end - it 'has empty trace' do - expect(job.reload.trace.raw).to eq '' + it "has empty trace" do + expect(job.reload.trace.raw).to eq "" end - context 'when we perform partial patch' do + context "when we perform partial patch" do before do - patch_the_trace('hello', headers.merge({ 'Content-Range' => "28-32/5" })) + patch_the_trace("hello", headers.merge({"Content-Range" => "28-32/5"})) end - it 'returns an error' do + it "returns an error" do expect(response.status).to eq(416) - expect(response.header['Range']).to eq('0-0') + expect(response.header["Range"]).to eq("0-0") end end - context 'when we resend full trace' do + context "when we resend full trace" do before do - patch_the_trace('BUILD TRACE appended appended hello', headers.merge({ 'Content-Range' => "0-34/35" })) + patch_the_trace("BUILD TRACE appended appended hello", headers.merge({"Content-Range" => "0-34/35"})) end - it 'succeeds with updating trace' do + it "succeeds with updating trace" do expect(response.status).to eq(202) - expect(job.reload.trace.raw).to eq 'BUILD TRACE appended appended hello' + expect(job.reload.trace.raw).to eq "BUILD TRACE appended appended hello" end end end end - context 'when concurrent update of trace is happening' do + context "when concurrent update of trace is happening" do before do - job.trace.write('wb') do + job.trace.write("wb") do patch_the_trace end end - it 'returns that operation conflicts' do + it "returns that operation conflicts" do expect(response.status).to eq(409) end end - context 'when the job is canceled' do + context "when the job is canceled" do before do job.cancel patch_the_trace end - it 'receives status in header' do - expect(response.header['Job-Status']).to eq 'canceled' + it "receives status in header" do + expect(response.header["Job-Status"]).to eq "canceled" end end end - context 'when Runner makes a force-patch' do + context "when Runner makes a force-patch" do before do force_patch_the_trace end - it 'gets correct response' do + it "gets correct response" do expect(response.status).to eq 202 - expect(job.reload.trace.raw).to eq 'BUILD TRACE appended' - expect(response.header).to have_key 'Range' - expect(response.header).to have_key 'Job-Status' + expect(job.reload.trace.raw).to eq "BUILD TRACE appended" + expect(response.header).to have_key "Range" + expect(response.header).to have_key "Job-Status" end end - context 'when content-range start is too big' do - let(:headers_with_range) { headers.merge({ 'Content-Range' => '15-20/6' }) } + context "when content-range start is too big" do + let(:headers_with_range) { headers.merge({"Content-Range" => "15-20/6"}) } - it 'gets 416 error response with range headers' do + it "gets 416 error response with range headers" do expect(response.status).to eq 416 - expect(response.header).to have_key 'Range' - expect(response.header['Range']).to eq '0-11' + expect(response.header).to have_key "Range" + expect(response.header["Range"]).to eq "0-11" end end - context 'when content-range start is too small' do - let(:headers_with_range) { headers.merge({ 'Content-Range' => '8-20/13' }) } + context "when content-range start is too small" do + let(:headers_with_range) { headers.merge({"Content-Range" => "8-20/13"}) } - it 'gets 416 error response with range headers' do + it "gets 416 error response with range headers" do expect(response.status).to eq 416 - expect(response.header).to have_key 'Range' - expect(response.header['Range']).to eq '0-11' + expect(response.header).to have_key "Range" + expect(response.header["Range"]).to eq "0-11" end end - context 'when Content-Range header is missing' do + context "when Content-Range header is missing" do let(:headers_with_range) { headers } it { expect(response.status).to eq 400 } end - context 'when job has been errased' do + context "when job has been errased" do let(:job) { create(:ci_build, runner_id: runner.id, erased_at: Time.now) } it { expect(response.status).to eq 403 } end - def patch_the_trace(content = ' appended', request_headers = nil) + def patch_the_trace(content = " appended", request_headers = nil) unless request_headers job.trace.read do |stream| offset = stream.size limit = offset + content.length - 1 - request_headers = headers.merge({ 'Content-Range' => "#{offset}-#{limit}" }) + request_headers = headers.merge({"Content-Range" => "#{offset}-#{limit}"}) end end @@ -1222,80 +1225,80 @@ describe API::Runner, :clean_gitlab_redis_shared_state do end def initial_patch_the_trace - patch_the_trace(' appended', headers_with_range) + patch_the_trace(" appended", headers_with_range) end def force_patch_the_trace - 2.times { patch_the_trace('') } + 2.times { patch_the_trace("") } end end - describe 'artifacts' do + describe "artifacts" do let(:job) { create(:ci_build, :pending, pipeline: pipeline, runner_id: runner.id) } - let(:jwt_token) { JWT.encode({ 'iss' => 'gitlab-workhorse' }, Gitlab::Workhorse.secret, 'HS256') } - let(:headers) { { 'GitLab-Workhorse' => '1.0', Gitlab::Workhorse::INTERNAL_API_REQUEST_HEADER => jwt_token } } + let(:jwt_token) { JWT.encode({"iss" => "gitlab-workhorse"}, Gitlab::Workhorse.secret, "HS256") } + let(:headers) { {"GitLab-Workhorse" => "1.0", Gitlab::Workhorse::INTERNAL_API_REQUEST_HEADER => jwt_token} } let(:headers_with_token) { headers.merge(API::Helpers::Runner::JOB_TOKEN_HEADER => job.token) } - let(:file_upload) { fixture_file_upload('spec/fixtures/banana_sample.gif', 'image/gif') } - let(:file_upload2) { fixture_file_upload('spec/fixtures/dk.png', 'image/gif') } + let(:file_upload) { fixture_file_upload("spec/fixtures/banana_sample.gif", "image/gif") } + let(:file_upload2) { fixture_file_upload("spec/fixtures/dk.png", "image/gif") } before do stub_artifacts_object_storage job.run! end - describe 'POST /api/v4/jobs/:id/artifacts/authorize' do - context 'when using token as parameter' do - context 'posting artifacts to running job' do + describe "POST /api/v4/jobs/:id/artifacts/authorize" do + context "when using token as parameter" do + context "posting artifacts to running job" do subject do authorize_artifacts_with_token_in_params end - shared_examples 'authorizes local file' do - it 'succeeds' do + shared_examples "authorizes local file" do + it "succeeds" do subject expect(response).to have_gitlab_http_status(200) expect(response.content_type.to_s).to eq(Gitlab::Workhorse::INTERNAL_API_CONTENT_TYPE) - expect(json_response['TempPath']).to eq(JobArtifactUploader.workhorse_local_upload_path) - expect(json_response['RemoteObject']).to be_nil + expect(json_response["TempPath"]).to eq(JobArtifactUploader.workhorse_local_upload_path) + expect(json_response["RemoteObject"]).to be_nil end end - context 'when using local storage' do - it_behaves_like 'authorizes local file' + context "when using local storage" do + it_behaves_like "authorizes local file" end - context 'when using remote storage' do - context 'when direct upload is enabled' do + context "when using remote storage" do + context "when direct upload is enabled" do before do stub_artifacts_object_storage(enabled: true, direct_upload: true) end - it 'succeeds' do + it "succeeds" do subject expect(response).to have_gitlab_http_status(200) expect(response.content_type.to_s).to eq(Gitlab::Workhorse::INTERNAL_API_CONTENT_TYPE) - expect(json_response['TempPath']).to eq(JobArtifactUploader.workhorse_local_upload_path) - expect(json_response['RemoteObject']).to have_key('ID') - expect(json_response['RemoteObject']).to have_key('GetURL') - expect(json_response['RemoteObject']).to have_key('StoreURL') - expect(json_response['RemoteObject']).to have_key('DeleteURL') - expect(json_response['RemoteObject']).to have_key('MultipartUpload') + expect(json_response["TempPath"]).to eq(JobArtifactUploader.workhorse_local_upload_path) + expect(json_response["RemoteObject"]).to have_key("ID") + expect(json_response["RemoteObject"]).to have_key("GetURL") + expect(json_response["RemoteObject"]).to have_key("StoreURL") + expect(json_response["RemoteObject"]).to have_key("DeleteURL") + expect(json_response["RemoteObject"]).to have_key("MultipartUpload") end end - context 'when direct upload is disabled' do + context "when direct upload is disabled" do before do stub_artifacts_object_storage(enabled: true, direct_upload: false) end - it_behaves_like 'authorizes local file' + it_behaves_like "authorizes local file" end end end - it 'fails to post too large artifact' do + it "fails to post too large artifact" do stub_application_setting(max_artifacts_size: 0) authorize_artifacts_with_token_in_params(filesize: 100) @@ -1304,16 +1307,16 @@ describe API::Runner, :clean_gitlab_redis_shared_state do end end - context 'when using token as header' do - it 'authorizes posting artifacts to running job' do + context "when using token as header" do + it "authorizes posting artifacts to running job" do authorize_artifacts_with_token_in_headers expect(response).to have_gitlab_http_status(200) expect(response.content_type.to_s).to eq(Gitlab::Workhorse::INTERNAL_API_CONTENT_TYPE) - expect(json_response['TempPath']).not_to be_nil + expect(json_response["TempPath"]).not_to be_nil end - it 'fails to post too large artifact' do + it "fails to post too large artifact" do stub_application_setting(max_artifacts_size: 0) authorize_artifacts_with_token_in_headers(filesize: 100) @@ -1322,15 +1325,15 @@ describe API::Runner, :clean_gitlab_redis_shared_state do end end - context 'when using runners token' do - it 'fails to authorize artifacts posting' do + context "when using runners token" do + it "fails to authorize artifacts posting" do authorize_artifacts(token: job.project.runners_token) expect(response).to have_gitlab_http_status(403) end end - it 'reject requests that did not go through gitlab-workhorse' do + it "reject requests that did not go through gitlab-workhorse" do headers.delete(Gitlab::Workhorse::INTERNAL_API_REQUEST_HEADER) authorize_artifacts @@ -1338,9 +1341,9 @@ describe API::Runner, :clean_gitlab_redis_shared_state do expect(response).to have_gitlab_http_status(500) end - context 'authorization token is invalid' do - it 'responds with forbidden' do - authorize_artifacts(token: 'invalid', filesize: 100 ) + context "authorization token is invalid" do + it "responds with forbidden" do + authorize_artifacts(token: "invalid", filesize: 100) expect(response).to have_gitlab_http_status(403) end @@ -1360,77 +1363,77 @@ describe API::Runner, :clean_gitlab_redis_shared_state do end end - describe 'POST /api/v4/jobs/:id/artifacts' do - context 'when artifacts are being stored inside of tmp path' do + describe "POST /api/v4/jobs/:id/artifacts" do + context "when artifacts are being stored inside of tmp path" do before do # by configuring this path we allow to pass temp file from any path - allow(JobArtifactUploader).to receive(:workhorse_upload_path).and_return('/') + allow(JobArtifactUploader).to receive(:workhorse_upload_path).and_return("/") end - context 'when job has been erased' do + context "when job has been erased" do let(:job) { create(:ci_build, erased_at: Time.now) } before do upload_artifacts(file_upload, headers_with_token) end - it 'responds with forbidden' do + it "responds with forbidden" do upload_artifacts(file_upload, headers_with_token) expect(response).to have_gitlab_http_status(403) end end - context 'when job is running' do - shared_examples 'successful artifacts upload' do - it 'updates successfully' do + context "when job is running" do + shared_examples "successful artifacts upload" do + it "updates successfully" do expect(response).to have_gitlab_http_status(201) end end - context 'when uses accelerated file post' do - context 'for file stored locally' do + context "when uses accelerated file post" do + context "for file stored locally" do before do upload_artifacts(file_upload, headers_with_token) end - it_behaves_like 'successful artifacts upload' + it_behaves_like "successful artifacts upload" end - context 'for file stored remotelly' do + context "for file stored remotelly" do let!(:fog_connection) do stub_artifacts_object_storage(direct_upload: true) end before do - fog_connection.directories.new(key: 'artifacts').files.create( - key: 'tmp/uploads/12312300', - body: 'content' + fog_connection.directories.new(key: "artifacts").files.create( + key: "tmp/uploads/12312300", + body: "content" ) upload_artifacts(file_upload, headers_with_token, - { 'file.remote_id' => remote_id }) + {"file.remote_id" => remote_id}) end - context 'when valid remote_id is used' do - let(:remote_id) { '12312300' } + context "when valid remote_id is used" do + let(:remote_id) { "12312300" } - it_behaves_like 'successful artifacts upload' + it_behaves_like "successful artifacts upload" end - context 'when invalid remote_id is used' do - let(:remote_id) { 'invalid id' } + context "when invalid remote_id is used" do + let(:remote_id) { "invalid id" } - it 'responds with bad request' do + it "responds with bad request" do expect(response).to have_gitlab_http_status(500) - expect(json_response['message']).to eq("Missing file") + expect(json_response["message"]).to eq("Missing file") end end end end - context 'when using runners token' do - it 'responds with forbidden' do + context "when using runners token" do + it "responds with forbidden" do upload_artifacts(file_upload, headers.merge(API::Helpers::Runner::JOB_TOKEN_HEADER => job.project.runners_token)) expect(response).to have_gitlab_http_status(403) @@ -1438,8 +1441,8 @@ describe API::Runner, :clean_gitlab_redis_shared_state do end end - context 'when artifacts file is too large' do - it 'fails to post too large artifact' do + context "when artifacts file is too large" do + it "fails to post too large artifact" do stub_application_setting(max_artifacts_size: 0) upload_artifacts(file_upload, headers_with_token) @@ -1448,28 +1451,28 @@ describe API::Runner, :clean_gitlab_redis_shared_state do end end - context 'when artifacts post request does not contain file' do - it 'fails to post artifacts without file' do + context "when artifacts post request does not contain file" do + it "fails to post artifacts without file" do post api("/jobs/#{job.id}/artifacts"), params: {}, headers: headers_with_token expect(response).to have_gitlab_http_status(400) end end - context 'GitLab Workhorse is not configured' do - it 'fails to post artifacts without GitLab-Workhorse' do - post api("/jobs/#{job.id}/artifacts"), params: { token: job.token }, headers: {} + context "GitLab Workhorse is not configured" do + it "fails to post artifacts without GitLab-Workhorse" do + post api("/jobs/#{job.id}/artifacts"), params: {token: job.token}, headers: {} expect(response).to have_gitlab_http_status(403) end end - context 'when setting an expire date' do + context "when setting an expire date" do let(:default_artifacts_expire_in) {} let(:post_data) do - { 'file.path' => file_upload.path, - 'file.name' => file_upload.original_filename, - 'expire_in' => expire_in } + {"file.path" => file_upload.path, + "file.name" => file_upload.original_filename, + "expire_in" => expire_in,} end before do @@ -1478,37 +1481,37 @@ describe API::Runner, :clean_gitlab_redis_shared_state do post(api("/jobs/#{job.id}/artifacts"), params: post_data, headers: headers_with_token) end - context 'when an expire_in is given' do - let(:expire_in) { '7 days' } + context "when an expire_in is given" do + let(:expire_in) { "7 days" } - it 'updates when specified' do + it "updates when specified" do expect(response).to have_gitlab_http_status(201) expect(job.reload.artifacts_expire_at).to be_within(5.minutes).of(7.days.from_now) end end - context 'when no expire_in is given' do + context "when no expire_in is given" do let(:expire_in) { nil } - it 'ignores if not specified' do + it "ignores if not specified" do expect(response).to have_gitlab_http_status(201) expect(job.reload.artifacts_expire_at).to be_nil end - context 'with application default' do - context 'when default is 5 days' do - let(:default_artifacts_expire_in) { '5 days' } + context "with application default" do + context "when default is 5 days" do + let(:default_artifacts_expire_in) { "5 days" } - it 'sets to application default' do + it "sets to application default" do expect(response).to have_gitlab_http_status(201) expect(job.reload.artifacts_expire_at).to be_within(5.minutes).of(5.days.from_now) end end - context 'when default is 0' do - let(:default_artifacts_expire_in) { '0' } + context "when default is 0" do + let(:default_artifacts_expire_in) { "0" } - it 'does not set expire_in' do + it "does not set expire_in" do expect(response).to have_gitlab_http_status(201) expect(job.reload.artifacts_expire_at).to be_nil end @@ -1517,7 +1520,7 @@ describe API::Runner, :clean_gitlab_redis_shared_state do end end - context 'posts artifacts file and metadata file' do + context "posts artifacts file and metadata file" do let!(:artifacts) { file_upload } let!(:artifacts_sha256) { Digest::SHA256.file(artifacts.path).hexdigest } let!(:metadata) { file_upload2 } @@ -1533,17 +1536,17 @@ describe API::Runner, :clean_gitlab_redis_shared_state do post(api("/jobs/#{job.id}/artifacts"), params: post_data, headers: headers_with_token) end - context 'when posts data accelerated by workhorse is correct' do + context "when posts data accelerated by workhorse is correct" do let(:post_data) do - { 'file.path' => artifacts.path, - 'file.name' => artifacts.original_filename, - 'file.sha256' => artifacts_sha256, - 'metadata.path' => metadata.path, - 'metadata.name' => metadata.original_filename, - 'metadata.sha256' => metadata_sha256 } + {"file.path" => artifacts.path, + "file.name" => artifacts.original_filename, + "file.sha256" => artifacts_sha256, + "metadata.path" => metadata.path, + "metadata.name" => metadata.original_filename, + "metadata.sha256" => metadata_sha256,} end - it 'stores artifacts and artifacts metadata' do + it "stores artifacts and artifacts metadata" do expect(response).to have_gitlab_http_status(201) expect(stored_artifacts_file.original_filename).to eq(artifacts.original_filename) expect(stored_metadata_file.original_filename).to eq(metadata.original_filename) @@ -1553,26 +1556,26 @@ describe API::Runner, :clean_gitlab_redis_shared_state do end end - context 'when there is no artifacts file in post data' do + context "when there is no artifacts file in post data" do let(:post_data) do - { 'metadata' => metadata } + {"metadata" => metadata} end - it 'is expected to respond with bad request' do + it "is expected to respond with bad request" do expect(response).to have_gitlab_http_status(400) end - it 'does not store metadata' do + it "does not store metadata" do expect(stored_metadata_file).to be_nil end end end - context 'when artifact_type is archive' do - context 'when artifact_format is zip' do - let(:params) { { artifact_type: :archive, artifact_format: :zip } } + context "when artifact_type is archive" do + context "when artifact_format is zip" do + let(:params) { {artifact_type: :archive, artifact_format: :zip} } - it 'stores junit test report' do + it "stores junit test report" do upload_artifacts(file_upload, headers_with_token, params) expect(response).to have_gitlab_http_status(201) @@ -1580,10 +1583,10 @@ describe API::Runner, :clean_gitlab_redis_shared_state do end end - context 'when artifact_format is gzip' do - let(:params) { { artifact_type: :archive, artifact_format: :gzip } } + context "when artifact_format is gzip" do + let(:params) { {artifact_type: :archive, artifact_format: :gzip} } - it 'returns an error' do + it "returns an error" do upload_artifacts(file_upload, headers_with_token, params) expect(response).to have_gitlab_http_status(400) @@ -1592,12 +1595,12 @@ describe API::Runner, :clean_gitlab_redis_shared_state do end end - context 'when artifact_type is junit' do - context 'when artifact_format is gzip' do - let(:file_upload) { fixture_file_upload('spec/fixtures/junit/junit.xml.gz') } - let(:params) { { artifact_type: :junit, artifact_format: :gzip } } + context "when artifact_type is junit" do + context "when artifact_format is gzip" do + let(:file_upload) { fixture_file_upload("spec/fixtures/junit/junit.xml.gz") } + let(:params) { {artifact_type: :junit, artifact_format: :gzip} } - it 'stores junit test report' do + it "stores junit test report" do upload_artifacts(file_upload, headers_with_token, params) expect(response).to have_gitlab_http_status(201) @@ -1605,11 +1608,11 @@ describe API::Runner, :clean_gitlab_redis_shared_state do end end - context 'when artifact_format is raw' do - let(:file_upload) { fixture_file_upload('spec/fixtures/junit/junit.xml.gz') } - let(:params) { { artifact_type: :junit, artifact_format: :raw } } + context "when artifact_format is raw" do + let(:file_upload) { fixture_file_upload("spec/fixtures/junit/junit.xml.gz") } + let(:params) { {artifact_type: :junit, artifact_format: :raw} } - it 'returns an error' do + it "returns an error" do upload_artifacts(file_upload, headers_with_token, params) expect(response).to have_gitlab_http_status(400) @@ -1619,7 +1622,7 @@ describe API::Runner, :clean_gitlab_redis_shared_state do end end - context 'when artifacts are being stored outside of tmp path' do + context "when artifacts are being stored outside of tmp path" do let(:new_tmpdir) { Dir.mktmpdir } before do @@ -1644,18 +1647,18 @@ describe API::Runner, :clean_gitlab_redis_shared_state do def upload_artifacts(file, headers = {}, params = {}) params = params.merge({ - 'file.path' => file.path, - 'file.name' => file.original_filename + "file.path" => file.path, + "file.name" => file.original_filename, }) post api("/jobs/#{job.id}/artifacts"), params: params, headers: headers end end - describe 'GET /api/v4/jobs/:id/artifacts' do + describe "GET /api/v4/jobs/:id/artifacts" do let(:token) { job.token } - context 'when job has artifacts' do + context "when job has artifacts" do let(:job) { create(:ci_build) } let(:store) { JobArtifactUploader::Store::LOCAL } @@ -1663,67 +1666,68 @@ describe API::Runner, :clean_gitlab_redis_shared_state do create(:ci_job_artifact, :archive, file_store: store, job: job) end - context 'when using job token' do - context 'when artifacts are stored locally' do + context "when using job token" do + context "when artifacts are stored locally" do let(:download_headers) do - { 'Content-Transfer-Encoding' => 'binary', - 'Content-Disposition' => %q(attachment; filename="ci_build_artifacts.zip"; filename*=UTF-8''ci_build_artifacts.zip) } + {"Content-Transfer-Encoding" => "binary", + "Content-Disposition" => %q(attachment; filename="ci_build_artifacts.zip"; filename*=UTF-8''ci_build_artifacts.zip),} end before do download_artifact end - it 'download artifacts' do + it "download artifacts" do expect(response).to have_http_status(200) expect(response.headers.to_h).to include download_headers end end - context 'when artifacts are stored remotely' do + context "when artifacts are stored remotely" do let(:store) { JobArtifactUploader::Store::REMOTE } let!(:job) { create(:ci_build) } - context 'when proxy download is being used' do + context "when proxy download is being used" do before do download_artifact(direct_download: false) end - it 'uses workhorse send-url' do + it "uses workhorse send-url" do expect(response).to have_gitlab_http_status(200) expect(response.headers.to_h).to include( - 'Gitlab-Workhorse-Send-Data' => /send-url:/) + "Gitlab-Workhorse-Send-Data" => /send-url:/ + ) end end - context 'when direct download is being used' do + context "when direct download is being used" do before do download_artifact(direct_download: true) end - it 'receive redirect for downloading artifacts' do + it "receive redirect for downloading artifacts" do expect(response).to have_gitlab_http_status(302) - expect(response.headers).to include('Location') + expect(response.headers).to include("Location") end end end end - context 'when using runnners token' do + context "when using runnners token" do let(:token) { job.project.runners_token } before do download_artifact end - it 'responds with forbidden' do + it "responds with forbidden" do expect(response).to have_gitlab_http_status(403) end end end - context 'when job does not has artifacts' do - it 'responds with not found' do + context "when job does not has artifacts" do + it "responds with not found" do download_artifact expect(response).to have_gitlab_http_status(404) diff --git a/spec/requests/api/runners_spec.rb b/spec/requests/api/runners_spec.rb index 5548e3fd01a..9194ed70e78 100644 --- a/spec/requests/api/runners_spec.rb +++ b/spec/requests/api/runners_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe API::Runners do let(:admin) { create(:user, :admin) } @@ -11,10 +11,10 @@ describe API::Runners do let(:group) { create(:group).tap { |group| group.add_owner(user) } } let(:group2) { create(:group).tap { |group| group.add_owner(user) } } - let!(:shared_runner) { create(:ci_runner, :instance, description: 'Shared runner') } - let!(:project_runner) { create(:ci_runner, :project, description: 'Project runner', projects: [project]) } - let!(:two_projects_runner) { create(:ci_runner, :project, description: 'Two projects runner', projects: [project, project2]) } - let!(:group_runner) { create(:ci_runner, :group, description: 'Group runner', groups: [group]) } + let!(:shared_runner) { create(:ci_runner, :instance, description: "Shared runner") } + let!(:project_runner) { create(:ci_runner, :project, description: "Project runner", projects: [project]) } + let!(:two_projects_runner) { create(:ci_runner, :project, description: "Two projects runner", projects: [project, project2]) } + let!(:group_runner) { create(:ci_runner, :group, description: "Group runner", groups: [group]) } before do # Set project access for users @@ -23,228 +23,228 @@ describe API::Runners do create(:project_member, :reporter, user: user2, project: project) end - describe 'GET /runners' do - context 'authorized user' do - it 'returns response status and headers' do - get api('/runners', user) + describe "GET /runners" do + context "authorized user" do + it "returns response status and headers" do + get api("/runners", user) expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers end - it 'returns user available runners' do - get api('/runners', user) + it "returns user available runners" do + get api("/runners", user) expect(json_response).to match_array [ - a_hash_including('description' => 'Project runner'), - a_hash_including('description' => 'Two projects runner'), - a_hash_including('description' => 'Group runner') + a_hash_including("description" => "Project runner"), + a_hash_including("description" => "Two projects runner"), + a_hash_including("description" => "Group runner"), ] end - it 'filters runners by scope' do - create(:ci_runner, :project, :inactive, description: 'Inactive project runner', projects: [project]) + it "filters runners by scope" do + create(:ci_runner, :project, :inactive, description: "Inactive project runner", projects: [project]) - get api('/runners?scope=paused', user) + get api("/runners?scope=paused", user) expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response).to match_array [ - a_hash_including('description' => 'Inactive project runner') + a_hash_including("description" => "Inactive project runner"), ] end - it 'avoids filtering if scope is invalid' do - get api('/runners?scope=unknown', user) + it "avoids filtering if scope is invalid" do + get api("/runners?scope=unknown", user) expect(response).to have_gitlab_http_status(400) end - it 'filters runners by type' do - get api('/runners?type=project_type', user) + it "filters runners by type" do + get api("/runners?type=project_type", user) expect(json_response).to match_array [ - a_hash_including('description' => 'Project runner'), - a_hash_including('description' => 'Two projects runner') + a_hash_including("description" => "Project runner"), + a_hash_including("description" => "Two projects runner"), ] end - it 'does not filter by invalid type' do - get api('/runners?type=bogus', user) + it "does not filter by invalid type" do + get api("/runners?type=bogus", user) expect(response).to have_gitlab_http_status(400) end - it 'filters runners by status' do - create(:ci_runner, :project, :inactive, description: 'Inactive project runner', projects: [project]) + it "filters runners by status" do + create(:ci_runner, :project, :inactive, description: "Inactive project runner", projects: [project]) - get api('/runners?status=paused', user) + get api("/runners?status=paused", user) expect(json_response).to match_array [ - a_hash_including('description' => 'Inactive project runner') + a_hash_including("description" => "Inactive project runner"), ] end - it 'does not filter by invalid status' do - get api('/runners?status=bogus', user) + it "does not filter by invalid status" do + get api("/runners?status=bogus", user) expect(response).to have_gitlab_http_status(400) end - it 'filters runners by tag_list' do - create(:ci_runner, :project, description: 'Runner tagged with tag1 and tag2', projects: [project], tag_list: %w[tag1 tag2]) - create(:ci_runner, :project, description: 'Runner tagged with tag2', projects: [project], tag_list: ['tag2']) + it "filters runners by tag_list" do + create(:ci_runner, :project, description: "Runner tagged with tag1 and tag2", projects: [project], tag_list: %w[tag1 tag2]) + create(:ci_runner, :project, description: "Runner tagged with tag2", projects: [project], tag_list: ["tag2"]) - get api('/runners?tag_list=tag1,tag2', user) + get api("/runners?tag_list=tag1,tag2", user) expect(json_response).to match_array [ - a_hash_including('description' => 'Runner tagged with tag1 and tag2') + a_hash_including("description" => "Runner tagged with tag1 and tag2"), ] end end - context 'unauthorized user' do - it 'does not return runners' do - get api('/runners') + context "unauthorized user" do + it "does not return runners" do + get api("/runners") expect(response).to have_gitlab_http_status(401) end end end - describe 'GET /runners/all' do - context 'authorized user' do - context 'with admin privileges' do - it 'returns response status and headers' do - get api('/runners/all', admin) + describe "GET /runners/all" do + context "authorized user" do + context "with admin privileges" do + it "returns response status and headers" do + get api("/runners/all", admin) expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers end - it 'returns all runners' do - get api('/runners/all', admin) + it "returns all runners" do + get api("/runners/all", admin) expect(json_response).to match_array [ - a_hash_including('description' => 'Project runner'), - a_hash_including('description' => 'Two projects runner'), - a_hash_including('description' => 'Group runner'), - a_hash_including('description' => 'Shared runner') + a_hash_including("description" => "Project runner"), + a_hash_including("description" => "Two projects runner"), + a_hash_including("description" => "Group runner"), + a_hash_including("description" => "Shared runner"), ] end - it 'filters runners by scope' do - get api('/runners/all?scope=shared', admin) + it "filters runners by scope" do + get api("/runners/all?scope=shared", admin) - shared = json_response.all? { |r| r['is_shared'] } + shared = json_response.all? { |r| r["is_shared"] } expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response).to be_an Array - expect(json_response[0]).to have_key('ip_address') + expect(json_response[0]).to have_key("ip_address") expect(shared).to be_truthy end - it 'filters runners by scope' do - get api('/runners/all?scope=specific', admin) + it "filters runners by scope" do + get api("/runners/all?scope=specific", admin) expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response).to match_array [ - a_hash_including('description' => 'Project runner'), - a_hash_including('description' => 'Two projects runner'), - a_hash_including('description' => 'Group runner') + a_hash_including("description" => "Project runner"), + a_hash_including("description" => "Two projects runner"), + a_hash_including("description" => "Group runner"), ] end - it 'avoids filtering if scope is invalid' do - get api('/runners/all?scope=unknown', admin) + it "avoids filtering if scope is invalid" do + get api("/runners/all?scope=unknown", admin) expect(response).to have_gitlab_http_status(400) end - it 'filters runners by type' do - get api('/runners/all?type=project_type', admin) + it "filters runners by type" do + get api("/runners/all?type=project_type", admin) expect(json_response).to match_array [ - a_hash_including('description' => 'Project runner'), - a_hash_including('description' => 'Two projects runner') + a_hash_including("description" => "Project runner"), + a_hash_including("description" => "Two projects runner"), ] end - it 'does not filter by invalid type' do - get api('/runners/all?type=bogus', admin) + it "does not filter by invalid type" do + get api("/runners/all?type=bogus", admin) expect(response).to have_gitlab_http_status(400) end - it 'filters runners by status' do - create(:ci_runner, :project, :inactive, description: 'Inactive project runner', projects: [project]) + it "filters runners by status" do + create(:ci_runner, :project, :inactive, description: "Inactive project runner", projects: [project]) - get api('/runners/all?status=paused', admin) + get api("/runners/all?status=paused", admin) expect(json_response).to match_array [ - a_hash_including('description' => 'Inactive project runner') + a_hash_including("description" => "Inactive project runner"), ] end - it 'does not filter by invalid status' do - get api('/runners/all?status=bogus', admin) + it "does not filter by invalid status" do + get api("/runners/all?status=bogus", admin) expect(response).to have_gitlab_http_status(400) end - it 'filters runners by tag_list' do - create(:ci_runner, :project, description: 'Runner tagged with tag1 and tag2', projects: [project], tag_list: %w[tag1 tag2]) - create(:ci_runner, :project, description: 'Runner tagged with tag2', projects: [project], tag_list: ['tag2']) + it "filters runners by tag_list" do + create(:ci_runner, :project, description: "Runner tagged with tag1 and tag2", projects: [project], tag_list: %w[tag1 tag2]) + create(:ci_runner, :project, description: "Runner tagged with tag2", projects: [project], tag_list: ["tag2"]) - get api('/runners/all?tag_list=tag1,tag2', admin) + get api("/runners/all?tag_list=tag1,tag2", admin) expect(json_response).to match_array [ - a_hash_including('description' => 'Runner tagged with tag1 and tag2') + a_hash_including("description" => "Runner tagged with tag1 and tag2"), ] end end - context 'without admin privileges' do - it 'does not return runners list' do - get api('/runners/all', user) + context "without admin privileges" do + it "does not return runners list" do + get api("/runners/all", user) expect(response).to have_gitlab_http_status(403) end end end - context 'unauthorized user' do - it 'does not return runners' do - get api('/runners') + context "unauthorized user" do + it "does not return runners" do + get api("/runners") expect(response).to have_gitlab_http_status(401) end end end - describe 'GET /runners/:id' do - context 'admin user' do - context 'when runner is shared' do + describe "GET /runners/:id" do + context "admin user" do + context "when runner is shared" do it "returns runner's details" do get api("/runners/#{shared_runner.id}", admin) expect(response).to have_gitlab_http_status(200) - expect(json_response['description']).to eq(shared_runner.description) - expect(json_response['maximum_timeout']).to be_nil + expect(json_response["description"]).to eq(shared_runner.description) + expect(json_response["maximum_timeout"]).to be_nil end end - context 'when runner is not shared' do - context 'when unused runner is present' do + context "when runner is not shared" do + context "when unused runner is present" do let!(:unused_project_runner) { create(:ci_runner, :project, :without_projects) } - it 'deletes unused runner' do - expect do + it "deletes unused runner" do + expect { delete api("/runners/#{unused_project_runner.id}", admin) expect(response).to have_gitlab_http_status(204) - end.to change { Ci::Runner.project_type.count }.by(-1) + }.to change { Ci::Runner.project_type.count }.by(-1) end end @@ -252,44 +252,44 @@ describe API::Runners do get api("/runners/#{project_runner.id}", admin) expect(response).to have_gitlab_http_status(200) - expect(json_response['description']).to eq(project_runner.description) + expect(json_response["description"]).to eq(project_runner.description) end it "returns the project's details for a project runner" do get api("/runners/#{project_runner.id}", admin) - expect(json_response['projects'].first['id']).to eq(project.id) + expect(json_response["projects"].first["id"]).to eq(project.id) end end - it 'returns 404 if runner does not exists' do - get api('/runners/0', admin) + it "returns 404 if runner does not exists" do + get api("/runners/0", admin) expect(response).to have_gitlab_http_status(404) end end context "runner project's administrative user" do - context 'when runner is not shared' do + context "when runner is not shared" do it "returns runner's details" do get api("/runners/#{project_runner.id}", user) expect(response).to have_gitlab_http_status(200) - expect(json_response['description']).to eq(project_runner.description) + expect(json_response["description"]).to eq(project_runner.description) end end - context 'when runner is shared' do + context "when runner is shared" do it "returns runner's details" do get api("/runners/#{shared_runner.id}", user) expect(response).to have_gitlab_http_status(200) - expect(json_response['description']).to eq(shared_runner.description) + expect(json_response["description"]).to eq(shared_runner.description) end end end - context 'other authorized user' do + context "other authorized user" do it "does not return project runner's details" do get api("/runners/#{project_runner.id}", user2) @@ -297,7 +297,7 @@ describe API::Runners do end end - context 'unauthorized user' do + context "unauthorized user" do it "does not return project runner's details" do get api("/runners/#{project_runner.id}") @@ -306,11 +306,11 @@ describe API::Runners do end end - describe 'PUT /runners/:id' do - context 'admin user' do + describe "PUT /runners/:id" do + context "admin user" do # see https://gitlab.com/gitlab-org/gitlab-ce/issues/48625 - context 'single parameter update' do - it 'runner description' do + context "single parameter update" do + it "runner description" do description = shared_runner.description update_runner(shared_runner.id, admin, description: "#{description}_updated") @@ -318,7 +318,7 @@ describe API::Runners do expect(shared_runner.reload.description).to eq("#{description}_updated") end - it 'runner active state' do + it "runner active state" do active = shared_runner.active update_runner(shared_runner.id, admin, active: !active) @@ -326,44 +326,44 @@ describe API::Runners do expect(shared_runner.reload.active).to eq(!active) end - it 'runner tag list' do - update_runner(shared_runner.id, admin, tag_list: ['ruby2.1', 'pgsql', 'mysql']) + it "runner tag list" do + update_runner(shared_runner.id, admin, tag_list: ["ruby2.1", "pgsql", "mysql"]) expect(response).to have_gitlab_http_status(200) - expect(shared_runner.reload.tag_list).to include('ruby2.1', 'pgsql', 'mysql') + expect(shared_runner.reload.tag_list).to include("ruby2.1", "pgsql", "mysql") end - it 'runner untagged flag' do + it "runner untagged flag" do # Ensure tag list is non-empty before setting untagged to false. - update_runner(shared_runner.id, admin, tag_list: ['ruby2.1', 'pgsql', 'mysql']) - update_runner(shared_runner.id, admin, run_untagged: 'false') + update_runner(shared_runner.id, admin, tag_list: ["ruby2.1", "pgsql", "mysql"]) + update_runner(shared_runner.id, admin, run_untagged: "false") expect(response).to have_gitlab_http_status(200) expect(shared_runner.reload.run_untagged?).to be(false) end - it 'runner unlocked flag' do - update_runner(shared_runner.id, admin, locked: 'true') + it "runner unlocked flag" do + update_runner(shared_runner.id, admin, locked: "true") expect(response).to have_gitlab_http_status(200) expect(shared_runner.reload.locked?).to be(true) end - it 'runner access level' do - update_runner(shared_runner.id, admin, access_level: 'ref_protected') + it "runner access level" do + update_runner(shared_runner.id, admin, access_level: "ref_protected") expect(response).to have_gitlab_http_status(200) expect(shared_runner.reload.ref_protected?).to be_truthy end - it 'runner maximum timeout' do + it "runner maximum timeout" do update_runner(shared_runner.id, admin, maximum_timeout: 1234) expect(response).to have_gitlab_http_status(200) expect(shared_runner.reload.maximum_timeout).to eq(1234) end - it 'fails with no parameters' do + it "fails with no parameters" do put api("/runners/#{shared_runner.id}", admin) shared_runner.reload @@ -371,25 +371,25 @@ describe API::Runners do end end - context 'when runner is shared' do - it 'updates runner' do + context "when runner is shared" do + it "updates runner" do description = shared_runner.description active = shared_runner.active runner_queue_value = shared_runner.ensure_runner_queue_value update_runner(shared_runner.id, admin, description: "#{description}_updated", active: !active, - tag_list: ['ruby2.1', 'pgsql', 'mysql'], - run_untagged: 'false', - locked: 'true', - access_level: 'ref_protected', + tag_list: ["ruby2.1", "pgsql", "mysql"], + run_untagged: "false", + locked: "true", + access_level: "ref_protected", maximum_timeout: 1234) shared_runner.reload expect(response).to have_gitlab_http_status(200) expect(shared_runner.description).to eq("#{description}_updated") 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") expect(shared_runner.run_untagged?).to be(false) expect(shared_runner.locked?).to be(true) expect(shared_runner.ref_protected?).to be_truthy @@ -399,24 +399,24 @@ describe API::Runners do end end - context 'when runner is not shared' do - it 'updates runner' do + context "when runner is not shared" do + it "updates runner" do description = project_runner.description runner_queue_value = project_runner.ensure_runner_queue_value - update_runner(project_runner.id, admin, description: 'test') + update_runner(project_runner.id, admin, description: "test") project_runner.reload expect(response).to have_gitlab_http_status(200) - expect(project_runner.description).to eq('test') + expect(project_runner.description).to eq("test") expect(project_runner.description).not_to eq(description) expect(project_runner.ensure_runner_queue_value) .not_to eq(runner_queue_value) end end - it 'returns 404 if runner does not exists' do - update_runner(0, admin, description: 'test') + it "returns 404 if runner does not exists" do + update_runner(0, admin, description: "test") expect(response).to have_gitlab_http_status(404) end @@ -426,36 +426,36 @@ describe API::Runners do end end - context 'authorized user' do - context 'when runner is shared' do - it 'does not update runner' do - put api("/runners/#{shared_runner.id}", user), params: { description: 'test' } + context "authorized user" do + context "when runner is shared" do + it "does not update runner" do + put api("/runners/#{shared_runner.id}", user), params: {description: "test"} expect(response).to have_gitlab_http_status(403) end end - context 'when runner is not shared' do - it 'does not update project runner without access to it' do - put api("/runners/#{project_runner.id}", user2), params: { description: 'test' } + context "when runner is not shared" do + it "does not update project runner without access to it" do + put api("/runners/#{project_runner.id}", user2), params: {description: "test"} expect(response).to have_http_status(403) end - it 'updates project runner with access to it' do + it "updates project runner with access to it" do description = project_runner.description - put api("/runners/#{project_runner.id}", admin), params: { description: 'test' } + put api("/runners/#{project_runner.id}", admin), params: {description: "test"} project_runner.reload expect(response).to have_gitlab_http_status(200) - expect(project_runner.description).to eq('test') + expect(project_runner.description).to eq("test") expect(project_runner.description).not_to eq(description) end end end - context 'unauthorized user' do - it 'does not delete project runner' do + context "unauthorized user" do + it "does not delete project runner" do put api("/runners/#{project_runner.id}") expect(response).to have_http_status(401) @@ -463,74 +463,74 @@ describe API::Runners do end end - describe 'DELETE /runners/:id' do - context 'admin user' do - context 'when runner is shared' do - it 'deletes runner' do - expect do + describe "DELETE /runners/:id" do + context "admin user" do + context "when runner is shared" do + it "deletes runner" do + expect { delete api("/runners/#{shared_runner.id}", admin) expect(response).to have_gitlab_http_status(204) - end.to change { Ci::Runner.instance_type.count }.by(-1) + }.to change { Ci::Runner.instance_type.count }.by(-1) end - it_behaves_like '412 response' do + it_behaves_like "412 response" do let(:request) { api("/runners/#{shared_runner.id}", admin) } end end - context 'when runner is not shared' do - it 'deletes used project runner' do - expect do + context "when runner is not shared" do + it "deletes used project runner" do + expect { delete api("/runners/#{project_runner.id}", admin) expect(response).to have_http_status(204) - end.to change { Ci::Runner.project_type.count }.by(-1) + }.to change { Ci::Runner.project_type.count }.by(-1) end end - it 'returns 404 if runner does not exists' do - delete api('/runners/0', admin) + it "returns 404 if runner does not exists" do + delete api("/runners/0", admin) expect(response).to have_gitlab_http_status(404) end end - context 'authorized user' do - context 'when runner is shared' do - it 'does not delete runner' do + context "authorized user" do + context "when runner is shared" do + it "does not delete runner" do delete api("/runners/#{shared_runner.id}", user) expect(response).to have_gitlab_http_status(403) end end - context 'when runner is not shared' do - it 'does not delete runner without access to it' do + context "when runner is not shared" do + it "does not delete runner without access to it" do delete api("/runners/#{project_runner.id}", user2) expect(response).to have_gitlab_http_status(403) end - it 'does not delete project runner with more than one associated project' do + it "does not delete project runner with more than one associated project" do delete api("/runners/#{two_projects_runner.id}", user) expect(response).to have_gitlab_http_status(403) end - it 'deletes project runner for one owned project' do - expect do + it "deletes project runner for one owned project" do + expect { delete api("/runners/#{project_runner.id}", user) expect(response).to have_http_status(204) - end.to change { Ci::Runner.project_type.count }.by(-1) + }.to change { Ci::Runner.project_type.count }.by(-1) end - it_behaves_like '412 response' do + it_behaves_like "412 response" do let(:request) { api("/runners/#{project_runner.id}", user) } end end end - context 'unauthorized user' do - it 'does not delete project runner' do + context "unauthorized user" do + it "does not delete project runner" do delete api("/runners/#{project_runner.id}") expect(response).to have_http_status(401) @@ -538,17 +538,17 @@ describe API::Runners do end end - describe 'GET /runners/:id/jobs' do + describe "GET /runners/:id/jobs" do set(:job_1) { create(:ci_build) } let!(:job_2) { create(:ci_build, :running, runner: shared_runner, project: project) } let!(:job_3) { create(:ci_build, :failed, runner: shared_runner, project: project) } let!(:job_4) { create(:ci_build, :running, runner: project_runner, project: project) } let!(:job_5) { create(:ci_build, :failed, runner: project_runner, project: project) } - context 'admin user' do - context 'when runner exists' do - context 'when runner is shared' do - it 'return jobs' do + context "admin user" do + context "when runner exists" do + context "when runner is shared" do + it "return jobs" do get api("/runners/#{shared_runner.id}/jobs", admin) expect(response).to have_gitlab_http_status(200) @@ -559,8 +559,8 @@ describe API::Runners do end end - context 'when runner is specific' do - it 'return jobs' do + context "when runner is specific" do + it "return jobs" do get api("/runners/#{project_runner.id}/jobs", admin) expect(response).to have_gitlab_http_status(200) @@ -571,8 +571,8 @@ describe API::Runners do end end - context 'when valid status is provided' do - it 'return filtered jobs' do + context "when valid status is provided" do + it "return filtered jobs" do get api("/runners/#{project_runner.id}/jobs?status=failed", admin) expect(response).to have_gitlab_http_status(200) @@ -580,12 +580,12 @@ describe API::Runners do expect(json_response).to be_an(Array) expect(json_response.length).to eq(1) - expect(json_response.first).to include('id' => job_5.id) + expect(json_response.first).to include("id" => job_5.id) end end - context 'when invalid status is provided' do - it 'return 400' do + context "when invalid status is provided" do + it "return 400" do get api("/runners/#{project_runner.id}/jobs?status=non-existing", admin) expect(response).to have_gitlab_http_status(400) @@ -594,8 +594,8 @@ describe API::Runners do end context "when runner doesn't exist" do - it 'returns 404' do - get api('/runners/0/jobs', admin) + it "returns 404" do + get api("/runners/0/jobs", admin) expect(response).to have_gitlab_http_status(404) end @@ -603,17 +603,17 @@ describe API::Runners do end context "runner project's administrative user" do - context 'when runner exists' do - context 'when runner is shared' do - it 'returns 403' do + context "when runner exists" do + context "when runner is shared" do + it "returns 403" do get api("/runners/#{shared_runner.id}/jobs", user) expect(response).to have_gitlab_http_status(403) end end - context 'when runner is specific' do - it 'return jobs' do + context "when runner is specific" do + it "return jobs" do get api("/runners/#{project_runner.id}/jobs", user) expect(response).to have_gitlab_http_status(200) @@ -624,8 +624,8 @@ describe API::Runners do end end - context 'when valid status is provided' do - it 'return filtered jobs' do + context "when valid status is provided" do + it "return filtered jobs" do get api("/runners/#{project_runner.id}/jobs?status=failed", user) expect(response).to have_gitlab_http_status(200) @@ -633,12 +633,12 @@ describe API::Runners do expect(json_response).to be_an(Array) expect(json_response.length).to eq(1) - expect(json_response.first).to include('id' => job_5.id) + expect(json_response.first).to include("id" => job_5.id) end end - context 'when invalid status is provided' do - it 'return 400' do + context "when invalid status is provided" do + it "return 400" do get api("/runners/#{project_runner.id}/jobs?status=non-existing", user) expect(response).to have_gitlab_http_status(400) @@ -647,24 +647,24 @@ describe API::Runners do end context "when runner doesn't exist" do - it 'returns 404' do - get api('/runners/0/jobs', user) + it "returns 404" do + get api("/runners/0/jobs", user) expect(response).to have_gitlab_http_status(404) end end end - context 'other authorized user' do - it 'does not return jobs' do + context "other authorized user" do + it "does not return jobs" do get api("/runners/#{project_runner.id}/jobs", user2) expect(response).to have_gitlab_http_status(403) end end - context 'unauthorized user' do - it 'does not return jobs' do + context "unauthorized user" do + it "does not return jobs" do get api("/runners/#{project_runner.id}/jobs") expect(response).to have_gitlab_http_status(401) @@ -672,86 +672,86 @@ describe API::Runners do end end - describe 'GET /projects/:id/runners' do - context 'authorized user with maintainer privileges' do - it 'returns response status and headers' do - get api('/runners/all', admin) + describe "GET /projects/:id/runners" do + context "authorized user with maintainer privileges" do + it "returns response status and headers" do + get api("/runners/all", admin) expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers end - it 'returns all runners' do + it "returns all runners" do get api("/projects/#{project.id}/runners", user) expect(json_response).to match_array [ - a_hash_including('description' => 'Project runner'), - a_hash_including('description' => 'Two projects runner'), - a_hash_including('description' => 'Shared runner') + a_hash_including("description" => "Project runner"), + a_hash_including("description" => "Two projects runner"), + a_hash_including("description" => "Shared runner"), ] end - it 'filters runners by scope' do + it "filters runners by scope" do get api("/projects/#{project.id}/runners?scope=specific", user) expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response).to match_array [ - a_hash_including('description' => 'Project runner'), - a_hash_including('description' => 'Two projects runner') + a_hash_including("description" => "Project runner"), + a_hash_including("description" => "Two projects runner"), ] end - it 'avoids filtering if scope is invalid' do + it "avoids filtering if scope is invalid" do get api("/projects/#{project.id}/runners?scope=unknown", user) expect(response).to have_gitlab_http_status(400) end - it 'filters runners by type' do + it "filters runners by type" do get api("/projects/#{project.id}/runners?type=project_type", user) expect(json_response).to match_array [ - a_hash_including('description' => 'Project runner'), - a_hash_including('description' => 'Two projects runner') + a_hash_including("description" => "Project runner"), + a_hash_including("description" => "Two projects runner"), ] end - it 'does not filter by invalid type' do + it "does not filter by invalid type" do get api("/projects/#{project.id}/runners?type=bogus", user) expect(response).to have_gitlab_http_status(400) end - it 'filters runners by status' do - create(:ci_runner, :project, :inactive, description: 'Inactive project runner', projects: [project]) + it "filters runners by status" do + create(:ci_runner, :project, :inactive, description: "Inactive project runner", projects: [project]) get api("/projects/#{project.id}/runners?status=paused", user) expect(json_response).to match_array [ - a_hash_including('description' => 'Inactive project runner') + a_hash_including("description" => "Inactive project runner"), ] end - it 'does not filter by invalid status' do + it "does not filter by invalid status" do get api("/projects/#{project.id}/runners?status=bogus", user) expect(response).to have_gitlab_http_status(400) end - it 'filters runners by tag_list' do - create(:ci_runner, :project, description: 'Runner tagged with tag1 and tag2', projects: [project], tag_list: %w[tag1 tag2]) - create(:ci_runner, :project, description: 'Runner tagged with tag2', projects: [project], tag_list: ['tag2']) + it "filters runners by tag_list" do + create(:ci_runner, :project, description: "Runner tagged with tag1 and tag2", projects: [project], tag_list: %w[tag1 tag2]) + create(:ci_runner, :project, description: "Runner tagged with tag2", projects: [project], tag_list: ["tag2"]) get api("/projects/#{project.id}/runners?tag_list=tag1,tag2", user) expect(json_response).to match_array [ - a_hash_including('description' => 'Runner tagged with tag1 and tag2') + a_hash_including("description" => "Runner tagged with tag1 and tag2"), ] end end - context 'authorized user without maintainer privileges' do + context "authorized user without maintainer privileges" do it "does not return project's runners" do get api("/projects/#{project.id}/runners", user2) @@ -759,7 +759,7 @@ describe API::Runners do end end - context 'unauthorized user' do + context "unauthorized user" do it "does not return project's runners" do get api("/projects/#{project.id}/runners") @@ -768,95 +768,95 @@ describe API::Runners do end end - describe 'POST /projects/:id/runners' do - context 'authorized user' do + describe "POST /projects/:id/runners" do + context "authorized user" do let(:project_runner2) { create(:ci_runner, :project, projects: [project2]) } - it 'enables specific runner' do - expect do - post api("/projects/#{project.id}/runners", user), params: { runner_id: project_runner2.id } - end.to change { project.runners.count }.by(+1) + it "enables specific runner" do + expect { + post api("/projects/#{project.id}/runners", user), params: {runner_id: project_runner2.id} + }.to change { project.runners.count }.by(+1) expect(response).to have_gitlab_http_status(201) end - it 'avoids changes when enabling already enabled runner' do - expect do - post api("/projects/#{project.id}/runners", user), params: { runner_id: project_runner.id } - end.to change { project.runners.count }.by(0) + it "avoids changes when enabling already enabled runner" do + expect { + post api("/projects/#{project.id}/runners", user), params: {runner_id: project_runner.id} + }.to change { project.runners.count }.by(0) expect(response).to have_gitlab_http_status(400) end - it 'does not enable locked runner' do + it "does not enable locked runner" do project_runner2.update(locked: true) - expect do - post api("/projects/#{project.id}/runners", user), params: { runner_id: project_runner2.id } - end.to change { project.runners.count }.by(0) + expect { + post api("/projects/#{project.id}/runners", user), params: {runner_id: project_runner2.id} + }.to change { project.runners.count }.by(0) expect(response).to have_gitlab_http_status(403) end - it 'does not enable shared runner' do - post api("/projects/#{project.id}/runners", user), params: { runner_id: shared_runner.id } + it "does not enable shared runner" do + post api("/projects/#{project.id}/runners", user), params: {runner_id: shared_runner.id} expect(response).to have_gitlab_http_status(403) end - it 'does not enable group runner' do - post api("/projects/#{project.id}/runners", user), params: { runner_id: group_runner.id } + it "does not enable group runner" do + post api("/projects/#{project.id}/runners", user), params: {runner_id: group_runner.id} expect(response).to have_http_status(403) end - context 'user is admin' do - context 'when project runner is used' do + context "user is admin" do + context "when project runner is used" do let!(:new_project_runner) { create(:ci_runner, :project) } - it 'enables any specific runner' do - expect do - post api("/projects/#{project.id}/runners", admin), params: { runner_id: new_project_runner.id } - end.to change { project.runners.count }.by(+1) + it "enables any specific runner" do + expect { + post api("/projects/#{project.id}/runners", admin), params: {runner_id: new_project_runner.id} + }.to change { project.runners.count }.by(+1) expect(response).to have_gitlab_http_status(201) end end - it 'enables a instance type runner' do - expect do - post api("/projects/#{project.id}/runners", admin), params: { runner_id: shared_runner.id } - end.to change { project.runners.count }.by(1) + it "enables a instance type runner" do + expect { + post api("/projects/#{project.id}/runners", admin), params: {runner_id: shared_runner.id} + }.to change { project.runners.count }.by(1) expect(shared_runner.reload).not_to be_instance_type expect(response).to have_gitlab_http_status(201) end end - it 'raises an error when no runner_id param is provided' do + it "raises an error when no runner_id param is provided" do post api("/projects/#{project.id}/runners", admin) expect(response).to have_gitlab_http_status(400) end end - context 'user is not admin' do + context "user is not admin" do let!(:new_project_runner) { create(:ci_runner, :project) } - it 'does not enable runner without access to' do - post api("/projects/#{project.id}/runners", user), params: { runner_id: new_project_runner.id } + it "does not enable runner without access to" do + post api("/projects/#{project.id}/runners", user), params: {runner_id: new_project_runner.id} expect(response).to have_gitlab_http_status(403) end end - context 'authorized user without permissions' do - it 'does not enable runner' do + context "authorized user without permissions" do + it "does not enable runner" do post api("/projects/#{project.id}/runners", user2) expect(response).to have_gitlab_http_status(403) end end - context 'unauthorized user' do - it 'does not enable runner' do + context "unauthorized user" do + it "does not enable runner" do post api("/projects/#{project.id}/runners") expect(response).to have_gitlab_http_status(401) @@ -864,39 +864,39 @@ describe API::Runners do end end - describe 'DELETE /projects/:id/runners/:runner_id' do - context 'authorized user' do - context 'when runner have more than one associated projects' do + describe "DELETE /projects/:id/runners/:runner_id" do + context "authorized user" do + context "when runner have more than one associated projects" do it "disables project's runner" do - expect do + expect { delete api("/projects/#{project.id}/runners/#{two_projects_runner.id}", user) expect(response).to have_gitlab_http_status(204) - end.to change { project.runners.count }.by(-1) + }.to change { project.runners.count }.by(-1) end - it_behaves_like '412 response' do + it_behaves_like "412 response" do let(:request) { api("/projects/#{project.id}/runners/#{two_projects_runner.id}", user) } end end - context 'when runner have one associated projects' do + context "when runner have one associated projects" do it "does not disable project's runner" do - expect do + expect { delete api("/projects/#{project.id}/runners/#{project_runner.id}", user) - end.to change { project.runners.count }.by(0) + }.to change { project.runners.count }.by(0) expect(response).to have_gitlab_http_status(403) end end - it 'returns 404 is runner is not found' do + it "returns 404 is runner is not found" do delete api("/projects/#{project.id}/runners/0", user) expect(response).to have_gitlab_http_status(404) end end - context 'authorized user without permissions' do + context "authorized user without permissions" do it "does not disable project's runner" do delete api("/projects/#{project.id}/runners/#{project_runner.id}", user2) @@ -904,7 +904,7 @@ describe API::Runners do end end - context 'unauthorized user' do + context "unauthorized user" do it "does not disable project's runner" do delete api("/projects/#{project.id}/runners/#{project_runner.id}") diff --git a/spec/requests/api/search_spec.rb b/spec/requests/api/search_spec.rb index c48ca832c85..5c430e2ed46 100644 --- a/spec/requests/api/search_spec.rb +++ b/spec/requests/api/search_spec.rb @@ -1,336 +1,336 @@ -require 'spec_helper' +require "spec_helper" describe API::Search do set(:user) { create(:user) } set(:group) { create(:group) } - set(:project) { create(:project, :wiki_repo, :public, name: 'awesome project', group: group) } + set(:project) { create(:project, :wiki_repo, :public, name: "awesome project", group: group) } set(:repo_project) { create(:project, :public, :repository, group: group) } - shared_examples 'response is correct' do |schema:, size: 1| + shared_examples "response is correct" do |schema:, size: 1| it { expect(response).to have_gitlab_http_status(200) } it { expect(response).to match_response_schema(schema) } it { expect(response).to include_limited_pagination_headers } it { expect(json_response.size).to eq(size) } end - describe 'GET /search' do - context 'when user is not authenticated' do - it 'returns 401 error' do - get api('/search'), params: { scope: 'projects', search: 'awesome' } + describe "GET /search" do + context "when user is not authenticated" do + it "returns 401 error" do + get api("/search"), params: {scope: "projects", search: "awesome"} expect(response).to have_gitlab_http_status(401) end end - context 'when scope is not supported' do - it 'returns 400 error' do - get api('/search', user), params: { scope: 'unsupported', search: 'awesome' } + context "when scope is not supported" do + it "returns 400 error" do + get api("/search", user), params: {scope: "unsupported", search: "awesome"} expect(response).to have_gitlab_http_status(400) end end - context 'when scope is missing' do - it 'returns 400 error' do - get api('/search', user), params: { search: 'awesome' } + context "when scope is missing" do + it "returns 400 error" do + get api("/search", user), params: {search: "awesome"} expect(response).to have_gitlab_http_status(400) end end - context 'with correct params' do - context 'for projects scope' do + context "with correct params" do + context "for projects scope" do before do - get api('/search', user), params: { scope: 'projects', search: 'awesome' } + get api("/search", user), params: {scope: "projects", search: "awesome"} end - it_behaves_like 'response is correct', schema: 'public_api/v4/projects' + it_behaves_like "response is correct", schema: "public_api/v4/projects" end - context 'for issues scope' do + context "for issues scope" do before do - create(:issue, project: project, title: 'awesome issue') + create(:issue, project: project, title: "awesome issue") - get api('/search', user), params: { scope: 'issues', search: 'awesome' } + get api("/search", user), params: {scope: "issues", search: "awesome"} end - it_behaves_like 'response is correct', schema: 'public_api/v4/issues' + it_behaves_like "response is correct", schema: "public_api/v4/issues" end - context 'for merge_requests scope' do + context "for merge_requests scope" do before do - create(:merge_request, source_project: repo_project, title: 'awesome mr') + create(:merge_request, source_project: repo_project, title: "awesome mr") - get api('/search', user), params: { scope: 'merge_requests', search: 'awesome' } + get api("/search", user), params: {scope: "merge_requests", search: "awesome"} end - it_behaves_like 'response is correct', schema: 'public_api/v4/merge_requests' + it_behaves_like "response is correct", schema: "public_api/v4/merge_requests" end - context 'for milestones scope' do + context "for milestones scope" do before do - create(:milestone, project: project, title: 'awesome milestone') + create(:milestone, project: project, title: "awesome milestone") - get api('/search', user), params: { scope: 'milestones', search: 'awesome' } + get api("/search", user), params: {scope: "milestones", search: "awesome"} end - it_behaves_like 'response is correct', schema: 'public_api/v4/milestones' + it_behaves_like "response is correct", schema: "public_api/v4/milestones" end - context 'for snippet_titles scope' do + context "for snippet_titles scope" do before do - create(:snippet, :public, title: 'awesome snippet', content: 'snippet content') + create(:snippet, :public, title: "awesome snippet", content: "snippet content") - get api('/search', user), params: { scope: 'snippet_titles', search: 'awesome' } + get api("/search", user), params: {scope: "snippet_titles", search: "awesome"} end - it_behaves_like 'response is correct', schema: 'public_api/v4/snippets' + it_behaves_like "response is correct", schema: "public_api/v4/snippets" end - context 'for snippet_blobs scope' do + context "for snippet_blobs scope" do before do - create(:snippet, :public, title: 'awesome snippet', content: 'snippet content') + create(:snippet, :public, title: "awesome snippet", content: "snippet content") - get api('/search', user), params: { scope: 'snippet_blobs', search: 'content' } + get api("/search", user), params: {scope: "snippet_blobs", search: "content"} end - it_behaves_like 'response is correct', schema: 'public_api/v4/snippets' + it_behaves_like "response is correct", schema: "public_api/v4/snippets" end end end describe "GET /groups/:id/search" do - context 'when user is not authenticated' do - it 'returns 401 error' do - get api("/groups/#{group.id}/search"), params: { scope: 'projects', search: 'awesome' } + context "when user is not authenticated" do + it "returns 401 error" do + get api("/groups/#{group.id}/search"), params: {scope: "projects", search: "awesome"} expect(response).to have_gitlab_http_status(401) end end - context 'when scope is not supported' do - it 'returns 400 error' do - get api("/groups/#{group.id}/search", user), params: { scope: 'unsupported', search: 'awesome' } + context "when scope is not supported" do + it "returns 400 error" do + get api("/groups/#{group.id}/search", user), params: {scope: "unsupported", search: "awesome"} expect(response).to have_gitlab_http_status(400) end end - context 'when scope is missing' do - it 'returns 400 error' do - get api("/groups/#{group.id}/search", user), params: { search: 'awesome' } + context "when scope is missing" do + it "returns 400 error" do + get api("/groups/#{group.id}/search", user), params: {search: "awesome"} expect(response).to have_gitlab_http_status(400) end end - context 'when group does not exist' do - it 'returns 404 error' do - get api('/groups/0/search', user), params: { scope: 'issues', search: 'awesome' } + context "when group does not exist" do + it "returns 404 error" do + get api("/groups/0/search", user), params: {scope: "issues", search: "awesome"} expect(response).to have_gitlab_http_status(404) end end - context 'when user does can not see the group' do - it 'returns 404 error' do + context "when user does can not see the group" do + it "returns 404 error" do private_group = create(:group, :private) - get api("/groups/#{private_group.id}/search", user), params: { scope: 'issues', search: 'awesome' } + get api("/groups/#{private_group.id}/search", user), params: {scope: "issues", search: "awesome"} expect(response).to have_gitlab_http_status(404) end end - context 'with correct params' do - context 'for projects scope' do + context "with correct params" do + context "for projects scope" do before do - get api("/groups/#{group.id}/search", user), params: { scope: 'projects', search: 'awesome' } + get api("/groups/#{group.id}/search", user), params: {scope: "projects", search: "awesome"} end - it_behaves_like 'response is correct', schema: 'public_api/v4/projects' + it_behaves_like "response is correct", schema: "public_api/v4/projects" end - context 'for issues scope' do + context "for issues scope" do before do - create(:issue, project: project, title: 'awesome issue') + create(:issue, project: project, title: "awesome issue") - get api("/groups/#{group.id}/search", user), params: { scope: 'issues', search: 'awesome' } + get api("/groups/#{group.id}/search", user), params: {scope: "issues", search: "awesome"} end - it_behaves_like 'response is correct', schema: 'public_api/v4/issues' + it_behaves_like "response is correct", schema: "public_api/v4/issues" end - context 'for merge_requests scope' do + context "for merge_requests scope" do before do - create(:merge_request, source_project: repo_project, title: 'awesome mr') + create(:merge_request, source_project: repo_project, title: "awesome mr") - get api("/groups/#{group.id}/search", user), params: { scope: 'merge_requests', search: 'awesome' } + get api("/groups/#{group.id}/search", user), params: {scope: "merge_requests", search: "awesome"} end - it_behaves_like 'response is correct', schema: 'public_api/v4/merge_requests' + it_behaves_like "response is correct", schema: "public_api/v4/merge_requests" end - context 'for milestones scope' do + context "for milestones scope" do before do - create(:milestone, project: project, title: 'awesome milestone') + create(:milestone, project: project, title: "awesome milestone") - get api("/groups/#{group.id}/search", user), params: { scope: 'milestones', search: 'awesome' } + get api("/groups/#{group.id}/search", user), params: {scope: "milestones", search: "awesome"} end - it_behaves_like 'response is correct', schema: 'public_api/v4/milestones' + it_behaves_like "response is correct", schema: "public_api/v4/milestones" end - context 'for milestones scope with group path as id' do + context "for milestones scope with group path as id" do before do another_project = create(:project, :public) - create(:milestone, project: project, title: 'awesome milestone') - create(:milestone, project: another_project, title: 'awesome milestone other project') + create(:milestone, project: project, title: "awesome milestone") + create(:milestone, project: another_project, title: "awesome milestone other project") - get api("/groups/#{CGI.escape(group.full_path)}/search", user), params: { scope: 'milestones', search: 'awesome' } + get api("/groups/#{CGI.escape(group.full_path)}/search", user), params: {scope: "milestones", search: "awesome"} end - it_behaves_like 'response is correct', schema: 'public_api/v4/milestones' + it_behaves_like "response is correct", schema: "public_api/v4/milestones" end end end describe "GET /projects/:id/search" do - context 'when user is not authenticated' do - it 'returns 401 error' do - get api("/projects/#{project.id}/search"), params: { scope: 'issues', search: 'awesome' } + context "when user is not authenticated" do + it "returns 401 error" do + get api("/projects/#{project.id}/search"), params: {scope: "issues", search: "awesome"} expect(response).to have_gitlab_http_status(401) end end - context 'when scope is not supported' do - it 'returns 400 error' do - get api("/projects/#{project.id}/search", user), params: { scope: 'unsupported', search: 'awesome' } + context "when scope is not supported" do + it "returns 400 error" do + get api("/projects/#{project.id}/search", user), params: {scope: "unsupported", search: "awesome"} expect(response).to have_gitlab_http_status(400) end end - context 'when scope is missing' do - it 'returns 400 error' do - get api("/projects/#{project.id}/search", user), params: { search: 'awesome' } + context "when scope is missing" do + it "returns 400 error" do + get api("/projects/#{project.id}/search", user), params: {search: "awesome"} expect(response).to have_gitlab_http_status(400) end end - context 'when project does not exist' do - it 'returns 404 error' do - get api('/projects/0/search', user), params: { scope: 'issues', search: 'awesome' } + context "when project does not exist" do + it "returns 404 error" do + get api("/projects/0/search", user), params: {scope: "issues", search: "awesome"} expect(response).to have_gitlab_http_status(404) end end - context 'when user does can not see the project' do - it 'returns 404 error' do + context "when user does can not see the project" do + it "returns 404 error" do project.update!(visibility_level: Gitlab::VisibilityLevel::PRIVATE) - get api("/projects/#{project.id}/search", user), params: { scope: 'issues', search: 'awesome' } + get api("/projects/#{project.id}/search", user), params: {scope: "issues", search: "awesome"} expect(response).to have_gitlab_http_status(404) end end - context 'with correct params' do - context 'for issues scope' do + context "with correct params" do + context "for issues scope" do before do - create(:issue, project: project, title: 'awesome issue') + create(:issue, project: project, title: "awesome issue") - get api("/projects/#{project.id}/search", user), params: { scope: 'issues', search: 'awesome' } + get api("/projects/#{project.id}/search", user), params: {scope: "issues", search: "awesome"} end - it_behaves_like 'response is correct', schema: 'public_api/v4/issues' + it_behaves_like "response is correct", schema: "public_api/v4/issues" end - context 'for merge_requests scope' do + context "for merge_requests scope" do before do - create(:merge_request, source_project: repo_project, title: 'awesome mr') + create(:merge_request, source_project: repo_project, title: "awesome mr") - get api("/projects/#{repo_project.id}/search", user), params: { scope: 'merge_requests', search: 'awesome' } + get api("/projects/#{repo_project.id}/search", user), params: {scope: "merge_requests", search: "awesome"} end - it_behaves_like 'response is correct', schema: 'public_api/v4/merge_requests' + it_behaves_like "response is correct", schema: "public_api/v4/merge_requests" end - context 'for milestones scope' do + context "for milestones scope" do before do - create(:milestone, project: project, title: 'awesome milestone') + create(:milestone, project: project, title: "awesome milestone") - get api("/projects/#{project.id}/search", user), params: { scope: 'milestones', search: 'awesome' } + get api("/projects/#{project.id}/search", user), params: {scope: "milestones", search: "awesome"} end - it_behaves_like 'response is correct', schema: 'public_api/v4/milestones' + it_behaves_like "response is correct", schema: "public_api/v4/milestones" end - context 'for notes scope' do + context "for notes scope" do before do - create(:note_on_merge_request, project: project, note: 'awesome note') + create(:note_on_merge_request, project: project, note: "awesome note") - get api("/projects/#{project.id}/search", user), params: { scope: 'notes', search: 'awesome' } + get api("/projects/#{project.id}/search", user), params: {scope: "notes", search: "awesome"} end - it_behaves_like 'response is correct', schema: 'public_api/v4/notes' + it_behaves_like "response is correct", schema: "public_api/v4/notes" end - context 'for wiki_blobs scope' do + context "for wiki_blobs scope" do before do wiki = create(:project_wiki, project: project) - create(:wiki_page, wiki: wiki, attrs: { title: 'home', content: "Awesome page" }) + create(:wiki_page, wiki: wiki, attrs: {title: "home", content: "Awesome page"}) - get api("/projects/#{project.id}/search", user), params: { scope: 'wiki_blobs', search: 'awesome' } + get api("/projects/#{project.id}/search", user), params: {scope: "wiki_blobs", search: "awesome"} end - it_behaves_like 'response is correct', schema: 'public_api/v4/blobs' + it_behaves_like "response is correct", schema: "public_api/v4/blobs" end - context 'for commits scope' do + context "for commits scope" do before do - get api("/projects/#{repo_project.id}/search", user), params: { scope: 'commits', search: '498214de67004b1da3d820901307bed2a68a8ef6' } + get api("/projects/#{repo_project.id}/search", user), params: {scope: "commits", search: "498214de67004b1da3d820901307bed2a68a8ef6"} end - it_behaves_like 'response is correct', schema: 'public_api/v4/commits_details' + it_behaves_like "response is correct", schema: "public_api/v4/commits_details" end - context 'for commits scope with project path as id' do + context "for commits scope with project path as id" do before do - get api("/projects/#{CGI.escape(repo_project.full_path)}/search", user), params: { scope: 'commits', search: '498214de67004b1da3d820901307bed2a68a8ef6' } + get api("/projects/#{CGI.escape(repo_project.full_path)}/search", user), params: {scope: "commits", search: "498214de67004b1da3d820901307bed2a68a8ef6"} end - it_behaves_like 'response is correct', schema: 'public_api/v4/commits_details' + it_behaves_like "response is correct", schema: "public_api/v4/commits_details" end - context 'for blobs scope' do + context "for blobs scope" do before do - get api("/projects/#{repo_project.id}/search", user), params: { scope: 'blobs', search: 'monitors' } + get api("/projects/#{repo_project.id}/search", user), params: {scope: "blobs", search: "monitors"} end - it_behaves_like 'response is correct', schema: 'public_api/v4/blobs', size: 2 + it_behaves_like "response is correct", schema: "public_api/v4/blobs", size: 2 - context 'filters' do - it 'by filename' do - get api("/projects/#{repo_project.id}/search", user), params: { scope: 'blobs', search: 'mon filename:PROCESS.md' } + context "filters" do + it "by filename" do + get api("/projects/#{repo_project.id}/search", user), params: {scope: "blobs", search: "mon filename:PROCESS.md"} expect(response).to have_gitlab_http_status(200) expect(json_response.size).to eq(2) - expect(json_response.first['filename']).to eq('PROCESS.md') + expect(json_response.first["filename"]).to eq("PROCESS.md") end - it 'by path' do - get api("/projects/#{repo_project.id}/search", user), params: { scope: 'blobs', search: 'mon path:markdown' } + it "by path" do + get api("/projects/#{repo_project.id}/search", user), params: {scope: "blobs", search: "mon path:markdown"} expect(response).to have_gitlab_http_status(200) expect(json_response.size).to eq(8) end - it 'by extension' do - get api("/projects/#{repo_project.id}/search", user), params: { scope: 'blobs', search: 'mon extension:md' } + it "by extension" do + get api("/projects/#{repo_project.id}/search", user), params: {scope: "blobs", search: "mon extension:md"} expect(response).to have_gitlab_http_status(200) expect(json_response.size).to eq(11) diff --git a/spec/requests/api/services_spec.rb b/spec/requests/api/services_spec.rb index e260aa21e25..cb9552b0fe7 100644 --- a/spec/requests/api/services_spec.rb +++ b/spec/requests/api/services_spec.rb @@ -31,11 +31,11 @@ describe API::Services do it "returns if required fields missing" do attrs = service_attrs - required_attributes = service_attrs_list.select do |attr| + required_attributes = service_attrs_list.select { |attr| service_klass.validators_on(attr).any? do |v| v.class == ActiveRecord::Validations::PresenceValidator end - end + } if required_attributes.empty? expected_code = 200 @@ -74,7 +74,7 @@ describe API::Services do initialize_service(service) end - it 'returns authentication error when unauthenticated' do + it "returns authentication error when unauthenticated" do get api("/projects/#{project.id}/services/#{dashed_service}") expect(response).to have_gitlab_http_status(401) end @@ -83,14 +83,14 @@ describe API::Services do get api("/projects/#{project.id}/services/#{dashed_service}", admin) expect(response).to have_gitlab_http_status(200) - expect(json_response['properties'].keys).to match_array(service_instance.api_field_names) + expect(json_response["properties"].keys).to match_array(service_instance.api_field_names) end it "returns properties of service #{service} other than passwords when authenticated as project owner" do get api("/projects/#{project.id}/services/#{dashed_service}", user) expect(response).to have_gitlab_http_status(200) - expect(json_response['properties'].keys).to match_array(service_instance.api_field_names) + expect(json_response["properties"].keys).to match_array(service_instance.api_field_names) end it "returns error when authenticated but not a project owner" do @@ -102,12 +102,12 @@ describe API::Services do end end - describe 'POST /projects/:id/services/:slug/trigger' do - describe 'Mattermost Service' do - let(:service_name) { 'mattermost_slash_commands' } + describe "POST /projects/:id/services/:slug/trigger" do + describe "Mattermost Service" do + let(:service_name) { "mattermost_slash_commands" } - context 'no service is available' do - it 'returns a not found message' do + context "no service is available" do + it "returns a not found message" do post api("/projects/#{project.id}/services/idonotexist/trigger") expect(response).to have_gitlab_http_status(404) @@ -115,10 +115,10 @@ describe API::Services do end end - context 'the service exists' do - let(:params) { { token: 'token' } } + context "the service exists" do + let(:params) { {token: "token"} } - context 'the service is not active' do + context "the service is not active" do before do project.create_mattermost_slash_commands_service( active: false, @@ -126,14 +126,14 @@ describe API::Services do ) end - it 'when the service is inactive' do + it "when the service is inactive" do post api("/projects/#{project.id}/services/#{service_name}/trigger"), params: params expect(response).to have_gitlab_http_status(404) end end - context 'the service is active' do + context "the service is active" do before do project.create_mattermost_slash_commands_service( active: true, @@ -141,15 +141,15 @@ describe API::Services do ) end - it 'returns status 200' do + it "returns status 200" do post api("/projects/#{project.id}/services/#{service_name}/trigger"), params: params expect(response).to have_gitlab_http_status(200) end end - context 'when the project can not be found' do - it 'returns a generic 404' do + context "when the project can not be found" do + it "returns a generic 404" do post api("/projects/404/services/#{service_name}/trigger"), params: params expect(response).to have_gitlab_http_status(404) @@ -159,29 +159,29 @@ describe API::Services do end end - describe 'Slack Service' do - let(:service_name) { 'slack_slash_commands' } + describe "Slack Service" do + let(:service_name) { "slack_slash_commands" } before do project.create_slack_slash_commands_service( active: true, - properties: { token: 'token' } + properties: {token: "token"} ) end - it 'returns status 200' do - post api("/projects/#{project.id}/services/#{service_name}/trigger"), params: { token: 'token', text: 'help' } + it "returns status 200" do + post api("/projects/#{project.id}/services/#{service_name}/trigger"), params: {token: "token", text: "help"} expect(response).to have_gitlab_http_status(200) - expect(json_response['response_type']).to eq("ephemeral") + expect(json_response["response_type"]).to eq("ephemeral") end end end - describe 'Mattermost service' do - let(:service_name) { 'mattermost' } + describe "Mattermost service" do + let(:service_name) { "mattermost" } let(:params) do - { webhook: 'https://hook.example.com', username: 'username' } + {webhook: "https://hook.example.com", username: "username"} end before do @@ -191,11 +191,11 @@ describe API::Services do ) end - it 'accepts a username for update' do - put api("/projects/#{project.id}/services/mattermost", user), params: params.merge(username: 'new_username') + it "accepts a username for update" do + put api("/projects/#{project.id}/services/mattermost", user), params: params.merge(username: "new_username") expect(response).to have_gitlab_http_status(200) - expect(json_response['properties']['username']).to eq('new_username') + expect(json_response["properties"]["username"]).to eq("new_username") end end end diff --git a/spec/requests/api/settings_spec.rb b/spec/requests/api/settings_spec.rb index f33eb5b9e02..68da45e2484 100644 --- a/spec/requests/api/settings_spec.rb +++ b/spec/requests/api/settings_spec.rb @@ -1,6 +1,6 @@ -require 'spec_helper' +require "spec_helper" -describe API::Settings, 'Settings' do +describe API::Settings, "Settings" do let(:user) { create(:user) } set(:admin) { create(:admin) } @@ -10,22 +10,22 @@ describe API::Settings, 'Settings' do expect(response).to have_gitlab_http_status(200) expect(json_response).to be_an Hash - expect(json_response['default_projects_limit']).to eq(42) - expect(json_response['password_authentication_enabled_for_web']).to be_truthy - expect(json_response['repository_storages']).to eq(['default']) - expect(json_response['plantuml_enabled']).to be_falsey - expect(json_response['plantuml_url']).to be_nil - expect(json_response['default_project_visibility']).to be_a String - expect(json_response['default_snippet_visibility']).to be_a String - expect(json_response['default_group_visibility']).to be_a String - expect(json_response['rsa_key_restriction']).to eq(0) - expect(json_response['dsa_key_restriction']).to eq(0) - expect(json_response['ecdsa_key_restriction']).to eq(0) - expect(json_response['ed25519_key_restriction']).to eq(0) - expect(json_response['performance_bar_allowed_group_id']).to be_nil - expect(json_response['instance_statistics_visibility_private']).to be(false) - expect(json_response).not_to have_key('performance_bar_allowed_group_path') - expect(json_response).not_to have_key('performance_bar_enabled') + expect(json_response["default_projects_limit"]).to eq(42) + expect(json_response["password_authentication_enabled_for_web"]).to be_truthy + expect(json_response["repository_storages"]).to eq(["default"]) + expect(json_response["plantuml_enabled"]).to be_falsey + expect(json_response["plantuml_url"]).to be_nil + expect(json_response["default_project_visibility"]).to be_a String + expect(json_response["default_snippet_visibility"]).to be_a String + expect(json_response["default_group_visibility"]).to be_a String + expect(json_response["rsa_key_restriction"]).to eq(0) + expect(json_response["dsa_key_restriction"]).to eq(0) + expect(json_response["ecdsa_key_restriction"]).to eq(0) + expect(json_response["ed25519_key_restriction"]).to eq(0) + expect(json_response["performance_bar_allowed_group_id"]).to be_nil + expect(json_response["instance_statistics_visibility_private"]).to be(false) + expect(json_response).not_to have_key("performance_bar_allowed_group_path") + expect(json_response).not_to have_key("performance_bar_enabled") end end @@ -36,7 +36,7 @@ describe API::Settings, 'Settings' do before do # Add a possible storage to the config storages = Gitlab.config.repositories.storages - .merge({ 'custom' => 'tmp/tests/custom_repositories' }) + .merge({"custom" => "tmp/tests/custom_repositories"}) allow(Gitlab.config.repositories).to receive(:storages).and_return(storages) end @@ -45,81 +45,81 @@ describe API::Settings, 'Settings' do params: { default_projects_limit: 3, password_authentication_enabled_for_web: false, - repository_storages: ['custom'], + repository_storages: ["custom"], plantuml_enabled: true, - plantuml_url: 'http://plantuml.example.com', - default_snippet_visibility: 'internal', - restricted_visibility_levels: ['public'], - default_artifacts_expire_in: '2 days', - help_page_text: 'custom help text', + plantuml_url: "http://plantuml.example.com", + default_snippet_visibility: "internal", + restricted_visibility_levels: ["public"], + default_artifacts_expire_in: "2 days", + help_page_text: "custom help text", help_page_hide_commercial_content: true, - help_page_support_url: 'http://example.com/help', + help_page_support_url: "http://example.com/help", project_export_enabled: false, rsa_key_restriction: ApplicationSetting::FORBIDDEN_KEY_VALUE, dsa_key_restriction: 2048, ecdsa_key_restriction: 384, ed25519_key_restriction: 256, enforce_terms: true, - terms: 'Hello world!', + terms: "Hello world!", performance_bar_allowed_group_path: group.full_path, instance_statistics_visibility_private: true, diff_max_patch_bytes: 150_000, default_branch_protection: Gitlab::Access::PROTECTION_DEV_CAN_MERGE, - local_markdown_version: 3 + local_markdown_version: 3, } expect(response).to have_gitlab_http_status(200) - expect(json_response['default_projects_limit']).to eq(3) - expect(json_response['password_authentication_enabled_for_web']).to be_falsey - expect(json_response['repository_storages']).to eq(['custom']) - expect(json_response['plantuml_enabled']).to be_truthy - expect(json_response['plantuml_url']).to eq('http://plantuml.example.com') - expect(json_response['default_snippet_visibility']).to eq('internal') - expect(json_response['restricted_visibility_levels']).to eq(['public']) - expect(json_response['default_artifacts_expire_in']).to eq('2 days') - expect(json_response['help_page_text']).to eq('custom help text') - expect(json_response['help_page_hide_commercial_content']).to be_truthy - expect(json_response['help_page_support_url']).to eq('http://example.com/help') - expect(json_response['project_export_enabled']).to be_falsey - expect(json_response['rsa_key_restriction']).to eq(ApplicationSetting::FORBIDDEN_KEY_VALUE) - expect(json_response['dsa_key_restriction']).to eq(2048) - expect(json_response['ecdsa_key_restriction']).to eq(384) - expect(json_response['ed25519_key_restriction']).to eq(256) - expect(json_response['enforce_terms']).to be(true) - expect(json_response['terms']).to eq('Hello world!') - expect(json_response['performance_bar_allowed_group_id']).to eq(group.id) - expect(json_response['instance_statistics_visibility_private']).to be(true) - expect(json_response['diff_max_patch_bytes']).to eq(150_000) - expect(json_response['default_branch_protection']).to eq(Gitlab::Access::PROTECTION_DEV_CAN_MERGE) - expect(json_response['local_markdown_version']).to eq(3) + expect(json_response["default_projects_limit"]).to eq(3) + expect(json_response["password_authentication_enabled_for_web"]).to be_falsey + expect(json_response["repository_storages"]).to eq(["custom"]) + expect(json_response["plantuml_enabled"]).to be_truthy + expect(json_response["plantuml_url"]).to eq("http://plantuml.example.com") + expect(json_response["default_snippet_visibility"]).to eq("internal") + expect(json_response["restricted_visibility_levels"]).to eq(["public"]) + expect(json_response["default_artifacts_expire_in"]).to eq("2 days") + expect(json_response["help_page_text"]).to eq("custom help text") + expect(json_response["help_page_hide_commercial_content"]).to be_truthy + expect(json_response["help_page_support_url"]).to eq("http://example.com/help") + expect(json_response["project_export_enabled"]).to be_falsey + expect(json_response["rsa_key_restriction"]).to eq(ApplicationSetting::FORBIDDEN_KEY_VALUE) + expect(json_response["dsa_key_restriction"]).to eq(2048) + expect(json_response["ecdsa_key_restriction"]).to eq(384) + expect(json_response["ed25519_key_restriction"]).to eq(256) + expect(json_response["enforce_terms"]).to be(true) + expect(json_response["terms"]).to eq("Hello world!") + expect(json_response["performance_bar_allowed_group_id"]).to eq(group.id) + expect(json_response["instance_statistics_visibility_private"]).to be(true) + expect(json_response["diff_max_patch_bytes"]).to eq(150_000) + expect(json_response["default_branch_protection"]).to eq(Gitlab::Access::PROTECTION_DEV_CAN_MERGE) + expect(json_response["local_markdown_version"]).to eq(3) end end it "supports legacy performance_bar_allowed_group_id" do put api("/application/settings", admin), - params: { performance_bar_allowed_group_id: group.full_path } + params: {performance_bar_allowed_group_id: group.full_path} expect(response).to have_gitlab_http_status(200) - expect(json_response['performance_bar_allowed_group_id']).to eq(group.id) + expect(json_response["performance_bar_allowed_group_id"]).to eq(group.id) end it "supports legacy performance_bar_enabled" do put api("/application/settings", admin), params: { performance_bar_enabled: false, - performance_bar_allowed_group_id: group.full_path + performance_bar_allowed_group_id: group.full_path, } expect(response).to have_gitlab_http_status(200) - expect(json_response['performance_bar_allowed_group_id']).to be_nil + expect(json_response["performance_bar_allowed_group_id"]).to be_nil end context "missing plantuml_url value when plantuml_enabled is true" do it "returns a blank parameter error message" do - put api("/application/settings", admin), params: { plantuml_enabled: true } + put api("/application/settings", admin), params: {plantuml_enabled: true} expect(response).to have_gitlab_http_status(400) - expect(json_response['error']).to eq('plantuml_url is missing') + expect(json_response["error"]).to eq("plantuml_url is missing") end end end diff --git a/spec/requests/api/sidekiq_metrics_spec.rb b/spec/requests/api/sidekiq_metrics_spec.rb index fff9adb7f57..230a2f14947 100644 --- a/spec/requests/api/sidekiq_metrics_spec.rb +++ b/spec/requests/api/sidekiq_metrics_spec.rb @@ -1,38 +1,38 @@ -require 'spec_helper' +require "spec_helper" describe API::SidekiqMetrics do let(:admin) { create(:user, :admin) } - describe 'GET sidekiq/*' do - it 'defines the `queue_metrics` endpoint' do - get api('/sidekiq/queue_metrics', admin) + describe "GET sidekiq/*" do + it "defines the `queue_metrics` endpoint" do + get api("/sidekiq/queue_metrics", admin) expect(response).to have_gitlab_http_status(200) expect(json_response).to be_a Hash end - it 'defines the `process_metrics` endpoint' do - get api('/sidekiq/process_metrics', admin) + it "defines the `process_metrics` endpoint" do + get api("/sidekiq/process_metrics", admin) expect(response).to have_gitlab_http_status(200) - expect(json_response['processes']).to be_an Array + expect(json_response["processes"]).to be_an Array end - it 'defines the `job_stats` endpoint' do - get api('/sidekiq/job_stats', admin) + it "defines the `job_stats` endpoint" do + get api("/sidekiq/job_stats", admin) expect(response).to have_gitlab_http_status(200) expect(json_response).to be_a Hash end - it 'defines the `compound_metrics` endpoint' do - get api('/sidekiq/compound_metrics', admin) + it "defines the `compound_metrics` endpoint" do + get api("/sidekiq/compound_metrics", admin) expect(response).to have_gitlab_http_status(200) expect(json_response).to be_a Hash - expect(json_response['queues']).to be_a Hash - expect(json_response['processes']).to be_an Array - expect(json_response['jobs']).to be_a Hash + expect(json_response["queues"]).to be_a Hash + expect(json_response["processes"]).to be_an Array + expect(json_response["jobs"]).to be_a Hash end end end diff --git a/spec/requests/api/snippets_spec.rb b/spec/requests/api/snippets_spec.rb index 7c8512f7589..b57a92b54eb 100644 --- a/spec/requests/api/snippets_spec.rb +++ b/spec/requests/api/snippets_spec.rb @@ -1,10 +1,10 @@ -require 'rails_helper' +require "rails_helper" describe API::Snippets do let!(:user) { create(:user) } - describe 'GET /snippets/' do - it 'returns snippets available' do + describe "GET /snippets/" do + it "returns snippets available" do public_snippet = create(:personal_snippet, :public, author: user) private_snippet = create(:personal_snippet, :private, author: user) internal_snippet = create(:personal_snippet, :internal, author: user) @@ -14,16 +14,17 @@ describe API::Snippets do expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response).to be_an Array - expect(json_response.map { |snippet| snippet['id']} ).to contain_exactly( + expect(json_response.map { |snippet| snippet["id"]}).to contain_exactly( public_snippet.id, internal_snippet.id, - private_snippet.id) - expect(json_response.last).to have_key('web_url') - expect(json_response.last).to have_key('raw_url') - expect(json_response.last).to have_key('visibility') + private_snippet.id + ) + expect(json_response.last).to have_key("web_url") + expect(json_response.last).to have_key("raw_url") + expect(json_response.last).to have_key("visibility") end - it 'hides private snippets from regular user' do + it "hides private snippets from regular user" do create(:personal_snippet, :private) get api("/snippets/", user) @@ -34,7 +35,7 @@ describe API::Snippets do expect(json_response.size).to eq(0) end - it 'returns 404 for non-authenticated' do + it "returns 404 for non-authenticated" do create(:personal_snippet, :internal) get api("/snippets/") @@ -42,7 +43,7 @@ describe API::Snippets do expect(response).to have_gitlab_http_status(401) end - it 'does not return snippets related to a project with disable feature visibility' do + it "does not return snippets related to a project with disable feature visibility" do project = create(:project) create(:project_member, project: project, user: user) public_snippet = create(:personal_snippet, :public, author: user, project: project) @@ -56,7 +57,7 @@ describe API::Snippets do end end - describe 'GET /snippets/public' do + describe "GET /snippets/public" do let!(:other_user) { create(:user) } let!(:public_snippet) { create(:personal_snippet, :public, author: user) } let!(:private_snippet) { create(:personal_snippet, :private, author: user) } @@ -65,95 +66,98 @@ describe API::Snippets do let!(:private_snippet_other) { create(:personal_snippet, :private, author: other_user) } let!(:internal_snippet_other) { create(:personal_snippet, :internal, author: other_user) } - it 'returns all snippets with public visibility from all users' do + it "returns all snippets with public visibility from all users" do get api("/snippets/public", user) expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response).to be_an Array - expect(json_response.map { |snippet| snippet['id']} ).to contain_exactly( + expect(json_response.map { |snippet| snippet["id"]}).to contain_exactly( public_snippet.id, - public_snippet_other.id) - expect(json_response.map { |snippet| snippet['web_url']} ).to include( + public_snippet_other.id + ) + expect(json_response.map { |snippet| snippet["web_url"]}).to include( "http://localhost/snippets/#{public_snippet.id}", - "http://localhost/snippets/#{public_snippet_other.id}") - expect(json_response.map { |snippet| snippet['raw_url']} ).to include( + "http://localhost/snippets/#{public_snippet_other.id}" + ) + expect(json_response.map { |snippet| snippet["raw_url"]}).to include( "http://localhost/snippets/#{public_snippet.id}/raw", - "http://localhost/snippets/#{public_snippet_other.id}/raw") + "http://localhost/snippets/#{public_snippet_other.id}/raw" + ) end end - describe 'GET /snippets/:id/raw' do + describe "GET /snippets/:id/raw" do let(:snippet) { create(:personal_snippet, author: user) } - it 'returns raw text' do + it "returns raw text" do get api("/snippets/#{snippet.id}/raw", user) expect(response).to have_gitlab_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) end - it 'forces attachment content disposition' do + it "forces attachment content disposition" do get api("/snippets/#{snippet.id}/raw", user) - expect(headers['Content-Disposition']).to match(/^attachment/) + expect(headers["Content-Disposition"]).to match(/^attachment/) end - it 'returns 404 for invalid snippet id' do + it "returns 404 for invalid snippet id" do get api("/snippets/1234/raw", user) expect(response).to have_gitlab_http_status(404) - expect(json_response['message']).to eq('404 Snippet Not Found') + expect(json_response["message"]).to eq("404 Snippet Not Found") end end - describe 'GET /snippets/:id' do + describe "GET /snippets/:id" do let(:snippet) { create(:personal_snippet, author: user) } - it 'returns snippet json' do + it "returns snippet json" do get api("/snippets/#{snippet.id}", user) expect(response).to have_gitlab_http_status(200) - expect(json_response['title']).to eq(snippet.title) - expect(json_response['description']).to eq(snippet.description) - expect(json_response['file_name']).to eq(snippet.file_name) - expect(json_response['visibility']).to eq(snippet.visibility) + expect(json_response["title"]).to eq(snippet.title) + expect(json_response["description"]).to eq(snippet.description) + expect(json_response["file_name"]).to eq(snippet.file_name) + expect(json_response["visibility"]).to eq(snippet.visibility) end - it 'returns 404 for invalid snippet id' do + it "returns 404 for invalid snippet id" do get api("/snippets/1234", user) expect(response).to have_gitlab_http_status(404) - expect(json_response['message']).to eq('404 Not found') + expect(json_response["message"]).to eq("404 Not found") end end - describe 'POST /snippets/' do + describe "POST /snippets/" do let(:params) do { - title: 'Test Title', - file_name: 'test.rb', - description: 'test description', + title: "Test Title", + file_name: "test.rb", + description: "test description", content: 'puts "hello world"', - visibility: 'public' + visibility: "public", } end - it 'creates a new snippet' do - expect do + it "creates a new snippet" do + expect { post api("/snippets/", user), params: params - end.to change { PersonalSnippet.count }.by(1) + }.to change { PersonalSnippet.count }.by(1) expect(response).to have_gitlab_http_status(201) - expect(json_response['title']).to eq(params[:title]) - expect(json_response['description']).to eq(params[:description]) - expect(json_response['file_name']).to eq(params[:file_name]) - expect(json_response['visibility']).to eq(params[:visibility]) + expect(json_response["title"]).to eq(params[:title]) + expect(json_response["description"]).to eq(params[:description]) + expect(json_response["file_name"]).to eq(params[:file_name]) + expect(json_response["visibility"]).to eq(params[:visibility]) end - it 'returns 400 for missing parameters' do + it "returns 400 for missing parameters" do params.delete(:title) post api("/snippets/", user), params: params @@ -161,51 +165,51 @@ describe API::Snippets do expect(response).to have_gitlab_http_status(400) end - context 'when the snippet is spam' do + context "when the snippet is spam" do def create_snippet(snippet_params = {}) - post api('/snippets', user), params: params.merge(snippet_params) + post api("/snippets", user), params: params.merge(snippet_params) end before do allow_any_instance_of(AkismetService).to receive(:spam?).and_return(true) end - context 'when the snippet is private' do - it 'creates the snippet' do - expect { create_snippet(visibility: 'private') } + context "when the snippet is private" do + it "creates the snippet" do + expect { create_snippet(visibility: "private") } .to change { Snippet.count }.by(1) end end - context 'when the snippet is public' do - it 'rejects the shippet' do - expect { create_snippet(visibility: 'public') } + context "when the snippet is public" do + it "rejects the shippet" do + expect { create_snippet(visibility: "public") } .not_to change { Snippet.count } expect(response).to have_gitlab_http_status(400) - expect(json_response['message']).to eq({ "error" => "Spam detected" }) + expect(json_response["message"]).to eq({"error" => "Spam detected"}) end - it 'creates a spam log' do - expect { create_snippet(visibility: 'public') } + it "creates a spam log" do + expect { create_snippet(visibility: "public") } .to change { SpamLog.count }.by(1) end end end end - describe 'PUT /snippets/:id' do + describe "PUT /snippets/:id" do let(:visibility_level) { Snippet::PUBLIC } let(:other_user) { create(:user) } let(:snippet) do create(:personal_snippet, author: user, visibility_level: visibility_level) end - it 'updates snippet' do - new_content = 'New content' - new_description = 'New description' + it "updates snippet" do + new_content = "New content" + new_description = "New description" - put api("/snippets/#{snippet.id}", user), params: { content: new_content, description: new_description } + put api("/snippets/#{snippet.id}", user), params: {content: new_content, description: new_description} expect(response).to have_gitlab_http_status(200) snippet.reload @@ -213,27 +217,27 @@ describe API::Snippets do expect(snippet.description).to eq(new_description) end - it 'returns 404 for invalid snippet id' do - put api("/snippets/1234", user), params: { title: 'foo' } + it "returns 404 for invalid snippet id" do + put api("/snippets/1234", user), params: {title: "foo"} expect(response).to have_gitlab_http_status(404) - expect(json_response['message']).to eq('404 Snippet Not Found') + expect(json_response["message"]).to eq("404 Snippet Not Found") end it "returns 404 for another user's snippet" do - put api("/snippets/#{snippet.id}", other_user), params: { title: 'fubar' } + put api("/snippets/#{snippet.id}", other_user), params: {title: "fubar"} expect(response).to have_gitlab_http_status(404) - expect(json_response['message']).to eq('404 Snippet Not Found') + expect(json_response["message"]).to eq("404 Snippet Not Found") end - it 'returns 400 for missing parameters' do + it "returns 400 for missing parameters" do put api("/snippets/1234", user) expect(response).to have_gitlab_http_status(400) end - context 'when the snippet is spam' do + context "when the snippet is spam" do def update_snippet(snippet_params = {}) put api("/snippets/#{snippet.id}", user), params: snippet_params end @@ -242,66 +246,66 @@ describe API::Snippets do allow_any_instance_of(AkismetService).to receive(:spam?).and_return(true) end - context 'when the snippet is private' do + context "when the snippet is private" do let(:visibility_level) { Snippet::PRIVATE } - it 'updates the snippet' do - expect { update_snippet(title: 'Foo') } - .to change { snippet.reload.title }.to('Foo') + it "updates the snippet" do + expect { update_snippet(title: "Foo") } + .to change { snippet.reload.title }.to("Foo") end end - context 'when the snippet is public' do + context "when the snippet is public" do let(:visibility_level) { Snippet::PUBLIC } - it 'rejects the shippet' do - expect { update_snippet(title: 'Foo') } + it "rejects the shippet" do + expect { update_snippet(title: "Foo") } .not_to change { snippet.reload.title } expect(response).to have_gitlab_http_status(400) - expect(json_response['message']).to eq({ "error" => "Spam detected" }) + expect(json_response["message"]).to eq({"error" => "Spam detected"}) end - it 'creates a spam log' do - expect { update_snippet(title: 'Foo') } + it "creates a spam log" do + expect { update_snippet(title: "Foo") } .to change { SpamLog.count }.by(1) end end - context 'when a private snippet is made public' do + context "when a private snippet is made public" do let(:visibility_level) { Snippet::PRIVATE } - it 'rejects the snippet' do - expect { update_snippet(title: 'Foo', visibility: 'public') } + it "rejects the snippet" do + expect { update_snippet(title: "Foo", visibility: "public") } .not_to change { snippet.reload.title } end - it 'creates a spam log' do - expect { update_snippet(title: 'Foo', visibility: 'public') } + it "creates a spam log" do + expect { update_snippet(title: "Foo", visibility: "public") } .to change { SpamLog.count }.by(1) end end end end - describe 'DELETE /snippets/:id' do + describe "DELETE /snippets/:id" do let!(:public_snippet) { create(:personal_snippet, :public, author: user) } - it 'deletes snippet' do - expect do + it "deletes snippet" do + expect { delete api("/snippets/#{public_snippet.id}", user) expect(response).to have_gitlab_http_status(204) - end.to change { PersonalSnippet.count }.by(-1) + }.to change { PersonalSnippet.count }.by(-1) end - it 'returns 404 for invalid snippet id' do + it "returns 404 for invalid snippet id" do delete api("/snippets/1234", user) expect(response).to have_gitlab_http_status(404) - expect(json_response['message']).to eq('404 Snippet Not Found') + expect(json_response["message"]).to eq("404 Snippet Not Found") end - it_behaves_like '412 response' do + it_behaves_like "412 response" do let(:request) { api("/snippets/#{public_snippet.id}", user) } end end @@ -311,13 +315,13 @@ describe API::Snippets do let(:snippet) { create(:personal_snippet, :public, author: user) } let!(:user_agent_detail) { create(:user_agent_detail, subject: snippet) } - it 'exposes known attributes' do + it "exposes known attributes" do get api("/snippets/#{snippet.id}/user_agent_detail", admin) expect(response).to have_gitlab_http_status(200) - expect(json_response['user_agent']).to eq(user_agent_detail.user_agent) - expect(json_response['ip_address']).to eq(user_agent_detail.ip_address) - expect(json_response['akismet_submitted']).to eq(user_agent_detail.submitted) + expect(json_response["user_agent"]).to eq(user_agent_detail.user_agent) + expect(json_response["ip_address"]).to eq(user_agent_detail.ip_address) + expect(json_response["akismet_submitted"]).to eq(user_agent_detail.submitted) end it "returns unauthorized for non-admin users" do diff --git a/spec/requests/api/submodules_spec.rb b/spec/requests/api/submodules_spec.rb index 064392fb185..c0c77888509 100644 --- a/spec/requests/api/submodules_spec.rb +++ b/spec/requests/api/submodules_spec.rb @@ -1,22 +1,22 @@ # frozen_string_literal: true -require 'spec_helper' +require "spec_helper" describe API::Submodules do let(:user) { create(:user) } - let!(:project) { create(:project, :repository, namespace: user.namespace ) } + let!(:project) { create(:project, :repository, namespace: user.namespace) } let(:guest) { create(:user) { |u| project.add_guest(u) } } - let(:submodule) { 'six' } - let(:commit_sha) { 'e25eda1fece24ac7a03624ed1320f82396f35bd8' } - let(:branch) { 'master' } - let(:commit_message) { 'whatever' } + let(:submodule) { "six" } + let(:commit_sha) { "e25eda1fece24ac7a03624ed1320f82396f35bd8" } + let(:branch) { "master" } + let(:commit_message) { "whatever" } let(:params) do { submodule: submodule, commit_sha: commit_sha, branch: branch, - commit_message: commit_message + commit_message: commit_message, } end @@ -29,68 +29,68 @@ describe API::Submodules do end describe "PUT /projects/:id/repository/submodule/:submodule" do - context 'when unauthenticated' do - it 'returns 401' do + context "when unauthenticated" do + it "returns 401" do put api(route(submodule)), params: params expect(response).to have_gitlab_http_status(401) end end - context 'when authenticated', 'as a guest' do - it 'returns 403' do + context "when authenticated", "as a guest" do + it "returns 403" do put api(route(submodule), guest), params: params expect(response).to have_gitlab_http_status(403) end end - context 'when authenticated', 'as a developer' do - it 'returns 400 if params is missing' do + context "when authenticated", "as a developer" do + it "returns 400 if params is missing" do put api(route(submodule), user) expect(response).to have_gitlab_http_status(400) end - it 'returns 400 if branch is missing' do + it "returns 400 if branch is missing" do put api(route(submodule), user), params: params.except(:branch) expect(response).to have_gitlab_http_status(400) end - it 'returns 400 if commit_sha is missing' do + it "returns 400 if commit_sha is missing" do put api(route(submodule), user), params: params.except(:commit_sha) expect(response).to have_gitlab_http_status(400) end - it 'returns the commit' do + it "returns the commit" do head_commit = project.repository.commit.id put api(route(submodule), user), params: params expect(response).to have_gitlab_http_status(200) - expect(json_response['message']).to eq commit_message - expect(json_response['author_name']).to eq user.name - expect(json_response['committer_name']).to eq user.name - expect(json_response['parent_ids'].first).to eq head_commit + expect(json_response["message"]).to eq commit_message + expect(json_response["author_name"]).to eq user.name + expect(json_response["committer_name"]).to eq user.name + expect(json_response["parent_ids"].first).to eq head_commit end - context 'when the submodule name is urlencoded' do - let(:submodule) { 'test_inside_folder/another_folder/six' } - let(:branch) { 'submodule_inside_folder' } + context "when the submodule name is urlencoded" do + let(:submodule) { "test_inside_folder/another_folder/six" } + let(:branch) { "submodule_inside_folder" } let(:encoded_submodule) { CGI.escape(submodule) } - it 'returns the commit' do + it "returns the commit" do expect(Submodules::UpdateService) .to receive(:new) - .with(any_args, hash_including(submodule: submodule)) - .and_call_original + .with(any_args, hash_including(submodule: submodule)) + .and_call_original put api(route(encoded_submodule), user), params: params expect(response).to have_gitlab_http_status(200) - expect(json_response['id']).to eq project.repository.commit(branch).id + expect(json_response["id"]).to eq project.repository.commit(branch).id expect(project.repository.blob_at(branch, submodule).id).to eq commit_sha end end diff --git a/spec/requests/api/suggestions_spec.rb b/spec/requests/api/suggestions_spec.rb index 3c2842e5725..b0def1ee6d4 100644 --- a/spec/requests/api/suggestions_spec.rb +++ b/spec/requests/api/suggestions_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'spec_helper' +require "spec_helper" describe API::Suggestions do let(:project) { create(:project, :repository) } @@ -28,55 +28,55 @@ describe API::Suggestions do describe "PUT /suggestions/:id/apply" do let(:url) { "/suggestions/#{suggestion.id}/apply" } - context 'when successfully applies patch' do + context "when successfully applies patch" do let(:suggestion) do create(:suggestion, note: diff_note, from_content: " raise RuntimeError, \"System commands must be given as an array of strings\"\n", to_content: " raise RuntimeError, 'Explosion'\n # explosion?") end - it 'returns 200 with json content' do + it "returns 200 with json content" do project.add_maintainer(user) - put api(url, user), params: { id: suggestion.id } + put api(url, user), params: {id: suggestion.id} expect(response).to have_gitlab_http_status(200) expect(json_response) - .to include('id', 'from_original_line', 'to_original_line', - 'from_line', 'to_line', 'appliable', 'applied', - 'from_content', 'to_content') + .to include("id", "from_original_line", "to_original_line", + "from_line", "to_line", "appliable", "applied", + "from_content", "to_content") end end - context 'when not able to apply patch' do + context "when not able to apply patch" do let(:suggestion) do create(:suggestion, :unappliable, note: diff_note) end - it 'returns 400 with json content' do + it "returns 400 with json content" do project.add_maintainer(user) - put api(url, user), params: { id: suggestion.id } + put api(url, user), params: {id: suggestion.id} expect(response).to have_gitlab_http_status(400) - expect(json_response).to eq({ 'message' => 'Suggestion is not appliable' }) + expect(json_response).to eq({"message" => "Suggestion is not appliable"}) end end - context 'when unauthorized' do + context "when unauthorized" do let(:suggestion) do create(:suggestion, note: diff_note, from_content: " raise RuntimeError, \"System commands must be given as an array of strings\"\n", to_content: " raise RuntimeError, 'Explosion'\n # explosion?") end - it 'returns 403 with json content' do + it "returns 403 with json content" do project.add_reporter(user) - put api(url, user), params: { id: suggestion.id } + put api(url, user), params: {id: suggestion.id} expect(response).to have_gitlab_http_status(403) - expect(json_response).to eq({ 'message' => '403 Forbidden' }) + expect(json_response).to eq({"message" => "403 Forbidden"}) end end end diff --git a/spec/requests/api/system_hooks_spec.rb b/spec/requests/api/system_hooks_spec.rb index b6e8d74c2e9..7fca7a8be8a 100644 --- a/spec/requests/api/system_hooks_spec.rb +++ b/spec/requests/api/system_hooks_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe API::SystemHooks do let(:user) { create(:user) } @@ -33,20 +33,20 @@ describe API::SystemHooks do expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response).to be_an Array - expect(json_response.first['url']).to eq(hook.url) - expect(json_response.first['push_events']).to be false - expect(json_response.first['tag_push_events']).to be false - expect(json_response.first['merge_requests_events']).to be false - expect(json_response.first['repository_update_events']).to be true + expect(json_response.first["url"]).to eq(hook.url) + expect(json_response.first["push_events"]).to be false + expect(json_response.first["tag_push_events"]).to be false + expect(json_response.first["merge_requests_events"]).to be false + expect(json_response.first["repository_update_events"]).to be true end end end describe "POST /hooks" do it "creates new hook" do - expect do - post api("/hooks", admin), params: { url: 'http://example.com' } - end.to change { SystemHook.count }.by(1) + expect { + post api("/hooks", admin), params: {url: "http://example.com"} + }.to change { SystemHook.count }.by(1) end it "responds with 400 if url not given" do @@ -56,42 +56,42 @@ describe API::SystemHooks do end it "responds with 400 if url is invalid" do - post api("/hooks", admin), params: { url: 'hp://mep.mep' } + post api("/hooks", admin), params: {url: "hp://mep.mep"} expect(response).to have_gitlab_http_status(400) end it "does not create new hook without url" do - expect do + expect { post api("/hooks", admin) - end.not_to change { SystemHook.count } + }.not_to change { SystemHook.count } end - it 'sets default values for events' do - post api('/hooks', admin), params: { url: 'http://mep.mep' } + it "sets default values for events" do + post api("/hooks", admin), params: {url: "http://mep.mep"} expect(response).to have_gitlab_http_status(201) - expect(json_response['enable_ssl_verification']).to be true - expect(json_response['push_events']).to be false - expect(json_response['tag_push_events']).to be false - expect(json_response['merge_requests_events']).to be false + expect(json_response["enable_ssl_verification"]).to be true + expect(json_response["push_events"]).to be false + expect(json_response["tag_push_events"]).to be false + expect(json_response["merge_requests_events"]).to be false end - it 'sets explicit values for events' do - post api('/hooks', admin), + it "sets explicit values for events" do + post api("/hooks", admin), params: { - url: 'http://mep.mep', + url: "http://mep.mep", enable_ssl_verification: false, push_events: true, tag_push_events: true, - merge_requests_events: true + merge_requests_events: true, } expect(response).to have_http_status(201) - expect(json_response['enable_ssl_verification']).to be false - expect(json_response['push_events']).to be true - expect(json_response['tag_push_events']).to be true - expect(json_response['merge_requests_events']).to be true + expect(json_response["enable_ssl_verification"]).to be false + expect(json_response["push_events"]).to be true + expect(json_response["tag_push_events"]).to be true + expect(json_response["merge_requests_events"]).to be true end end @@ -99,7 +99,7 @@ describe API::SystemHooks do it "returns hook by id" do get api("/hooks/#{hook.id}", admin) expect(response).to have_gitlab_http_status(200) - expect(json_response['event_name']).to eq('project_create') + expect(json_response["event_name"]).to eq("project_create") end it "returns 404 on failure" do @@ -110,20 +110,20 @@ describe API::SystemHooks do describe "DELETE /hooks/:id" do it "deletes a hook" do - expect do + expect { delete api("/hooks/#{hook.id}", admin) expect(response).to have_gitlab_http_status(204) - end.to change { SystemHook.count }.by(-1) + }.to change { SystemHook.count }.by(-1) end - it 'returns 404 if the system hook does not exist' do - delete api('/hooks/12345', admin) + it "returns 404 if the system hook does not exist" do + delete api("/hooks/12345", admin) expect(response).to have_gitlab_http_status(404) end - it_behaves_like '412 response' do + it_behaves_like "412 response" do let(:request) { api("/hooks/#{hook.id}", admin) } end end diff --git a/spec/requests/api/tags_spec.rb b/spec/requests/api/tags_spec.rb index fffe878ddbd..47cea7eb0a9 100644 --- a/spec/requests/api/tags_spec.rb +++ b/spec/requests/api/tags_spec.rb @@ -1,10 +1,10 @@ -require 'spec_helper' +require "spec_helper" describe API::Tags do let(:user) { create(:user) } let(:guest) { create(:user).tap { |u| project.add_guest(u) } } - let(:project) { create(:project, :repository, creator: user, path: 'my.project') } - let(:tag_name) { project.repository.find_tag('v1.1.0').name } + let(:project) { create(:project, :repository, creator: user, path: "my.project") } + let(:tag_name) { project.repository.find_tag("v1.1.0").name } let(:project_id) { project.id } let(:current_user) { nil } @@ -13,475 +13,475 @@ describe API::Tags do project.add_maintainer(user) end - describe 'GET /projects/:id/repository/tags' do + describe "GET /projects/:id/repository/tags" do let(:route) { "/projects/#{project_id}/repository/tags" } - context 'sorting' do + context "sorting" do let(:current_user) { user } - it 'sorts by descending order by default' do + it "sorts by descending order by default" do get api(route, current_user) desc_order_tags = project.repository.tags.sort_by { |tag| tag.dereferenced_target.committed_date } desc_order_tags.reverse!.map! { |tag| tag.dereferenced_target.id } - expect(json_response.map { |tag| tag['commit']['id'] }).to eq(desc_order_tags) + expect(json_response.map { |tag| tag["commit"]["id"] }).to eq(desc_order_tags) end - it 'sorts by ascending order if specified' do + it "sorts by ascending order if specified" do get api("#{route}?sort=asc", current_user) asc_order_tags = project.repository.tags.sort_by { |tag| tag.dereferenced_target.committed_date } asc_order_tags.map! { |tag| tag.dereferenced_target.id } - expect(json_response.map { |tag| tag['commit']['id'] }).to eq(asc_order_tags) + expect(json_response.map { |tag| tag["commit"]["id"] }).to eq(asc_order_tags) end - it 'sorts by name in descending order when requested' do + it "sorts by name in descending order when requested" do get api("#{route}?order_by=name", current_user) ordered_by_name = project.repository.tags.map { |tag| tag.name }.sort.reverse - expect(json_response.map { |tag| tag['name'] }).to eq(ordered_by_name) + expect(json_response.map { |tag| tag["name"] }).to eq(ordered_by_name) end - it 'sorts by name in ascending order when requested' do + it "sorts by name in ascending order when requested" do get api("#{route}?order_by=name&sort=asc", current_user) ordered_by_name = project.repository.tags.map { |tag| tag.name }.sort - expect(json_response.map { |tag| tag['name'] }).to eq(ordered_by_name) + expect(json_response.map { |tag| tag["name"] }).to eq(ordered_by_name) end end - context 'searching' do - it 'only returns searched tags' do - get api("#{route}", user), params: { search: 'v1.1.0' } + context "searching" do + it "only returns searched tags" do + get api(route.to_s, user), params: {search: "v1.1.0"} expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response).to be_an Array expect(json_response.size).to eq(1) - expect(json_response[0]['name']).to eq('v1.1.0') + expect(json_response[0]["name"]).to eq("v1.1.0") end end - shared_examples_for 'repository tags' do - it 'returns the repository tags' do + shared_examples_for "repository tags" do + it "returns the repository tags" do get api(route, current_user) expect(response).to have_gitlab_http_status(200) - expect(response).to match_response_schema('public_api/v4/tags') + expect(response).to match_response_schema("public_api/v4/tags") expect(response).to include_pagination_headers - expect(json_response.first['name']).to eq(tag_name) + expect(json_response.first["name"]).to eq(tag_name) end - context 'when repository is disabled' do - include_context 'disabled repository' + context "when repository is disabled" do + include_context "disabled repository" - it_behaves_like '403 response' do + it_behaves_like "403 response" do let(:request) { get api(route, current_user) } end end end - context 'when unauthenticated', 'and project is public' do + context "when unauthenticated", "and project is public" do let(:project) { create(:project, :public, :repository) } - it_behaves_like 'repository tags' + it_behaves_like "repository tags" end - context 'when unauthenticated', 'and project is private' do - it_behaves_like '404 response' do + context "when unauthenticated", "and project is private" do + it_behaves_like "404 response" do let(:request) { get api(route) } - let(:message) { '404 Project Not Found' } + let(:message) { "404 Project Not Found" } end end - context 'when authenticated', 'as a maintainer' do + context "when authenticated", "as a maintainer" do let(:current_user) { user } - it_behaves_like 'repository tags' + it_behaves_like "repository tags" - context 'requesting with the escaped project full path' do + context "requesting with the escaped project full path" do let(:project_id) { CGI.escape(project.full_path) } - it_behaves_like 'repository tags' + it_behaves_like "repository tags" end end - context 'when authenticated', 'as a guest' do - it_behaves_like '403 response' do + context "when authenticated", "as a guest" do + it_behaves_like "403 response" do let(:request) { get api(route, guest) } end end - context 'with releases' do - let(:description) { 'Awesome release!' } + context "with releases" do + let(:description) { "Awesome release!" } let!(:release) do create(:release, - :legacy, - project: project, - tag: tag_name, - description: description) + :legacy, + project: project, + tag: tag_name, + description: description) end - it 'returns an array of project tags with release info' do + it "returns an array of project tags with release info" do get api(route, user) expect(response).to have_gitlab_http_status(200) - expect(response).to match_response_schema('public_api/v4/tags') + expect(response).to match_response_schema("public_api/v4/tags") expect(response).to include_pagination_headers - expect(json_response.first['name']).to eq(tag_name) - expect(json_response.first['message']).to eq('Version 1.1.0') - expect(json_response.first['release']['description']).to eq(description) + expect(json_response.first["name"]).to eq(tag_name) + expect(json_response.first["message"]).to eq("Version 1.1.0") + expect(json_response.first["release"]["description"]).to eq(description) end end end - describe 'GET /projects/:id/repository/tags/:tag_name' do + describe "GET /projects/:id/repository/tags/:tag_name" do let(:route) { "/projects/#{project_id}/repository/tags/#{tag_name}" } - shared_examples_for 'repository tag' do - it 'returns the repository branch' do + shared_examples_for "repository tag" do + it "returns the repository branch" do get api(route, current_user) expect(response).to have_gitlab_http_status(200) - expect(response).to match_response_schema('public_api/v4/tag') - expect(json_response['name']).to eq(tag_name) + expect(response).to match_response_schema("public_api/v4/tag") + expect(json_response["name"]).to eq(tag_name) end - context 'when tag does not exist' do - let(:tag_name) { 'unknown' } + context "when tag does not exist" do + let(:tag_name) { "unknown" } - it_behaves_like '404 response' do + it_behaves_like "404 response" do let(:request) { get api(route, current_user) } - let(:message) { '404 Tag Not Found' } + let(:message) { "404 Tag Not Found" } end end - context 'when repository is disabled' do - include_context 'disabled repository' + context "when repository is disabled" do + include_context "disabled repository" - it_behaves_like '403 response' do + it_behaves_like "403 response" do let(:request) { get api(route, current_user) } end end end - context 'when unauthenticated', 'and project is public' do + context "when unauthenticated", "and project is public" do let(:project) { create(:project, :public, :repository) } - it_behaves_like 'repository tag' + it_behaves_like "repository tag" end - context 'when unauthenticated', 'and project is private' do - it_behaves_like '404 response' do + context "when unauthenticated", "and project is private" do + it_behaves_like "404 response" do let(:request) { get api(route) } - let(:message) { '404 Project Not Found' } + let(:message) { "404 Project Not Found" } end end - context 'when authenticated', 'as a maintainer' do + context "when authenticated", "as a maintainer" do let(:current_user) { user } - it_behaves_like 'repository tag' + it_behaves_like "repository tag" - context 'requesting with the escaped project full path' do + context "requesting with the escaped project full path" do let(:project_id) { CGI.escape(project.full_path) } - it_behaves_like 'repository tag' + it_behaves_like "repository tag" end end - context 'when authenticated', 'as a guest' do - it_behaves_like '403 response' do + context "when authenticated", "as a guest" do + it_behaves_like "403 response" do let(:request) { get api(route, guest) } end end end - describe 'POST /projects/:id/repository/tags' do - let(:tag_name) { 'new_tag' } + describe "POST /projects/:id/repository/tags" do + let(:tag_name) { "new_tag" } let(:route) { "/projects/#{project_id}/repository/tags" } - shared_examples_for 'repository new tag' do - it 'creates a new tag' do - post api(route, current_user), params: { tag_name: tag_name, ref: 'master' } + shared_examples_for "repository new tag" do + it "creates a new tag" do + post api(route, current_user), params: {tag_name: tag_name, ref: "master"} expect(response).to have_gitlab_http_status(201) - expect(response).to match_response_schema('public_api/v4/tag') - expect(json_response['name']).to eq(tag_name) + expect(response).to match_response_schema("public_api/v4/tag") + expect(json_response["name"]).to eq(tag_name) end - context 'when repository is disabled' do - include_context 'disabled repository' + context "when repository is disabled" do + include_context "disabled repository" - it_behaves_like '403 response' do + it_behaves_like "403 response" do let(:request) { post api(route, current_user) } end end end - context 'when unauthenticated', 'and project is private' do - it_behaves_like '404 response' do + context "when unauthenticated", "and project is private" do + it_behaves_like "404 response" do let(:request) { post api(route) } - let(:message) { '404 Project Not Found' } + let(:message) { "404 Project Not Found" } end end - context 'when authenticated', 'as a guest' do - it_behaves_like '403 response' do + context "when authenticated", "as a guest" do + it_behaves_like "403 response" do let(:request) { post api(route, guest) } end end - context 'when authenticated', 'as a maintainer' do + context "when authenticated", "as a maintainer" do let(:current_user) { user } context "when a protected branch doesn't already exist" do - it_behaves_like 'repository new tag' + it_behaves_like "repository new tag" - context 'when tag contains a dot' do - let(:tag_name) { 'v7.0.1' } + context "when tag contains a dot" do + let(:tag_name) { "v7.0.1" } - it_behaves_like 'repository new tag' + it_behaves_like "repository new tag" end - context 'requesting with the escaped project full path' do + context "requesting with the escaped project full path" do let(:project_id) { CGI.escape(project.full_path) } - it_behaves_like 'repository new tag' + it_behaves_like "repository new tag" - context 'when tag contains a dot' do - let(:tag_name) { 'v7.0.1' } + context "when tag contains a dot" do + let(:tag_name) { "v7.0.1" } - it_behaves_like 'repository new tag' + it_behaves_like "repository new tag" end end end - it 'returns 400 if tag name is invalid' do - post api(route, current_user), params: { tag_name: 'new design', ref: 'master' } + it "returns 400 if tag name is invalid" do + post api(route, current_user), params: {tag_name: "new design", ref: "master"} expect(response).to have_gitlab_http_status(400) - expect(json_response['message']).to eq('Tag name invalid') + expect(json_response["message"]).to eq("Tag name invalid") end - it 'returns 400 if tag already exists' do - post api(route, current_user), params: { tag_name: 'new_design1', ref: 'master' } + it "returns 400 if tag already exists" do + post api(route, current_user), params: {tag_name: "new_design1", ref: "master"} expect(response).to have_gitlab_http_status(201) - expect(response).to match_response_schema('public_api/v4/tag') + expect(response).to match_response_schema("public_api/v4/tag") - post api(route, current_user), params: { tag_name: 'new_design1', ref: 'master' } + post api(route, current_user), params: {tag_name: "new_design1", ref: "master"} expect(response).to have_gitlab_http_status(400) - expect(json_response['message']).to eq('Tag new_design1 already exists') + expect(json_response["message"]).to eq("Tag new_design1 already exists") end - it 'returns 400 if ref name is invalid' do - post api(route, current_user), params: { tag_name: 'new_design3', ref: 'foo' } + it "returns 400 if ref name is invalid" do + post api(route, current_user), params: {tag_name: "new_design3", ref: "foo"} expect(response).to have_gitlab_http_status(400) - expect(json_response['message']).to eq('Target foo is invalid') + expect(json_response["message"]).to eq("Target foo is invalid") end - context 'lightweight tags with release notes' do - it 'creates a new tag' do - post api(route, current_user), params: { tag_name: tag_name, ref: 'master', release_description: 'Wow' } + context "lightweight tags with release notes" do + it "creates a new tag" do + post api(route, current_user), params: {tag_name: tag_name, ref: "master", release_description: "Wow"} expect(response).to have_gitlab_http_status(201) - expect(response).to match_response_schema('public_api/v4/tag') - expect(json_response['name']).to eq(tag_name) - expect(json_response['release']['description']).to eq('Wow') + expect(response).to match_response_schema("public_api/v4/tag") + expect(json_response["name"]).to eq(tag_name) + expect(json_response["release"]["description"]).to eq("Wow") end end - context 'annotated tag' do - it 'creates a new annotated tag' do + context "annotated tag" do + it "creates a new annotated tag" do # Identity must be set in .gitconfig to create annotated tag. - repo_path = Gitlab::GitalyClient::StorageSettings.allow_disk_access do + repo_path = Gitlab::GitalyClient::StorageSettings.allow_disk_access { project.repository.path_to_repo - end + } - system(*%W(#{Gitlab.config.git.bin_path} --git-dir=#{repo_path} config user.name #{user.name})) - system(*%W(#{Gitlab.config.git.bin_path} --git-dir=#{repo_path} config user.email #{user.email})) + system(Gitlab.config.git.bin_path.to_s, "--git-dir=#{repo_path}", "config", "user.name", user.name.to_s) + system(Gitlab.config.git.bin_path.to_s, "--git-dir=#{repo_path}", "config", "user.email", user.email.to_s) - post api(route, current_user), params: { tag_name: 'v7.1.0', ref: 'master', message: 'Release 7.1.0' } + post api(route, current_user), params: {tag_name: "v7.1.0", ref: "master", message: "Release 7.1.0"} expect(response).to have_gitlab_http_status(201) - expect(response).to match_response_schema('public_api/v4/tag') - expect(json_response['name']).to eq('v7.1.0') - expect(json_response['message']).to eq('Release 7.1.0') + expect(response).to match_response_schema("public_api/v4/tag") + expect(json_response["name"]).to eq("v7.1.0") + expect(json_response["message"]).to eq("Release 7.1.0") end end end end - describe 'DELETE /projects/:id/repository/tags/:tag_name' do + describe "DELETE /projects/:id/repository/tags/:tag_name" do let(:route) { "/projects/#{project_id}/repository/tags/#{tag_name}" } before do allow_any_instance_of(Repository).to receive(:rm_tag).and_return(true) end - shared_examples_for 'repository delete tag' do - it 'deletes a tag' do + shared_examples_for "repository delete tag" do + it "deletes a tag" do delete api(route, current_user) expect(response).to have_gitlab_http_status(204) end - it_behaves_like '412 response' do + it_behaves_like "412 response" do let(:request) { api(route, current_user) } end - context 'when tag does not exist' do - let(:tag_name) { 'unknown' } + context "when tag does not exist" do + let(:tag_name) { "unknown" } - it_behaves_like '404 response' do + it_behaves_like "404 response" do let(:request) { delete api(route, current_user) } - let(:message) { '404 Tag Not Found' } + let(:message) { "404 Tag Not Found" } end end - context 'when repository is disabled' do - include_context 'disabled repository' + context "when repository is disabled" do + include_context "disabled repository" - it_behaves_like '403 response' do + it_behaves_like "403 response" do let(:request) { delete api(route, current_user) } end end end - context 'when authenticated', 'as a maintainer' do + context "when authenticated", "as a maintainer" do let(:current_user) { user } - it_behaves_like 'repository delete tag' + it_behaves_like "repository delete tag" - context 'requesting with the escaped project full path' do + context "requesting with the escaped project full path" do let(:project_id) { CGI.escape(project.full_path) } - it_behaves_like 'repository delete tag' + it_behaves_like "repository delete tag" end end end - describe 'POST /projects/:id/repository/tags/:tag_name/release' do + describe "POST /projects/:id/repository/tags/:tag_name/release" do let(:route) { "/projects/#{project_id}/repository/tags/#{tag_name}/release" } - let(:description) { 'Awesome release!' } + let(:description) { "Awesome release!" } - shared_examples_for 'repository new release' do - it 'creates description for existing git tag' do - post api(route, user), params: { description: description } + shared_examples_for "repository new release" do + it "creates description for existing git tag" do + post api(route, user), params: {description: description} expect(response).to have_gitlab_http_status(201) - expect(response).to match_response_schema('public_api/v4/release') - expect(json_response['tag_name']).to eq(tag_name) - expect(json_response['description']).to eq(description) + expect(response).to match_response_schema("public_api/v4/release") + expect(json_response["tag_name"]).to eq(tag_name) + expect(json_response["description"]).to eq(description) end - context 'when tag does not exist' do - let(:tag_name) { 'unknown' } + context "when tag does not exist" do + let(:tag_name) { "unknown" } - it_behaves_like '404 response' do - let(:request) { post api(route, current_user), params: { description: description } } - let(:message) { '404 Tag Not Found' } + it_behaves_like "404 response" do + let(:request) { post api(route, current_user), params: {description: description} } + let(:message) { "404 Tag Not Found" } end end - context 'when repository is disabled' do - include_context 'disabled repository' + context "when repository is disabled" do + include_context "disabled repository" - it_behaves_like '403 response' do - let(:request) { post api(route, current_user), params: { description: description } } + it_behaves_like "403 response" do + let(:request) { post api(route, current_user), params: {description: description} } end end end - context 'when authenticated', 'as a maintainer' do + context "when authenticated", "as a maintainer" do let(:current_user) { user } - it_behaves_like 'repository new release' + it_behaves_like "repository new release" - context 'requesting with the escaped project full path' do + context "requesting with the escaped project full path" do let(:project_id) { CGI.escape(project.full_path) } - it_behaves_like 'repository new release' + it_behaves_like "repository new release" end - context 'on tag with existing release' do + context "on tag with existing release" do let!(:release) { create(:release, :legacy, project: project, tag: tag_name, description: description) } - it 'returns 409 if there is already a release' do - post api(route, user), params: { description: description } + it "returns 409 if there is already a release" do + post api(route, user), params: {description: description} expect(response).to have_gitlab_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 - describe 'PUT id/repository/tags/:tag_name/release' do + describe "PUT id/repository/tags/:tag_name/release" do let(:route) { "/projects/#{project_id}/repository/tags/#{tag_name}/release" } - let(:description) { 'Awesome release!' } - let(:new_description) { 'The best release!' } + let(:description) { "Awesome release!" } + let(:new_description) { "The best release!" } - shared_examples_for 'repository update release' do - context 'on tag with existing release' do + shared_examples_for "repository update release" do + context "on tag with existing release" do let!(:release) do create(:release, - :legacy, - project: project, - tag: tag_name, - description: description) + :legacy, + project: project, + tag: tag_name, + description: description) end - it 'updates the release description' do - put api(route, current_user), params: { description: new_description } + it "updates the release description" do + put api(route, current_user), params: {description: new_description} expect(response).to have_gitlab_http_status(200) - expect(json_response['tag_name']).to eq(tag_name) - expect(json_response['description']).to eq(new_description) + expect(json_response["tag_name"]).to eq(tag_name) + expect(json_response["description"]).to eq(new_description) end end - context 'when tag does not exist' do - let(:tag_name) { 'unknown' } + context "when tag does not exist" do + let(:tag_name) { "unknown" } - it_behaves_like '403 response' do - let(:request) { put api(route, current_user), params: { description: new_description } } - let(:message) { '403 Forbidden' } + it_behaves_like "403 response" do + let(:request) { put api(route, current_user), params: {description: new_description} } + let(:message) { "403 Forbidden" } end end - context 'when repository is disabled' do - include_context 'disabled repository' + context "when repository is disabled" do + include_context "disabled repository" - it_behaves_like '403 response' do - let(:request) { put api(route, current_user), params: { description: new_description } } + it_behaves_like "403 response" do + let(:request) { put api(route, current_user), params: {description: new_description} } end end end - context 'when authenticated', 'as a maintainer' do + context "when authenticated", "as a maintainer" do let(:current_user) { user } - it_behaves_like 'repository update release' + it_behaves_like "repository update release" - context 'requesting with the escaped project full path' do + context "requesting with the escaped project full path" do let(:project_id) { CGI.escape(project.full_path) } - it_behaves_like 'repository update release' + it_behaves_like "repository update release" end - context 'when release does not exist' do - it_behaves_like '403 response' do - let(:request) { put api(route, current_user), params: { description: new_description } } - let(:message) { '403 Forbidden' } + context "when release does not exist" do + it_behaves_like "403 response" do + let(:request) { put api(route, current_user), params: {description: new_description} } + let(:message) { "403 Forbidden" } end end end diff --git a/spec/requests/api/templates_spec.rb b/spec/requests/api/templates_spec.rb index d1e16ab9ca9..3ac7018d860 100644 --- a/spec/requests/api/templates_spec.rb +++ b/spec/requests/api/templates_spec.rb @@ -1,27 +1,27 @@ -require 'spec_helper' +require "spec_helper" describe API::Templates do - context 'the Template Entity' do + context "the Template Entity" do before do - get api('/templates/gitignores/Ruby') + get api("/templates/gitignores/Ruby") end - it { expect(json_response['name']).to eq('Ruby') } - it { expect(json_response['content']).to include('*.gem') } + it { expect(json_response["name"]).to eq("Ruby") } + it { expect(json_response["content"]).to include("*.gem") } end - context 'the TemplateList Entity' do + context "the TemplateList Entity" do before do - get api('/templates/gitignores') + get api("/templates/gitignores") end - it { expect(json_response.first['name']).not_to be_nil } - it { expect(json_response.first['content']).to be_nil } + it { expect(json_response.first["name"]).not_to be_nil } + it { expect(json_response.first["content"]).to be_nil } end - context 'requesting gitignores' do - it 'returns a list of available gitignore templates' do - get api('/templates/gitignores') + context "requesting gitignores" do + it "returns a list of available gitignore templates" do + get api("/templates/gitignores") expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers @@ -30,161 +30,161 @@ describe API::Templates do end end - context 'requesting gitlab-ci-ymls' do - it 'returns a list of available gitlab_ci_ymls' do - get api('/templates/gitlab_ci_ymls') + context "requesting gitlab-ci-ymls" do + it "returns a list of available gitlab_ci_ymls" do + get api("/templates/gitlab_ci_ymls") expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers 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 - context 'requesting gitlab-ci-yml for Ruby' do - it 'adds a disclaimer on the top' do - get api('/templates/gitlab_ci_ymls/Ruby') + context "requesting gitlab-ci-yml for Ruby" do + it "adds a disclaimer on the top" do + get api("/templates/gitlab_ci_ymls/Ruby") expect(response).to have_gitlab_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 - context 'the License Template Entity' do + context "the License Template Entity" do before do - get api('/templates/licenses/mit') + get api("/templates/licenses/mit") end - it 'returns a license template' do + it "returns a license template" do expect(response).to have_gitlab_http_status(200) - expect(json_response['key']).to eq('mit') - expect(json_response['name']).to eq('MIT License') - expect(json_response['nickname']).to be_nil - expect(json_response['popular']).to be true - expect(json_response['html_url']).to eq('http://choosealicense.com/licenses/mit/') - expect(json_response['source_url']).to eq('https://opensource.org/licenses/MIT') - expect(json_response['description']).to include('A short and simple permissive license with conditions') - expect(json_response['conditions']).to eq(%w[include-copyright]) - expect(json_response['permissions']).to eq(%w[commercial-use modifications distribution private-use]) - expect(json_response['limitations']).to eq(%w[liability warranty]) - expect(json_response['content']).to include('MIT License') + expect(json_response["key"]).to eq("mit") + expect(json_response["name"]).to eq("MIT License") + expect(json_response["nickname"]).to be_nil + expect(json_response["popular"]).to be true + expect(json_response["html_url"]).to eq("http://choosealicense.com/licenses/mit/") + expect(json_response["source_url"]).to eq("https://opensource.org/licenses/MIT") + expect(json_response["description"]).to include("A short and simple permissive license with conditions") + expect(json_response["conditions"]).to eq(%w[include-copyright]) + expect(json_response["permissions"]).to eq(%w[commercial-use modifications distribution private-use]) + expect(json_response["limitations"]).to eq(%w[liability warranty]) + expect(json_response["content"]).to include("MIT License") end end - context 'GET templates/licenses' do - it 'returns a list of available license templates' do - get api('/templates/licenses') + context "GET templates/licenses" do + it "returns a list of available license templates" do + get api("/templates/licenses") expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response).to be_an Array expect(json_response.size).to eq(12) - expect(json_response.map { |l| l['key'] }).to include('agpl-3.0') + expect(json_response.map { |l| l["key"] }).to include("agpl-3.0") end - describe 'the popular parameter' do - context 'with popular=1' do - it 'returns a list of available popular license templates' do - get api('/templates/licenses?popular=1') + describe "the popular parameter" do + context "with popular=1" do + it "returns a list of available popular license templates" do + get api("/templates/licenses?popular=1") expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response).to be_an Array 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") end end end end - context 'GET templates/licenses/:name' do - context 'with :project and :fullname given' do + context "GET templates/licenses/:name" do + context "with :project and :fullname given" do before do get api("/templates/licenses/#{license_type}?project=My+Awesome+Project&fullname=Anton+#{license_type.upcase}") end - context 'for the mit license' do - let(:license_type) { 'mit' } + context "for the mit license" do + let(:license_type) { "mit" } - it 'returns the license text' do - expect(json_response['content']).to include('MIT License') + it "returns the license text" do + expect(json_response["content"]).to include("MIT License") end - it 'replaces placeholder values' do - expect(json_response['content']).to include("Copyright (c) #{Time.now.year} Anton") + it "replaces placeholder values" do + expect(json_response["content"]).to include("Copyright (c) #{Time.now.year} Anton") end end - context 'for the agpl-3.0 license' do - let(:license_type) { 'agpl-3.0' } + context "for the agpl-3.0 license" do + let(:license_type) { "agpl-3.0" } - it 'returns the license text' do - expect(json_response['content']).to include('GNU AFFERO GENERAL PUBLIC LICENSE') + it "returns the license text" do + expect(json_response["content"]).to include("GNU AFFERO GENERAL PUBLIC LICENSE") end - it 'replaces placeholder values' do - expect(json_response['content']).to include('My Awesome Project') - expect(json_response['content']).to include("Copyright (C) #{Time.now.year} Anton") + it "replaces placeholder values" do + expect(json_response["content"]).to include("My Awesome Project") + expect(json_response["content"]).to include("Copyright (C) #{Time.now.year} Anton") end end - context 'for the gpl-3.0 license' do - let(:license_type) { 'gpl-3.0' } + context "for the gpl-3.0 license" do + let(:license_type) { "gpl-3.0" } - it 'returns the license text' do - expect(json_response['content']).to include('GNU GENERAL PUBLIC LICENSE') + it "returns the license text" do + expect(json_response["content"]).to include("GNU GENERAL PUBLIC LICENSE") end - it 'replaces placeholder values' do - expect(json_response['content']).to include('My Awesome Project') - expect(json_response['content']).to include("Copyright (C) #{Time.now.year} Anton") + it "replaces placeholder values" do + expect(json_response["content"]).to include("My Awesome Project") + expect(json_response["content"]).to include("Copyright (C) #{Time.now.year} Anton") end end - context 'for the gpl-2.0 license' do - let(:license_type) { 'gpl-2.0' } + context "for the gpl-2.0 license" do + let(:license_type) { "gpl-2.0" } - it 'returns the license text' do - expect(json_response['content']).to include('GNU GENERAL PUBLIC LICENSE') + it "returns the license text" do + expect(json_response["content"]).to include("GNU GENERAL PUBLIC LICENSE") end - it 'replaces placeholder values' do - expect(json_response['content']).to include('My Awesome Project') - expect(json_response['content']).to include("Copyright (C) #{Time.now.year} Anton") + it "replaces placeholder values" do + expect(json_response["content"]).to include("My Awesome Project") + expect(json_response["content"]).to include("Copyright (C) #{Time.now.year} Anton") end end - context 'for the apache-2.0 license' do - let(:license_type) { 'apache-2.0' } + context "for the apache-2.0 license" do + let(:license_type) { "apache-2.0" } - it 'returns the license text' do - expect(json_response['content']).to include('Apache License') + it "returns the license text" do + expect(json_response["content"]).to include("Apache License") end - it 'replaces placeholder values' do - expect(json_response['content']).to include("Copyright #{Time.now.year} Anton") + it "replaces placeholder values" do + expect(json_response["content"]).to include("Copyright #{Time.now.year} Anton") end end - context 'for an uknown license' do - let(:license_type) { 'muth-over9000' } + context "for an uknown license" do + let(:license_type) { "muth-over9000" } - it 'returns a 404' do + it "returns a 404" do expect(response).to have_gitlab_http_status(404) end end end - context 'with no :fullname given' do - context 'with an authenticated user' do + context "with no :fullname given" do + context "with an authenticated user" do let(:user) { create(:user) } - it 'replaces the copyright owner placeholder with the name of the current user' do - get api('/templates/licenses/mit', user) + it "replaces the copyright owner placeholder with the name of the current user" do + get api("/templates/licenses/mit", user) expect(response).to have_gitlab_http_status(200) - expect(json_response['content']).to include("Copyright (c) #{Time.now.year} #{user.name}") + expect(json_response["content"]).to include("Copyright (c) #{Time.now.year} #{user.name}") end end end diff --git a/spec/requests/api/todos_spec.rb b/spec/requests/api/todos_spec.rb index f121a1d3b78..22219a5fd03 100644 --- a/spec/requests/api/todos_spec.rb +++ b/spec/requests/api/todos_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe API::Todos do let(:group) { create(:group) } @@ -6,7 +6,7 @@ describe API::Todos do let(:project_2) { create(:project) } let(:author_1) { create(:user) } let(:author_2) { create(:user) } - let(:john_doe) { create(:user, username: 'john_doe') } + let(:john_doe) { create(:user, username: "john_doe") } let(:merge_request) { create(:merge_request, source_project: project_1) } let!(:pending_1) { create(:todo, :mentioned, project: project_1, author: author_1, user: john_doe) } let!(:pending_2) { create(:todo, project: project_2, author: author_2, user: john_doe) } @@ -18,38 +18,38 @@ describe API::Todos do project_2.add_developer(john_doe) end - describe 'GET /todos' do - context 'when unauthenticated' do - it 'returns authentication error' do - get api('/todos') + describe "GET /todos" do + context "when unauthenticated" do + it "returns authentication error" do + get api("/todos") expect(response.status).to eq(401) end end - context 'when authenticated' do - it 'returns an array of pending todos for current user' do - get api('/todos', john_doe) + context "when authenticated" do + it "returns an array of pending todos for current user" do + get api("/todos", john_doe) expect(response.status).to eq(200) expect(response).to include_pagination_headers expect(json_response).to be_an Array expect(json_response.length).to eq(3) - expect(json_response[0]['id']).to eq(pending_3.id) - expect(json_response[0]['project']).to be_a Hash - expect(json_response[0]['author']).to be_a Hash - expect(json_response[0]['target_type']).to be_present - expect(json_response[0]['target']).to be_a Hash - expect(json_response[0]['target_url']).to be_present - expect(json_response[0]['body']).to be_present - expect(json_response[0]['state']).to eq('pending') - expect(json_response[0]['action_name']).to eq('assigned') - expect(json_response[0]['created_at']).to be_present - end - - context 'and using the author filter' do - it 'filters based on author_id param' do - get api('/todos', john_doe), params: { author_id: author_2.id } + expect(json_response[0]["id"]).to eq(pending_3.id) + expect(json_response[0]["project"]).to be_a Hash + expect(json_response[0]["author"]).to be_a Hash + expect(json_response[0]["target_type"]).to be_present + expect(json_response[0]["target"]).to be_a Hash + expect(json_response[0]["target_url"]).to be_present + expect(json_response[0]["body"]).to be_present + expect(json_response[0]["state"]).to eq("pending") + expect(json_response[0]["action_name"]).to eq("assigned") + expect(json_response[0]["created_at"]).to be_present + end + + context "and using the author filter" do + it "filters based on author_id param" do + get api("/todos", john_doe), params: {author_id: author_2.id} expect(response.status).to eq(200) expect(response).to include_pagination_headers @@ -58,11 +58,11 @@ describe API::Todos do end end - context 'and using the type filter' do - it 'filters based on type param' do + context "and using the type filter" do + it "filters based on type param" do create(:todo, project: project_1, author: author_2, user: john_doe, target: merge_request) - get api('/todos', john_doe), params: { type: 'MergeRequest' } + get api("/todos", john_doe), params: {type: "MergeRequest"} expect(response.status).to eq(200) expect(response).to include_pagination_headers @@ -71,9 +71,9 @@ describe API::Todos do end end - context 'and using the state filter' do - it 'filters based on state param' do - get api('/todos', john_doe), params: { state: 'done' } + context "and using the state filter" do + it "filters based on state param" do + get api("/todos", john_doe), params: {state: "done"} expect(response.status).to eq(200) expect(response).to include_pagination_headers @@ -82,9 +82,9 @@ describe API::Todos do end end - context 'and using the project filter' do - it 'filters based on project_id param' do - get api('/todos', john_doe), params: { project_id: project_2.id } + context "and using the project filter" do + it "filters based on project_id param" do + get api("/todos", john_doe), params: {project_id: project_2.id} expect(response.status).to eq(200) expect(response).to include_pagination_headers @@ -93,9 +93,9 @@ describe API::Todos do end end - context 'and using the group filter' do - it 'filters based on project_id param' do - get api('/todos', john_doe), params: { group_id: group.id, sort: :target_id } + context "and using the group filter" do + it "filters based on project_id param" do + get api("/todos", john_doe), params: {group_id: group.id, sort: :target_id} expect(response.status).to eq(200) expect(response).to include_pagination_headers @@ -104,9 +104,9 @@ describe API::Todos do end end - context 'and using the action filter' do - it 'filters based on action param' do - get api('/todos', john_doe), params: { action: 'mentioned' } + context "and using the action filter" do + it "filters based on action param" do + get api("/todos", john_doe), params: {action: "mentioned"} expect(response.status).to eq(200) expect(response).to include_pagination_headers @@ -117,32 +117,32 @@ describe API::Todos do end end - describe 'POST /todos/:id/mark_as_done' do - context 'when unauthenticated' do - it 'returns authentication error' do + describe "POST /todos/:id/mark_as_done" do + context "when unauthenticated" do + it "returns authentication error" do post api("/todos/#{pending_1.id}/mark_as_done") expect(response).to have_gitlab_http_status(401) end end - context 'when authenticated' do - it 'marks a todo as done' do + context "when authenticated" do + it "marks a todo as done" do post api("/todos/#{pending_1.id}/mark_as_done", john_doe) expect(response).to have_gitlab_http_status(201) - expect(json_response['id']).to eq(pending_1.id) - expect(json_response['state']).to eq('done') + expect(json_response["id"]).to eq(pending_1.id) + expect(json_response["state"]).to eq("done") expect(pending_1.reload).to be_done end - it 'updates todos cache' do + it "updates todos cache" do expect_any_instance_of(User).to receive(:update_todos_count_cache).and_call_original post api("/todos/#{pending_1.id}/mark_as_done", john_doe) end - it 'returns 404 if the todo does not belong to the current user' do + it "returns 404 if the todo does not belong to the current user" do post api("/todos/#{pending_1.id}/mark_as_done", author_1) expect(response.status).to eq(404) @@ -150,18 +150,18 @@ describe API::Todos do end end - describe 'POST /mark_as_done' do - context 'when unauthenticated' do - it 'returns authentication error' do - post api('/todos/mark_as_done') + describe "POST /mark_as_done" do + context "when unauthenticated" do + it "returns authentication error" do + post api("/todos/mark_as_done") expect(response).to have_gitlab_http_status(401) end end - context 'when authenticated' do - it 'marks all todos as done' do - post api('/todos/mark_as_done', john_doe) + context "when authenticated" do + it "marks all todos as done" do + post api("/todos/mark_as_done", john_doe) expect(response).to have_gitlab_http_status(204) expect(pending_1.reload).to be_done @@ -169,7 +169,7 @@ describe API::Todos do expect(pending_3.reload).to be_done end - it 'updates todos cache' do + it "updates todos cache" do expect_any_instance_of(User).to receive(:update_todos_count_cache).and_call_original post api("/todos/mark_as_done", john_doe) @@ -177,23 +177,23 @@ describe API::Todos do end end - shared_examples 'an issuable' do |issuable_type| - it 'creates a todo on an issuable' do + shared_examples "an issuable" do |issuable_type| + it "creates a todo on an issuable" do post api("/projects/#{project_1.id}/#{issuable_type}/#{issuable.iid}/todo", john_doe) expect(response.status).to eq(201) - expect(json_response['project']).to be_a Hash - expect(json_response['author']).to be_a Hash - expect(json_response['target_type']).to eq(issuable.class.name) - expect(json_response['target']).to be_a Hash - expect(json_response['target_url']).to be_present - expect(json_response['body']).to be_present - expect(json_response['state']).to eq('pending') - expect(json_response['action_name']).to eq('marked') - expect(json_response['created_at']).to be_present + expect(json_response["project"]).to be_a Hash + expect(json_response["author"]).to be_a Hash + expect(json_response["target_type"]).to eq(issuable.class.name) + expect(json_response["target"]).to be_a Hash + expect(json_response["target_url"]).to be_present + expect(json_response["body"]).to be_present + expect(json_response["state"]).to eq("pending") + expect(json_response["action_name"]).to eq("marked") + expect(json_response["created_at"]).to be_present end - it 'returns 304 there already exist a todo on that issuable' do + it "returns 304 there already exist a todo on that issuable" do create(:todo, project: project_1, author: author_1, user: john_doe, target: issuable) post api("/projects/#{project_1.id}/#{issuable_type}/#{issuable.iid}/todo", john_doe) @@ -201,19 +201,19 @@ describe API::Todos do expect(response.status).to eq(304) end - it 'returns 404 if the issuable is not found' do + it "returns 404 if the issuable is not found" do post api("/projects/#{project_1.id}/#{issuable_type}/123/todo", john_doe) expect(response.status).to eq(404) end - it 'returns an error if the issuable is not accessible' do + it "returns an error if the issuable is not accessible" do guest = create(:user) project_1.add_guest(guest) post api("/projects/#{project_1.id}/#{issuable_type}/#{issuable.iid}/todo", guest) - if issuable_type == 'merge_requests' + if issuable_type == "merge_requests" expect(response).to have_gitlab_http_status(403) else expect(response).to have_gitlab_http_status(404) @@ -221,15 +221,15 @@ describe API::Todos do end end - describe 'POST :id/issuable_type/:issueable_id/todo' do - context 'for an issue' do - it_behaves_like 'an issuable', 'issues' do + describe "POST :id/issuable_type/:issueable_id/todo" do + context "for an issue" do + it_behaves_like "an issuable", "issues" do let(:issuable) { create(:issue, :confidential, author: author_1, project: project_1) } end end - context 'for a merge request' do - it_behaves_like 'an issuable', 'merge_requests' do + context "for a merge request" do + it_behaves_like "an issuable", "merge_requests" do let(:issuable) { merge_request } end end diff --git a/spec/requests/api/triggers_spec.rb b/spec/requests/api/triggers_spec.rb index f0f01e97f1d..77ff4e3051d 100644 --- a/spec/requests/api/triggers_spec.rb +++ b/spec/requests/api/triggers_spec.rb @@ -1,23 +1,23 @@ -require 'spec_helper' +require "spec_helper" describe API::Triggers do set(:user) { create(:user) } set(:user2) { create(:user) } - let!(:trigger_token) { 'secure_token' } - let!(:trigger_token_2) { 'secure_token_2' } + let!(:trigger_token) { "secure_token" } + let!(:trigger_token_2) { "secure_token_2" } let!(:project) { create(:project, :repository, creator: user) } let!(:maintainer) { create(:project_member, :maintainer, user: user, project: project) } let!(:developer) { create(:project_member, :developer, user: user2, project: project) } let!(:trigger) { create(:ci_trigger, project: project, token: trigger_token, owner: user) } let!(:trigger2) { create(:ci_trigger, project: project, token: trigger_token_2, owner: user2) } - let!(:trigger_request) { create(:ci_trigger_request, trigger: trigger, created_at: '2015-01-01 12:13:14') } + let!(:trigger_request) { create(:ci_trigger_request, trigger: trigger, created_at: "2015-01-01 12:13:14") } - describe 'POST /projects/:project_id/trigger/pipeline' do + describe "POST /projects/:project_id/trigger/pipeline" do let!(:project2) { create(:project, :repository) } let(:options) do { - token: trigger_token + token: trigger_token, } end @@ -25,77 +25,77 @@ describe API::Triggers do stub_ci_pipeline_to_return_yaml_file end - context 'Handles errors' do - it 'returns bad request if token is missing' do - post api("/projects/#{project.id}/trigger/pipeline"), params: { ref: 'master' } + context "Handles errors" do + it "returns bad request if token is missing" do + post api("/projects/#{project.id}/trigger/pipeline"), params: {ref: "master"} expect(response).to have_gitlab_http_status(400) end - it 'returns not found if project is not found' do - post api('/projects/0/trigger/pipeline'), params: options.merge(ref: 'master') + it "returns not found if project is not found" do + post api("/projects/0/trigger/pipeline"), params: options.merge(ref: "master") expect(response).to have_gitlab_http_status(404) end end - context 'Have a commit' do + context "Have a commit" do let(:pipeline) { project.ci_pipelines.last } - it 'creates pipeline' do - post api("/projects/#{project.id}/trigger/pipeline"), params: options.merge(ref: 'master') + it "creates pipeline" do + post api("/projects/#{project.id}/trigger/pipeline"), params: options.merge(ref: "master") expect(response).to have_gitlab_http_status(201) - expect(json_response).to include('id' => pipeline.id) + expect(json_response).to include("id" => pipeline.id) pipeline.builds.reload expect(pipeline.builds.pending.size).to eq(2) expect(pipeline.builds.size).to eq(5) end - it 'returns bad request with no pipeline created if there\'s no commit for that ref' do - post api("/projects/#{project.id}/trigger/pipeline"), params: options.merge(ref: 'other-branch') + it "returns bad request with no pipeline created if there's no commit for that ref" do + post api("/projects/#{project.id}/trigger/pipeline"), params: options.merge(ref: "other-branch") expect(response).to have_gitlab_http_status(400) - expect(json_response['message']).to eq('base' => ["Reference not found"]) + expect(json_response["message"]).to eq("base" => ["Reference not found"]) end - context 'Validates variables' do + context "Validates variables" do let(:variables) do - { 'TRIGGER_KEY' => 'TRIGGER_VALUE' } + {"TRIGGER_KEY" => "TRIGGER_VALUE"} end - it 'validates variables to be a hash' do - post api("/projects/#{project.id}/trigger/pipeline"), params: options.merge(variables: 'value', ref: 'master') + it "validates variables to be a hash" do + post api("/projects/#{project.id}/trigger/pipeline"), params: options.merge(variables: "value", ref: "master") expect(response).to have_gitlab_http_status(400) - expect(json_response['error']).to eq('variables is invalid') + expect(json_response["error"]).to eq("variables is invalid") end - it 'validates variables needs to be a map of key-valued strings' do - post api("/projects/#{project.id}/trigger/pipeline"), params: options.merge(variables: { key: %w(1 2) }, ref: 'master') + it "validates variables needs to be a map of key-valued strings" do + post api("/projects/#{project.id}/trigger/pipeline"), params: options.merge(variables: {key: %w[1 2]}, ref: "master") expect(response).to have_gitlab_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 - it 'creates trigger request with variables' do - post api("/projects/#{project.id}/trigger/pipeline"), params: options.merge(variables: variables, ref: 'master') + it "creates trigger request with variables" do + post api("/projects/#{project.id}/trigger/pipeline"), params: options.merge(variables: variables, ref: "master") expect(response).to have_gitlab_http_status(201) - expect(pipeline.variables.map { |v| { v.key => v.value } }.last).to eq(variables) + expect(pipeline.variables.map { |v| {v.key => v.value} }.last).to eq(variables) end end - context 'when legacy trigger' do + context "when legacy trigger" do before do trigger.update(owner: nil) end - it 'creates pipeline' do - post api("/projects/#{project.id}/trigger/pipeline"), params: options.merge(ref: 'master') + it "creates pipeline" do + post api("/projects/#{project.id}/trigger/pipeline"), params: options.merge(ref: "master") expect(response).to have_gitlab_http_status(201) - expect(json_response).to include('id' => pipeline.id) + expect(json_response).to include("id" => pipeline.id) pipeline.builds.reload expect(pipeline.builds.pending.size).to eq(2) expect(pipeline.builds.size).to eq(5) @@ -103,28 +103,28 @@ describe API::Triggers do end end - context 'when triggering a pipeline from a trigger token' do - it 'does not leak the presence of project when token is for different project' do - post api("/projects/#{project2.id}/ref/master/trigger/pipeline?token=#{trigger_token}"), params: { ref: 'refs/heads/other-branch' } + context "when triggering a pipeline from a trigger token" do + it "does not leak the presence of project when token is for different project" do + post api("/projects/#{project2.id}/ref/master/trigger/pipeline?token=#{trigger_token}"), params: {ref: "refs/heads/other-branch"} expect(response).to have_gitlab_http_status(404) end - it 'creates builds from the ref given in the URL, not in the body' do - expect do - post api("/projects/#{project.id}/ref/master/trigger/pipeline?token=#{trigger_token}"), params: { ref: 'refs/heads/other-branch' } - end.to change(project.builds, :count).by(5) + it "creates builds from the ref given in the URL, not in the body" do + expect { + post api("/projects/#{project.id}/ref/master/trigger/pipeline?token=#{trigger_token}"), params: {ref: "refs/heads/other-branch"} + }.to change(project.builds, :count).by(5) expect(response).to have_gitlab_http_status(201) end - context 'when ref contains a dot' do - it 'creates builds from the ref given in the URL, not in the body' do - project.repository.create_file(user, '.gitlab/gitlabhq/new_feature.md', 'something valid', message: 'new_feature', branch_name: 'v.1-branch') + context "when ref contains a dot" do + it "creates builds from the ref given in the URL, not in the body" do + project.repository.create_file(user, ".gitlab/gitlabhq/new_feature.md", "something valid", message: "new_feature", branch_name: "v.1-branch") - expect do - post api("/projects/#{project.id}/ref/v.1-branch/trigger/pipeline?token=#{trigger_token}"), params: { ref: 'refs/heads/other-branch' } - end.to change(project.builds, :count).by(4) + expect { + post api("/projects/#{project.id}/ref/v.1-branch/trigger/pipeline?token=#{trigger_token}"), params: {ref: "refs/heads/other-branch"} + }.to change(project.builds, :count).by(4) expect(response).to have_gitlab_http_status(201) end @@ -132,9 +132,9 @@ describe API::Triggers do end end - describe 'GET /projects/:id/triggers' do - context 'authenticated user who can access triggers' do - it 'returns a list of triggers with tokens exposed correctly' do + describe "GET /projects/:id/triggers" do + context "authenticated user who can access triggers" do + it "returns a list of triggers with tokens exposed correctly" do get api("/projects/#{project.id}/triggers", user) expect(response).to have_gitlab_http_status(200) @@ -142,21 +142,21 @@ describe API::Triggers do expect(json_response).to be_a(Array) expect(json_response.size).to eq 2 - expect(json_response.dig(0, 'token')).to eq trigger_token - expect(json_response.dig(1, 'token')).to eq trigger_token_2[0..3] + expect(json_response.dig(0, "token")).to eq trigger_token + expect(json_response.dig(1, "token")).to eq trigger_token_2[0..3] end end - context 'authenticated user with invalid permissions' do - it 'does not return triggers list' do + context "authenticated user with invalid permissions" do + it "does not return triggers list" do get api("/projects/#{project.id}/triggers", user2) expect(response).to have_gitlab_http_status(403) end end - context 'unauthenticated user' do - it 'does not return triggers list' do + context "unauthenticated user" do + it "does not return triggers list" do get api("/projects/#{project.id}/triggers") expect(response).to have_gitlab_http_status(401) @@ -164,32 +164,32 @@ describe API::Triggers do end end - describe 'GET /projects/:id/triggers/:trigger_id' do - context 'authenticated user with valid permissions' do - it 'returns trigger details' do + describe "GET /projects/:id/triggers/:trigger_id" do + context "authenticated user with valid permissions" do + it "returns trigger details" do get api("/projects/#{project.id}/triggers/#{trigger.id}", user) expect(response).to have_gitlab_http_status(200) expect(json_response).to be_a(Hash) end - it 'responds with 404 Not Found if requesting non-existing trigger' do + it "responds with 404 Not Found if requesting non-existing trigger" do get api("/projects/#{project.id}/triggers/-5", user) expect(response).to have_gitlab_http_status(404) end end - context 'authenticated user with invalid permissions' do - it 'does not return triggers list' do + context "authenticated user with invalid permissions" do + it "does not return triggers list" do get api("/projects/#{project.id}/triggers/#{trigger.id}", user2) expect(response).to have_gitlab_http_status(403) end end - context 'unauthenticated user' do - it 'does not return triggers list' do + context "unauthenticated user" do + it "does not return triggers list" do get api("/projects/#{project.id}/triggers/#{trigger.id}") expect(response).to have_gitlab_http_status(401) @@ -197,22 +197,22 @@ describe API::Triggers do end end - describe 'POST /projects/:id/triggers' do - context 'authenticated user with valid permissions' do - context 'with required parameters' do - it 'creates trigger' do - expect do + describe "POST /projects/:id/triggers" do + context "authenticated user with valid permissions" do + context "with required parameters" do + it "creates trigger" do + expect { post api("/projects/#{project.id}/triggers", user), - params: { description: 'trigger' } - end.to change {project.triggers.count}.by(1) + params: {description: "trigger"} + }.to change {project.triggers.count}.by(1) expect(response).to have_gitlab_http_status(201) - expect(json_response).to include('description' => 'trigger') + expect(json_response).to include("description" => "trigger") end end - context 'without required parameters' do - it 'does not create trigger' do + context "without required parameters" do + it "does not create trigger" do post api("/projects/#{project.id}/triggers", user) expect(response).to have_gitlab_http_status(:bad_request) @@ -220,49 +220,49 @@ describe API::Triggers do end end - context 'authenticated user with invalid permissions' do - it 'does not create trigger' do + context "authenticated user with invalid permissions" do + it "does not create trigger" do post api("/projects/#{project.id}/triggers", user2), - params: { description: 'trigger' } + params: {description: "trigger"} expect(response).to have_gitlab_http_status(403) end end - context 'unauthenticated user' do - it 'does not create trigger' do + context "unauthenticated user" do + it "does not create trigger" do post api("/projects/#{project.id}/triggers"), - params: { description: 'trigger' } + params: {description: "trigger"} expect(response).to have_gitlab_http_status(401) end end end - describe 'PUT /projects/:id/triggers/:trigger_id' do - context 'authenticated user with valid permissions' do - let(:new_description) { 'new description' } + describe "PUT /projects/:id/triggers/:trigger_id" do + context "authenticated user with valid permissions" do + let(:new_description) { "new description" } - it 'updates description' do + it "updates description" do put api("/projects/#{project.id}/triggers/#{trigger.id}", user), - params: { description: new_description } + params: {description: new_description} expect(response).to have_gitlab_http_status(200) - expect(json_response).to include('description' => new_description) + expect(json_response).to include("description" => new_description) expect(trigger.reload.description).to eq(new_description) end end - context 'authenticated user with invalid permissions' do - it 'does not update trigger' do + context "authenticated user with invalid permissions" do + it "does not update trigger" do put api("/projects/#{project.id}/triggers/#{trigger.id}", user2) expect(response).to have_gitlab_http_status(403) end end - context 'unauthenticated user' do - it 'does not update trigger' do + context "unauthenticated user" do + it "does not update trigger" do put api("/projects/#{project.id}/triggers/#{trigger.id}") expect(response).to have_gitlab_http_status(401) @@ -270,27 +270,27 @@ describe API::Triggers do end end - describe 'POST /projects/:id/triggers/:trigger_id/take_ownership' do - context 'authenticated user with valid permissions' do - it 'updates owner' do + describe "POST /projects/:id/triggers/:trigger_id/take_ownership" do + context "authenticated user with valid permissions" do + it "updates owner" do post api("/projects/#{project.id}/triggers/#{trigger.id}/take_ownership", user) expect(response).to have_gitlab_http_status(200) - expect(json_response).to include('owner') + expect(json_response).to include("owner") expect(trigger.reload.owner).to eq(user) end end - context 'authenticated user with invalid permissions' do - it 'does not update owner' do + context "authenticated user with invalid permissions" do + it "does not update owner" do post api("/projects/#{project.id}/triggers/#{trigger.id}/take_ownership", user2) expect(response).to have_gitlab_http_status(403) end end - context 'unauthenticated user' do - it 'does not update owner' do + context "unauthenticated user" do + it "does not update owner" do post api("/projects/#{project.id}/triggers/#{trigger.id}/take_ownership") expect(response).to have_gitlab_http_status(401) @@ -298,37 +298,37 @@ describe API::Triggers do end end - describe 'DELETE /projects/:id/triggers/:trigger_id' do - context 'authenticated user with valid permissions' do - it 'deletes trigger' do - expect do + describe "DELETE /projects/:id/triggers/:trigger_id" do + context "authenticated user with valid permissions" do + it "deletes trigger" do + expect { delete api("/projects/#{project.id}/triggers/#{trigger.id}", user) expect(response).to have_gitlab_http_status(204) - end.to change {project.triggers.count}.by(-1) + }.to change {project.triggers.count}.by(-1) end - it 'responds with 404 Not Found if requesting non-existing trigger' do + it "responds with 404 Not Found if requesting non-existing trigger" do delete api("/projects/#{project.id}/triggers/-5", user) expect(response).to have_gitlab_http_status(404) end - it_behaves_like '412 response' do + it_behaves_like "412 response" do let(:request) { api("/projects/#{project.id}/triggers/#{trigger.id}", user) } end end - context 'authenticated user with invalid permissions' do - it 'does not delete trigger' do + context "authenticated user with invalid permissions" do + it "does not delete trigger" do delete api("/projects/#{project.id}/triggers/#{trigger.id}", user2) expect(response).to have_gitlab_http_status(403) end end - context 'unauthenticated user' do - it 'does not delete trigger' do + context "unauthenticated user" do + it "does not delete trigger" do delete api("/projects/#{project.id}/triggers/#{trigger.id}") expect(response).to have_gitlab_http_status(401) diff --git a/spec/requests/api/users_spec.rb b/spec/requests/api/users_spec.rb index a879426589d..88372d6d9e5 100644 --- a/spec/requests/api/users_spec.rb +++ b/spec/requests/api/users_spec.rb @@ -1,40 +1,40 @@ -require 'spec_helper' +require "spec_helper" describe API::Users do - let(:user) { create(:user, username: 'user.with.dot') } + let(:user) { create(:user, username: "user.with.dot") } let(:admin) { create(:admin) } let(:key) { create(:key, user: user) } let(:gpg_key) { create(:gpg_key, user: user) } let(:email) { create(:email, user: user) } let(:omniauth_user) { create(:omniauth_user) } - let(:ldap_user) { create(:omniauth_user, provider: 'ldapmain') } - let(:ldap_blocked_user) { create(:omniauth_user, provider: 'ldapmain', state: 'ldap_blocked') } - let(:not_existing_user_id) { (User.maximum('id') || 0 ) + 10 } - let(:not_existing_pat_id) { (PersonalAccessToken.maximum('id') || 0 ) + 10 } + let(:ldap_user) { create(:omniauth_user, provider: "ldapmain") } + let(:ldap_blocked_user) { create(:omniauth_user, provider: "ldapmain", state: "ldap_blocked") } + let(:not_existing_user_id) { (User.maximum("id") || 0) + 10 } + let(:not_existing_pat_id) { (PersonalAccessToken.maximum("id") || 0) + 10 } let(:private_user) { create(:user, private_profile: true) } - shared_examples 'rendering user status' do - it 'returns the status if there was one' do + shared_examples "rendering user status" do + it "returns the status if there was one" do create(:user_status, user: user) get api(path, user) expect(response).to have_gitlab_http_status(:success) - expect(json_response['message']).to be_present - expect(json_response['message_html']).to be_present - expect(json_response['emoji']).to be_present + expect(json_response["message"]).to be_present + expect(json_response["message_html"]).to be_present + expect(json_response["emoji"]).to be_present end - it 'returns an empty response if there was no status' do + it "returns an empty response if there was no status" do get api(path, user) expect(response).to have_gitlab_http_status(:success) - expect(json_response['message']).to be_nil - expect(json_response['emoji']).to be_nil + expect(json_response["message"]).to be_nil + expect(json_response["emoji"]).to be_nil end end - describe 'GET /users' do + describe "GET /users" do context "when unauthenticated" do it "returns authorization error when the `username` parameter is not passed" do get api("/users") @@ -43,25 +43,25 @@ describe API::Users do end it "returns the user when a valid `username` parameter is passed" do - get api("/users"), params: { username: user.username } + get api("/users"), params: {username: user.username} - expect(response).to match_response_schema('public_api/v4/user/basics') + expect(response).to match_response_schema("public_api/v4/user/basics") expect(json_response.size).to eq(1) - expect(json_response[0]['id']).to eq(user.id) - expect(json_response[0]['username']).to eq(user.username) + expect(json_response[0]["id"]).to eq(user.id) + expect(json_response[0]["username"]).to eq(user.username) end it "returns the user when a valid `username` parameter is passed (case insensitive)" do - get api("/users"), params: { username: user.username.upcase } + get api("/users"), params: {username: user.username.upcase} - expect(response).to match_response_schema('public_api/v4/user/basics') + expect(response).to match_response_schema("public_api/v4/user/basics") expect(json_response.size).to eq(1) - expect(json_response[0]['id']).to eq(user.id) - expect(json_response[0]['username']).to eq(user.username) + expect(json_response[0]["id"]).to eq(user.id) + expect(json_response[0]["username"]).to eq(user.username) end it "returns an empty response when an invalid `username` parameter is passed" do - get api("/users"), params: { username: 'invalid' } + get api("/users"), params: {username: "invalid"} expect(response).to have_gitlab_http_status(200) expect(json_response).to be_an Array @@ -74,7 +74,7 @@ describe API::Users do end it "returns authorization error when the `username` parameter refers to an inaccessible user" do - get api("/users"), params: { username: user.username } + get api("/users"), params: {username: user.username} expect(response).to have_gitlab_http_status(403) end @@ -94,19 +94,19 @@ describe API::Users do stub_application_setting(restricted_visibility_levels: [Gitlab::VisibilityLevel::PUBLIC]) end - context 'when authenticate as a regular user' do + context "when authenticate as a regular user" do it "renders 200" do get api("/users", user) - expect(response).to match_response_schema('public_api/v4/user/basics') + expect(response).to match_response_schema("public_api/v4/user/basics") end end - context 'when authenticate as an admin' do + context "when authenticate as an admin" do it "renders 200" do get api("/users", admin) - expect(response).to match_response_schema('public_api/v4/user/basics') + expect(response).to match_response_schema("public_api/v4/user/basics") end end end @@ -114,39 +114,39 @@ describe API::Users do it "returns an array of users" do get api("/users", user) - expect(response).to match_response_schema('public_api/v4/user/basics') + expect(response).to match_response_schema("public_api/v4/user/basics") expect(response).to include_pagination_headers username = user.username - expect(json_response.detect do |user| - user['username'] == username - end['username']).to eq(username) + expect(json_response.detect { |user| + user["username"] == username + }["username"]).to eq(username) end it "returns an array of blocked users" do ldap_blocked_user - create(:user, state: 'blocked') + create(:user, state: "blocked") get api("/users?blocked=true", user) - expect(response).to match_response_schema('public_api/v4/user/basics') + expect(response).to match_response_schema("public_api/v4/user/basics") expect(response).to include_pagination_headers - expect(json_response).to all(include('state' => /(blocked|ldap_blocked)/)) + expect(json_response).to all(include("state" => /(blocked|ldap_blocked)/)) end it "returns one user" do get api("/users?username=#{omniauth_user.username}", user) - expect(response).to match_response_schema('public_api/v4/user/basics') + expect(response).to match_response_schema("public_api/v4/user/basics") expect(response).to include_pagination_headers - expect(json_response.first['username']).to eq(omniauth_user.username) + expect(json_response.first["username"]).to eq(omniauth_user.username) end it "returns one user (case insensitive)" do get api("/users?username=#{omniauth_user.username.upcase}", user) - expect(response).to match_response_schema('public_api/v4/user/basics') + expect(response).to match_response_schema("public_api/v4/user/basics") expect(response).to include_pagination_headers - expect(json_response.first['username']).to eq(omniauth_user.username) + expect(json_response.first["username"]).to eq(omniauth_user.username) end it "returns a 403 when non-admin user searches by external UID" do @@ -155,17 +155,17 @@ describe API::Users do expect(response).to have_gitlab_http_status(403) end - it 'does not reveal the `is_admin` flag of the user' do - get api('/users', user) + it "does not reveal the `is_admin` flag of the user" do + get api("/users", user) - expect(response).to match_response_schema('public_api/v4/user/basics') - expect(json_response.first.keys).not_to include 'is_admin' + expect(response).to match_response_schema("public_api/v4/user/basics") + expect(json_response.first.keys).not_to include "is_admin" end end context "when admin" do - context 'when sudo is defined' do - it 'does not return 500' do + context "when sudo is defined" do + it "does not return 500" do admin_personal_access_token = create(:personal_access_token, user: admin, scopes: [:sudo]) get api("/users?sudo=#{user.id}", admin, personal_access_token: admin_personal_access_token) @@ -176,7 +176,7 @@ describe API::Users do it "returns an array of users" do get api("/users", admin) - expect(response).to match_response_schema('public_api/v4/user/admins') + expect(response).to match_response_schema("public_api/v4/user/admins") expect(response).to include_pagination_headers end @@ -185,17 +185,17 @@ describe API::Users do get api("/users?external=true", admin) - expect(response).to match_response_schema('public_api/v4/user/admins') + expect(response).to match_response_schema("public_api/v4/user/admins") expect(response).to include_pagination_headers - expect(json_response).to all(include('external' => true)) + expect(json_response).to all(include("external" => true)) end it "returns one user by external UID" do get api("/users?extern_uid=#{omniauth_user.identities.first.extern_uid}&provider=#{omniauth_user.identities.first.provider}", admin) - expect(response).to match_response_schema('public_api/v4/user/admins') + expect(response).to match_response_schema("public_api/v4/user/admins") expect(json_response.size).to eq(1) - expect(json_response.first['username']).to eq(omniauth_user.username) + expect(json_response.first["username"]).to eq(omniauth_user.username) end it "returns 400 error if provider with no extern_uid" do @@ -215,9 +215,9 @@ describe API::Users do get api("/users?created_before=2000-01-02T00:00:00.060Z", admin) - expect(response).to match_response_schema('public_api/v4/user/admins') + expect(response).to match_response_schema("public_api/v4/user/admins") expect(json_response.size).to eq(1) - expect(json_response.first['username']).to eq(user.username) + expect(json_response.first["username"]).to eq(user.username) end it "returns no users created before a specific date" do @@ -225,7 +225,7 @@ describe API::Users do get api("/users?created_before=2000-01-02T00:00:00.060Z", admin) - expect(response).to match_response_schema('public_api/v4/user/admins') + expect(response).to match_response_schema("public_api/v4/user/admins") expect(json_response.size).to eq(0) end @@ -234,37 +234,37 @@ describe API::Users do get api("/users?created_before=2001-01-02T00:00:00.060Z&created_after=1999-01-02T00:00:00.060", admin) - expect(response).to match_response_schema('public_api/v4/user/admins') + expect(response).to match_response_schema("public_api/v4/user/admins") expect(json_response.size).to eq(1) - expect(json_response.first['username']).to eq(user.username) + expect(json_response.first["username"]).to eq(user.username) end - it 'returns the correct order when sorted by id' do + it "returns the correct order when sorted by id" do admin user - get api('/users', admin), params: { order_by: 'id', sort: 'asc' } + get api("/users", admin), params: {order_by: "id", sort: "asc"} - expect(response).to match_response_schema('public_api/v4/user/admins') + expect(response).to match_response_schema("public_api/v4/user/admins") expect(json_response.size).to eq(2) - expect(json_response.first['id']).to eq(admin.id) - expect(json_response.last['id']).to eq(user.id) + expect(json_response.first["id"]).to eq(admin.id) + expect(json_response.last["id"]).to eq(user.id) end - it 'returns users with 2fa enabled' do + it "returns users with 2fa enabled" do admin user user_with_2fa = create(:user, :two_factor_via_otp) - get api('/users', admin), params: { two_factor: 'enabled' } + get api("/users", admin), params: {two_factor: "enabled"} - expect(response).to match_response_schema('public_api/v4/user/admins') + expect(response).to match_response_schema("public_api/v4/user/admins") expect(json_response.size).to eq(1) - expect(json_response.first['id']).to eq(user_with_2fa.id) + expect(json_response.first["id"]).to eq(user_with_2fa.id) end - it 'returns 400 when provided incorrect sort params' do - get api('/users', admin), params: { order_by: 'magic', sort: 'asc' } + it "returns 400 when provided incorrect sort params" do + get api("/users", admin), params: {order_by: "magic", sort: "asc"} expect(response).to have_gitlab_http_status(400) end @@ -275,39 +275,39 @@ describe API::Users do it "returns a user by id" do get api("/users/#{user.id}", user) - expect(response).to match_response_schema('public_api/v4/user/basic') - expect(json_response['username']).to eq(user.username) + expect(response).to match_response_schema("public_api/v4/user/basic") + expect(json_response["username"]).to eq(user.username) end it "does not return the user's `is_admin` flag" do get api("/users/#{user.id}", user) - expect(response).to match_response_schema('public_api/v4/user/basic') - expect(json_response.keys).not_to include 'is_admin' + expect(response).to match_response_schema("public_api/v4/user/basic") + expect(json_response.keys).not_to include "is_admin" end - context 'when authenticated as admin' do - it 'includes the `is_admin` field' do + context "when authenticated as admin" do + it "includes the `is_admin` field" do get api("/users/#{user.id}", admin) - expect(response).to match_response_schema('public_api/v4/user/admin') - expect(json_response['is_admin']).to be(false) + expect(response).to match_response_schema("public_api/v4/user/admin") + expect(json_response["is_admin"]).to be(false) end it "includes the `created_at` field for private users" do get api("/users/#{private_user.id}", admin) - expect(response).to match_response_schema('public_api/v4/user/admin') - expect(json_response.keys).to include 'created_at' + expect(response).to match_response_schema("public_api/v4/user/admin") + expect(json_response.keys).to include "created_at" end end - context 'for an anonymous user' do + context "for an anonymous user" do it "returns a user by id" do get api("/users/#{user.id}") - expect(response).to match_response_schema('public_api/v4/user/basic') - expect(json_response['username']).to eq(user.username) + expect(response).to match_response_schema("public_api/v4/user/basic") + expect(json_response["username"]).to eq(user.username) end it "returns a 404 if the target user is present but inaccessible" do @@ -322,15 +322,15 @@ describe API::Users do it "returns the `created_at` field for public users" do get api("/users/#{user.id}") - expect(response).to match_response_schema('public_api/v4/user/basic') - expect(json_response.keys).to include 'created_at' + expect(response).to match_response_schema("public_api/v4/user/basic") + expect(json_response.keys).to include "created_at" end it "does not return the `created_at` field for private users" do get api("/users/#{private_user.id}") - expect(response).to match_response_schema('public_api/v4/user/basic') - expect(json_response.keys).not_to include 'created_at' + expect(response).to match_response_schema("public_api/v4/user/basic") + expect(json_response.keys).not_to include "created_at" end end @@ -338,7 +338,7 @@ describe API::Users do get api("/users/0", user) expect(response).to have_gitlab_http_status(404) - expect(json_response['message']).to eq('404 User Not Found') + expect(json_response["message"]).to eq("404 User Not Found") end it "returns a 404 for invalid ID" do @@ -348,21 +348,21 @@ describe API::Users do end end - describe 'GET /users/:id_or_username/status' do - context 'when finding the user by id' do - it_behaves_like 'rendering user status' do + describe "GET /users/:id_or_username/status" do + context "when finding the user by id" do + it_behaves_like "rendering user status" do let(:path) { "/users/#{user.id}/status" } end end - context 'when finding the user by username' do - it_behaves_like 'rendering user status' do + context "when finding the user by username" do + it_behaves_like "rendering user status" do let(:path) { "/users/#{user.username}/status" } end end - context 'when finding the user by username (case insensitive)' do - it_behaves_like 'rendering user status' do + context "when finding the user by username (case insensitive)" do + it_behaves_like "rendering user status" do let(:path) { "/users/#{user.username.upcase}/status" } end end @@ -374,15 +374,15 @@ describe API::Users do end it "creates user" do - expect do + expect { post api("/users", admin), params: attributes_for(:user, projects_limit: 3) - end.to change { User.count }.by(1) + }.to change { User.count }.by(1) end it "creates user with correct attributes" do - post api('/users', admin), params: attributes_for(:user, admin: true, can_create_group: true) + post api("/users", admin), params: attributes_for(:user, admin: true, can_create_group: true) expect(response).to have_gitlab_http_status(201) - user_id = json_response['id'] + user_id = json_response["id"] new_user = User.find(user_id) expect(new_user).not_to eq(nil) expect(new_user.admin).to eq(true) @@ -390,18 +390,18 @@ describe API::Users do end it "creates user with optional attributes" do - optional_attributes = { confirm: true } + optional_attributes = {confirm: true} attributes = attributes_for(:user).merge(optional_attributes) - post api('/users', admin), params: attributes + post api("/users", admin), params: attributes expect(response).to have_gitlab_http_status(201) end it "creates non-admin user" do - post api('/users', admin), params: attributes_for(:user, admin: false, can_create_group: false) + post api("/users", admin), params: attributes_for(:user, admin: false, can_create_group: false) expect(response).to have_gitlab_http_status(201) - user_id = json_response['id'] + user_id = json_response["id"] new_user = User.find(user_id) expect(new_user).not_to eq(nil) expect(new_user.admin).to eq(false) @@ -409,9 +409,9 @@ describe API::Users do end it "creates non-admin users by default" do - post api('/users', admin), params: attributes_for(:user) + post api("/users", admin), params: attributes_for(:user) expect(response).to have_gitlab_http_status(201) - user_id = json_response['id'] + user_id = json_response["id"] new_user = User.find(user_id) expect(new_user).not_to eq(nil) expect(new_user.admin).to eq(false) @@ -422,32 +422,32 @@ describe API::Users do expect(response).to have_gitlab_http_status(201) end - it 'creates non-external users by default' do + it "creates non-external users by default" do post api("/users", admin), params: attributes_for(:user) expect(response).to have_gitlab_http_status(201) - user_id = json_response['id'] + user_id = json_response["id"] new_user = User.find(user_id) expect(new_user).not_to eq nil expect(new_user.external).to be_falsy end - it 'allows an external user to be created' do + it "allows an external user to be created" do post api("/users", admin), params: attributes_for(:user, external: true) expect(response).to have_gitlab_http_status(201) - user_id = json_response['id'] + user_id = json_response["id"] new_user = User.find(user_id) expect(new_user).not_to eq nil expect(new_user.external).to be_truthy end it "creates user with reset password" do - post api('/users', admin), params: attributes_for(:user, reset_password: true).except(:password) + post api("/users", admin), params: attributes_for(:user, reset_password: true).except(:password) expect(response).to have_gitlab_http_status(201) - user_id = json_response['id'] + user_id = json_response["id"] new_user = User.find(user_id) expect(new_user).not_to eq(nil) @@ -455,11 +455,11 @@ describe API::Users do end it "creates user with private profile" do - post api('/users', admin), params: attributes_for(:user, private_profile: true) + post api("/users", admin), params: attributes_for(:user, private_profile: true) expect(response).to have_gitlab_http_status(201) - user_id = json_response['id'] + user_id = json_response["id"] new_user = User.find(user_id) expect(new_user).not_to eq(nil) @@ -467,53 +467,53 @@ describe API::Users do end it "does not create user with invalid email" do - post api('/users', admin), - params: { - email: 'invalid email', - password: 'password', - name: 'test' - } + post api("/users", admin), + params: { + email: "invalid email", + password: "password", + name: "test", + } expect(response).to have_gitlab_http_status(400) end - it 'returns 400 error if name not given' do - post api('/users', admin), params: attributes_for(:user).except(:name) + it "returns 400 error if name not given" do + post api("/users", admin), params: attributes_for(:user).except(:name) expect(response).to have_gitlab_http_status(400) end - it 'returns 400 error if password not given' do - post api('/users', admin), params: attributes_for(:user).except(:password) + it "returns 400 error if password not given" do + post api("/users", admin), params: attributes_for(:user).except(:password) expect(response).to have_gitlab_http_status(400) end - it 'returns 400 error if email not given' do - post api('/users', admin), params: attributes_for(:user).except(:email) + it "returns 400 error if email not given" do + post api("/users", admin), params: attributes_for(:user).except(:email) expect(response).to have_gitlab_http_status(400) end - it 'returns 400 error if username not given' do - post api('/users', admin), params: attributes_for(:user).except(:username) + it "returns 400 error if username not given" do + post api("/users", admin), params: attributes_for(:user).except(:username) expect(response).to have_gitlab_http_status(400) end - it 'returns 400 error if user does not validate' do - post api('/users', admin), - params: { - password: 'pass', - email: 'test@example.com', - username: 'test!', - name: 'test', - bio: 'g' * 256, - projects_limit: -1 - } + it "returns 400 error if user does not validate" do + post api("/users", admin), + params: { + password: "pass", + email: "test@example.com", + username: "test!", + name: "test", + bio: "g" * 256, + projects_limit: -1, + } expect(response).to have_gitlab_http_status(400) - expect(json_response['message']['password']) - .to eq(['is too short (minimum is 8 characters)']) - expect(json_response['message']['bio']) - .to eq(['is too long (maximum is 255 characters)']) - expect(json_response['message']['projects_limit']) - .to eq(['must be greater than or equal to 0']) - expect(json_response['message']['username']) + expect(json_response["message"]["password"]) + .to eq(["is too short (minimum is 8 characters)"]) + expect(json_response["message"]["bio"]) + .to eq(["is too long (maximum is 255 characters)"]) + expect(json_response["message"]["projects_limit"]) + .to eq(["must be greater than or equal to 0"]) + expect(json_response["message"]["username"]) .to eq([Gitlab::PathRegex.namespace_format_message]) end @@ -522,71 +522,71 @@ describe API::Users do expect(response).to have_gitlab_http_status(403) end - context 'with existing user' do + context "with existing user" do before do - post api('/users', admin), - params: { - email: 'test@example.com', - password: 'password', - username: 'test', - name: 'foo' - } - end - - it 'returns 409 conflict error if user with same email exists' do - expect do - post api('/users', admin), - params: { - name: 'foo', - email: 'test@example.com', - password: 'password', - username: 'foo' - } - end.to change { User.count }.by(0) + post api("/users", admin), + params: { + email: "test@example.com", + password: "password", + username: "test", + name: "foo", + } + end + + it "returns 409 conflict error if user with same email exists" do + expect { + post api("/users", admin), + params: { + name: "foo", + email: "test@example.com", + password: "password", + username: "foo", + } + }.to change { User.count }.by(0) expect(response).to have_gitlab_http_status(409) - expect(json_response['message']).to eq('Email has already been taken') - end - - it 'returns 409 conflict error if same username exists' do - expect do - post api('/users', admin), - params: { - name: 'foo', - email: 'foo@example.com', - password: 'password', - username: 'test' - } - end.to change { User.count }.by(0) + expect(json_response["message"]).to eq("Email has already been taken") + end + + it "returns 409 conflict error if same username exists" do + expect { + post api("/users", admin), + params: { + name: "foo", + email: "foo@example.com", + password: "password", + username: "test", + } + }.to change { User.count }.by(0) expect(response).to have_gitlab_http_status(409) - expect(json_response['message']).to eq('Username has already been taken') - end - - it 'returns 409 conflict error if same username exists (case insensitive)' do - expect do - post api('/users', admin), - params: { - name: 'foo', - email: 'foo@example.com', - password: 'password', - username: 'TEST' - } - end.to change { User.count }.by(0) + expect(json_response["message"]).to eq("Username has already been taken") + end + + it "returns 409 conflict error if same username exists (case insensitive)" do + expect { + post api("/users", admin), + params: { + name: "foo", + email: "foo@example.com", + password: "password", + username: "TEST", + } + }.to change { User.count }.by(0) expect(response).to have_gitlab_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 - it 'creates user with new identity' do - post api("/users", admin), params: attributes_for(:user, provider: 'github', extern_uid: '67890') + it "creates user with new identity" do + post api("/users", admin), params: attributes_for(:user, provider: "github", extern_uid: "67890") expect(response).to have_gitlab_http_status(201) - expect(json_response['identities'].first['extern_uid']).to eq('67890') - expect(json_response['identities'].first['provider']).to eq('github') + expect(json_response["identities"].first["extern_uid"]).to eq("67890") + expect(json_response["identities"].first["provider"]).to eq("github") end end context "scopes" do let(:user) { admin } - let(:path) { '/users' } + let(:path) { "/users" } let(:api_call) { method(:api) } include_examples 'does not allow the "read_user" scope' @@ -605,42 +605,42 @@ describe API::Users do let!(:admin_user) { create(:admin) } it "updates user with new bio" do - put api("/users/#{user.id}", admin), params: { bio: 'new test bio' } + put api("/users/#{user.id}", admin), params: {bio: "new test bio"} expect(response).to have_gitlab_http_status(200) - expect(json_response['bio']).to eq('new test bio') - expect(user.reload.bio).to eq('new test bio') + expect(json_response["bio"]).to eq("new test bio") + expect(user.reload.bio).to eq("new test bio") end it "updates user with new password and forces reset on next login" do - put api("/users/#{user.id}", admin), params: { password: '12345678' } + put api("/users/#{user.id}", admin), params: {password: "12345678"} expect(response).to have_gitlab_http_status(200) expect(user.reload.password_expires_at).to be <= Time.now end it "updates user with organization" do - put api("/users/#{user.id}", admin), params: { organization: 'GitLab' } + put api("/users/#{user.id}", admin), params: {organization: "GitLab"} expect(response).to have_gitlab_http_status(200) - expect(json_response['organization']).to eq('GitLab') - expect(user.reload.organization).to eq('GitLab') + expect(json_response["organization"]).to eq("GitLab") + expect(user.reload.organization).to eq("GitLab") end - it 'updates user with avatar' do - put api("/users/#{user.id}", admin), params: { avatar: fixture_file_upload('spec/fixtures/banana_sample.gif', 'image/gif') } + it "updates user with avatar" do + put api("/users/#{user.id}", admin), params: {avatar: fixture_file_upload("spec/fixtures/banana_sample.gif", "image/gif")} user.reload expect(user.avatar).to be_present expect(response).to have_gitlab_http_status(200) - expect(json_response['avatar_url']).to include(user.avatar_path) + expect(json_response["avatar_url"]).to include(user.avatar_path) end - it 'updates user with a new email' do + it "updates user with a new email" do old_email = user.email old_notification_email = user.notification_email - put api("/users/#{user.id}", admin), params: { email: 'new@email.com' } + put api("/users/#{user.id}", admin), params: {email: "new@email.com"} user.reload @@ -648,66 +648,66 @@ describe API::Users do expect(user).to be_confirmed expect(user.email).to eq(old_email) expect(user.notification_email).to eq(old_notification_email) - expect(user.unconfirmed_email).to eq('new@email.com') + expect(user.unconfirmed_email).to eq("new@email.com") end - it 'skips reconfirmation when requested' do - put api("/users/#{user.id}", admin), params: { email: 'new@email.com', skip_reconfirmation: true } + it "skips reconfirmation when requested" do + put api("/users/#{user.id}", admin), params: {email: "new@email.com", skip_reconfirmation: true} user.reload expect(response).to have_gitlab_http_status(200) expect(user).to be_confirmed - expect(user.email).to eq('new@email.com') + expect(user.email).to eq("new@email.com") end - it 'updates user with his own username' do - put api("/users/#{user.id}", admin), params: { username: user.username } + it "updates user with his own username" do + put api("/users/#{user.id}", admin), params: {username: user.username} expect(response).to have_gitlab_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) end it "updates user's existing identity" do - put api("/users/#{omniauth_user.id}", admin), params: { provider: 'ldapmain', extern_uid: '654321' } + put api("/users/#{omniauth_user.id}", admin), params: {provider: "ldapmain", extern_uid: "654321"} expect(response).to have_gitlab_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 - it 'updates user with new identity' do - put api("/users/#{user.id}", admin), params: { provider: 'github', extern_uid: 'john' } + it "updates user with new identity" do + put api("/users/#{user.id}", admin), params: {provider: "github", extern_uid: "john"} expect(response).to have_gitlab_http_status(200) - expect(user.reload.identities.first.extern_uid).to eq('john') - expect(user.reload.identities.first.provider).to eq('github') + expect(user.reload.identities.first.extern_uid).to eq("john") + expect(user.reload.identities.first.provider).to eq("github") end it "updates admin status" do - put api("/users/#{user.id}", admin), params: { admin: true } + put api("/users/#{user.id}", admin), params: {admin: true} expect(response).to have_gitlab_http_status(200) expect(user.reload.admin).to eq(true) end it "updates external status" do - put api("/users/#{user.id}", admin), params: { external: true } + put api("/users/#{user.id}", admin), params: {external: true} expect(response.status).to eq 200 - expect(json_response['external']).to eq(true) + expect(json_response["external"]).to eq(true) expect(user.reload.external?).to be_truthy end it "updates private profile" do - put api("/users/#{user.id}", admin), params: { private_profile: true } + put api("/users/#{user.id}", admin), params: {private_profile: true} expect(response).to have_gitlab_http_status(200) expect(user.reload.private_profile).to eq(true) end it "does not update admin status" do - put api("/users/#{admin_user.id}", admin), params: { can_create_group: false } + put api("/users/#{admin_user.id}", admin), params: {can_create_group: false} expect(response).to have_gitlab_http_status(200) expect(admin_user.reload.admin).to eq(true) @@ -715,27 +715,27 @@ describe API::Users do end it "does not allow invalid update" do - put api("/users/#{user.id}", admin), params: { email: 'invalid email' } + put api("/users/#{user.id}", admin), params: {email: "invalid email"} expect(response).to have_gitlab_http_status(400) - expect(user.reload.email).not_to eq('invalid email') + expect(user.reload.email).not_to eq("invalid email") end - context 'when the current user is not an admin' do + context "when the current user is not an admin" do it "is not available" do - expect do + expect { put api("/users/#{user.id}", user), params: attributes_for(:user) - end.not_to change { user.reload.attributes } + }.not_to change { user.reload.attributes } expect(response).to have_gitlab_http_status(403) end end it "returns 404 for non-existing user" do - put api("/users/0", admin), params: { bio: 'update should fail' } + put api("/users/0", admin), params: {bio: "update should fail"} expect(response).to have_gitlab_http_status(404) - expect(json_response['message']).to eq('404 User Not Found') + expect(json_response["message"]).to eq("404 User Not Found") end it "returns a 404 if invalid ID" do @@ -744,64 +744,64 @@ describe API::Users do expect(response).to have_gitlab_http_status(404) end - it 'returns 400 error if user does not validate' do + it "returns 400 error if user does not validate" do put api("/users/#{user.id}", admin), - params: { - password: 'pass', - email: 'test@example.com', - username: 'test!', - name: 'test', - bio: 'g' * 256, - projects_limit: -1 - } + params: { + password: "pass", + email: "test@example.com", + username: "test!", + name: "test", + bio: "g" * 256, + projects_limit: -1, + } expect(response).to have_gitlab_http_status(400) - expect(json_response['message']['password']) - .to eq(['is too short (minimum is 8 characters)']) - expect(json_response['message']['bio']) - .to eq(['is too long (maximum is 255 characters)']) - expect(json_response['message']['projects_limit']) - .to eq(['must be greater than or equal to 0']) - expect(json_response['message']['username']) + expect(json_response["message"]["password"]) + .to eq(["is too short (minimum is 8 characters)"]) + expect(json_response["message"]["bio"]) + .to eq(["is too long (maximum is 255 characters)"]) + expect(json_response["message"]["projects_limit"]) + .to eq(["must be greater than or equal to 0"]) + expect(json_response["message"]["username"]) .to eq([Gitlab::PathRegex.namespace_format_message]) end - it 'returns 400 if provider is missing for identity update' do - put api("/users/#{omniauth_user.id}", admin), params: { extern_uid: '654321' } + it "returns 400 if provider is missing for identity update" do + put api("/users/#{omniauth_user.id}", admin), params: {extern_uid: "654321"} expect(response).to have_gitlab_http_status(400) end - it 'returns 400 if external UID is missing for identity update' do - put api("/users/#{omniauth_user.id}", admin), params: { provider: 'ldap' } + it "returns 400 if external UID is missing for identity update" do + put api("/users/#{omniauth_user.id}", admin), params: {provider: "ldap"} expect(response).to have_gitlab_http_status(400) end context "with existing user" do before do - post api("/users", admin), params: { email: 'test@example.com', password: 'password', username: 'test', name: 'test' } - post api("/users", admin), params: { email: 'foo@bar.com', password: 'password', username: 'john', name: 'john' } + post api("/users", admin), params: {email: "test@example.com", password: "password", username: "test", name: "test"} + post api("/users", admin), params: {email: "foo@bar.com", password: "password", username: "john", name: "john"} @user = User.all.last end - it 'returns 409 conflict error if email address exists' do - put api("/users/#{@user.id}", admin), params: { email: 'test@example.com' } + it "returns 409 conflict error if email address exists" do + put api("/users/#{@user.id}", admin), params: {email: "test@example.com"} expect(response).to have_gitlab_http_status(409) expect(@user.reload.email).to eq(@user.email) end - it 'returns 409 conflict error if username taken' do + it "returns 409 conflict error if username taken" do @user_id = User.all.last.id - put api("/users/#{@user.id}", admin), params: { username: 'test' } + put api("/users/#{@user.id}", admin), params: {username: "test"} expect(response).to have_gitlab_http_status(409) expect(@user.reload.username).to eq(@user.username) end - it 'returns 409 conflict error if username taken (case insensitive)' do + it "returns 409 conflict error if username taken (case insensitive)" do @user_id = User.all.last.id - put api("/users/#{@user.id}", admin), params: { username: 'TEST' } + put api("/users/#{@user.id}", admin), params: {username: "TEST"} expect(response).to have_gitlab_http_status(409) expect(@user.reload.username).to eq(@user.username) @@ -815,24 +815,24 @@ describe API::Users do end it "does not create invalid ssh key" do - post api("/users/#{user.id}/keys", admin), params: { title: "invalid key" } + post api("/users/#{user.id}/keys", admin), params: {title: "invalid key"} expect(response).to have_gitlab_http_status(400) - expect(json_response['error']).to eq('key is missing') + expect(json_response["error"]).to eq("key is missing") end - it 'does not create key without title' do - post api("/users/#{user.id}/keys", admin), params: { key: 'some key' } + it "does not create key without title" do + post api("/users/#{user.id}/keys", admin), params: {key: "some key"} expect(response).to have_gitlab_http_status(400) - expect(json_response['error']).to eq('title is missing') + expect(json_response["error"]).to eq("title is missing") end it "creates ssh key" do key_attrs = attributes_for :key - expect do + expect { post api("/users/#{user.id}/keys", admin), params: key_attrs - end.to change { user.keys.count }.by(1) + }.to change { user.keys.count }.by(1) end it "returns 400 for invalid ID" do @@ -841,17 +841,17 @@ describe API::Users do end end - describe 'GET /user/:id/keys' do - it 'returns 404 for non-existing user' do + describe "GET /user/:id/keys" do + it "returns 404 for non-existing user" do user_id = not_existing_user_id get api("/users/#{user_id}/keys") expect(response).to have_gitlab_http_status(404) - expect(json_response['message']).to eq('404 User Not Found') + expect(json_response["message"]).to eq("404 User Not Found") end - it 'returns array of ssh keys' do + it "returns array of ssh keys" do user.keys << key user.save @@ -860,111 +860,111 @@ describe API::Users do expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers 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 - describe 'DELETE /user/:id/keys/:key_id' do + describe "DELETE /user/:id/keys/:key_id" do before do admin end - context 'when unauthenticated' do - it 'returns authentication error' do + context "when unauthenticated" do + it "returns authentication error" do delete api("/users/#{user.id}/keys/42") expect(response).to have_gitlab_http_status(401) end end - context 'when authenticated' do - it 'deletes existing key' do + context "when authenticated" do + it "deletes existing key" do user.keys << key user.save - expect do + expect { delete api("/users/#{user.id}/keys/#{key.id}", admin) expect(response).to have_gitlab_http_status(204) - end.to change { user.keys.count }.by(-1) + }.to change { user.keys.count }.by(-1) end - it_behaves_like '412 response' do + it_behaves_like "412 response" do let(:request) { api("/users/#{user.id}/keys/#{key.id}", admin) } end - it 'returns 404 error if user not found' do + it "returns 404 error if user not found" do user.keys << key user.save delete api("/users/0/keys/#{key.id}", admin) expect(response).to have_gitlab_http_status(404) - expect(json_response['message']).to eq('404 User Not Found') + expect(json_response["message"]).to eq("404 User Not Found") end - it 'returns 404 error if key not foud' do + it "returns 404 error if key not foud" do delete api("/users/#{user.id}/keys/42", admin) expect(response).to have_gitlab_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 - describe 'POST /users/:id/keys' do + describe "POST /users/:id/keys" do before do admin end - it 'does not create invalid GPG key' do + it "does not create invalid GPG key" do post api("/users/#{user.id}/gpg_keys", admin) expect(response).to have_gitlab_http_status(400) - expect(json_response['error']).to eq('key is missing') + expect(json_response["error"]).to eq("key is missing") end - it 'creates GPG key' do + it "creates GPG key" do key_attrs = attributes_for :gpg_key - expect do + expect { post api("/users/#{user.id}/gpg_keys", admin), params: key_attrs expect(response).to have_gitlab_http_status(201) - end.to change { user.gpg_keys.count }.by(1) + }.to change { user.gpg_keys.count }.by(1) end - it 'returns 400 for invalid ID' do - post api('/users/0/gpg_keys', admin) + it "returns 400 for invalid ID" do + post api("/users/0/gpg_keys", admin) expect(response).to have_gitlab_http_status(400) end end - describe 'GET /user/:id/gpg_keys' do + describe "GET /user/:id/gpg_keys" do before do admin end - context 'when unauthenticated' do - it 'returns authentication error' do + context "when unauthenticated" do + it "returns authentication error" do get api("/users/#{user.id}/gpg_keys") expect(response).to have_gitlab_http_status(401) end end - context 'when authenticated' do - it 'returns 404 for non-existing user' do - get api('/users/0/gpg_keys', admin) + context "when authenticated" do + it "returns 404 for non-existing user" do + get api("/users/0/gpg_keys", admin) expect(response).to have_gitlab_http_status(404) - expect(json_response['message']).to eq('404 User Not Found') + expect(json_response["message"]).to eq("404 User Not Found") end - it 'returns 404 error if key not foud' do + it "returns 404 error if key not foud" do delete api("/users/#{user.id}/gpg_keys/42", admin) expect(response).to have_gitlab_http_status(404) - expect(json_response['message']).to eq('404 GPG Key Not Found') + expect(json_response["message"]).to eq("404 GPG Key Not Found") end - it 'returns array of GPG keys' do + it "returns array of GPG keys" do user.gpg_keys << gpg_key user.save @@ -973,95 +973,95 @@ describe API::Users do expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response).to be_an Array - expect(json_response.first['key']).to eq(gpg_key.key) + expect(json_response.first["key"]).to eq(gpg_key.key) end end end - describe 'DELETE /user/:id/gpg_keys/:key_id' do + describe "DELETE /user/:id/gpg_keys/:key_id" do before do admin end - context 'when unauthenticated' do - it 'returns authentication error' do + context "when unauthenticated" do + it "returns authentication error" do delete api("/users/#{user.id}/keys/42") expect(response).to have_gitlab_http_status(401) end end - context 'when authenticated' do - it 'deletes existing key' do + context "when authenticated" do + it "deletes existing key" do user.gpg_keys << gpg_key user.save - expect do + expect { delete api("/users/#{user.id}/gpg_keys/#{gpg_key.id}", admin) expect(response).to have_gitlab_http_status(204) - end.to change { user.gpg_keys.count }.by(-1) + }.to change { user.gpg_keys.count }.by(-1) end - it 'returns 404 error if user not found' do + it "returns 404 error if user not found" do user.keys << key user.save delete api("/users/0/gpg_keys/#{gpg_key.id}", admin) expect(response).to have_gitlab_http_status(404) - expect(json_response['message']).to eq('404 User Not Found') + expect(json_response["message"]).to eq("404 User Not Found") end - it 'returns 404 error if key not foud' do + it "returns 404 error if key not foud" do delete api("/users/#{user.id}/gpg_keys/42", admin) expect(response).to have_gitlab_http_status(404) - expect(json_response['message']).to eq('404 GPG Key Not Found') + expect(json_response["message"]).to eq("404 GPG Key Not Found") end end end - describe 'POST /user/:id/gpg_keys/:key_id/revoke' do + describe "POST /user/:id/gpg_keys/:key_id/revoke" do before do admin end - context 'when unauthenticated' do - it 'returns authentication error' do + context "when unauthenticated" do + it "returns authentication error" do post api("/users/#{user.id}/gpg_keys/42/revoke") expect(response).to have_gitlab_http_status(401) end end - context 'when authenticated' do - it 'revokes existing key' do + context "when authenticated" do + it "revokes existing key" do user.gpg_keys << gpg_key user.save - expect do + expect { post api("/users/#{user.id}/gpg_keys/#{gpg_key.id}/revoke", admin) expect(response).to have_gitlab_http_status(:accepted) - end.to change { user.gpg_keys.count }.by(-1) + }.to change { user.gpg_keys.count }.by(-1) end - it 'returns 404 error if user not found' do + it "returns 404 error if user not found" do user.gpg_keys << gpg_key user.save post api("/users/0/gpg_keys/#{gpg_key.id}/revoke", admin) expect(response).to have_gitlab_http_status(404) - expect(json_response['message']).to eq('404 User Not Found') + expect(json_response["message"]).to eq("404 User Not Found") end - it 'returns 404 error if key not foud' do + it "returns 404 error if key not foud" do post api("/users/#{user.id}/gpg_keys/42/revoke", admin) expect(response).to have_gitlab_http_status(404) - expect(json_response['message']).to eq('404 GPG Key Not Found') + expect(json_response["message"]).to eq("404 GPG Key Not Found") end end end @@ -1075,14 +1075,14 @@ describe API::Users do post api("/users/#{user.id}/emails", admin), params: {} expect(response).to have_gitlab_http_status(400) - expect(json_response['error']).to eq('email is missing') + expect(json_response["error"]).to eq("email is missing") end it "creates unverified email" do email_attrs = attributes_for :email - expect do + expect { post api("/users/#{user.id}/emails", admin), params: email_attrs - end.to change { user.emails.count }.by(1) + }.to change { user.emails.count }.by(1) email = Email.find_by(user_id: user.id, email: email_attrs[:email]) expect(email).not_to be_confirmed @@ -1107,26 +1107,26 @@ describe API::Users do end end - describe 'GET /user/:id/emails' do + describe "GET /user/:id/emails" do before do admin end - context 'when unauthenticated' do - it 'returns authentication error' do + context "when unauthenticated" do + it "returns authentication error" do get api("/users/#{user.id}/emails") expect(response).to have_gitlab_http_status(401) end end - context 'when authenticated' do - it 'returns 404 for non-existing user' do - get api('/users/0/emails', admin) + context "when authenticated" do + it "returns 404 for non-existing user" do + get api("/users/0/emails", admin) expect(response).to have_gitlab_http_status(404) - expect(json_response['message']).to eq('404 User Not Found') + expect(json_response["message"]).to eq("404 User Not Found") end - it 'returns array of emails' do + it "returns array of emails" do user.emails << email user.save @@ -1135,7 +1135,7 @@ describe API::Users do expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers 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 it "returns a 404 for invalid ID" do @@ -1146,46 +1146,46 @@ describe API::Users do end end - describe 'DELETE /user/:id/emails/:email_id' do + describe "DELETE /user/:id/emails/:email_id" do before do admin end - context 'when unauthenticated' do - it 'returns authentication error' do + context "when unauthenticated" do + it "returns authentication error" do delete api("/users/#{user.id}/emails/42") expect(response).to have_gitlab_http_status(401) end end - context 'when authenticated' do - it 'deletes existing email' do + context "when authenticated" do + it "deletes existing email" do user.emails << email user.save - expect do + expect { delete api("/users/#{user.id}/emails/#{email.id}", admin) expect(response).to have_gitlab_http_status(204) - end.to change { user.emails.count }.by(-1) + }.to change { user.emails.count }.by(-1) end - it_behaves_like '412 response' do + it_behaves_like "412 response" do let(:request) { api("/users/#{user.id}/emails/#{email.id}", admin) } end - it 'returns 404 error if user not found' do + it "returns 404 error if user not found" do user.emails << email user.save delete api("/users/0/emails/#{email.id}", admin) expect(response).to have_gitlab_http_status(404) - expect(json_response['message']).to eq('404 User Not Found') + expect(json_response["message"]).to eq("404 User Not Found") end - it 'returns 404 error if email not foud' do + it "returns 404 error if email not foud" do delete api("/users/#{user.id}/emails/42", admin) expect(response).to have_gitlab_http_status(404) - expect(json_response['message']).to eq('404 Email Not Found') + expect(json_response["message"]).to eq("404 Email Not Found") end it "returns a 404 for invalid ID" do @@ -1212,7 +1212,7 @@ describe API::Users do expect { Namespace.find(namespace.id) }.to raise_error ActiveRecord::RecordNotFound end - it_behaves_like '412 response' do + it_behaves_like "412 response" do let(:request) { api("/users/#{user.id}", admin) } end @@ -1229,7 +1229,7 @@ describe API::Users do it "returns 404 for non-existing user" do perform_enqueued_jobs { delete api("/users/0", admin) } expect(response).to have_gitlab_http_status(404) - expect(json_response['message']).to eq('404 User Not Found') + expect(json_response["message"]).to eq("404 User Not Found") end it "returns a 404 for invalid ID" do @@ -1261,22 +1261,22 @@ describe API::Users do describe "GET /user" do let(:personal_access_token) { create(:personal_access_token, user: user).token } - shared_examples 'get user info' do |version| - context 'with regular user' do - context 'with personal access token' do - it 'returns 403 without private token when sudo is defined' do + shared_examples "get user info" do |version| + context "with regular user" do + context "with personal access token" do + it "returns 403 without private token when sudo is defined" do get api("/user?private_token=#{personal_access_token}&sudo=123", version: version) expect(response).to have_gitlab_http_status(403) end end - it 'returns current user without private token when sudo not defined' do + it "returns current user without private token when sudo not defined" do get api("/user", user, version: version) expect(response).to have_gitlab_http_status(200) - expect(response).to match_response_schema('public_api/v4/user/public') - expect(json_response['id']).to eq(user.id) + expect(response).to match_response_schema("public_api/v4/user/public") + expect(json_response["id"]).to eq(user.id) end context "scopes" do @@ -1287,27 +1287,27 @@ describe API::Users do end end - context 'with admin' do + context "with admin" do let(:admin_personal_access_token) { create(:personal_access_token, user: admin).token } - context 'with personal access token' do - it 'returns 403 without private token when sudo defined' do + context "with personal access token" do + it "returns 403 without private token when sudo defined" do get api("/user?private_token=#{admin_personal_access_token}&sudo=#{user.id}", version: version) expect(response).to have_gitlab_http_status(403) end - it 'returns initial current user without private token but with is_admin when sudo not defined' do + it "returns initial current user without private token but with is_admin when sudo not defined" do get api("/user?private_token=#{admin_personal_access_token}", version: version) expect(response).to have_gitlab_http_status(200) - expect(response).to match_response_schema('public_api/v4/user/admin') - expect(json_response['id']).to eq(admin.id) + expect(response).to match_response_schema("public_api/v4/user/admin") + expect(json_response["id"]).to eq(admin.id) end end end - context 'with unauthenticated user' do + context "with unauthenticated user" do it "returns 401 error if user is unauthenticated" do get api("/user", version: version) @@ -1316,8 +1316,8 @@ describe API::Users do end end - it_behaves_like 'get user info', 'v3' - it_behaves_like 'get user info', 'v4' + it_behaves_like "get user info", "v3" + it_behaves_like "get user info", "v4" end describe "GET /user/keys" do @@ -1363,7 +1363,7 @@ describe API::Users do get api("/user/keys/42", user) expect(response).to have_gitlab_http_status(404) - expect(json_response['message']).to eq('404 Key Not Found') + expect(json_response["message"]).to eq("404 Key Not Found") end it "returns 404 error if admin accesses user's ssh key" do @@ -1372,7 +1372,7 @@ describe API::Users do admin get api("/user/keys/#{key.id}", admin) expect(response).to have_gitlab_http_status(404) - expect(json_response['message']).to eq('404 Key Not Found') + expect(json_response["message"]).to eq("404 Key Not Found") end it "returns 404 for invalid ID" do @@ -1392,33 +1392,33 @@ describe API::Users do describe "POST /user/keys" do it "creates ssh key" do key_attrs = attributes_for :key - expect do + expect { post api("/user/keys", user), params: key_attrs - end.to change { user.keys.count }.by(1) + }.to change { user.keys.count }.by(1) expect(response).to have_gitlab_http_status(201) end it "returns a 401 error if unauthorized" do - post api("/user/keys"), params: { title: 'some title', key: 'some key' } + post api("/user/keys"), params: {title: "some title", key: "some key"} expect(response).to have_gitlab_http_status(401) end it "does not create ssh key without key" do - post api("/user/keys", user), params: { title: 'title' } + post api("/user/keys", user), params: {title: "title"} expect(response).to have_gitlab_http_status(400) - expect(json_response['error']).to eq('key is missing') + expect(json_response["error"]).to eq("key is missing") end - it 'does not create ssh key without title' do - post api('/user/keys', user), params: { key: 'some key' } + it "does not create ssh key without title" do + post api("/user/keys", user), params: {key: "some key"} expect(response).to have_gitlab_http_status(400) - expect(json_response['error']).to eq('title is missing') + expect(json_response["error"]).to eq("title is missing") end it "does not create ssh key without title" do - post api("/user/keys", user), params: { key: "somekey" } + post api("/user/keys", user), params: {key: "somekey"} expect(response).to have_gitlab_http_status(400) end end @@ -1428,14 +1428,14 @@ describe API::Users do user.keys << key user.save - expect do + expect { delete api("/user/keys/#{key.id}", user) expect(response).to have_gitlab_http_status(204) - end.to change { user.keys.count}.by(-1) + }.to change { user.keys.count}.by(-1) end - it_behaves_like '412 response' do + it_behaves_like "412 response" do let(:request) { api("/user/keys/#{key.id}", user) } end @@ -1443,7 +1443,7 @@ describe API::Users do delete api("/user/keys/42", user) expect(response).to have_gitlab_http_status(404) - expect(json_response['message']).to eq('404 Key Not Found') + expect(json_response["message"]).to eq("404 Key Not Found") end it "returns 401 error if unauthorized" do @@ -1460,30 +1460,30 @@ describe API::Users do end end - describe 'GET /user/gpg_keys' do - context 'when unauthenticated' do - it 'returns authentication error' do - get api('/user/gpg_keys') + describe "GET /user/gpg_keys" do + context "when unauthenticated" do + it "returns authentication error" do + get api("/user/gpg_keys") expect(response).to have_gitlab_http_status(401) end end - context 'when authenticated' do - it 'returns array of GPG keys' do + context "when authenticated" do + it "returns array of GPG keys" do user.gpg_keys << gpg_key user.save - get api('/user/gpg_keys', user) + get api("/user/gpg_keys", user) expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response).to be_an Array - expect(json_response.first['key']).to eq(gpg_key.key) + expect(json_response.first["key"]).to eq(gpg_key.key) end - context 'scopes' do - let(:path) { '/user/gpg_keys' } + context "scopes" do + let(:path) { "/user/gpg_keys" } let(:api_call) { method(:api) } include_examples 'allows the "read_user" scope' @@ -1491,22 +1491,22 @@ describe API::Users do end end - describe 'GET /user/gpg_keys/:key_id' do - it 'returns a single key' do + describe "GET /user/gpg_keys/:key_id" do + it "returns a single key" do user.gpg_keys << gpg_key user.save get api("/user/gpg_keys/#{gpg_key.id}", user) expect(response).to have_gitlab_http_status(200) - expect(json_response['key']).to eq(gpg_key.key) + expect(json_response["key"]).to eq(gpg_key.key) end - it 'returns 404 Not Found within invalid ID' do - get api('/user/gpg_keys/42', user) + it "returns 404 Not Found within invalid ID" do + get api("/user/gpg_keys/42", user) expect(response).to have_gitlab_http_status(404) - expect(json_response['message']).to eq('404 GPG Key Not Found') + expect(json_response["message"]).to eq("404 GPG Key Not Found") end it "returns 404 error if admin accesses user's GPG key" do @@ -1516,16 +1516,16 @@ describe API::Users do get api("/user/gpg_keys/#{gpg_key.id}", admin) expect(response).to have_gitlab_http_status(404) - expect(json_response['message']).to eq('404 GPG Key Not Found') + expect(json_response["message"]).to eq("404 GPG Key Not Found") end - it 'returns 404 for invalid ID' do - get api('/users/gpg_keys/ASDF', admin) + it "returns 404 for invalid ID" do + get api("/users/gpg_keys/ASDF", admin) expect(response).to have_gitlab_http_status(404) end - context 'scopes' do + context "scopes" do let(:path) { "/user/gpg_keys/#{gpg_key.id}" } let(:api_call) { method(:api) } @@ -1533,50 +1533,50 @@ describe API::Users do end end - describe 'POST /user/gpg_keys' do - it 'creates a GPG key' do + describe "POST /user/gpg_keys" do + it "creates a GPG key" do key_attrs = attributes_for :gpg_key - expect do - post api('/user/gpg_keys', user), params: key_attrs + expect { + post api("/user/gpg_keys", user), params: key_attrs expect(response).to have_gitlab_http_status(201) - end.to change { user.gpg_keys.count }.by(1) + }.to change { user.gpg_keys.count }.by(1) end - it 'returns a 401 error if unauthorized' do - post api('/user/gpg_keys'), params: { key: 'some key' } + it "returns a 401 error if unauthorized" do + post api("/user/gpg_keys"), params: {key: "some key"} expect(response).to have_gitlab_http_status(401) end - it 'does not create GPG key without key' do - post api('/user/gpg_keys', user) + it "does not create GPG key without key" do + post api("/user/gpg_keys", user) expect(response).to have_gitlab_http_status(400) - expect(json_response['error']).to eq('key is missing') + expect(json_response["error"]).to eq("key is missing") end end - describe 'POST /user/gpg_keys/:key_id/revoke' do - it 'revokes existing GPG key' do + describe "POST /user/gpg_keys/:key_id/revoke" do + it "revokes existing GPG key" do user.gpg_keys << gpg_key user.save - expect do + expect { post api("/user/gpg_keys/#{gpg_key.id}/revoke", user) expect(response).to have_gitlab_http_status(:accepted) - end.to change { user.gpg_keys.count}.by(-1) + }.to change { user.gpg_keys.count}.by(-1) end - it 'returns 404 if key ID not found' do - post api('/user/gpg_keys/42/revoke', user) + it "returns 404 if key ID not found" do + post api("/user/gpg_keys/42/revoke", user) expect(response).to have_gitlab_http_status(404) - expect(json_response['message']).to eq('404 GPG Key Not Found') + expect(json_response["message"]).to eq("404 GPG Key Not Found") end - it 'returns 401 error if unauthorized' do + it "returns 401 error if unauthorized" do user.gpg_keys << gpg_key user.save @@ -1585,33 +1585,33 @@ describe API::Users do expect(response).to have_gitlab_http_status(401) end - it 'returns a 404 for invalid ID' do - post api('/users/gpg_keys/ASDF/revoke', admin) + it "returns a 404 for invalid ID" do + post api("/users/gpg_keys/ASDF/revoke", admin) expect(response).to have_gitlab_http_status(404) end end - describe 'DELETE /user/gpg_keys/:key_id' do - it 'deletes existing GPG key' do + describe "DELETE /user/gpg_keys/:key_id" do + it "deletes existing GPG key" do user.gpg_keys << gpg_key user.save - expect do + expect { delete api("/user/gpg_keys/#{gpg_key.id}", user) expect(response).to have_gitlab_http_status(204) - end.to change { user.gpg_keys.count}.by(-1) + }.to change { user.gpg_keys.count}.by(-1) end - it 'returns 404 if key ID not found' do - delete api('/user/gpg_keys/42', user) + it "returns 404 if key ID not found" do + delete api("/user/gpg_keys/42", user) expect(response).to have_gitlab_http_status(404) - expect(json_response['message']).to eq('404 GPG Key Not Found') + expect(json_response["message"]).to eq("404 GPG Key Not Found") end - it 'returns 401 error if unauthorized' do + it "returns 401 error if unauthorized" do user.gpg_keys << gpg_key user.save @@ -1620,8 +1620,8 @@ describe API::Users do expect(response).to have_gitlab_http_status(401) end - it 'returns a 404 for invalid ID' do - delete api('/users/gpg_keys/ASDF', admin) + it "returns a 404 for invalid ID" do + delete api("/users/gpg_keys/ASDF", admin) expect(response).to have_gitlab_http_status(404) end @@ -1669,7 +1669,7 @@ describe API::Users do it "returns 404 Not Found within invalid ID" do get api("/user/emails/42", user) expect(response).to have_gitlab_http_status(404) - expect(json_response['message']).to eq('404 Email Not Found') + expect(json_response["message"]).to eq("404 Email Not Found") end it "returns 404 error if admin accesses user's email" do @@ -1678,7 +1678,7 @@ describe API::Users do admin get api("/user/emails/#{email.id}", admin) expect(response).to have_gitlab_http_status(404) - expect(json_response['message']).to eq('404 Email Not Found') + expect(json_response["message"]).to eq("404 Email Not Found") end it "returns 404 for invalid ID" do @@ -1698,14 +1698,14 @@ describe API::Users do describe "POST /user/emails" do it "creates email" do email_attrs = attributes_for :email - expect do + expect { post api("/user/emails", user), params: email_attrs - end.to change { user.emails.count }.by(1) + }.to change { user.emails.count }.by(1) expect(response).to have_gitlab_http_status(201) end it "returns a 401 error if unauthorized" do - post api("/user/emails"), params: { email: 'some email' } + post api("/user/emails"), params: {email: "some email"} expect(response).to have_gitlab_http_status(401) end @@ -1713,7 +1713,7 @@ describe API::Users do post api("/user/emails", user), params: {} expect(response).to have_gitlab_http_status(400) - expect(json_response['error']).to eq('email is missing') + expect(json_response["error"]).to eq("email is missing") end end @@ -1722,14 +1722,14 @@ describe API::Users do user.emails << email user.save - expect do + expect { delete api("/user/emails/#{email.id}", user) expect(response).to have_gitlab_http_status(204) - end.to change { user.emails.count}.by(-1) + }.to change { user.emails.count}.by(-1) end - it_behaves_like '412 response' do + it_behaves_like "412 response" do let(:request) { api("/user/emails/#{email.id}", user) } end @@ -1737,7 +1737,7 @@ describe API::Users do delete api("/user/emails/42", user) expect(response).to have_gitlab_http_status(404) - expect(json_response['message']).to eq('404 Email Not Found') + expect(json_response["message"]).to eq("404 Email Not Found") end it "returns 401 error if unauthorized" do @@ -1754,71 +1754,71 @@ describe API::Users do end end - describe 'POST /users/:id/block' do + describe "POST /users/:id/block" do before do admin end - it 'blocks existing user' do + it "blocks existing user" do post api("/users/#{user.id}/block", admin) expect(response).to have_gitlab_http_status(201) - expect(user.reload.state).to eq('blocked') + expect(user.reload.state).to eq("blocked") end - it 'does not re-block ldap blocked users' do + it "does not re-block ldap blocked users" do post api("/users/#{ldap_blocked_user.id}/block", admin) expect(response).to have_gitlab_http_status(403) - expect(ldap_blocked_user.reload.state).to eq('ldap_blocked') + expect(ldap_blocked_user.reload.state).to eq("ldap_blocked") end - it 'does not be available for non admin users' do + it "does not be available for non admin users" do post api("/users/#{user.id}/block", user) expect(response).to have_gitlab_http_status(403) - expect(user.reload.state).to eq('active') + expect(user.reload.state).to eq("active") end - it 'returns a 404 error if user id not found' do - post api('/users/0/block', admin) + it "returns a 404 error if user id not found" do + post api("/users/0/block", admin) expect(response).to have_gitlab_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 - describe 'POST /users/:id/unblock' do - let(:blocked_user) { create(:user, state: 'blocked') } + describe "POST /users/:id/unblock" do + let(:blocked_user) { create(:user, state: "blocked") } before do admin end - it 'unblocks existing user' do + it "unblocks existing user" do post api("/users/#{user.id}/unblock", admin) expect(response).to have_gitlab_http_status(201) - expect(user.reload.state).to eq('active') + expect(user.reload.state).to eq("active") end - it 'unblocks a blocked user' do + it "unblocks a blocked user" do post api("/users/#{blocked_user.id}/unblock", admin) expect(response).to have_gitlab_http_status(201) - expect(blocked_user.reload.state).to eq('active') + expect(blocked_user.reload.state).to eq("active") end - it 'does not unblock ldap blocked users' do + it "does not unblock ldap blocked users" do post api("/users/#{ldap_blocked_user.id}/unblock", admin) expect(response).to have_gitlab_http_status(403) - expect(ldap_blocked_user.reload.state).to eq('ldap_blocked') + expect(ldap_blocked_user.reload.state).to eq("ldap_blocked") end - it 'does not be available for non admin users' do + it "does not be available for non admin users" do post api("/users/#{user.id}/unblock", user) expect(response).to have_gitlab_http_status(403) - expect(user.reload.state).to eq('active') + expect(user.reload.state).to eq("active") end - it 'returns a 404 error if user id not found' do - post api('/users/0/block', admin) + it "returns a 404 error if user id not found" do + post api("/users/0/block", admin) expect(response).to have_gitlab_http_status(404) - expect(json_response['message']).to eq('404 User Not Found') + expect(json_response["message"]).to eq("404 User Not Found") end it "returns a 404 for invalid ID" do @@ -1832,16 +1832,16 @@ describe API::Users do let!(:old_active_user) { create(:user, last_activity_on: Time.utc(2000, 1, 1)) } let!(:newly_active_user) { create(:user, last_activity_on: 2.days.ago.midday) } - context 'last activity as normal user' do - it 'has no permission' do + context "last activity as normal user" do + it "has no permission" do get api("/user/activities", user) expect(response).to have_gitlab_http_status(403) end end - context 'as admin' do - it 'returns the activities from the last 6 months' do + context "as admin" do + it "returns the activities from the last 6 months" do get api("/user/activities", admin) expect(response).to include_pagination_headers @@ -1849,13 +1849,13 @@ describe API::Users do activity = json_response.last - expect(activity['username']).to eq(newly_active_user.username) - expect(activity['last_activity_on']).to eq(2.days.ago.to_date.to_s) - expect(activity['last_activity_at']).to eq(2.days.ago.to_date.to_s) + expect(activity["username"]).to eq(newly_active_user.username) + expect(activity["last_activity_on"]).to eq(2.days.ago.to_date.to_s) + expect(activity["last_activity_at"]).to eq(2.days.ago.to_date.to_s) end - context 'passing a :from parameter' do - it 'returns the activities from the given date' do + context "passing a :from parameter" do + it "returns the activities from the given date" do get api("/user/activities?from=2000-1-1", admin) expect(response).to include_pagination_headers @@ -1863,64 +1863,64 @@ describe API::Users do activity = json_response.first - expect(activity['username']).to eq(old_active_user.username) - expect(activity['last_activity_on']).to eq(Time.utc(2000, 1, 1).to_date.to_s) - expect(activity['last_activity_at']).to eq(Time.utc(2000, 1, 1).to_date.to_s) + expect(activity["username"]).to eq(old_active_user.username) + expect(activity["last_activity_on"]).to eq(Time.utc(2000, 1, 1).to_date.to_s) + expect(activity["last_activity_at"]).to eq(Time.utc(2000, 1, 1).to_date.to_s) end end end end - describe 'GET /user/status' do - let(:path) { '/user/status' } - it_behaves_like 'rendering user status' + describe "GET /user/status" do + let(:path) { "/user/status" } + it_behaves_like "rendering user status" end - describe 'PUT /user/status' do - it 'saves the status' do - put api('/user/status', user), params: { emoji: 'smirk', message: 'hello world' } + describe "PUT /user/status" do + it "saves the status" do + put api("/user/status", user), params: {emoji: "smirk", message: "hello world"} expect(response).to have_gitlab_http_status(:success) - expect(json_response['emoji']).to eq('smirk') + expect(json_response["emoji"]).to eq("smirk") end - it 'renders errors when the status was invalid' do - put api('/user/status', user), params: { emoji: 'does not exist', message: 'hello world' } + it "renders errors when the status was invalid" do + put api("/user/status", user), params: {emoji: "does not exist", message: "hello world"} expect(response).to have_gitlab_http_status(400) - expect(json_response['message']['emoji']).to be_present + expect(json_response["message"]["emoji"]).to be_present end - it 'deletes the status when passing empty values' do - put api('/user/status', user) + it "deletes the status when passing empty values" do + put api("/user/status", user) expect(response).to have_gitlab_http_status(:success) expect(user.reload.status).to be_nil end end - describe 'GET /users/:user_id/impersonation_tokens' do + describe "GET /users/:user_id/impersonation_tokens" do let!(:active_personal_access_token) { create(:personal_access_token, user: user) } let!(:revoked_personal_access_token) { create(:personal_access_token, :revoked, user: user) } let!(:expired_personal_access_token) { create(:personal_access_token, :expired, user: user) } let!(:impersonation_token) { create(:personal_access_token, :impersonation, user: user) } let!(:revoked_impersonation_token) { create(:personal_access_token, :impersonation, :revoked, user: user) } - it 'returns a 404 error if user not found' do + it "returns a 404 error if user not found" do get api("/users/#{not_existing_user_id}/impersonation_tokens", admin) expect(response).to have_gitlab_http_status(404) - expect(json_response['message']).to eq('404 User Not Found') + expect(json_response["message"]).to eq("404 User Not Found") end - it 'returns a 403 error when authenticated as normal user' do + it "returns a 403 error when authenticated as normal user" do get api("/users/#{not_existing_user_id}/impersonation_tokens", user) expect(response).to have_gitlab_http_status(403) - expect(json_response['message']).to eq('403 Forbidden') + expect(json_response["message"]).to eq("403 Forbidden") end - it 'returns an array of all impersonated tokens' do + it "returns an array of all impersonated tokens" do get api("/users/#{user.id}/impersonation_tokens", admin) expect(response).to have_gitlab_http_status(200) @@ -1929,161 +1929,161 @@ describe API::Users do expect(json_response.size).to eq(2) end - it 'returns an array of active impersonation tokens if state active' do + it "returns an array of active impersonation tokens if state active" do get api("/users/#{user.id}/impersonation_tokens?state=active", admin) expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response).to be_an Array expect(json_response.size).to eq(1) - expect(json_response).to all(include('active' => true)) + expect(json_response).to all(include("active" => true)) end - it 'returns an array of inactive personal access tokens if active is set to false' do + it "returns an array of inactive personal access tokens if active is set to false" do get api("/users/#{user.id}/impersonation_tokens?state=inactive", admin) expect(response).to have_gitlab_http_status(200) expect(json_response).to be_an Array expect(json_response.size).to eq(1) - expect(json_response).to all(include('active' => false)) + expect(json_response).to all(include("active" => false)) end end - describe 'POST /users/:user_id/impersonation_tokens' do - let(:name) { 'my new pat' } - let(:expires_at) { '2016-12-28' } - let(:scopes) { %w(api read_user) } + describe "POST /users/:user_id/impersonation_tokens" do + let(:name) { "my new pat" } + let(:expires_at) { "2016-12-28" } + let(:scopes) { %w[api read_user] } let(:impersonation) { true } - it 'returns validation error if impersonation token misses some attributes' do + it "returns validation error if impersonation token misses some attributes" do post api("/users/#{user.id}/impersonation_tokens", admin) expect(response).to have_gitlab_http_status(400) - expect(json_response['error']).to eq('name is missing') + expect(json_response["error"]).to eq("name is missing") end - it 'returns a 404 error if user not found' do + it "returns a 404 error if user not found" do post api("/users/#{not_existing_user_id}/impersonation_tokens", admin), params: { name: name, - expires_at: expires_at + expires_at: expires_at, } expect(response).to have_gitlab_http_status(404) - expect(json_response['message']).to eq('404 User Not Found') + expect(json_response["message"]).to eq("404 User Not Found") end - it 'returns a 403 error when authenticated as normal user' do + it "returns a 403 error when authenticated as normal user" do post api("/users/#{user.id}/impersonation_tokens", user), params: { name: name, - expires_at: expires_at + expires_at: expires_at, } expect(response).to have_gitlab_http_status(403) - expect(json_response['message']).to eq('403 Forbidden') + expect(json_response["message"]).to eq("403 Forbidden") end - it 'creates a impersonation token' do + it "creates a impersonation token" do post api("/users/#{user.id}/impersonation_tokens", admin), params: { name: name, expires_at: expires_at, scopes: scopes, - impersonation: impersonation + impersonation: impersonation, } expect(response).to have_gitlab_http_status(201) - expect(json_response['name']).to eq(name) - expect(json_response['scopes']).to eq(scopes) - expect(json_response['expires_at']).to eq(expires_at) - expect(json_response['id']).to be_present - expect(json_response['created_at']).to be_present - expect(json_response['active']).to be_falsey - expect(json_response['revoked']).to be_falsey - expect(json_response['token']).to be_present - expect(json_response['impersonation']).to eq(impersonation) + expect(json_response["name"]).to eq(name) + expect(json_response["scopes"]).to eq(scopes) + expect(json_response["expires_at"]).to eq(expires_at) + expect(json_response["id"]).to be_present + expect(json_response["created_at"]).to be_present + expect(json_response["active"]).to be_falsey + expect(json_response["revoked"]).to be_falsey + expect(json_response["token"]).to be_present + expect(json_response["impersonation"]).to eq(impersonation) end end - describe 'GET /users/:user_id/impersonation_tokens/:impersonation_token_id' do + describe "GET /users/:user_id/impersonation_tokens/:impersonation_token_id" do let!(:personal_access_token) { create(:personal_access_token, user: user) } let!(:impersonation_token) { create(:personal_access_token, :impersonation, user: user) } - it 'returns 404 error if user not found' do + it "returns 404 error if user not found" do get api("/users/#{not_existing_user_id}/impersonation_tokens/1", admin) expect(response).to have_gitlab_http_status(404) - expect(json_response['message']).to eq('404 User Not Found') + expect(json_response["message"]).to eq("404 User Not Found") end - it 'returns a 404 error if impersonation token not found' do + it "returns a 404 error if impersonation token not found" do get api("/users/#{user.id}/impersonation_tokens/#{not_existing_pat_id}", admin) expect(response).to have_gitlab_http_status(404) - expect(json_response['message']).to eq('404 Impersonation Token Not Found') + expect(json_response["message"]).to eq("404 Impersonation Token Not Found") end - it 'returns a 404 error if token is not impersonation token' do + it "returns a 404 error if token is not impersonation token" do get api("/users/#{user.id}/impersonation_tokens/#{personal_access_token.id}", admin) expect(response).to have_gitlab_http_status(404) - expect(json_response['message']).to eq('404 Impersonation Token Not Found') + expect(json_response["message"]).to eq("404 Impersonation Token Not Found") end - it 'returns a 403 error when authenticated as normal user' do + it "returns a 403 error when authenticated as normal user" do get api("/users/#{user.id}/impersonation_tokens/#{impersonation_token.id}", user) expect(response).to have_gitlab_http_status(403) - expect(json_response['message']).to eq('403 Forbidden') + expect(json_response["message"]).to eq("403 Forbidden") end - it 'returns an impersonation token' do + it "returns an impersonation token" do get api("/users/#{user.id}/impersonation_tokens/#{impersonation_token.id}", admin) expect(response).to have_gitlab_http_status(200) - expect(json_response['token']).not_to be_present - expect(json_response['impersonation']).to be_truthy + expect(json_response["token"]).not_to be_present + expect(json_response["impersonation"]).to be_truthy end end - describe 'DELETE /users/:user_id/impersonation_tokens/:impersonation_token_id' do + describe "DELETE /users/:user_id/impersonation_tokens/:impersonation_token_id" do let!(:personal_access_token) { create(:personal_access_token, user: user) } let!(:impersonation_token) { create(:personal_access_token, :impersonation, user: user) } - it 'returns a 404 error if user not found' do + it "returns a 404 error if user not found" do delete api("/users/#{not_existing_user_id}/impersonation_tokens/1", admin) expect(response).to have_gitlab_http_status(404) - expect(json_response['message']).to eq('404 User Not Found') + expect(json_response["message"]).to eq("404 User Not Found") end - it 'returns a 404 error if impersonation token not found' do + it "returns a 404 error if impersonation token not found" do delete api("/users/#{user.id}/impersonation_tokens/#{not_existing_pat_id}", admin) expect(response).to have_gitlab_http_status(404) - expect(json_response['message']).to eq('404 Impersonation Token Not Found') + expect(json_response["message"]).to eq("404 Impersonation Token Not Found") end - it 'returns a 404 error if token is not impersonation token' do + it "returns a 404 error if token is not impersonation token" do delete api("/users/#{user.id}/impersonation_tokens/#{personal_access_token.id}", admin) expect(response).to have_gitlab_http_status(404) - expect(json_response['message']).to eq('404 Impersonation Token Not Found') + expect(json_response["message"]).to eq("404 Impersonation Token Not Found") end - it 'returns a 403 error when authenticated as normal user' do + it "returns a 403 error when authenticated as normal user" do delete api("/users/#{user.id}/impersonation_tokens/#{impersonation_token.id}", user) expect(response).to have_gitlab_http_status(403) - expect(json_response['message']).to eq('403 Forbidden') + expect(json_response["message"]).to eq("403 Forbidden") end - it_behaves_like '412 response' do + it_behaves_like "412 response" do let(:request) { api("/users/#{user.id}/impersonation_tokens/#{impersonation_token.id}", admin) } end - it 'revokes a impersonation token' do + it "revokes a impersonation token" do delete api("/users/#{user.id}/impersonation_tokens/#{impersonation_token.id}", admin) expect(response).to have_gitlab_http_status(204) @@ -2092,7 +2092,7 @@ describe API::Users do end end - it_behaves_like 'custom attributes endpoints', 'users' do + it_behaves_like "custom attributes endpoints", "users" do let(:attributable) { user } let(:other_attributable) { admin } end diff --git a/spec/requests/api/variables_spec.rb b/spec/requests/api/variables_spec.rb index 5df6baf0ddf..05e77d674f0 100644 --- a/spec/requests/api/variables_spec.rb +++ b/spec/requests/api/variables_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe API::Variables do let(:user) { create(:user) } @@ -8,9 +8,9 @@ describe API::Variables do let!(:developer) { create(:project_member, :developer, user: user2, project: project) } let!(:variable) { create(:ci_variable, project: project) } - describe 'GET /projects/:id/variables' do - context 'authorized user with proper permissions' do - it 'returns project variables' do + describe "GET /projects/:id/variables" do + context "authorized user with proper permissions" do + it "returns project variables" do get api("/projects/#{project.id}/variables", user) expect(response).to have_gitlab_http_status(200) @@ -18,16 +18,16 @@ describe API::Variables do end end - context 'authorized user with invalid permissions' do - it 'does not return project variables' do + context "authorized user with invalid permissions" do + it "does not return project variables" do get api("/projects/#{project.id}/variables", user2) expect(response).to have_gitlab_http_status(403) end end - context 'unauthorized user' do - it 'does not return project variables' do + context "unauthorized user" do + it "does not return project variables" do get api("/projects/#{project.id}/variables") expect(response).to have_gitlab_http_status(401) @@ -35,33 +35,33 @@ describe API::Variables do end end - describe 'GET /projects/:id/variables/:key' do - context 'authorized user with proper permissions' do - it 'returns project variable details' do + describe "GET /projects/:id/variables/:key" do + context "authorized user with proper permissions" do + it "returns project variable details" do get api("/projects/#{project.id}/variables/#{variable.key}", user) expect(response).to have_gitlab_http_status(200) - expect(json_response['value']).to eq(variable.value) - expect(json_response['protected']).to eq(variable.protected?) + expect(json_response["value"]).to eq(variable.value) + expect(json_response["protected"]).to eq(variable.protected?) end - it 'responds with 404 Not Found if requesting non-existing variable' do + it "responds with 404 Not Found if requesting non-existing variable" do get api("/projects/#{project.id}/variables/non_existing_variable", user) expect(response).to have_gitlab_http_status(404) end end - context 'authorized user with invalid permissions' do - it 'does not return project variable details' do + context "authorized user with invalid permissions" do + it "does not return project variable details" do get api("/projects/#{project.id}/variables/#{variable.key}", user2) expect(response).to have_gitlab_http_status(403) end end - context 'unauthorized user' do - it 'does not return project variable details' do + context "unauthorized user" do + it "does not return project variable details" do get api("/projects/#{project.id}/variables/#{variable.key}") expect(response).to have_gitlab_http_status(401) @@ -69,49 +69,49 @@ describe API::Variables do end end - describe 'POST /projects/:id/variables' do - context 'authorized user with proper permissions' do - it 'creates variable' do - expect do - post api("/projects/#{project.id}/variables", user), params: { key: 'TEST_VARIABLE_2', value: 'PROTECTED_VALUE_2', protected: true } - end.to change {project.variables.count}.by(1) + describe "POST /projects/:id/variables" do + context "authorized user with proper permissions" do + it "creates variable" do + expect { + post api("/projects/#{project.id}/variables", user), params: {key: "TEST_VARIABLE_2", value: "PROTECTED_VALUE_2", protected: true} + }.to change {project.variables.count}.by(1) expect(response).to have_gitlab_http_status(201) - expect(json_response['key']).to eq('TEST_VARIABLE_2') - expect(json_response['value']).to eq('PROTECTED_VALUE_2') - expect(json_response['protected']).to be_truthy + expect(json_response["key"]).to eq("TEST_VARIABLE_2") + expect(json_response["value"]).to eq("PROTECTED_VALUE_2") + expect(json_response["protected"]).to be_truthy end - it 'creates variable with optional attributes' do - expect do - post api("/projects/#{project.id}/variables", user), params: { key: 'TEST_VARIABLE_2', value: 'VALUE_2' } - end.to change {project.variables.count}.by(1) + it "creates variable with optional attributes" do + expect { + post api("/projects/#{project.id}/variables", user), params: {key: "TEST_VARIABLE_2", value: "VALUE_2"} + }.to change {project.variables.count}.by(1) expect(response).to have_gitlab_http_status(201) - expect(json_response['key']).to eq('TEST_VARIABLE_2') - expect(json_response['value']).to eq('VALUE_2') - expect(json_response['protected']).to be_falsey + expect(json_response["key"]).to eq("TEST_VARIABLE_2") + expect(json_response["value"]).to eq("VALUE_2") + expect(json_response["protected"]).to be_falsey end - it 'does not allow to duplicate variable key' do - expect do - post api("/projects/#{project.id}/variables", user), params: { key: variable.key, value: 'VALUE_2' } - end.to change {project.variables.count}.by(0) + it "does not allow to duplicate variable key" do + expect { + post api("/projects/#{project.id}/variables", user), params: {key: variable.key, value: "VALUE_2"} + }.to change {project.variables.count}.by(0) expect(response).to have_gitlab_http_status(400) end end - context 'authorized user with invalid permissions' do - it 'does not create variable' do + context "authorized user with invalid permissions" do + it "does not create variable" do post api("/projects/#{project.id}/variables", user2) expect(response).to have_gitlab_http_status(403) end end - context 'unauthorized user' do - it 'does not create variable' do + context "unauthorized user" do + it "does not create variable" do post api("/projects/#{project.id}/variables") expect(response).to have_gitlab_http_status(401) @@ -119,39 +119,39 @@ describe API::Variables do end end - describe 'PUT /projects/:id/variables/:key' do - context 'authorized user with proper permissions' do - it 'updates variable data' do + describe "PUT /projects/:id/variables/:key" do + context "authorized user with proper permissions" do + it "updates variable data" do initial_variable = project.variables.reload.first value_before = initial_variable.value - put api("/projects/#{project.id}/variables/#{variable.key}", user), params: { value: 'VALUE_1_UP', protected: true } + put api("/projects/#{project.id}/variables/#{variable.key}", user), params: {value: "VALUE_1_UP", protected: true} updated_variable = project.variables.reload.first expect(response).to have_gitlab_http_status(200) 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") expect(updated_variable).to be_protected end - it 'responds with 404 Not Found if requesting non-existing variable' do + it "responds with 404 Not Found if requesting non-existing variable" do put api("/projects/#{project.id}/variables/non_existing_variable", user) expect(response).to have_gitlab_http_status(404) end end - context 'authorized user with invalid permissions' do - it 'does not update variable' do + context "authorized user with invalid permissions" do + it "does not update variable" do put api("/projects/#{project.id}/variables/#{variable.key}", user2) expect(response).to have_gitlab_http_status(403) end end - context 'unauthorized user' do - it 'does not update variable' do + context "unauthorized user" do + it "does not update variable" do put api("/projects/#{project.id}/variables/#{variable.key}") expect(response).to have_gitlab_http_status(401) @@ -159,33 +159,33 @@ describe API::Variables do end end - describe 'DELETE /projects/:id/variables/:key' do - context 'authorized user with proper permissions' do - it 'deletes variable' do - expect do + describe "DELETE /projects/:id/variables/:key" do + context "authorized user with proper permissions" do + it "deletes variable" do + expect { delete api("/projects/#{project.id}/variables/#{variable.key}", user) expect(response).to have_gitlab_http_status(204) - end.to change {project.variables.count}.by(-1) + }.to change {project.variables.count}.by(-1) end - it 'responds with 404 Not Found if requesting non-existing variable' do + it "responds with 404 Not Found if requesting non-existing variable" do delete api("/projects/#{project.id}/variables/non_existing_variable", user) expect(response).to have_gitlab_http_status(404) end end - context 'authorized user with invalid permissions' do - it 'does not delete variable' do + context "authorized user with invalid permissions" do + it "does not delete variable" do delete api("/projects/#{project.id}/variables/#{variable.key}", user2) expect(response).to have_gitlab_http_status(403) end end - context 'unauthorized user' do - it 'does not delete variable' do + context "unauthorized user" do + it "does not delete variable" do delete api("/projects/#{project.id}/variables/#{variable.key}") expect(response).to have_gitlab_http_status(401) diff --git a/spec/requests/api/version_spec.rb b/spec/requests/api/version_spec.rb index 38b618191fb..645acf4f833 100644 --- a/spec/requests/api/version_spec.rb +++ b/spec/requests/api/version_spec.rb @@ -1,24 +1,24 @@ -require 'spec_helper' +require "spec_helper" describe API::Version do - describe 'GET /version' do - context 'when unauthenticated' do - it 'returns authentication error' do - get api('/version') + describe "GET /version" do + context "when unauthenticated" do + it "returns authentication error" do + get api("/version") expect(response).to have_gitlab_http_status(401) end end - context 'when authenticated' do + context "when authenticated" do let(:user) { create(:user) } - it 'returns the version information' do - get api('/version', user) + it "returns the version information" do + get api("/version", user) expect(response).to have_gitlab_http_status(200) - expect(json_response['version']).to eq(Gitlab::VERSION) - expect(json_response['revision']).to eq(Gitlab.revision) + expect(json_response["version"]).to eq(Gitlab::VERSION) + expect(json_response["revision"]).to eq(Gitlab.revision) end end end diff --git a/spec/requests/api/wikis_spec.rb b/spec/requests/api/wikis_spec.rb index d1b58aac104..1cd3e8a2ec4 100644 --- a/spec/requests/api/wikis_spec.rb +++ b/spec/requests/api/wikis_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" # For every API endpoint we test 3 states of wikis: # - disabled @@ -14,18 +14,18 @@ describe API::Wikis do let(:user) { create(:user) } let(:group) { create(:group).tap { |g| g.add_owner(user) } } let(:project_wiki) { create(:project_wiki, project: project, user: user) } - let(:payload) { { content: 'content', format: 'rdoc', title: 'title' } } - let(:expected_keys_with_content) { %w(content format slug title) } - let(:expected_keys_without_content) { %w(format slug title) } + let(:payload) { {content: "content", format: "rdoc", title: "title"} } + let(:expected_keys_with_content) { %w[content format slug title] } + let(:expected_keys_without_content) { %w[format slug title] } - shared_examples_for 'returns list of wiki pages' do - context 'when wiki has pages' do + shared_examples_for "returns list of wiki pages" do + context "when wiki has pages" do let!(:pages) do - [create(:wiki_page, wiki: project_wiki, attrs: { title: 'page1', content: 'content of page1' }), - create(:wiki_page, wiki: project_wiki, attrs: { title: 'page2.with.dot', content: 'content of page2' })] + [create(:wiki_page, wiki: project_wiki, attrs: {title: "page1", content: "content of page1"}), + create(:wiki_page, wiki: project_wiki, attrs: {title: "page2.with.dot", content: "content of page2"}),] end - it 'returns the list of wiki pages without content' do + it "returns the list of wiki pages without content" do get api(url, user) expect(response).to have_gitlab_http_status(200) @@ -33,27 +33,27 @@ describe API::Wikis do json_response.each_with_index do |page, index| expect(page.keys).to match_array(expected_keys_without_content) - expect(page['slug']).to eq(pages[index].slug) - expect(page['title']).to eq(pages[index].title) + expect(page["slug"]).to eq(pages[index].slug) + expect(page["title"]).to eq(pages[index].title) end end - it 'returns the list of wiki pages with content' do - get api(url, user), params: { with_content: 1 } + it "returns the list of wiki pages with content" do + get api(url, user), params: {with_content: 1} expect(response).to have_gitlab_http_status(200) expect(json_response.size).to eq(2) json_response.each_with_index do |page, index| expect(page.keys).to match_array(expected_keys_with_content) - expect(page['content']).to eq(pages[index].content) - expect(page['slug']).to eq(pages[index].slug) - expect(page['title']).to eq(pages[index].title) + expect(page["content"]).to eq(pages[index].content) + expect(page["slug"]).to eq(pages[index].slug) + expect(page["title"]).to eq(pages[index].title) end end end - it 'return the empty list of wiki pages' do + it "return the empty list of wiki pages" do get api(url, user) expect(response).to have_gitlab_http_status(200) @@ -61,28 +61,28 @@ describe API::Wikis do end end - shared_examples_for 'returns wiki page' do - it 'returns the wiki page' do + shared_examples_for "returns wiki page" do + it "returns the wiki page" do expect(response).to have_gitlab_http_status(200) expect(json_response.size).to eq(4) expect(json_response.keys).to match_array(expected_keys_with_content) - expect(json_response['content']).to eq(page.content) - expect(json_response['slug']).to eq(page.slug) - expect(json_response['title']).to eq(page.title) + expect(json_response["content"]).to eq(page.content) + expect(json_response["slug"]).to eq(page.slug) + expect(json_response["title"]).to eq(page.title) end end - shared_examples_for 'creates wiki page' do - it 'creates the wiki page' do + shared_examples_for "creates wiki page" do + it "creates the wiki page" do post(api(url, user), params: payload) expect(response).to have_gitlab_http_status(201) expect(json_response.size).to eq(4) expect(json_response.keys).to match_array(expected_keys_with_content) - expect(json_response['content']).to eq(payload[:content]) - expect(json_response['slug']).to eq(payload[:title].tr(' ', '-')) - expect(json_response['title']).to eq(payload[:title]) - expect(json_response['rdoc']).to eq(payload[:rdoc]) + expect(json_response["content"]).to eq(payload[:content]) + expect(json_response["slug"]).to eq(payload[:title].tr(" ", "-")) + expect(json_response["title"]).to eq(payload[:title]) + expect(json_response["rdoc"]).to eq(payload[:rdoc]) end [:title, :content].each do |part| @@ -93,21 +93,21 @@ describe API::Wikis do expect(response).to have_gitlab_http_status(400) expect(json_response.size).to eq(1) - expect(json_response['error']).to eq("#{part} is missing") + expect(json_response["error"]).to eq("#{part} is missing") end end end - shared_examples_for 'updates wiki page' do - it 'updates the wiki page' do + shared_examples_for "updates wiki page" do + it "updates the wiki page" do put(api(url, user), params: payload) expect(response).to have_gitlab_http_status(200) expect(json_response.size).to eq(4) expect(json_response.keys).to match_array(expected_keys_with_content) - expect(json_response['content']).to eq(payload[:content]) - expect(json_response['slug']).to eq(payload[:title].tr(' ', '-')) - expect(json_response['title']).to eq(payload[:title]) + expect(json_response["content"]).to eq(payload[:content]) + expect(json_response["slug"]).to eq(payload[:title].tr(" ", "-")) + expect(json_response["title"]).to eq(payload[:title]) end [:title, :content, :format].each do |part| @@ -121,39 +121,39 @@ describe API::Wikis do end end - shared_examples_for '403 Forbidden' do - it 'returns 403 Forbidden' do + shared_examples_for "403 Forbidden" do + it "returns 403 Forbidden" do expect(response).to have_gitlab_http_status(403) expect(json_response.size).to eq(1) - expect(json_response['message']).to eq('403 Forbidden') + expect(json_response["message"]).to eq("403 Forbidden") end end - shared_examples_for '404 Wiki Page Not Found' do - it 'returns 404 Wiki Page Not Found' do + shared_examples_for "404 Wiki Page Not Found" do + it "returns 404 Wiki Page Not Found" do expect(response).to have_gitlab_http_status(404) expect(json_response.size).to eq(1) - expect(json_response['message']).to eq('404 Wiki Page Not Found') + expect(json_response["message"]).to eq("404 Wiki Page Not Found") end end - shared_examples_for '404 Project Not Found' do - it 'returns 404 Project Not Found' do + shared_examples_for "404 Project Not Found" do + it "returns 404 Project Not Found" do expect(response).to have_gitlab_http_status(404) expect(json_response.size).to eq(1) - expect(json_response['message']).to eq('404 Project Not Found') + expect(json_response["message"]).to eq("404 Project Not Found") end end - shared_examples_for '204 No Content' do - it 'returns 204 No Content' do + shared_examples_for "204 No Content" do + it "returns 204 No Content" do expect(response).to have_gitlab_http_status(204) end end - shared_examples_for 'uploads wiki attachment' do - it 'pushes attachment to the wiki repository' do - allow(SecureRandom).to receive(:hex).and_return('fixed_hex') + shared_examples_for "uploads wiki attachment" do + it "pushes attachment to the wiki repository" do + allow(SecureRandom).to receive(:hex).and_return("fixed_hex") post(api(url, user), params: payload) @@ -161,690 +161,690 @@ describe API::Wikis do expect(json_response).to eq result_hash.deep_stringify_keys end - it 'responds with validation error on empty file' do + it "responds with validation error on empty file" do payload.delete(:file) post(api(url, user), params: payload) expect(response).to have_gitlab_http_status(400) expect(json_response.size).to eq(1) - expect(json_response['error']).to eq('file is missing') + expect(json_response["error"]).to eq("file is missing") end - it 'responds with validation error on invalid temp file' do - payload[:file] = { tempfile: '/etc/hosts' } + it "responds with validation error on invalid temp file" do + payload[:file] = {tempfile: "/etc/hosts"} post(api(url, user), params: payload) expect(response).to have_gitlab_http_status(400) expect(json_response.size).to eq(1) - expect(json_response['error']).to eq('file is invalid') + expect(json_response["error"]).to eq("file is invalid") end end - describe 'GET /projects/:id/wikis' do + describe "GET /projects/:id/wikis" do let(:url) { "/projects/#{project.id}/wikis" } - context 'when wiki is disabled' do + context "when wiki is disabled" do let(:project) { create(:project, :wiki_repo, :wiki_disabled) } - context 'when user is guest' do + context "when user is guest" do before do get api(url) end - include_examples '404 Project Not Found' + include_examples "404 Project Not Found" end - context 'when user is developer' do + context "when user is developer" do before do project.add_developer(user) get api(url, user) end - include_examples '403 Forbidden' + include_examples "403 Forbidden" end - context 'when user is maintainer' do + context "when user is maintainer" do before do project.add_maintainer(user) get api(url, user) end - include_examples '403 Forbidden' + include_examples "403 Forbidden" end end - context 'when wiki is available only for team members' do + context "when wiki is available only for team members" do let(:project) { create(:project, :wiki_repo, :wiki_private) } - context 'when user is guest' do + context "when user is guest" do before do get api(url) end - include_examples '404 Project Not Found' + include_examples "404 Project Not Found" end - context 'when user is developer' do + context "when user is developer" do before do project.add_developer(user) end - include_examples 'returns list of wiki pages' + include_examples "returns list of wiki pages" end - context 'when user is maintainer' do + context "when user is maintainer" do before do project.add_maintainer(user) end - include_examples 'returns list of wiki pages' + include_examples "returns list of wiki pages" end end - context 'when wiki is available for everyone with access' do + context "when wiki is available for everyone with access" do let(:project) { create(:project, :wiki_repo) } - context 'when user is guest' do + context "when user is guest" do before do get api(url) end - include_examples '404 Project Not Found' + include_examples "404 Project Not Found" end - context 'when user is developer' do + context "when user is developer" do before do project.add_developer(user) end - include_examples 'returns list of wiki pages' + include_examples "returns list of wiki pages" end - context 'when user is maintainer' do + context "when user is maintainer" do before do project.add_maintainer(user) end - include_examples 'returns list of wiki pages' + include_examples "returns list of wiki pages" end end end - describe 'GET /projects/:id/wikis/:slug' do + describe "GET /projects/:id/wikis/:slug" do let(:page) { create(:wiki_page, wiki: project.wiki) } let(:url) { "/projects/#{project.id}/wikis/#{page.slug}" } - context 'when wiki is disabled' do + context "when wiki is disabled" do let(:project) { create(:project, :wiki_repo, :wiki_disabled) } - context 'when user is guest' do + context "when user is guest" do before do get api(url) end - include_examples '404 Project Not Found' + include_examples "404 Project Not Found" end - context 'when user is developer' do + context "when user is developer" do before do project.add_developer(user) get api(url, user) end - include_examples '403 Forbidden' + include_examples "403 Forbidden" end - context 'when user is maintainer' do + context "when user is maintainer" do before do project.add_maintainer(user) get api(url, user) end - include_examples '403 Forbidden' + include_examples "403 Forbidden" end end - context 'when wiki is available only for team members' do + context "when wiki is available only for team members" do let(:project) { create(:project, :wiki_repo, :wiki_private) } - context 'when user is guest' do + context "when user is guest" do before do get api(url) end - include_examples '404 Project Not Found' + include_examples "404 Project Not Found" end - context 'when user is developer' do + context "when user is developer" do before do project.add_developer(user) get api(url, user) end - include_examples 'returns wiki page' + include_examples "returns wiki page" - context 'when page is not existing' do + context "when page is not existing" do let(:url) { "/projects/#{project.id}/wikis/unknown" } - include_examples '404 Wiki Page Not Found' + include_examples "404 Wiki Page Not Found" end end - context 'when user is maintainer' do + context "when user is maintainer" do before do project.add_maintainer(user) get api(url, user) end - include_examples 'returns wiki page' + include_examples "returns wiki page" - context 'when page is not existing' do + context "when page is not existing" do let(:url) { "/projects/#{project.id}/wikis/unknown" } - include_examples '404 Wiki Page Not Found' + include_examples "404 Wiki Page Not Found" end end end - context 'when wiki is available for everyone with access' do + context "when wiki is available for everyone with access" do let(:project) { create(:project, :wiki_repo) } - context 'when user is guest' do + context "when user is guest" do before do get api(url) end - include_examples '404 Project Not Found' + include_examples "404 Project Not Found" end - context 'when user is developer' do + context "when user is developer" do before do project.add_developer(user) get api(url, user) end - include_examples 'returns wiki page' + include_examples "returns wiki page" - context 'when page is not existing' do + context "when page is not existing" do let(:url) { "/projects/#{project.id}/wikis/unknown" } - include_examples '404 Wiki Page Not Found' + include_examples "404 Wiki Page Not Found" end end - context 'when user is maintainer' do + context "when user is maintainer" do before do project.add_maintainer(user) get api(url, user) end - include_examples 'returns wiki page' + include_examples "returns wiki page" - context 'when page is not existing' do + context "when page is not existing" do let(:url) { "/projects/#{project.id}/wikis/unknown" } - include_examples '404 Wiki Page Not Found' + include_examples "404 Wiki Page Not Found" end end end end - describe 'POST /projects/:id/wikis' do - let(:payload) { { title: 'title', content: 'content' } } + describe "POST /projects/:id/wikis" do + let(:payload) { {title: "title", content: "content"} } let(:url) { "/projects/#{project.id}/wikis" } - context 'when wiki is disabled' do + context "when wiki is disabled" do let(:project) { create(:project, :wiki_disabled, :wiki_repo) } - context 'when user is guest' do + context "when user is guest" do before do post(api(url), params: payload) end - include_examples '404 Project Not Found' + include_examples "404 Project Not Found" end - context 'when user is developer' do + context "when user is developer" do before do project.add_developer(user) post(api(url, user), params: payload) end - include_examples '403 Forbidden' + include_examples "403 Forbidden" end - context 'when user is maintainer' do + context "when user is maintainer" do before do project.add_maintainer(user) post(api(url, user), params: payload) end - include_examples '403 Forbidden' + include_examples "403 Forbidden" end end - context 'when wiki is available only for team members' do + context "when wiki is available only for team members" do let(:project) { create(:project, :wiki_private, :wiki_repo) } - context 'when user is guest' do + context "when user is guest" do before do post(api(url), params: payload) end - include_examples '404 Project Not Found' + include_examples "404 Project Not Found" end - context 'when user is developer' do + context "when user is developer" do before do project.add_developer(user) end - include_examples 'creates wiki page' + include_examples "creates wiki page" end - context 'when user is maintainer' do + context "when user is maintainer" do before do project.add_maintainer(user) end - include_examples 'creates wiki page' + include_examples "creates wiki page" end end - context 'when wiki is available for everyone with access' do + context "when wiki is available for everyone with access" do let(:project) { create(:project, :wiki_repo) } - context 'when user is guest' do + context "when user is guest" do before do post(api(url), params: payload) end - include_examples '404 Project Not Found' + include_examples "404 Project Not Found" end - context 'when user is developer' do + context "when user is developer" do before do project.add_developer(user) end - include_examples 'creates wiki page' + include_examples "creates wiki page" end - context 'when user is maintainer' do + context "when user is maintainer" do before do project.add_maintainer(user) end - include_examples 'creates wiki page' + include_examples "creates wiki page" end end end - describe 'PUT /projects/:id/wikis/:slug' do + describe "PUT /projects/:id/wikis/:slug" do let(:page) { create(:wiki_page, wiki: project_wiki) } - let(:payload) { { title: 'new title', content: 'new content' } } + let(:payload) { {title: "new title", content: "new content"} } let(:url) { "/projects/#{project.id}/wikis/#{page.slug}" } - context 'when wiki is disabled' do + context "when wiki is disabled" do let(:project) { create(:project, :wiki_disabled, :wiki_repo) } - context 'when user is guest' do + context "when user is guest" do before do put(api(url), params: payload) end - include_examples '404 Project Not Found' + include_examples "404 Project Not Found" end - context 'when user is developer' do + context "when user is developer" do before do project.add_developer(user) put(api(url, user), params: payload) end - include_examples '403 Forbidden' + include_examples "403 Forbidden" end - context 'when user is maintainer' do + context "when user is maintainer" do before do project.add_maintainer(user) put(api(url, user), params: payload) end - include_examples '403 Forbidden' + include_examples "403 Forbidden" end end - context 'when wiki is available only for team members' do + context "when wiki is available only for team members" do let(:project) { create(:project, :wiki_private, :wiki_repo) } - context 'when user is guest' do + context "when user is guest" do before do put(api(url), params: payload) end - include_examples '404 Project Not Found' + include_examples "404 Project Not Found" end - context 'when user is developer' do + context "when user is developer" do before do project.add_developer(user) end - include_examples 'updates wiki page' + include_examples "updates wiki page" - context 'when page is not existing' do + context "when page is not existing" do let(:url) { "/projects/#{project.id}/wikis/unknown" } before do put(api(url, user), params: payload) end - include_examples '404 Wiki Page Not Found' + include_examples "404 Wiki Page Not Found" end end - context 'when user is maintainer' do + context "when user is maintainer" do before do project.add_maintainer(user) end - include_examples 'updates wiki page' + include_examples "updates wiki page" - context 'when page is not existing' do + context "when page is not existing" do let(:url) { "/projects/#{project.id}/wikis/unknown" } before do put(api(url, user), params: payload) end - include_examples '404 Wiki Page Not Found' + include_examples "404 Wiki Page Not Found" end end end - context 'when wiki is available for everyone with access' do + context "when wiki is available for everyone with access" do let(:project) { create(:project, :wiki_repo) } - context 'when user is guest' do + context "when user is guest" do before do put(api(url), params: payload) end - include_examples '404 Project Not Found' + include_examples "404 Project Not Found" end - context 'when user is developer' do + context "when user is developer" do before do project.add_developer(user) end - include_examples 'updates wiki page' + include_examples "updates wiki page" - context 'when page is not existing' do + context "when page is not existing" do let(:url) { "/projects/#{project.id}/wikis/unknown" } before do put(api(url, user), params: payload) end - include_examples '404 Wiki Page Not Found' + include_examples "404 Wiki Page Not Found" end end - context 'when user is maintainer' do + context "when user is maintainer" do before do project.add_maintainer(user) end - include_examples 'updates wiki page' + include_examples "updates wiki page" - context 'when page is not existing' do + context "when page is not existing" do let(:url) { "/projects/#{project.id}/wikis/unknown" } before do put(api(url, user), params: payload) end - include_examples '404 Wiki Page Not Found' + include_examples "404 Wiki Page Not Found" end end end - context 'when wiki belongs to a group project' do + context "when wiki belongs to a group project" do let(:project) { create(:project, :wiki_repo, namespace: group) } - include_examples 'updates wiki page' + include_examples "updates wiki page" end end - describe 'DELETE /projects/:id/wikis/:slug' do + describe "DELETE /projects/:id/wikis/:slug" do let(:page) { create(:wiki_page, wiki: project_wiki) } let(:url) { "/projects/#{project.id}/wikis/#{page.slug}" } - context 'when wiki is disabled' do + context "when wiki is disabled" do let(:project) { create(:project, :wiki_disabled, :wiki_repo) } - context 'when user is guest' do + context "when user is guest" do before do delete(api(url)) end - include_examples '404 Project Not Found' + include_examples "404 Project Not Found" end - context 'when user is developer' do + context "when user is developer" do before do project.add_developer(user) delete(api(url, user)) end - include_examples '403 Forbidden' + include_examples "403 Forbidden" end - context 'when user is maintainer' do + context "when user is maintainer" do before do project.add_maintainer(user) delete(api(url, user)) end - include_examples '403 Forbidden' + include_examples "403 Forbidden" end end - context 'when wiki is available only for team members' do + context "when wiki is available only for team members" do let(:project) { create(:project, :wiki_private, :wiki_repo) } - context 'when user is guest' do + context "when user is guest" do before do delete(api(url)) end - include_examples '404 Project Not Found' + include_examples "404 Project Not Found" end - context 'when user is developer' do + context "when user is developer" do before do project.add_developer(user) delete(api(url, user)) end - include_examples '403 Forbidden' + include_examples "403 Forbidden" end - context 'when user is maintainer' do + context "when user is maintainer" do before do project.add_maintainer(user) delete(api(url, user)) end - include_examples '204 No Content' + include_examples "204 No Content" end end - context 'when wiki is available for everyone with access' do + context "when wiki is available for everyone with access" do let(:project) { create(:project, :wiki_repo) } - context 'when user is guest' do + context "when user is guest" do before do delete(api(url)) end - include_examples '404 Project Not Found' + include_examples "404 Project Not Found" end - context 'when user is developer' do + context "when user is developer" do before do project.add_developer(user) delete(api(url, user)) end - include_examples '403 Forbidden' + include_examples "403 Forbidden" end - context 'when user is maintainer' do + context "when user is maintainer" do before do project.add_maintainer(user) delete(api(url, user)) end - include_examples '204 No Content' + include_examples "204 No Content" - context 'when page is not existing' do + context "when page is not existing" do let(:url) { "/projects/#{project.id}/wikis/unknown" } - include_examples '404 Wiki Page Not Found' + include_examples "404 Wiki Page Not Found" end end end - context 'when wiki belongs to a group project' do + context "when wiki belongs to a group project" do let(:project) { create(:project, :wiki_repo, namespace: group) } before do delete(api(url, user)) end - include_examples '204 No Content' + include_examples "204 No Content" end end - describe 'POST /projects/:id/wikis/attachments' do - let(:payload) { { file: fixture_file_upload('spec/fixtures/dk.png') } } + describe "POST /projects/:id/wikis/attachments" do + let(:payload) { {file: fixture_file_upload("spec/fixtures/dk.png")} } let(:url) { "/projects/#{project.id}/wikis/attachments" } let(:file_path) { "#{Wikis::CreateAttachmentService::ATTACHMENT_PATH}/fixed_hex/dk.png" } let(:result_hash) do { - file_name: 'dk.png', + file_name: "dk.png", file_path: file_path, - branch: 'master', + branch: "master", link: { url: file_path, - markdown: "" - } + markdown: "", + }, } end - context 'when wiki is disabled' do + context "when wiki is disabled" do let(:project) { create(:project, :wiki_disabled, :wiki_repo) } - context 'when user is guest' do + context "when user is guest" do before do post(api(url), params: payload) end - include_examples '404 Project Not Found' + include_examples "404 Project Not Found" end - context 'when user is developer' do + context "when user is developer" do before do project.add_developer(user) post(api(url, user), params: payload) end - include_examples '403 Forbidden' + include_examples "403 Forbidden" end - context 'when user is maintainer' do + context "when user is maintainer" do before do project.add_maintainer(user) post(api(url, user), params: payload) end - include_examples '403 Forbidden' + include_examples "403 Forbidden" end end - context 'when wiki is available only for team members' do + context "when wiki is available only for team members" do let(:project) { create(:project, :wiki_private, :wiki_repo) } - context 'when user is guest' do + context "when user is guest" do before do post(api(url), params: payload) end - include_examples '404 Project Not Found' + include_examples "404 Project Not Found" end - context 'when user is developer' do + context "when user is developer" do before do project.add_developer(user) end - include_examples 'uploads wiki attachment' + include_examples "uploads wiki attachment" end - context 'when user is maintainer' do + context "when user is maintainer" do before do project.add_maintainer(user) end - include_examples 'uploads wiki attachment' + include_examples "uploads wiki attachment" end end - context 'when wiki is available for everyone with access' do + context "when wiki is available for everyone with access" do let(:project) { create(:project, :wiki_repo) } - context 'when user is guest' do + context "when user is guest" do before do post(api(url), params: payload) end - include_examples '404 Project Not Found' + include_examples "404 Project Not Found" end - context 'when user is developer' do + context "when user is developer" do before do project.add_developer(user) end - include_examples 'uploads wiki attachment' + include_examples "uploads wiki attachment" end - context 'when user is maintainer' do + context "when user is maintainer" do before do project.add_maintainer(user) end - include_examples 'uploads wiki attachment' + include_examples "uploads wiki attachment" end end end diff --git a/spec/requests/git_http_spec.rb b/spec/requests/git_http_spec.rb index 5b625fd47be..fb027f18685 100644 --- a/spec/requests/git_http_spec.rb +++ b/spec/requests/git_http_spec.rb @@ -1,17 +1,17 @@ require "spec_helper" -describe 'Git HTTP requests' do +describe "Git HTTP requests" do include ProjectForksHelper include TermsHelper include GitHttpHelpers include WorkhorseHelpers - shared_examples 'pulls require Basic HTTP Authentication' do + shared_examples "pulls require Basic HTTP Authentication" do context "when no credentials are provided" do it "responds to downloads with status 401 Unauthorized (no project existence information leak)" do download(path) do |response| expect(response).to have_gitlab_http_status(:unauthorized) - expect(response.header['WWW-Authenticate']).to start_with('Basic ') + expect(response.header["WWW-Authenticate"]).to start_with("Basic ") end end end @@ -20,7 +20,7 @@ describe 'Git HTTP requests' do it "responds to downloads with status 401 Unauthorized" do download(path, user: user.username) do |response| expect(response).to have_gitlab_http_status(:unauthorized) - expect(response.header['WWW-Authenticate']).to start_with('Basic ') + expect(response.header["WWW-Authenticate"]).to start_with("Basic ") end end end @@ -30,7 +30,7 @@ describe 'Git HTTP requests' do it "responds to downloads with status 401 Unauthorized" do download(path, user: user.username, password: "wrong-password") do |response| expect(response).to have_gitlab_http_status(:unauthorized) - expect(response.header['WWW-Authenticate']).to start_with('Basic ') + expect(response.header["WWW-Authenticate"]).to start_with("Basic ") end end end @@ -39,19 +39,19 @@ describe 'Git HTTP requests' do it "does not respond to downloads with status 401 Unauthorized" do download(path, user: user.username, password: user.password) do |response| expect(response).not_to have_gitlab_http_status(:unauthorized) - expect(response.header['WWW-Authenticate']).to be_nil + expect(response.header["WWW-Authenticate"]).to be_nil end end end end end - shared_examples 'pushes require Basic HTTP Authentication' do + shared_examples "pushes require Basic HTTP Authentication" do context "when no credentials are provided" do it "responds to uploads with status 401 Unauthorized (no project existence information leak)" do upload(path) do |response| expect(response).to have_gitlab_http_status(:unauthorized) - expect(response.header['WWW-Authenticate']).to start_with('Basic ') + expect(response.header["WWW-Authenticate"]).to start_with("Basic ") end end end @@ -60,7 +60,7 @@ describe 'Git HTTP requests' do it "responds to uploads with status 401 Unauthorized" do upload(path, user: user.username) do |response| expect(response).to have_gitlab_http_status(:unauthorized) - expect(response.header['WWW-Authenticate']).to start_with('Basic ') + expect(response.header["WWW-Authenticate"]).to start_with("Basic ") end end end @@ -70,7 +70,7 @@ describe 'Git HTTP requests' do it "responds to uploads with status 401 Unauthorized" do upload(path, user: user.username, password: "wrong-password") do |response| expect(response).to have_gitlab_http_status(:unauthorized) - expect(response.header['WWW-Authenticate']).to start_with('Basic ') + expect(response.header["WWW-Authenticate"]).to start_with("Basic ") end end end @@ -79,14 +79,14 @@ describe 'Git HTTP requests' do it "does not respond to uploads with status 401 Unauthorized" do upload(path, user: user.username, password: user.password) do |response| expect(response).not_to have_gitlab_http_status(:unauthorized) - expect(response.header['WWW-Authenticate']).to be_nil + expect(response.header["WWW-Authenticate"]).to be_nil end end end end end - shared_examples_for 'pulls are allowed' do + shared_examples_for "pulls are allowed" do it do download(path, env) do |response| expect(response).to have_gitlab_http_status(:ok) @@ -95,7 +95,7 @@ describe 'Git HTTP requests' do end end - shared_examples_for 'pushes are allowed' do + shared_examples_for "pushes are allowed" do it do upload(path, env) do |response| expect(response).to have_gitlab_http_status(:ok) @@ -109,13 +109,13 @@ describe 'Git HTTP requests' do context "when the project doesn't exist" do context "when namespace doesn't exist" do - let(:path) { 'doesnt/exist.git' } + let(:path) { "doesnt/exist.git" } - it_behaves_like 'pulls require Basic HTTP Authentication' - it_behaves_like 'pushes require Basic HTTP Authentication' + it_behaves_like "pulls require Basic HTTP Authentication" + it_behaves_like "pushes require Basic HTTP Authentication" - context 'when authenticated' do - it 'rejects downloads and uploads with 404 Not Found' do + context "when authenticated" do + it "rejects downloads and uploads with 404 Not Found" do download_or_upload(path, user: user.username, password: user.password) do |response| expect(response).to have_gitlab_http_status(:not_found) end @@ -123,19 +123,19 @@ describe 'Git HTTP requests' do end end - context 'when namespace exists' do + context "when namespace exists" do let(:path) { "#{user.namespace.path}/new-project.git"} - context 'when authenticated' do - it 'creates a new project under the existing namespace' do - expect do + context "when authenticated" do + it "creates a new project under the existing namespace" do + expect { upload(path, user: user.username, password: user.password) do |response| expect(response).to have_gitlab_http_status(:ok) end - end.to change { user.projects.count }.by(1) + }.to change { user.projects.count }.by(1) end - it 'rejects push with 422 Unprocessable Entity when project is invalid' do + it "rejects push with 422 Unprocessable Entity when project is invalid" do path = "#{user.namespace.path}/new.git" push_get(path, user: user.username, password: user.password) @@ -153,42 +153,42 @@ describe 'Git HTTP requests' do context "when the project is public" do let(:project) { create(:project, :wiki_repo, :public, :wiki_enabled) } - it_behaves_like 'pushes require Basic HTTP Authentication' + it_behaves_like "pushes require Basic HTTP Authentication" - context 'when unauthenticated' do + context "when unauthenticated" do let(:env) { {} } - it_behaves_like 'pulls are allowed' + it_behaves_like "pulls are allowed" it "responds to pulls with the wiki's repo" do download(path) do |response| json_body = ActiveSupport::JSON.decode(response.body) - expect(json_body['Repository']['relative_path']).to eq(wiki.repository.relative_path) + expect(json_body["Repository"]["relative_path"]).to eq(wiki.repository.relative_path) end end end - context 'when authenticated' do - let(:env) { { user: user.username, password: user.password } } + context "when authenticated" do + let(:env) { {user: user.username, password: user.password} } - context 'and as a developer on the team' do + context "and as a developer on the team" do before do project.add_developer(user) end - context 'but the repo is disabled' do + context "but the repo is disabled" do let(:project) { create(:project, :wiki_repo, :public, :repository_disabled, :wiki_enabled) } - it_behaves_like 'pulls are allowed' - it_behaves_like 'pushes are allowed' + it_behaves_like "pulls are allowed" + it_behaves_like "pushes are allowed" end end - context 'and not on the team' do - it_behaves_like 'pulls are allowed' + context "and not on the team" do + it_behaves_like "pulls are allowed" - it 'rejects pushes with 403 Forbidden' do + it "rejects pushes with 403 Forbidden" do upload(path, env) do |response| expect(response).to have_gitlab_http_status(:forbidden) expect(response.body).to eq(git_access_wiki_error(:write_to_wiki)) @@ -201,25 +201,25 @@ describe 'Git HTTP requests' do context "when the project is private" do let(:project) { create(:project, :wiki_repo, :private, :wiki_enabled) } - it_behaves_like 'pulls require Basic HTTP Authentication' - it_behaves_like 'pushes require Basic HTTP Authentication' + it_behaves_like "pulls require Basic HTTP Authentication" + it_behaves_like "pushes require Basic HTTP Authentication" - context 'when authenticated' do - context 'and as a developer on the team' do + context "when authenticated" do + context "and as a developer on the team" do before do project.add_developer(user) end - context 'but the repo is disabled' do + context "but the repo is disabled" do let(:project) { create(:project, :wiki_repo, :private, :repository_disabled, :wiki_enabled) } - it 'allows clones' do + it "allows clones" do download(path, user: user.username, password: user.password) do |response| expect(response).to have_gitlab_http_status(:ok) end end - it 'pushes are allowed' do + it "pushes are allowed" do upload(path, user: user.username, password: user.password) do |response| expect(response).to have_gitlab_http_status(:ok) end @@ -227,15 +227,15 @@ describe 'Git HTTP requests' do end end - context 'and not on the team' do - it 'rejects clones with 404 Not Found' do + context "and not on the team" do + it "rejects clones with 404 Not Found" do download(path, user: user.username, password: user.password) do |response| expect(response).to have_gitlab_http_status(:not_found) expect(response.body).to eq(git_access_error(:project_not_found)) end end - it 'rejects pushes with 404 Not Found' do + it "rejects pushes with 404 Not Found" do upload(path, user: user.username, password: user.password) do |response| expect(response).to have_gitlab_http_status(:not_found) expect(response.body).to eq(git_access_error(:project_not_found)) @@ -252,31 +252,31 @@ describe 'Git HTTP requests' do context "when the project is public" do let(:project) { create(:project, :repository, :public) } - it_behaves_like 'pushes require Basic HTTP Authentication' + it_behaves_like "pushes require Basic HTTP Authentication" - context 'when not authenticated' do + context "when not authenticated" do let(:env) { {} } - it_behaves_like 'pulls are allowed' + it_behaves_like "pulls are allowed" end context "when authenticated" do - let(:env) { { user: user.username, password: user.password } } + let(:env) { {user: user.username, password: user.password} } - context 'as a developer on the team' do + context "as a developer on the team" do before do project.add_developer(user) end - it_behaves_like 'pulls are allowed' - it_behaves_like 'pushes are allowed' + it_behaves_like "pulls are allowed" + it_behaves_like "pushes are allowed" - context 'but git-receive-pack over HTTP is disabled in config' do + context "but git-receive-pack over HTTP is disabled in config" do before do allow(Gitlab.config.gitlab_shell).to receive(:receive_pack).and_return(false) end - it 'rejects pushes with 403 Forbidden' do + it "rejects pushes with 403 Forbidden" do upload(path, env) do |response| expect(response).to have_gitlab_http_status(:forbidden) expect(response.body).to eq(git_access_error(:receive_pack_disabled_over_http)) @@ -284,7 +284,7 @@ describe 'Git HTTP requests' do end end - context 'but git-upload-pack over HTTP is disabled in config' do + context "but git-upload-pack over HTTP is disabled in config" do it "rejects pushes with 403 Forbidden" do allow(Gitlab.config.gitlab_shell).to receive(:upload_pack).and_return(false) @@ -296,73 +296,73 @@ describe 'Git HTTP requests' do end end - context 'and not a member of the team' do - it_behaves_like 'pulls are allowed' + context "and not a member of the team" do + it_behaves_like "pulls are allowed" - it 'rejects pushes with 403 Forbidden' do + it "rejects pushes with 403 Forbidden" do upload(path, env) do |response| expect(response).to have_gitlab_http_status(:forbidden) - expect(response.body).to eq('You are not allowed to push code to this project.') + expect(response.body).to eq("You are not allowed to push code to this project.") end end - context 'when merge requests are open that allow maintainer access' do + context "when merge requests are open that allow maintainer access" do let(:canonical_project) { create(:project, :public, :repository) } let(:project) { fork_project(canonical_project, nil, repository: true) } before do canonical_project.add_maintainer(user) create(:merge_request, - source_project: project, - target_project: canonical_project, - source_branch: 'fixes', - allow_collaboration: true) + source_project: project, + target_project: canonical_project, + source_branch: "fixes", + allow_collaboration: true) end - it_behaves_like 'pushes are allowed' + it_behaves_like "pushes are allowed" end end end - context 'when the request is not from gitlab-workhorse' do - it 'raises an exception' do - expect do + context "when the request is not from gitlab-workhorse" do + it "raises an exception" do + expect { get("/#{project.full_path}.git/info/refs?service=git-upload-pack") - end.to raise_error(JWT::DecodeError) + }.to raise_error(JWT::DecodeError) end end - context 'when the repo is public' do - context 'but the repo is disabled' do + context "when the repo is public" do + context "but the repo is disabled" do let(:project) { create(:project, :public, :repository, :repository_disabled) } let(:path) { "#{project.full_path}.git" } let(:env) { {} } - it_behaves_like 'pulls require Basic HTTP Authentication' - it_behaves_like 'pushes require Basic HTTP Authentication' + it_behaves_like "pulls require Basic HTTP Authentication" + it_behaves_like "pushes require Basic HTTP Authentication" end - context 'but the repo is enabled' do + context "but the repo is enabled" do let(:project) { create(:project, :public, :repository, :repository_enabled) } let(:path) { "#{project.full_path}.git" } let(:env) { {} } - it_behaves_like 'pulls are allowed' + it_behaves_like "pulls are allowed" end - context 'but only project members are allowed' do + context "but only project members are allowed" do let(:project) { create(:project, :public, :repository, :repository_private) } - it_behaves_like 'pulls require Basic HTTP Authentication' - it_behaves_like 'pushes require Basic HTTP Authentication' + it_behaves_like "pulls require Basic HTTP Authentication" + it_behaves_like "pushes require Basic HTTP Authentication" end end - context 'and the user requests a redirected path' do - let!(:redirect) { project.route.create_redirect('foo/bar') } + context "and the user requests a redirected path" do + let!(:redirect) { project.route.create_redirect("foo/bar") } let(:path) { "#{redirect.path}.git" } - it 'downloads get status 200 for redirects' do + it "downloads get status 200 for redirects" do clone_get(path, {}) expect(response).to have_gitlab_http_status(:ok) @@ -373,21 +373,21 @@ describe 'Git HTTP requests' do context "when the project is private" do let(:project) { create(:project, :repository, :private) } - it_behaves_like 'pulls require Basic HTTP Authentication' - it_behaves_like 'pushes require Basic HTTP Authentication' + it_behaves_like "pulls require Basic HTTP Authentication" + it_behaves_like "pushes require Basic HTTP Authentication" context "when username and password are provided" do - let(:env) { { user: user.username, password: 'nope' } } + let(:env) { {user: user.username, password: "nope"} } context "when authentication fails" do context "when the user is IP banned" do before do - Gitlab.config.rack_attack.git_basic_auth['enabled'] = true + Gitlab.config.rack_attack.git_basic_auth["enabled"] = true end it "responds with status 401" do expect(Rack::Attack::Allow2Ban).to receive(:filter).and_return(true) - allow_any_instance_of(ActionDispatch::Request).to receive(:ip).and_return('1.2.3.4') + allow_any_instance_of(ActionDispatch::Request).to receive(:ip).and_return("1.2.3.4") clone_get(path, env) @@ -397,7 +397,7 @@ describe 'Git HTTP requests' do end context "when authentication succeeds" do - let(:env) { { user: user.username, password: user.password } } + let(:env) { {user: user.username, password: user.password} } context "when the user has access to the project" do before do @@ -417,7 +417,7 @@ describe 'Git HTTP requests' do it "rejects pulls with 401 Unauthorized for unknown projects (no project existence information leak)" do user.block - download('doesnt/exist.git', env) do |response| + download("doesnt/exist.git", env) do |response| expect(response).to have_gitlab_http_status(:unauthorized) end end @@ -425,7 +425,7 @@ describe 'Git HTTP requests' do context "when the user isn't blocked" do before do - Gitlab.config.rack_attack.git_basic_auth['enabled'] = true + Gitlab.config.rack_attack.git_basic_auth["enabled"] = true end it "resets the IP in Rack Attack on download" do @@ -446,7 +446,7 @@ describe 'Git HTTP requests' do end end - it 'updates the user last activity', :clean_gitlab_redis_shared_state do + it "updates the user last activity", :clean_gitlab_redis_shared_state do expect(user.last_activity_on).to be_nil download(path, env) do |response| @@ -462,13 +462,13 @@ describe 'Git HTTP requests' do end let(:path) { "#{project.full_path}.git" } - let(:env) { { user: 'oauth2', password: @token.token } } + let(:env) { {user: "oauth2", password: @token.token} } - it_behaves_like 'pulls are allowed' - it_behaves_like 'pushes are allowed' + it_behaves_like "pulls are allowed" + it_behaves_like "pushes are allowed" end - context 'when user has 2FA enabled' do + context "when user has 2FA enabled" do let(:user) { create(:user, :two_factor) } let(:access_token) { create(:personal_access_token, user: user) } let(:path) { "#{project.full_path}.git" } @@ -477,60 +477,60 @@ describe 'Git HTTP requests' do project.add_maintainer(user) end - context 'when username and password are provided' do - it 'rejects pulls with personal access token error message' do + context "when username and password are provided" do + it "rejects pulls with personal access token error message" do download(path, user: user.username, password: user.password) do |response| expect(response).to have_gitlab_http_status(:unauthorized) - expect(response.body).to include('You must use a personal access token with \'api\' scope for Git over HTTP') + expect(response.body).to include("You must use a personal access token with 'api' scope for Git over HTTP") end end - it 'rejects the push attempt with personal access token error message' do + it "rejects the push attempt with personal access token error message" do upload(path, user: user.username, password: user.password) do |response| expect(response).to have_gitlab_http_status(:unauthorized) - expect(response.body).to include('You must use a personal access token with \'api\' scope for Git over HTTP') + expect(response.body).to include("You must use a personal access token with 'api' scope for Git over HTTP") end end end - context 'when username and personal access token are provided' do - let(:env) { { user: user.username, password: access_token.token } } + context "when username and personal access token are provided" do + let(:env) { {user: user.username, password: access_token.token} } - it_behaves_like 'pulls are allowed' - it_behaves_like 'pushes are allowed' + it_behaves_like "pulls are allowed" + it_behaves_like "pushes are allowed" end end - context 'when internal auth is disabled' do + context "when internal auth is disabled" do before do allow_any_instance_of(ApplicationSetting).to receive(:password_authentication_enabled_for_git?) { false } end - it 'rejects pulls with personal access token error message' do - download(path, user: 'foo', password: 'bar') do |response| + it "rejects pulls with personal access token error message" do + download(path, user: "foo", password: "bar") do |response| expect(response).to have_gitlab_http_status(:unauthorized) - expect(response.body).to include('You must use a personal access token with \'api\' scope for Git over HTTP') + expect(response.body).to include("You must use a personal access token with 'api' scope for Git over HTTP") end end - it 'rejects pushes with personal access token error message' do - upload(path, user: 'foo', password: 'bar') do |response| + it "rejects pushes with personal access token error message" do + upload(path, user: "foo", password: "bar") do |response| expect(response).to have_gitlab_http_status(:unauthorized) - expect(response.body).to include('You must use a personal access token with \'api\' scope for Git over HTTP') + expect(response.body).to include("You must use a personal access token with 'api' scope for Git over HTTP") end end - context 'when LDAP is configured' do + context "when LDAP is configured" do before do allow(Gitlab::Auth::LDAP::Config).to receive(:enabled?).and_return(true) allow_any_instance_of(Gitlab::Auth::LDAP::Authentication) .to receive(:login).and_return(nil) end - it 'does not display the personal access token error message' do - upload(path, user: 'foo', password: 'bar') do |response| + it "does not display the personal access token error message" do + upload(path, user: "foo", password: "bar") do |response| expect(response).to have_gitlab_http_status(:unauthorized) - expect(response.body).not_to include('You must use a personal access token with \'api\' scope for Git over HTTP') + expect(response.body).not_to include("You must use a personal access token with 'api' scope for Git over HTTP") end end end @@ -546,7 +546,7 @@ describe 'Git HTTP requests' do it "repeated attempts followed by successful attempt" do options = Gitlab.config.rack_attack.git_basic_auth maxretry = options[:maxretry] - 1 - ip = '1.2.3.4' + ip = "1.2.3.4" allow_any_instance_of(ActionDispatch::Request).to receive(:ip).and_return(ip) Rack::Attack::Allow2Ban.reset(ip, options) @@ -566,8 +566,8 @@ describe 'Git HTTP requests' do end end - context 'and the user requests a redirected path' do - let!(:redirect) { project.route.create_redirect('foo/bar') } + context "and the user requests a redirected path" do + let!(:redirect) { project.route.create_redirect("foo/bar") } let(:path) { "#{redirect.path}.git" } let(:project_moved_message) do <<-MSG.strip_heredoc @@ -579,7 +579,7 @@ describe 'Git HTTP requests' do MSG end - it 'downloads get status 200' do + it "downloads get status 200" do clone_get(path, env) expect(response).to have_gitlab_http_status(:ok) @@ -618,11 +618,11 @@ describe 'Git HTTP requests' do build.update!(project: project) # can't associate it on factory create end - context 'when build created by system is authenticated' do + context "when build created by system is authenticated" do let(:path) { "#{project.full_path}.git" } - let(:env) { { user: 'gitlab-ci-token', password: build.token } } + let(:env) { {user: "gitlab-ci-token", password: build.token} } - it_behaves_like 'pulls are allowed' + it_behaves_like "pulls are allowed" # A non-401 here is not an information leak since the system is # "authenticated" as CI using the correct token. It does not have @@ -648,22 +648,22 @@ describe 'Git HTTP requests' do end end - context 'and build created by' do + context "and build created by" do before do build.update(user: user) project.add_reporter(user) end - shared_examples 'can download code only' do + shared_examples "can download code only" do let(:path) { "#{project.full_path}.git" } - let(:env) { { user: 'gitlab-ci-token', password: build.token } } + let(:env) { {user: "gitlab-ci-token", password: build.token} } - it_behaves_like 'pulls are allowed' + it_behaves_like "pulls are allowed" - context 'when the repo does not exist' do + context "when the repo does not exist" do let(:project) { create(:project) } - it 'rejects pulls with 404 Not Found' do + it "rejects pulls with 404 Not Found" do clone_get path, env expect(response).to have_gitlab_http_status(:not_found) @@ -671,7 +671,7 @@ describe 'Git HTTP requests' do end end - it 'rejects pushes with 403 Forbidden' do + it "rejects pushes with 403 Forbidden" do push_get path, env expect(response).to have_gitlab_http_status(:forbidden) @@ -679,25 +679,25 @@ describe 'Git HTTP requests' do end end - context 'administrator' do + context "administrator" do let(:user) { create(:admin) } - it_behaves_like 'can download code only' + it_behaves_like "can download code only" - it 'downloads from other project get status 403' do - clone_get "#{other_project.full_path}.git", user: 'gitlab-ci-token', password: build.token + it "downloads from other project get status 403" do + clone_get "#{other_project.full_path}.git", user: "gitlab-ci-token", password: build.token expect(response).to have_gitlab_http_status(:forbidden) end end - context 'regular user' do + context "regular user" do let(:user) { create(:user) } - it_behaves_like 'can download code only' + it_behaves_like "can download code only" - it 'downloads from other project get status 404' do - clone_get "#{other_project.full_path}.git", user: 'gitlab-ci-token', password: build.token + it "downloads from other project get status 404" do + clone_get "#{other_project.full_path}.git", user: "gitlab-ci-token", password: build.token expect(response).to have_gitlab_http_status(:not_found) end @@ -707,7 +707,7 @@ describe 'Git HTTP requests' do end context "when the project path doesn't end in .git" do - let(:project) { create(:project, :repository, :public, path: 'project.git-project') } + let(:project) { create(:project, :repository, :public, path: "project.git-project") } context "GET info/refs" do let(:path) { "/#{project.full_path}/info/refs" } @@ -723,7 +723,7 @@ describe 'Git HTTP requests' do end context "when the upload-pack service is requested" do - let(:params) { { service: 'git-upload-pack' } } + let(:params) { {service: "git-upload-pack"} } before do get path, params: params @@ -735,7 +735,7 @@ describe 'Git HTTP requests' do end context "when the receive-pack service is requested" do - let(:params) { { service: 'git-receive-pack' } } + let(:params) { {service: "git-receive-pack"} } before do get path, params: params @@ -747,7 +747,7 @@ describe 'Git HTTP requests' do end context "when the params are anything else" do - let(:params) { { service: 'git-implode-pack' } } + let(:params) { {service: "git-implode-pack"} } before do get path, params: params @@ -779,8 +779,8 @@ describe 'Git HTTP requests' do before do # Provide a dummy file in its place allow_any_instance_of(Repository).to receive(:blob_at).and_call_original - allow_any_instance_of(Repository).to receive(:blob_at).with('b83d6e391c22777fca1ed3012fce84f633d7fed0', 'info/refs') do - Blob.decorate(Gitlab::Git::Blob.find(project.repository, 'master', 'bar/branch-test.txt'), project) + allow_any_instance_of(Repository).to receive(:blob_at).with("b83d6e391c22777fca1ed3012fce84f633d7fed0", "info/refs") do + Blob.decorate(Gitlab::Git::Blob.find(project.repository, "master", "bar/branch-test.txt"), project) end get "/#{project.full_path}/blob/master/info/refs" @@ -806,8 +806,8 @@ describe 'Git HTTP requests' do describe "User with LDAP identity" do let(:user) { create(:omniauth_user, extern_uid: dn) } - let(:dn) { 'uid=john,ou=people,dc=example,dc=com' } - let(:path) { 'doesnt/exist.git' } + let(:dn) { "uid=john,ou=people,dc=example,dc=com" } + let(:path) { "doesnt/exist.git" } before do allow(Gitlab::Auth::OAuth::Provider).to receive(:enabled?).and_return(true) @@ -815,8 +815,8 @@ describe 'Git HTTP requests' do allow_any_instance_of(Gitlab::Auth::LDAP::Authentication).to receive(:login).with(user.username, user.password).and_return(user) end - it_behaves_like 'pulls require Basic HTTP Authentication' - it_behaves_like 'pushes require Basic HTTP Authentication' + it_behaves_like "pulls require Basic HTTP Authentication" + it_behaves_like "pushes require Basic HTTP Authentication" context "when authentication succeeds" do context "when the project doesn't exist" do @@ -830,9 +830,9 @@ describe 'Git HTTP requests' do context "when the project exists" do let(:project) { create(:project, :repository) } let(:path) { "#{project.full_path}.git" } - let(:env) { { user: user.username, password: user.password } } + let(:env) { {user: user.username, password: user.password} } - context 'and the user is on the team' do + context "and the user is on the team" do before do project.add_maintainer(user) end @@ -843,25 +843,25 @@ describe 'Git HTTP requests' do end end - it_behaves_like 'pulls are allowed' - it_behaves_like 'pushes are allowed' + it_behaves_like "pulls are allowed" + it_behaves_like "pushes are allowed" end end end end - context 'when terms are enforced' do + context "when terms are enforced" do let(:project) { create(:project, :repository) } let(:user) { create(:user) } let(:path) { "#{project.full_path}.git" } - let(:env) { { user: user.username, password: user.password } } + let(:env) { {user: user.username, password: user.password} } before do project.add_maintainer(user) enforce_terms end - it 'blocks git access when the user did not accept terms', :aggregate_failures do + it "blocks git access when the user did not accept terms", :aggregate_failures do clone_get(path, env) do |response| expect(response).to have_gitlab_http_status(:forbidden) end @@ -875,30 +875,30 @@ describe 'Git HTTP requests' do end end - context 'when the user accepted the terms' do + context "when the user accepted the terms" do before do accept_terms(user) end - it 'allows clones' do + it "allows clones" do clone_get(path, env) do |response| expect(response).to have_gitlab_http_status(:ok) end end - it_behaves_like 'pulls are allowed' - it_behaves_like 'pushes are allowed' + it_behaves_like "pulls are allowed" + it_behaves_like "pushes are allowed" end - context 'from CI' do + context "from CI" do let(:build) { create(:ci_build, :running) } - let(:env) { { user: 'gitlab-ci-token', password: build.token } } + let(:env) { {user: "gitlab-ci-token", password: build.token} } before do build.update!(user: user, project: project) end - it_behaves_like 'pulls are allowed' + it_behaves_like "pulls are allowed" end end end diff --git a/spec/requests/jwt_controller_spec.rb b/spec/requests/jwt_controller_spec.rb index 4bb3b848e17..14debcd4075 100644 --- a/spec/requests/jwt_controller_spec.rb +++ b/spec/requests/jwt_controller_spec.rb @@ -1,155 +1,155 @@ -require 'spec_helper' +require "spec_helper" describe JwtController do let(:service) { double(execute: {}) } let(:service_class) { double(new: service) } - let(:service_name) { 'test' } - let(:parameters) { { service: service_name } } + let(:service_name) { "test" } + let(:parameters) { {service: service_name} } before do - stub_const('JwtController::SERVICES', service_name => service_class) + stub_const("JwtController::SERVICES", service_name => service_class) end - context 'existing service' do - subject! { get '/jwt/auth', params: parameters } + context "existing service" do + subject! { get "/jwt/auth", params: parameters } it { expect(response).to have_gitlab_http_status(200) } - context 'returning custom http code' do - let(:service) { double(execute: { http_status: 505 }) } + context "returning custom http code" do + let(:service) { double(execute: {http_status: 505}) } it { expect(response).to have_gitlab_http_status(505) } end end - context 'when using authenticated request' do - context 'using CI token' do + context "when using authenticated request" do + context "using CI token" do let(:build) { create(:ci_build, :running) } let(:project) { build.project } - let(:headers) { { authorization: credentials('gitlab-ci-token', build.token) } } + let(:headers) { {authorization: credentials("gitlab-ci-token", build.token)} } - context 'project with enabled CI' do - subject! { get '/jwt/auth', params: parameters, headers: headers } + context "project with enabled CI" do + subject! { get "/jwt/auth", params: parameters, headers: headers } it { expect(service_class).to have_received(:new).with(project, nil, ActionController::Parameters.new(parameters).permit!) } end - context 'project with disabled CI' do + context "project with disabled CI" do before do project.project_feature.update_attribute(:builds_access_level, ProjectFeature::DISABLED) end - subject! { get '/jwt/auth', params: parameters, headers: headers } + subject! { get "/jwt/auth", params: parameters, headers: headers } it { expect(response).to have_gitlab_http_status(401) } end - context 'using personal access tokens' do + context "using personal access tokens" do let(:user) { create(:user) } - let(:pat) { create(:personal_access_token, user: user, scopes: ['read_registry']) } - let(:headers) { { authorization: credentials('personal_access_token', pat.token) } } + let(:pat) { create(:personal_access_token, user: user, scopes: ["read_registry"]) } + let(:headers) { {authorization: credentials("personal_access_token", pat.token)} } before do stub_container_registry_config(enabled: true) end - subject! { get '/jwt/auth', params: parameters, headers: headers } + subject! { get "/jwt/auth", params: parameters, headers: headers } - it 'authenticates correctly' do + it "authenticates correctly" do expect(response).to have_gitlab_http_status(200) expect(service_class).to have_received(:new).with(nil, user, ActionController::Parameters.new(parameters).permit!) end end end - context 'using User login' do + context "using User login" do let(:user) { create(:user) } - let(:headers) { { authorization: credentials(user.username, user.password) } } + let(:headers) { {authorization: credentials(user.username, user.password)} } - subject! { get '/jwt/auth', params: parameters, headers: headers } + subject! { get "/jwt/auth", params: parameters, headers: headers } it { expect(service_class).to have_received(:new).with(nil, user, ActionController::Parameters.new(parameters).permit!) } - context 'when passing a flat array of scopes' do + context "when passing a flat array of scopes" do # We use this trick to make rails to generate a query_string: # scope=scope1&scope=scope2 # It works because :scope and 'scope' are the same as string, but different objects let(:parameters) do { :service => service_name, - :scope => 'scope1', - 'scope' => 'scope2' + :scope => "scope1", + "scope" => "scope2", } end let(:service_parameters) do - ActionController::Parameters.new({ service: service_name, scopes: %w(scope1 scope2) }).permit! + ActionController::Parameters.new({service: service_name, scopes: %w[scope1 scope2]}).permit! end it { expect(service_class).to have_received(:new).with(nil, user, service_parameters) } end - context 'when user has 2FA enabled' do + context "when user has 2FA enabled" do let(:user) { create(:user, :two_factor) } - context 'without personal token' do - it 'rejects the authorization attempt' do + context "without personal token" do + it "rejects the authorization attempt" do expect(response).to have_gitlab_http_status(401) - expect(response.body).to include('You must use a personal access token with \'api\' scope for Git over HTTP') + expect(response.body).to include("You must use a personal access token with 'api' scope for Git over HTTP") end end - context 'with personal token' do + context "with personal token" do let(:access_token) { create(:personal_access_token, user: user) } - let(:headers) { { authorization: credentials(user.username, access_token.token) } } + let(:headers) { {authorization: credentials(user.username, access_token.token)} } - it 'accepts the authorization attempt' do + it "accepts the authorization attempt" do expect(response).to have_gitlab_http_status(200) end end end end - context 'using invalid login' do - let(:headers) { { authorization: credentials('invalid', 'password') } } + context "using invalid login" do + let(:headers) { {authorization: credentials("invalid", "password")} } - context 'when internal auth is enabled' do - it 'rejects the authorization attempt' do - get '/jwt/auth', params: parameters, headers: headers + context "when internal auth is enabled" do + it "rejects the authorization attempt" do + get "/jwt/auth", params: parameters, headers: headers expect(response).to have_gitlab_http_status(401) - expect(response.body).not_to include('You must use a personal access token with \'api\' scope for Git over HTTP') + expect(response.body).not_to include("You must use a personal access token with 'api' scope for Git over HTTP") end end - context 'when internal auth is disabled' do - it 'rejects the authorization attempt with personal access token message' do + context "when internal auth is disabled" do + it "rejects the authorization attempt with personal access token message" do allow_any_instance_of(ApplicationSetting).to receive(:password_authentication_enabled_for_git?) { false } - get '/jwt/auth', params: parameters, headers: headers + get "/jwt/auth", params: parameters, headers: headers expect(response).to have_gitlab_http_status(401) - expect(response.body).to include('You must use a personal access token with \'api\' scope for Git over HTTP') + expect(response.body).to include("You must use a personal access token with 'api' scope for Git over HTTP") end end end end - context 'when using unauthenticated request' do - it 'accepts the authorization attempt' do - get '/jwt/auth', params: parameters + context "when using unauthenticated request" do + it "accepts the authorization attempt" do + get "/jwt/auth", params: parameters expect(response).to have_gitlab_http_status(200) end - it 'allows read access' do + it "allows read access" do expect(service).to receive(:execute).with(authentication_abilities: Gitlab::Auth.read_authentication_abilities) - get '/jwt/auth', params: parameters + get "/jwt/auth", params: parameters end end - context 'unknown service' do - subject! { get '/jwt/auth', params: { service: 'unknown' } } + context "unknown service" do + subject! { get "/jwt/auth", params: {service: "unknown"} } it { expect(response).to have_gitlab_http_status(404) } end diff --git a/spec/requests/lfs_http_spec.rb b/spec/requests/lfs_http_spec.rb index 1781759c54b..dfaf813aff0 100644 --- a/spec/requests/lfs_http_spec.rb +++ b/spec/requests/lfs_http_spec.rb @@ -1,6 +1,6 @@ -require 'spec_helper' +require "spec_helper" -describe 'Git LFS API and storage' do +describe "Git LFS API and storage" do include WorkhorseHelpers include ProjectForksHelper @@ -9,8 +9,8 @@ describe 'Git LFS API and storage' do let(:headers) do { - 'Authorization' => authorization, - 'X-Sendfile-Type' => sendfile + "Authorization" => authorization, + "X-Sendfile-Type" => sendfile, }.compact end let(:authorization) { } @@ -20,17 +20,17 @@ describe 'Git LFS API and storage' do let(:sample_oid) { lfs_object.oid } let(:sample_size) { lfs_object.size } - describe 'when lfs is disabled' do + describe "when lfs is disabled" do let(:project) { create(:project) } let(:body) do { - 'objects' => [ - { 'oid' => '91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897', - 'size' => 1575078 }, - { 'oid' => sample_oid, - 'size' => sample_size } + "objects" => [ + {"oid" => "91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897", + "size" => 1575078,}, + {"oid" => sample_oid, + "size" => sample_size,}, ], - 'operation' => 'upload' + "operation" => "upload", } end let(:authorization) { authorize_user } @@ -40,63 +40,63 @@ describe 'Git LFS API and storage' do post_lfs_json "#{project.http_url_to_repo}/info/lfs/objects/batch", body, headers end - it 'responds with 501' do + it "responds with 501" do expect(response).to have_gitlab_http_status(501) - expect(json_response).to include('message' => 'Git LFS is not enabled on this GitLab server, contact your admin.') + expect(json_response).to include("message" => "Git LFS is not enabled on this GitLab server, contact your admin.") end end - context 'project specific LFS settings' do + context "project specific LFS settings" do let(:project) { create(:project) } let(:body) do { - 'objects' => [ - { 'oid' => '91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897', - 'size' => 1575078 }, - { 'oid' => sample_oid, - 'size' => sample_size } + "objects" => [ + {"oid" => "91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897", + "size" => 1575078,}, + {"oid" => sample_oid, + "size" => sample_size,}, ], - 'operation' => 'upload' + "operation" => "upload", } end let(:authorization) { authorize_user } - context 'with LFS disabled globally' do + context "with LFS disabled globally" do before do project.add_maintainer(user) allow(Gitlab.config.lfs).to receive(:enabled).and_return(false) end - describe 'LFS disabled in project' do + describe "LFS disabled in project" do before do project.update_attribute(:lfs_enabled, false) end - it 'responds with a 501 message on upload' do + it "responds with a 501 message on upload" do post_lfs_json "#{project.http_url_to_repo}/info/lfs/objects/batch", body, headers expect(response).to have_gitlab_http_status(501) end - it 'responds with a 501 message on download' do + it "responds with a 501 message on download" do get "#{project.http_url_to_repo}/gitlab-lfs/objects/#{sample_oid}", params: {}, headers: headers expect(response).to have_gitlab_http_status(501) end end - describe 'LFS enabled in project' do + describe "LFS enabled in project" do before do project.update_attribute(:lfs_enabled, true) end - it 'responds with a 501 message on upload' do + it "responds with a 501 message on upload" do post_lfs_json "#{project.http_url_to_repo}/info/lfs/objects/batch", body, headers expect(response).to have_gitlab_http_status(501) end - it 'responds with a 501 message on download' do + it "responds with a 501 message on download" do get "#{project.http_url_to_repo}/gitlab-lfs/objects/#{sample_oid}", params: {}, headers: headers expect(response).to have_gitlab_http_status(501) @@ -104,45 +104,45 @@ describe 'Git LFS API and storage' do end end - context 'with LFS enabled globally' do + context "with LFS enabled globally" do before do project.add_maintainer(user) enable_lfs end - describe 'LFS disabled in project' do + describe "LFS disabled in project" do before do project.update_attribute(:lfs_enabled, false) end - it 'responds with a 403 message on upload' do + it "responds with a 403 message on upload" do post_lfs_json "#{project.http_url_to_repo}/info/lfs/objects/batch", body, headers expect(response).to have_gitlab_http_status(403) - expect(json_response).to include('message' => 'Access forbidden. Check your access level.') + expect(json_response).to include("message" => "Access forbidden. Check your access level.") end - it 'responds with a 403 message on download' do + it "responds with a 403 message on download" do get "#{project.http_url_to_repo}/gitlab-lfs/objects/#{sample_oid}", params: {}, headers: headers expect(response).to have_gitlab_http_status(403) - expect(json_response).to include('message' => 'Access forbidden. Check your access level.') + expect(json_response).to include("message" => "Access forbidden. Check your access level.") end end - describe 'LFS enabled in project' do + describe "LFS enabled in project" do before do project.update_attribute(:lfs_enabled, true) end - it 'responds with a 200 message on upload' do + it "responds with a 200 message on upload" do post_lfs_json "#{project.http_url_to_repo}/info/lfs/objects/batch", body, headers expect(response).to have_gitlab_http_status(200) - expect(json_response['objects'].first['size']).to eq(1575078) + expect(json_response["objects"].first["size"]).to eq(1575078) end - it 'responds with a 200 message on download' do + it "responds with a 200 message on download" do get "#{project.http_url_to_repo}/gitlab-lfs/objects/#{sample_oid}", params: {}, headers: headers expect(response).to have_gitlab_http_status(200) @@ -151,44 +151,44 @@ describe 'Git LFS API and storage' do end end - describe 'deprecated API' do + describe "deprecated API" do let(:project) { create(:project) } before do enable_lfs end - shared_examples 'a deprecated' do - it 'responds with 501' do + shared_examples "a deprecated" do + it "responds with 501" do expect(response).to have_gitlab_http_status(501) end - it 'returns deprecated message' do - expect(json_response).to include('message' => 'Server supports batch API only, please update your Git LFS client to version 1.0.1 and up.') + it "returns deprecated message" do + expect(json_response).to include("message" => "Server supports batch API only, please update your Git LFS client to version 1.0.1 and up.") end end - context 'when fetching lfs object using deprecated API' do + context "when fetching lfs object using deprecated API" do let(:authorization) { authorize_user } before do get "#{project.http_url_to_repo}/info/lfs/objects/#{sample_oid}", params: {}, headers: headers end - it_behaves_like 'a deprecated' + it_behaves_like "a deprecated" end - context 'when handling lfs request using deprecated API' do + context "when handling lfs request using deprecated API" do let(:authorization) { authorize_user } before do post_lfs_json "#{project.http_url_to_repo}/info/lfs/objects", nil, headers end - it_behaves_like 'a deprecated' + it_behaves_like "a deprecated" end end - describe 'when fetching lfs object' do + describe "when fetching lfs object" do let(:project) { create(:project) } let(:update_permissions) { } let(:before_get) { } @@ -200,75 +200,75 @@ describe 'Git LFS API and storage' do get "#{project.http_url_to_repo}/gitlab-lfs/objects/#{sample_oid}", params: {}, headers: headers end - context 'and request comes from gitlab-workhorse' do - context 'without user being authorized' do - it 'responds with status 401' do + context "and request comes from gitlab-workhorse" do + context "without user being authorized" do + it "responds with status 401" do expect(response).to have_gitlab_http_status(401) end end - context 'with required headers' do - shared_examples 'responds with a file' do - let(:sendfile) { 'X-Sendfile' } + context "with required headers" do + shared_examples "responds with a file" do + let(:sendfile) { "X-Sendfile" } - it 'responds with status 200' do + it "responds with status 200" do expect(response).to have_gitlab_http_status(200) end - it 'responds with the file location' do - expect(response.headers['Content-Type']).to eq('application/octet-stream') - expect(response.headers['X-Sendfile']).to eq(lfs_object.file.path) + it "responds with the file location" do + expect(response.headers["Content-Type"]).to eq("application/octet-stream") + expect(response.headers["X-Sendfile"]).to eq(lfs_object.file.path) end end - context 'with user is authorized' do + context "with user is authorized" do let(:authorization) { authorize_user } - context 'and does not have project access' do + context "and does not have project access" do let(:update_permissions) do project.lfs_objects << lfs_object end - it 'responds with status 404' do + it "responds with status 404" do expect(response).to have_gitlab_http_status(404) end end - context 'and does have project access' do + context "and does have project access" do let(:update_permissions) do project.add_maintainer(user) project.lfs_objects << lfs_object end - it_behaves_like 'responds with a file' + it_behaves_like "responds with a file" - context 'when LFS uses object storage' do - context 'when proxy download is enabled' do + context "when LFS uses object storage" do + context "when proxy download is enabled" do let(:before_get) do stub_lfs_object_storage(proxy_download: true) lfs_object.file.migrate!(LfsObjectUploader::Store::REMOTE) end - it 'responds with redirect' do + it "responds with redirect" do expect(response).to have_gitlab_http_status(200) end - it 'responds with the workhorse send-url' do + it "responds with the workhorse send-url" do expect(response.headers[Gitlab::Workhorse::SEND_DATA_HEADER]).to start_with("send-url:") end end - context 'when proxy download is disabled' do + context "when proxy download is disabled" do let(:before_get) do stub_lfs_object_storage(proxy_download: false) lfs_object.file.migrate!(LfsObjectUploader::Store::REMOTE) end - it 'responds with redirect' do + it "responds with redirect" do expect(response).to have_gitlab_http_status(302) end - it 'responds with the file location' do + it "responds with the file location" do expect(response.location).to include(lfs_object.reload.file.path) end end @@ -276,7 +276,7 @@ describe 'Git LFS API and storage' do end end - context 'when deploy key is authorized' do + context "when deploy key is authorized" do let(:key) { create(:deploy_key) } let(:authorization) { authorize_deploy_key } @@ -285,47 +285,47 @@ describe 'Git LFS API and storage' do project.lfs_objects << lfs_object end - it_behaves_like 'responds with a file' + it_behaves_like "responds with a file" end - describe 'when using a user key' do + describe "when using a user key" do let(:authorization) { authorize_user_key } - context 'when user allowed' do + context "when user allowed" do let(:update_permissions) do project.add_maintainer(user) project.lfs_objects << lfs_object end - it_behaves_like 'responds with a file' + it_behaves_like "responds with a file" end - context 'when user not allowed' do + context "when user not allowed" do let(:update_permissions) do project.lfs_objects << lfs_object end - it 'responds with status 404' do + it "responds with status 404" do expect(response).to have_gitlab_http_status(404) end end end - context 'when build is authorized as' do + context "when build is authorized as" do let(:authorization) { authorize_ci_project } - shared_examples 'can download LFS only from own projects' do - context 'for owned project' do + shared_examples "can download LFS only from own projects" do + context "for owned project" do let(:project) { create(:project, namespace: user.namespace) } let(:update_permissions) do project.lfs_objects << lfs_object end - it_behaves_like 'responds with a file' + it_behaves_like "responds with a file" end - context 'for member of project' do + context "for member of project" do let(:pipeline) { create(:ci_empty_pipeline, project: project) } let(:update_permissions) do @@ -333,10 +333,10 @@ describe 'Git LFS API and storage' do project.lfs_objects << lfs_object end - it_behaves_like 'responds with a file' + it_behaves_like "responds with a file" end - context 'for other project' do + context "for other project" do let(:other_project) { create(:project) } let(:pipeline) { create(:ci_empty_pipeline, project: other_project) } @@ -344,36 +344,36 @@ describe 'Git LFS API and storage' do project.lfs_objects << lfs_object end - it 'rejects downloading code' do + it "rejects downloading code" do expect(response).to have_gitlab_http_status(other_project_status) end end end - context 'administrator' do + context "administrator" do let(:user) { create(:admin) } let(:build) { create(:ci_build, :running, pipeline: pipeline, user: user) } - it_behaves_like 'can download LFS only from own projects' do + it_behaves_like "can download LFS only from own projects" do # We render 403, because administrator does have normally access let(:other_project_status) { 403 } end end - context 'regular user' do + context "regular user" do let(:user) { create(:user) } let(:build) { create(:ci_build, :running, pipeline: pipeline, user: user) } - it_behaves_like 'can download LFS only from own projects' do + it_behaves_like "can download LFS only from own projects" do # We render 404, to prevent data leakage about existence of the project let(:other_project_status) { 404 } end end - context 'does not have user' do + context "does not have user" do let(:build) { create(:ci_build, :running, pipeline: pipeline) } - it_behaves_like 'can download LFS only from own projects' do + it_behaves_like "can download LFS only from own projects" do # We render 404, to prevent data leakage about existence of the project let(:other_project_status) { 404 } end @@ -381,17 +381,17 @@ describe 'Git LFS API and storage' do end end - context 'without required headers' do + context "without required headers" do let(:authorization) { authorize_user } - it 'responds with status 404' do + it "responds with status 404" do expect(response).to have_gitlab_http_status(404) end end end end - describe 'when handling lfs batch request' do + describe "when handling lfs batch request" do let(:update_lfs_permissions) { } let(:update_user_permissions) { } @@ -402,113 +402,113 @@ describe 'Git LFS API and storage' do post_lfs_json "#{project.http_url_to_repo}/info/lfs/objects/batch", body, headers end - describe 'download' do + describe "download" do let(:project) { create(:project) } let(:body) do { - 'operation' => 'download', - 'objects' => [ - { 'oid' => sample_oid, - 'size' => sample_size } - ] + "operation" => "download", + "objects" => [ + {"oid" => sample_oid, + "size" => sample_size,}, + ], } end - shared_examples 'an authorized requests' do - context 'when downloading an lfs object that is assigned to our project' do + shared_examples "an authorized requests" do + context "when downloading an lfs object that is assigned to our project" do let(:update_lfs_permissions) do project.lfs_objects << lfs_object end - it 'responds with status 200' do + it "responds with status 200" do expect(response).to have_gitlab_http_status(200) end - it 'with href to download' do + it "with href to download" do expect(json_response).to eq({ - 'objects' => [ + "objects" => [ { - 'oid' => sample_oid, - 'size' => sample_size, - 'actions' => { - 'download' => { - 'href' => "#{project.http_url_to_repo}/gitlab-lfs/objects/#{sample_oid}", - 'header' => { 'Authorization' => authorization } - } - } - } - ] + "oid" => sample_oid, + "size" => sample_size, + "actions" => { + "download" => { + "href" => "#{project.http_url_to_repo}/gitlab-lfs/objects/#{sample_oid}", + "header" => {"Authorization" => authorization}, + }, + }, + }, + ], }) end end - context 'when downloading an lfs object that is assigned to other project' do + context "when downloading an lfs object that is assigned to other project" do let(:other_project) { create(:project) } let(:update_lfs_permissions) do other_project.lfs_objects << lfs_object end - it 'responds with status 200' do + it "responds with status 200" do expect(response).to have_gitlab_http_status(200) end - it 'with href to download' do + it "with href to download" do expect(json_response).to eq({ - 'objects' => [ + "objects" => [ { - 'oid' => sample_oid, - 'size' => sample_size, - 'error' => { - 'code' => 404, - 'message' => "Object does not exist on the server or you don't have permissions to access it" - } - } - ] + "oid" => sample_oid, + "size" => sample_size, + "error" => { + "code" => 404, + "message" => "Object does not exist on the server or you don't have permissions to access it", + }, + }, + ], }) end end - context 'when downloading a lfs object that does not exist' do + context "when downloading a lfs object that does not exist" do let(:body) do { - 'operation' => 'download', - 'objects' => [ - { 'oid' => '91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897', - 'size' => 1575078 } - ] + "operation" => "download", + "objects" => [ + {"oid" => "91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897", + "size" => 1575078,}, + ], } end - it 'responds with status 200' do + it "responds with status 200" do expect(response).to have_gitlab_http_status(200) end - it 'with an 404 for specific object' do + it "with an 404 for specific object" do expect(json_response).to eq({ - 'objects' => [ + "objects" => [ { - 'oid' => '91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897', - 'size' => 1575078, - 'error' => { - 'code' => 404, - 'message' => "Object does not exist on the server or you don't have permissions to access it" - } - } - ] + "oid" => "91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897", + "size" => 1575078, + "error" => { + "code" => 404, + "message" => "Object does not exist on the server or you don't have permissions to access it", + }, + }, + ], }) end end - context 'when downloading one new and one existing lfs object' do + context "when downloading one new and one existing lfs object" do let(:body) do { - 'operation' => 'download', - 'objects' => [ - { 'oid' => '91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897', - 'size' => 1575078 }, - { 'oid' => sample_oid, - 'size' => sample_size } - ] + "operation" => "download", + "objects" => [ + {"oid" => "91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897", + "size" => 1575078,}, + {"oid" => sample_oid, + "size" => sample_size,}, + ], } end @@ -516,66 +516,66 @@ describe 'Git LFS API and storage' do project.lfs_objects << lfs_object end - it 'responds with status 200' do + it "responds with status 200" do expect(response).to have_gitlab_http_status(200) end - it 'responds with upload hypermedia link for the new object' do + it "responds with upload hypermedia link for the new object" do expect(json_response).to eq({ - 'objects' => [ + "objects" => [ { - 'oid' => '91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897', - 'size' => 1575078, - 'error' => { - 'code' => 404, - 'message' => "Object does not exist on the server or you don't have permissions to access it" - } + "oid" => "91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897", + "size" => 1575078, + "error" => { + "code" => 404, + "message" => "Object does not exist on the server or you don't have permissions to access it", + }, }, { - 'oid' => sample_oid, - 'size' => sample_size, - 'actions' => { - 'download' => { - 'href' => "#{project.http_url_to_repo}/gitlab-lfs/objects/#{sample_oid}", - 'header' => { 'Authorization' => authorization } - } - } - } - ] + "oid" => sample_oid, + "size" => sample_size, + "actions" => { + "download" => { + "href" => "#{project.http_url_to_repo}/gitlab-lfs/objects/#{sample_oid}", + "header" => {"Authorization" => authorization}, + }, + }, + }, + ], }) end end end - context 'when user is authenticated' do + context "when user is authenticated" do let(:authorization) { authorize_user } let(:update_user_permissions) do project.add_role(user, role) end - it_behaves_like 'an authorized requests' do + it_behaves_like "an authorized requests" do let(:role) { :reporter } end - context 'when user does is not member of the project' do + context "when user does is not member of the project" do let(:update_user_permissions) { nil } - it 'responds with 404' do + it "responds with 404" do expect(response).to have_gitlab_http_status(404) end end - context 'when user does not have download access' do + context "when user does not have download access" do let(:role) { :guest } - it 'responds with 403' do + it "responds with 403" do expect(response).to have_gitlab_http_status(403) end end end - context 'when using Deploy Tokens' do + context "when using Deploy Tokens" do let(:project) { create(:project, :repository) } let(:authorization) { authorize_deploy_token } let(:update_user_permissions) { nil } @@ -584,201 +584,201 @@ describe 'Git LFS API and storage' do project.lfs_objects << lfs_object end - context 'when Deploy Token is valid' do + context "when Deploy Token is valid" do let(:deploy_token) { create(:deploy_token, projects: [project]) } - it_behaves_like 'an authorized requests' + it_behaves_like "an authorized requests" end - context 'when Deploy Token is not valid' do + context "when Deploy Token is not valid" do let(:deploy_token) { create(:deploy_token, projects: [project], read_repository: false) } - it 'responds with access denied' do + it "responds with access denied" do expect(response).to have_gitlab_http_status(401) end end - context 'when Deploy Token is not related to the project' do + context "when Deploy Token is not related to the project" do let(:another_project) { create(:project, :repository) } let(:deploy_token) { create(:deploy_token, projects: [another_project]) } - it 'responds with access forbidden' do + it "responds with access forbidden" do # We render 404, to prevent data leakage about existence of the project expect(response).to have_gitlab_http_status(404) end end end - context 'when build is authorized as' do + context "when build is authorized as" do let(:authorization) { authorize_ci_project } let(:update_lfs_permissions) do project.lfs_objects << lfs_object end - shared_examples 'can download LFS only from own projects' do - context 'for own project' do + shared_examples "can download LFS only from own projects" do + context "for own project" do let(:pipeline) { create(:ci_empty_pipeline, project: project) } let(:update_user_permissions) do project.add_reporter(user) end - it_behaves_like 'an authorized requests' + it_behaves_like "an authorized requests" end - context 'for other project' do + context "for other project" do let(:other_project) { create(:project) } let(:pipeline) { create(:ci_empty_pipeline, project: other_project) } - it 'rejects downloading code' do + it "rejects downloading code" do expect(response).to have_gitlab_http_status(other_project_status) end end end - context 'administrator' do + context "administrator" do let(:user) { create(:admin) } let(:build) { create(:ci_build, :running, pipeline: pipeline, user: user) } - it_behaves_like 'can download LFS only from own projects' do + it_behaves_like "can download LFS only from own projects" do # We render 403, because administrator does have normally access let(:other_project_status) { 403 } end end - context 'regular user' do + context "regular user" do let(:user) { create(:user) } let(:build) { create(:ci_build, :running, pipeline: pipeline, user: user) } - it_behaves_like 'can download LFS only from own projects' do + it_behaves_like "can download LFS only from own projects" do # We render 404, to prevent data leakage about existence of the project let(:other_project_status) { 404 } end end - context 'does not have user' do + context "does not have user" do let(:build) { create(:ci_build, :running, pipeline: pipeline) } - it_behaves_like 'can download LFS only from own projects' do + it_behaves_like "can download LFS only from own projects" do # We render 404, to prevent data leakage about existence of the project let(:other_project_status) { 404 } end end end - context 'when user is not authenticated' do - describe 'is accessing public project' do + context "when user is not authenticated" do + describe "is accessing public project" do let(:project) { create(:project, :public) } let(:update_lfs_permissions) do project.lfs_objects << lfs_object end - it 'responds with status 200 and href to download' do + it "responds with status 200 and href to download" do expect(response).to have_gitlab_http_status(200) end - it 'responds with status 200 and href to download' do + it "responds with status 200 and href to download" do expect(json_response).to eq({ - 'objects' => [ + "objects" => [ { - 'oid' => sample_oid, - 'size' => sample_size, - 'authenticated' => true, - 'actions' => { - 'download' => { - 'href' => "#{project.http_url_to_repo}/gitlab-lfs/objects/#{sample_oid}", - 'header' => {} - } - } - } - ] + "oid" => sample_oid, + "size" => sample_size, + "authenticated" => true, + "actions" => { + "download" => { + "href" => "#{project.http_url_to_repo}/gitlab-lfs/objects/#{sample_oid}", + "header" => {}, + }, + }, + }, + ], }) end end - describe 'is accessing non-public project' do + describe "is accessing non-public project" do let(:update_lfs_permissions) do project.lfs_objects << lfs_object end - it 'responds with authorization required' do + it "responds with authorization required" do expect(response).to have_gitlab_http_status(401) end end end end - describe 'upload' do + describe "upload" do let(:project) { create(:project, :public) } let(:body) do { - 'operation' => 'upload', - 'objects' => [ - { 'oid' => sample_oid, - 'size' => sample_size } - ] + "operation" => "upload", + "objects" => [ + {"oid" => sample_oid, + "size" => sample_size,}, + ], } end - shared_examples 'pushes new LFS objects' do + shared_examples "pushes new LFS objects" do let(:sample_size) { 150.megabytes } - let(:sample_oid) { '91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897' } + let(:sample_oid) { "91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897" } - it 'responds with upload hypermedia link' do + it "responds with upload hypermedia link" do expect(response).to have_gitlab_http_status(200) - expect(json_response['objects']).to be_kind_of(Array) - expect(json_response['objects'].first['oid']).to eq(sample_oid) - expect(json_response['objects'].first['size']).to eq(sample_size) - expect(json_response['objects'].first['actions']['upload']['href']).to eq("#{Gitlab.config.gitlab.url}/#{project.full_path}.git/gitlab-lfs/objects/#{sample_oid}/#{sample_size}") - expect(json_response['objects'].first['actions']['upload']['header']).to eq({ 'Authorization' => authorization, 'Content-Type' => 'application/octet-stream' }) + expect(json_response["objects"]).to be_kind_of(Array) + expect(json_response["objects"].first["oid"]).to eq(sample_oid) + expect(json_response["objects"].first["size"]).to eq(sample_size) + expect(json_response["objects"].first["actions"]["upload"]["href"]).to eq("#{Gitlab.config.gitlab.url}/#{project.full_path}.git/gitlab-lfs/objects/#{sample_oid}/#{sample_size}") + expect(json_response["objects"].first["actions"]["upload"]["header"]).to eq({"Authorization" => authorization, "Content-Type" => "application/octet-stream"}) end end - describe 'when request is authenticated' do - describe 'when user has project push access' do + describe "when request is authenticated" do + describe "when user has project push access" do let(:authorization) { authorize_user } let(:update_user_permissions) do project.add_developer(user) end - context 'when pushing an lfs object that already exists' do + context "when pushing an lfs object that already exists" do let(:other_project) { create(:project) } let(:update_lfs_permissions) do other_project.lfs_objects << lfs_object end - it 'responds with status 200' do + it "responds with status 200" do expect(response).to have_gitlab_http_status(200) end - it 'responds with links the object to the project' do - expect(json_response['objects']).to be_kind_of(Array) - expect(json_response['objects'].first['oid']).to eq(sample_oid) - expect(json_response['objects'].first['size']).to eq(sample_size) + it "responds with links the object to the project" do + expect(json_response["objects"]).to be_kind_of(Array) + expect(json_response["objects"].first["oid"]).to eq(sample_oid) + expect(json_response["objects"].first["size"]).to eq(sample_size) expect(lfs_object.projects.pluck(:id)).not_to include(project.id) expect(lfs_object.projects.pluck(:id)).to include(other_project.id) - expect(json_response['objects'].first['actions']['upload']['href']).to eq("#{project.http_url_to_repo}/gitlab-lfs/objects/#{sample_oid}/#{sample_size}") - expect(json_response['objects'].first['actions']['upload']['header']).to eq({ 'Authorization' => authorization, 'Content-Type' => 'application/octet-stream' }) + expect(json_response["objects"].first["actions"]["upload"]["href"]).to eq("#{project.http_url_to_repo}/gitlab-lfs/objects/#{sample_oid}/#{sample_size}") + expect(json_response["objects"].first["actions"]["upload"]["header"]).to eq({"Authorization" => authorization, "Content-Type" => "application/octet-stream"}) end end - context 'when pushing a lfs object that does not exist' do - it_behaves_like 'pushes new LFS objects' + context "when pushing a lfs object that does not exist" do + it_behaves_like "pushes new LFS objects" end - context 'when pushing one new and one existing lfs object' do + context "when pushing one new and one existing lfs object" do let(:body) do { - 'operation' => 'upload', - 'objects' => [ - { 'oid' => '91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897', - 'size' => 1575078 }, - { 'oid' => sample_oid, - 'size' => sample_size } - ] + "operation" => "upload", + "objects" => [ + {"oid" => "91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897", + "size" => 1575078,}, + {"oid" => sample_oid, + "size" => sample_size,}, + ], } end @@ -786,69 +786,69 @@ describe 'Git LFS API and storage' do project.lfs_objects << lfs_object end - it 'responds with status 200' do + it "responds with status 200" do expect(response).to have_gitlab_http_status(200) end - it 'responds with upload hypermedia link for the new object' do - expect(json_response['objects']).to be_kind_of(Array) + it "responds with upload hypermedia link for the new object" do + expect(json_response["objects"]).to be_kind_of(Array) - expect(json_response['objects'].first['oid']).to eq("91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897") - expect(json_response['objects'].first['size']).to eq(1575078) - expect(json_response['objects'].first['actions']['upload']['href']).to eq("#{project.http_url_to_repo}/gitlab-lfs/objects/91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897/1575078") - expect(json_response['objects'].first['actions']['upload']['header']).to eq({ 'Authorization' => authorization, 'Content-Type' => 'application/octet-stream' }) + expect(json_response["objects"].first["oid"]).to eq("91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897") + expect(json_response["objects"].first["size"]).to eq(1575078) + expect(json_response["objects"].first["actions"]["upload"]["href"]).to eq("#{project.http_url_to_repo}/gitlab-lfs/objects/91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897/1575078") + expect(json_response["objects"].first["actions"]["upload"]["header"]).to eq({"Authorization" => authorization, "Content-Type" => "application/octet-stream"}) - expect(json_response['objects'].last['oid']).to eq(sample_oid) - expect(json_response['objects'].last['size']).to eq(sample_size) - expect(json_response['objects'].last).not_to have_key('actions') + expect(json_response["objects"].last["oid"]).to eq(sample_oid) + expect(json_response["objects"].last["size"]).to eq(sample_size) + expect(json_response["objects"].last).not_to have_key("actions") end end end - context 'when user does not have push access' do + context "when user does not have push access" do let(:authorization) { authorize_user } - it 'responds with 403' do + it "responds with 403" do expect(response).to have_gitlab_http_status(403) end end - context 'when build is authorized' do + context "when build is authorized" do let(:authorization) { authorize_ci_project } - context 'build has an user' do + context "build has an user" do let(:user) { create(:user) } - context 'tries to push to own project' do + context "tries to push to own project" do let(:build) { create(:ci_build, :running, pipeline: pipeline, user: user) } - it 'responds with 403 (not 404 because project is public)' do + it "responds with 403 (not 404 because project is public)" do expect(response).to have_gitlab_http_status(403) end end - context 'tries to push to other project' do + context "tries to push to other project" do let(:other_project) { create(:project) } let(:pipeline) { create(:ci_empty_pipeline, project: other_project) } let(:build) { create(:ci_build, :running, pipeline: pipeline, user: user) } # I'm not sure what this tests that is different from the previous test - it 'responds with 403 (not 404 because project is public)' do + it "responds with 403 (not 404 because project is public)" do expect(response).to have_gitlab_http_status(403) end end end - context 'does not have user' do + context "does not have user" do let(:build) { create(:ci_build, :running, pipeline: pipeline) } - it 'responds with 403 (not 404 because project is public)' do + it "responds with 403 (not 404 because project is public)" do expect(response).to have_gitlab_http_status(403) end end end - context 'when deploy key has project push access' do + context "when deploy key has project push access" do let(:key) { create(:deploy_key) } let(:authorization) { authorize_deploy_key } @@ -856,54 +856,54 @@ describe 'Git LFS API and storage' do project.deploy_keys_projects.create(deploy_key: key, can_push: true) end - it_behaves_like 'pushes new LFS objects' + it_behaves_like "pushes new LFS objects" end end - context 'when user is not authenticated' do - context 'when user has push access' do + context "when user is not authenticated" do + context "when user has push access" do let(:update_user_permissions) do project.add_maintainer(user) end - it 'responds with status 401' do + it "responds with status 401" do expect(response).to have_gitlab_http_status(401) end end - context 'when user does not have push access' do - it 'responds with status 401' do + context "when user does not have push access" do + it "responds with status 401" do expect(response).to have_gitlab_http_status(401) end end end end - describe 'unsupported' do + describe "unsupported" do let(:project) { create(:project) } let(:authorization) { authorize_user } let(:body) do { - 'operation' => 'other', - 'objects' => [ - { 'oid' => sample_oid, - 'size' => sample_size } - ] + "operation" => "other", + "objects" => [ + {"oid" => sample_oid, + "size" => sample_size,}, + ], } end - it 'responds with status 404' do + it "responds with status 404" do expect(response).to have_gitlab_http_status(404) end end end - describe 'when handling lfs batch request on a read-only GitLab instance' do + describe "when handling lfs batch request on a read-only GitLab instance" do let(:authorization) { authorize_user } let(:project) { create(:project) } let(:path) { "#{project.http_url_to_repo}/info/lfs/objects/batch" } let(:body) do - { 'objects' => [{ 'oid' => sample_oid, 'size' => sample_size }] } + {"objects" => [{"oid" => sample_oid, "size" => sample_size}]} end before do @@ -912,192 +912,192 @@ describe 'Git LFS API and storage' do enable_lfs end - it 'responds with a 200 message on download' do - post_lfs_json path, body.merge('operation' => 'download'), headers + it "responds with a 200 message on download" do + post_lfs_json path, body.merge("operation" => "download"), headers expect(response).to have_gitlab_http_status(200) end - it 'responds with a 403 message on upload' do - post_lfs_json path, body.merge('operation' => 'upload'), headers + it "responds with a 403 message on upload" do + post_lfs_json path, body.merge("operation" => "upload"), headers expect(response).to have_gitlab_http_status(403) - expect(json_response).to include('message' => 'You cannot write to this read-only GitLab instance.') + expect(json_response).to include("message" => "You cannot write to this read-only GitLab instance.") end end - describe 'when pushing a lfs object' do + describe "when pushing a lfs object" do before do enable_lfs end - shared_examples 'unauthorized' do - context 'and request is sent by gitlab-workhorse to authorize the request' do + shared_examples "unauthorized" do + context "and request is sent by gitlab-workhorse to authorize the request" do before do put_authorize end - it 'responds with status 401' do + it "responds with status 401" do expect(response).to have_gitlab_http_status(401) end end - context 'and request is sent by gitlab-workhorse to finalize the upload' do + context "and request is sent by gitlab-workhorse to finalize the upload" do before do put_finalize end - it 'responds with status 401' do + it "responds with status 401" do expect(response).to have_gitlab_http_status(401) end end - context 'and request is sent with a malformed headers' do + context "and request is sent with a malformed headers" do before do - put_finalize('/etc/passwd') + put_finalize("/etc/passwd") end - it 'does not recognize it as a valid lfs command' do + it "does not recognize it as a valid lfs command" do expect(response).to have_gitlab_http_status(401) end end end - shared_examples 'forbidden' do - context 'and request is sent by gitlab-workhorse to authorize the request' do + shared_examples "forbidden" do + context "and request is sent by gitlab-workhorse to authorize the request" do before do put_authorize end - it 'responds with 403' do + it "responds with 403" do expect(response).to have_gitlab_http_status(403) end end - context 'and request is sent by gitlab-workhorse to finalize the upload' do + context "and request is sent by gitlab-workhorse to finalize the upload" do before do put_finalize end - it 'responds with 403' do + it "responds with 403" do expect(response).to have_gitlab_http_status(403) end end - context 'and request is sent with a malformed headers' do + context "and request is sent with a malformed headers" do before do - put_finalize('/etc/passwd') + put_finalize("/etc/passwd") end - it 'does not recognize it as a valid lfs command' do + it "does not recognize it as a valid lfs command" do expect(response).to have_gitlab_http_status(403) end end end - describe 'to one project' do + describe "to one project" do let(:project) { create(:project) } - describe 'when user is authenticated' do + describe "when user is authenticated" do let(:authorization) { authorize_user } - describe 'when user has push access to the project' do + describe "when user has push access to the project" do before do project.add_developer(user) end - context 'and the request bypassed workhorse' do - it 'raises an exception' do + context "and the request bypassed workhorse" do + it "raises an exception" do expect { put_authorize(verified: false) }.to raise_error JWT::DecodeError end end - context 'and request is sent by gitlab-workhorse to authorize the request' do - shared_examples 'a valid response' do + context "and request is sent by gitlab-workhorse to authorize the request" do + shared_examples "a valid response" do before do put_authorize end - it 'responds with status 200' do + it "responds with status 200" do expect(response).to have_gitlab_http_status(200) end - it 'uses the gitlab-workhorse content type' do + it "uses the gitlab-workhorse content type" do expect(response.content_type.to_s).to eq(Gitlab::Workhorse::INTERNAL_API_CONTENT_TYPE) end end - shared_examples 'a local file' do - it_behaves_like 'a valid response' do - it 'responds with status 200, location of lfs store and object details' do - expect(json_response['TempPath']).to eq(LfsObjectUploader.workhorse_local_upload_path) - expect(json_response['RemoteObject']).to be_nil - expect(json_response['LfsOid']).to eq(sample_oid) - expect(json_response['LfsSize']).to eq(sample_size) + shared_examples "a local file" do + it_behaves_like "a valid response" do + it "responds with status 200, location of lfs store and object details" do + expect(json_response["TempPath"]).to eq(LfsObjectUploader.workhorse_local_upload_path) + expect(json_response["RemoteObject"]).to be_nil + expect(json_response["LfsOid"]).to eq(sample_oid) + expect(json_response["LfsSize"]).to eq(sample_size) end end end - context 'when using local storage' do - it_behaves_like 'a local file' + context "when using local storage" do + it_behaves_like "a local file" end - context 'when using remote storage' do - context 'when direct upload is enabled' do + context "when using remote storage" do + context "when direct upload is enabled" do before do stub_lfs_object_storage(enabled: true, direct_upload: true) end - it_behaves_like 'a valid response' do - it 'responds with status 200, location of lfs remote store and object details' do - expect(json_response['TempPath']).to eq(LfsObjectUploader.workhorse_local_upload_path) - expect(json_response['RemoteObject']).to have_key('ID') - expect(json_response['RemoteObject']).to have_key('GetURL') - expect(json_response['RemoteObject']).to have_key('StoreURL') - expect(json_response['RemoteObject']).to have_key('DeleteURL') - expect(json_response['RemoteObject']).not_to have_key('MultipartUpload') - expect(json_response['LfsOid']).to eq(sample_oid) - expect(json_response['LfsSize']).to eq(sample_size) + it_behaves_like "a valid response" do + it "responds with status 200, location of lfs remote store and object details" do + expect(json_response["TempPath"]).to eq(LfsObjectUploader.workhorse_local_upload_path) + expect(json_response["RemoteObject"]).to have_key("ID") + expect(json_response["RemoteObject"]).to have_key("GetURL") + expect(json_response["RemoteObject"]).to have_key("StoreURL") + expect(json_response["RemoteObject"]).to have_key("DeleteURL") + expect(json_response["RemoteObject"]).not_to have_key("MultipartUpload") + expect(json_response["LfsOid"]).to eq(sample_oid) + expect(json_response["LfsSize"]).to eq(sample_size) end end end - context 'when direct upload is disabled' do + context "when direct upload is disabled" do before do stub_lfs_object_storage(enabled: true, direct_upload: false) end - it_behaves_like 'a local file' + it_behaves_like "a local file" end end end - context 'and request is sent by gitlab-workhorse to finalize the upload' do + context "and request is sent by gitlab-workhorse to finalize the upload" do before do put_finalize end - it 'responds with status 200' do + it "responds with status 200" do expect(response).to have_gitlab_http_status(200) end - it 'lfs object is linked to the project' do + it "lfs object is linked to the project" do expect(lfs_object.projects.pluck(:id)).to include(project.id) end end - context 'and request to finalize the upload is not sent by gitlab-workhorse' do - it 'fails with a JWT decode error' do + context "and request to finalize the upload is not sent by gitlab-workhorse" do + it "fails with a JWT decode error" do expect { put_finalize(lfs_tmp_file, verified: false) }.to raise_error(JWT::DecodeError) end end - context 'and workhorse requests upload finalize for a new lfs object' do + context "and workhorse requests upload finalize for a new lfs object" do before do lfs_object.destroy end - context 'with object storage disabled' do + context "with object storage disabled" do it "doesn't attempt to migrate file to object storage" do expect(ObjectStorage::BackgroundMoveWorker).not_to receive(:perform_async) @@ -1105,21 +1105,21 @@ describe 'Git LFS API and storage' do end end - context 'with object storage enabled' do - context 'and direct upload enabled' do + context "with object storage enabled" do + context "and direct upload enabled" do let!(:fog_connection) do stub_lfs_object_storage(direct_upload: true) end - ['123123', '../../123123'].each do |remote_id| + ["123123", "../../123123"].each do |remote_id| context "with invalid remote_id: #{remote_id}" do subject do put_finalize(with_tempfile: true, args: { - 'file.remote_id' => remote_id + "file.remote_id" => remote_id, }) end - it 'responds with status 403' do + it "responds with status 403" do subject expect(response).to have_gitlab_http_status(403) @@ -1127,34 +1127,34 @@ describe 'Git LFS API and storage' do end end - context 'with valid remote_id' do + context "with valid remote_id" do before do - fog_connection.directories.new(key: 'lfs-objects').files.create( - key: 'tmp/uploads/12312300', - body: 'content' + fog_connection.directories.new(key: "lfs-objects").files.create( + key: "tmp/uploads/12312300", + body: "content" ) end subject do put_finalize(with_tempfile: true, args: { - 'file.remote_id' => '12312300', - 'file.name' => 'name' + "file.remote_id" => "12312300", + "file.name" => "name", }) end - it 'responds with status 200' do + it "responds with status 200" do subject expect(response).to have_gitlab_http_status(200) end - it 'schedules migration of file to object storage' do + it "schedules migration of file to object storage" do subject expect(LfsObject.last.projects).to include(project) end - it 'have valid file' do + it "have valid file" do subject expect(LfsObject.last.file_store).to eq(ObjectStorage::Store::REMOTE) @@ -1163,13 +1163,13 @@ describe 'Git LFS API and storage' do end end - context 'and background upload enabled' do + context "and background upload enabled" do before do stub_lfs_object_storage(background_upload: true) end - it 'schedules migration of file to object storage' do - expect(ObjectStorage::BackgroundMoveWorker).to receive(:perform_async).with('LfsObjectUploader', 'LfsObject', :file, kind_of(Numeric)) + it "schedules migration of file to object storage" do + expect(ObjectStorage::BackgroundMoveWorker).to receive(:perform_async).with("LfsObjectUploader", "LfsObject", :file, kind_of(Numeric)) put_finalize(with_tempfile: true) end @@ -1177,34 +1177,34 @@ describe 'Git LFS API and storage' do end end - context 'invalid tempfiles' do + context "invalid tempfiles" do before do lfs_object.destroy end - it 'rejects slashes in the tempfile name (path traversal)' do - put_finalize('../bar', with_tempfile: true) + it "rejects slashes in the tempfile name (path traversal)" do + put_finalize("../bar", with_tempfile: true) expect(response).to have_gitlab_http_status(403) end end end - describe 'and user does not have push access' do + describe "and user does not have push access" do before do project.add_reporter(user) end - it_behaves_like 'forbidden' + it_behaves_like "forbidden" end end - context 'when build is authorized' do + context "when build is authorized" do let(:authorization) { authorize_ci_project } - context 'build has an user' do + context "build has an user" do let(:user) { create(:user) } - context 'tries to push to own project' do + context "tries to push to own project" do let(:build) { create(:ci_build, :running, pipeline: pipeline, user: user) } before do @@ -1212,12 +1212,12 @@ describe 'Git LFS API and storage' do put_authorize end - it 'responds with 403 (not 404 because the build user can read the project)' do + it "responds with 403 (not 404 because the build user can read the project)" do expect(response).to have_gitlab_http_status(403) end end - context 'tries to push to other project' do + context "tries to push to other project" do let(:other_project) { create(:project) } let(:pipeline) { create(:ci_empty_pipeline, project: other_project) } let(:build) { create(:ci_build, :running, pipeline: pipeline, user: user) } @@ -1226,123 +1226,123 @@ describe 'Git LFS API and storage' do put_authorize end - it 'responds with 404 (do not leak non-public project existence)' do + it "responds with 404 (do not leak non-public project existence)" do expect(response).to have_gitlab_http_status(404) end end end - context 'does not have user' do + context "does not have user" do let(:build) { create(:ci_build, :running, pipeline: pipeline) } before do put_authorize end - it 'responds with 404 (do not leak non-public project existence)' do + it "responds with 404 (do not leak non-public project existence)" do expect(response).to have_gitlab_http_status(404) end end end - context 'for unauthenticated' do - it_behaves_like 'unauthorized' + context "for unauthenticated" do + it_behaves_like "unauthorized" end end - describe 'to a forked project' do + describe "to a forked project" do let(:upstream_project) { create(:project, :public) } let(:project_owner) { create(:user) } let(:project) { fork_project(upstream_project, project_owner) } - describe 'when user is authenticated' do + describe "when user is authenticated" do let(:authorization) { authorize_user } - describe 'when user has push access to the project' do + describe "when user has push access to the project" do before do project.add_developer(user) end - context 'and request is sent by gitlab-workhorse to authorize the request' do + context "and request is sent by gitlab-workhorse to authorize the request" do before do put_authorize end - it 'responds with status 200' do + it "responds with status 200" do expect(response).to have_gitlab_http_status(200) end - it 'with location of lfs store and object details' do - expect(json_response['TempPath']).to eq(LfsObjectUploader.workhorse_local_upload_path) - expect(json_response['LfsOid']).to eq(sample_oid) - expect(json_response['LfsSize']).to eq(sample_size) + it "with location of lfs store and object details" do + expect(json_response["TempPath"]).to eq(LfsObjectUploader.workhorse_local_upload_path) + expect(json_response["LfsOid"]).to eq(sample_oid) + expect(json_response["LfsSize"]).to eq(sample_size) end end - context 'and request is sent by gitlab-workhorse to finalize the upload' do + context "and request is sent by gitlab-workhorse to finalize the upload" do before do put_finalize end - it 'responds with status 200' do + it "responds with status 200" do expect(response).to have_gitlab_http_status(200) end - it 'lfs object is linked to the source project' do + it "lfs object is linked to the source project" do expect(lfs_object.projects.pluck(:id)).to include(upstream_project.id) end end end - describe 'and user does not have push access' do - it_behaves_like 'forbidden' + describe "and user does not have push access" do + it_behaves_like "forbidden" end end - context 'when build is authorized' do + context "when build is authorized" do let(:authorization) { authorize_ci_project } before do put_authorize end - context 'build has an user' do + context "build has an user" do let(:user) { create(:user) } - context 'tries to push to own project' do + context "tries to push to own project" do let(:build) { create(:ci_build, :running, pipeline: pipeline, user: user) } - it 'responds with 403 (not 404 because project is public)' do + it "responds with 403 (not 404 because project is public)" do expect(response).to have_gitlab_http_status(403) end end - context 'tries to push to other project' do + context "tries to push to other project" do let(:other_project) { create(:project) } let(:pipeline) { create(:ci_empty_pipeline, project: other_project) } let(:build) { create(:ci_build, :running, pipeline: pipeline, user: user) } # I'm not sure what this tests that is different from the previous test - it 'responds with 403 (not 404 because project is public)' do + it "responds with 403 (not 404 because project is public)" do expect(response).to have_gitlab_http_status(403) end end end - context 'does not have user' do + context "does not have user" do let(:build) { create(:ci_build, :running, pipeline: pipeline) } - it 'responds with 403 (not 404 because project is public)' do + it "responds with 403 (not 404 because project is public)" do expect(response).to have_gitlab_http_status(403) end end end - context 'for unauthenticated' do - it_behaves_like 'unauthorized' + context "for unauthenticated" do + it_behaves_like "unauthorized" end - describe 'and second project not related to fork or a source project' do + describe "and second project not related to fork or a source project" do let(:second_project) { create(:project) } let(:authorization) { authorize_user } @@ -1351,22 +1351,22 @@ describe 'Git LFS API and storage' do upstream_project.lfs_objects << lfs_object end - context 'when pushing the same lfs object to the second project' do + context "when pushing the same lfs object to the second project" do before do finalize_headers = headers - .merge('X-Gitlab-Lfs-Tmp' => lfs_tmp_file) + .merge("X-Gitlab-Lfs-Tmp" => lfs_tmp_file) .merge(workhorse_internal_api_request_header) put "#{second_project.http_url_to_repo}/gitlab-lfs/objects/#{sample_oid}/#{sample_size}", - params: {}, - headers: finalize_headers + params: {}, + headers: finalize_headers end - it 'responds with status 200' do + it "responds with status 200" do expect(response).to have_gitlab_http_status(200) end - it 'links the lfs object to the project' do + it "links the lfs object to the project" do expect(lfs_object.projects.pluck(:id)).to include(second_project.id, upstream_project.id) end end @@ -1382,7 +1382,7 @@ describe 'Git LFS API and storage' do def put_finalize(lfs_tmp = lfs_tmp_file, with_tempfile: false, verified: true, args: {}) upload_path = LfsObjectUploader.workhorse_local_upload_path - file_path = upload_path + '/' + lfs_tmp if lfs_tmp + file_path = upload_path + "/" + lfs_tmp if lfs_tmp if with_tempfile FileUtils.mkdir_p(upload_path) @@ -1390,8 +1390,8 @@ describe 'Git LFS API and storage' do end extra_args = { - 'file.path' => file_path, - 'file.name' => File.basename(file_path) + "file.path" => file_path, + "file.name" => File.basename(file_path), } put_finalize_with_args(args.merge(extra_args).compact, verified: verified) @@ -1414,7 +1414,7 @@ describe 'Git LFS API and storage' do end def authorize_ci_project - ActionController::HttpAuthentication::Basic.encode_credentials('gitlab-ci-token', build.token) + ActionController::HttpAuthentication::Basic.encode_credentials("gitlab-ci-token", build.token) end def authorize_user @@ -1435,7 +1435,7 @@ describe 'Git LFS API and storage' do def post_lfs_json(url, body = nil, headers = nil) params = body.try(:to_json) - headers = (headers || {}).merge('Content-Type' => LfsRequest::CONTENT_TYPE) + headers = (headers || {}).merge("Content-Type" => LfsRequest::CONTENT_TYPE) post(url, params: params, headers: headers) end diff --git a/spec/requests/lfs_locks_api_spec.rb b/spec/requests/lfs_locks_api_spec.rb index 5b7b3d2fdd6..6cdf3456b94 100644 --- a/spec/requests/lfs_locks_api_spec.rb +++ b/spec/requests/lfs_locks_api_spec.rb @@ -1,24 +1,24 @@ -require 'spec_helper' +require "spec_helper" -describe 'Git LFS File Locking API' do +describe "Git LFS File Locking API" do include WorkhorseHelpers let(:project) { create(:project) } let(:maintainer) { create(:user) } let(:developer) { create(:user) } let(:guest) { create(:user) } - let(:path) { 'README.md' } + let(:path) { "README.md" } let(:headers) do { - 'Authorization' => authorization + "Authorization" => authorization, }.compact end - shared_examples 'unauthorized request' do - context 'when user is not authorized' do + shared_examples "unauthorized request" do + context "when user is not authorized" do let(:authorization) { authorize_user(guest) } - it 'returns a forbidden 403 response' do + it "returns a forbidden 403 response" do post_lfs_json url, body, headers expect(response).to have_gitlab_http_status(403) @@ -34,111 +34,111 @@ describe 'Git LFS File Locking API' do project.add_guest(guest) end - describe 'Create File Lock endpoint' do + describe "Create File Lock endpoint" do let(:url) { "#{project.http_url_to_repo}/info/lfs/locks" } let(:authorization) { authorize_user(developer) } - let(:body) { { path: path } } + let(:body) { {path: path} } - include_examples 'unauthorized request' + include_examples "unauthorized request" - context 'with an existent lock' do + context "with an existent lock" do before do - lock_file('README.md', developer) + lock_file("README.md", developer) end - it 'return an error message' do + it "return an error message" do post_lfs_json url, body, headers expect(response).to have_gitlab_http_status(409) - expect(json_response.keys).to match_array(%w(lock message documentation_url)) - expect(json_response['message']).to match(/already locked/) + expect(json_response.keys).to match_array(%w[lock message documentation_url]) + expect(json_response["message"]).to match(/already locked/) end - it 'returns the existen lock' do + it "returns the existen lock" do post_lfs_json url, body, headers - expect(json_response['lock']['path']).to eq('README.md') + expect(json_response["lock"]["path"]).to eq("README.md") end end - context 'without an existent lock' do - it 'creates the lock' do + context "without an existent lock" do + it "creates the lock" do post_lfs_json url, body, headers expect(response).to have_gitlab_http_status(201) - expect(json_response['lock'].keys).to match_array(%w(id path locked_at owner)) + expect(json_response["lock"].keys).to match_array(%w[id path locked_at owner]) end end end - describe 'Listing File Locks endpoint' do + describe "Listing File Locks endpoint" do let(:url) { "#{project.http_url_to_repo}/info/lfs/locks" } let(:authorization) { authorize_user(developer) } - include_examples 'unauthorized request' + include_examples "unauthorized request" - it 'returns the list of locked files' do - lock_file('README.md', developer) - lock_file('README', developer) + it "returns the list of locked files" do + lock_file("README.md", developer) + lock_file("README", developer) do_get url, nil, headers expect(response).to have_gitlab_http_status(200) - expect(json_response['locks'].size).to eq(2) - expect(json_response['locks'].first.keys).to match_array(%w(id path locked_at owner)) + expect(json_response["locks"].size).to eq(2) + expect(json_response["locks"].first.keys).to match_array(%w[id path locked_at owner]) end end - describe 'List File Locks for verification endpoint' do + describe "List File Locks for verification endpoint" do let(:url) { "#{project.http_url_to_repo}/info/lfs/locks/verify" } let(:authorization) { authorize_user(developer) } - include_examples 'unauthorized request' + include_examples "unauthorized request" - it 'returns the list of locked files grouped by owner' do - lock_file('README.md', maintainer) - lock_file('README', developer) + it "returns the list of locked files grouped by owner" do + lock_file("README.md", maintainer) + lock_file("README", developer) post_lfs_json url, nil, headers expect(response).to have_gitlab_http_status(200) - expect(json_response['ours'].size).to eq(1) - expect(json_response['ours'].first['path']).to eq('README') - expect(json_response['theirs'].size).to eq(1) - expect(json_response['theirs'].first['path']).to eq('README.md') + expect(json_response["ours"].size).to eq(1) + expect(json_response["ours"].first["path"]).to eq("README") + expect(json_response["theirs"].size).to eq(1) + expect(json_response["theirs"].first["path"]).to eq("README.md") end end - describe 'Delete File Lock endpoint' do - let!(:lock) { lock_file('README.md', developer) } + describe "Delete File Lock endpoint" do + let!(:lock) { lock_file("README.md", developer) } let(:url) { "#{project.http_url_to_repo}/info/lfs/locks/#{lock[:id]}/unlock" } let(:authorization) { authorize_user(developer) } - include_examples 'unauthorized request' + include_examples "unauthorized request" - context 'with an existent lock' do - it 'deletes the lock' do + context "with an existent lock" do + it "deletes the lock" do post_lfs_json url, nil, headers expect(response).to have_gitlab_http_status(200) end - it 'returns the deleted lock' do + it "returns the deleted lock" do post_lfs_json url, nil, headers - expect(json_response['lock'].keys).to match_array(%w(id path locked_at owner)) + expect(json_response["lock"].keys).to match_array(%w[id path locked_at owner]) end - context 'when a maintainer uses force' do + context "when a maintainer uses force" do let(:authorization) { authorize_user(maintainer) } - it 'deletes the lock' do + it "deletes the lock" do project.add_maintainer(maintainer) - post_lfs_json url, { force: true }, headers + post_lfs_json url, {force: true}, headers expect(response).to have_gitlab_http_status(200) end @@ -147,7 +147,7 @@ describe 'Git LFS File Locking API' do end def lock_file(path, author) - result = Lfs::LockFileService.new(project, author, { path: path }).execute + result = Lfs::LockFileService.new(project, author, {path: path}).execute result[:lock] end @@ -157,11 +157,11 @@ describe 'Git LFS File Locking API' do end def post_lfs_json(url, body = nil, headers = nil) - post(url, params: body.try(:to_json), headers: (headers || {}).merge('Content-Type' => LfsRequest::CONTENT_TYPE)) + post(url, params: body.try(:to_json), headers: (headers || {}).merge("Content-Type" => LfsRequest::CONTENT_TYPE)) end def do_get(url, params = nil, headers = nil) - get(url, params: (params || {}), headers: (headers || {}).merge('Content-Type' => LfsRequest::CONTENT_TYPE)) + get(url, params: (params || {}), headers: (headers || {}).merge("Content-Type" => LfsRequest::CONTENT_TYPE)) end def json_response diff --git a/spec/requests/oauth_tokens_spec.rb b/spec/requests/oauth_tokens_spec.rb index 3873e754060..9174a0c9789 100644 --- a/spec/requests/oauth_tokens_spec.rb +++ b/spec/requests/oauth_tokens_spec.rb @@ -1,17 +1,17 @@ -require 'spec_helper' +require "spec_helper" -describe 'OAuth Tokens requests' do +describe "OAuth Tokens requests" do let(:user) { create :user } - let(:application) { create :oauth_application, scopes: 'api' } + let(:application) { create :oauth_application, scopes: "api" } def request_access_token(user) - post '/oauth/token', + post "/oauth/token", params: { - grant_type: 'authorization_code', + grant_type: "authorization_code", code: generate_access_grant(user).token, redirect_uri: application.redirect_uri, client_id: application.uid, - client_secret: application.secret + client_secret: application.secret, } end @@ -19,39 +19,39 @@ describe 'OAuth Tokens requests' do create :oauth_access_grant, application: application, resource_owner_id: user.id end - context 'when there is already a token for the application' do + context "when there is already a token for the application" do let!(:existing_token) { create :oauth_access_token, application: application, resource_owner_id: user.id } - context 'and the request is done by the resource owner' do - it 'reuses and returns the stored token' do - expect do + context "and the request is done by the resource owner" do + it "reuses and returns the stored token" do + expect { request_access_token(user) - end.not_to change { Doorkeeper::AccessToken.count } + }.not_to change { Doorkeeper::AccessToken.count } - expect(json_response['access_token']).to eq existing_token.token + expect(json_response["access_token"]).to eq existing_token.token end end - context 'and the request is done by a different user' do + context "and the request is done by a different user" do let(:other_user) { create :user } - it 'generates and returns a different token for a different owner' do - expect do + it "generates and returns a different token for a different owner" do + expect { request_access_token(other_user) - end.to change { Doorkeeper::AccessToken.count }.by(1) + }.to change { Doorkeeper::AccessToken.count }.by(1) - expect(json_response['access_token']).not_to be_nil + expect(json_response["access_token"]).not_to be_nil end end end - context 'when there is no token stored for the application' do - it 'generates and returns a new token' do - expect do + context "when there is no token stored for the application" do + it "generates and returns a new token" do + expect { request_access_token(user) - end.to change { Doorkeeper::AccessToken.count }.by(1) + }.to change { Doorkeeper::AccessToken.count }.by(1) - expect(json_response['access_token']).not_to be_nil + expect(json_response["access_token"]).not_to be_nil end end end diff --git a/spec/requests/openid_connect_spec.rb b/spec/requests/openid_connect_spec.rb index 2a455523e2c..c32cf0de55a 100644 --- a/spec/requests/openid_connect_spec.rb +++ b/spec/requests/openid_connect_spec.rb @@ -1,20 +1,20 @@ -require 'spec_helper' +require "spec_helper" -describe 'OpenID Connect requests' do +describe "OpenID Connect requests" do let(:user) do create( :user, - name: 'Alice', - username: 'alice', - email: 'private@example.com', + name: "Alice", + username: "alice", + email: "private@example.com", emails: [public_email], public_email: public_email.email, - website_url: 'https://example.com', - avatar: fixture_file_upload('spec/fixtures/dk.png') + website_url: "https://example.com", + avatar: fixture_file_upload("spec/fixtures/dk.png") ) end - let(:public_email) { build :email, email: 'public@example.com' } + let(:public_email) { build :email, email: "public@example.com" } let(:access_grant) { create :oauth_access_grant, application: application, resource_owner_id: user.id } let(:access_token) { create :oauth_access_token, application: application, resource_owner_id: user.id } @@ -25,52 +25,52 @@ describe 'OpenID Connect requests' do let(:id_token_claims) do { - 'sub' => user.id.to_s, - 'sub_legacy' => hashed_subject + "sub" => user.id.to_s, + "sub_legacy" => hashed_subject, } end let(:user_info_claims) do { - 'name' => 'Alice', - 'nickname' => 'alice', - 'email' => 'public@example.com', - 'email_verified' => false, - 'website' => 'https://example.com', - 'profile' => 'http://localhost/alice', - 'picture' => "http://localhost/uploads/-/system/user/avatar/#{user.id}/dk.png", - 'groups' => kind_of(Array) + "name" => "Alice", + "nickname" => "alice", + "email" => "public@example.com", + "email_verified" => false, + "website" => "https://example.com", + "profile" => "http://localhost/alice", + "picture" => "http://localhost/uploads/-/system/user/avatar/#{user.id}/dk.png", + "groups" => kind_of(Array), } end def request_access_token! login_as user - post '/oauth/token', + post "/oauth/token", params: { - grant_type: 'authorization_code', + grant_type: "authorization_code", code: access_grant.token, redirect_uri: application.redirect_uri, client_id: application.uid, - client_secret: application.secret + client_secret: application.secret, } end def request_user_info! - get '/oauth/userinfo', params: {}, headers: { 'Authorization' => "Bearer #{access_token.token}" } + get "/oauth/userinfo", params: {}, headers: {"Authorization" => "Bearer #{access_token.token}"} end - context 'Application without OpenID scope' do - let(:application) { create :oauth_application, scopes: 'api' } + context "Application without OpenID scope" do + let(:application) { create :oauth_application, scopes: "api" } - it 'token response does not include an ID token' do + it "token response does not include an ID token" do request_access_token! - expect(json_response).to include 'access_token' - expect(json_response).not_to include 'id_token' + expect(json_response).to include "access_token" + expect(json_response).not_to include "id_token" end - it 'userinfo response is unauthorized' do + it "userinfo response is unauthorized" do request_user_info! expect(response).to have_gitlab_http_status 403 @@ -78,16 +78,16 @@ describe 'OpenID Connect requests' do end end - context 'Application with OpenID scope' do - let(:application) { create :oauth_application, scopes: 'openid' } + context "Application with OpenID scope" do + let(:application) { create :oauth_application, scopes: "openid" } - it 'token response includes an ID token' do + it "token response includes an ID token" do request_access_token! - expect(json_response).to include 'id_token' + expect(json_response).to include "id_token" end - context 'UserInfo payload' do + context "UserInfo payload" do let!(:group1) { create :group } let!(:group2) { create :group } let!(:group3) { create :group, parent: group2 } @@ -100,50 +100,50 @@ describe 'OpenID Connect requests' do request_user_info! end - it 'includes all user information and group memberships' do + it "includes all user information and group memberships" do expect(json_response).to match(id_token_claims.merge(user_info_claims)) expected_groups = [group1.full_path, group3.full_path] expected_groups << group4.full_path if Group.supports_nested_objects? - expect(json_response['groups']).to match_array(expected_groups) + expect(json_response["groups"]).to match_array(expected_groups) end - it 'does not include any unknown claims' do + it "does not include any unknown claims" do expect(json_response.keys).to eq %w[sub sub_legacy] + user_info_claims.keys end - it 'includes email and email_verified claims' do - expect(json_response.keys).to include('email', 'email_verified') + it "includes email and email_verified claims" do + expect(json_response.keys).to include("email", "email_verified") end - it 'has public email in email claim' do - expect(json_response['email']).to eq(user.public_email) + it "has public email in email claim" do + expect(json_response["email"]).to eq(user.public_email) end - it 'has false in email_verified claim' do - expect(json_response['email_verified']).to eq(false) + it "has false in email_verified claim" do + expect(json_response["email_verified"]).to eq(false) end end - context 'ID token payload' do + context "ID token payload" do before do request_access_token! - @payload = JSON::JWT.decode(json_response['id_token'], :skip_verification) + @payload = JSON::JWT.decode(json_response["id_token"], :skip_verification) end - it 'includes the subject claims' do + it "includes the subject claims" do expect(@payload).to match(a_hash_including(id_token_claims)) end - it 'includes the GitLab root URL' do - expect(@payload['iss']).to eq Gitlab.config.gitlab.url + it "includes the GitLab root URL" do + expect(@payload["iss"]).to eq Gitlab.config.gitlab.url end - it 'includes the time of the last authentication', :clean_gitlab_redis_shared_state do - expect(@payload['auth_time']).to eq user.current_sign_in_at.to_i + it "includes the time of the last authentication", :clean_gitlab_redis_shared_state do + expect(@payload["auth_time"]).to eq user.current_sign_in_at.to_i end - it 'does not include any unknown properties' do + it "does not include any unknown properties" do expect(@payload.keys).to eq %w[iss sub aud exp iat auth_time sub_legacy] end end @@ -157,64 +157,64 @@ describe 'OpenID Connect requests' do # When the patch gets merged and we update Warden, these specs will need to # updated to check the response instead of a raised exception. # https://gitlab.com/gitlab-org/gitlab-ce/issues/40218 - context 'when user is blocked' do - it 'returns authentication error' do + context "when user is blocked" do + it "returns authentication error" do access_grant user.block! - expect do + expect { request_access_token! - end.to raise_error UncaughtThrowError + }.to raise_error UncaughtThrowError end end - context 'when user is ldap_blocked' do - it 'returns authentication error' do + context "when user is ldap_blocked" do + it "returns authentication error" do access_grant user.ldap_block! - expect do + expect { request_access_token! - end.to raise_error UncaughtThrowError + }.to raise_error UncaughtThrowError end end end - context 'OpenID configuration information' do - it 'correctly returns the configuration' do - get '/.well-known/openid-configuration' + context "OpenID configuration information" do + it "correctly returns the configuration" do + get "/.well-known/openid-configuration" expect(response).to have_gitlab_http_status(200) - expect(json_response['issuer']).to eq('http://localhost') - expect(json_response['jwks_uri']).to eq('http://www.example.com/oauth/discovery/keys') - expect(json_response['scopes_supported']).to eq(%w[api read_user sudo read_repository openid profile email]) + expect(json_response["issuer"]).to eq("http://localhost") + expect(json_response["jwks_uri"]).to eq("http://www.example.com/oauth/discovery/keys") + expect(json_response["scopes_supported"]).to eq(%w[api read_user sudo read_repository openid profile email]) end end - context 'Application with OpenID and email scopes' do - let(:application) { create :oauth_application, scopes: 'openid email' } + context "Application with OpenID and email scopes" do + let(:application) { create :oauth_application, scopes: "openid email" } - it 'token response includes an ID token' do + it "token response includes an ID token" do request_access_token! - expect(json_response).to include 'id_token' + expect(json_response).to include "id_token" end - context 'UserInfo payload' do + context "UserInfo payload" do before do request_user_info! end - it 'includes the email and email_verified claims' do - expect(json_response.keys).to include('email', 'email_verified') + it "includes the email and email_verified claims" do + expect(json_response.keys).to include("email", "email_verified") end - it 'has private email in email claim' do - expect(json_response['email']).to eq(user.email) + it "has private email in email claim" do + expect(json_response["email"]).to eq(user.email) end - it 'has true in email_verified claim' do - expect(json_response['email_verified']).to eq(true) + it "has true in email_verified claim" do + expect(json_response["email_verified"]).to eq(true) end end end diff --git a/spec/requests/projects/cycle_analytics_events_spec.rb b/spec/requests/projects/cycle_analytics_events_spec.rb index 49412b628b3..d5061a7064b 100644 --- a/spec/requests/projects/cycle_analytics_events_spec.rb +++ b/spec/requests/projects/cycle_analytics_events_spec.rb @@ -1,11 +1,11 @@ -require 'spec_helper' +require "spec_helper" -describe 'cycle analytics events' do +describe "cycle analytics events" do let(:user) { create(:user) } let(:project) { create(:project, :repository, public_builds: false) } let(:issue) { create(:issue, project: project, created_at: 2.days.ago) } - describe 'GET /:namespace/:project/cycle_analytics/events/issues' do + describe "GET /:namespace/:project/cycle_analytics/events/issues" do before do project.add_developer(user) @@ -20,95 +20,95 @@ describe 'cycle analytics events' do login_as(user) end - it 'lists the issue events' do + it "lists the issue events" do get project_cycle_analytics_issue_path(project, format: :json) first_issue_iid = project.issues.sort_by_attribute(:created_desc).pluck(:iid).first.to_s - expect(json_response['events']).not_to be_empty - expect(json_response['events'].first['iid']).to eq(first_issue_iid) + expect(json_response["events"]).not_to be_empty + expect(json_response["events"].first["iid"]).to eq(first_issue_iid) end - it 'lists the plan events' do + it "lists the plan events" do get project_cycle_analytics_plan_path(project, format: :json) first_mr_short_sha = project.merge_requests.sort_by_attribute(:created_asc).first.commits.first.short_id - expect(json_response['events']).not_to be_empty - expect(json_response['events'].first['short_sha']).to eq(first_mr_short_sha) + expect(json_response["events"]).not_to be_empty + expect(json_response["events"].first["short_sha"]).to eq(first_mr_short_sha) end - it 'lists the code events' do + it "lists the code events" do get project_cycle_analytics_code_path(project, format: :json) - expect(json_response['events']).not_to be_empty + expect(json_response["events"]).not_to be_empty first_mr_iid = project.merge_requests.sort_by_attribute(:created_desc).pluck(:iid).first.to_s - expect(json_response['events'].first['iid']).to eq(first_mr_iid) + expect(json_response["events"].first["iid"]).to eq(first_mr_iid) end - it 'lists the test events' do + it "lists the test events" do get project_cycle_analytics_test_path(project, format: :json) - expect(json_response['events']).not_to be_empty - expect(json_response['events'].first['date']).not_to be_empty + expect(json_response["events"]).not_to be_empty + expect(json_response["events"].first["date"]).not_to be_empty end - it 'lists the review events' do + it "lists the review events" do get project_cycle_analytics_review_path(project, format: :json) first_mr_iid = project.merge_requests.sort_by_attribute(:created_desc).pluck(:iid).first.to_s - expect(json_response['events']).not_to be_empty - expect(json_response['events'].first['iid']).to eq(first_mr_iid) + expect(json_response["events"]).not_to be_empty + expect(json_response["events"].first["iid"]).to eq(first_mr_iid) end - it 'lists the staging events' do + it "lists the staging events" do get project_cycle_analytics_staging_path(project, format: :json) - expect(json_response['events']).not_to be_empty - expect(json_response['events'].first['date']).not_to be_empty + expect(json_response["events"]).not_to be_empty + expect(json_response["events"].first["date"]).not_to be_empty end - it 'lists the production events' do + it "lists the production events" do get project_cycle_analytics_production_path(project, format: :json) first_issue_iid = project.issues.sort_by_attribute(:created_desc).pluck(:iid).first.to_s - expect(json_response['events']).not_to be_empty - expect(json_response['events'].first['iid']).to eq(first_issue_iid) + expect(json_response["events"]).not_to be_empty + expect(json_response["events"].first["iid"]).to eq(first_issue_iid) end - context 'specific branch' do - it 'lists the test events' do + context "specific branch" do + it "lists the test events" do branch = project.merge_requests.first.source_branch get project_cycle_analytics_test_path(project, format: :json, branch: branch) - expect(json_response['events']).not_to be_empty - expect(json_response['events'].first['date']).not_to be_empty + expect(json_response["events"]).not_to be_empty + expect(json_response["events"].first["date"]).not_to be_empty end end - context 'with private project and builds' do + context "with private project and builds" do before do project.members.last.update(access_level: Gitlab::Access::GUEST) end - it 'does not list the test events' do + it "does not list the test events" do get project_cycle_analytics_test_path(project, format: :json) expect(response).to have_gitlab_http_status(:not_found) end - it 'does not list the staging events' do + it "does not list the staging events" do get project_cycle_analytics_staging_path(project, format: :json) expect(response).to have_gitlab_http_status(:not_found) end - it 'lists the issue events' do + it "lists the issue events" do get project_cycle_analytics_issue_path(project, format: :json) expect(response).to have_gitlab_http_status(:ok) @@ -121,7 +121,7 @@ describe 'cycle analytics events' do issue.update(milestone: milestone) mr = create_merge_request_closing_issue(user, project, issue, commit_message: "References #{issue.to_reference}") - pipeline = create(:ci_empty_pipeline, status: 'created', project: project, ref: mr.source_branch, sha: mr.source_branch_sha, head_pipeline_of: mr) + pipeline = create(:ci_empty_pipeline, status: "created", project: project, ref: mr.source_branch, sha: mr.source_branch_sha, head_pipeline_of: mr) pipeline.run create(:ci_build, pipeline: pipeline, status: :success, author: user) diff --git a/spec/requests/rack_attack_global_spec.rb b/spec/requests/rack_attack_global_spec.rb index 49021f5d1b7..afb64ae6626 100644 --- a/spec/requests/rack_attack_global_spec.rb +++ b/spec/requests/rack_attack_global_spec.rb @@ -1,6 +1,6 @@ -require 'spec_helper' +require "spec_helper" -describe 'Rack Attack global throttles' do +describe "Rack Attack global throttles" do let(:settings) { Gitlab::CurrentSettings.current_application_settings } # Start with really high limits and override them with low limits to ensure @@ -12,7 +12,7 @@ describe 'Rack Attack global throttles' do throttle_authenticated_api_requests_per_period: 100, throttle_authenticated_api_period_in_seconds: 1, throttle_authenticated_web_requests_per_period: 100, - throttle_authenticated_web_period_in_seconds: 1 + throttle_authenticated_web_period_in_seconds: 1, } end @@ -20,10 +20,10 @@ describe 'Rack Attack global throttles' do let(:period_in_seconds) { 10000 } let(:period) { period_in_seconds.seconds } - let(:url_that_does_not_require_authentication) { '/users/sign_in' } - let(:url_that_requires_authentication) { '/dashboard/snippets' } - let(:url_api_internal) { '/api/v4/internal/check' } - let(:api_partial_url) { '/todos' } + let(:url_that_does_not_require_authentication) { "/users/sign_in" } + let(:url_that_requires_authentication) { "/dashboard/snippets" } + let(:url_api_internal) { "/api/v4/internal/check" } + let(:api_partial_url) { "/todos" } around do |example| # Instead of test environment's :null_store so the throttles can increment @@ -39,20 +39,20 @@ describe 'Rack Attack global throttles' do # * throttle_setting_prefix (e.g. "throttle_authenticated_api" or "throttle_authenticated_web") # * get_args # * other_user_get_args - shared_examples_for 'rate-limited token-authenticated requests' do + shared_examples_for "rate-limited token-authenticated requests" do before do # Set low limits settings_to_set[:"#{throttle_setting_prefix}_requests_per_period"] = requests_per_period settings_to_set[:"#{throttle_setting_prefix}_period_in_seconds"] = period_in_seconds end - context 'when the throttle is enabled' do + context "when the throttle is enabled" do before do settings_to_set[:"#{throttle_setting_prefix}_enabled"] = true stub_application_setting(settings_to_set) end - it 'rejects requests over the rate limit' do + it "rejects requests over the rate limit" do # At first, allow requests under the rate limit. requests_per_period.times do get(*get_args) @@ -63,7 +63,7 @@ describe 'Rack Attack global throttles' do expect_rejection { get(*get_args) } end - it 'allows requests after throttling and then waiting for the next period' do + it "allows requests after throttling and then waiting for the next period" do requests_per_period.times do get(*get_args) expect(response).to have_http_status 200 @@ -81,7 +81,7 @@ describe 'Rack Attack global throttles' do end end - it 'counts requests from different users separately, even from the same IP' do + it "counts requests from different users separately, even from the same IP" do requests_per_period.times do get(*get_args) expect(response).to have_http_status 200 @@ -92,25 +92,25 @@ describe 'Rack Attack global throttles' do expect(response).to have_http_status 200 end - it 'counts all requests from the same user, even via different IPs' do + it "counts all requests from the same user, even via different IPs" do requests_per_period.times do get(*get_args) expect(response).to have_http_status 200 end - expect_any_instance_of(Rack::Attack::Request).to receive(:ip).and_return('1.2.3.4') + expect_any_instance_of(Rack::Attack::Request).to receive(:ip).and_return("1.2.3.4") expect_rejection { get(*get_args) } end end - context 'when the throttle is disabled' do + context "when the throttle is disabled" do before do settings_to_set[:"#{throttle_setting_prefix}_enabled"] = false stub_application_setting(settings_to_set) end - it 'allows requests over the rate limit' do + it "allows requests over the rate limit" do (1 + requests_per_period).times do get(*get_args) expect(response).to have_http_status 200 @@ -119,20 +119,20 @@ describe 'Rack Attack global throttles' do end end - describe 'unauthenticated requests' do + describe "unauthenticated requests" do before do # Set low limits settings_to_set[:throttle_unauthenticated_requests_per_period] = requests_per_period settings_to_set[:throttle_unauthenticated_period_in_seconds] = period_in_seconds end - context 'when the throttle is enabled' do + context "when the throttle is enabled" do before do settings_to_set[:throttle_unauthenticated_enabled] = true stub_application_setting(settings_to_set) end - it 'rejects requests over the rate limit' do + it "rejects requests over the rate limit" do # At first, allow requests under the rate limit. requests_per_period.times do get url_that_does_not_require_authentication @@ -143,7 +143,7 @@ describe 'Rack Attack global throttles' do expect_rejection { get url_that_does_not_require_authentication } end - it 'allows requests after throttling and then waiting for the next period' do + it "allows requests after throttling and then waiting for the next period" do requests_per_period.times do get url_that_does_not_require_authentication expect(response).to have_http_status 200 @@ -161,36 +161,36 @@ describe 'Rack Attack global throttles' do end end - it 'counts requests from different IPs separately' do + it "counts requests from different IPs separately" do requests_per_period.times do get url_that_does_not_require_authentication expect(response).to have_http_status 200 end - expect_any_instance_of(Rack::Attack::Request).to receive(:ip).and_return('1.2.3.4') + expect_any_instance_of(Rack::Attack::Request).to receive(:ip).and_return("1.2.3.4") # would be over limit for the same IP get url_that_does_not_require_authentication expect(response).to have_http_status 200 end - context 'when the request is to the api internal endpoints' do - it 'allows requests over the rate limit' do + context "when the request is to the api internal endpoints" do + it "allows requests over the rate limit" do (1 + requests_per_period).times do - get url_api_internal, params: { secret_token: Gitlab::Shell.secret_token } + get url_api_internal, params: {secret_token: Gitlab::Shell.secret_token} expect(response).to have_http_status 200 end end end end - context 'when the throttle is disabled' do + context "when the throttle is disabled" do before do settings_to_set[:throttle_unauthenticated_enabled] = false stub_application_setting(settings_to_set) end - it 'allows requests over the rate limit' do + it "allows requests over the rate limit" do (1 + requests_per_period).times do get url_that_does_not_require_authentication expect(response).to have_http_status 200 @@ -199,66 +199,66 @@ describe 'Rack Attack global throttles' do end end - describe 'API requests authenticated with personal access token', :api do + describe "API requests authenticated with personal access token", :api do let(:user) { create(:user) } let(:token) { create(:personal_access_token, user: user) } let(:other_user) { create(:user) } let(:other_user_token) { create(:personal_access_token, user: other_user) } - let(:throttle_setting_prefix) { 'throttle_authenticated_api' } + let(:throttle_setting_prefix) { "throttle_authenticated_api" } - context 'with the token in the query string' do + context "with the token in the query string" do let(:get_args) { [api(api_partial_url, personal_access_token: token)] } let(:other_user_get_args) { [api(api_partial_url, personal_access_token: other_user_token)] } - it_behaves_like 'rate-limited token-authenticated requests' + it_behaves_like "rate-limited token-authenticated requests" end - context 'with the token in the headers' do + context "with the token in the headers" do let(:get_args) { api_get_args_with_token_headers(api_partial_url, personal_access_token_headers(token)) } let(:other_user_get_args) { api_get_args_with_token_headers(api_partial_url, personal_access_token_headers(other_user_token)) } - it_behaves_like 'rate-limited token-authenticated requests' + it_behaves_like "rate-limited token-authenticated requests" end end - describe 'API requests authenticated with OAuth token', :api do + describe "API requests authenticated with OAuth token", :api do let(:user) { create(:user) } let(:application) { Doorkeeper::Application.create!(name: "MyApp", redirect_uri: "https://app.com", owner: user) } let(:token) { Doorkeeper::AccessToken.create!(application_id: application.id, resource_owner_id: user.id, scopes: "api") } let(:other_user) { create(:user) } let(:other_user_application) { Doorkeeper::Application.create!(name: "MyApp", redirect_uri: "https://app.com", owner: other_user) } let(:other_user_token) { Doorkeeper::AccessToken.create!(application_id: application.id, resource_owner_id: other_user.id, scopes: "api") } - let(:throttle_setting_prefix) { 'throttle_authenticated_api' } + let(:throttle_setting_prefix) { "throttle_authenticated_api" } - context 'with the token in the query string' do + context "with the token in the query string" do let(:get_args) { [api(api_partial_url, oauth_access_token: token)] } let(:other_user_get_args) { [api(api_partial_url, oauth_access_token: other_user_token)] } - it_behaves_like 'rate-limited token-authenticated requests' + it_behaves_like "rate-limited token-authenticated requests" end - context 'with the token in the headers' do + context "with the token in the headers" do let(:get_args) { api_get_args_with_token_headers(api_partial_url, oauth_token_headers(token)) } let(:other_user_get_args) { api_get_args_with_token_headers(api_partial_url, oauth_token_headers(other_user_token)) } - it_behaves_like 'rate-limited token-authenticated requests' + it_behaves_like "rate-limited token-authenticated requests" end end describe '"web" (non-API) requests authenticated with RSS token' do let(:user) { create(:user) } let(:other_user) { create(:user) } - let(:throttle_setting_prefix) { 'throttle_authenticated_web' } + let(:throttle_setting_prefix) { "throttle_authenticated_web" } - context 'with the token in the query string' do + context "with the token in the query string" do let(:get_args) { [rss_url(user), nil] } let(:other_user_get_args) { [rss_url(other_user), nil] } - it_behaves_like 'rate-limited token-authenticated requests' + it_behaves_like "rate-limited token-authenticated requests" end end - describe 'web requests authenticated with regular login' do + describe "web requests authenticated with regular login" do let(:user) { create(:user) } before do @@ -269,13 +269,13 @@ describe 'Rack Attack global throttles' do settings_to_set[:throttle_authenticated_web_period_in_seconds] = period_in_seconds end - context 'when the throttle is enabled' do + context "when the throttle is enabled" do before do settings_to_set[:throttle_authenticated_web_enabled] = true stub_application_setting(settings_to_set) end - it 'rejects requests over the rate limit' do + it "rejects requests over the rate limit" do # At first, allow requests under the rate limit. requests_per_period.times do get url_that_requires_authentication @@ -286,7 +286,7 @@ describe 'Rack Attack global throttles' do expect_rejection { get url_that_requires_authentication } end - it 'allows requests after throttling and then waiting for the next period' do + it "allows requests after throttling and then waiting for the next period" do requests_per_period.times do get url_that_requires_authentication expect(response).to have_http_status 200 @@ -304,7 +304,7 @@ describe 'Rack Attack global throttles' do end end - it 'counts requests from different users separately, even from the same IP' do + it "counts requests from different users separately, even from the same IP" do requests_per_period.times do get url_that_requires_authentication expect(response).to have_http_status 200 @@ -317,25 +317,25 @@ describe 'Rack Attack global throttles' do expect(response).to have_http_status 200 end - it 'counts all requests from the same user, even via different IPs' do + it "counts all requests from the same user, even via different IPs" do requests_per_period.times do get url_that_requires_authentication expect(response).to have_http_status 200 end - expect_any_instance_of(Rack::Attack::Request).to receive(:ip).and_return('1.2.3.4') + expect_any_instance_of(Rack::Attack::Request).to receive(:ip).and_return("1.2.3.4") expect_rejection { get url_that_requires_authentication } end end - context 'when the throttle is disabled' do + context "when the throttle is disabled" do before do settings_to_set[:throttle_authenticated_web_enabled] = false stub_application_setting(settings_to_set) end - it 'allows requests over the rate limit' do + it "allows requests over the rate limit" do (1 + requests_per_period).times do get url_that_requires_authentication expect(response).to have_http_status 200 @@ -353,15 +353,15 @@ describe 'Rack Attack global throttles' do end def private_token_headers(user) - { 'HTTP_PRIVATE_TOKEN' => user.private_token } + {"HTTP_PRIVATE_TOKEN" => user.private_token} end def personal_access_token_headers(personal_access_token) - { 'HTTP_PRIVATE_TOKEN' => personal_access_token.token } + {"HTTP_PRIVATE_TOKEN" => personal_access_token.token} end def oauth_token_headers(oauth_access_token) - { 'AUTHORIZATION' => "Bearer #{oauth_access_token.token}" } + {"AUTHORIZATION" => "Bearer #{oauth_access_token.token}"} end def expect_rejection(&block) diff --git a/spec/requests/request_profiler_spec.rb b/spec/requests/request_profiler_spec.rb index 75b22b1879b..cf23033b1d3 100644 --- a/spec/requests/request_profiler_spec.rb +++ b/spec/requests/request_profiler_spec.rb @@ -1,9 +1,9 @@ -require 'spec_helper' +require "spec_helper" -describe 'Request Profiler' do +describe "Request Profiler" do let(:user) { create(:user) } - shared_examples 'profiling a request' do + shared_examples "profiling a request" do before do allow(Rails).to receive(:cache).and_return(ActiveSupport::Cache::MemoryStore.new) allow(RubyProf::Profile).to receive(:profile) do |&blk| @@ -12,16 +12,16 @@ describe 'Request Profiler' do end end - it 'creates a profile of the request' do + it "creates a profile of the request" do project = create(:project, namespace: user.namespace) time = Time.now path = "/#{project.full_path}" Timecop.freeze(time) do - get path, params: {}, headers: { 'X-Profile-Token' => Gitlab::RequestProfiler.profile_token } + get path, params: {}, headers: {"X-Profile-Token" => Gitlab::RequestProfiler.profile_token} end - profile_path = "#{Gitlab.config.shared.path}/tmp/requests_profiles/#{path.tr('/', '|')}_#{time.to_i}.html" + profile_path = "#{Gitlab.config.shared.path}/tmp/requests_profiles/#{path.tr("/", "|")}_#{time.to_i}.html" expect(File.exist?(profile_path)).to be true end @@ -35,10 +35,10 @@ describe 'Request Profiler' do login_as(user) end - include_examples 'profiling a request' + include_examples "profiling a request" end context "when user is not logged-in" do - include_examples 'profiling a request' + include_examples "profiling a request" end end diff --git a/spec/requests/user_activity_spec.rb b/spec/requests/user_activity_spec.rb index 15666e00b9f..85f74f254a2 100644 --- a/spec/requests/user_activity_spec.rb +++ b/spec/requests/user_activity_spec.rb @@ -1,13 +1,13 @@ # frozen_string_literal: true -require 'spec_helper' +require "spec_helper" -describe 'Update of user activity' do +describe "Update of user activity" do let(:user) { create(:user, last_activity_on: nil) } before do - group = create(:group, name: 'group') - project = create(:project, :public, namespace: group, name: 'project') + group = create(:group, name: "group") + project = create(:project, :public, namespace: group, name: "project") create(:issue, project: project, iid: 10) create(:merge_request, source_project: project, iid: 15) @@ -16,44 +16,44 @@ describe 'Update of user activity' do end paths_to_visit = [ - '/group', - '/group/project', - '/groups/group/-/issues', - '/groups/group/-/boards', - '/dashboard/projects', - '/dashboard/snippets', - '/dashboard/groups', - '/dashboard/todos', - '/group/project/issues', - '/group/project/issues/10', - '/group/project/merge_requests', - '/group/project/merge_requests/15' + "/group", + "/group/project", + "/groups/group/-/issues", + "/groups/group/-/boards", + "/dashboard/projects", + "/dashboard/snippets", + "/dashboard/groups", + "/dashboard/todos", + "/group/project/issues", + "/group/project/issues/10", + "/group/project/merge_requests", + "/group/project/merge_requests/15", ] - context 'without an authenticated user' do - it 'does not set the last activity cookie' do + context "without an authenticated user" do + it "does not set the last activity cookie" do get "/group/project" - expect(response.cookies['user_last_activity_on']).to be_nil + expect(response.cookies["user_last_activity_on"]).to be_nil end end - context 'with an authenticated user' do + context "with an authenticated user" do before do login_as(user) end - context 'with a POST request' do - it 'does not set the last activity cookie' do + context "with a POST request" do + it "does not set the last activity cookie" do post "/group/project/archive" - expect(response.cookies['user_last_activity_on']).to be_nil + expect(response.cookies["user_last_activity_on"]).to be_nil end end paths_to_visit.each do |path| context "on GET to #{path}" do - it 'updates the last activity date' do + it "updates the last activity date" do expect(Users::ActivityService).to receive(:new).and_call_original get path @@ -61,8 +61,8 @@ describe 'Update of user activity' do expect(user.last_activity_on).to eq(Date.today) end - context 'when calling it twice' do - it 'updates last_activity_on just once' do + context "when calling it twice" do + it "updates last_activity_on just once" do expect(Users::ActivityService).to receive(:new).once.and_call_original 2.times do @@ -71,12 +71,12 @@ describe 'Update of user activity' do end end - context 'when last_activity_on is nil' do + context "when last_activity_on is nil" do before do user.update_attribute(:last_activity_on, nil) end - it 'updates the last activity date' do + it "updates the last activity date" do expect(user.last_activity_on).to be_nil get path @@ -85,24 +85,24 @@ describe 'Update of user activity' do end end - context 'when last_activity_on is stale' do + context "when last_activity_on is stale" do before do user.update_attribute(:last_activity_on, 2.days.ago.to_date) end - it 'updates the last activity date' do + it "updates the last activity date" do get path expect(user.last_activity_on).to eq(Date.today) end end - context 'when last_activity_on is up to date' do + context "when last_activity_on is up to date" do before do user.update_attribute(:last_activity_on, Date.today) end - it 'does not try to update it' do + it "does not try to update it" do expect(Users::ActivityService).not_to receive(:new) get path |