gitlab-org--gitlab-foss/spec/services/ci/create_trigger_request_service_spec.rb

53 lines
1.6 KiB
Ruby
Raw Normal View History

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
let(:service) { described_class.new }
let(:project) { create(:project, :repository) }
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
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
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