Module: Importo::TestHelpers

Defined in:
lib/importo/test_helpers.rb

Instance Method Summary collapse

Instance Method Details

#import_sheet(kind, sheet, filename: 'import.xlsx', locale: I18n.locale, owner: users(:admin)) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/importo/test_helpers.rb', line 26

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

#sample_sheet(kind, locale: I18n.locale) ⇒ Object



20
21
22
23
24
# File 'lib/importo/test_helpers.rb', line 20

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

#simple_sheet(an_array, sheet_name: "Import") ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/importo/test_helpers.rb', line 8

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