Permalink
Browse files

True, False, and Nil should be represented in as_json as themselves.

Conflicts:

	activesupport/lib/active_support/json/encoding.rb
	activesupport/test/json/encoding_test.rb
  • Loading branch information...
1 parent f09ae85 commit 624f801d27e946cae2244924e7f6a04565666036 Erich Menge committed May 30, 2012
Showing with 12 additions and 6 deletions.
  1. +6 −6 activesupport/lib/active_support/json/encoding.rb
  2. +6 −0 activesupport/test/json/encoding_test.rb
View
12 activesupport/lib/active_support/json/encoding.rb
@@ -158,18 +158,18 @@ def as_json(options = nil)
end
class TrueClass
- AS_JSON = ActiveSupport::JSON::Variable.new('true').freeze
- def as_json(options = nil) AS_JSON end #:nodoc:
+ def as_json(options = nil) self end #:nodoc:
+ def encode_json(encoder) to_s end #:nodoc:
end
class FalseClass
- AS_JSON = ActiveSupport::JSON::Variable.new('false').freeze
- def as_json(options = nil) AS_JSON end #:nodoc:
+ def as_json(options = nil) self end #:nodoc:
+ def encode_json(encoder) to_s end #:nodoc:
end
class NilClass
- AS_JSON = ActiveSupport::JSON::Variable.new('null').freeze
- def as_json(options = nil) AS_JSON end #:nodoc:
+ def as_json(options = nil) self end #:nodoc:
+ def encode_json(encoder) 'null' end #:nodoc:
end
class String
View
6 activesupport/test/json/encoding_test.rb
@@ -270,6 +270,12 @@ def test_struct_encoding
JSON.parse(json_string_and_date))
end
+ def test_nil_true_and_false_represented_as_themselves
+ assert_equal nil, nil.as_json
+ assert_equal true, true.as_json
+ assert_equal false, false.as_json
+ end
+
protected
def object_keys(json_object)

0 comments on commit 624f801

Please sign in to comment.