summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/uploaders/file_uploader.rb8
-rw-r--r--lib/gitlab/gfm/uploads_rewriter.rb10
-rw-r--r--spec/lib/gitlab/gfm/uploads_rewriter_spec.rb8
3 files changed, 10 insertions, 16 deletions
diff --git a/app/uploaders/file_uploader.rb b/app/uploaders/file_uploader.rb
index 730153a4740..1af9e9b0edb 100644
--- a/app/uploaders/file_uploader.rb
+++ b/app/uploaders/file_uploader.rb
@@ -24,10 +24,6 @@ class FileUploader < CarrierWave::Uploader::Base
File.join(base_dir, 'tmp', @project.path_with_namespace, @secret)
end
- def self.generate_secret
- SecureRandom.hex
- end
-
def secure_url
File.join("/uploads", @secret, file.filename)
end
@@ -50,4 +46,8 @@ class FileUploader < CarrierWave::Uploader::Base
markdown: markdown
}
end
+
+ def self.generate_secret
+ SecureRandom.hex
+ end
end
diff --git a/lib/gitlab/gfm/uploads_rewriter.rb b/lib/gitlab/gfm/uploads_rewriter.rb
index 2e61f799a03..abc8c8c55e6 100644
--- a/lib/gitlab/gfm/uploads_rewriter.rb
+++ b/lib/gitlab/gfm/uploads_rewriter.rb
@@ -17,11 +17,11 @@ module Gitlab
def rewrite(target_project)
return @text unless needs_rewrite?
- new_uploader = file_uploader(target_project)
@text.gsub(@pattern) do |markdown|
file = find_file(@source_project, $~[:secret], $~[:file])
return markdown unless file.try(:exists?)
+ new_uploader = FileUploader.new(target_project)
new_uploader.store!(file)
new_uploader.to_markdown
end
@@ -42,16 +42,10 @@ module Gitlab
private
def find_file(project, secret, file)
- uploader = file_uploader(project, secret)
+ uploader = FileUploader.new(project, secret)
uploader.retrieve_from_store!(file)
uploader.file
end
-
- def file_uploader(project, secret = nil)
- uploader = FileUploader.new(project, secret)
- uploader.define_singleton_method(:move_to_store) { false }
- uploader
- end
end
end
end
diff --git a/spec/lib/gitlab/gfm/uploads_rewriter_spec.rb b/spec/lib/gitlab/gfm/uploads_rewriter_spec.rb
index ec6c7d6beed..0a3856b6de5 100644
--- a/spec/lib/gitlab/gfm/uploads_rewriter_spec.rb
+++ b/spec/lib/gitlab/gfm/uploads_rewriter_spec.rb
@@ -8,13 +8,13 @@ describe Gitlab::Gfm::UploadsRewriter do
context 'text contains links to uploads' do
let(:uploader) { build(:file_uploader, project: old_project) }
- let(:markdown) { uploader.to_h[:markdown] }
- let(:text) { "Text and #{markdown}"}
+ let(:text) { "Text and #{uploader.to_markdown}"}
describe '#rewrite' do
let!(:new_text) { rewriter.rewrite(new_project) }
+
let(:new_rewriter) { described_class.new(new_text, new_project, user) }
- let(:old_file) { rewriter.files.first }
+ let(:old_file) { uploader.file }
let(:new_file) { new_rewriter.files.first }
it 'rewrites content' do
@@ -29,7 +29,7 @@ describe Gitlab::Gfm::UploadsRewriter do
end
it 'does not remove old files' do
- expect(old_file.exists?).to be true
+ expect(old_file).to exist
end
end