Fix import options and add tests
This commit is contained in:
parent
610cd8fce4
commit
26e7012ef0
5 changed files with 20 additions and 16 deletions
|
@ -8,10 +8,10 @@ class FoodsoftFile
|
|||
# the parsed article is a simple hash
|
||||
def self.parse(file, options = {})
|
||||
filepath = file.is_a?(String) ? file : file.to_path
|
||||
filename = options[:filename] || filepath
|
||||
fileext = ::File.extname(filename)
|
||||
options = {col_sep: ';', encoding: 'utf-8'}.merge(options)
|
||||
s = Roo::Spreadsheet.open filepath, extension: fileext, csv_options: options
|
||||
filename = options.delete(:filename) || filepath
|
||||
fileext = File.extname(filename)
|
||||
options[:csv_options] = {col_sep: ';', encoding: 'utf-8'}.merge(options[:csv_options]||{})
|
||||
s = Roo::Spreadsheet.open(filepath, options.merge({extension: fileext}))
|
||||
|
||||
row_index = 1
|
||||
s.each do |row|
|
||||
|
|
BIN
spec/fixtures/foodsoft_file_01.ods
vendored
Normal file
BIN
spec/fixtures/foodsoft_file_01.ods
vendored
Normal file
Binary file not shown.
BIN
spec/fixtures/foodsoft_file_01.xls
vendored
Normal file
BIN
spec/fixtures/foodsoft_file_01.xls
vendored
Normal file
Binary file not shown.
BIN
spec/fixtures/foodsoft_file_01.xlsx
vendored
Normal file
BIN
spec/fixtures/foodsoft_file_01.xlsx
vendored
Normal file
Binary file not shown.
|
@ -60,22 +60,26 @@ describe 'supplier', :type => :feature do
|
|||
expect(page).to have_content(article.name)
|
||||
end
|
||||
|
||||
it 'can import articles' do
|
||||
|
||||
Dir.glob('spec/fixtures/foodsoft_file_01.*') do |file|
|
||||
it "can import articles from #{file}" do
|
||||
article_category.save!
|
||||
visit upload_supplier_articles_path(supplier)
|
||||
attach_file 'articles_file', Rails.root.join('spec/fixtures/foodsoft_file_01.csv')
|
||||
attach_file 'articles_file', Rails.root.join(file)
|
||||
find('input[type="submit"]').click
|
||||
|
||||
expect(find("#articles_0_note").value).to eq "bio ◎"
|
||||
expect(find("#articles_1_name").value).to eq "Pijnboompitten"
|
||||
expect(find("tr:nth-child(1) #new_articles__note").value).to eq "bio ◎"
|
||||
expect(find("tr:nth-child(2) #new_articles__name").value).to eq "Pijnboompitten"
|
||||
|
||||
4.times do |i|
|
||||
select article_category.name, :from => "articles_#{i}_article_category_id"
|
||||
all("tr:nth-child(#{i+1}) select > option")[1].select_option
|
||||
end
|
||||
find('input[type="submit"]').click
|
||||
expect(page).to have_content("Pijnboompitten")
|
||||
|
||||
expect(supplier.articles.count).to eq 4
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue