2016-07-12 13:28:39 -04:00
|
|
|
require 'spec_helper'
|
2016-04-03 01:00:06 -04:00
|
|
|
|
|
|
|
describe FileUploader do
|
2016-07-12 13:28:39 -04:00
|
|
|
let(:project) { create(:project) }
|
2016-04-03 01:00:06 -04:00
|
|
|
|
|
|
|
before do
|
2016-07-12 13:28:39 -04:00
|
|
|
@previous_enable_processing = FileUploader.enable_processing
|
2016-04-03 01:00:06 -04:00
|
|
|
FileUploader.enable_processing = false
|
|
|
|
@uploader = FileUploader.new(project)
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
2016-07-12 13:28:39 -04:00
|
|
|
FileUploader.enable_processing = @previous_enable_processing
|
2016-04-03 01:00:06 -04:00
|
|
|
@uploader.remove!
|
|
|
|
end
|
|
|
|
|
2016-07-12 13:28:39 -04:00
|
|
|
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
|
2016-04-03 01:00:06 -04:00
|
|
|
end
|
2016-08-18 10:31:44 -04:00
|
|
|
|
|
|
|
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
|
2016-04-03 01:00:06 -04:00
|
|
|
end
|