122 lines
3.3 KiB
Ruby
122 lines
3.3 KiB
Ruby
require 'spec_helper'
|
|
|
|
require 'carrierwave/test/matchers'
|
|
|
|
describe JamTrack do
|
|
include CarrierWave::Test::Matchers
|
|
include UsesTempFiles
|
|
|
|
let(:user) {FactoryGirl.create(:user)}
|
|
|
|
it "created" do
|
|
jam_track = FactoryGirl.create(:jam_track)
|
|
jam_track.licensor.should_not be_nil
|
|
jam_track.licensor.jam_tracks.should == [jam_track]
|
|
end
|
|
|
|
describe "index" do
|
|
it "empty query" do
|
|
query, pager = JamTrack.index({}, user)
|
|
query.size.should == 0
|
|
end
|
|
|
|
it "sorts by name" do
|
|
jam_track1 = FactoryGirl.create(:jam_track_with_tracks, name: 'a')
|
|
jam_track2 = FactoryGirl.create(:jam_track_with_tracks, name: 'b')
|
|
|
|
query, pager = JamTrack.index({}, user)
|
|
query.size.should == 2
|
|
|
|
query[0].should eq(jam_track1)
|
|
query[1].should eq(jam_track2)
|
|
|
|
# flip order by mucking with name
|
|
jam_track1.name = 'c'
|
|
jam_track1.save!
|
|
|
|
query, pager = JamTrack.index({}, user)
|
|
query[0].should eq(jam_track2)
|
|
query[1].should eq(jam_track1)
|
|
end
|
|
|
|
it "supports showing purchased only" do
|
|
jam_track1 = FactoryGirl.create(:jam_track_with_tracks, name: 'a')
|
|
|
|
# no results yet
|
|
query, pager = JamTrack.index({show_purchased_only:true}, user)
|
|
query.size.should == 0
|
|
|
|
# but after the user buys it, it is returned
|
|
FactoryGirl.create(:jam_track_right, jam_track: jam_track1, user: user)
|
|
query, pager = JamTrack.index({show_purchased_only:true}, user)
|
|
query.size.should == 1
|
|
query[0].should eq(jam_track1)
|
|
end
|
|
end
|
|
|
|
describe "validations" do
|
|
|
|
describe "price" do
|
|
|
|
it "0.99" do
|
|
FactoryGirl.build(:jam_track, price: 0.99).valid?.should be_true
|
|
end
|
|
|
|
it "1" do
|
|
FactoryGirl.build(:jam_track, price: 1).valid?.should be_true
|
|
end
|
|
|
|
it "100" do
|
|
FactoryGirl.build(:jam_track, price: 100).valid?.should be_true
|
|
end
|
|
|
|
it "100.1" do
|
|
FactoryGirl.build(:jam_track, price: 100.1).valid?.should be_true
|
|
end
|
|
|
|
it "100.12" do
|
|
FactoryGirl.build(:jam_track, price: 100.12).valid?.should be_true
|
|
end
|
|
|
|
it "100.123" do
|
|
jam_track = FactoryGirl.build(:jam_track, price: 100.123)
|
|
jam_track.valid?.should be_false
|
|
jam_track.errors[:price].should == ['is invalid']
|
|
end
|
|
end
|
|
|
|
describe "reproduction_royalty_amount" do
|
|
it "0.99" do
|
|
FactoryGirl.build(:jam_track, reproduction_royalty_amount: 0.99).valid?.should be_true
|
|
end
|
|
|
|
it "1" do
|
|
FactoryGirl.build(:jam_track, reproduction_royalty_amount: 1).valid?.should be_true
|
|
end
|
|
|
|
it "100" do
|
|
FactoryGirl.build(:jam_track, reproduction_royalty_amount: 100).valid?.should be_true
|
|
end
|
|
|
|
it "100.1" do
|
|
FactoryGirl.build(:jam_track, reproduction_royalty_amount: 100.1).valid?.should be_true
|
|
end
|
|
|
|
it "100.12" do
|
|
FactoryGirl.build(:jam_track, reproduction_royalty_amount: 100.12).valid?.should be_true
|
|
end
|
|
|
|
it "100.123" do
|
|
FactoryGirl.build(:jam_track, reproduction_royalty_amount: 100.123).valid?.should be_true
|
|
end
|
|
|
|
it "100.1234" do
|
|
jam_track = FactoryGirl.build(:jam_track, reproduction_royalty_amount: 100.1234)
|
|
jam_track.valid?.should be_false
|
|
jam_track.errors[:reproduction_royalty_amount].should == ['is invalid']
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|