-
-
Save dennismonsewicz/3d7b4a1e733a06603c61 to your computer and use it in GitHub Desktop.
Rspec test for ManagesVideoFiles module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
describe ManagesVideoFiles do | |
let(:athlete) { create(:athlete) } | |
let(:video) { create(:video, athlete_id: athlete.id) } | |
let(:panda_screenshot_url) { "http://foo.com/image.ext" } | |
let(:secure_panda_screenshot_url) { panda_screenshot_url.sub "http", "https" } | |
let(:panda_encoding_url) { "http://hello.io" } | |
let(:secure_panda_encoding_url) { panda_encoding_url.sub "http", "https" } | |
describe "instance methods" do | |
describe "#thumbnail_url" do | |
context "when video has thumbail_url object property" do | |
it "should return thumbnail_url from database" do | |
url = "https://foo.com/image.ext" | |
video.thumbnail_url = url | |
video.save | |
video.thumbnail_url.should eq url | |
end | |
end | |
context "when panda_id is nil" do | |
it "should return nil" do | |
video.stub(:panda_id).with(nil) | |
video.stub(:panda_video).and_return nil | |
video.thumbnail_url.should be_nil | |
end | |
end | |
context "when panda can find video" do | |
it "should return encoding object with screenshots" do | |
video.stub(:panda_video).and_return double(encodings: [double(panda_encoding_object(100, :success))]) | |
video.get_encoding.stub(:screenshots).and_return [ panda_screenshot_url ] | |
video.thumbnail_url | |
video.thumbnail_url.should eq secure_panda_screenshot_url | |
end | |
end | |
end | |
describe "#mp4_url" do | |
context "when encoding is available from panda" do | |
it "should set mp4 url to encoding from panda object" do | |
video.stub(:panda_video).and_return double(encodings: [double(panda_encoding_object(100, :success))]) | |
video.mp4_url | |
video.mp4_video_url.should eq secure_panda_encoding_url | |
end | |
end | |
context "when encoding is not available from panda" do | |
it "should return nil" do | |
video.stub(:panda_id).with(nil) | |
video.stub(:panda_video).and_return nil | |
video.mp4_url.should be_nil | |
end | |
end | |
context "when encoding is available from panda but progress is less than 100" do | |
it "should return nil" do | |
video.stub(:panda_video).and_return double(encodings: [double(panda_encoding_object(50, :success))]) | |
video.mp4_video_url.should be_nil | |
end | |
end | |
context "when encoding is available from panda but status has failed" do | |
it "should return nil" do | |
video.stub(:panda_video).and_return double(encodings: [double(panda_encoding_object(100, :fail))]) | |
video.mp4_video_url.should be_nil | |
end | |
end | |
end | |
describe "#get_encoding" do | |
context "when encoding is unavailable from panda" do | |
it "should return nil" do | |
video.stub(:panda_video).and_return nil | |
video.get_encoding.should be_nil | |
end | |
end | |
context "when encoding is available from panda" do | |
it "should return panda object" do | |
video.stub(:panda_video).and_return double(encodings: [double(panda_encoding_object(100, :success))]) | |
video.get_encoding.should eq video.panda_video.encodings.first | |
end | |
end | |
end | |
end | |
end | |
def panda_encoding_object progress, status | |
{ url: panda_encoding_url, encoding_progress: progress, status: status.to_s } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment