summaryrefslogtreecommitdiff
path: root/spec/requests/api/triggers_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/requests/api/triggers_spec.rb')
-rw-r--r--spec/requests/api/triggers_spec.rb216
1 files changed, 108 insertions, 108 deletions
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)