summaryrefslogtreecommitdiff
path: root/spec/requests
diff options
context:
space:
mode:
authorJacob Vosmaer <contact@jacobvosmaer.nl>2015-12-15 16:24:14 +0100
committerJacob Vosmaer <contact@jacobvosmaer.nl>2015-12-15 16:24:14 +0100
commitd27befe64dd0d55bec2472ef641c4733cc669215 (patch)
tree623db3d658408b42d8b25e923eb9ccf68016d9fa /spec/requests
parent447e598ec4ee0d2fae29303d4359ffe6a06d3ba5 (diff)
parent4493d3fd556af6ded47f940f258b0fc26c9eb3e8 (diff)
downloadgitlab-ce-d27befe64dd0d55bec2472ef641c4733cc669215.tar.gz
Merge branch 'master' of gitlab.com:gitlab-org/gitlab-ce into workhorse-passthrough
Diffstat (limited to 'spec/requests')
-rw-r--r--spec/requests/api/project_hooks_spec.rb12
-rw-r--r--spec/requests/api/projects_spec.rb12
-rw-r--r--spec/requests/api/triggers_spec.rb80
-rw-r--r--spec/requests/ci/api/builds_spec.rb40
-rw-r--r--spec/requests/ci/api/commits_spec.rb65
-rw-r--r--spec/requests/ci/api/projects_spec.rb232
-rw-r--r--spec/requests/ci/api/runners_spec.rb37
-rw-r--r--spec/requests/ci/api/triggers_spec.rb21
8 files changed, 128 insertions, 371 deletions
diff --git a/spec/requests/api/project_hooks_spec.rb b/spec/requests/api/project_hooks_spec.rb
index 606b226ad77..142b637d291 100644
--- a/spec/requests/api/project_hooks_spec.rb
+++ b/spec/requests/api/project_hooks_spec.rb
@@ -1,11 +1,17 @@
require 'spec_helper'
-describe API::API, 'ProjectHooks', api: true do
+describe API::API, 'ProjectHooks', api: true do
include ApiHelpers
let(:user) { create(:user) }
let(:user3) { create(:user) }
let!(:project) { create(:project, creator_id: user.id, namespace: user.namespace) }
- let!(:hook) { create(:project_hook, project: project, url: "http://example.com", push_events: true, merge_requests_events: true, tag_push_events: true, issues_events: true, note_events: true, enable_ssl_verification: true) }
+ let!(:hook) do
+ create(:project_hook,
+ project: project, url: "http://example.com",
+ push_events: true, merge_requests_events: true, tag_push_events: true,
+ issues_events: true, note_events: true, build_events: true,
+ enable_ssl_verification: true)
+ end
before do
project.team << [user, :master]
@@ -26,6 +32,7 @@ describe API::API, 'ProjectHooks', api: true do
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['build_events']).to eq(true)
expect(json_response.first['enable_ssl_verification']).to eq(true)
end
end
@@ -83,6 +90,7 @@ describe API::API, 'ProjectHooks', api: true do
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['build_events']).to eq(false)
expect(json_response['enable_ssl_verification']).to eq(true)
end
diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb
index 24b765f4979..e784b7d1f2d 100644
--- a/spec/requests/api/projects_spec.rb
+++ b/spec/requests/api/projects_spec.rb
@@ -86,18 +86,6 @@ describe API::API, api: true do
expect(json_response).to be_an Array
expect(json_response.first['id']).to eq(project3.id)
end
-
- it 'returns projects in the correct order when ci_enabled_first parameter is passed' do
- [project, project2, project3].each do |project|
- project.builds_enabled = false
- project.build_missing_services
- end
- project2.builds_enabled = true
- get api('/projects', user), { ci_enabled_first: 'true' }
- expect(response.status).to eq(200)
- expect(json_response).to be_an Array
- expect(json_response.first['id']).to eq(project2.id)
- end
end
end
end
diff --git a/spec/requests/api/triggers_spec.rb b/spec/requests/api/triggers_spec.rb
new file mode 100644
index 00000000000..314bd7ddc59
--- /dev/null
+++ b/spec/requests/api/triggers_spec.rb
@@ -0,0 +1,80 @@
+require 'spec_helper'
+
+describe API::API do
+ include ApiHelpers
+
+ describe 'POST /projects/:project_id/trigger' do
+ let!(:trigger_token) { 'secure token' }
+ let!(:project) { FactoryGirl.create(:project) }
+ let!(:project2) { FactoryGirl.create(:empty_project) }
+ let!(:trigger) { FactoryGirl.create(:ci_trigger, project: project, token: trigger_token) }
+ let(:options) do
+ {
+ token: trigger_token
+ }
+ end
+
+ before do
+ stub_ci_commit_to_return_yaml_file
+ end
+
+ context 'Handles errors' do
+ it 'should return bad request if token is missing' do
+ post api("/projects/#{project.id}/trigger/builds"), ref: 'master'
+ expect(response.status).to eq(400)
+ end
+
+ it 'should return not found if project is not found' do
+ post api('/projects/0/trigger/builds'), options.merge(ref: 'master')
+ expect(response.status).to eq(404)
+ end
+
+ it 'should return unauthorized if token is for different project' do
+ post api("/projects/#{project2.id}/trigger/builds"), options.merge(ref: 'master')
+ expect(response.status).to eq(401)
+ end
+ end
+
+ context 'Have a commit' do
+ let(:commit) { project.ci_commits.last }
+
+ it 'should create builds' do
+ post api("/projects/#{project.id}/trigger/builds"), options.merge(ref: 'master')
+ expect(response.status).to eq(201)
+ commit.builds.reload
+ expect(commit.builds.size).to eq(2)
+ end
+
+ it 'should return bad request with no builds created if there\'s no commit for that ref' do
+ post api("/projects/#{project.id}/trigger/builds"), options.merge(ref: 'other-branch')
+ expect(response.status).to eq(400)
+ expect(json_response['message']).to eq('No builds created')
+ end
+
+ context 'Validates variables' do
+ let(:variables) do
+ { 'TRIGGER_KEY' => 'TRIGGER_VALUE' }
+ end
+
+ it 'should validate variables to be a hash' do
+ post api("/projects/#{project.id}/trigger/builds"), options.merge(variables: 'value', ref: 'master')
+ expect(response.status).to eq(400)
+ expect(json_response['message']).to eq('variables needs to be a hash')
+ end
+
+ it 'should validate variables needs to be a map of key-valued strings' do
+ post api("/projects/#{project.id}/trigger/builds"), options.merge(variables: { key: %w(1 2) }, ref: 'master')
+ expect(response.status).to eq(400)
+ expect(json_response['message']).to eq('variables needs to be a map of key-valued strings')
+ end
+
+ it 'create trigger request with variables' do
+ post api("/projects/#{project.id}/trigger/builds"), options.merge(variables: variables, ref: 'master')
+ expect(response.status).to eq(201)
+ commit.builds.reload
+ expect(commit.builds.first.trigger_request.variables).to eq(variables)
+ end
+ end
+ end
+ end
+end
diff --git a/spec/requests/ci/api/builds_spec.rb b/spec/requests/ci/api/builds_spec.rb
index c2be045099d..c27e87c4acc 100644
--- a/spec/requests/ci/api/builds_spec.rb
+++ b/spec/requests/ci/api/builds_spec.rb
@@ -4,8 +4,7 @@ describe Ci::API::API do
include ApiHelpers
let(:runner) { FactoryGirl.create(:ci_runner, tag_list: ["mysql", "ruby"]) }
- let(:project) { FactoryGirl.create(:ci_project) }
- let(:gl_project) { project.gl_project }
+ let(:project) { FactoryGirl.create(:empty_project) }
before do
stub_ci_commit_to_return_yaml_file
@@ -13,16 +12,15 @@ describe Ci::API::API do
describe "Builds API for runners" do
let(:shared_runner) { FactoryGirl.create(:ci_runner, token: "SharedRunner") }
- let(:shared_project) { FactoryGirl.create(:ci_project, name: "SharedProject") }
- let(:shared_gl_project) { shared_project.gl_project }
+ let(:shared_project) { FactoryGirl.create(:empty_project, name: "SharedProject") }
before do
- FactoryGirl.create :ci_runner_project, project_id: project.id, runner_id: runner.id
+ FactoryGirl.create :ci_runner_project, project: project, runner: runner
end
describe "POST /builds/register" do
it "should start a build" do
- commit = FactoryGirl.create(:ci_commit, gl_project: gl_project)
+ commit = FactoryGirl.create(:ci_commit, project: project)
commit.create_builds('master', false, nil)
build = commit.builds.first
@@ -40,7 +38,7 @@ describe Ci::API::API do
end
it "should return 404 error if no builds for specific runner" do
- commit = FactoryGirl.create(:ci_commit, gl_project: shared_gl_project)
+ commit = FactoryGirl.create(:ci_commit, project: shared_project)
FactoryGirl.create(:ci_build, commit: commit, status: 'pending')
post ci_api("/builds/register"), token: runner.token
@@ -49,7 +47,7 @@ describe Ci::API::API do
end
it "should return 404 error if no builds for shared runner" do
- commit = FactoryGirl.create(:ci_commit, gl_project: gl_project)
+ commit = FactoryGirl.create(:ci_commit, project: project)
FactoryGirl.create(:ci_build, commit: commit, status: 'pending')
post ci_api("/builds/register"), token: shared_runner.token
@@ -58,7 +56,7 @@ describe Ci::API::API do
end
it "returns options" do
- commit = FactoryGirl.create(:ci_commit, gl_project: gl_project)
+ commit = FactoryGirl.create(:ci_commit, project: project)
commit.create_builds('master', false, nil)
post ci_api("/builds/register"), token: runner.token, info: { platform: :darwin }
@@ -68,7 +66,7 @@ describe Ci::API::API do
end
it "returns variables" do
- commit = FactoryGirl.create(:ci_commit, gl_project: gl_project)
+ commit = FactoryGirl.create(:ci_commit, project: project)
commit.create_builds('master', false, nil)
project.variables << Ci::Variable.new(key: "SECRET_KEY", value: "secret_value")
@@ -85,7 +83,7 @@ describe Ci::API::API do
it "returns variables for triggers" do
trigger = FactoryGirl.create(:ci_trigger, project: project)
- commit = FactoryGirl.create(:ci_commit, gl_project: gl_project)
+ commit = FactoryGirl.create(:ci_commit, project: project)
trigger_request = FactoryGirl.create(:ci_trigger_request_with_variables, commit: commit, trigger: trigger)
commit.create_builds('master', false, nil, trigger_request)
@@ -106,7 +104,7 @@ describe Ci::API::API do
end
describe "PUT /builds/:id" do
- let(:commit) { FactoryGirl.create(:ci_commit, gl_project: gl_project)}
+ let(:commit) { FactoryGirl.create(:ci_commit, project: project)}
let(:build) { FactoryGirl.create(:ci_build, commit: commit, runner_id: runner.id) }
it "should update a running build" do
@@ -126,14 +124,14 @@ describe Ci::API::API do
context "Artifacts" do
let(:file_upload) { fixture_file_upload(Rails.root + 'spec/fixtures/banana_sample.gif', 'image/gif') }
let(:file_upload2) { fixture_file_upload(Rails.root + 'spec/fixtures/dk.png', 'image/gif') }
- let(:commit) { FactoryGirl.create(:ci_commit, gl_project: gl_project) }
+ let(:commit) { FactoryGirl.create(:ci_commit, project: project) }
let(:build) { FactoryGirl.create(:ci_build, commit: commit, runner_id: runner.id) }
let(:authorize_url) { ci_api("/builds/#{build.id}/artifacts/authorize") }
let(:post_url) { ci_api("/builds/#{build.id}/artifacts") }
let(:delete_url) { ci_api("/builds/#{build.id}/artifacts") }
let(:get_url) { ci_api("/builds/#{build.id}/artifacts") }
let(:headers) { { "GitLab-Workhorse" => "1.0" } }
- let(:headers_with_token) { headers.merge(Ci::API::Helpers::BUILD_TOKEN_HEADER => build.project.token) }
+ let(:headers_with_token) { headers.merge(Ci::API::Helpers::BUILD_TOKEN_HEADER => build.token) }
describe "POST /builds/:id/artifacts/authorize" do
context "should authorize posting artifact to running build" do
@@ -142,7 +140,7 @@ describe Ci::API::API do
end
it "using token as parameter" do
- post authorize_url, { token: build.project.token }, headers
+ post authorize_url, { token: build.token }, headers
expect(response.status).to eq(200)
expect(json_response["TempPath"]).to_not be_nil
end
@@ -161,7 +159,7 @@ describe Ci::API::API do
it "using token as parameter" do
stub_application_setting(max_artifacts_size: 0)
- post authorize_url, { token: build.project.token, filesize: 100 }, headers
+ post authorize_url, { token: build.token, filesize: 100 }, headers
expect(response.status).to eq(413)
end
@@ -241,7 +239,7 @@ describe Ci::API::API do
end
it do
- post post_url, { token: build.project.token }, {}
+ post post_url, { token: build.token }, {}
expect(response.status).to eq(403)
end
end
@@ -281,12 +279,12 @@ describe Ci::API::API do
describe "DELETE /builds/:id/artifacts" do
before do
build.run!
- post delete_url, token: build.project.token, file: file_upload
+ post delete_url, token: build.token, file: file_upload
end
it "should delete artifact build" do
build.success
- delete delete_url, token: build.project.token
+ delete delete_url, token: build.token
expect(response.status).to eq(200)
end
end
@@ -298,12 +296,12 @@ describe Ci::API::API do
it "should download artifact" do
build.update_attributes(artifacts_file: file_upload)
- get get_url, token: build.project.token
+ get get_url, token: build.token
expect(response.status).to eq(200)
end
it "should fail to download if no artifact uploaded" do
- get get_url, token: build.project.token
+ get get_url, token: build.token
expect(response.status).to eq(404)
end
end
diff --git a/spec/requests/ci/api/commits_spec.rb b/spec/requests/ci/api/commits_spec.rb
deleted file mode 100644
index aa51ba95bca..00000000000
--- a/spec/requests/ci/api/commits_spec.rb
+++ /dev/null
@@ -1,65 +0,0 @@
-require 'spec_helper'
-
-describe Ci::API::API, 'Commits' do
- include ApiHelpers
-
- let(:project) { FactoryGirl.create(:ci_project) }
- let(:gl_project) { project.gl_project }
- let(:commit) { FactoryGirl.create(:ci_commit, gl_project: gl_project) }
-
- let(:options) do
- {
- project_token: project.token,
- project_id: project.id
- }
- end
-
- describe "GET /commits" do
- before { commit }
-
- it "should return commits per project" do
- get ci_api("/commits"), options
-
- expect(response.status).to eq(200)
- expect(json_response.count).to eq(1)
- expect(json_response.first["project_id"]).to eq(project.id)
- expect(json_response.first["sha"]).to eq(commit.sha)
- end
- end
-
- describe "POST /commits" do
- let(:data) do
- {
- "before" => "95790bf891e76fee5e1747ab589903a6a1f80f22",
- "after" => "da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
- "ref" => "refs/heads/master",
- "commits" => [
- {
- "id" => "b6568db1bc1dcd7f8b4d5a946b0b91f9dacd7327",
- "message" => "Update Catalan translation to e38cb41.",
- "timestamp" => "2011-12-12T14:27:31+02:00",
- "url" => "http://localhost/diaspora/commits/b6568db1bc1dcd7f8b4d5a946b0b91f9dacd7327",
- "author" => {
- "name" => "Jordi Mallach",
- "email" => "jordi@softcatala.org",
- }
- }
- ]
- }
- end
-
- it "should create a build" do
- post ci_api("/commits"), options.merge(data: data)
-
- expect(response.status).to eq(201)
- expect(json_response['sha']).to eq("da1560886d4f094c3e6c9ef40349f7d38b5d27d7")
- end
-
- it "should return 400 error if no data passed" do
- post ci_api("/commits"), options
-
- expect(response.status).to eq(400)
- expect(json_response['message']).to eq("400 (Bad request) \"data\" not given")
- end
- end
-end
diff --git a/spec/requests/ci/api/projects_spec.rb b/spec/requests/ci/api/projects_spec.rb
deleted file mode 100644
index 893fd168d3e..00000000000
--- a/spec/requests/ci/api/projects_spec.rb
+++ /dev/null
@@ -1,232 +0,0 @@
-require 'spec_helper'
-
-describe Ci::API::API do
- include ApiHelpers
-
- let(:gitlab_url) { GitlabCi.config.gitlab_ci.url }
- let(:user) { create(:user) }
- let(:private_token) { user.private_token }
-
- let(:options) do
- {
- private_token: private_token,
- url: gitlab_url
- }
- end
-
- before do
- stub_gitlab_calls
- end
-
- context "requests for scoped projects" do
- # NOTE: These ids are tied to the actual projects on demo.gitlab.com
- describe "GET /projects" do
- let!(:project1) { FactoryGirl.create(:ci_project) }
- let!(:project2) { FactoryGirl.create(:ci_project) }
-
- before do
- project1.gl_project.team << [user, :developer]
- project2.gl_project.team << [user, :developer]
- end
-
- it "should return all projects on the CI instance" do
- get ci_api("/projects"), options
- expect(response.status).to eq(200)
- expect(json_response.count).to eq(2)
- expect(json_response.first["id"]).to eq(project1.id)
- expect(json_response.last["id"]).to eq(project2.id)
- end
- end
-
- describe "GET /projects/owned" do
- let!(:gl_project1) {FactoryGirl.create(:empty_project, namespace: user.namespace)}
- let!(:gl_project2) {FactoryGirl.create(:empty_project, namespace: user.namespace)}
- let!(:project1) { gl_project1.ensure_gitlab_ci_project }
- let!(:project2) { gl_project2.ensure_gitlab_ci_project }
-
- before do
- project1.gl_project.team << [user, :developer]
- project2.gl_project.team << [user, :developer]
- end
-
- it "should return all projects on the CI instance" do
- get ci_api("/projects/owned"), options
-
- expect(response.status).to eq(200)
- expect(json_response.count).to eq(2)
- end
- end
- end
-
- describe "POST /projects/:project_id/webhooks" do
- let!(:project) { FactoryGirl.create(:ci_project) }
-
- context "Valid Webhook URL" do
- let!(:webhook) { { web_hook: "http://example.com/sth/1/ala_ma_kota" } }
-
- before do
- options.merge!(webhook)
- end
-
- it "should create webhook for specified project" do
- project.gl_project.team << [user, :master]
- post ci_api("/projects/#{project.id}/webhooks"), options
- expect(response.status).to eq(201)
- expect(json_response["url"]).to eq(webhook[:web_hook])
- end
-
- it "fails to create webhook for non existsing project" do
- post ci_api("/projects/non-existant-id/webhooks"), options
- expect(response.status).to eq(404)
- end
-
- it "non-manager is not authorized" do
- post ci_api("/projects/#{project.id}/webhooks"), options
- expect(response.status).to eq(401)
- end
- end
-
- context "Invalid Webhook URL" do
- let!(:webhook) { { web_hook: "ala_ma_kota" } }
-
- before do
- options.merge!(webhook)
- end
-
- it "fails to create webhook for not valid url" do
- project.gl_project.team << [user, :master]
- post ci_api("/projects/#{project.id}/webhooks"), options
- expect(response.status).to eq(400)
- end
- end
-
- context "Missed web_hook parameter" do
- it "fails to create webhook for not provided url" do
- project.gl_project.team << [user, :master]
- post ci_api("/projects/#{project.id}/webhooks"), options
- expect(response.status).to eq(400)
- end
- end
- end
-
- describe "GET /projects/:id" do
- let!(:project) { FactoryGirl.create(:ci_project) }
-
- before do
- project.gl_project.team << [user, :developer]
- end
-
- context "with an existing project" do
- it "should retrieve the project info" do
- get ci_api("/projects/#{project.id}"), options
- expect(response.status).to eq(200)
- expect(json_response['id']).to eq(project.id)
- end
- end
-
- context "with a non-existing project" do
- it "should return 404 error if project not found" do
- get ci_api("/projects/non_existent_id"), options
- expect(response.status).to eq(404)
- end
- end
- end
-
- describe "PUT /projects/:id" do
- let!(:project) { FactoryGirl.create(:ci_project) }
- let!(:project_info) { { default_ref: "develop" } }
-
- before do
- options.merge!(project_info)
- end
-
- it "should update a specific project's information" do
- project.gl_project.team << [user, :master]
- put ci_api("/projects/#{project.id}"), options
- expect(response.status).to eq(200)
- expect(json_response["default_ref"]).to eq(project_info[:default_ref])
- end
-
- it "fails to update a non-existing project" do
- put ci_api("/projects/non-existant-id"), options
- expect(response.status).to eq(404)
- end
-
- it "non-manager is not authorized" do
- put ci_api("/projects/#{project.id}"), options
- expect(response.status).to eq(401)
- end
- end
-
- describe "DELETE /projects/:id" do
- let!(:project) { FactoryGirl.create(:ci_project) }
-
- it "should delete a specific project" do
- project.gl_project.team << [user, :master]
- delete ci_api("/projects/#{project.id}"), options
- expect(response.status).to eq(200)
- expect { project.reload }.
- to raise_error(ActiveRecord::RecordNotFound)
- end
-
- it "non-manager is not authorized" do
- delete ci_api("/projects/#{project.id}"), options
- expect(response.status).to eq(401)
- end
-
- it "is getting not found error" do
- delete ci_api("/projects/not-existing_id"), options
- expect(response.status).to eq(404)
- end
- end
-
- describe "POST /projects/:id/runners/:id" do
- let(:project) { FactoryGirl.create(:ci_project) }
- let(:runner) { FactoryGirl.create(:ci_runner) }
-
- it "should add the project to the runner" do
- project.gl_project.team << [user, :master]
- post ci_api("/projects/#{project.id}/runners/#{runner.id}"), options
- expect(response.status).to eq(201)
-
- project.reload
- expect(project.runners.first.id).to eq(runner.id)
- end
-
- it "should fail if it tries to link a non-existing project or runner" do
- post ci_api("/projects/#{project.id}/runners/non-existing"), options
- expect(response.status).to eq(404)
-
- post ci_api("/projects/non-existing/runners/#{runner.id}"), options
- expect(response.status).to eq(404)
- end
-
- it "non-manager is not authorized" do
- allow_any_instance_of(User).to receive(:can_manage_project?).and_return(false)
- post ci_api("/projects/#{project.id}/runners/#{runner.id}"), options
- expect(response.status).to eq(401)
- end
- end
-
- describe "DELETE /projects/:id/runners/:id" do
- let(:project) { FactoryGirl.create(:ci_project) }
- let(:runner) { FactoryGirl.create(:ci_runner) }
-
- it "should remove the project from the runner" do
- project.gl_project.team << [user, :master]
- post ci_api("/projects/#{project.id}/runners/#{runner.id}"), options
-
- expect(project.runners).to be_present
- delete ci_api("/projects/#{project.id}/runners/#{runner.id}"), options
- expect(response.status).to eq(200)
-
- project.reload
- expect(project.runners).to be_empty
- end
-
- it "non-manager is not authorized" do
- delete ci_api("/projects/#{project.id}/runners/#{runner.id}"), options
- expect(response.status).to eq(401)
- end
- end
-end
diff --git a/spec/requests/ci/api/runners_spec.rb b/spec/requests/ci/api/runners_spec.rb
index 11dc089e1f5..567da013e6f 100644
--- a/spec/requests/ci/api/runners_spec.rb
+++ b/spec/requests/ci/api/runners_spec.rb
@@ -4,57 +4,38 @@ describe Ci::API::API do
include ApiHelpers
include StubGitlabCalls
+ let(:registration_token) { 'abcdefg123456' }
+
before do
stub_gitlab_calls
- end
-
- describe "GET /runners" do
- let(:gitlab_url) { GitlabCi.config.gitlab_ci.url }
- let(:private_token) { create(:user).private_token }
- let(:options) do
- {
- private_token: private_token,
- url: gitlab_url
- }
- end
-
- before do
- 5.times { FactoryGirl.create(:ci_runner) }
- end
-
- it "should retrieve a list of all runners" do
- get ci_api("/runners", nil), options
- expect(response.status).to eq(200)
- expect(json_response.count).to eq(5)
- expect(json_response.last).to have_key("id")
- expect(json_response.last).to have_key("token")
- end
+ stub_application_setting(ensure_runners_registration_token: registration_token)
+ stub_application_setting(runners_registration_token: registration_token)
end
describe "POST /runners/register" do
describe "should create a runner if token provided" do
- before { post ci_api("/runners/register"), token: GitlabCi::REGISTRATION_TOKEN }
+ before { post ci_api("/runners/register"), token: registration_token }
it { expect(response.status).to eq(201) }
end
describe "should create a runner with description" do
- before { post ci_api("/runners/register"), token: GitlabCi::REGISTRATION_TOKEN, description: "server.hostname" }
+ before { post ci_api("/runners/register"), token: registration_token, description: "server.hostname" }
it { expect(response.status).to eq(201) }
it { expect(Ci::Runner.first.description).to eq("server.hostname") }
end
describe "should create a runner with tags" do
- before { post ci_api("/runners/register"), token: GitlabCi::REGISTRATION_TOKEN, tag_list: "tag1, tag2" }
+ before { post ci_api("/runners/register"), token: registration_token, tag_list: "tag1, tag2" }
it { expect(response.status).to eq(201) }
it { expect(Ci::Runner.first.tag_list.sort).to eq(["tag1", "tag2"]) }
end
describe "should create a runner if project token provided" do
- let(:project) { FactoryGirl.create(:ci_project) }
- before { post ci_api("/runners/register"), token: project.token }
+ let(:project) { FactoryGirl.create(:empty_project) }
+ before { post ci_api("/runners/register"), token: project.runners_token }
it { expect(response.status).to eq(201) }
it { expect(project.runners.size).to eq(1) }
diff --git a/spec/requests/ci/api/triggers_spec.rb b/spec/requests/ci/api/triggers_spec.rb
index a2b436d5811..0ef03f9371b 100644
--- a/spec/requests/ci/api/triggers_spec.rb
+++ b/spec/requests/ci/api/triggers_spec.rb
@@ -5,9 +5,8 @@ describe Ci::API::API do
describe 'POST /projects/:project_id/refs/:ref/trigger' do
let!(:trigger_token) { 'secure token' }
- let!(:gl_project) { FactoryGirl.create(:project) }
- let!(:project) { gl_project.ensure_gitlab_ci_project }
- let!(:project2) { FactoryGirl.create(:ci_project) }
+ let!(:project) { FactoryGirl.create(:project, ci_id: 10) }
+ let!(:project2) { FactoryGirl.create(:empty_project, ci_id: 11) }
let!(:trigger) { FactoryGirl.create(:ci_trigger, project: project, token: trigger_token) }
let(:options) do
{
@@ -21,7 +20,7 @@ describe Ci::API::API do
context 'Handles errors' do
it 'should return bad request if token is missing' do
- post ci_api("/projects/#{project.id}/refs/master/trigger")
+ post ci_api("/projects/#{project.ci_id}/refs/master/trigger")
expect(response.status).to eq(400)
end
@@ -31,23 +30,23 @@ describe Ci::API::API do
end
it 'should return unauthorized if token is for different project' do
- post ci_api("/projects/#{project2.id}/refs/master/trigger"), options
+ post ci_api("/projects/#{project2.ci_id}/refs/master/trigger"), options
expect(response.status).to eq(401)
end
end
context 'Have a commit' do
- let(:commit) { project.commits.last }
+ let(:commit) { project.ci_commits.last }
it 'should create builds' do
- post ci_api("/projects/#{project.id}/refs/master/trigger"), options
+ post ci_api("/projects/#{project.ci_id}/refs/master/trigger"), options
expect(response.status).to eq(201)
commit.builds.reload
expect(commit.builds.size).to eq(2)
end
it 'should return bad request with no builds created if there\'s no commit for that ref' do
- post ci_api("/projects/#{project.id}/refs/other-branch/trigger"), options
+ post ci_api("/projects/#{project.ci_id}/refs/other-branch/trigger"), options
expect(response.status).to eq(400)
expect(json_response['message']).to eq('No builds created')
end
@@ -58,19 +57,19 @@ describe Ci::API::API do
end
it 'should validate variables to be a hash' do
- post ci_api("/projects/#{project.id}/refs/master/trigger"), options.merge(variables: 'value')
+ post ci_api("/projects/#{project.ci_id}/refs/master/trigger"), options.merge(variables: 'value')
expect(response.status).to eq(400)
expect(json_response['message']).to eq('variables needs to be a hash')
end
it 'should validate variables needs to be a map of key-valued strings' do
- post ci_api("/projects/#{project.id}/refs/master/trigger"), options.merge(variables: { key: %w(1 2) })
+ post ci_api("/projects/#{project.ci_id}/refs/master/trigger"), options.merge(variables: { key: %w(1 2) })
expect(response.status).to eq(400)
expect(json_response['message']).to eq('variables needs to be a map of key-valued strings')
end
it 'create trigger request with variables' do
- post ci_api("/projects/#{project.id}/refs/master/trigger"), options.merge(variables: variables)
+ post ci_api("/projects/#{project.ci_id}/refs/master/trigger"), options.merge(variables: variables)
expect(response.status).to eq(201)
commit.builds.reload
expect(commit.builds.first.trigger_request.variables).to eq(variables)