Sha256: e8a7a020f7507597e4d3a43252feeb84388434d90629dd16f88c0e80762c0897

Contents?: true

Size: 1.4 KB

Versions: 31

Compression:

Stored size: 1.4 KB

Contents

require 'spec_helper'

fixture_path = 'spec/fixtures'

describe ':remove_unmapped_keys option' do

  it 'it has no effect on loading a file without options' do 
  	options = {}
    data = SmarterCSV.process("#{fixture_path}/lots_of_columns.csv", options)
    data.size.should eq 1
    data.first.size.should eq 474 # there are some empty rows in the fixture
  end

  it 'it has no effect if provided without :key_mapping' do
  	options = {:remove_unmapped_keys => true}
    data = SmarterCSV.process("#{fixture_path}/lots_of_columns.csv", options)
    data.size.should eq 1
    data.first.size.should eq 474 # there are some empty rows in the fixture
  end

  it 'it defaults to false and has no effect if :key_mapping is provided without :remove_unmapped_keys' do
  	options = {:key_mapping => {:column_0 => :one, :column_15 => :two, :column_42 => :three}}
    data = SmarterCSV.process("#{fixture_path}/lots_of_columns.csv", options)
    data.size.should eq 1
    data.first.size.should eq 474 # there are some empty rows in the fixture
  end

  it 'it removes non-mapped keys/columns when set to true and :key_mapping is provided' do 
  	options = {:remove_unmapped_keys => true, :key_mapping => {:column_0 => :one, :column_15 => :two, :column_42 => :three}}
    data = SmarterCSV.process("#{fixture_path}/lots_of_columns.csv", options)
    data.size.should eq 1
    data.first.size.should eq 2 # column_15 is empty
  end
end

Version data entries

31 entries across 31 versions & 2 rubygems

Version Path
smarter_csv-1.1.5 spec/smarter_csv/remove_not_mapped_keys_spec.rb
smarter_csv-1.1.4 spec/smarter_csv/remove_not_mapped_keys_spec.rb
smarter_csv-1.1.3 spec/smarter_csv/remove_not_mapped_keys_spec.rb
smarter_csv-1.1.2 spec/smarter_csv/remove_not_mapped_keys_spec.rb
smarter_csv-1.1.1 spec/smarter_csv/remove_not_mapped_keys_spec.rb
smarter_csv-1.1.0 spec/smarter_csv/remove_not_mapped_keys_spec.rb
smarter_csv-1.0.19 spec/smarter_csv/remove_not_mapped_keys_spec.rb
smarter_csv-1.0.18 spec/smarter_csv/remove_not_mapped_keys_spec.rb
smarter_csv-1.0.17 spec/smarter_csv/remove_not_mapped_keys_spec.rb
smarter_csv-1.0.16 spec/smarter_csv/remove_not_mapped_keys_spec.rb
smarter_csv-1.0.15 spec/smarter_csv/remove_not_mapped_keys_spec.rb