diff --git a/lib/jam_ruby/models/recording.rb b/lib/jam_ruby/models/recording.rb index e2a1f6b30..8c084a680 100644 --- a/lib/jam_ruby/models/recording.rb +++ b/lib/jam_ruby/models/recording.rb @@ -64,6 +64,16 @@ module JamRuby music_session.save end + + # FIXME: + # NEED TO SEND NOTIFICATION TO ALL USERS IN THE SESSION THAT RECORDING HAS STARTED HERE. + # I'LL STUB IT A BIT. NOTE THAT I REDO THE FIND HERE BECAUSE I DON'T WANT TO SEND THESE + # NOTIFICATIONS WHILE THE DB ROW IS LOCKED + music_session = MusicSession.find(music_session_id) + music_session.connections.each do |connection| + # connection.notify_recording_has_started + end + recording end @@ -82,6 +92,19 @@ module JamRuby music_session.save end end + + # Update the metadata for the recording + def update(description, genres) + self.description = description unless description.nil? + unless genres.nil? + self.genres = [] + genres.each do |genre_id| + g = Genre.find(genre_id) + self.genres << g + end + end + save + end def self.search(query, options = { :limit => 10 }) diff --git a/spec/jam_ruby/models/recording_spec.rb b/spec/jam_ruby/models/recording_spec.rb index 4ead8d49e..afcd1402b 100644 --- a/spec/jam_ruby/models/recording_spec.rb +++ b/spec/jam_ruby/models/recording_spec.rb @@ -54,6 +54,30 @@ describe Recording do expect { @recording.stop }.to raise_error end + it "should be able to start, stop then start a recording again for the same music session" do + @recording = Recording.start(@music_session.id, @user, "Description") + @recording.stop + @recording2 = Recording.start(@music_session.id, @user, "Description 2") + @music_session.recording.should == @recording2 + end + + it "should attach the recording to all users in a the music session when recording started" do + @user2 = FactoryGirl.create(:user) + @connection2 = FactoryGirl.create(:connection, :user => @user2) + @instrument2 = FactoryGirl.create(:instrument, :description => 'a great instrument') + @track2 = FactoryGirl.create(:track, :connection => @connection2, :instrument => @instrument2) + + @music_session.connections << @connection2 + + @recording = Recording.start(@music_session.id, @user, "Description") + @user.recordings.length.should == 1 + @user.recordings.first.should == @recording + + @user2.recordings.length.should == 1 + @user2.recordings.first.should == @recording + + end + end