1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
From 415e11c830af0cfaa304268693d422e707ba0778 Mon Sep 17 00:00:00 2001
From: Yehuda Katz <yehudakatz@YK.local>
Date: Wed, 10 Feb 2010 14:46:16 -0800
Subject: [PATCH] Fix a JSON ordering issue
(cherry picked from commit a3eaaf6b50b76a51080ec9ae6b217095868f3054)
---
activesupport/test/json/encoding_test.rb | 10 +++++++---
1 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/activesupport/test/json/encoding_test.rb b/activesupport/test/json/encoding_test.rb
index 47b2ba2..d4be0bb 100644
--- a/activesupport/test/json/encoding_test.rb
+++ b/activesupport/test/json/encoding_test.rb
@@ -49,13 +49,18 @@ class TestJSONEncoding < Test::Unit::TestCase
StandardDateTimeTests = [[ DateTime.civil(2005,2,1,15,15,10), %("2005-02-01T15:15:10+00:00") ]]
StandardStringTests = [[ 'this is the <string>', %("this is the <string>")]]
+ def sorted_json(json)
+ return json unless json =~ /^\{.*\}$/
+ '{' + json[1..-2].split(',').sort.join(',') + '}'
+ end
+
constants.grep(/Tests$/).each do |class_tests|
define_method("test_#{class_tests[0..-6].underscore}") do
begin
ActiveSupport.escape_html_entities_in_json = class_tests !~ /^Standard/
ActiveSupport.use_standard_json_time_format = class_tests =~ /^Standard/
self.class.const_get(class_tests).each do |pair|
- assert_equal pair.last, ActiveSupport::JSON.encode(pair.first)
+ assert_equal pair.last, sorted_json(ActiveSupport::JSON.encode(pair.first))
end
ensure
ActiveSupport.escape_html_entities_in_json = false
@@ -70,8 +75,7 @@ class TestJSONEncoding < Test::Unit::TestCase
assert_equal %({\"a\":[1,2]}), ActiveSupport::JSON.encode('a' => [1,2])
assert_equal %({"1":2}), ActiveSupport::JSON.encode(1 => 2)
- sorted_json = '{' + ActiveSupport::JSON.encode(:a => :b, :c => :d)[1..-2].split(',').sort.join(',') + '}'
- assert_equal %({\"a\":\"b\",\"c\":\"d\"}), sorted_json
+ assert_equal %({\"a\":\"b\",\"c\":\"d\"}), sorted_json(ActiveSupport::JSON.encode(:a => :b, :c => :d))
end
def test_utf8_string_encoded_properly_when_kcode_is_utf8
--
1.7.1
|