Commit da13b56d authored by Shinya Maeda's avatar Shinya Maeda

Merge branch 'id-undefined-modified_paths' into 'master'

Fix NoMethodError for calling modified_paths on nil pipeline

See merge request gitlab-org/gitlab!80089
parents 9cd3bed4 fe96b2d0
......@@ -9,7 +9,7 @@ module Gitlab
end
def satisfied_by?(pipeline, context)
return true if pipeline.modified_paths.nil?
return true unless pipeline&.modified_paths
expanded_globs = expand_globs(context)
pipeline.modified_paths.any? do |path|
......
......@@ -8,7 +8,7 @@ module Gitlab
@expression = expression
end
def satisfied_by?(pipeline, context)
def satisfied_by?(_pipeline, context)
::Gitlab::Ci::Pipeline::Expression::Statement.new(
@expression, context.variables_hash).truthful?
end
......
......@@ -4,14 +4,23 @@ require 'spec_helper'
RSpec.describe Gitlab::Ci::Build::Rules::Rule::Clause::Changes do
describe '#satisfied_by?' do
subject { described_class.new(globs).satisfied_by?(pipeline, context) }
it_behaves_like 'a glob matching rule' do
let(:pipeline) { build(:ci_pipeline) }
let(:context) {}
before do
allow(pipeline).to receive(:modified_paths).and_return(files.keys)
end
end
subject { described_class.new(globs).satisfied_by?(pipeline, nil) }
context 'when pipeline is nil' do
let(:pipeline) {}
let(:context) {}
let(:globs) { [] }
it { is_expected.to be_truthy }
end
context 'when using variable expansion' do
......@@ -20,8 +29,6 @@ RSpec.describe Gitlab::Ci::Build::Rules::Rule::Clause::Changes do
let(:globs) { ['$HELM_DIR/**/*'] }
let(:context) { double('context') }
subject { described_class.new(globs).satisfied_by?(pipeline, context) }
before do
allow(pipeline).to receive(:modified_paths).and_return(modified_paths)
end
......@@ -32,6 +39,12 @@ RSpec.describe Gitlab::Ci::Build::Rules::Rule::Clause::Changes do
it { is_expected.to be_falsey }
end
context 'when modified paths are nil' do
let(:modified_paths) {}
it { is_expected.to be_truthy }
end
context 'when context has the specified variables' do
let(:variables_hash) do
{ 'HELM_DIR' => 'helm' }
......
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