# Functional tests and attachment\_fu

**URL:** <https://www.ruby-forum.com/t/functional-tests-and-attachment-fu/140957>\
**Category:** Rails\
**Created:** [June 20, 2008, 5:51am UTC](https://www.ruby-forum.com/t/functional-tests-and-attachment-fu/140957 "2008-06-20T05:51:24Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sean\_OSHara](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/dbc845/32.png) [@Sean\_OSHara](https://www.ruby-forum.com/u/Sean_OSHara)\
**Post date:** [June 20, 2008, 5:51am UTC](https://www.ruby-forum.com/t/functional-tests-and-attachment-fu/140957/1 "2008-06-20T05:51:24Z")

</div>

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
