2014-11-04 20:55:12 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
|
|
require 'carrierwave/test/matchers'
|
|
|
|
|
|
|
|
|
|
describe JamTrack do
|
|
|
|
|
include CarrierWave::Test::Matchers
|
|
|
|
|
include UsesTempFiles
|
|
|
|
|
|
2015-01-07 22:16:57 +00:00
|
|
|
let(:user) {FactoryGirl.create(:user)}
|
2014-11-04 20:55:12 +00:00
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
2015-01-07 22:16:57 +00:00
|
|
|
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
|
|
|
|
|
|
2014-11-04 20:55:12 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
|
|
describe "upload/download" do
|
2015-03-11 03:10:22 +00:00
|
|
|
PREVIEW_NAME = 'blah.ogg'
|
2014-11-04 20:55:12 +00:00
|
|
|
|
2015-03-11 03:10:22 +00:00
|
|
|
in_directory_with_file(PREVIEW_NAME)
|
2014-11-04 20:55:12 +00:00
|
|
|
|
|
|
|
|
before(:all) do
|
|
|
|
|
original_storage = JamTrackUploader.storage = :fog
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
after(:all) do
|
|
|
|
|
JamTrackUploader.storage = @original_storage
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
before(:each) do
|
|
|
|
|
content_for_file('abc')
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "uploads to s3 with correct name, and then downloads via signed URL" do
|
|
|
|
|
jam_track = FactoryGirl.create(:jam_track)
|
2015-03-11 03:10:22 +00:00
|
|
|
uploader = JamTrackUploader.new(jam_track, :preview_url)
|
|
|
|
|
uploader.store!(File.open(PREVIEW_NAME)) # uploads file
|
2014-11-04 20:55:12 +00:00
|
|
|
jam_track.save!
|
|
|
|
|
|
|
|
|
|
# verify that the uploader stores the correct path
|
2015-03-11 03:10:22 +00:00
|
|
|
jam_track[:preview_url].should == jam_track.preview_filename
|
2014-11-04 20:55:12 +00:00
|
|
|
|
|
|
|
|
# verify it's on S3
|
|
|
|
|
s3 = S3Manager.new(APP_CONFIG.aws_bucket, APP_CONFIG.aws_access_key_id, APP_CONFIG.aws_secret_access_key)
|
2015-03-11 03:10:22 +00:00
|
|
|
s3.exists?(jam_track[:preview_url]).should be_true
|
|
|
|
|
s3.length(jam_track[:preview_url]).should == 'abc'.length
|
2014-11-04 20:55:12 +00:00
|
|
|
|
|
|
|
|
# download it via signed URL, and check contents
|
|
|
|
|
url = jam_track.sign_url
|
|
|
|
|
downloaded_contents = open(url).read
|
|
|
|
|
downloaded_contents.should == 'abc'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|