Sha256: adb32f25d56db897dd940605375f2385fb94ba42a2465d9f8da3a91ff3a35865

Contents?: true

Size: 1004 Bytes

Versions: 1

Compression:

Stored size: 1004 Bytes

Contents

# frozen_string_literal: true

require "axlsx"
require "roo/excelx"

module Importo
  module TestHelpers
    def simple_sheet(an_array, sheet_name: "Import")
      xls = Axlsx::Package.new
      workbook = xls.workbook
      sheet = workbook.add_worksheet(name: sheet_name)

      an_array.each do |a|
        sheet.add_row a
      end

      xls.to_stream
    end

    def sample_sheet(kind, locale: I18n.locale)
      excel = Importo::Import.new(kind: kind, locale: locale).importer.sample_file

      Roo::Excelx.new(excel.set_encoding("BINARY"))
    end

    def import_sheet(kind, sheet, filename: 'import.xlsx', locale: I18n.locale, owner: users(:admin))
      import = Importo::Import.new(kind: kind, locale: locale, importo_ownable: owner)

      import.original.attach(io: sheet, filename: filename, content_type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", identify: false)
      import.save!

      ImportService.perform(import: import)
      import
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
importo-3.0.14 lib/importo/test_helpers.rb