Sha256: 78846115dc4c695e60a2f8c674620bb438c471b6b668b22fe53f5797a3a720b8

Contents?: true

Size: 956 Bytes

Versions: 8

Compression:

Stored size: 956 Bytes

Contents

# encoding: UTF-8

require 'helper'

class DebJuice < Minitest::Test
  class Jam
    attr_accessor :x, :y

    def initialize(x, y)
      @x = x
      @y = y
    end

    def eql?(o)
      self.class == o.class && @x == o.x && @y == o.y
    end
    alias == eql?

  end# Jam

  # contributed by sauliusg to fix as_json
  class Orange < Jam
    def initialize(x, y)
      super
    end

    def as_json()
      { :json_class => self.class,
        :x => @x,
        :y => @y }
    end

    def self.json_create(h)
      self.new(h['x'], h['y'])
    end
  end

  def test_as_json_object_compat_hash_cached
    Oj.default_options = { :mode => :compat, :class_cache => true }
    obj = Orange.new(true, 58)
    json = Oj.dump(obj, :indent => 2)
    assert(!json.nil?)
    dump_and_load(obj, true)
  end

  def dump_and_load(obj, trace=false)
    json = Oj.dump(obj, :indent => 2)
    loaded = Oj.load(json);
    assert_equal(obj, loaded)
    loaded
  end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
oj-2.10.2 test/test_debian.rb
oj-2.10.1 test/test_debian.rb
oj-2.10.0 test/test_debian.rb
oj-2.9.9 test/test_debian.rb
oj-2.9.8 test/test_debian.rb
oj-2.9.7 test/test_debian.rb
oj-2.9.6 test/test_debian.rb
oj-2.9.5 test/test_debian.rb