PERF: Use Oj for serializing JSON. (#7780)

This commit is contained in:
Bianca Nenciu 2019-06-24 18:32:00 +03:00 committed by GitHub
parent f4e354afff
commit b4df8c5466
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 0 deletions

View File

@ -1,4 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
Oj.optimize_rails
# Not sure why it's not using this by default! # Not sure why it's not using this by default!
MultiJson.engine = :oj MultiJson.engine = :oj

19
spec/integrity/oj_spec.rb Normal file
View File

@ -0,0 +1,19 @@
# frozen_string_literal: true
require "rails_helper"
describe 'Oj' do
it "is enabled" do
classes = Set.new
tracer = TracePoint.new(:c_call) { |tp| classes << tp.defined_class }
tracer.enable { ActiveModel::ArraySerializer.new([1, 2, 3]).to_json }
expect(classes).to include(Oj::Rails::Encoder)
end
it "escapes HTML entities the same as ActiveSupport" do
expect("<b>hello</b>".to_json).to eq("\"\\u003cb\\u003ehello\\u003c/b\\u003e\"")
expect('"hello world"'.to_json). to eq('"\"hello world\""')
expect("\u2028\u2029><&".to_json).to eq('"\u2028\u2029\u003e\u003c\u0026"')
end
end