Permalink
Browse files

Deprecate ActiveSupport::JSON::Variable

Reason: ActiveSupport::JSON::Variable is not used anymore internally. It
was deprecated in 3-2-stable but we reverted all the deprecation for
point releases.

See #6536 and #6546.
Conflicts:
	activesupport/lib/active_support/json/variable.rb
  • Loading branch information...
1 parent 481dac9 commit 83f2ffcf4388f08e1b15d58b66fff1dfad9e99ef Erich Menge committed with rafaelfranca May 30, 2012
View
3 activesupport/CHANGELOG.md
@@ -1,5 +1,8 @@
## Rails 4.0.0 (unreleased) ##
+* ActiveSupport::JSON::Variable is deprecated. Define your own #as_json and #encode_json methods
+ for custom JSON string literals. *Erich Menge*
+
* Add String#indent. *fxn & Ace Suares*
* Inflections can now be defined per locale. `singularize` and `pluralize` accept locale as an extra argument. *David Celis*
View
17 activesupport/lib/active_support/json/variable.rb
@@ -0,0 +1,17 @@
+require 'active_support/deprecation'
+
+module ActiveSupport
+ module JSON
+ # Deprecated: 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
+ end
+end
View
7 activesupport/test/json/encoding_test.rb
@@ -85,6 +85,13 @@ 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)

0 comments on commit 83f2ffc

Please sign in to comment.