diff --git a/lib/foodsoft_file.rb b/lib/foodsoft_file.rb index 43a784c2..6ceba5cf 100644 --- a/lib/foodsoft_file.rb +++ b/lib/foodsoft_file.rb @@ -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| diff --git a/spec/fixtures/foodsoft_file_01.ods b/spec/fixtures/foodsoft_file_01.ods new file mode 100644 index 00000000..2f8a1d8a Binary files /dev/null and b/spec/fixtures/foodsoft_file_01.ods differ diff --git a/spec/fixtures/foodsoft_file_01.xls b/spec/fixtures/foodsoft_file_01.xls new file mode 100644 index 00000000..5f9f6758 Binary files /dev/null and b/spec/fixtures/foodsoft_file_01.xls differ diff --git a/spec/fixtures/foodsoft_file_01.xlsx b/spec/fixtures/foodsoft_file_01.xlsx new file mode 100644 index 00000000..2bd28fe5 Binary files /dev/null and b/spec/fixtures/foodsoft_file_01.xlsx differ diff --git a/spec/integration/supplier_spec.rb b/spec/integration/supplier_spec.rb index 34ec912c..e9be4894 100644 --- a/spec/integration/supplier_spec.rb +++ b/spec/integration/supplier_spec.rb @@ -60,21 +60,25 @@ describe 'supplier', :type => :feature do expect(page).to have_content(article.name) end - it 'can import articles' do - article_category.save! - visit upload_supplier_articles_path(supplier) - attach_file 'articles_file', Rails.root.join('spec/fixtures/foodsoft_file_01.csv') - find('input[type="submit"]').click - expect(find("#articles_0_note").value).to eq "bio ◎" - expect(find("#articles_1_name").value).to eq "Pijnboompitten" + 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(file) + find('input[type="submit"]').click - 4.times do |i| - select article_category.name, :from => "articles_#{i}_article_category_id" + 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| + 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 - find('input[type="submit"]').click - - expect(supplier.articles.count).to eq 4 end end