2015-08-25 21:42:46 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2015-12-09 05:55:49 -05:00
|
|
|
describe Ci::CreateTriggerRequestService, services: true do
|
2016-08-11 09:22:35 -04:00
|
|
|
let(:service) { described_class.new }
|
2017-03-27 17:14:01 -04:00
|
|
|
let(:project) { create(:project, :repository) }
|
2015-10-05 10:21:18 -04:00
|
|
|
let(:trigger) { create(:ci_trigger, project: project) }
|
2015-08-25 21:42:46 -04:00
|
|
|
|
2015-10-05 07:37:50 -04:00
|
|
|
before do
|
2016-06-03 10:22:26 -04:00
|
|
|
stub_ci_pipeline_to_return_yaml_file
|
2015-10-05 07:37:50 -04:00
|
|
|
end
|
|
|
|
|
2016-07-11 18:12:31 -04:00
|
|
|
describe '#execute' do
|
2015-08-25 21:42:46 -04:00
|
|
|
context 'valid params' do
|
|
|
|
subject { service.execute(project, trigger, 'master') }
|
|
|
|
|
2017-03-05 12:23:42 -05:00
|
|
|
context 'without owner' do
|
|
|
|
it { expect(subject).to be_kind_of(Ci::TriggerRequest) }
|
|
|
|
it { expect(subject.pipeline).to be_kind_of(Ci::Pipeline) }
|
2017-05-24 09:13:51 -04:00
|
|
|
it { expect(subject.pipeline).to be_trigger }
|
2017-03-05 12:23:42 -05:00
|
|
|
it { expect(subject.builds.first).to be_kind_of(Ci::Build) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with owner' do
|
|
|
|
let(:owner) { create(:user) }
|
|
|
|
let(:trigger) { create(:ci_trigger, project: project, owner: owner) }
|
|
|
|
|
|
|
|
it { expect(subject).to be_kind_of(Ci::TriggerRequest) }
|
|
|
|
it { expect(subject.pipeline).to be_kind_of(Ci::Pipeline) }
|
2017-05-24 09:13:51 -04:00
|
|
|
it { expect(subject.pipeline).to be_trigger }
|
2017-03-05 12:23:42 -05:00
|
|
|
it { expect(subject.pipeline.user).to eq(owner) }
|
|
|
|
it { expect(subject.builds.first).to be_kind_of(Ci::Build) }
|
|
|
|
it { expect(subject.builds.first.user).to eq(owner) }
|
|
|
|
end
|
2015-08-25 21:42:46 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'no commit for ref' do
|
|
|
|
subject { service.execute(project, trigger, 'other-branch') }
|
|
|
|
|
2015-09-15 09:00:45 -04:00
|
|
|
it { expect(subject).to be_nil }
|
2015-08-25 21:42:46 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'no builds created' do
|
|
|
|
subject { service.execute(project, trigger, 'master') }
|
|
|
|
|
|
|
|
before do
|
2016-08-11 09:22:35 -04:00
|
|
|
stub_ci_pipeline_yaml_file('script: { only: [develop], script: hello World }')
|
2015-08-25 21:42:46 -04:00
|
|
|
end
|
|
|
|
|
2015-09-15 09:00:45 -04:00
|
|
|
it { expect(subject).to be_nil }
|
2015-08-25 21:42:46 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|