# Simulate sending file in functional test

**URL:** <https://www.ruby-forum.com/t/simulate-sending-file-in-functional-test/76637>\
**Category:** Rails\
**Created:** [November 20, 2006, 2:46pm UTC](https://www.ruby-forum.com/t/simulate-sending-file-in-functional-test/76637 "2006-11-20T14:46:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rinda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ce73a5/32.png) [@rinda](https://www.ruby-forum.com/u/rinda)\
**Post date:** [November 20, 2006, 2:46pm UTC](https://www.ruby-forum.com/t/simulate-sending-file-in-functional-test/76637/1 "2006-11-20T14:46:49Z")

</div>

I have this controller method:  
def create\_stk  
eval \<\<-EOS  
@#{@controller\_varname} = @class\_controller.find(@params[:id])  
if params[@controller\_varname][:stk].content\_type.chomp ==  
‘application/pdf’ then  
@#{@controller\_varname}.stk =  
params[@controller\_varname][:stk].read  
if @#{@controller\_varname}.save  
flash[‘notice’] = ‘STK #{Inflector.titleize(@controller\_varname)}  
berhasil dibuat.’  
redirect\_to :controller =\> ‘element’  
else  
render\_action ‘create\_stk’  
end  
else  
flash[:notice] = ‘Dokumen yang dikirim harus berformat pdf.’  
redirect\_to :action =\> ‘new\_stk’, :id =\> @params[:id]  
end  
EOS  
end

I want to test it with functional test. First I have to tell you what  
the controller is doing? It just accept file that somebody send, check  
the type ( must be pdf ), then put in attribute of database record that  
already exists. So I want to test if somebody does not send pdf file,  
the view must display some warnings. But how do you emulate sending  
file in controller test. Here is the test method:  
def test\_send\_invalid\_stk  
post :create\_stk, { :id =\> @don\_dafii\_order.id, :thermo\_detector =\>  
{ :stk =\> ‘’ }}  
end

:stk is the file parameter. If I execute this, it complains there is no  
content\_type method for string.

Thank you.
