diff --git a/ruby/lib/jam_ruby/models/jam_track_right.rb b/ruby/lib/jam_ruby/models/jam_track_right.rb index f99833f08..f7f1f7ddf 100644 --- a/ruby/lib/jam_ruby/models/jam_track_right.rb +++ b/ruby/lib/jam_ruby/models/jam_track_right.rb @@ -102,7 +102,7 @@ module JamRuby def enqueue(bitrate=48) begin JamTrackRight.where(:id => self.id).update_all(:signing_queued_at => Time.now, :signing_started_at => nil, :last_signed_at => nil) - Resque.enqueue(JamTracksBuilder, self.id, bitrate: bitrate) + Resque.enqueue(JamTracksBuilder, self.id, bitrate) true rescue Exception => e puts "e: #{e}" diff --git a/ruby/spec/files/off.ogg b/ruby/spec/files/off.ogg new file mode 100644 index 000000000..743d6e3aa Binary files /dev/null and b/ruby/spec/files/off.ogg differ diff --git a/web/spec/controllers/api_jam_tracks_controller_spec.rb b/web/spec/controllers/api_jam_tracks_controller_spec.rb index b9db1eefd..210aa39f6 100644 --- a/web/spec/controllers/api_jam_tracks_controller_spec.rb +++ b/web/spec/controllers/api_jam_tracks_controller_spec.rb @@ -6,6 +6,7 @@ describe ApiJamTracksController do before(:all) do @original_storage = JamTrackTrackUploader.storage = :fog @original_storage_right = JamTrackRightUploader.storage = :fog + @s3 = S3Manager.new(APP_CONFIG.aws_bucket, APP_CONFIG.aws_access_key_id, APP_CONFIG.aws_secret_access_key) end after(:all) do @@ -76,7 +77,7 @@ describe ApiJamTracksController do it "finds a download" do #get "/download/#{right.id}/" right = JamTrackRight.create(:user=>@user, :jam_track=>@jam_track) - get :download, { :format => 'json', :id => @jam_track.id } + get :download, { :format=>'json', :id=>@jam_track.id } response.should be_success response.status.should == 202 @@ -115,43 +116,81 @@ describe ApiJamTracksController do @jam_track = FactoryGirl.create(:jam_track) #jam_track_track.jam_track jam_track_track = @jam_track.jam_track_tracks.first + # 48 kHz: uploader = JamTrackTrackUploader.new(jam_track_track, :url_48) uploader.store!(File.open(@ogg_path, 'rb')) + + # 44 kHz: + uploader = JamTrackTrackUploader.new(jam_track_track, :url_44) + uploader.store!(File.open(File.join('spec', 'files', 'off.ogg'), 'rb')) + #jam_track_track.url.store!(File.open(ogg_path, "rb")) jam_track_track.save! jam_track_track.reload ResqueSpec.reset! end - it "download depends on rights" do - s3 = S3Manager.new(APP_CONFIG.aws_bucket, APP_CONFIG.aws_access_key_id, APP_CONFIG.aws_secret_access_key) - get :download, :id => @jam_track.id + it "download depends on rights" do + get :download, :id=>@jam_track.id response.status.should == 403 right = JamTrackRight.create(:user=>@user, :jam_track=>@jam_track) - get :download, :id => @jam_track.id + get :download, :id=>@jam_track.id response.status.should == 202 right.download_count.should eq(0) right.private_key.should be_nil - JamTracksBuilder.should have_queued(right.id).in(:jam_tracks_builder) - qname = "#{ResqueSpec.queue_name(JamRuby::JamTracksBuilder)}" + #puts "ResqueSpec.peek(qname)#{ResqueSpec.peek(qname)}" + JamTracksBuilder.should have_queued(right.id,nil).in(:jam_tracks_builder) + expect(ResqueSpec.peek(qname).present?).to eq(true) ResqueSpec.perform_next(qname) - JamTracksBuilder.should_not have_queued(right.id).in(:jam_tracks_builder) + JamTracksBuilder.should_not have_queued(right.id,nil).in(:jam_tracks_builder) right.reload right.private_key.should_not be_nil right.download_count.should eq(0) - get :download, :id => @jam_track.id + get :download, :id=>@jam_track.id response.status.should == 302 response.location.should =~ /.*#{Regexp.escape(right.filename)}.*/ right.reload right.download_count.should eq(1) - notifications = Notification.where(:jam_track_right_id => right.id) + notifications = Notification.where(:jam_track_right_id=>right.id) + notifications.count.should == 1 + end + + it "supports multiple bitrates" do + get :download, :id=>@jam_track.id, :bitrate=>44 + response.status.should == 403 + + right = JamTrackRight.create(:user=>@user, :jam_track=>@jam_track) + get :download, :id=>@jam_track.id, :bitrate=>44 + response.status.should == 202 + right.download_count.should eq(0) + right.private_key.should be_nil + + qname = "#{ResqueSpec.queue_name(JamRuby::JamTracksBuilder)}" + #puts "ResqueSpec.peek(qname)#{ResqueSpec.peek(qname)}" + JamTracksBuilder.should have_queued(right.id,"44").in(:jam_tracks_builder) + + expect(ResqueSpec.peek(qname).present?).to eq(true) + ResqueSpec.perform_next(qname) + + JamTracksBuilder.should_not have_queued(right.id,"44").in(:jam_tracks_builder) + right.reload + right.private_key.should_not be_nil + right.download_count.should eq(0) + + get :download, :id=>@jam_track.id, :bitrate=>44 + response.status.should == 302 + response.location.should =~ /.*#{Regexp.escape(right.filename)}.*/ + right.reload + right.download_count.should eq(1) + + notifications = Notification.where(:jam_track_right_id=>right.id) notifications.count.should == 1 end end @@ -213,7 +252,7 @@ describe ApiJamTracksController do it "success" do right = FactoryGirl.create(:jam_track_right, user: @user, signed: false) right.signing_queued_at.should be_nil - post :enqueue, {:format => 'json', :id => right.jam_track.id} + post :enqueue, {:format=>'json', :id=>right.jam_track.id} response.should be_success right.reload @@ -225,7 +264,7 @@ describe ApiJamTracksController do it "success" do right = FactoryGirl.create(:jam_track_right, user: @user) - get :show_jam_track_right, {:id => right.jam_track.id} + get :show_jam_track_right, {:id=>right.jam_track.id} response.should be_success json = JSON.parse(response.body) json['signing_state'].should eq('QUIET') diff --git a/web/spec/files/off.ogg b/web/spec/files/off.ogg new file mode 100644 index 000000000..743d6e3aa Binary files /dev/null and b/web/spec/files/off.ogg differ