2016-03-24 07:28:43 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Gitlab::Gfm::UploadsRewriter do
|
|
|
|
let(:user) { create(:user) }
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:old_project) { create(:project) }
|
|
|
|
let(:new_project) { create(:project) }
|
2016-03-24 07:28:43 -04:00
|
|
|
let(:rewriter) { described_class.new(text, old_project, user) }
|
|
|
|
|
|
|
|
context 'text contains links to uploads' do
|
2016-03-31 03:43:47 -04:00
|
|
|
let(:image_uploader) do
|
|
|
|
build(:file_uploader, project: old_project)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:zip_uploader) do
|
|
|
|
build(:file_uploader, project: old_project,
|
2016-03-31 04:41:57 -04:00
|
|
|
fixture: 'ci_build_artifacts.zip')
|
2016-03-31 03:43:47 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
let(:text) do
|
2018-01-29 12:57:34 -05:00
|
|
|
"Text and #{image_uploader.markdown_link} and #{zip_uploader.markdown_link}"
|
2016-03-31 03:43:47 -04:00
|
|
|
end
|
2016-03-24 07:28:43 -04:00
|
|
|
|
|
|
|
describe '#rewrite' do
|
|
|
|
let!(:new_text) { rewriter.rewrite(new_project) }
|
2016-03-30 06:11:27 -04:00
|
|
|
|
2016-03-31 03:43:47 -04:00
|
|
|
let(:old_files) { [image_uploader, zip_uploader].map(&:file) }
|
|
|
|
let(:new_files) do
|
|
|
|
described_class.new(new_text, new_project, user).files
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:old_paths) { old_files.map(&:path) }
|
|
|
|
let(:new_paths) { new_files.map(&:path) }
|
2016-03-24 07:28:43 -04:00
|
|
|
|
|
|
|
it 'rewrites content' do
|
2016-05-23 19:37:59 -04:00
|
|
|
expect(new_text).not_to eq text
|
2016-03-24 07:28:43 -04:00
|
|
|
expect(new_text.length).to eq text.length
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'copies files' do
|
2016-03-31 03:43:47 -04:00
|
|
|
expect(new_files).to all(exist)
|
2016-05-23 19:37:59 -04:00
|
|
|
expect(old_paths).not_to match_array new_paths
|
2017-12-01 08:58:49 -05:00
|
|
|
expect(old_paths).to all(include(old_project.disk_path))
|
|
|
|
expect(new_paths).to all(include(new_project.disk_path))
|
2016-03-24 07:28:43 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not remove old files' do
|
2016-03-31 03:43:47 -04:00
|
|
|
expect(old_files).to all(exist)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'generates a new secret for each file' do
|
2016-05-23 19:37:59 -04:00
|
|
|
expect(new_paths).not_to include image_uploader.secret
|
|
|
|
expect(new_paths).not_to include zip_uploader.secret
|
2016-03-24 07:28:43 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-03-29 07:21:57 -04:00
|
|
|
describe '#needs_rewrite?' do
|
|
|
|
subject { rewriter.needs_rewrite? }
|
2016-03-24 07:28:43 -04:00
|
|
|
it { is_expected.to eq true }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#files' do
|
|
|
|
subject { rewriter.files }
|
|
|
|
it { is_expected.to be_an(Array) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|