2014-09-08 13:42:12 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2015-12-09 05:55:36 -05:00
|
|
|
describe Gitlab::Diff::File, lib: true do
|
2014-09-08 13:42:12 -04:00
|
|
|
include RepoHelpers
|
|
|
|
|
|
|
|
let(:project) { create(:project) }
|
2015-04-21 09:13:40 -04:00
|
|
|
let(:commit) { project.commit(sample_commit.id) }
|
2016-07-27 13:00:34 -04:00
|
|
|
let(:diff) { commit.raw_diffs.first }
|
2016-06-20 12:51:48 -04:00
|
|
|
let(:diff_file) { Gitlab::Diff::File.new(diff, diff_refs: commit.diff_refs, repository: project.repository) }
|
2014-09-08 13:42:12 -04:00
|
|
|
|
2016-07-11 18:12:31 -04:00
|
|
|
describe '#diff_lines' do
|
2014-09-08 13:42:12 -04:00
|
|
|
let(:diff_lines) { diff_file.diff_lines }
|
|
|
|
|
2015-02-12 13:17:35 -05:00
|
|
|
it { expect(diff_lines.size).to eq(30) }
|
|
|
|
it { expect(diff_lines.first).to be_kind_of(Gitlab::Diff::Line) }
|
2014-09-08 13:42:12 -04:00
|
|
|
end
|
|
|
|
|
2016-07-11 18:12:31 -04:00
|
|
|
describe '#mode_changed?' do
|
2015-02-12 13:17:35 -05:00
|
|
|
it { expect(diff_file.mode_changed?).to be_falsey }
|
2014-09-08 13:42:12 -04:00
|
|
|
end
|
2016-03-11 11:40:59 -05:00
|
|
|
|
|
|
|
describe '#too_large?' do
|
|
|
|
it 'returns true for a file that is too large' do
|
|
|
|
expect(diff).to receive(:too_large?).and_return(true)
|
|
|
|
|
|
|
|
expect(diff_file.too_large?).to eq(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false for a file that is small enough' do
|
|
|
|
expect(diff).to receive(:too_large?).and_return(false)
|
|
|
|
|
|
|
|
expect(diff_file.too_large?).to eq(false)
|
|
|
|
end
|
|
|
|
end
|
2016-07-15 03:04:18 -04:00
|
|
|
|
|
|
|
describe '#collapsed?' do
|
|
|
|
it 'returns true for a file that is quite big' do
|
|
|
|
expect(diff).to receive(:collapsed?).and_return(true)
|
|
|
|
|
|
|
|
expect(diff_file.collapsed?).to eq(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false for a file that is small enough' do
|
|
|
|
expect(diff).to receive(:collapsed?).and_return(false)
|
|
|
|
|
|
|
|
expect(diff_file.collapsed?).to eq(false)
|
|
|
|
end
|
|
|
|
end
|
2016-08-27 23:59:48 -04:00
|
|
|
|
|
|
|
describe '#old_content_commit' do
|
|
|
|
it 'returns base commit' do
|
|
|
|
old_content_commit = diff_file.old_content_commit
|
|
|
|
|
|
|
|
expect(old_content_commit.id).to eq('6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#old_blob' do
|
|
|
|
it 'returns blob of commit of base commit' do
|
|
|
|
old_data = diff_file.old_blob.data
|
|
|
|
|
|
|
|
expect(old_data).to include('raise "System commands must be given as an array of strings"')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#blob' do
|
|
|
|
it 'returns blob of new commit' do
|
|
|
|
data = diff_file.blob.data
|
|
|
|
|
|
|
|
expect(data).to include('raise RuntimeError, "System commands must be given as an array of strings"')
|
|
|
|
end
|
|
|
|
end
|
2014-09-08 13:42:12 -04:00
|
|
|
end
|