VRFS-2023 - Migration, models and spec for recorded_video, a video analog to recorded_track.

This commit is contained in:
Steven Miers 2014-10-03 14:12:09 -05:00
parent 5135fe7faf
commit 66feb39de8
10 changed files with 70 additions and 3 deletions

View File

@ -216,3 +216,4 @@ fix_find_session_sorting_2216c.sql
entabulate_current_network_scores.sql
discard_scores_changed.sql
video_sources.sql
recorded_videos.sql

17
db/up/recorded_videos.sql Normal file
View File

@ -0,0 +1,17 @@
CREATE TABLE recorded_videos (
id BIGINT PRIMARY KEY,
user_id VARCHAR(64) REFERENCES users(id) ON DELETE CASCADE,
fully_uploaded BOOLEAN NOT NULL DEFAULT FALSE,
recording_id VARCHAR(64) NOT NULL,
length BIGINT,
client_video_source_id VARCHAR(64) NOT NULL,
url VARCHAR(1024),
file_offset BIGINT,
upload_failures INTEGER NOT NULL DEFAULT 0,
discard BOOLEAN,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);
ALTER TABLE recorded_videos ALTER COLUMN id SET DEFAULT nextval('tracks_next_tracker_seq');

View File

@ -174,6 +174,7 @@ require "jam_ruby/models/generic_state"
require "jam_ruby/models/score_history"
require "jam_ruby/models/jam_company"
require "jam_ruby/models/video_source"
require "jam_ruby/models/recorded_video"
include Jampb

View File

@ -0,0 +1,18 @@
module JamRuby
# Video analog to JamRuby::RecordedTrack
class RecordedVideo < ActiveRecord::Base
belongs_to :user, :class_name => "JamRuby::User", :inverse_of => :recorded_videos
belongs_to :recording, :class_name => "JamRuby::Recording", :inverse_of => :recorded_videos
validates :client_video_source_id, :presence => true
def self.create_from_video_source(video_source, recording)
recorded_video_source = self.new
recorded_video_source.recording = recording
recorded_video_source.client_video_source_id = video_source.id
recorded_video_source.user = video_source.connection.user
recorded_video_source.save
recorded_video_source
end
end
end

View File

@ -9,6 +9,7 @@ module JamRuby
has_many :claimed_recordings, :class_name => "JamRuby::ClaimedRecording", :inverse_of => :recording, :foreign_key => 'recording_id', :dependent => :destroy
has_many :mixes, :class_name => "JamRuby::Mix", :inverse_of => :recording, :foreign_key => 'recording_id', :dependent => :destroy
has_many :recorded_tracks, :class_name => "JamRuby::RecordedTrack", :foreign_key => :recording_id, :dependent => :destroy
has_many :recorded_videos, :class_name => "JamRuby::RecordedVideo", :foreign_key => :recording_id, :dependent => :destroy
has_many :comments, :class_name => "JamRuby::RecordingComment", :foreign_key => "recording_id", :dependent => :destroy
has_many :likes, :class_name => "JamRuby::RecordingLiker", :foreign_key => "recording_id", :dependent => :destroy
has_many :plays, :class_name => "JamRuby::PlayablePlay", :as => :playable, :dependent => :destroy

View File

@ -103,6 +103,7 @@ module JamRuby
# saved tracks
has_many :recorded_tracks, :foreign_key => "user_id", :class_name => "JamRuby::RecordedTrack", :inverse_of => :user
has_many :recorded_videos, :foreign_key => "user_id", :class_name => "JamRuby::RecordedVideo", :inverse_of => :user
# invited users
has_many :invited_users, :foreign_key => "sender_id", :class_name => "JamRuby::InvitedUser"

View File

@ -1,5 +1,5 @@
# Video analog to JamRuby::Track
module JamRuby
# Video analog to JamRuby::Track
class VideoSource < ActiveRecord::Base
self.table_name = "video_sources"
self.primary_key = 'id'

View File

@ -248,6 +248,12 @@ FactoryGirl.define do
association :recording, factory: :recording
end
factory :recorded_video, :class => JamRuby::RecordedVideo do
sequence(:client_id) { |n| "client_id-#{n}"}
sequence(:track_id) { |n| "track_id-#{n}"}
sequence(:client_track_id) { |n| "client_track_id-#{n}"}
end
factory :instrument, :class => JamRuby::Instrument do
description { |n| "Instrument #{n}" }
end

View File

@ -0,0 +1,21 @@
require 'spec_helper'
require 'rest-client'
describe RecordedVideo do
include UsesTempFiles
let (:user) {FactoryGirl.create(:user)}
let (:connection) {FactoryGirl.create(:connection, :user => user)}
let (:music_session){FactoryGirl.create(:active_music_session, :creator => user, :musician_access => true)}
let (:recording) {FactoryGirl.create(:recording, :music_session => music_session, :owner => user)}
let (:video_source) {FactoryGirl.create(:video_source, :connection => connection)}
it "should create from a video source" do
recorded_video_source = RecordedVideo.create_from_video_source(video_source, recording)
recorded_video_source.should_not be_nil
recorded_video_source.user.id.should == video_source.connection.user.id
recorded_video_source.fully_uploaded.should == false
recorded_video_source.client_video_source_id.should == video_source.id
end
end

View File

@ -7,14 +7,15 @@ describe VideoSource do
let (:connection) { FactoryGirl.create(:connection, :user => user, :music_session => music_session) }
let (:msuh) {FactoryGirl.create(:music_session_user_history, :history => music_session.music_session, :user => user, :client_id => connection.client_id) }
before(:each) do
msuh.touch
end
describe "simple create" do
it "create a video source" do
track = FactoryGirl.create(:video_source, :connection => connection)
track.should_not be_nil
video_source = FactoryGirl.create(:video_source, :connection => connection)
video_source.should_not be_nil
end
end
end