more work

This commit is contained in:
Mike Slemmer 2013-01-29 21:46:40 -08:00
parent 60d5964ecb
commit 5d1af73685
6 changed files with 66 additions and 55 deletions

View File

@ -25,7 +25,6 @@ require "jam_ruby/models/user"
require "jam_ruby/models/user_authorization"
require "jam_ruby/models/join_request"
require "jam_ruby/models/band"
require "jam_ruby/models/band_recording"
require "jam_ruby/models/band_invitation"
require "jam_ruby/models/band_liker"
require "jam_ruby/models/band_follower"
@ -48,8 +47,7 @@ require "jam_ruby/models/user_following"
require "jam_ruby/models/user_favorite"
require "jam_ruby/models/search"
require "jam_ruby/models/recording"
require "jam_ruby/models/musician_recording"
require "jam_ruby/models/saved_track"
require "jam_ruby/models/recorded_track"
include Jampb

View File

@ -17,8 +17,8 @@ module JamRuby
def self.create_from_track(track, recording)
recorded_track = self.new
recorded_track.recording = recording
recorded_track.user_id = track.connection.user.id
recorded_track.instrument_id = track.instrument_id
recorded_track.user = track.connection.user
recorded_track.instrument = track.instrument
recorded_track.sound = track.sound
recorded_track.save
recorded_track

View File

@ -1,11 +1,11 @@
module JamRuby
class Recording < ActiveRecord::Base
self.primary_key = 'id'
has_and_belongs_to_many :users, :class_name => "JamRuby::User"
belongs_to :owner, :class_name => "JamRuby::User", :inverse_of => :owned_recording
belongs_to :band, :class_name => "JamRuby::Band", :inverse_of => :recording
belongs_to :owner, :class_name => "JamRuby::User", :inverse_of => :owned_recordings
belongs_to :band, :class_name => "JamRuby::Band", :inverse_of => :recordings
belongs_to :music_session, :class_name => "JamRuby::MusicSession", :inverse_of => :recording
has_many :recorded_tracks, :class_name => "JamRuby::RecordedTrack", :foreign_key => :recording_id
@ -24,7 +24,10 @@ module JamRuby
end
# Start recording a session.
def self.start(music_session_id, creator_id)
def self.start(music_session_id, owner, description)
recording = nil
# Use a transaction and lock to avoid races.
ActiveRecord::Base.transaction do
music_session = MusicSession.find(music_session_id, :lock => true)
@ -36,11 +39,11 @@ module JamRuby
if music_session.recording
raise PermissionError, "the session is already being recorded"
end
music_session.recording = true
recording = Recording.new
recording.description = description
recording.music_session = music_session
recording.owner = owner
music_session.connections.each do |connection|
recording.users << connection.user
@ -54,11 +57,14 @@ module JamRuby
end
# Note that I believe this can be nil.
recording.band_id = music_session.band_id
recording.band = music_session.band
recording.save
music_session.recording = recording
music_session.save
end
recording
end
# Stop recording a session
@ -72,7 +78,7 @@ module JamRuby
unless music_session.recording
raise PermissionError, "the session is not currently being recorded"
end
music_session.recording = false
music_session.recording = nil
music_session.save
end
end
@ -99,7 +105,7 @@ module JamRuby
def self.save(id, is_public, description, genres, updater_id, owner_id, is_band)
return nil
# Spec: https://jamkazam.atlassian.net/wiki/display/PS/Product+Specification+-+Studio
# This is seriously wrong. A recording needs to be created from inside a session. I'm not sure who owns
# the recording, but I do know that it's affiliated with the session and then should be able to get the band id
@ -113,6 +119,7 @@ module JamRuby
# recording completion is when you have the track -> saved_track (rename this to recorded_track) transition.
# * The metadata in general is filled in *after* the recording ends. This is important because it means the save method below
# is sort of jacked.
=begin
creator = User.find(updater_id)
if is_band
@ -175,6 +182,7 @@ module JamRuby
end
return recording
=end
end
private

View File

@ -63,9 +63,13 @@ FactoryGirl.define do
end
factory :saved_track, :class => JamRuby::SavedTrack do
factory :recorded_track, :class => JamRuby::RecordedTrack do
end
factory :instrument, :class => JamRuby::Instrument do
end
factory :recording, :class => JamRuby::Recording do
end
end

View File

@ -0,0 +1,41 @@
require 'spec_helper'
describe RecordedTrack do
before do
@user = FactoryGirl.create(:user)
@connection = FactoryGirl.create(:connection, :user => @user)
@instrument = FactoryGirl.create(:instrument, :description => 'a great instrument')
@track = FactoryGirl.create(:track, :connection => @connection, :instrument => @instrument)
@recording = FactoryGirl.create(:recording, :description => 'description', :owner => @user)
end
it "should copy from a regular track properly" do
@recorded_track = RecordedTrack.create_from_track(@track, @recording)
@recorded_track.user.id.should == @track.connection.user.id
@recorded_track.instrument.id.should == @track.instrument.id
@recorded_track.next_part_to_upload.should == 0
@recorded_track.fully_uploaded.should == false
end
it "should update the next part to upload properly" do
@recorded_track = RecordedTrack.create_from_track(@track, @recording)
@recorded_track.upload_part_complete(0)
@recorded_track.upload_part_complete(1)
@recorded_track.upload_part_complete(2)
@recorded_track.next_part_to_upload.should == 3
end
it "should error if the wrong part is uploaded" do
@recorded_track = RecordedTrack.create_from_track(@track, @recording)
@recorded_track.upload_part_complete(0)
@recorded_track.upload_part_complete(1)
expect { @recorded_track.upload_part_complete(3) }.to raise_error
@recorded_track.next_part_to_upload.should == 2
end
end

View File

@ -1,40 +0,0 @@
require 'spec_helper'
describe SavedTrack do
before do
@user = FactoryGirl.create(:user)
@connection = FactoryGirl.create(:connection, :user => @user)
@instrument = FactoryGirl.create(:instrument, :description => 'a great instrument')
@track = FactoryGirl.create(:track, :connection => @connection, :instrument => @instrument)
end
it "should copy from a regular track properly" do
@saved_track = SavedTrack.create_from_track(@track)
@saved_track.user.id.should == @track.connection.user.id
@saved_track.instrument.id.should == @track.instrument.id
@saved_track.next_part_to_upload.should == 0
@saved_track.fully_uploaded.should == false
end
it "should update the next part to upload properly" do
@saved_track = SavedTrack.create_from_track(@track)
@saved_track.upload_part_complete(0)
@saved_track.upload_part_complete(1)
@saved_track.upload_part_complete(2)
@saved_track.next_part_to_upload.should == 3
end
it "should error if the wrong part is uploaded" do
@saved_track = SavedTrack.create_from_track(@track)
@saved_track.upload_part_complete(0)
@saved_track.upload_part_complete(1)
expect { @saved_track.upload_part_complete(3) }.to raise_error
@saved_track.next_part_to_upload.should == 2
end
end