提交 83f2ffcf 编写于 作者: E Erich Menge 提交者: Rafael Mendonça França

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
上级 481dac9e
## 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*
......
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
......@@ -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)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册