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.
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---