Sha256: 61c470ddd53866ae3431ba7f8f0daff2ad5b471d869c0100ed459a7bb9cb67eb

Contents?: true

Size: 978 Bytes

Versions: 42

Compression:

Stored size: 978 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, :use_to_json => 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

42 entries across 42 versions & 1 rubygems

Version Path
oj-2.17.5 test/test_debian.rb
oj-2.17.4 test/test_debian.rb
oj-2.17.3 test/test_debian.rb
oj-2.17.2 test/test_debian.rb
oj-2.17.1 test/test_debian.rb
oj-2.17.0 test/test_debian.rb
oj-2.16.1 test/test_debian.rb
oj-2.16.0 test/test_debian.rb
oj-2.15.1 test/test_debian.rb
oj-2.15.0 test/test_debian.rb
oj-2.14.6 test/test_debian.rb
oj-2.14.5 test/test_debian.rb
oj-2.14.4 test/test_debian.rb
oj-2.14.3 test/test_debian.rb
oj-2.14.2 test/test_debian.rb
oj-2.14.1 test/test_debian.rb
oj-2.14.0 test/test_debian.rb
oj-2.13.1 test/test_debian.rb
oj-2.13.0 test/test_debian.rb
oj-2.12.14 test/test_debian.rb