Permalink
Browse files

Add TextTrackFile

Model, view, template, file type, factory, fixture and migration.
  • Loading branch information...
1 parent a7ee7fc commit 2569c38e0fb7daa538d7a9bdfb3c19f755b19189 @aviav aviav committed Sep 1, 2016
@@ -0,0 +1,9 @@
+module Pageflow
+ class TextTrackFile < ActiveRecord::Base
+ include HostedFile
+
+ def meta_data_attributes=(attributes)
+ self.attributes = attributes.symbolize_keys.slice(:label, :kind, :srclang)
+ end
+ end
+end
@@ -0,0 +1,31 @@
+class AddTextTrackFiles < ActiveRecord::Migration
+ def change
+ create_table :pageflow_text_track_files do |t|
+ t.belongs_to(:entry, index: true)
+ t.belongs_to(:uploader, index: true)
+
+ t.string(:state)
+ t.string(:rights)
+
+ t.string(:attachment_on_filesystem_file_name)
+ t.string(:attachment_on_filesystem_content_type)
+ t.integer(:attachment_on_filesystem_file_size, limit: 8)
+ t.datetime(:attachment_on_filesystem_updated_at)
+
+ t.string(:attachment_on_s3_file_name)
+ t.string(:attachment_on_s3_content_type)
+ t.integer(:attachment_on_s3_file_size, limit: 8)
+ t.datetime(:attachment_on_s3_updated_at)
+
+ t.timestamps
+
+ t.integer(:parent_file_id)
+ t.string(:parent_file_model_type)
+
+ t.text(:configuration)
+ end
+
+ add_index :pageflow_text_track_files, [:parent_file_id, :parent_file_model_type],
+ name: 'index_text_track_files_on_parent_id_and_parent_model_type'
+ end
+end
@@ -14,14 +14,21 @@ def self.video
FileType.new(model: 'Pageflow::VideoFile',
editor_partial: 'pageflow/editor/video_files/video_file',
collection_name: 'video_files',
- top_level_type: true)
+ top_level_type: true,
+ nested_file_types: [BuiltInFileType.text_track])
end
def self.audio
FileType.new(model: 'Pageflow::AudioFile',
editor_partial: 'pageflow/editor/audio_files/audio_file',
collection_name: 'audio_files',
- top_level_type: true)
+ top_level_type: true,
+ nested_file_types: [BuiltInFileType.text_track])
+ end
+
+ def self.text_track
+ FileType.new(model: 'Pageflow::TextTrackFile',
+ collection_name: 'text_track_files')
end
end
end
@@ -0,0 +1,23 @@
+module Pageflow
+ FactoryGirl.define do
+ factory :text_track_file, class: TextTrackFile do
+ entry
+ uploader { create(:user) }
+ parent_file { create(:video_file) }
+
+ attachment_on_s3 File.open(Engine.root.join('spec', 'fixtures', 'sample.vtt'))
+
+ trait :on_filesystem do
+ attachment_on_filesystem File.open(Engine.root.join('spec', 'fixtures', 'et.ogg'))
+ attachment_on_s3 nil
+ state 'not_uploaded_to_s3'
+ end
+
+ trait :uploading_to_s3_failed do
+ attachment_on_filesystem File.open(Engine.root.join('spec', 'fixtures', 'et.ogg'))
+ attachment_on_s3 nil
+ state 'uploading_to_s3_failed'
+ end
+ end
+ end
+end
@@ -0,0 +1,40 @@
+WEBVTT
+
+00:11.000 --> 00:13.000
+<v Leonato>I learn in this letter that Don Peter of Arragon comes this night to Messina.
+
+00:13.000 --> 00:16.000
+<v Messenger>He is very near by this: he was not three leagues off when I left him.
+
+00:16.000 --> 00:18.000
+<v Leonato>How many gentlemen have you lost in this action?
+
+00:18.000 --> 00:20.000
+<v Messenger>But few of any sort, and none of name.
+
+00:20.000 --> 00:22.000
+<v Leonato>A victory is twice itself when the achiever brings home full numbers. I find here that Don Peter hath bestowed much honour on a young Florentine called Claudio.
+
+00:22.000 --> 00:24.000
+<v Messenger>Much deserved on his part and equally remembered by Don Pedro: he hath borne himself beyond the promise of his age, doing, in the figure of a lamb, the feats of a lion: he hath indeed better bettered expectation than you must expect of me to tell you how.
+
+00:24.000 --> 00:26.000
+<v Leonato>He hath an uncle here in Messina will be very much glad of it.
+
+00:27.000 --> 00:30.000
+<v Messenger>I have already delivered him letters, and there appears much joy in him; even so much that joy could not show itself modest enough without a badge of bitterness.
+
+00:30.000 --> 00:31.500 align:right size:50%
+<v Leonato>Did he break out into tears?
+
+00:30.500 --> 00:32.500 align:left size:50%
+<v Messenger>In great measure.
+
+00:32.000 --> 00:35.500 align:right size:50%
+<v Leonato>A kind overflow of kindness: there are no faces truer than those that are so washed. How much better is it to weep at joy than to joy at weeping!
+
+00:32.500 --> 00:33.500 align:left size:50%
+<v Beatrice><i>You know I’m so excited my glasses are falling off here.</i>
+
+00:35.500 --> 00:38.000
+<v Messenger>Is't possible?
@@ -108,6 +108,7 @@ module Pageflow
expect(video_file_seed).to have_key('url')
expect(video_file_seed).to have_key('usage_id')
expect(video_file_seed).to have_key('width')
+ expect(video_file_seed).to have_key('text_track_file')
end
it 'seeds required data for an audio file' do
@@ -131,6 +132,32 @@ module Pageflow
expect(audio_file_seed).to have_key('state')
expect(audio_file_seed).to have_key('url')
expect(audio_file_seed).to have_key('usage_id')
+ expect(audio_file_seed).to have_key('nested_files')
+ end
+
+ it 'seeds required data for a nested text track file' do
+ revision = create(:revision, :published)
+ entry = create(:entry, published_revision: revision)
+ published_entry = PublishedEntry.new(entry)
+ audio_file = create(:audio_file)
+ create(:file_usage, revision: revision, file: audio_file)
+ create(:text_track_file, parent_file: audio_file, entry: audio_file.entry)
+
+ files_seed = JSON.parse(helper.files_json_seeds(published_entry))
+ text_track_file_seed = files_seed['audio_files']
+ .first['nested_files']['text_track_files'].first
+
+ expect(text_track_file_seed).to have_key('id')
+ expect(text_track_file_seed).to have_key('state')
+ expect(text_track_file_seed).to have_key('rights')
+ expect(text_track_file_seed).to have_key('usage_id')
+ expect(text_track_file_seed).to have_key('retryable')
+ expect(text_track_file_seed).to have_key('file_name')
+ expect(text_track_file_seed).to have_key('url')
+ expect(text_track_file_seed).to have_key('original_url')
+ expect(text_track_file_seed).to have_key('label')
+ expect(text_track_file_seed).to have_key('kind')
+ expect(text_track_file_seed).to have_key('srclang')
end
end
end

0 comments on commit 2569c38

Please sign in to comment.