Sha256: 1b4b8aad9d15e64b81ca1158822958cc69ef6164768e54cfb35776f493c10855

Contents?: true

Size: 953 Bytes

Versions: 162

Compression:

Stored size: 953 Bytes

Contents

#!/usr/bin/env ruby
# encoding: UTF-8

$: << File.dirname(__FILE__)

require 'helper'
require 'oj'

class ObjectFolder < Minitest::Test
  class Raccoon
    attr_accessor :name

    def initialize(name)
      @name = name
    end

    def as_json(options={})
      {:name => @name}.merge(options)
    end
  end

  def setup
    @default_options = Oj.default_options
  end

  def teardown
    Oj.default_options = @default_options
  end

  def test_as_json_options
    Oj.mimic_JSON()
    raccoon = Raccoon.new('Rocket')
    json = raccoon.to_json()
    assert_equal(json, '{"name":"Rocket"}')

    json = raccoon.to_json(:occupation => 'bounty hunter')
    # depending on the ruby version the order of the hash members maybe different.
    if (json.start_with?('{"name'))
        assert_equal(json, '{"name":"Rocket","occupation":"bounty hunter"}')
    else
        assert_equal(json, '{"occupation":"bounty hunter","name":"Rocket"}')
    end
  end

end

Version data entries

162 entries across 162 versions & 3 rubygems

Version Path
oj-3.16.7 test/isolated/test_mimic_as_json.rb
oj-3.16.6 test/isolated/test_mimic_as_json.rb
oj-3.16.5 test/isolated/test_mimic_as_json.rb
oj-3.16.4 test/isolated/test_mimic_as_json.rb
oj-3.16.3 test/isolated/test_mimic_as_json.rb
oj-3.16.2 test/isolated/test_mimic_as_json.rb
oj-3.16.1 test/isolated/test_mimic_as_json.rb
oj-3.16.0 test/isolated/test_mimic_as_json.rb
oj-3.15.1 test/isolated/test_mimic_as_json.rb
oj-3.15.0 test/isolated/test_mimic_as_json.rb
oj-3.14.3 test/isolated/test_mimic_as_json.rb
devcycle-ruby-server-sdk-2.0.0 vendor/bundle/ruby/3.0.0/gems/oj-3.13.2/test/isolated/test_mimic_as_json.rb
oj-3.14.2 test/isolated/test_mimic_as_json.rb
oj-3.14.1 test/isolated/test_mimic_as_json.rb
oj-3.14.0 test/isolated/test_mimic_as_json.rb
oj-3.13.23 test/isolated/test_mimic_as_json.rb
oj-3.13.22 test/isolated/test_mimic_as_json.rb
oj-3.13.21 test/isolated/test_mimic_as_json.rb
oj-3.13.20 test/isolated/test_mimic_as_json.rb
oj-3.13.19 test/isolated/test_mimic_as_json.rb