Skip to content
Snippets Groups Projects
Commit 6ecbcdb0 authored by Kamil Trzcinski's avatar Kamil Trzcinski Committed by Robert Speicher
Browse files

Added CreateTriggerRequestService specs

parent bceb6550
No related branches found
No related tags found
No related merge requests found
class CreateTriggerRequestService
def execute(project, trigger, ref, variables)
commit = project.commits.find_by_ref(ref)
def execute(project, trigger, ref, variables = nil)
commit = project.commits.where(ref: ref).last
return unless commit
 
trigger_request = trigger.trigger_requests.create!(
Loading
Loading
Loading
Loading
@@ -51,15 +51,24 @@ FactoryGirl.define do
}
end
 
factory :commit_without_jobs do
after(:create) do |commit, evaluator|
commit.push_data[:ci_yaml_file] = YAML.dump({})
commit.save
end
end
factory :commit_with_one_job do
after(:create) do |commit, evaluator|
commit.push_data[:ci_yaml_file] = YAML.dump({rspec: { script: "ls" }})
commit.save
end
end
 
factory :commit_with_two_jobs do
after(:create) do |commit, evaluator|
commit.push_data[:ci_yaml_file] = YAML.dump({rspec: { script: "ls" }, spinach: { script: "ls" }})
commit.save
end
end
end
Loading
Loading
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment