2015-09-04 18:11:42 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
|
|
describe JamTrackMixdown do
|
|
|
|
|
|
|
|
|
|
let(:user) {FactoryGirl.create(:user)}
|
|
|
|
|
let(:jam_track) {FactoryGirl.create(:jam_track)}
|
2015-09-12 02:11:19 +00:00
|
|
|
let(:settings) { {speed:5} }
|
2015-09-04 18:11:42 +00:00
|
|
|
|
|
|
|
|
it "can be created (factory girl)" do
|
|
|
|
|
mixdown = FactoryGirl.create(:jam_track_mixdown)
|
|
|
|
|
|
|
|
|
|
mixdown = JamTrackMixdown.find(mixdown.id)
|
2016-07-17 15:16:27 +00:00
|
|
|
mixdown.settings.should eq({"speed" => 5})
|
2015-09-04 18:11:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "can be created" do
|
2015-09-12 02:11:19 +00:00
|
|
|
mixdown = JamTrackMixdown.create('abc', 'description', user, jam_track, settings)
|
2015-09-04 18:11:42 +00:00
|
|
|
mixdown.errors.any?.should == false
|
|
|
|
|
end
|
2015-09-08 14:59:53 +00:00
|
|
|
|
|
|
|
|
it "index" do
|
|
|
|
|
query, start, count = JamTrackMixdown.index({id: jam_track}, user)
|
|
|
|
|
|
|
|
|
|
query.length.should eq(0)
|
|
|
|
|
start.should be_nil
|
|
|
|
|
count.should eq(0)
|
|
|
|
|
|
|
|
|
|
mixdown = FactoryGirl.create(:jam_track_mixdown, user: user, jam_track: jam_track)
|
|
|
|
|
|
|
|
|
|
query, start, count = JamTrackMixdown.index({id: jam_track}, user)
|
|
|
|
|
query[0].should eq(mixdown)
|
|
|
|
|
start.should be_nil
|
|
|
|
|
count.should eq(1)
|
|
|
|
|
end
|
|
|
|
|
|
2015-09-12 18:49:30 +00:00
|
|
|
describe "settings" do
|
|
|
|
|
it "validates empty settings" do
|
|
|
|
|
invalid = FactoryGirl.build(:jam_track_mixdown, settings: {}.to_json)
|
|
|
|
|
invalid.save
|
|
|
|
|
invalid.errors.any?.should be_true
|
2016-07-17 15:16:27 +00:00
|
|
|
invalid.errors["settings"].should eq(["can't be blank", "have nothing specified"])
|
2015-09-12 18:49:30 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "validates speed numeric" do
|
2015-11-08 21:31:38 +00:00
|
|
|
invalid = FactoryGirl.build(:jam_track_mixdown, settings: {"speed" => "5"}.to_json)
|
2015-09-12 18:49:30 +00:00
|
|
|
invalid.save
|
|
|
|
|
invalid.errors.any?.should be_true
|
|
|
|
|
invalid.errors["settings"].should eq(["has non-integer speed"])
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "validates pitch numeric" do
|
2015-11-08 21:31:38 +00:00
|
|
|
invalid = FactoryGirl.build(:jam_track_mixdown, settings: {"pitch" => "5"}.to_json)
|
2015-09-12 18:49:30 +00:00
|
|
|
invalid.save
|
|
|
|
|
invalid.errors.any?.should be_true
|
|
|
|
|
invalid.errors["settings"].should eq(["has non-integer pitch"])
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "validates speed not-float" do
|
2015-11-08 21:31:38 +00:00
|
|
|
invalid = FactoryGirl.build(:jam_track_mixdown, settings: {"speed" => 5.5}.to_json)
|
2015-09-12 18:49:30 +00:00
|
|
|
invalid.save
|
|
|
|
|
invalid.errors.any?.should be_true
|
|
|
|
|
invalid.errors["settings"].should eq(["has non-integer speed"])
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "validates pitch not-float" do
|
2015-11-08 21:31:38 +00:00
|
|
|
invalid = FactoryGirl.build(:jam_track_mixdown, settings: {"pitch" => 10.5}.to_json)
|
2015-09-12 18:49:30 +00:00
|
|
|
invalid.save
|
|
|
|
|
invalid.errors.any?.should be_true
|
|
|
|
|
invalid.errors["settings"].should eq(["has non-integer pitch"])
|
|
|
|
|
end
|
2015-09-12 02:11:19 +00:00
|
|
|
end
|
|
|
|
|
|
2015-09-12 18:49:30 +00:00
|
|
|
|
2015-09-04 18:11:42 +00:00
|
|
|
end
|
|
|
|
|
|