Welcome to mirror list, hosted at ThFree Co, Russian Federation.

create_trigger_request_service_spec.rb « services « ci « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 41db01c223533779d44d3c4b22a124b1066ed723 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
require 'spec_helper'

describe CreateTriggerRequestService do
  let(:service) { CreateTriggerRequestService.new }
  let(:project) { FactoryGirl.create :project }
  let(:trigger) { FactoryGirl.create :trigger, project: project }

  describe :execute do
    context 'valid params' do
      subject { service.execute(project, trigger, 'master') }

      before do
        @commit = FactoryGirl.create :commit, project: project
      end

      it { subject.should be_kind_of(TriggerRequest) }
      it { subject.commit.should == @commit }
    end

    context 'no commit for ref' do
      subject { service.execute(project, trigger, 'other-branch') }

      it { subject.should be_nil }
    end

    context 'no builds created' do
      subject { service.execute(project, trigger, 'master') }

      before do
        FactoryGirl.create :commit_without_jobs, project: project
      end

      it { subject.should be_nil }
    end

    context 'for multiple commits' do
      subject { service.execute(project, trigger, 'master') }

      before do
        @commit1 = FactoryGirl.create :commit, committed_at: 2.hour.ago, project: project
        @commit2 = FactoryGirl.create :commit, committed_at: 1.hour.ago, project: project
        @commit3 = FactoryGirl.create :commit, committed_at: 3.hour.ago, project: project
      end

      context 'retries latest one' do
        it { subject.should be_kind_of(TriggerRequest) }
        it { subject.should be_persisted }
        it { subject.commit.should == @commit2 }
      end
    end
  end
end