Implement track/stream

* Add Streamer class
* Use FactoryGirl for factories
* Add sha256 field to tracks
* Add mime_type field to tracks
This commit is contained in:
Thibault Jouan
2011-07-23 16:30:51 +00:00
parent 47fa969617
commit 2f6a447416
18 changed files with 166 additions and 51 deletions

View File

@@ -9,30 +9,51 @@ describe Track do
end
context 'when name empty' do
before do
track.name = ''
end
before { track.name = '' }
it { should_not be_valid }
end
describe '#uploaded_file=' do
let(:track) { Track.new :name => 'Mega song' }
context 'when mime_type empty' do
before { track.mime_type = '' }
it { should_not be_valid }
end
it 'saves an uploaded file' do
filepath = "#{Rails.root}/spec/fixtures/test.mp3"
file = mock(Rack::Test::UploadedFile)
file.stub(
:tempfile => File.new(filepath),
:content_type => 'audio/mpeg'
)
track.uploaded_file = file
track.save
File.read("#{Rails.root}/data/tracks/#{track.id.to_s}").should == File.read(filepath)
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 -rf #{Rails.root}/data/tracks/*`
`rm -f #{Rails.root}/data/tracks/*`
end
end
end