New Version
Sync with Latest Instiki Trunk. Migrate to Rails 1.2.5. Bump version number.
This commit is contained in:
parent
de125367b0
commit
207fb1f7f2
120 changed files with 2592 additions and 662 deletions
|
@ -470,3 +470,40 @@ class HashToXmlTest < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
class QueryTest < Test::Unit::TestCase
|
||||
def test_simple_conversion
|
||||
assert_query_equal 'a=10', :a => 10
|
||||
end
|
||||
|
||||
def test_cgi_escaping
|
||||
assert_query_equal 'a%3Ab=c+d', 'a:b' => 'c d'
|
||||
end
|
||||
|
||||
def test_nil_parameter_value
|
||||
empty = Object.new
|
||||
def empty.to_param; nil end
|
||||
assert_query_equal 'a=', 'a' => empty
|
||||
end
|
||||
|
||||
def test_nested_conversion
|
||||
assert_query_equal 'person%5Bname%5D=Nicholas&person%5Blogin%5D=seckar',
|
||||
:person => {:name => 'Nicholas', :login => 'seckar'}
|
||||
end
|
||||
|
||||
def test_multiple_nested
|
||||
assert_query_equal 'account%5Bperson%5D%5Bid%5D=20&person%5Bid%5D=10',
|
||||
:person => {:id => 10}, :account => {:person => {:id => 20}}
|
||||
end
|
||||
|
||||
def test_array_values
|
||||
assert_query_equal 'person%5Bid%5D%5B%5D=10&person%5Bid%5D%5B%5D=20',
|
||||
:person => {:id => [10, 20]}
|
||||
end
|
||||
|
||||
private
|
||||
def assert_query_equal(expected, actual, message = nil)
|
||||
assert_equal expected.split('&').sort, actual.to_query.split('&').sort
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
require File.dirname(__FILE__) + '/../abstract_unit'
|
||||
|
||||
module One
|
||||
Constant1 = "Hello World"
|
||||
Constant2 = "What's up?"
|
||||
end
|
||||
|
||||
class Ab
|
||||
include One
|
||||
Constant1 = "Hello World" # Will have different object id than One::Constant1
|
||||
Constant3 = "Goodbye World"
|
||||
end
|
||||
|
||||
module Xy
|
||||
|
@ -91,6 +95,10 @@ class ModuleTest < Test::Unit::TestCase
|
|||
assert_equal [Yz::Zy, Yz, Object], Yz::Zy::Cd.parents
|
||||
assert_equal [Yz, Object], Yz::Zy.parents
|
||||
end
|
||||
|
||||
def test_local_constants
|
||||
assert_equal %w(Constant1 Constant3), Ab.local_constants.sort
|
||||
end
|
||||
|
||||
def test_as_load_path
|
||||
assert_equal 'yz/zy', Yz::Zy.as_load_path
|
||||
|
|
|
@ -9,6 +9,10 @@ module ModuleWithMissing
|
|||
end
|
||||
end
|
||||
|
||||
module ModuleWithConstant
|
||||
InheritedConstant = "Hello"
|
||||
end
|
||||
|
||||
class DependenciesTest < Test::Unit::TestCase
|
||||
def teardown
|
||||
Dependencies.clear
|
||||
|
@ -574,6 +578,13 @@ class DependenciesTest < Test::Unit::TestCase
|
|||
Object.send :remove_const, :M rescue nil
|
||||
end
|
||||
|
||||
def test_new_constants_in_with_inherited_constants
|
||||
m = Dependencies.new_constants_in(:Object) do
|
||||
Object.send :include, ModuleWithConstant
|
||||
end
|
||||
assert_equal [], m
|
||||
end
|
||||
|
||||
def test_file_with_multiple_constants_and_require_dependency
|
||||
with_loading 'autoloading_fixtures' do
|
||||
assert ! defined?(MultipleConstantFile)
|
||||
|
|
97
vendor/rails/activesupport/test/json_test.rb
vendored
Normal file
97
vendor/rails/activesupport/test/json_test.rb
vendored
Normal file
|
@ -0,0 +1,97 @@
|
|||
require File.dirname(__FILE__) + '/abstract_unit'
|
||||
|
||||
class JsonFoo
|
||||
def initialize(a, b)
|
||||
@a, @b = a, b
|
||||
end
|
||||
end
|
||||
|
||||
class TestJSONEmitters < Test::Unit::TestCase
|
||||
TrueTests = [[ true, %(true) ]]
|
||||
FalseTests = [[ false, %(false) ]]
|
||||
NilTests = [[ nil, %(null) ]]
|
||||
NumericTests = [[ 1, %(1) ],
|
||||
[ 2.5, %(2.5) ]]
|
||||
|
||||
StringTests = [[ 'this is the string', %("this is the string") ],
|
||||
[ 'a "string" with quotes<script>', %("a \\"string\\" with quotes\\074script\\076") ]]
|
||||
|
||||
ArrayTests = [[ ['a', 'b', 'c'], %([\"a\", \"b\", \"c\"]) ],
|
||||
[ [1, 'a', :b, nil, false], %([1, \"a\", \"b\", null, false]) ]]
|
||||
|
||||
SymbolTests = [[ :a, %("a") ],
|
||||
[ :this, %("this") ],
|
||||
[ :"a b", %("a b") ]]
|
||||
|
||||
ObjectTests = [[ JsonFoo.new(1, 2), %({\"a\": 1, \"b\": 2}) ]]
|
||||
|
||||
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']]
|
||||
|
||||
constants.grep(/Tests$/).each do |class_tests|
|
||||
define_method("test_#{class_tests[0..-6].downcase}") do
|
||||
self.class.const_get(class_tests).each do |pair|
|
||||
assert_equal pair.last, pair.first.to_json
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def setup
|
||||
unquote(false)
|
||||
end
|
||||
|
||||
def teardown
|
||||
unquote(true)
|
||||
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'
|
||||
assert_equal '"\\u20ac2.99"', '€2.99'.to_json
|
||||
assert_equal '"\\u270e\\u263a"', '✎☺'.to_json
|
||||
ensure
|
||||
$KCODE = old_kcode
|
||||
end
|
||||
|
||||
def test_exception_raised_when_encoding_circular_reference
|
||||
a = [1]
|
||||
a << a
|
||||
assert_raises(ActiveSupport::JSON::CircularReferenceError) { a.to_json }
|
||||
end
|
||||
|
||||
def test_unquote_hash_key_identifiers
|
||||
values = {0 => 0, 1 => 1, :_ => :_, "$" => "$", "a" => "a", :A => :A, :A0 => :A0, "A0B" => "A0B"}
|
||||
|
||||
assert_equal %({"a": "a"}), {"a"=>"a"}.to_json
|
||||
assert_equal %({0: 0}), { 0 => 0 }.to_json
|
||||
assert_equal %({"_": "_"}), {:_ =>:_ }.to_json
|
||||
assert_equal %({"$": "$"}), {"$"=>"$"}.to_json
|
||||
|
||||
unquote(true) do
|
||||
assert_equal %({a: "a"}), {"a"=>"a"}.to_json
|
||||
assert_equal %({0: 0}), { 0 => 0 }.to_json
|
||||
assert_equal %({_: "_"}), {:_ =>:_ }.to_json
|
||||
assert_equal %({$: "$"}), {"$"=>"$"}.to_json
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
def unquote(value)
|
||||
previous_value = ActiveSupport::JSON.unquote_hash_key_identifiers
|
||||
ActiveSupport::JSON.unquote_hash_key_identifiers = value
|
||||
yield if block_given?
|
||||
ensure
|
||||
ActiveSupport::JSON.unquote_hash_key_identifiers = previous_value if block_given?
|
||||
end
|
||||
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue