summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Trzcinski <ayufan@ayufan.eu>2015-10-05 13:37:50 +0200
committerKamil Trzcinski <ayufan@ayufan.eu>2015-10-05 13:37:50 +0200
commit782c8f9aa0a32def807da126e9f07f278772b6a2 (patch)
treef365c204920467226d5cb7f19ba43a44a838a37d
parentd2d2df0738f3cd8311963c34d90ebc8ce4081aa6 (diff)
downloadgitlab-ce-782c8f9aa0a32def807da126e9f07f278772b6a2.tar.gz
Fix triggers spec
-rw-r--r--app/services/ci/create_trigger_request_service.rb10
-rw-r--r--spec/services/ci/create_trigger_request_service_spec.rb31
2 files changed, 15 insertions, 26 deletions
diff --git a/app/services/ci/create_trigger_request_service.rb b/app/services/ci/create_trigger_request_service.rb
index f13ed787ed2..3597372528b 100644
--- a/app/services/ci/create_trigger_request_service.rb
+++ b/app/services/ci/create_trigger_request_service.rb
@@ -1,10 +1,14 @@
module Ci
class CreateTriggerRequestService
def execute(project, trigger, ref, variables = nil)
- commit = project.gl_project.commit(ref)
- return unless commit
+ target = project.gl_project.repository.rev_parse_target(ref)
+ 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!(
variables: variables
)
diff --git a/spec/services/ci/create_trigger_request_service_spec.rb b/spec/services/ci/create_trigger_request_service_spec.rb
index 525a24cc200..7aa1912b2a3 100644
--- a/spec/services/ci/create_trigger_request_service_spec.rb
+++ b/spec/services/ci/create_trigger_request_service_spec.rb
@@ -3,19 +3,19 @@ require 'spec_helper'
describe Ci::CreateTriggerRequestService do
let(:service) { Ci::CreateTriggerRequestService.new }
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 }
+ before do
+ stub_ci_commit_to_return_yaml_file
+ end
+
describe :execute do
context 'valid params' do
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.commit).to eq(@commit) }
+ it { expect(subject.commit).to be_kind_of(Ci::Commit) }
end
context 'no commit for ref' do
@@ -28,26 +28,11 @@ describe Ci::CreateTriggerRequestService do
subject { service.execute(project, trigger, 'master') }
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
it { expect(subject).to be_nil }
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