86 lines
2.5 KiB
Ruby
Executable File
86 lines
2.5 KiB
Ruby
Executable File
require 'spec_helper'
|
|
|
|
describe Mix 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)
|
|
@music_session = FactoryGirl.create(:music_session, :creator => @user, :musician_access => true)
|
|
@music_session.connections << @connection
|
|
@music_session.save
|
|
@recording = Recording.start(@music_session, @user)
|
|
@recording.stop
|
|
@recording.claim(@user, "name", "description", Genre.first, true, true)
|
|
@mix = Mix.schedule(@recording, "{}")
|
|
end
|
|
|
|
it "should create a mix for a user's recording properly" do
|
|
@mix.recording_id.should == @recording.id
|
|
@mix.manifest.should == "{}"
|
|
@mix.mix_server.should be_nil
|
|
@mix.started_at.should be_nil
|
|
@mix.completed_at.should be_nil
|
|
end
|
|
|
|
it "should fail to create a mix if the userid doesn't own the recording" do
|
|
@user2 = FactoryGirl.create(:user)
|
|
expect { Mix.schedule(@recording) }.to raise_error
|
|
end
|
|
|
|
it "should fail if the recording doesn't exist" do
|
|
expect { @mix2 = Mix.schedule(Recording.find('lskdjflsd')) }.to raise_error
|
|
end
|
|
|
|
it "should return a mix when the cron asks for it" do
|
|
this_mix = Mix.next("server")
|
|
this_mix.id.should == @mix.id
|
|
@mix.reload
|
|
@mix.started_at.should_not be_nil
|
|
@mix.mix_server.should == "server"
|
|
@mix.completed_at.should be_nil
|
|
end
|
|
|
|
it "should record when a mix has finished" do
|
|
Mix.find(@mix.id).finish(10000, "md5hash")
|
|
@mix.reload
|
|
@mix.completed_at.should_not be_nil
|
|
@mix.length.should == 10000
|
|
@mix.md5.should == "md5hash"
|
|
end
|
|
|
|
it "should re-run a mix if it was started a long time ago" do
|
|
this_mix = Mix.next("server")
|
|
@mix.reload
|
|
@mix.started_at -= 1000000
|
|
@mix.save
|
|
this_mix = Mix.next("server")
|
|
this_mix.id.should == @mix.id
|
|
end
|
|
|
|
it "signs url" do
|
|
stub_const("APP_CONFIG", app_config)
|
|
@mix.sign_url.should_not be_nil
|
|
end
|
|
|
|
it "mixes are restricted by user" do
|
|
|
|
@mix.finish(1, "abc")
|
|
@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"
|
|
recordings[0][:id].should == @mix.id
|
|
|
|
recordings = Recording.list_downloads(@user2)["downloads"]
|
|
recordings.length.should == 0
|
|
end
|
|
|
|
end
|
|
|
|
|