oj 2.11.5 → 2.12.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of oj might be problematic. Click here for more details.

@@ -1,63 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # encoding: UTF-8
3
-
4
- $VERBOSE = true
5
-
6
- %w(lib ext test).each do |dir|
7
- $LOAD_PATH.unshift File.expand_path("../../#{dir}", __FILE__)
8
- end
9
-
10
- require 'rubygems' if RUBY_VERSION.start_with?('1.8.')
11
-
12
- #require "minitest/spec"
13
- require "minitest/autorun"
14
-
15
- require "oj"
16
-
17
- # Uncomment this line and test_big_decimal will fail
18
- require "active_support/json"
19
-
20
- # With ActiveSupport 4.0, neither of these settings affect BigDecimal#to_json,
21
- # only BigDecimal#as_json
22
- #
23
- # ActiveSupport.encode_big_decimal_as_string = false
24
- # ActiveSupport::JSON::Encoding.encode_big_decimal_as_string = false
25
-
26
- describe Oj do
27
-
28
- # Options set by default in Rails 4.0 / Rabl
29
- def options
30
- {
31
- :bigdecimal_as_decimal=>true, # default = true
32
- :use_to_json=>true, # default = false
33
- :mode=>:compat, # default = object
34
- :time_format=>:ruby, # default = unix
35
- }
36
- end
37
-
38
- def test_big_decimal
39
- orig = BigDecimal.new("3.14159265359")
40
- puts "*** to_s: #{orig.to_s}"
41
- puts "*** to_json: #{orig.to_json}"
42
- puts "*** JSON.dump: #{JSON.dump(orig)}"
43
- json = Oj.dump(orig, options)
44
- puts "*** json: #{json}"
45
-
46
- value = Oj.load(json)
47
- puts "*** value: #{value.class}"
48
- assert_equal(value, orig)
49
-
50
- # by default, without active support
51
- # assert_equal("0.314159265359E1", json)
52
- # in Rails 4.1, with active support
53
- # assert_equal("3.14159265359", json)
54
- end
55
-
56
- # Floats are unaffected
57
- def test_float
58
- orig = 3.14159265359
59
- json = Oj.dump(orig, options)
60
- assert_equal("3.14159265359", json)
61
- end
62
-
63
- end