Commit b9f57192 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Remove reduntant `move_to_store` override

parent 99ee8228
...@@ -24,10 +24,6 @@ class FileUploader < CarrierWave::Uploader::Base ...@@ -24,10 +24,6 @@ class FileUploader < CarrierWave::Uploader::Base
File.join(base_dir, 'tmp', @project.path_with_namespace, @secret) File.join(base_dir, 'tmp', @project.path_with_namespace, @secret)
end end
def self.generate_secret
SecureRandom.hex
end
def secure_url def secure_url
File.join("/uploads", @secret, file.filename) File.join("/uploads", @secret, file.filename)
end end
...@@ -50,4 +46,8 @@ class FileUploader < CarrierWave::Uploader::Base ...@@ -50,4 +46,8 @@ class FileUploader < CarrierWave::Uploader::Base
markdown: markdown markdown: markdown
} }
end end
def self.generate_secret
SecureRandom.hex
end
end end
...@@ -17,11 +17,11 @@ module Gitlab ...@@ -17,11 +17,11 @@ module Gitlab
def rewrite(target_project) def rewrite(target_project)
return @text unless needs_rewrite? return @text unless needs_rewrite?
new_uploader = file_uploader(target_project)
@text.gsub(@pattern) do |markdown| @text.gsub(@pattern) do |markdown|
file = find_file(@source_project, $~[:secret], $~[:file]) file = find_file(@source_project, $~[:secret], $~[:file])
return markdown unless file.try(:exists?) return markdown unless file.try(:exists?)
new_uploader = FileUploader.new(target_project)
new_uploader.store!(file) new_uploader.store!(file)
new_uploader.to_markdown new_uploader.to_markdown
end end
...@@ -42,16 +42,10 @@ module Gitlab ...@@ -42,16 +42,10 @@ module Gitlab
private private
def find_file(project, secret, file) def find_file(project, secret, file)
uploader = file_uploader(project, secret) uploader = FileUploader.new(project, secret)
uploader.retrieve_from_store!(file) uploader.retrieve_from_store!(file)
uploader.file uploader.file
end 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 end
end end
...@@ -8,13 +8,13 @@ describe Gitlab::Gfm::UploadsRewriter do ...@@ -8,13 +8,13 @@ describe Gitlab::Gfm::UploadsRewriter do
context 'text contains links to uploads' do context 'text contains links to uploads' do
let(:uploader) { build(:file_uploader, project: old_project) } let(:uploader) { build(:file_uploader, project: old_project) }
let(:markdown) { uploader.to_h[:markdown] } let(:text) { "Text and #{uploader.to_markdown}"}
let(:text) { "Text and #{markdown}"}
describe '#rewrite' do describe '#rewrite' do
let!(:new_text) { rewriter.rewrite(new_project) } let!(:new_text) { rewriter.rewrite(new_project) }
let(:new_rewriter) { described_class.new(new_text, new_project, user) } 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 } let(:new_file) { new_rewriter.files.first }
it 'rewrites content' do it 'rewrites content' do
...@@ -29,7 +29,7 @@ describe Gitlab::Gfm::UploadsRewriter do ...@@ -29,7 +29,7 @@ describe Gitlab::Gfm::UploadsRewriter do
end end
it 'does not remove old files' do it 'does not remove old files' do
expect(old_file.exists?).to be true expect(old_file).to exist
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment