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'
describe Ci::CreateTriggerRequestService do
2015-09-15 09:42:02 -04:00
let(:service) { Ci::CreateTriggerRequestService.new }
let(:project) { FactoryGirl.create :ci_project }
let(:trigger) { FactoryGirl.create :ci_trigger, project: project }
2015-08-25 21:42:46 -04:00
describe :execute do
context 'valid params' do
subject { service.execute(project, trigger, 'master') }
before do
2015-09-15 09:42:02 -04:00
@commit = FactoryGirl.create :ci_commit, project: project
2015-08-25 21:42:46 -04:00
end
2015-09-15 09:42:02 -04:00
it { expect(subject).to be_kind_of(Ci::TriggerRequest) }
2015-09-15 09:00:45 -04:00
it { expect(subject.commit).to eq(@commit) }
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
2015-09-15 09:42:02 -04:00
FactoryGirl.create :ci_commit_without_jobs, project: project
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
context 'for multiple commits' do
subject { service.execute(project, trigger, 'master') }
before do
2015-09-15 09:42:02 -04:00
@commit1 = FactoryGirl.create :ci_commit, committed_at: 2.hour.ago, project: project
@commit2 = FactoryGirl.create :ci_commit, committed_at: 1.hour.ago, project: project
@commit3 = FactoryGirl.create :ci_commit, committed_at: 3.hour.ago, project: project
2015-08-25 21:42:46 -04:00
end
context 'retries latest one' do
2015-09-15 09:42:02 -04:00
it { expect(subject).to be_kind_of(Ci::TriggerRequest) }
2015-09-15 09:00:45 -04:00
it { expect(subject).to be_persisted }
it { expect(subject.commit).to eq(@commit2) }
2015-08-25 21:42:46 -04:00
end
end
end
end