diff options
author | Eric Hayes <eric@erichayes.net> | 2016-04-02 22:00:06 -0700 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2016-07-19 18:51:09 +0200 |
commit | c266c7fa18848586cd6ee903cc4c4d4f9049100e (patch) | |
tree | 8fa8d0b2dca828bec6af0ad49855cbb4e69a9e30 /spec | |
parent | 81e57e783e8882de21d27d9191c09404ed7faca3 (diff) | |
download | gitlab-ce-c266c7fa18848586cd6ee903cc4c4d4f9049100e.tar.gz |
First support of videos in issues, MRs and notes
* Registered video MIME types
* Currently supporting browser-supported formats with extensions that match the mime type
Diffstat (limited to 'spec')
-rw-r--r-- | spec/fixtures/video_sample.mp4 | bin | 0 -> 59122 bytes | |||
-rw-r--r-- | spec/lib/banzai/filter/video_link_filter_spec.rb | 36 | ||||
-rw-r--r-- | spec/uploaders/file_uploader_spec.rb | 42 |
3 files changed, 78 insertions, 0 deletions
diff --git a/spec/fixtures/video_sample.mp4 b/spec/fixtures/video_sample.mp4 Binary files differnew file mode 100644 index 00000000000..acd45190998 --- /dev/null +++ b/spec/fixtures/video_sample.mp4 diff --git a/spec/lib/banzai/filter/video_link_filter_spec.rb b/spec/lib/banzai/filter/video_link_filter_spec.rb new file mode 100644 index 00000000000..8ccfb9c0fca --- /dev/null +++ b/spec/lib/banzai/filter/video_link_filter_spec.rb @@ -0,0 +1,36 @@ +require 'spec_helper' + +describe Banzai::Filter::VideoLinkFilter, lib: true do + def filter(doc, contexts = {}) + contexts.reverse_merge!({ + project: project + }) + + described_class.call(doc, contexts) + end + + def image(path) + %(<img src="#{path}" />) + end + + let(:project) { create(:project) } + + context 'when the element src has a video extension' do + it 'replaces the image tag with a video tag' do + doc = filter(image("/path/video.mov")) + element = doc.children.first + expect(element.name).to eq( "video" ) + expect(element['src']).to eq( "/path/video.mov" ) + end + end + + context 'when the element src is an image' do + it 'leaves the document unchanged' do + doc = filter(image("/path/my_image.jpg")) + element = doc.children.first + expect(element.name).to eq( "img" ) + end + end + + +end diff --git a/spec/uploaders/file_uploader_spec.rb b/spec/uploaders/file_uploader_spec.rb new file mode 100644 index 00000000000..b59f44e0a65 --- /dev/null +++ b/spec/uploaders/file_uploader_spec.rb @@ -0,0 +1,42 @@ +require "spec_helper" + +# provides matchers like `have_dimensions` +# https://github.com/carrierwaveuploader/carrierwave#testing-with-carrierwave +# require "carrierwave/test/matchers" + + +describe FileUploader do + # include CarrierWave::Test::Matchers + + let(:project){ create(:project) } + + let(:image_file){ File.new Rails.root.join("spec", "fixtures", "rails_sample.jpg") } + let(:video_file){ File.new Rails.root.join("spec", "fixtures", "video_sample.mp4") } + let(:text_file) { File.new Rails.root.join("spec", "fixtures", "doc_sample.txt") } + + before do + FileUploader.enable_processing = false + @uploader = FileUploader.new(project) + end + + after do + FileUploader.enable_processing = true + @uploader.remove! + end + + it "should detect an image based on file extension" do + @uploader.store!(image_file) + expect(@uploader.image_or_video?).to be true + end + + it "should detect a video based on file extension" do + @uploader.store!(video_file) + expect(@uploader.image_or_video?).to be true + end + + it "should not return image_or_video? for other types" do + @uploader.store!(text_file) + expect(@uploader.image_or_video?).to be false + end + +end |