Skip to content

Commit

Permalink
Revert "Deprecate ActiveSupport::JSON::Variable"
Browse files Browse the repository at this point in the history
This reverts commit bcfa013.
  • Loading branch information
rafaelfranca committed Aug 1, 2012
1 parent 857697b commit af65b8c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 23 deletions.
16 changes: 10 additions & 6 deletions activesupport/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
## Rails 3.2.8 ##

* No changes.
* Reverted the deprecation of ActiveSupport::JSON::Variable. *Rafael Mendonça França*

## Rails 3.2.7 (Jul 26, 2012) ##

* Hash#fetch(fetch) is not the same as doing hash[key]
* adds a missing require [fixes #6896]
* make sure the inflection rules are loaded when cherry-picking active_support/core_ext/string/inflections.rb [fixes #6884]
* Merge pull request #6857 from rsutphin/as_core_ext_time_missing_require
* bump AS deprecation_horizon to 4.0
* Hash#fetch(fetch) is not the same as doing hash[key]

* adds a missing require [fixes #6896]

* make sure the inflection rules are loaded when cherry-picking active_support/core_ext/string/inflections.rb [fixes #6884]

* Merge pull request #6857 from rsutphin/as_core_ext_time_missing_require

* bump AS deprecation_horizon to 4.0

## Rails 3.2.6 (Jun 12, 2012) ##

Expand Down
10 changes: 1 addition & 9 deletions activesupport/lib/active_support/json/variable.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
require 'active_support/deprecation'

module ActiveSupport
module JSON
# Deprecated: A string that returns itself as its JSON-encoded form.
# A string that returns itself as its JSON-encoded form.
class Variable < String
def initialize(*args)
ActiveSupport::Deprecation.warn 'ActiveSupport::JSON::Variable is deprecated and will be removed in Rails 4.0. ' \
'For your own custom JSON literals, define #as_json and #encode_json yourself.'
super
end

def as_json(options = nil) self end #:nodoc:
def encode_json(encoder) self end #:nodoc:
end
Expand Down
11 changes: 3 additions & 8 deletions activesupport/test/json/encoding_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require 'active_support/core_ext/string/inflections'
require 'active_support/json'

class TestJSONEncoding < ActiveSupport::TestCase
class TestJSONEncoding < Test::Unit::TestCase
class Foo
def initialize(a, b)
@a, @b = a, b
Expand Down Expand Up @@ -46,6 +46,8 @@ def as_json(options)
HashlikeTests = [[ Hashlike.new, %({\"a\":1}) ]]
CustomTests = [[ Custom.new, '"custom"' ]]

VariableTests = [[ ActiveSupport::JSON::Variable.new('foo'), 'foo'],
[ ActiveSupport::JSON::Variable.new('alert("foo")'), 'alert("foo")']]
RegexpTests = [[ /^a/, '"(?-mix:^a)"' ], [/^\w{1,2}[a-z]+/ix, '"(?ix-m:^\\\\w{1,2}[a-z]+)"']]

DateTests = [[ Date.new(2005,2,1), %("2005/02/01") ]]
Expand Down Expand Up @@ -77,13 +79,6 @@ def sorted_json(json)
end
end

def test_json_variable
assert_deprecated do
assert_equal ActiveSupport::JSON::Variable.new('foo'), 'foo'
assert_equal ActiveSupport::JSON::Variable.new('alert("foo")'), 'alert("foo")'
end
end

def test_hash_encoding
assert_equal %({\"a\":\"b\"}), ActiveSupport::JSON.encode(:a => :b)
assert_equal %({\"a\":1}), ActiveSupport::JSON.encode('a' => 1)
Expand Down

0 comments on commit af65b8c

Please sign in to comment.