Sha256: b3cf9d2038c498ea070d7a95b68bf25baffc1816d0bdd35141c1e25c6cfd8794

Contents?: true

Size: 1 KB

Versions: 25

Compression:

Stored size: 1 KB

Contents

require 'test_helper'

class SerializeDeserializeTest < BaseTest
  subject { Struct.new(:song).new.extend(representer) }

  describe "deserialize" do
    representer! do
      property :song,
        :instance => lambda { |fragment, *| fragment.to_s.upcase },
        :prepare  => lambda { |fragment, *| fragment }, # TODO: allow false.
        :deserialize => lambda { |object, fragment, args|
          "#{object} #{fragment} #{args.inspect}"
        }
    end

    it { subject.from_hash({"song" => Object}, {:volume => 9}).song.must_equal "OBJECT Object {:volume=>9}" }
  end

  describe "serialize" do
    representer! do
      property :song,
        :representable => true,
        :prepare  => lambda { |fragment, *| fragment }, # TODO: allow false.
        :serialize => lambda { |object, args|
          "#{object} #{args.inspect}"
        }
    end

    before { subject.song = "Arrested In Shanghai" }

    it { subject.to_hash({:volume => 9}).must_equal({"song"=>"Arrested In Shanghai {:volume=>9}"}) }
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
representable-2.3.0 test/serialize_deserialize_test.rb
representable-2.2.3 test/serialize_deserialize_test.rb
representable-2.2.2 test/serialize_deserialize_test.rb
representable-2.2.1 test/serialize_deserialize_test.rb
representable-2.2.0 test/serialize_deserialize_test.rb
representable-2.1.8 test/serialize_deserialize_test.rb
representable-2.1.7 test/serialize_deserialize_test.rb
representable-2.1.6 test/serialize_deserialize_test.rb
representable-2.1.5 test/serialize_deserialize_test.rb
representable-2.1.4 test/serialize_deserialize_test.rb
representable-2.1.3 test/serialize_deserialize_test.rb
representable-2.1.1 test/serialize_deserialize_test.rb
representable-2.1.0 test/serialize_deserialize_test.rb
representable-2.0.4 test/serialize_deserialize_test.rb
representable-2.0.3 test/serialize_deserialize_test.rb
representable-2.0.2 test/serialize_deserialize_test.rb
representable-2.0.1 test/serialize_deserialize_test.rb
representable-2.0.0 test/serialize_deserialize_test.rb
representable-2.0.0.rc2 test/serialize_deserialize_test.rb
representable-2.0.0.rc1 test/serialize_deserialize_test.rb