Sha256: ec87375e2e2f51875c268680d1174bd1538269527006bb3a4d34af4d40516c70

Contents?: true

Size: 937 Bytes

Versions: 12

Compression:

Stored size: 937 Bytes

Contents

# frozen_string_literal: true

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 as_json
      { :json_class => self.class,
        :x => @x,
        :y => @y }
    end

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

  def test_as_json_object_compat_hash_cached
    Oj.default_options = { :mode => :compat, :class_cache => true, :use_as_json => true }
    obj = Orange.new(true, 58)
    json = Oj.dump(obj, :indent => 2)
    refute_nil(json)
    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

12 entries across 12 versions & 1 rubygems

Version Path
oj-3.16.9 test/test_debian.rb
oj-3.16.8 test/test_debian.rb
oj-3.16.7 test/test_debian.rb
oj-3.16.6 test/test_debian.rb
oj-3.16.5 test/test_debian.rb
oj-3.16.4 test/test_debian.rb
oj-3.16.3 test/test_debian.rb
oj-3.16.2 test/test_debian.rb
oj-3.16.1 test/test_debian.rb
oj-3.16.0 test/test_debian.rb
oj-3.15.1 test/test_debian.rb
oj-3.15.0 test/test_debian.rb