mirror of
https://github.com/lingble/chatwoot.git
synced 2025-10-31 19:17:48 +00:00
Fixes: https://linear.app/chatwoot/issue/CW-1362/csv-imports-are-not-working-properly Fixes: #3462 --------- Co-authored-by: Sojan <sojan@pepalo.com>
19 lines
557 B
Ruby
19 lines
557 B
Ruby
module CsvSpecHelpers
|
|
# Generates a Rack::Test::UploadedFile object from an array of arrays
|
|
# data: Accepts an array of arrays as the only argument
|
|
def generate_csv_file(data)
|
|
# Create a temporary file
|
|
temp_file = Tempfile.new(['data', '.csv'])
|
|
|
|
# Write the array of arrays to the temporary file as CSV
|
|
CSV.open(temp_file.path, 'wb') do |csv|
|
|
data.each do |row|
|
|
csv << row
|
|
end
|
|
end
|
|
|
|
# Create and return a Rack::Test::UploadedFile object
|
|
Rack::Test::UploadedFile.new(temp_file.path, 'text/csv')
|
|
end
|
|
end
|