Reputation: 852
I do some integration testing like this :
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 run the testing it is said that : goodsins.xls file does not exist. FYI : I put the file in the folder that named fixtures.
Any idea? Thx u very much
Upvotes: 6
Views: 2363
Reputation: 1414
The 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 Question Owner:
Solution:
add include ActionDispatch::TestProcess
to test_helper.rb
Upvotes: 9