Commit b59abf5b authored by Shinya Maeda's avatar Shinya Maeda

Use let(:params) instead of def param

parent 34d2b8e7
...@@ -9,19 +9,23 @@ describe Ci::PipelineTriggerService, services: true do ...@@ -9,19 +9,23 @@ describe Ci::PipelineTriggerService, services: true do
describe '#execute' do describe '#execute' do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:trigger) { create(:ci_trigger, project: project, owner: user) }
let(:result) { described_class.new(project, user, params).execute }
let(:params) do
{ token: token, ref: ref, variables: variables }
end
before do before do
project.add_developer(user) project.add_developer(user)
end end
let(:result) { described_class.new(project, user, params).execute }
let(:trigger) { create(:ci_trigger, project: project, owner: user) }
context 'when params have an existsed trigger token' do context 'when params have an existsed trigger token' do
let(:token) { trigger.token } let(:token) { trigger.token }
context 'when params have an existsed ref' do context 'when params have an existsed ref' do
let(:ref) { 'master' } let(:ref) { 'master' }
let(:variables) {}
it 'triggers a pipeline' do it 'triggers a pipeline' do
expect { result }.to change { Ci::Pipeline.count }.by(1) expect { result }.to change { Ci::Pipeline.count }.by(1)
...@@ -44,6 +48,7 @@ describe Ci::PipelineTriggerService, services: true do ...@@ -44,6 +48,7 @@ describe Ci::PipelineTriggerService, services: true do
context 'when params have a non-existsed ref' do context 'when params have a non-existsed ref' do
let(:ref) { 'invalid-ref' } let(:ref) { 'invalid-ref' }
let(:variables) {}
it 'does not trigger a pipeline' do it 'does not trigger a pipeline' do
expect { result }.not_to change { Ci::Pipeline.count } expect { result }.not_to change { Ci::Pipeline.count }
...@@ -54,6 +59,8 @@ describe Ci::PipelineTriggerService, services: true do ...@@ -54,6 +59,8 @@ describe Ci::PipelineTriggerService, services: true do
context 'when params have a non-existsed trigger token' do context 'when params have a non-existsed trigger token' do
let(:token) { 'invalid-token' } let(:token) { 'invalid-token' }
let(:ref) {}
let(:variables) {}
it 'does not trigger a pipeline' do it 'does not trigger a pipeline' do
expect { result }.not_to change { Ci::Pipeline.count } expect { result }.not_to change { Ci::Pipeline.count }
...@@ -61,10 +68,4 @@ describe Ci::PipelineTriggerService, services: true do ...@@ -61,10 +68,4 @@ describe Ci::PipelineTriggerService, services: true do
end end
end end
end end
def params
{ token: defined?(token) ? token : nil,
ref: defined?(ref) ? ref : nil,
variables: defined?(variables) ? variables : nil }
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment