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 =
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.

This should help you:

http://manuals.rubyonrails.com/read/chapter/28#page237

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