2019-03-30 03:23:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-06-06 17:28:06 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe DiffViewer::ServerSide do
|
2020-02-12 10:09:37 -05:00
|
|
|
let_it_be(:project) { create(:project, :repository) }
|
2017-11-03 09:16:43 -04:00
|
|
|
let(:commit) { project.commit_by(oid: '570e7b2abdd848b95f2f578043fc23bd6f6fd24d') }
|
|
|
|
let!(:diff_file) { commit.diffs.diff_file_with_new_path('files/ruby/popen.rb') }
|
2017-06-06 17:28:06 -04:00
|
|
|
|
|
|
|
let(:viewer_class) do
|
|
|
|
Class.new(DiffViewer::Base) do
|
|
|
|
include DiffViewer::ServerSide
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
subject { viewer_class.new(diff_file) }
|
|
|
|
|
|
|
|
describe '#prepare!' do
|
|
|
|
it 'loads all diff file data' do
|
2017-11-03 09:16:43 -04:00
|
|
|
expect(Blob).to receive(:lazy).at_least(:twice)
|
2017-06-06 17:28:06 -04:00
|
|
|
|
|
|
|
subject.prepare!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#render_error' do
|
|
|
|
context 'when the diff file is stored externally' do
|
|
|
|
before do
|
|
|
|
allow(diff_file).to receive(:stored_externally?).and_return(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'return :server_side_but_stored_externally' do
|
|
|
|
expect(subject.render_error).to eq(:server_side_but_stored_externally)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-12-13 12:49:05 -05:00
|
|
|
|
|
|
|
describe '#render_error_reason' do
|
|
|
|
context 'when the diff file is stored externally' do
|
|
|
|
before do
|
|
|
|
allow(diff_file).to receive(:stored_externally?).and_return(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns error message if stored in LFS' do
|
|
|
|
allow(diff_file).to receive(:external_storage).and_return(:lfs)
|
|
|
|
|
|
|
|
expect(subject.render_error_message).to include('it is stored in LFS')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns error message if stored externally' do
|
|
|
|
allow(diff_file).to receive(:external_storage).and_return(:foo)
|
|
|
|
|
|
|
|
expect(subject.render_error_message).to include('it is stored externally')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-06-06 17:28:06 -04:00
|
|
|
end
|