diff --git a/db/manifest b/db/manifest index 93204fbd6..981182ab1 100755 --- a/db/manifest +++ b/db/manifest @@ -101,4 +101,6 @@ facebook_signup.sql audiomixer_mp3.sql share_token_2.sql large_photo_url.sql -add_secret_to_user_authorization.sql \ No newline at end of file +add_secret_to_user_authorization.sql +track_connection_id_not_null.sql +recordings_all_discarded.sql \ No newline at end of file diff --git a/db/up/recordings_all_discarded.sql b/db/up/recordings_all_discarded.sql new file mode 100644 index 000000000..b96d9383d --- /dev/null +++ b/db/up/recordings_all_discarded.sql @@ -0,0 +1 @@ +ALTER TABLE recordings ADD COLUMN all_discarded boolean NOT NULL DEFAULT false; \ No newline at end of file diff --git a/db/up/track_connection_id_not_null.sql b/db/up/track_connection_id_not_null.sql new file mode 100644 index 000000000..6f6f3fd95 --- /dev/null +++ b/db/up/track_connection_id_not_null.sql @@ -0,0 +1 @@ +ALTER TABLE tracks ALTER COLUMN connection_id SET NOT NULL; \ No newline at end of file diff --git a/ruby/lib/jam_ruby/models/connection.rb b/ruby/lib/jam_ruby/models/connection.rb index cbc4a9bc2..c1fbec61f 100644 --- a/ruby/lib/jam_ruby/models/connection.rb +++ b/ruby/lib/jam_ruby/models/connection.rb @@ -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]} diff --git a/ruby/lib/jam_ruby/models/recording.rb b/ruby/lib/jam_ruby/models/recording.rb index beba63625..8757ae0fb 100644 --- a/ruby/lib/jam_ruby/models/recording.rb +++ b/ruby/lib/jam_ruby/models/recording.rb @@ -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({ diff --git a/ruby/lib/jam_ruby/models/track.rb b/ruby/lib/jam_ruby/models/track.rb index d91f00f42..0a14457d7 100644 --- a/ruby/lib/jam_ruby/models/track.rb +++ b/ruby/lib/jam_ruby/models/track.rb @@ -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 diff --git a/ruby/spec/jam_ruby/models/recording_spec.rb b/ruby/spec/jam_ruby/models/recording_spec.rb index 19b9f8f8c..0cebe3880 100644 --- a/ruby/spec/jam_ruby/models/recording_spec.rb +++ b/ruby/spec/jam_ruby/models/recording_spec.rb @@ -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 diff --git a/ruby/spec/jam_ruby/models/track_spec.rb b/ruby/spec/jam_ruby/models/track_spec.rb index 1ce79df7f..b4281b1a5 100644 --- a/ruby/spec/jam_ruby/models/track_spec.rb +++ b/ruby/spec/jam_ruby/models/track_spec.rb @@ -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 @@ -92,5 +93,4 @@ describe Track do found.client_track_id.should == track.client_track_id end end -end -=end \ No newline at end of file +end \ No newline at end of file