* Add Streamer class * Use FactoryGirl for factories * Add sha256 field to tracks * Add mime_type field to tracks
60 lines
1.4 KiB
Ruby
60 lines
1.4 KiB
Ruby
require 'spec_helper'
|
|
|
|
describe Track do
|
|
subject { track }
|
|
let(:track) { FactoryGirl.build(:track) }
|
|
|
|
context 'with valid attributes' do
|
|
it { should be_valid }
|
|
end
|
|
|
|
context 'when name empty' do
|
|
before { track.name = '' }
|
|
it { should_not be_valid }
|
|
end
|
|
|
|
context 'when mime_type empty' do
|
|
before { track.mime_type = '' }
|
|
it { should_not be_valid }
|
|
end
|
|
|
|
context 'when sha256 empty' do
|
|
before { track.sha256 = '' }
|
|
it { should_not be_valid }
|
|
end
|
|
|
|
describe '#filepath' do
|
|
it 'returns the path to the track file' do
|
|
track.filepath.should == "#{Rails.root}/data/tracks/#{track.sha256}"
|
|
end
|
|
end
|
|
|
|
describe '#save_with_file' do
|
|
let(:file) { File.new("#{Rails.root}/spec/fixtures/test.mp3") }
|
|
|
|
it 'calls save' do
|
|
Track.any_instance.should_receive(:save!)
|
|
track.save_with_file(file, 'audio/ogg')
|
|
end
|
|
|
|
it 'saves the file content' do
|
|
track.save_with_file(file, 'audio/ogg')
|
|
File.read(track.filepath).should == File.read(file.path)
|
|
end
|
|
|
|
it 'saves the file SHA256 digest' do
|
|
track.save_with_file(file, 'audio/ogg')
|
|
track.sha256.should == Digest::SHA256.file(file.path).hexdigest
|
|
end
|
|
|
|
it 'saves the file mime type' do
|
|
track.save_with_file(file, 'audio/mpeg')
|
|
track.mime_type.should == 'audio/mpeg'
|
|
end
|
|
|
|
after do
|
|
`rm -f #{Rails.root}/data/tracks/*`
|
|
end
|
|
end
|
|
end
|