gitlab-org--gitlab-foss/spec/lib/gitlab/gfm/uploads_rewriter_spec.rb

67 lines
1.9 KiB
Ruby
Raw Normal View History

require 'spec_helper'
describe Gitlab::Gfm::UploadsRewriter do
let(:user) { create(:user) }
let(:old_project) { create(:project) }
let(:new_project) { create(:project) }
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,
fixture: 'ci_build_artifacts.zip')
2016-03-31 03:43:47 -04:00
end
let(:text) do
"Text and #{image_uploader.to_markdown} and #{zip_uploader.to_markdown}"
end
describe '#rewrite' do
let!(:new_text) { rewriter.rewrite(new_project) }
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) }
it 'rewrites content' do
expect(new_text).not_to eq text
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)
expect(old_paths).not_to match_array new_paths
expect(old_paths).to all(include(old_project.full_path))
expect(new_paths).to all(include(new_project.full_path))
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
expect(new_paths).not_to include image_uploader.secret
expect(new_paths).not_to include zip_uploader.secret
end
end
describe '#needs_rewrite?' do
subject { rewriter.needs_rewrite? }
it { is_expected.to eq true }
end
describe '#files' do
subject { rewriter.files }
it { is_expected.to be_an(Array) }
end
end
end