summaryrefslogtreecommitdiff
path: root/spec/uploaders/content_type_whitelist_spec.rb
blob: be519ead1c8c6fe1b7679256ac2b853962876c6e (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
# frozen_string_literal: true

require 'spec_helper'

describe ContentTypeWhitelist do
  class DummyUploader < CarrierWave::Uploader::Base
    include ContentTypeWhitelist::Concern

    def content_type_whitelist
      %w[image/png image/jpeg]
    end
  end

  let_it_be(:model) { build_stubbed(:user) }
  let_it_be(:uploader) { DummyUploader.new(model, :dummy) }

  context 'upload whitelisted file content type' do
    let(:path) { File.join('spec', 'fixtures', 'rails_sample.jpg') }

    it_behaves_like 'accepted carrierwave upload'
  end

  context 'upload non-whitelisted file content type' do
    let(:path) { File.join('spec', 'fixtures', 'sanitized.svg') }

    it_behaves_like 'denied carrierwave upload'
  end

  context 'upload misnamed non-whitelisted file content type' do
    let(:path) { File.join('spec', 'fixtures', 'not_a_png.png') }

    it_behaves_like 'denied carrierwave upload'
  end
end