Save track files in new Sound model:
* Consolidate migrations * Add Sound model. Each sound can belong to a track and contains informations about one sound file.
This commit is contained in:
25
spec/controllers/sounds_controller_spec.rb
Normal file
25
spec/controllers/sounds_controller_spec.rb
Normal file
@@ -0,0 +1,25 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe SoundsController do
|
||||
before do
|
||||
controller.current_user = Factory.create(:user)
|
||||
end
|
||||
|
||||
describe 'GET show' do
|
||||
let(:sound) { Factory.create(:sound) }
|
||||
|
||||
def do_show
|
||||
get :show, :id => sound.id
|
||||
end
|
||||
|
||||
it 'sends the sound file as the response body' do
|
||||
do_show
|
||||
response.body.should == File.read(sound.path)
|
||||
end
|
||||
|
||||
it 'sets the sound file mime-type as the response content-type' do
|
||||
do_show
|
||||
response.content_type.should == sound.mime_type
|
||||
end
|
||||
end
|
||||
end
|
@@ -13,20 +13,6 @@ describe TracksController do
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET download' do
|
||||
let(:track) { Factory.create(:track) }
|
||||
|
||||
it 'streams the requested track' do
|
||||
get :download, :id => track.id.to_s
|
||||
response.should be_success
|
||||
end
|
||||
|
||||
it 'returns the track mime-type as content-type' do
|
||||
get :download, :id => track.id.to_s
|
||||
response.content_type.should == track.mime_type
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET new' do
|
||||
it 'assigns a new track as @track' do
|
||||
get :new
|
||||
@@ -35,48 +21,46 @@ describe TracksController do
|
||||
end
|
||||
|
||||
describe 'POST create' do
|
||||
let(:track) { mock_model(Track).as_null_object }
|
||||
let(:file) {
|
||||
fixture_file_upload("#{Rails.root}/spec/fixtures/test.mp3", 'audio/mpeg')
|
||||
}
|
||||
before { Track.stub(:new).and_return(track) }
|
||||
let(:track) { mock_model(Track).as_null_object }
|
||||
let(:attributes) { Factory.attributes_for(:track).stringify_keys }
|
||||
|
||||
it 'creates a new track' do
|
||||
attributes = Factory.attributes_for(:track)
|
||||
Track.should_receive(:new).
|
||||
with({:name => attributes[:name]}).
|
||||
and_return(track)
|
||||
post :create, :track => {
|
||||
:name => attributes[:name],
|
||||
:file => file
|
||||
}
|
||||
before do
|
||||
Track.stub(:new).and_return(track)
|
||||
end
|
||||
|
||||
it 'saves the track with a file' do
|
||||
track.should_receive(:save_with_file).
|
||||
with(file, 'audio/mpeg')
|
||||
post :create, :track => { :file => file }
|
||||
def do_create
|
||||
post :create, :track => attributes
|
||||
end
|
||||
|
||||
it 'creates a new track' do
|
||||
Track.should_receive(:new).with(attributes)
|
||||
do_create
|
||||
end
|
||||
|
||||
it 'saves the track' do
|
||||
track.should_receive :save
|
||||
do_create
|
||||
end
|
||||
|
||||
context 'when the track saves successfully' do
|
||||
it 'redirects to the track page' do
|
||||
post :create, :track => { :file => file }
|
||||
do_create
|
||||
response.should redirect_to(track)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the track fails to save' do
|
||||
before do
|
||||
track.stub(:save_with_file).and_return(false)
|
||||
track.stub(:save).and_return(false)
|
||||
end
|
||||
|
||||
it 'assigns the track as @track' do
|
||||
post :create, :track => { :file => file }
|
||||
do_create
|
||||
assigns[:track].should == track
|
||||
end
|
||||
|
||||
it 'renders the new template' do
|
||||
post :create, :track => { :file => file }
|
||||
do_create
|
||||
response.should render_template('new')
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user