Sha256: 7c6f64086284eaf1c9627551cdb267f46de4693c19c0fc2d667006a8ff4ea9e2

Contents?: true

Size: 1.98 KB

Versions: 16

Compression:

Stored size: 1.98 KB

Contents

require 'test_helper'
require 'ndr_import/file/registry'

module NdrImport
  module File
    # Registry file handler tests
    class RegistryTest < ActiveSupport::TestCase
      def setup
        @home = SafePath.new('test_space_rw')
        @permanent_test_files = SafePath.new('permanent_test_files')
      end

      test 'Registry.handlers' do
        assert_instance_of Hash, NdrImport::File::Registry.handlers
        assert_equal %w(csv doc pdf pipe thorn txt xls xlsx zip),
                     NdrImport::File::Registry.handlers.keys.sort
      end

      test 'should fail to enumerate unknown format' do
        exception = assert_raises(RuntimeError) do
          file_path = @permanent_test_files.join('normal.csv')
          tables = NdrImport::File::Registry.tables(file_path, 'mp3')
          tables.each do |tablename, sheet|
            assert_nil tablename
            sheet.to_a
          end
        end

        assert_equal 'Error: Unknown file format "mp3"', exception.message
      end

      test 'should enumerate pdf file table' do
        file_path = @permanent_test_files.join('hello_world.pdf')
        tables = NdrImport::File::Registry.tables(file_path, nil)
        tables.each do |tablename, sheet|
          assert_nil tablename
          assert_instance_of Enumerator, sheet
          assert_equal ['Hello World'], sheet.to_a
        end
      end

      test 'should enumerate zip file tables' do
        options = { 'unzip_path' => @home }
        file_path = @permanent_test_files.join('normal.csv.zip')
        files = NdrImport::File::Registry.files(file_path, options)
        files.each do |filename|
          tables = NdrImport::File::Registry.tables(filename, nil, options)

          tables.each do |tablename, sheet|
            assert_nil tablename
            sheet = sheet.to_a
            assert_equal(('A'..'Z').to_a, sheet[0])
            assert_equal ['1'] * 26, sheet[1]
            assert_equal ['2'] * 26, sheet[2]
          end
        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
ndr_import-4.1.4 test/file/registry_test.rb
ndr_import-4.1.3 test/file/registry_test.rb
ndr_import-4.1.2 test/file/registry_test.rb
ndr_import-4.1.1 test/file/registry_test.rb
ndr_import-4.1.0 test/file/registry_test.rb
ndr_import-4.0.1 test/file/registry_test.rb
ndr_import-4.0.0 test/file/registry_test.rb
ndr_import-3.1.6 test/file/registry_test.rb
ndr_import-3.1.5 test/file/registry_test.rb
ndr_import-3.1.4 test/file/registry_test.rb
ndr_import-3.1.3 test/file/registry_test.rb
ndr_import-3.1.2 test/file/registry_test.rb
ndr_import-3.1.1 test/file/registry_test.rb
ndr_import-3.1.0 test/file/registry_test.rb
ndr_import-3.0.1 test/file/registry_test.rb
ndr_import-3.0.0 test/file/registry_test.rb