gitlab-org--gitlab-foss/spec/models/diff_viewer/server_side_spec.rb
Francisco Javier López 5a3e6fdff9
Fixing image lfs bug and also displaying text lfs
This commit, introduced in https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/23812,
fixes a problem creating a displaying image diff notes when the image
is stored in LFS. The main problem was that `Gitlab::Diff::File` was
returning an invalid valid in `text?` for this kind of files.

It also fixes a rendering problem with other LFS files, like text
ones. They LFS pointer shouldn't be shown when LFS is enabled
for the project, but they were.
2018-12-27 16:51:07 +01:00

55 lines
1.6 KiB
Ruby

require 'spec_helper'
describe DiffViewer::ServerSide do
set(:project) { create(:project, :repository) }
let(:commit) { project.commit_by(oid: '570e7b2abdd848b95f2f578043fc23bd6f6fd24d') }
let!(:diff_file) { commit.diffs.diff_file_with_new_path('files/ruby/popen.rb') }
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
expect(Blob).to receive(:lazy).at_least(:twice)
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
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
end