A platform for community discussion. Free, open, simple.
PERF: Use Oj for serializing JSON. (#7820)
Bianca Nenciu1942ba1d42e4
diff --git a/config/initializers/100-oj.rb b/config/initializers/100-oj.rbindex 4e51c78a904..0936beaa79e 100644--- a/config/initializers/100-oj.rb+++ b/config/initializers/100-oj.rb@@ -1,4 +1,8 @@# frozen_string_literal: true+Oj::Rails.set_encoder()+Oj::Rails.set_decoder()+Oj::Rails.optimize()+# Not sure why it's not using this by default!MultiJson.engine = :ojdiff --git a/spec/integrity/oj_spec.rb b/spec/integrity/oj_spec.rbnew file mode 100644index 00000000000..9a02b27d528--- /dev/null+++ b/spec/integrity/oj_spec.rb@@ -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