Commit 104051d7 authored by Vitali Tatarintev's avatar Vitali Tatarintev

Merge branch 'ck3g-fix-danger-helper-for-renamed-files' into 'master'

Fix Danger::Helper check for renamed files

See merge request gitlab-org/gitlab!41805
parents 2b616758 5573ea05
......@@ -44,7 +44,10 @@ module Gitlab
# "+ # Test change",
# "- # Old change" ]
def changed_lines(changed_file)
git.diff_for_file(changed_file).patch.split("\n").select { |line| %r{^[+-]}.match?(line) }
diff = git.diff_for_file(changed_file)
return [] unless diff
diff.patch.split("\n").select { |line| %r{^[+-]}.match?(line) }
end
def all_ee_changes
......
......@@ -76,6 +76,30 @@ RSpec.describe Gitlab::Danger::Helper do
end
end
describe '#changed_lines' do
subject { helper.changed_lines('changed_file.rb') }
before do
allow(fake_git).to receive(:diff_for_file).with('changed_file.rb').and_return(diff)
end
context 'when file has diff' do
let(:diff) { double(:diff, patch: "+ # New change here\n+ # New change there") }
it 'returns file changes' do
is_expected.to eq(['+ # New change here', '+ # New change there'])
end
end
context 'when file has no diff (renamed without changes)' do
let(:diff) { nil }
it 'returns a blank array' do
is_expected.to eq([])
end
end
end
describe "changed_files" do
it 'returns list of changed files matching given regex' do
expect(helper).to receive(:all_changed_files).and_return(%w[migration.rb usage_data.rb])
......
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