Commit 782c8f9a authored by Kamil Trzcinski's avatar Kamil Trzcinski

Fix triggers spec

parent d2d2df07
module Ci module Ci
class CreateTriggerRequestService class CreateTriggerRequestService
def execute(project, trigger, ref, variables = nil) def execute(project, trigger, ref, variables = nil)
commit = project.gl_project.commit(ref) target = project.gl_project.repository.rev_parse_target(ref)
return unless commit return unless target
ci_commit = project.gl_project.ensure_ci_commit(commit.sha) # check if ref is tag
sha = target.oid
tag = target.is_a?(Rugged::Tag) || target.is_a?(Rugged::Tag::Annotation)
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
) )
......
...@@ -3,19 +3,19 @@ require 'spec_helper' ...@@ -3,19 +3,19 @@ require 'spec_helper'
describe Ci::CreateTriggerRequestService do describe Ci::CreateTriggerRequestService do
let(:service) { Ci::CreateTriggerRequestService.new } let(:service) { Ci::CreateTriggerRequestService.new }
let(:project) { FactoryGirl.create :ci_project } 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(:trigger) { FactoryGirl.create :ci_trigger, project: project } let(:trigger) { FactoryGirl.create :ci_trigger, project: project }
before do
stub_ci_commit_to_return_yaml_file
end
describe :execute do describe :execute do
context 'valid params' do context 'valid params' do
subject { service.execute(project, trigger, 'master') } subject { service.execute(project, trigger, 'master') }
before do
@commit = FactoryGirl.create :ci_commit, gl_project: gl_project
end
it { expect(subject).to be_kind_of(Ci::TriggerRequest) } it { expect(subject).to be_kind_of(Ci::TriggerRequest) }
it { expect(subject.commit).to eq(@commit) } it { expect(subject.commit).to be_kind_of(Ci::Commit) }
end end
context 'no commit for ref' do context 'no commit for ref' do
...@@ -28,26 +28,11 @@ describe Ci::CreateTriggerRequestService do ...@@ -28,26 +28,11 @@ describe Ci::CreateTriggerRequestService do
subject { service.execute(project, trigger, 'master') } subject { service.execute(project, trigger, 'master') }
before do before do
FactoryGirl.create :ci_commit_without_jobs, gl_project: gl_project stub_ci_commit_yaml_file('{}')
FactoryGirl.create :ci_commit, gl_project: gl_project
end end
it { expect(subject).to be_nil } it { expect(subject).to be_nil }
end end
context 'for multiple commits' do
subject { service.execute(project, trigger, 'master') }
before do
@commit1 = FactoryGirl.create :ci_commit, committed_at: 2.hour.ago, gl_project: gl_project
@commit2 = FactoryGirl.create :ci_commit, committed_at: 1.hour.ago, gl_project: gl_project
@commit3 = FactoryGirl.create :ci_commit, committed_at: 3.hour.ago, gl_project: gl_project
end
context 'retries latest one' do
it { expect(subject).to be_kind_of(Ci::TriggerRequest) }
it { expect(subject).to be_persisted }
it { expect(subject.commit).to eq(@commit2) }
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