Commit 9d93c567 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Fix part of CI api tests

parent bf8013f1
...@@ -3,12 +3,12 @@ require 'spec_helper' ...@@ -3,12 +3,12 @@ require 'spec_helper'
describe Ci::API::API do describe Ci::API::API do
include ApiHelpers include ApiHelpers
let(:runner) { FactoryGirl.create(:runner, tag_list: ["mysql", "ruby"]) } let(:runner) { FactoryGirl.create(:ci_runner, tag_list: ["mysql", "ruby"]) }
let(:project) { FactoryGirl.create(:project) } let(:project) { FactoryGirl.create(:ci_project) }
describe "Builds API for runners" do describe "Builds API for runners" do
let(:shared_runner) { FactoryGirl.create(:runner, token: "SharedRunner") } let(:shared_runner) { FactoryGirl.create(:ci_runner, token: "SharedRunner") }
let(:shared_project) { FactoryGirl.create(:project, name: "SharedProject") } let(:shared_project) { FactoryGirl.create(:ci_project, name: "SharedProject") }
before do before do
FactoryGirl.create :runner_project, project_id: project.id, runner_id: runner.id FactoryGirl.create :runner_project, project_id: project.id, runner_id: runner.id
...@@ -16,92 +16,92 @@ describe Ci::API::API do ...@@ -16,92 +16,92 @@ describe Ci::API::API do
describe "POST /builds/register" do describe "POST /builds/register" do
it "should start a build" do it "should start a build" do
commit = FactoryGirl.create(:commit, project: project) commit = FactoryGirl.create(:ci_commit, project: project)
commit.create_builds commit.create_builds
build = commit.builds.first build = commit.builds.first
post api("/builds/register"), token: runner.token, info: {platform: :darwin} post api("/builds/register"), token: runner.token, info: {platform: :darwin}
response.status.should == 201 expect(response.status).to eq(201)
json_response['sha'].should == build.sha expect(json_response['sha']).to eq(build.sha)
runner.reload.platform.should == "darwin" expect(runner.reload.platform).to eq("darwin")
end end
it "should return 404 error if no pending build found" do it "should return 404 error if no pending build found" do
post api("/builds/register"), token: runner.token post api("/builds/register"), token: runner.token
response.status.should == 404 expect(response.status).to eq(404)
end end
it "should return 404 error if no builds for specific runner" do it "should return 404 error if no builds for specific runner" do
commit = FactoryGirl.create(:commit, project: shared_project) commit = FactoryGirl.create(:ci_commit, project: shared_project)
FactoryGirl.create(:build, commit: commit, status: 'pending' ) FactoryGirl.create(:ci_build, commit: commit, status: 'pending' )
post api("/builds/register"), token: runner.token post api("/builds/register"), token: runner.token
response.status.should == 404 expect(response.status).to eq(404)
end end
it "should return 404 error if no builds for shared runner" do it "should return 404 error if no builds for shared runner" do
commit = FactoryGirl.create(:commit, project: project) commit = FactoryGirl.create(:ci_commit, project: project)
FactoryGirl.create(:build, commit: commit, status: 'pending' ) FactoryGirl.create(:ci_build, commit: commit, status: 'pending' )
post api("/builds/register"), token: shared_runner.token post api("/builds/register"), token: shared_runner.token
response.status.should == 404 expect(response.status).to eq(404)
end end
it "returns options" do it "returns options" do
commit = FactoryGirl.create(:commit, project: project) commit = FactoryGirl.create(:ci_commit, project: project)
commit.create_builds commit.create_builds
post api("/builds/register"), token: runner.token, info: {platform: :darwin} post api("/builds/register"), token: runner.token, info: {platform: :darwin}
response.status.should == 201 expect(response.status).to eq(201)
json_response["options"].should == {"image" => "ruby:2.1", "services" => ["postgres"]} expect(json_response["options"]).to eq({"image" => "ruby:2.1", "services" => ["postgres"]})
end end
it "returns variables" do it "returns variables" do
commit = FactoryGirl.create(:commit, project: project) commit = FactoryGirl.create(:ci_commit, project: project)
commit.create_builds commit.create_builds
project.variables << Variable.new(key: "SECRET_KEY", value: "secret_value") project.variables << Variable.new(key: "SECRET_KEY", value: "secret_value")
post api("/builds/register"), token: runner.token, info: {platform: :darwin} post api("/builds/register"), token: runner.token, info: {platform: :darwin}
response.status.should == 201 expect(response.status).to eq(201)
json_response["variables"].should == [ expect(json_response["variables"]).to eq([
{"key" => "DB_NAME", "value" => "postgres", "public" => true}, {"key" => "DB_NAME", "value" => "postgres", "public" => true},
{"key" => "SECRET_KEY", "value" => "secret_value", "public" => false}, {"key" => "SECRET_KEY", "value" => "secret_value", "public" => false},
] ])
end end
it "returns variables for triggers" do it "returns variables for triggers" do
trigger = FactoryGirl.create(:trigger, project: project) trigger = FactoryGirl.create(:ci_trigger, project: project)
commit = FactoryGirl.create(:commit, project: project) commit = FactoryGirl.create(:ci_commit, project: project)
trigger_request = FactoryGirl.create(:trigger_request_with_variables, commit: commit, trigger: trigger) trigger_request = FactoryGirl.create(:ci_trigger_request_with_variables, commit: commit, trigger: trigger)
commit.create_builds(trigger_request) commit.create_builds(trigger_request)
project.variables << Variable.new(key: "SECRET_KEY", value: "secret_value") project.variables << Variable.new(key: "SECRET_KEY", value: "secret_value")
post api("/builds/register"), token: runner.token, info: {platform: :darwin} post api("/builds/register"), token: runner.token, info: {platform: :darwin}
response.status.should == 201 expect(response.status).to eq(201)
json_response["variables"].should == [ expect(json_response["variables"]).to eq([
{"key" => "DB_NAME", "value" => "postgres", "public" => true}, {"key" => "DB_NAME", "value" => "postgres", "public" => true},
{"key" => "SECRET_KEY", "value" => "secret_value", "public" => false}, {"key" => "SECRET_KEY", "value" => "secret_value", "public" => false},
{"key" => "TRIGGER_KEY", "value" => "TRIGGER_VALUE", "public" => false}, {"key" => "TRIGGER_KEY", "value" => "TRIGGER_VALUE", "public" => false},
] ])
end end
end end
describe "PUT /builds/:id" do describe "PUT /builds/:id" do
let(:commit) { FactoryGirl.create(:commit, project: project)} let(:commit) { FactoryGirl.create(:ci_commit, project: project)}
let(:build) { FactoryGirl.create(:build, commit: commit, runner_id: runner.id) } let(:build) { FactoryGirl.create(:ci_build, commit: commit, runner_id: runner.id) }
it "should update a running build" do it "should update a running build" do
build.run! build.run!
put api("/builds/#{build.id}"), token: runner.token put api("/builds/#{build.id}"), token: runner.token
response.status.should == 200 expect(response.status).to eq(200)
end end
it 'Should not override trace information when no trace is given' do it 'Should not override trace information when no trace is given' do
......
...@@ -3,8 +3,8 @@ require 'spec_helper' ...@@ -3,8 +3,8 @@ require 'spec_helper'
describe Ci::API::API, 'Commits' do describe Ci::API::API, 'Commits' do
include ApiHelpers include ApiHelpers
let(:project) { FactoryGirl.create(:project) } let(:project) { FactoryGirl.create(:ci_project) }
let(:commit) { FactoryGirl.create(:commit, project: project) } let(:commit) { FactoryGirl.create(:ci_commit, project: project) }
let(:options) { let(:options) {
{ {
...@@ -19,10 +19,10 @@ describe Ci::API::API, 'Commits' do ...@@ -19,10 +19,10 @@ describe Ci::API::API, 'Commits' do
it "should return commits per project" do it "should return commits per project" do
get api("/commits"), options get api("/commits"), options
response.status.should == 200 expect(response.status).to eq(200)
json_response.count.should == 1 expect(json_response.count).to eq(1)
json_response.first["project_id"].should == project.id expect(json_response.first["project_id"]).to eq(project.id)
json_response.first["sha"].should == commit.sha expect(json_response.first["sha"]).to eq(commit.sha)
end end
end end
...@@ -51,15 +51,15 @@ describe Ci::API::API, 'Commits' do ...@@ -51,15 +51,15 @@ describe Ci::API::API, 'Commits' do
it "should create a build" do it "should create a build" do
post api("/commits"), options.merge(data: data) post api("/commits"), options.merge(data: data)
response.status.should == 201 expect(response.status).to eq(201)
json_response['sha'].should == "da1560886d4f094c3e6c9ef40349f7d38b5d27d7" expect(json_response['sha']).to eq("da1560886d4f094c3e6c9ef40349f7d38b5d27d7")
end end
it "should return 400 error if no data passed" do it "should return 400 error if no data passed" do
post api("/commits"), options post api("/commits"), options
response.status.should == 400 expect(response.status).to eq(400)
json_response['message'].should == "400 (Bad request) \"data\" not given" expect(json_response['message']).to eq("400 (Bad request) \"data\" not given")
end end
end end
end end
...@@ -3,7 +3,7 @@ require 'spec_helper' ...@@ -3,7 +3,7 @@ require 'spec_helper'
describe Ci::API::API do describe Ci::API::API do
include ApiHelpers include ApiHelpers
let(:project) { FactoryGirl.create(:project) } let(:project) { FactoryGirl.create(:ci_project) }
let(:gitlab_url) { GitlabCi.config.gitlab_server.url } let(:gitlab_url) { GitlabCi.config.gitlab_server.url }
let(:private_token) { Network.new.authenticate(access_token: "some_token")["private_token"] } let(:private_token) { Network.new.authenticate(access_token: "some_token")["private_token"] }
...@@ -41,8 +41,8 @@ describe Ci::API::API do ...@@ -41,8 +41,8 @@ describe Ci::API::API do
it "should create a project with valid data" do it "should create a project with valid data" do
post api("/forks"), options post api("/forks"), options
response.status.should == 201 expect(response.status).to eq(201)
json_response['name'].should == "Gitlab.org / Underscore" expect(json_response['name']).to eq("Gitlab.org / Underscore")
end end
end end
...@@ -53,7 +53,7 @@ describe Ci::API::API do ...@@ -53,7 +53,7 @@ describe Ci::API::API do
it "should error with invalid data" do it "should error with invalid data" do
post api("/forks"), options post api("/forks"), options
response.status.should == 400 expect(response.status).to eq(400)
end end
end end
end end
......
...@@ -20,34 +20,34 @@ describe Ci::API::API do ...@@ -20,34 +20,34 @@ describe Ci::API::API do
context "requests for scoped projects" do context "requests for scoped projects" do
# NOTE: These ids are tied to the actual projects on demo.gitlab.com # NOTE: These ids are tied to the actual projects on demo.gitlab.com
describe "GET /projects" do describe "GET /projects" do
let!(:project1) { FactoryGirl.create(:project, name: "gitlabhq", gitlab_id: 3) } let!(:project1) { FactoryGirl.create(:ci_project, name: "gitlabhq", gitlab_id: 3) }
let!(:project2) { FactoryGirl.create(:project, name: "gitlab-ci", gitlab_id: 4) } let!(:project2) { FactoryGirl.create(:ci_project, name: "gitlab-ci", gitlab_id: 4) }
it "should return all projects on the CI instance" do it "should return all projects on the CI instance" do
get api("/projects"), options get api("/projects"), options
response.status.should == 200 expect(response.status).to eq(200)
json_response.count.should == 2 expect(json_response.count).to eq(2)
json_response.first["id"].should == project1.id expect(json_response.first["id"]).to eq(project1.id)
json_response.last["id"].should == project2.id expect(json_response.last["id"]).to eq(project2.id)
end end
end end
describe "GET /projects/owned" do describe "GET /projects/owned" do
# NOTE: This user doesn't own any of these projects on demo.gitlab.com # NOTE: This user doesn't own any of these projects on demo.gitlab.com
let!(:project1) { FactoryGirl.create(:project, name: "gitlabhq", gitlab_id: 3) } let!(:project1) { FactoryGirl.create(:ci_project, name: "gitlabhq", gitlab_id: 3) }
let!(:project2) { FactoryGirl.create(:project, name: "random-project", gitlab_id: 9898) } let!(:project2) { FactoryGirl.create(:ci_project, name: "random-project", gitlab_id: 9898) }
it "should return all projects on the CI instance" do it "should return all projects on the CI instance" do
get api("/projects/owned"), options get api("/projects/owned"), options
response.status.should == 200 expect(response.status).to eq(200)
json_response.count.should == 0 expect(json_response.count).to eq(0)
end end
end end
end end
describe "POST /projects/:project_id/webhooks" do describe "POST /projects/:project_id/webhooks" do
let!(:project) { FactoryGirl.create(:project) } let!(:project) { FactoryGirl.create(:ci_project) }
context "Valid Webhook URL" do context "Valid Webhook URL" do
let!(:webhook) { {web_hook: "http://example.com/sth/1/ala_ma_kota" } } let!(:webhook) { {web_hook: "http://example.com/sth/1/ala_ma_kota" } }
...@@ -58,19 +58,19 @@ describe Ci::API::API do ...@@ -58,19 +58,19 @@ describe Ci::API::API do
it "should create webhook for specified project" do it "should create webhook for specified project" do
post api("/projects/#{project.id}/webhooks"), options post api("/projects/#{project.id}/webhooks"), options
response.status.should == 201 expect(response.status).to eq(201)
json_response["url"].should == webhook[:web_hook] expect(json_response["url"]).to eq(webhook[:web_hook])
end end
it "fails to create webhook for non existsing project" do it "fails to create webhook for non existsing project" do
post api("/projects/non-existant-id/webhooks"), options post api("/projects/non-existant-id/webhooks"), options
response.status.should == 404 expect(response.status).to eq(404)
end end
it "non-manager is not authorized" do it "non-manager is not authorized" do
User.any_instance.stub(:can_manage_project?).and_return(false) allow_any_instance_of(User).to receive(:can_manage_project?).and_return(false)
post api("/projects/#{project.id}/webhooks"), options post api("/projects/#{project.id}/webhooks"), options
response.status.should == 401 expect(response.status).to eq(401)
end end
end end
...@@ -83,39 +83,39 @@ describe Ci::API::API do ...@@ -83,39 +83,39 @@ describe Ci::API::API do
it "fails to create webhook for not valid url" do it "fails to create webhook for not valid url" do
post api("/projects/#{project.id}/webhooks"), options post api("/projects/#{project.id}/webhooks"), options
response.status.should == 400 expect(response.status).to eq(400)
end end
end end
context "Missed web_hook parameter" do context "Missed web_hook parameter" do
it "fails to create webhook for not provided url" do it "fails to create webhook for not provided url" do
post api("/projects/#{project.id}/webhooks"), options post api("/projects/#{project.id}/webhooks"), options
response.status.should == 400 expect(response.status).to eq(400)
end end
end end
end end
describe "GET /projects/:id" do describe "GET /projects/:id" do
let!(:project) { FactoryGirl.create(:project) } let!(:project) { FactoryGirl.create(:ci_project) }
context "with an existing project" do context "with an existing project" do
it "should retrieve the project info" do it "should retrieve the project info" do
get api("/projects/#{project.id}"), options get api("/projects/#{project.id}"), options
response.status.should == 200 expect(response.status).to eq(200)
json_response['id'].should == project.id expect(json_response['id']).to eq(project.id)
end end
end end
context "with a non-existing project" do context "with a non-existing project" do
it "should return 404 error if project not found" do it "should return 404 error if project not found" do
get api("/projects/non_existent_id"), options get api("/projects/non_existent_id"), options
response.status.should == 404 expect(response.status).to eq(404)
end end
end end
end end
describe "PUT /projects/:id" do describe "PUT /projects/:id" do
let!(:project) { FactoryGirl.create(:project) } let!(:project) { FactoryGirl.create(:ci_project) }
let!(:project_info) { {name: "An updated name!" } } let!(:project_info) { {name: "An updated name!" } }
before do before do
...@@ -124,41 +124,41 @@ describe Ci::API::API do ...@@ -124,41 +124,41 @@ describe Ci::API::API do
it "should update a specific project's information" do it "should update a specific project's information" do
put api("/projects/#{project.id}"), options put api("/projects/#{project.id}"), options
response.status.should == 200 expect(response.status).to eq(200)
json_response["name"].should == project_info[:name] expect(json_response["name"]).to eq(project_info[:name])
end end
it "fails to update a non-existing project" do it "fails to update a non-existing project" do
put api("/projects/non-existant-id"), options put api("/projects/non-existant-id"), options
response.status.should == 404 expect(response.status).to eq(404)
end end
it "non-manager is not authorized" do it "non-manager is not authorized" do
User.any_instance.stub(:can_manage_project?).and_return(false) allow_any_instance_of(User).to receive(:can_manage_project?).and_return(false)
put api("/projects/#{project.id}"), options put api("/projects/#{project.id}"), options
response.status.should == 401 expect(response.status).to eq(401)
end end
end end
describe "DELETE /projects/:id" do describe "DELETE /projects/:id" do
let!(:project) { FactoryGirl.create(:project) } let!(:project) { FactoryGirl.create(:ci_project) }
it "should delete a specific project" do it "should delete a specific project" do
delete api("/projects/#{project.id}"), options delete api("/projects/#{project.id}"), options
response.status.should == 200 expect(response.status).to eq(200)
expect { project.reload }.to raise_error expect { project.reload }.to raise_error
end end
it "non-manager is not authorized" do it "non-manager is not authorized" do
User.any_instance.stub(:can_manage_project?).and_return(false) allow_any_instance_of(User).to receive(:can_manage_project?).and_return(false)
delete api("/projects/#{project.id}"), options delete api("/projects/#{project.id}"), options
response.status.should == 401 expect(response.status).to eq(401)
end end
it "is getting not found error" do it "is getting not found error" do
delete api("/projects/not-existing_id"), options delete api("/projects/not-existing_id"), options
response.status.should == 404 expect(response.status).to eq(404)
end end
end end
...@@ -181,8 +181,8 @@ describe Ci::API::API do ...@@ -181,8 +181,8 @@ describe Ci::API::API do
it "should create a project with valid data" do it "should create a project with valid data" do
post api("/projects"), options post api("/projects"), options
response.status.should == 201 expect(response.status).to eq(201)
json_response['name'].should == project_info[:name] expect(json_response['name']).to eq(project_info[:name])
end end
end end
...@@ -193,58 +193,58 @@ describe Ci::API::API do ...@@ -193,58 +193,58 @@ describe Ci::API::API do
it "should error with invalid data" do it "should error with invalid data" do
post api("/projects"), options post api("/projects"), options
response.status.should == 400 expect(response.status).to eq(400)
end end
end end
describe "POST /projects/:id/runners/:id" do describe "POST /projects/:id/runners/:id" do
let(:project) { FactoryGirl.create(:project) } let(:project) { FactoryGirl.create(:ci_project) }
let(:runner) { FactoryGirl.create(:runner) } let(:runner) { FactoryGirl.create(:ci_runner) }
it "should add the project to the runner" do it "should add the project to the runner" do
post api("/projects/#{project.id}/runners/#{runner.id}"), options post api("/projects/#{project.id}/runners/#{runner.id}"), options
response.status.should == 201 expect(response.status).to eq(201)
project.reload project.reload
project.runners.first.id.should == runner.id expect(project.runners.first.id).to eq(runner.id)
end end
it "should fail if it tries to link a non-existing project or runner" do it "should fail if it tries to link a non-existing project or runner" do
post api("/projects/#{project.id}/runners/non-existing"), options post api("/projects/#{project.id}/runners/non-existing"), options
response.status.should == 404 expect(response.status).to eq(404)
post api("/projects/non-existing/runners/#{runner.id}"), options post api("/projects/non-existing/runners/#{runner.id}"), options
response.status.should == 404 expect(response.status).to eq(404)
end end
it "non-manager is not authorized" do it "non-manager is not authorized" do
User.any_instance.stub(:can_manage_project?).and_return(false) allow_any_instance_of(User).to receive(:can_manage_project?).and_return(false)
post api("/projects/#{project.id}/runners/#{runner.id}"), options post api("/projects/#{project.id}/runners/#{runner.id}"), options
response.status.should == 401 expect(response.status).to eq(401)
end end
end end
describe "DELETE /projects/:id/runners/:id" do describe "DELETE /projects/:id/runners/:id" do
let(:project) { FactoryGirl.create(:project) } let(:project) { FactoryGirl.create(:ci_project) }
let(:runner) { FactoryGirl.create(:runner) } let(:runner) { FactoryGirl.create(:ci_runner) }
before do before do
post api("/projects/#{project.id}/runners/#{runner.id}"), options post api("/projects/#{project.id}/runners/#{runner.id}"), options
end end
it "should remove the project from the runner" do it "should remove the project from the runner" do
project.runners.should be_present expect(project.runners).to be_present
delete api("/projects/#{project.id}/runners/#{runner.id}"), options delete api("/projects/#{project.id}/runners/#{runner.id}"), options
response.status.should == 200 expect(response.status).to eq(200)
project.reload project.reload
project.runners.should be_empty expect(project.runners).to be_empty
end end
it "non-manager is not authorized" do it "non-manager is not authorized" do
User.any_instance.stub(:can_manage_project?).and_return(false) allow_any_instance_of(User).to receive(:can_manage_project?).and_return(false)
post api("/projects/#{project.id}/runners/#{runner.id}"), options post api("/projects/#{project.id}/runners/#{runner.id}"), options
response.status.should == 401 expect(response.status).to eq(401)
end end
end end
end end
......
...@@ -19,15 +19,15 @@ describe Ci::API::API do ...@@ -19,15 +19,15 @@ describe Ci::API::API do
} }
before do before do
5.times { FactoryGirl.create(:runner) } 5.times { FactoryGirl.create(:ci_runner) }
end end
it "should retrieve a list of all runners" do it "should retrieve a list of all runners" do
get api("/runners"), options get api("/runners"), options
response.status.should == 200 expect(response.status).to eq(200)
json_response.count.should == 5 expect(json_response.count).to eq(5)
json_response.last.should have_key("id") expect(json_response.last).to have_key("id")
json_response.last.should have_key("token") expect(json_response.last).to have_key("token")
end end
end end
...@@ -35,49 +35,49 @@ describe Ci::API::API do ...@@ -35,49 +35,49 @@ describe Ci::API::API do
describe "should create a runner if token provided" do describe "should create a runner if token provided" do
before { post api("/runners/register"), token: GitlabCi::REGISTRATION_TOKEN } before { post api("/runners/register"), token: GitlabCi::REGISTRATION_TOKEN }
it { response.status.should == 201 } it { expect(response.status).to eq(201) }
end end
describe "should create a runner with description" do describe "should create a runner with description" do
before { post api("/runners/register"), token: GitlabCi::REGISTRATION_TOKEN, description: "server.hostname" } before { post api("/runners/register"), token: GitlabCi::REGISTRATION_TOKEN, description: "server.hostname" }
it { response.status.should == 201 } it { expect(response.status).to eq(201) }
it { Runner.first.description.should == "server.hostname" } it { expect(Runner.first.description).to eq("server.hostname") }
end end
describe "should create a runner with tags" do describe "should create a runner with tags" do
before { post api("/runners/register"), token: GitlabCi::REGISTRATION_TOKEN, tag_list: "tag1, tag2" } before { post api("/runners/register"), token: GitlabCi::REGISTRATION_TOKEN, tag_list: "tag1, tag2" }
it { response.status.should == 201 } it { expect(response.status).to eq(201) }
it { Runner.first.tag_list.sort.should == ["tag1", "tag2"] } it { expect(Runner.first.tag_list.sort).to eq(["tag1", "tag2"]) }
end end
describe "should create a runner if project token provided" do describe "should create a runner if project token provided" do
let(:project) { FactoryGirl.create(:project) } let(:project) { FactoryGirl.create(:ci_project) }
before { post api("/runners/register"), token: project.token } before { post api("/runners/register"), token: project.token }
it { response.status.should == 201 } it { expect(response.status).to eq(201) }
it { project.runners.size.should == 1 } it { expect(project.runners.size).to eq(1) }
end end
it "should return 403 error if token is invalid" do it "should return 403 error if token is invalid" do
post api("/runners/register"), token: 'invalid' post api("/runners/register"), token: 'invalid'
response.status.should == 403 expect(response.status).to eq(403)
end end
it "should return 400 error if no token" do it "should return 400 error if no token" do
post api("/runners/register") post api("/runners/register")
response.status.should == 400 expect(response.status).to eq(400)
end end
end end
describe "DELETE /runners/delete" do describe "DELETE /runners/delete" do
let!(:runner) { FactoryGirl.create(:runner) } let!(:runner) { FactoryGirl.create(:ci_runner) }
before { delete api("/runners/delete"), token: runner.token } before { delete api("/runners/delete"), token: runner.token }
it { response.status.should == 200 } it { expect(response.status).to eq(200) }
it { Runner.count.should == 0 } it { expect(Runner.count).to eq(0) }
end end
end end
...@@ -5,9 +5,9 @@ describe Ci::API::API do ...@@ -5,9 +5,9 @@ describe Ci::API::API do
describe 'POST /projects/:project_id/refs/:ref/trigger' do describe 'POST /projects/:project_id/refs/:ref/trigger' do
let!(:trigger_token) { 'secure token' } let!(:trigger_token) { 'secure token' }
let!(:project) { FactoryGirl.create(:project) } let!(:project) { FactoryGirl.create(:ci_project) }
let!(:project2) { FactoryGirl.create(:project) } let!(:project2) { FactoryGirl.create(:ci_project) }
let!(:trigger) { FactoryGirl.create(:trigger, project: project, token: trigger_token) } let!(:trigger) { FactoryGirl.create(:ci_trigger, project: project, token: trigger_token) }
let(:options) { let(:options) {
{ {
token: trigger_token token: trigger_token
...@@ -17,36 +17,36 @@ describe Ci::API::API do ...@@ -17,36 +17,36 @@ describe Ci::API::API do
context 'Handles errors' do context 'Handles errors' do
it 'should return bad request if token is missing' do it 'should return bad request if token is missing' do
post api("/projects/#{project.id}/refs/master/trigger") post api("/projects/#{project.id}/refs/master/trigger")
response.status.should == 400 expect(response.status).to eq(400)
end end
it 'should return not found if project is not found' do it 'should return not found if project is not found' do
post api('/projects/0/refs/master/trigger'), options post api('/projects/0/refs/master/trigger'), options
response.status.should == 404 expect(response.status).to eq(404)
end end
it 'should return unauthorized if token is for different project' do it 'should return unauthorized if token is for different project' do
post api("/projects/#{project2.id}/refs/master/trigger"), options post api("/projects/#{project2.id}/refs/master/trigger"), options
response.status.should == 401 expect(response.status).to eq(401)
end end
end end
context 'Have a commit' do context 'Have a commit' do
before do before do
@commit = FactoryGirl.create(:commit, project: project) @commit = FactoryGirl.create(:ci_commit, project: project)
end end
it 'should create builds' do it 'should create builds' do
post api("/projects/#{project.id}/refs/master/trigger"), options post api("/projects/#{project.id}/refs/master/trigger"), options
response.status.should == 201 expect(response.status).to eq(201)
@commit.builds.reload @commit.builds.reload
@commit.builds.size.should == 2 expect(@commit.builds.size).to eq(2)
end end
it 'should return bad request with no builds created if there\'s no commit for that ref' do it 'should return bad request with no builds created if there\'s no commit for that ref' do
post api("/projects/#{project.id}/refs/other-branch/trigger"), options post api("/projects/#{project.id}/refs/other-branch/trigger"), options
response.status.should == 400 expect(response.status).to eq(400)
json_response['message'].should == 'No builds created' expect(json_response['message']).to eq('No builds created')
end end
context 'Validates variables' do context 'Validates variables' do
...@@ -56,21 +56,21 @@ describe Ci::API::API do ...@@ -56,21 +56,21 @@ describe Ci::API::API do
it 'should validate variables to be a hash' do it 'should validate variables to be a hash' do
post api("/projects/#{project.id}/refs/master/trigger"), options.merge(variables: 'value') post api("/projects/#{project.id}/refs/master/trigger"), options.merge(variables: 'value')
response.status.should == 400 expect(response.status).to eq(400)
json_response['message'].should == 'variables needs to be a hash' expect(json_response['message']).to eq('variables needs to be a hash')
end end
it 'should validate variables needs to be a map of key-valued strings' do it 'should validate variables needs to be a map of key-valued strings' do
post api("/projects/#{project.id}/refs/master/trigger"), options.merge(variables: {key: %w(1 2)}) post api("/projects/#{project.id}/refs/master/trigger"), options.merge(variables: {key: %w(1 2)})
response.status.should == 400 expect(response.status).to eq(400)
json_response['message'].should == 'variables needs to be a map of key-valued strings' expect(json_response['message']).to eq('variables needs to be a map of key-valued strings')
end end
it 'create trigger request with variables' do it 'create trigger request with variables' do
post api("/projects/#{project.id}/refs/master/trigger"), options.merge(variables: variables) post api("/projects/#{project.id}/refs/master/trigger"), options.merge(variables: variables)
response.status.should == 201 expect(response.status).to eq(201)
@commit.builds.reload @commit.builds.reload
@commit.builds.first.trigger_request.variables.should == variables expect(@commit.builds.first.trigger_request.variables).to eq(variables)
end end
end end
end end
......
...@@ -2,9 +2,9 @@ require 'spec_helper' ...@@ -2,9 +2,9 @@ require 'spec_helper'
describe "Builds" do describe "Builds" do
before do before do
@project = FactoryGirl.create :project @project = FactoryGirl.create :ci_project
@commit = FactoryGirl.create :commit, project: @project @commit = FactoryGirl.create :ci_commit, project: @project
@build = FactoryGirl.create :build, commit: @commit @build = FactoryGirl.create :ci_build, commit: @commit
end end
describe "GET /:project/builds/:id/status.json" do describe "GET /:project/builds/:id/status.json" do
...@@ -12,7 +12,7 @@ describe "Builds" do ...@@ -12,7 +12,7 @@ describe "Builds" do
get status_project_build_path(@project, @build), format: :json get status_project_build_path(@project, @build), format: :json
end end
it { response.status.should == 200 } it { expect(response.status).to eq(200) }
it { response.body.should include(@build.sha) } it { expect(response.body).to include(@build.sha) }
end end
end end
...@@ -2,8 +2,8 @@ require 'spec_helper' ...@@ -2,8 +2,8 @@ require 'spec_helper'
describe "Commits" do describe "Commits" do
before do before do
@project = FactoryGirl.create :project @project = FactoryGirl.create :ci_project
@commit = FactoryGirl.create :commit, project: @project @commit = FactoryGirl.create :ci_commit, project: @project
end end
describe "GET /:project/refs/:ref_name/commits/:id/status.json" do describe "GET /:project/refs/:ref_name/commits/:id/status.json" do
...@@ -11,7 +11,7 @@ describe "Commits" do ...@@ -11,7 +11,7 @@ describe "Commits" do
get status_project_ref_commit_path(@project, @commit.ref, @commit.sha), format: :json get status_project_ref_commit_path(@project, @commit.ref, @commit.sha), format: :json
end end
it { response.status.should == 200 } it { expect(response.status).to eq(200) }
it { response.body.should include(@commit.sha) } it { expect(response.body).to include(@commit.sha) }
end end
end end
...@@ -16,7 +16,7 @@ module StubGitlabCalls ...@@ -16,7 +16,7 @@ module StubGitlabCalls
private private
def gitlab_url def gitlab_url
GitlabCi.config.gitlab_server.url Gitlab.config.gitlab.url
end end
def stub_session def stub_session
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment