Commit f42078f7 authored by Kamil Trzcinski's avatar Kamil Trzcinski

Fix rest of tests

parent 0367dbf0
module Ci module Ci
class CreateTriggerRequestService class CreateTriggerRequestService
def execute(project, trigger, ref, variables = nil) def execute(project, trigger, ref, variables = nil)
return unless project.gl_project commit = project.gl_project.commit(ref)
return unless project.gl_project.repository return unless commit
# check if ref is tag # check if ref is tag
target = project.gl_project.repository.rev_parse_target(ref) tag = project.gl_project.repository.find_tag(ref).present?
sha = target.oid
tag = target.is_a?(Rugged::Tag) || target.is_a?(Rugged::Tag::Annotation) ci_commit = project.gl_project.ensure_ci_commit(commit.sha)
ci_commit = project.gl_project.ensure_ci_commit(sha)
trigger_request = trigger.trigger_requests.create!( trigger_request = trigger.trigger_requests.create!(
variables: variables variables: variables
) )
...@@ -17,8 +16,6 @@ module Ci ...@@ -17,8 +16,6 @@ module Ci
if ci_commit.create_builds(ref, tag, nil, trigger_request) if ci_commit.create_builds(ref, tag, nil, trigger_request)
trigger_request trigger_request
end end
rescue Rugged::OdbError
nil
end end
end end
end end
...@@ -27,6 +27,7 @@ module Ci ...@@ -27,6 +27,7 @@ module Ci
project_name: project.name, project_name: project.name,
gitlab_url: project.gitlab_url, gitlab_url: project.gitlab_url,
ref: build.ref, ref: build.ref,
before_sha: build.before_sha,
sha: build.sha, sha: build.sha,
}) })
end end
......
...@@ -31,6 +31,7 @@ FactoryGirl.define do ...@@ -31,6 +31,7 @@ FactoryGirl.define do
tag false tag false
started_at 'Di 29. Okt 09:51:28 CET 2013' started_at 'Di 29. Okt 09:51:28 CET 2013'
finished_at 'Di 29. Okt 09:53:28 CET 2013' finished_at 'Di 29. Okt 09:53:28 CET 2013'
commands 'ls -a'
options do options do
{ {
image: "ruby:2.1", image: "ruby:2.1",
......
...@@ -11,6 +11,10 @@ describe "Commits" do ...@@ -11,6 +11,10 @@ describe "Commits" do
@commit.project.gl_project.team << [@user, :master] @commit.project.gl_project.team << [@user, :master]
end end
before do
stub_ci_commit_to_return_yaml_file
end
describe "GET /:project/commits/:sha" do describe "GET /:project/commits/:sha" do
before do before do
visit ci_commit_path(@commit) visit ci_commit_path(@commit)
...@@ -38,9 +42,9 @@ describe "Commits" do ...@@ -38,9 +42,9 @@ describe "Commits" do
end end
it "shows warning" do it "shows warning" do
@commit_no_yaml = FactoryGirl.create :ci_empty_commit stub_ci_commit_yaml_file(nil)
visit ci_commit_path(@commit_no_yaml) visit ci_commit_path(@commit)
expect(page).to have_content ".gitlab-ci.yml not found in this commit" expect(page).to have_content ".gitlab-ci.yml not found in this commit"
end end
......
...@@ -3,70 +3,37 @@ require 'spec_helper' ...@@ -3,70 +3,37 @@ require 'spec_helper'
describe Ci::HipChatMessage do describe Ci::HipChatMessage do
subject { Ci::HipChatMessage.new(build) } subject { Ci::HipChatMessage.new(build) }
context "One build" do let(:commit) { FactoryGirl.create(:ci_commit_with_two_jobs) }
let(:commit) { FactoryGirl.create(:ci_commit_with_one_job) }
let(:build) do let(:build) do
commit.create_builds('master', false, nil) commit.builds.first
commit.builds.first
end
context 'when build succeeds' do
it 'returns a successful message' do
build.update(status: "success")
expect( subject.status_color ).to eq 'green'
expect( subject.notify? ).to be_falsey
expect( subject.to_s ).to match(/Build '[^']+' #\d+/)
expect( subject.to_s ).to match(/Successful in \d+ second\(s\)\./)
end
end
context 'when build fails' do
it 'returns a failure message' do
build.update(status: "failed")
expect( subject.status_color ).to eq 'red'
expect( subject.notify? ).to be_truthy
expect( subject.to_s ).to match(/Build '[^']+' #\d+/)
expect( subject.to_s ).to match(/Failed in \d+ second\(s\)\./)
end
end
end end
context "Several builds" do context 'when all matrix builds succeed' do
let(:commit) { FactoryGirl.create(:ci_commit_with_two_jobs) } it 'returns a successful message' do
commit.create_builds('master', false, nil)
let(:build) do commit.builds.update_all(status: "success")
commit.builds.first commit.reload
end
context 'when all matrix builds succeed' do
it 'returns a successful message' do
commit.create_builds('master', false, nil)
commit.builds.update_all(status: "success")
commit.reload
expect( subject.status_color ).to eq 'green' expect(subject.status_color).to eq 'green'
expect( subject.notify? ).to be_falsey expect(subject.notify?).to be_falsey
expect( subject.to_s ).to match(/Commit #\d+/) expect(subject.to_s).to match(/Commit #\d+/)
expect( subject.to_s ).to match(/Successful in \d+ second\(s\)\./) expect(subject.to_s).to match(/Successful in \d+ second\(s\)\./)
end
end end
end
context 'when at least one matrix build fails' do context 'when at least one matrix build fails' do
it 'returns a failure message' do it 'returns a failure message' do
commit.create_builds('master', false, nil) commit.create_builds('master', false, nil)
first_build = commit.builds.first first_build = commit.builds.first
second_build = commit.builds.last second_build = commit.builds.last
first_build.update(status: "success") first_build.update(status: "success")
second_build.update(status: "failed") second_build.update(status: "failed")
expect( subject.status_color ).to eq 'red' expect(subject.status_color).to eq 'red'
expect( subject.notify? ).to be_truthy expect(subject.notify?).to be_truthy
expect( subject.to_s ).to match(/Commit #\d+/) expect(subject.to_s).to match(/Commit #\d+/)
expect( subject.to_s ).to match(/Failed in \d+ second\(s\)\./) expect(subject.to_s).to match(/Failed in \d+ second\(s\)\./)
end
end end
end end
end end
...@@ -3,80 +3,41 @@ require 'spec_helper' ...@@ -3,80 +3,41 @@ require 'spec_helper'
describe Ci::SlackMessage do describe Ci::SlackMessage do
subject { Ci::SlackMessage.new(commit) } subject { Ci::SlackMessage.new(commit) }
context "One build" do let(:commit) { FactoryGirl.create(:ci_commit_with_two_jobs) }
let(:commit) { FactoryGirl.create(:ci_commit_with_one_job) }
let(:build) do context 'when all matrix builds succeeded' do
commit.create_builds('master', false, nil) let(:color) { 'good' }
commit.builds.first
end
context 'when build succeeded' do
let(:color) { 'good' }
it 'returns a message with succeeded build' do
build.update(status: "success")
expect(subject.color).to eq(color)
expect(subject.fallback).to include('Build')
expect(subject.fallback).to include("\##{build.id}")
expect(subject.fallback).to include('succeeded')
expect(subject.attachments.first[:fields]).to be_empty
end
end
context 'when build failed' do
let(:color) { 'danger' }
it 'returns a message with failed build' do
build.update(status: "failed")
expect(subject.color).to eq(color) it 'returns a message with success' do
expect(subject.fallback).to include('Build') commit.create_builds('master', false, nil)
expect(subject.fallback).to include("\##{build.id}") commit.builds.update_all(status: "success")
expect(subject.fallback).to include('failed') commit.reload
expect(subject.attachments.first[:fields]).to be_empty
end expect(subject.color).to eq(color)
expect(subject.fallback).to include('Commit')
expect(subject.fallback).to include("\##{commit.id}")
expect(subject.fallback).to include('succeeded')
expect(subject.attachments.first[:fields]).to be_empty
end end
end end
context "Several builds" do context 'when one of matrix builds failed' do
let(:commit) { FactoryGirl.create(:ci_commit_with_two_jobs) } let(:color) { 'danger' }
context 'when all matrix builds succeeded' do
let(:color) { 'good' }
it 'returns a message with success' do
commit.create_builds('master', false, nil)
commit.builds.update_all(status: "success")
commit.reload
expect(subject.color).to eq(color)
expect(subject.fallback).to include('Commit')
expect(subject.fallback).to include("\##{commit.id}")
expect(subject.fallback).to include('succeeded')
expect(subject.attachments.first[:fields]).to be_empty
end
end
context 'when one of matrix builds failed' do
let(:color) { 'danger' }
it 'returns a message with information about failed build' do it 'returns a message with information about failed build' do
commit.create_builds('master', false, nil) commit.create_builds('master', false, nil)
first_build = commit.builds.first first_build = commit.builds.first
second_build = commit.builds.last second_build = commit.builds.last
first_build.update(status: "success") first_build.update(status: "success")
second_build.update(status: "failed") second_build.update(status: "failed")
expect(subject.color).to eq(color) expect(subject.color).to eq(color)
expect(subject.fallback).to include('Commit') expect(subject.fallback).to include('Commit')
expect(subject.fallback).to include("\##{commit.id}") expect(subject.fallback).to include("\##{commit.id}")
expect(subject.fallback).to include('failed') expect(subject.fallback).to include('failed')
expect(subject.attachments.first[:fields].size).to eq(1) expect(subject.attachments.first[:fields].size).to eq(1)
expect(subject.attachments.first[:fields].first[:title]).to eq(second_build.name) expect(subject.attachments.first[:fields].first[:title]).to eq(second_build.name)
expect(subject.attachments.first[:fields].first[:value]).to include("\##{second_build.id}") expect(subject.attachments.first[:fields].first[:value]).to include("\##{second_build.id}")
end
end end
end 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