Update zencoder_callback to fetch and save the thumbnail

Signed-off-by: marcheing's avatarHeitor Reis <marcheing@gmail.com>
parent f7459e31
......@@ -39,6 +39,7 @@ class ContentsController < ApplicationController
@encoded_content.duration = params[:outputs].first[:duration_in_ms]
@encoded_content.file_size = params[:outputs].first[:file_size_in_bytes]
@encoded_content.video = open(params[:outputs].first[:url])
@encoded_content.thumbnail = open(params[:outputs].first[:thumbnails].first[:images].first[:url])
@encoded_content.save
end
......
......@@ -86,16 +86,19 @@ RSpec.describe ContentsController, type: :controller do
describe 'POST #zencoder_callback' do
let!(:job_id) { '1' }
let!(:thumb_output) { [ images: [ url: 'http://test.com' ] ] }
let!(:output) { { id: '2', state: 'finished', width: '640', height: '320', duration_in_ms: '5000',
file_size_in_bytes: '1024', url: 'http://test.com' } }
file_size_in_bytes: '1024', url: 'http://test.com', thumbnails: thumb_output } }
let!(:outputs) { [output] }
let!(:video_file_mock) { instance_double('video_file') }
let!(:thumb_file_mock) { instance_double('thumb_file') }
context 'when the content is found' do
let(:encoded_video) { build(:encoded_video) }
before do
expect(EncodedContent).to receive(:find_by).with(job_id: job_id).and_return(encoded_video)
expect(subject).to receive(:open).with(outputs.first[:url]).and_return(video_file_mock)
expect(subject).to receive(:open).with(thumb_output.first[:images].first[:url]).and_return(thumb_file_mock)
expect(encoded_video).to receive(:save).and_return(true)
expect(encoded_video).to receive(:output_id=).with(output[:id])
expect(encoded_video).to receive(:state=).with(output[:state])
......@@ -104,6 +107,7 @@ RSpec.describe ContentsController, type: :controller do
expect(encoded_video).to receive(:duration=).with(output[:duration_in_ms])
expect(encoded_video).to receive(:file_size=).with(output[:file_size_in_bytes])
expect(encoded_video).to receive(:video=).with(video_file_mock)
expect(encoded_video).to receive(:thumbnail=).with(thumb_file_mock)
post :zencoder_callback, params: { job: { id: job_id}, outputs: outputs }
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment