Commit 5064c903 authored by Kamil Trzcinski's avatar Kamil Trzcinski
Browse files

Fix next bunch of tests

parent e5aa0302aeae
......@@ -146,6 +146,10 @@ def retry(build)
delegate :sha, :short_sha, :project,
to: :commit, prefix: false
def before_sha
Gitlab::Git::BLANK_SHA
end
def trace_html
html = Ci::Ansi2html::convert(trace) if trace.present?
html || ''
......
module Ci
class CreateTriggerRequestService
def execute(project, trigger, ref, variables = nil)
target = project.gl_project.repository.rev_parse_target(ref)
return unless target
return unless project.gl_project
return unless project.gl_project.repository
# check if ref is tag
target = project.gl_project.repository.rev_parse_target(ref)
sha = target.oid
tag = target.is_a?(Rugged::Tag) || target.is_a?(Rugged::Tag::Annotation)
......@@ -16,6 +17,8 @@ def execute(project, trigger, ref, variables = nil)
if ci_commit.create_builds(ref, tag, nil, trigger_request)
trigger_request
end
rescue Rugged::OdbError
nil
end
end
end
......@@ -7,6 +7,10 @@
let(:project) { FactoryGirl.create(:ci_project) }
let(:gl_project) { FactoryGirl.create(:empty_project, gitlab_ci_project: project) }
before do
stub_ci_commit_to_return_yaml_file
end
describe "Builds API for runners" do
let(:shared_runner) { FactoryGirl.create(:ci_runner, token: "SharedRunner") }
let(:shared_project) { FactoryGirl.create(:ci_project, name: "SharedProject") }
......
......@@ -6,7 +6,7 @@
describe 'POST /projects/:project_id/refs/:ref/trigger' do
let!(:trigger_token) { 'secure token' }
let!(:project) { FactoryGirl.create(:ci_project) }
let!(:gl_project) { FactoryGirl.create(:empty_project, gitlab_ci_project: project) }
let!(:gl_project) { FactoryGirl.create(:project, gitlab_ci_project: project) }
let!(:project2) { FactoryGirl.create(:ci_project) }
let!(:trigger) { FactoryGirl.create(:ci_trigger, project: project, token: trigger_token) }
let(:options) do
......@@ -15,6 +15,10 @@
}
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 ci_api("/projects/#{project.id}/refs/master/trigger")
......@@ -33,15 +37,13 @@
end
context 'Have a commit' do
before do
@commit = FactoryGirl.create(:ci_commit, gl_project: gl_project)
end
let(:commit) { project.commits.last }
it 'should create builds' do
post ci_api("/projects/#{project.id}/refs/master/trigger"), options
expect(response.status).to eq(201)
@commit.builds.reload
expect(@commit.builds.size).to eq(2)
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
......@@ -70,8 +72,8 @@
it 'create trigger request with variables' do
post ci_api("/projects/#{project.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)
commit.builds.reload
expect(commit.builds.first.trigger_request.variables).to eq(variables)
end
end
end
......
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