* VRFS-1090 all_discarded add to db schema

This commit is contained in:
Seth Call 2014-02-08 03:05:16 +00:00
parent 64de2bc4cb
commit fa7f83a371
8 changed files with 26 additions and 9 deletions

View File

@ -102,3 +102,5 @@ audiomixer_mp3.sql
share_token_2.sql
large_photo_url.sql
add_secret_to_user_authorization.sql
track_connection_id_not_null.sql
recordings_all_discarded.sql

View File

@ -0,0 +1 @@
ALTER TABLE recordings ADD COLUMN all_discarded boolean NOT NULL DEFAULT false;

View File

@ -0,0 +1 @@
ALTER TABLE tracks ALTER COLUMN connection_id SET NOT NULL;

View File

@ -10,7 +10,7 @@ module JamRuby
belongs_to :user, :class_name => "JamRuby::User"
belongs_to :music_session, :class_name => "JamRuby::MusicSession"
has_many :tracks, :class_name => "JamRuby::Track", :inverse_of => :connection
has_many :tracks, :class_name => "JamRuby::Track", :inverse_of => :connection, :foreign_key => 'connection_id', :dependent => :delete_all
validates :as_musician, :inclusion => {:in => [true, false]}

View File

@ -158,6 +158,13 @@ module JamRuby
# the user votes to discard their tracks for this recording
def discard(user)
recorded_tracks_for_user(user).update_all(:discard => true)
]# check if all recorded_tracks for this recording are discarded
if recorded_tracks.where('discard = false or discard is NULL').length == 0
self.all_discarded = true
self.save(:validate => false)
end
end
# Find out if all the tracks for this recording have been uploaded
@ -248,6 +255,7 @@ module JamRuby
.where('recorded_tracks.id > ?', since)
.where("upload_failures <= #{RecordedTrack::MAX_UPLOAD_FAILURES}")
.where("duration IS NOT NULL")
.where('all_discarded = false')
.order('recorded_tracks.id')
.limit(limit).each do |recorded_track|
uploads.push({

View File

@ -11,10 +11,11 @@ module JamRuby
SOUND = %w(mono stereo)
belongs_to :connection, :class_name => "JamRuby::Connection", :inverse_of => :tracks
belongs_to :connection, :class_name => "JamRuby::Connection", :inverse_of => :tracks, :foreign_key => 'connection_id'
belongs_to :instrument, :class_name => "JamRuby::Instrument", :inverse_of => :tracks
validates :sound, :inclusion => {:in => SOUND}
validates :connection, presence: true
def user
self.connection.user

View File

@ -251,6 +251,7 @@ describe Recording do
end
it "no one votes" do
@recording.all_discarded.should be_false
@recording2 = Recording.start(@music_session, @user)
@recording2.errors.any?.should be_true
@recording2.errors[:music_session].should == [ValidationMessages::PREVIOUS_RECORDING_STILL_BEING_FINALIZED]
@ -258,6 +259,7 @@ describe Recording do
it "only one discards" do
@recording.discard(@user)
@recording.all_discarded.should be_false
@recording2 = Recording.start(@music_session, @user)
@recording2.errors.any?.should be_true
@recording2.errors[:music_session].should == [ValidationMessages::PREVIOUS_RECORDING_STILL_BEING_FINALIZED]
@ -266,12 +268,14 @@ describe Recording do
it "everyone discards" do
@recording.discard(@user)
@recording.discard(@user2)
@recording.all_discarded.should be_true
@recording2 = Recording.start(@music_session, @user)
@recording2.errors.any?.should be_false
end
it "one discards, the other leaves the session" do
@recording.discard(@user)
@recording.all_discarded.should be_false
@connection2.delete
@recording2 = Recording.start(@music_session, @user2)
@recording2.errors.any?.should be_false

View File

@ -1,16 +1,17 @@
require 'spec_helper'
=begin
describe Track do
let (:connection) { FactoryGirl.create(:connection) }
let (:user) {FactoryGirl.create(:user) }
let (:music_session) { FactoryGirl.create(:music_session, :creator => user)}
let (:connection) { FactoryGirl.create(:connection, :music_session => music_session) }
let (:track) { FactoryGirl.create(:track, :connection => connection)}
let (:track2) { FactoryGirl.create(:track, :connection => connection)}
let (:msuh) {FactoryGirl.create(:music_session_user_history, :history => music_session.music_session_history, :user => user, :client_id => connection.client_id) }
let (:track_hash) { {:client_track_id => 'client_guid', :sound => 'stereo', :instrument_id => 'drums'} }
before(:each) do
msuh.touch
end
describe "sync" do
@ -93,4 +94,3 @@ describe Track do
end
end
end
=end