Fix broken tests
This commit is contained in:
parent
6384c757b7
commit
e53a56acea
7 changed files with 48 additions and 118 deletions
|
@ -66,30 +66,6 @@ module Ci
|
|||
class << self
|
||||
include Ci::CurrentSettings
|
||||
|
||||
def base_build_script
|
||||
<<-eos
|
||||
git submodule update --init
|
||||
ls -la
|
||||
eos
|
||||
end
|
||||
|
||||
def parse(project)
|
||||
params = {
|
||||
gitlab_id: project.id,
|
||||
default_ref: project.default_branch || 'master',
|
||||
email_add_pusher: current_application_settings.add_pusher,
|
||||
email_only_broken_builds: current_application_settings.all_broken_builds,
|
||||
}
|
||||
|
||||
project = Ci::Project.new(params)
|
||||
project.build_missing_services
|
||||
project
|
||||
end
|
||||
|
||||
def already_added?(project)
|
||||
where(gitlab_id: project.id).any?
|
||||
end
|
||||
|
||||
def unassigned(runner)
|
||||
joins("LEFT JOIN #{Ci::RunnerProject.table_name} ON #{Ci::RunnerProject.table_name}.project_id = #{Ci::Project.table_name}.id " \
|
||||
"AND #{Ci::RunnerProject.table_name}.runner_id = #{runner.id}").
|
||||
|
|
|
@ -28,8 +28,8 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Ci::Project do
|
||||
let(:gl_project) { FactoryGirl.create :empty_project }
|
||||
let(:project) { FactoryGirl.create :ci_project, gl_project: gl_project }
|
||||
let(:project) { FactoryGirl.create :ci_project }
|
||||
let(:gl_project) { project.gl_project }
|
||||
subject { project }
|
||||
|
||||
it { is_expected.to have_many(:runner_projects) }
|
||||
|
@ -194,18 +194,6 @@ describe Ci::Project do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'Project.parse' do
|
||||
let(:project) { FactoryGirl.create :project }
|
||||
|
||||
subject { Ci::Project.parse(project) }
|
||||
|
||||
it { is_expected.to be_valid }
|
||||
it { is_expected.to be_kind_of(Ci::Project) }
|
||||
it { expect(subject.name).to eq(project.name_with_namespace) }
|
||||
it { expect(subject.gitlab_id).to eq(project.id) }
|
||||
it { expect(subject.gitlab_url).to eq(project.web_url) }
|
||||
end
|
||||
|
||||
describe :repo_url_with_auth do
|
||||
let(:project) { FactoryGirl.create :ci_project }
|
||||
subject { project.repo_url_with_auth }
|
||||
|
|
|
@ -5,7 +5,7 @@ describe Ci::API::API do
|
|||
|
||||
let(:runner) { FactoryGirl.create(:ci_runner, tag_list: ["mysql", "ruby"]) }
|
||||
let(:project) { FactoryGirl.create(:ci_project) }
|
||||
let(:gl_project) { FactoryGirl.create(:empty_project, gitlab_ci_project: project) }
|
||||
let(:gl_project) { project.gl_project }
|
||||
|
||||
before do
|
||||
stub_ci_commit_to_return_yaml_file
|
||||
|
@ -14,7 +14,7 @@ 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) { FactoryGirl.create(:empty_project, gitlab_ci_project: shared_project) }
|
||||
let(:shared_gl_project) { shared_project.gl_project }
|
||||
|
||||
before do
|
||||
FactoryGirl.create :ci_runner_project, project_id: project.id, runner_id: runner.id
|
||||
|
|
|
@ -4,7 +4,7 @@ describe Ci::API::API, 'Commits' do
|
|||
include ApiHelpers
|
||||
|
||||
let(:project) { FactoryGirl.create(:ci_project) }
|
||||
let(:gl_project) { FactoryGirl.create(:empty_project, gitlab_ci_project: project) }
|
||||
let(:gl_project) { project.gl_project }
|
||||
let(:commit) { FactoryGirl.create(:ci_commit, gl_project: gl_project) }
|
||||
|
||||
let(:options) do
|
||||
|
|
|
@ -41,8 +41,8 @@ describe Ci::API::API do
|
|||
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) { FactoryGirl.create(:ci_project, gl_project: gl_project1) }
|
||||
let!(:project2) { FactoryGirl.create(:ci_project, gl_project: gl_project2) }
|
||||
let!(:project1) { gl_project1.ensure_gitlab_ci_project }
|
||||
let!(:project2) { gl_project2.ensure_gitlab_ci_project }
|
||||
|
||||
before do
|
||||
project1.gl_project.team << [user, :developer]
|
||||
|
@ -180,87 +180,53 @@ describe Ci::API::API do
|
|||
end
|
||||
end
|
||||
|
||||
describe "POST /projects" do
|
||||
let(:gl_project) { FactoryGirl.create :empty_project }
|
||||
let(:project_info) do
|
||||
{
|
||||
gitlab_id: gl_project.id
|
||||
}
|
||||
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
|
||||
|
||||
let(:invalid_project_info) { {} }
|
||||
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)
|
||||
|
||||
context "with valid project info" do
|
||||
before do
|
||||
options.merge!(project_info)
|
||||
end
|
||||
|
||||
it "should create a project with valid data" do
|
||||
post ci_api("/projects"), options
|
||||
expect(response.status).to eq(201)
|
||||
expect(json_response['name']).to eq(gl_project.name_with_namespace)
|
||||
end
|
||||
post ci_api("/projects/non-existing/runners/#{runner.id}"), options
|
||||
expect(response.status).to eq(404)
|
||||
end
|
||||
|
||||
context "with invalid project info" do
|
||||
before do
|
||||
options.merge!(invalid_project_info)
|
||||
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
|
||||
|
||||
it "should error with invalid data" do
|
||||
post ci_api("/projects"), options
|
||||
expect(response.status).to eq(400)
|
||||
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
|
||||
|
||||
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
|
||||
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
|
||||
|
|
|
@ -6,7 +6,7 @@ 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) { FactoryGirl.create(:ci_project, gl_project: gl_project) }
|
||||
let!(:project) { gl_project.ensure_gitlab_ci_project }
|
||||
let!(:project2) { FactoryGirl.create(:ci_project) }
|
||||
let!(:trigger) { FactoryGirl.create(:ci_trigger, project: project, token: trigger_token) }
|
||||
let(:options) do
|
||||
|
|
|
@ -3,7 +3,7 @@ require 'spec_helper'
|
|||
describe Ci::CreateTriggerRequestService do
|
||||
let(:service) { Ci::CreateTriggerRequestService.new }
|
||||
let(:gl_project) { create(:project) }
|
||||
let(:project) { create(:ci_project, gl_project: gl_project) }
|
||||
let(:project) { gl_project.ensure_gitlab_ci_project }
|
||||
let(:trigger) { create(:ci_trigger, project: project) }
|
||||
|
||||
before do
|
||||
|
|
Loading…
Reference in a new issue