Sha256: e574fd683a33e271e6e634a828630cf2ebb0a43be622a69582488258ea991bc2

Contents?: true

Size: 1.33 KB

Versions: 7

Compression:

Stored size: 1.33 KB

Contents

require 'spec_helper'

describe ActiveForce::Bulk::Records do
  subject { described_class.new(headers: headers, data: data)}
  let(:headers) { %w[header1 header2] }
  let(:data) do
    [
      %w[value1 value2],
      %w[value3 value4],
    ]
  end

  describe '#to_csv' do
    it 'returns CSV with headers' do
      expect(subject.to_csv).to eq "header1,header2\nvalue1,value2\nvalue3,value4\n"
    end
  end

  describe '::parse_from_attributes' do
    subject { described_class.parse_from_attributes(attributes) }
    let(:attributes) do
      [
        { header1: 'value1', header2: 'value2'},
        { header1: 'value3', header2: 'value4'},
      ]
    end
    it 'parses array of hash attributes into Records object with headers and data' do
      records = subject
      expect(records).to be_a described_class
      expect(records.headers).to eq headers
      expect(records.data).to eq data
    end

    context 'when there are NULL values' do
      let(:attributes) do
        [
          { header1: nil, header2: 'value2'},
          { header1: 'value3', header2: nil},
        ]
      end
      let(:data) do
        [
          %w[#N/A value2],
          %w[value3 #N/A],
        ]
      end

      it 'substitutes the expected SF value for NULL' do
        records = subject
        expect(records.data).to eq data
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
active_force-0.24.0 spec/active_force/bulk/record_spec.rb
active_force-0.23.0 spec/active_force/bulk/record_spec.rb
active_force-0.22.1 spec/active_force/bulk/record_spec.rb
active_force-0.22.0 spec/active_force/bulk/record_spec.rb
active_force-0.21.0 spec/active_force/bulk/record_spec.rb
active_force-0.20.1 spec/active_force/bulk/record_spec.rb
active_force-0.20.0 spec/active_force/bulk/record_spec.rb