Get FileUploader into test harness using factory

This attempts to get CarrierWave's uploader - `FileUploader` into test
harness using a factory. that makes it easier to build an instance of
it.

Along with !3435 it may be easier to use uploaders in tests
parent 701976e0
......@@ -7,9 +7,9 @@ class FileUploader < CarrierWave::Uploader::Base
attr_accessor :project, :secret
def initialize(project, secret = self.class.generate_secret)
def initialize(project, secret = nil)
@project = project
@secret = secret
@secret = secret || self.class.generate_secret
end
def base_dir
......
FactoryGirl.define do
factory :file_uploader, class: FileUploader do
project
secret nil
transient do
path { File.join(Rails.root, 'spec/fixtures/rails_sample.jpg') }
file { Rack::Test::UploadedFile.new(path) }
end
after(:build) do |uploader, evaluator|
uploader.store!(evaluator.file)
end
initialize_with do
new(project, secret)
end
end
end
......@@ -7,10 +7,7 @@ describe Gitlab::Gfm::UploadsRewriter do
let(:rewriter) { described_class.new(text, old_project, user) }
context 'text contains links to uploads' do
let(:path) { Rails.root + 'spec/fixtures/rails_sample.jpg' }
let(:file) { fixture_file_upload(path, 'image/jpg') }
let(:uploader) { FileUploader.new(old_project) }
let!(:store) { uploader.store!(file) } # TODO, see #xxx (carrierwave issue)
let(:uploader) { build(:file_uploader, project: old_project) }
let(:markdown) { uploader.to_h[:markdown] }
let(:text) { "Text and #{markdown}"}
......
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