aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Fuchs <thomas@fesch.at>2006-08-20 17:27:28 +0000
committerThomas Fuchs <thomas@fesch.at>2006-08-20 17:27:28 +0000
commitbb531a946d016ab0f41d91a4858a62156e65333e (patch)
tree38b5daf03747deb49ec24ccdeec7d5b413175b23
parentedb42088571f9ad61908032c3df12b4700e099e9 (diff)
downloadrails-bb531a946d016ab0f41d91a4858a62156e65333e.tar.gz
rails-bb531a946d016ab0f41d91a4858a62156e65333e.tar.bz2
rails-bb531a946d016ab0f41d91a4858a62156e65333e.zip
Fix unit tests for JSON emitters
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4795 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r--activesupport/test/json.rb14
1 files changed, 11 insertions, 3 deletions
diff --git a/activesupport/test/json.rb b/activesupport/test/json.rb
index d9c3cebf32..33c5a64ba5 100644
--- a/activesupport/test/json.rb
+++ b/activesupport/test/json.rb
@@ -19,8 +19,6 @@ class TestJSONEmitters < Test::Unit::TestCase
ArrayTests = [[ ['a', 'b', 'c'], %([\"a\", \"b\", \"c\"]) ],
[ [1, 'a', :b, nil, false], %([1, \"a\", \"b\", null, false]) ]]
- HashTests = [[ {:a => :b, :c => :d}, %({\"c\": \"d\", \"a\": \"b\"}) ]]
-
SymbolTests = [[ :a, %("a") ],
[ :this, %("this") ],
[ :"a b", %("a b") ]]
@@ -29,7 +27,7 @@ class TestJSONEmitters < Test::Unit::TestCase
VariableTests = [[ ActiveSupport::JSON::Variable.new('foo'), 'foo'],
[ ActiveSupport::JSON::Variable.new('alert("foo")'), 'alert("foo")']]
- RegexpTests = [[ /^a/, '/^a/' ], /^\w{1,2}[a-z]+/ix, '/^\\w{1,2}[a-z]+/ix']
+ RegexpTests = [[ /^a/, '/^a/' ], [/^\w{1,2}[a-z]+/ix, '/^\\w{1,2}[a-z]+/ix']]
constants.grep(/Tests$/).each do |class_tests|
define_method("test_#{class_tests[0..-6].downcase}") do
@@ -38,6 +36,16 @@ class TestJSONEmitters < Test::Unit::TestCase
end
end
end
+
+ def test_hash_encoding
+ assert_equal %({\"a\": \"b\"}), { :a => :b }.to_json
+ assert_equal %({\"a\": 1}), { 'a' => 1 }.to_json
+ assert_equal %({\"a\": [1, 2]}), { 'a' => [1,2] }.to_json
+
+ sorted_json =
+ '{' + {:a => :b, :c => :d}.to_json[1..-2].split(', ').sort.join(', ') + '}'
+ assert_equal %({\"a\": \"b\", \"c\": \"d\"}), sorted_json
+ end
def test_utf8_string_encoded_properly_when_kcode_is_utf8
old_kcode, $KCODE = $KCODE, 'UTF8'