Skip to content

Commit

Permalink
Remove deprecated ActiveSupport::JSON::Encoding::CircularReferenceError.
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelfranca committed Jan 4, 2015
1 parent c8019c0 commit d6e06ea
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 46 deletions.
4 changes: 4 additions & 0 deletions activesupport/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
* Remove deprecated `ActiveSupport::JSON::Encoding::CircularReferenceError`.

*Rafael Mendonça França*

* Remove deprecated methods `ActiveSupport::JSON::Encoding.encode_big_decimal_as_string=`
and `ActiveSupport::JSON::Encoding.encode_big_decimal_as_string`.

Expand Down
22 changes: 0 additions & 22 deletions activesupport/lib/active_support/json/encoding.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,28 +112,6 @@ class << self
# Sets the encoder used by Rails to encode Ruby objects into JSON strings
# in +Object#to_json+ and +ActiveSupport::JSON.encode+.
attr_accessor :json_encoder

# Deprecate CircularReferenceError
def const_missing(name)
if name == :CircularReferenceError
message = "The JSON encoder in Rails 4.1 no longer offers protection from circular references. " \
"You are seeing this warning because you are rescuing from (or otherwise referencing) " \
"ActiveSupport::Encoding::CircularReferenceError. In the future, this error will be " \
"removed from Rails. You should remove these rescue blocks from your code and ensure " \
"that your data structures are free of circular references so they can be properly " \
"serialized into JSON.\n\n" \
"For example, the following Hash contains a circular reference to itself:\n" \
" h = {}\n" \
" h['circular'] = h\n" \
"In this case, calling h.to_json would not work properly."

ActiveSupport::Deprecation.warn message

SystemStackError
else
super
end
end
end

self.use_standard_json_time_format = true
Expand Down
24 changes: 0 additions & 24 deletions activesupport/test/json/encoding_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,30 +176,6 @@ def test_wide_utf8_roundtrip
assert_equal "𐒑", decoded_hash['string']
end

def test_exception_raised_when_encoding_circular_reference_in_array
a = [1]
a << a
assert_deprecated do
assert_raise(ActiveSupport::JSON::Encoding::CircularReferenceError) { ActiveSupport::JSON.encode(a) }
end
end

def test_exception_raised_when_encoding_circular_reference_in_hash
a = { :name => 'foo' }
a[:next] = a
assert_deprecated do
assert_raise(ActiveSupport::JSON::Encoding::CircularReferenceError) { ActiveSupport::JSON.encode(a) }
end
end

def test_exception_raised_when_encoding_circular_reference_in_hash_inside_array
a = { :name => 'foo', :sub => [] }
a[:sub] << a
assert_deprecated do
assert_raise(ActiveSupport::JSON::Encoding::CircularReferenceError) { ActiveSupport::JSON.encode(a) }
end
end

def test_hash_key_identifiers_are_always_quoted
values = {0 => 0, 1 => 1, :_ => :_, "$" => "$", "a" => "a", :A => :A, :A0 => :A0, "A0B" => "A0B"}
assert_equal %w( "$" "A" "A0" "A0B" "_" "a" "0" "1" ).sort, object_keys(ActiveSupport::JSON.encode(values))
Expand Down

0 comments on commit d6e06ea

Please sign in to comment.