Add track/{new,create} with file upload for the track
This commit is contained in:
@@ -14,4 +14,58 @@ describe TracksController do
|
||||
assigns[:track].should == track
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET new' do
|
||||
it 'assigns a new track as @track' do
|
||||
get :new
|
||||
assigns[:track].should be_a_new(Track)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST create' do
|
||||
let(:track) { mock_model(Track).as_null_object }
|
||||
before { Track.stub(:new).and_return(track) }
|
||||
|
||||
it 'creates a new track' do
|
||||
Track.should_receive(:new).
|
||||
with(:name => 'Mega song').
|
||||
and_return(track)
|
||||
post :create, :track => valid_attributes
|
||||
end
|
||||
|
||||
it 'saves the track' do
|
||||
track.should_receive(:save)
|
||||
post :create, :track => {}
|
||||
end
|
||||
|
||||
it 'saves the file uploaded for the track' do
|
||||
file = mock(Rack::Test::UploadedFile)
|
||||
track.should_receive(:uploaded_file=).with(file)
|
||||
post :create, :track => { :file => file }
|
||||
end
|
||||
|
||||
context 'when the track saves successfully' do
|
||||
it 'redirects to the track page' do
|
||||
post :create, :track => valid_attributes
|
||||
response.should redirect_to(track)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the track fails to save' do
|
||||
before do
|
||||
track.stub(:save).and_return(false)
|
||||
end
|
||||
|
||||
it 'assigns the track as @track' do
|
||||
post :create, :track => {}
|
||||
assigns[:track].should == track
|
||||
end
|
||||
|
||||
it 'renders the new template' do
|
||||
post :create, :track => {}
|
||||
response.should render_template('new')
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user