2016-03-24 11:28:43 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Gitlab::Gfm::UploadsRewriter do
|
|
|
|
let(:user) { create(:user) }
|
2017-01-24 23:42:12 +00:00
|
|
|
let(:old_project) { create(:empty_project) }
|
|
|
|
let(:new_project) { create(:empty_project) }
|
2016-03-24 11:28:43 +00:00
|
|
|
let(:rewriter) { described_class.new(text, old_project, user) }
|
|
|
|
|
|
|
|
context 'text contains links to uploads' do
|
2016-03-31 07:43:47 +00: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 08:41:57 +00:00
|
|
|
fixture: 'ci_build_artifacts.zip')
|
2016-03-31 07:43:47 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
let(:text) do
|
|
|
|
"Text and #{image_uploader.to_markdown} and #{zip_uploader.to_markdown}"
|
|
|
|
end
|
2016-03-24 11:28:43 +00:00
|
|
|
|
|
|
|
describe '#rewrite' do
|
|
|
|
let!(:new_text) { rewriter.rewrite(new_project) }
|
2016-03-30 10:11:27 +00:00
|
|
|
|
2016-03-31 07:43:47 +00: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 11:28:43 +00:00
|
|
|
|
|
|
|
it 'rewrites content' do
|
2016-05-23 23:37:59 +00:00
|
|
|
expect(new_text).not_to eq text
|
2016-03-24 11:28:43 +00:00
|
|
|
expect(new_text.length).to eq text.length
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'copies files' do
|
2016-03-31 07:43:47 +00:00
|
|
|
expect(new_files).to all(exist)
|
2016-05-23 23:37:59 +00:00
|
|
|
expect(old_paths).not_to match_array new_paths
|
2016-03-31 07:43:47 +00:00
|
|
|
expect(old_paths).to all(include(old_project.path_with_namespace))
|
|
|
|
expect(new_paths).to all(include(new_project.path_with_namespace))
|
2016-03-24 11:28:43 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not remove old files' do
|
2016-03-31 07:43:47 +00:00
|
|
|
expect(old_files).to all(exist)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'generates a new secret for each file' do
|
2016-05-23 23:37:59 +00:00
|
|
|
expect(new_paths).not_to include image_uploader.secret
|
|
|
|
expect(new_paths).not_to include zip_uploader.secret
|
2016-03-24 11:28:43 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-03-29 11:21:57 +00:00
|
|
|
describe '#needs_rewrite?' do
|
|
|
|
subject { rewriter.needs_rewrite? }
|
2016-03-24 11:28:43 +00:00
|
|
|
it { is_expected.to eq true }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#files' do
|
|
|
|
subject { rewriter.files }
|
|
|
|
it { is_expected.to be_an(Array) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|