How to check file upload in rails for integration testing?

I perform some integration tests as follows:

def user.excel_import fixture_excel = fixture_file_upload('goodsins.xls', 'text/xls') post excel_import_goods_ins_goods_ins_path, :dump=> {:excel_file=>fixture_excel}, :html => { :multipart => "true" } assert_response :redirect assert_redirected_to goods_ins_path end 

But when I start testing, they say that: fileins.xls the file does not exist. FYI: I put the file in a folder called fixtures.

Any idea? thanks u very much

+4
source share
1 answer

Notes here: http://apidock.com/rails/ActionController/TestProcess/fixture_file_upload indicate that you need to include a slash before the path or file name.

try fixture_file_upload('/goodsins.xls', 'text/xls') and see if that helps.

fixture_file_upload Source:

 # File actionpack/lib/action_controller/test_process.rb, line 523 def fixture_file_upload(path, mime_type = nil, binary = false) if ActionController::TestCase.respond_to?(:fixture_path) fixture_path = ActionController::TestCase.send(:fixture_path) end ActionController::TestUploadedFile.new("#{fixture_path}#{path}", mime_type, binary) end 

Update from the owner of the question:

Decision:

add include ActionDispatch::TestProcess to test_helper.rb

+8
source

All Articles