Sha256: dd05e10264f89d16246c1385a37ae7aab5837df795c3e4168c1e23d53f0e86a0

Contents?: true

Size: 1.54 KB

Versions: 2

Compression:

Stored size: 1.54 KB

Contents

require File.dirname(__FILE__) + '/test_helper'
require File.dirname(__FILE__) + '/../lib/sweat_shop'

class MarshalSerializerTest < Test::Unit::TestCase

  class UnderTest
    attr_accessor :name, :address, :city, :state, :zip, :id
    def ==(other)
      ![:name, :address, :city, :state, :zip, :id].map{|a| return self.send(a) == other.send(a)}.include?(false)
    end
    
  end

  def setup
    @under_test = UnderTest.new
    @under_test.id = 87
    @under_test.name = "MarshalTest"
    @under_test.address = "555 Rock Ridge Road"
    @under_test.city = "Rock Ridge"
    @under_test.state = "Texas"
    @under_test.zip = "90210"
  end

  test "should properly serialize a simple data structure" do
    dump = SweatShop::Serializers::MarshalSerializer.serialize([{:foo => "bar"}, 23, 87, %w{doug cathy connor tommy}])
    assert_equal Marshal.dump([{:foo => "bar"}, 23, 87, %w{doug cathy connor tommy}]), dump
  end
  
  test "should be able to serialize an arbitrary class" do
    dump = SweatShop::Serializers::MarshalSerializer.serialize(@under_test)
    assert_equal Marshal.dump(@under_test), dump
  end
  
  test "should be able to deserialize a simple data structure" do
    assert_equal [{:foo => "bar"}, 23, 87, %w{doug cathy connor tommy}], SweatShop::Serializers::MarshalSerializer.deserialize(Marshal.dump([{:foo => "bar"}, 23, 87, %w{doug cathy connor tommy}]))
  end
  
  test "should be able to deserialize an arbitrary class" do
    assert_equal @under_test, SweatShop::Serializers::MarshalSerializer.deserialize(Marshal.dump(@under_test))
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
netinlet-sweat_shop-1.1.0 test/test_marshal_serializer.rb
netinlet-sweat_shop-1.1.1 test/test_marshal_serializer.rb