Sha256: 89a5098291dd6f887b656075aa08cd06478d6baf26b3465471825d34872b1ec1

Contents?: true

Size: 981 Bytes

Versions: 22

Compression:

Stored size: 981 Bytes

Contents

require 'test_helper'

class CSVSerializerTest < ActiveSupport::TestCase
  test "blank values are dumped as nil" do
    assert_dumped nil, ''
    assert_dumped nil, '  '
    assert_dumped nil, nil
    assert_dumped nil, []
  end

  test "blank values are loaded as an empty array" do
    assert_loaded [], ''
    assert_loaded [], '  '
    assert_loaded [], nil
  end

  test "load split the words by comma" do
    assert_loaded %w(foo bar), 'foo,bar'
  end

  test "dump join the words with a comma" do
    assert_dumped 'foo,bar', %w(foo bar)
  end

  private

  def assert_dumped(expected, object)
    message = "Expected CSVSerializer.dump(#{object.inspect}) to eq #{expected.inspect}"
    assert_equal(expected, Shipit::CSVSerializer.dump(object), message)
  end

  def assert_loaded(expected, payload)
    message = "Expected CSVSerializer.load(#{payload.inspect}) to eq #{expected.inspect}"
    assert_equal(expected, Shipit::CSVSerializer.load(payload), message)
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
shipit-engine-0.1.0 test/unit/csv_serializer_test.rb
shipit-engine-0.0.1.pre test/unit/csv_serializer_test.rb