Sha256: eca8b65794461a88b3cd3932996062a32a71140c731ed8a7e4679a12cc1fd233

Contents?: true

Size: 797 Bytes

Versions: 5

Compression:

Stored size: 797 Bytes

Contents

require 'spec_helper'

describe SerialTranslator::TranslationType do
  let(:type) { SerialTranslator::TranslationType.new }

  describe '#cast' do
    it 'works for JSON' do
      expect(type.cast('{"foo":"bar"}')).to eq(foo: 'bar')
    end

    it 'works for YAML' do
      expect(type.cast("---\nfoo: bar")).to eq('foo' => 'bar')
    end

    it 'does nothing if already a Hash' do
      expect(type.cast({foo: :bar})).to eq(foo: :bar)
    end

    it 'defaults to empty hash' do
      expect(type.cast(nil)).to eq({})
    end
  end

  describe '#serialize' do
    it 'converts to JSON' do
      expect(type.serialize({foo: :bar})).to eq('{"foo":"bar"}')
    end

    it 'leaves strings alone (to avoid double serialization)' do
      expect(type.serialize('foo')).to eq 'foo'
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
serial_translator-2.0.5 spec/lib/serial_translator/translation_type_spec.rb
serial_translator-2.0.4 spec/lib/serial_translator/translation_type_spec.rb
serial_translator-2.0.3 spec/lib/serial_translator/translation_type_spec.rb
serial_translator-2.0.2 spec/lib/serial_translator/translation_type_spec.rb
serial_translator-2.0.1 spec/lib/serial_translator/translation_type_spec.rb