Replace mock expectations with classic specs in tracks controller
This commit is contained in:
parent
2d478352bd
commit
37735a354d
@ -20,43 +20,37 @@ describe TracksController do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'POST create' do
|
describe 'POST create new' do
|
||||||
let(:track) { mock_model(Track).as_null_object }
|
|
||||||
let(:attributes) { Factory.attributes_for(:track).stringify_keys }
|
|
||||||
|
|
||||||
before do
|
|
||||||
Track.stub(:new).and_return(track)
|
|
||||||
end
|
|
||||||
|
|
||||||
def do_create
|
def do_create
|
||||||
post :create, :track => attributes
|
post :create, :track => Factory.attributes_for(:track).merge({
|
||||||
|
:file => fixture_file_upload(
|
||||||
|
"#{Rails.root}/spec/fixtures/test.mp3",
|
||||||
|
'audio/mpeg'
|
||||||
|
)
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'whith valid params' do
|
||||||
it 'creates a new track' do
|
it 'creates a new track' do
|
||||||
Track.should_receive(:new).with(attributes)
|
expect {
|
||||||
do_create
|
do_create
|
||||||
|
}.to change(Track, :count).by(1)
|
||||||
end
|
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
|
it 'redirects to the track page' do
|
||||||
do_create
|
do_create
|
||||||
response.should redirect_to(track)
|
response.should redirect_to(Track.last)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when the track fails to save' do
|
context 'whith invalid params' do
|
||||||
before do
|
before do
|
||||||
track.stub(:save).and_return(false)
|
Track.any_instance.stub(:save).and_return(false)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'assigns the track as @track' do
|
it 'assigns the track as @track' do
|
||||||
do_create
|
do_create
|
||||||
assigns[:track].should == track
|
assigns[:track].should be_a_new(Track)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'renders the new template' do
|
it 'renders the new template' do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user