BigW Consortium Gitlab

file_uploader_spec.rb 1.18 KB
Newer Older
1
require 'spec_helper'
2 3

describe FileUploader do
4
  let(:project) { create(:project) }
5 6

  before do
7
    @previous_enable_processing = FileUploader.enable_processing
8 9 10 11 12
    FileUploader.enable_processing = false
    @uploader = FileUploader.new(project)
  end

  after do
13
    FileUploader.enable_processing = @previous_enable_processing
14 15 16
    @uploader.remove!
  end

17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
  describe '#image_or_video?' do
    context 'given an image file' do
      before do
        @uploader.store!(File.new(Rails.root.join('spec', 'fixtures', 'rails_sample.jpg')))
      end

      it 'detects an image based on file extension' do
        expect(@uploader.image_or_video?).to be true
      end
    end

    context 'given an video file' do
      before do
        video_file = File.new(Rails.root.join('spec', 'fixtures', 'video_sample.mp4'))
        @uploader.store!(video_file)
      end

      it 'detects a video based on file extension' do
        expect(@uploader.image_or_video?).to be true
      end
    end

    it 'does not return image_or_video? for other types' do
      @uploader.store!(File.new(Rails.root.join('spec', 'fixtures', 'doc_sample.txt')))

      expect(@uploader.image_or_video?).to be false
    end
44 45
  end
end