Project

General

Profile

Bug #12100 ยป fix_csv_converter_single_arg_proc.patch

mdaubert (Matthew Daubert), 02/22/2016 04:14 PM

View differences:

lib/csv.rb
2217 2217
    fields.map.with_index do |field, index|
2218 2218
      converters.each do |converter|
2219 2219
        break if field.nil?
2220
        field = if converter.arity == 1  # straight field converter
2220
        field = if converter.arity.abs == 1  # straight field converter
2221 2221
          converter[field]
2222 2222
        else                             # FieldInfo converter
2223 2223
          header = @use_headers && !headers ? @headers[index] : nil
test/csv/test_data_converters.rb
161 161
    assert_equal(["Numbers", ":integer", "1", ":float", 3], @parser.shift)
162 162
  end
163 163

  
164
  def test_convert_with_custom_proc_one_arg
165
    # define custom converter as a proc accepting one argument
166
    assert_nothing_raised(Exception) { @parser.convert(&:upcase) }
167

  
168
    # and use
169
    assert_equal(["NUMBERS", ":INTEGER", "1", ":FLOAT", "3.015"], @parser.shift)
170
  end
171

  
164 172
  def test_convert_with_custom_code_using_field_info_header
165 173
    @parser = CSV.new(@data, headers: %w{one two three four five})
166 174

  
167
-