2013-04-12 22:36:05 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
|
|
describe Mix do
|
|
|
|
|
before do
|
2014-01-11 04:57:07 +00:00
|
|
|
stub_const("APP_CONFIG", app_config)
|
2013-04-12 22:36:05 +00:00
|
|
|
@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)
|
2014-05-06 13:34:38 +00:00
|
|
|
@music_session = FactoryGirl.create(:active_music_session, :creator => @user, :musician_access => true)
|
2014-04-29 03:38:30 +00:00
|
|
|
# @music_session.connections << @connection
|
2013-04-12 22:36:05 +00:00
|
|
|
@music_session.save
|
2014-06-09 20:43:16 +00:00
|
|
|
@connection.join_the_session(@music_session, true, nil, @user, 10)
|
2014-01-04 21:41:21 +00:00
|
|
|
@recording = Recording.start(@music_session, @user)
|
2014-01-05 01:25:05 +00:00
|
|
|
@recording.stop
|
2014-02-22 05:09:39 +00:00
|
|
|
@recording.claim(@user, "name", "description", Genre.first, true)
|
2014-01-08 03:28:15 +00:00
|
|
|
@recording.errors.any?.should be_false
|
2014-01-13 22:48:55 +00:00
|
|
|
@mix = Mix.schedule(@recording)
|
2014-01-11 04:57:07 +00:00
|
|
|
@mix.reload
|
2013-04-12 22:36:05 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "should create a mix for a user's recording properly" do
|
|
|
|
|
@mix.recording_id.should == @recording.id
|
|
|
|
|
@mix.mix_server.should be_nil
|
2014-01-13 22:48:55 +00:00
|
|
|
@mix.started_at.should_not be_nil
|
2013-04-12 22:36:05 +00:00
|
|
|
@mix.completed_at.should be_nil
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "should record when a mix has finished" do
|
2014-02-04 20:28:00 +00:00
|
|
|
Mix.find(@mix.id).finish(10000, "md5hash", 10000, "md5hash")
|
2013-04-12 22:36:05 +00:00
|
|
|
@mix.reload
|
|
|
|
|
@mix.completed_at.should_not be_nil
|
2014-02-04 20:28:00 +00:00
|
|
|
@mix.ogg_length.should == 10000
|
|
|
|
|
@mix.ogg_md5.should == "md5hash"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "create a good manifest" do
|
|
|
|
|
Mix.find(@mix.id).finish(10000, "md5hash", 10000, "md5hash")
|
|
|
|
|
@mix.reload
|
|
|
|
|
manifest = @mix.manifest
|
|
|
|
|
manifest["recording_id"].should == @recording.id
|
|
|
|
|
manifest["files"].length.should == 1
|
2013-04-12 22:36:05 +00:00
|
|
|
end
|
|
|
|
|
|
2013-12-17 19:44:21 +00:00
|
|
|
it "signs url" do
|
|
|
|
|
stub_const("APP_CONFIG", app_config)
|
|
|
|
|
@mix.sign_url.should_not be_nil
|
|
|
|
|
end
|
|
|
|
|
|
2013-12-30 18:34:15 +00:00
|
|
|
it "mixes are restricted by user" do
|
|
|
|
|
|
2014-02-04 20:28:00 +00:00
|
|
|
@mix.finish(1, "abc", 1, "def")
|
2013-12-30 18:34:15 +00:00
|
|
|
@mix.reload
|
|
|
|
|
@mix.errors.any?.should be_false
|
|
|
|
|
|
|
|
|
|
@user2 = FactoryGirl.create(:user)
|
|
|
|
|
|
|
|
|
|
recordings = Recording.list_downloads(@user)["downloads"]
|
|
|
|
|
recordings.length.should == 1
|
|
|
|
|
recordings[0][:type].should == "mix"
|
2014-01-13 13:23:09 +00:00
|
|
|
recordings[0][:id].should == @mix.id.to_s
|
2013-12-30 18:34:15 +00:00
|
|
|
|
|
|
|
|
recordings = Recording.list_downloads(@user2)["downloads"]
|
|
|
|
|
recordings.length.should == 0
|
|
|
|
|
end
|
|
|
|
|
|
2014-02-24 16:55:56 +00:00
|
|
|
|
|
|
|
|
describe "download count" do
|
|
|
|
|
it "will fail if too high" do
|
|
|
|
|
mix = FactoryGirl.create(:mix)
|
|
|
|
|
mix.current_user = mix.recording.owner
|
|
|
|
|
mix.update_download_count(APP_CONFIG.max_audio_downloads + 1)
|
|
|
|
|
mix.save
|
|
|
|
|
mix.errors[:download_count].should == ["must be less than or equal to 100"]
|
|
|
|
|
end
|
|
|
|
|
end
|
2013-04-12 22:36:05 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|