2019-06-27 22:16:00 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-27 22:27:38 -04:00
|
|
|
RSpec.describe "Oj" do
|
2019-06-27 22:16:00 -04:00
|
|
|
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
|