2016-06-28 12:25:32 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe MergeRequestDiff, models: true do
|
|
|
|
describe '#diffs' do
|
|
|
|
let(:mr) { create(:merge_request, :with_diffs) }
|
|
|
|
let(:mr_diff) { mr.merge_request_diff }
|
|
|
|
|
|
|
|
context 'when the :ignore_whitespace_change option is set' do
|
|
|
|
it 'creates a new compare object instead of loading from the DB' do
|
|
|
|
expect(mr_diff).not_to receive(:load_diffs)
|
|
|
|
expect(Gitlab::Git::Compare).to receive(:new).and_call_original
|
|
|
|
|
2016-08-03 17:32:12 -04:00
|
|
|
mr_diff.raw_diffs(ignore_whitespace_change: true)
|
2016-06-28 12:25:32 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the raw diffs are empty' do
|
|
|
|
before { mr_diff.update_attributes(st_diffs: '') }
|
|
|
|
|
|
|
|
it 'returns an empty DiffCollection' do
|
2016-08-03 17:32:12 -04:00
|
|
|
expect(mr_diff.raw_diffs).to be_a(Gitlab::Git::DiffCollection)
|
|
|
|
expect(mr_diff.raw_diffs).to be_empty
|
2016-06-28 12:25:32 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the raw diffs exist' do
|
|
|
|
it 'returns the diffs' do
|
2016-08-03 17:32:12 -04:00
|
|
|
expect(mr_diff.raw_diffs).to be_a(Gitlab::Git::DiffCollection)
|
|
|
|
expect(mr_diff.raw_diffs).not_to be_empty
|
2016-06-28 12:25:32 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the :paths option is set' do
|
2016-08-03 17:32:12 -04:00
|
|
|
let(:diffs) { mr_diff.raw_diffs(paths: ['files/ruby/popen.rb', 'files/ruby/popen.rb']) }
|
2016-06-28 12:25:32 -04:00
|
|
|
|
2016-07-08 17:50:06 -04:00
|
|
|
it 'only returns diffs that match the (old path, new path) given' do
|
|
|
|
expect(diffs.map(&:new_path)).to contain_exactly('files/ruby/popen.rb')
|
2016-06-28 12:25:32 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'uses the diffs from the DB' do
|
|
|
|
expect(mr_diff).to receive(:load_diffs)
|
|
|
|
|
|
|
|
diffs
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|