Sha256: e87a9dc9b31a335e15a9793aba38221f216c82bdae1a8e598182b5eaf19cf4ed

Contents?: true

Size: 1.33 KB

Versions: 2

Compression:

Stored size: 1.33 KB

Contents

require 'spec_helper'

describe DataMapper::Serializer, '#to_yaml' do
  #
  # ==== yummy YAML
  #

  before(:all) do
    DataMapper.finalize
    @harness = Class.new(SerializerTestHarness) do
      def method_name
        :to_yaml
      end

      def deserialize(result)
        result = YAML.load(result)
        process = lambda {|object|
          if object.is_a?(Array)
            object.collect(&process)
          elsif object.is_a?(Hash)
            object.inject({}) {|a, (key, value)| a.update(key.to_s => process[value]) }
          else
            object
          end
        }
        process[result]
      end
    end.new
  end

  it_should_behave_like 'A serialization method'
  it_should_behave_like 'A serialization method that also serializes core classes'

  it 'should allow static YAML dumping' do
    object = Cow.create(
      :id        => 89,
      :composite => 34,
      :name      => 'Berta',
      :breed     => 'Guernsey'
    )
    result = @harness.deserialize(YAML.dump(object))
    result['name'].should == 'Berta'
  end

  it 'should allow static YAML dumping of a collection' do
    object = Cow.create(
      :id        => 89,
      :composite => 34,
      :name      => 'Berta',
      :breed     => 'Guernsey'
    )
    result = @harness.deserialize(YAML.dump(Cow.all))
    result[0]['name'].should == 'Berta'
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dm-serializer-1.1.0 spec/public/to_yaml_spec.rb
dm-serializer-1.1.0.rc3 spec/public/to_yaml_spec.rb