From 6596693238a62cc4ce712bfb59873ccaae1fe41c Mon Sep 17 00:00:00 2001 From: Benjamin ter Kuile Date: Tue, 23 Sep 2025 12:56:42 -0500 Subject: [PATCH] Do not modify standard symbol in JSON behaviour. It seems to be good now --- config/initializers/symbol_to_json.rb | 19 ++++++++++--------- spec/symbol_spec.rb | 7 ++++++- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/config/initializers/symbol_to_json.rb b/config/initializers/symbol_to_json.rb index 84594e9c..69cfdb25 100644 --- a/config/initializers/symbol_to_json.rb +++ b/config/initializers/symbol_to_json.rb @@ -1,9 +1,10 @@ -class Symbol - def to_json(*) - to_s - end - - def as_json(*) - to_s - end -end +# #TODO: please investigate if this can be removed +# class Symbol +# def to_json(*) +# to_s +# end +# +# def as_json(*) +# to_s +# end +# end diff --git a/spec/symbol_spec.rb b/spec/symbol_spec.rb index 2dcccf83..333bea44 100644 --- a/spec/symbol_spec.rb +++ b/spec/symbol_spec.rb @@ -1,11 +1,16 @@ require 'spec_helper' +#TODO, is this really a good behaviour? describe Symbol do it 'to_json becomes a string in json format' do - :abc.to_json.should == 'abc' + :abc.to_json.should == '"abc"' end it 'as_json becomes a string in json format' do :abc.as_json.should == 'abc' end + + it 'works in hashes' do + expect([{abc: :def}].to_json).to eq %|[{"abc":"def"}]| + end end