diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2017-07-20 00:08:34 +0800 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2017-07-20 00:08:34 +0800 |
commit | a05bc477b99500fa919295e1086f7a8de903e3c4 (patch) | |
tree | 12a04ccc7551ff3eaae9ce7ae2d07c6e11886f93 | |
parent | d035d735242a47bee7cd5973c9daa7d984800700 (diff) | |
download | gitlab-ce-a05bc477b99500fa919295e1086f7a8de903e3c4.tar.gz |
Use hash to return multiple objects
-rw-r--r-- | app/services/ci/create_trigger_request_service.rb | 8 | ||||
-rw-r--r-- | lib/api/triggers.rb | 4 | ||||
-rw-r--r-- | lib/api/v3/triggers.rb | 6 | ||||
-rw-r--r-- | lib/ci/api/triggers.rb | 6 | ||||
-rw-r--r-- | spec/services/ci/create_trigger_request_service_spec.rb | 26 |
5 files changed, 25 insertions, 25 deletions
diff --git a/app/services/ci/create_trigger_request_service.rb b/app/services/ci/create_trigger_request_service.rb index 90f75606ddf..1674830a41a 100644 --- a/app/services/ci/create_trigger_request_service.rb +++ b/app/services/ci/create_trigger_request_service.rb @@ -1,13 +1,13 @@ module Ci - class CreateTriggerRequestService - def execute(project, trigger, ref, variables = nil) + module CreateTriggerRequestService + def self.execute(project, trigger, ref, variables = nil) trigger_request = trigger.trigger_requests.create(variables: variables) pipeline = Ci::CreatePipelineService.new(project, trigger.owner, ref: ref) .execute(:trigger, ignore_skip_ci: true, trigger_request: trigger_request) - trigger_request.pipeline = pipeline - trigger_request + { trigger_request: trigger_request, + pipeline: pipeline } end end end diff --git a/lib/api/triggers.rb b/lib/api/triggers.rb index 9e444563fdf..55528101f15 100644 --- a/lib/api/triggers.rb +++ b/lib/api/triggers.rb @@ -27,8 +27,8 @@ module API end # create request and trigger builds - trigger_request = Ci::CreateTriggerRequestService.new.execute(project, trigger, params[:ref].to_s, variables) - pipeline = trigger_request.pipeline + result = Ci::CreateTriggerRequestService.execute(project, trigger, params[:ref].to_s, variables) + pipeline = result[:pipeline] if pipeline.persisted? present pipeline, with: Entities::Pipeline diff --git a/lib/api/v3/triggers.rb b/lib/api/v3/triggers.rb index 7e75c579528..0e236423b8c 100644 --- a/lib/api/v3/triggers.rb +++ b/lib/api/v3/triggers.rb @@ -28,11 +28,11 @@ module API end # create request and trigger builds - trigger_request = Ci::CreateTriggerRequestService.new.execute(project, trigger, params[:ref].to_s, variables) - pipeline = trigger_request.pipeline + result = Ci::CreateTriggerRequestService.execute(project, trigger, params[:ref].to_s, variables) + pipeline = result[:pipeline] if pipeline.persisted? - present trigger_request, with: ::API::V3::Entities::TriggerRequest + present result[:trigger_request], with: ::API::V3::Entities::TriggerRequest else render_validation_error!(pipeline) end diff --git a/lib/ci/api/triggers.rb b/lib/ci/api/triggers.rb index 0e5174e13ab..ce0ef95b186 100644 --- a/lib/ci/api/triggers.rb +++ b/lib/ci/api/triggers.rb @@ -24,11 +24,11 @@ module Ci end # create request and trigger builds - trigger_request = Ci::CreateTriggerRequestService.new.execute(project, trigger, params[:ref], variables) - pipeline = trigger_request.pipeline + result = Ci::CreateTriggerRequestService.execute(project, trigger, params[:ref], variables) + pipeline = result[:pipeline] if pipeline.persisted? - present trigger_request, with: Entities::TriggerRequest + present result[:trigger_request], with: Entities::TriggerRequest else render_validation_error!(pipeline) end diff --git a/spec/services/ci/create_trigger_request_service_spec.rb b/spec/services/ci/create_trigger_request_service_spec.rb index 8582c74e734..48d9b0844f1 100644 --- a/spec/services/ci/create_trigger_request_service_spec.rb +++ b/spec/services/ci/create_trigger_request_service_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe Ci::CreateTriggerRequestService, services: true do - let(:service) { described_class.new } + let(:service) { described_class } let(:project) { create(:project, :repository) } let(:trigger) { create(:ci_trigger, project: project, owner: owner) } let(:owner) { create(:user) } @@ -17,26 +17,26 @@ describe Ci::CreateTriggerRequestService, services: true do subject { service.execute(project, trigger, 'master') } context 'without owner' do - it { expect(subject).to be_kind_of(Ci::TriggerRequest) } - it { expect(subject.pipeline).to be_kind_of(Ci::Pipeline) } - it { expect(subject.pipeline).to be_trigger } - it { expect(subject.builds.first).to be_kind_of(Ci::Build) } + it { expect(subject[:trigger_request]).to be_kind_of(Ci::TriggerRequest) } + it { expect(subject[:trigger_request].builds.first).to be_kind_of(Ci::Build) } + it { expect(subject[:pipeline]).to be_kind_of(Ci::Pipeline) } + it { expect(subject[:pipeline]).to be_trigger } end context 'with owner' do - it { expect(subject).to be_kind_of(Ci::TriggerRequest) } - it { expect(subject.pipeline).to be_kind_of(Ci::Pipeline) } - it { expect(subject.pipeline).to be_trigger } - 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) } + it { expect(subject[:trigger_request]).to be_kind_of(Ci::TriggerRequest) } + it { expect(subject[:trigger_request].builds.first).to be_kind_of(Ci::Build) } + it { expect(subject[:trigger_request].builds.first.user).to eq(owner) } + it { expect(subject[:pipeline]).to be_kind_of(Ci::Pipeline) } + it { expect(subject[:pipeline]).to be_trigger } + it { expect(subject[:pipeline].user).to eq(owner) } end end context 'no commit for ref' do subject { service.execute(project, trigger, 'other-branch') } - it { expect(subject.pipeline).not_to be_persisted } + it { expect(subject[:pipeline]).not_to be_persisted } end context 'no builds created' do @@ -46,7 +46,7 @@ describe Ci::CreateTriggerRequestService, services: true do stub_ci_pipeline_yaml_file('script: { only: [develop], script: hello World }') end - it { expect(subject.pipeline).not_to be_persisted } + it { expect(subject[:pipeline]).not_to be_persisted } end end end |