Hi,
I am trying to get my functional tests for an attachment_fu resource to pass, and I’ve been able to get the tests for create method to pass, but I cannot get the destroy method to pass (I am using a fixture), because attachment fu throws an error when it can’t find a file on the file system. So, I guess I have to get a file to be destroyed to exist on the file system temporarily before the test for the destroy method is run. Does anyone have any idea how to approach this? Also, I noticed that attahchment_fu uses the same directory for file storage in the test environment as it does in the dev/production environments. That leaves lots of clutter in the file system each time the tests are run. Below is my code for the two test. Any ideas are appreciated.
Thanks,
Sean
def test_should_create_band_image
@request.session[:password] = PASSWORD
num_band_images = BandImage.count
fdata = fixture_file_upload(‘/files/band.jpg’, ‘image/jpeg’)
post :create, :band_image => { :uploaded_data => fdata }, :band_id => bands(:one).url
assert_response :redirect
assert_redirected_to :action => ‘index’
assert_equal num_band_images + 2, BandImage.count
end
def test_should_destroy_band_image
@request.session[:password] = PASSWORD
assert_difference(‘BandImage.count’, -1) do
delete :destroy, :id => band_images(:one), :band_id => bands(:one).url
end
assert_redirected_to band_band_images_path(bands(:one))
end