Simulate sending file in functional testing

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 =
if @#{@controller_varname}.save
flash[‘notice’] = ‘STK #{Inflector.titleize(@controller_varname)}
berhasil dibuat.’
redirect_to :controller => ‘element’
render_action ‘create_stk’
flash[:notice] = ‘Dokumen yang dikirim harus berformat pdf.’
redirect_to :action => ‘new_stk’, :id => @params[:id]

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 =>, :thermo_detector =>
{ :stk => ‘’ }}

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

Thank you.

This should help you:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs