diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-03-29 13:12:57 +0300 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-03-30 11:44:18 +0300 |
commit | 0b8cefd3b2385a21cfed779bd659978c0402766d (patch) | |
tree | 9c4753cc8a610c153fb64e99dd619f3b8f0fc4d8 | |
parent | 701976e0815c273ff4a4c6e4d3489db0ce2f0860 (diff) |
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
-rw-r--r-- | app/uploaders/file_uploader.rb | 4 | ||||
-rw-r--r-- | spec/factories/file_uploader.rb | 19 | ||||
-rw-r--r-- | spec/lib/gitlab/gfm/uploads_rewriter_spec.rb | 5 |
3 files changed, 22 insertions, 6 deletions
diff --git a/app/uploaders/file_uploader.rb b/app/uploaders/file_uploader.rb index ac719f74f6a..25d879ff449 100644 --- a/app/uploaders/file_uploader.rb +++ b/app/uploaders/file_uploader.rb @@ -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 diff --git a/spec/factories/file_uploader.rb b/spec/factories/file_uploader.rb new file mode 100644 index 00000000000..69a4e6d28fb --- /dev/null +++ b/spec/factories/file_uploader.rb @@ -0,0 +1,19 @@ +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 diff --git a/spec/lib/gitlab/gfm/uploads_rewriter_spec.rb b/spec/lib/gitlab/gfm/uploads_rewriter_spec.rb index 7027954ef27..770c08148c9 100644 --- a/spec/lib/gitlab/gfm/uploads_rewriter_spec.rb +++ b/spec/lib/gitlab/gfm/uploads_rewriter_spec.rb @@ -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}"} |