From 66feb39de8ddbecc56ff6e0700eea6dd8da203de Mon Sep 17 00:00:00 2001 From: Steven Miers Date: Fri, 3 Oct 2014 14:12:09 -0500 Subject: [PATCH] VRFS-2023 - Migration, models and spec for recorded_video, a video analog to recorded_track. --- db/manifest | 1 + db/up/recorded_videos.sql | 17 +++++++++++++++ ruby/lib/jam_ruby.rb | 1 + ruby/lib/jam_ruby/models/recorded_video.rb | 18 ++++++++++++++++ ruby/lib/jam_ruby/models/recording.rb | 1 + ruby/lib/jam_ruby/models/user.rb | 1 + ruby/lib/jam_ruby/models/video_source.rb | 2 +- ruby/spec/factories.rb | 6 ++++++ .../jam_ruby/models/recorded_video_spec.rb | 21 +++++++++++++++++++ .../spec/jam_ruby/models/video_source_spec.rb | 5 +++-- 10 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 db/up/recorded_videos.sql create mode 100644 ruby/lib/jam_ruby/models/recorded_video.rb create mode 100644 ruby/spec/jam_ruby/models/recorded_video_spec.rb diff --git a/db/manifest b/db/manifest index 5d7ffd7b8..9407c2a3f 100755 --- a/db/manifest +++ b/db/manifest @@ -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 diff --git a/db/up/recorded_videos.sql b/db/up/recorded_videos.sql new file mode 100644 index 000000000..fc8e22814 --- /dev/null +++ b/db/up/recorded_videos.sql @@ -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'); diff --git a/ruby/lib/jam_ruby.rb b/ruby/lib/jam_ruby.rb index 5c98fa960..9daaa1e8d 100755 --- a/ruby/lib/jam_ruby.rb +++ b/ruby/lib/jam_ruby.rb @@ -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 diff --git a/ruby/lib/jam_ruby/models/recorded_video.rb b/ruby/lib/jam_ruby/models/recorded_video.rb new file mode 100644 index 000000000..63837c53a --- /dev/null +++ b/ruby/lib/jam_ruby/models/recorded_video.rb @@ -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 diff --git a/ruby/lib/jam_ruby/models/recording.rb b/ruby/lib/jam_ruby/models/recording.rb index edd2a4d1a..f1ff2677c 100644 --- a/ruby/lib/jam_ruby/models/recording.rb +++ b/ruby/lib/jam_ruby/models/recording.rb @@ -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 diff --git a/ruby/lib/jam_ruby/models/user.rb b/ruby/lib/jam_ruby/models/user.rb index 9cdc68a1c..672673b8f 100644 --- a/ruby/lib/jam_ruby/models/user.rb +++ b/ruby/lib/jam_ruby/models/user.rb @@ -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" diff --git a/ruby/lib/jam_ruby/models/video_source.rb b/ruby/lib/jam_ruby/models/video_source.rb index ebf095241..4517bf4bf 100644 --- a/ruby/lib/jam_ruby/models/video_source.rb +++ b/ruby/lib/jam_ruby/models/video_source.rb @@ -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' diff --git a/ruby/spec/factories.rb b/ruby/spec/factories.rb index 3f552fa0e..2d030b752 100644 --- a/ruby/spec/factories.rb +++ b/ruby/spec/factories.rb @@ -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 diff --git a/ruby/spec/jam_ruby/models/recorded_video_spec.rb b/ruby/spec/jam_ruby/models/recorded_video_spec.rb new file mode 100644 index 000000000..e8043f24a --- /dev/null +++ b/ruby/spec/jam_ruby/models/recorded_video_spec.rb @@ -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 + diff --git a/ruby/spec/jam_ruby/models/video_source_spec.rb b/ruby/spec/jam_ruby/models/video_source_spec.rb index 02b9c4e1c..166443c22 100644 --- a/ruby/spec/jam_ruby/models/video_source_spec.rb +++ b/ruby/spec/jam_ruby/models/video_source_spec.rb @@ -6,6 +6,7 @@ describe VideoSource do let (:music_session) { FactoryGirl.create(:active_music_session, :creator => user)} 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 @@ -13,8 +14,8 @@ describe VideoSource do 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 \ No newline at end of file