summaryrefslogtreecommitdiff
path: root/spec/uploaders/file_uploader_spec.rb
blob: 6a712e33c962caa6543d35f673b1a9adf45e5dfc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
require 'spec_helper'

describe FileUploader do
  let(:project) { create(:project) }

  before do
    @previous_enable_processing = FileUploader.enable_processing
    FileUploader.enable_processing = false
    @uploader = FileUploader.new(project)
  end

  after do
    FileUploader.enable_processing = @previous_enable_processing
    @uploader.remove!
  end

  describe '#image_or_video?' do
    context 'given an image file' do
      before do
        @uploader.store!(fixture_file_upload(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 = fixture_file_upload(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!(fixture_file_upload(Rails.root.join('spec', 'fixtures', 'doc_sample.txt')))

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

  describe '#move_to_cache' do
    it 'is true' do
      expect(@uploader.move_to_cache).to eq(true)
    end
  end

  describe '#move_to_store' do
    it 'is true' do
      expect(@uploader.move_to_store).to eq(true)
    end
  end
end