diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2009-04-23 14:34:37 +0100 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2009-04-23 14:34:37 +0100 |
commit | ae812c0a7bdb876c03752adfaa980ac4e74f2e17 (patch) | |
tree | 73eba5b0ddce60a4578fcbf6be581b8f35488273 /activesupport/test | |
parent | 67f30fd9639409877a57a7ba758cd13496433d69 (diff) | |
parent | 3c4c6bd0df598f865f49a983b4c65c415af4bcfc (diff) | |
download | rails-ae812c0a7bdb876c03752adfaa980ac4e74f2e17.tar.gz rails-ae812c0a7bdb876c03752adfaa980ac4e74f2e17.tar.bz2 rails-ae812c0a7bdb876c03752adfaa980ac4e74f2e17.zip |
Merge commit 'mainstream/master'
Diffstat (limited to 'activesupport/test')
31 files changed, 125 insertions, 62 deletions
diff --git a/activesupport/test/buffered_logger_test.rb b/activesupport/test/buffered_logger_test.rb index d48c7fcc54..7a0ec2e910 100644 --- a/activesupport/test/buffered_logger_test.rb +++ b/activesupport/test/buffered_logger_test.rb @@ -4,11 +4,13 @@ require 'fileutils' require 'active_support/buffered_logger' class BufferedLoggerTest < Test::Unit::TestCase + Logger = ActiveSupport::BufferedLogger + def setup @message = "A debug message" @integer_message = 12345 @output = StringIO.new - @logger = ActiveSupport::BufferedLogger.new(@output) + @logger = Logger.new(@output) end def test_should_log_debugging_message_when_debugging @@ -76,9 +78,9 @@ class BufferedLoggerTest < Test::Unit::TestCase define_method "test_disabling_auto_flush_with_#{disable.inspect}_should_flush_at_max_buffer_size_as_failsafe" do @logger.auto_flushing = disable - assert_equal ActiveSupport::BufferedLogger::MAX_BUFFER_SIZE, @logger.auto_flushing + assert_equal Logger::MAX_BUFFER_SIZE, @logger.auto_flushing - (ActiveSupport::BufferedLogger::MAX_BUFFER_SIZE - 1).times do + (Logger::MAX_BUFFER_SIZE - 1).times do @logger.info 'wait for it..' assert @output.string.empty?, @output.string end @@ -89,8 +91,8 @@ class BufferedLoggerTest < Test::Unit::TestCase end def test_should_know_if_its_loglevel_is_below_a_given_level - ActiveSupport::BufferedLogger::Severity.constants.each do |level| - @logger.level = ActiveSupport::BufferedLogger::Severity.const_get(level) - 1 + Logger::Severity.constants.each do |level| + @logger.level = Logger::Severity.const_get(level) - 1 assert @logger.send("#{level.downcase}?"), "didn't know if it was #{level.downcase}? or below" end end @@ -111,7 +113,7 @@ class BufferedLoggerTest < Test::Unit::TestCase tmp_directory = File.join(File.dirname(__FILE__), "tmp") log_file = File.join(tmp_directory, "development.log") assert !File.exist?(tmp_directory) - @logger = ActiveSupport::BufferedLogger.new(log_file) + @logger = Logger.new(log_file) assert File.exist?(tmp_directory) ensure FileUtils.rm_rf(tmp_directory) diff --git a/activesupport/test/core_ext/array_ext_test.rb b/activesupport/test/core_ext/array_ext_test.rb index 112cb998b1..24d33896ce 100644 --- a/activesupport/test/core_ext/array_ext_test.rb +++ b/activesupport/test/core_ext/array_ext_test.rb @@ -1,6 +1,9 @@ require 'abstract_unit' require 'active_support/core_ext/array' require 'active_support/core_ext/big_decimal' +require 'active_support/core_ext/object/conversions' + +require 'active_support/core_ext' # FIXME: pulling in all to_xml extensions class ArrayExtAccessTests < Test::Unit::TestCase def test_from diff --git a/activesupport/test/core_ext/blank_test.rb b/activesupport/test/core_ext/blank_test.rb index 00fea74639..1dbbf3ff30 100644 --- a/activesupport/test/core_ext/blank_test.rb +++ b/activesupport/test/core_ext/blank_test.rb @@ -1,4 +1,5 @@ require 'abstract_unit' +require 'active_support/core_ext/object/blank' class EmptyTrue def empty?() true; end diff --git a/activesupport/test/core_ext/class/attribute_accessor_test.rb b/activesupport/test/core_ext/class/attribute_accessor_test.rb index 85d0dd89e2..2214ba9894 100644 --- a/activesupport/test/core_ext/class/attribute_accessor_test.rb +++ b/activesupport/test/core_ext/class/attribute_accessor_test.rb @@ -1,4 +1,5 @@ require 'abstract_unit' +require 'active_support/core_ext/class/attribute_accessors' class ClassAttributeAccessorTest < Test::Unit::TestCase def setup diff --git a/activesupport/test/core_ext/class/class_inheritable_attributes_test.rb b/activesupport/test/core_ext/class/class_inheritable_attributes_test.rb index 7f859772e7..eeda468d9c 100644 --- a/activesupport/test/core_ext/class/class_inheritable_attributes_test.rb +++ b/activesupport/test/core_ext/class/class_inheritable_attributes_test.rb @@ -1,4 +1,5 @@ require 'abstract_unit' +require 'active_support/core_ext/class/inheritable_attributes' class ClassInheritableAttributesTest < Test::Unit::TestCase def setup diff --git a/activesupport/test/core_ext/date_time_ext_test.rb b/activesupport/test/core_ext/date_time_ext_test.rb index 45eb52c720..a7b179b2be 100644 --- a/activesupport/test/core_ext/date_time_ext_test.rb +++ b/activesupport/test/core_ext/date_time_ext_test.rb @@ -1,4 +1,5 @@ require 'abstract_unit' +require 'active_support/core_ext/date_time' class DateTimeExtCalculationsTest < Test::Unit::TestCase def test_to_s diff --git a/activesupport/test/core_ext/duplicable_test.rb b/activesupport/test/core_ext/duplicable_test.rb index 8b6127f31e..6e1f876959 100644 --- a/activesupport/test/core_ext/duplicable_test.rb +++ b/activesupport/test/core_ext/duplicable_test.rb @@ -1,4 +1,6 @@ require 'abstract_unit' +require 'bigdecimal' +require 'active_support/core_ext/object/duplicable' class DuplicableTest < Test::Unit::TestCase NO = [nil, false, true, :symbol, 1, 2.3, BigDecimal.new('4.56'), Class.new] diff --git a/activesupport/test/core_ext/duration_test.rb b/activesupport/test/core_ext/duration_test.rb index d4a4627e3e..ea6979bc6b 100644 --- a/activesupport/test/core_ext/duration_test.rb +++ b/activesupport/test/core_ext/duration_test.rb @@ -1,4 +1,5 @@ require 'abstract_unit' +require 'active_support/core/time' class DurationTest < ActiveSupport::TestCase def test_inspect diff --git a/activesupport/test/core_ext/exception_test.rb b/activesupport/test/core_ext/exception_test.rb index dabd8c7c06..e63842c0bd 100644 --- a/activesupport/test/core_ext/exception_test.rb +++ b/activesupport/test/core_ext/exception_test.rb @@ -1,4 +1,5 @@ require 'abstract_unit' +require 'active_support/core_ext/exception' class ExceptionExtTests < Test::Unit::TestCase diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb index bbb1c631f9..d65a5323bf 100644 --- a/activesupport/test/core_ext/hash_ext_test.rb +++ b/activesupport/test/core_ext/hash_ext_test.rb @@ -1,5 +1,7 @@ require 'abstract_unit' require 'active_support/core_ext/hash' +require 'bigdecimal' +require 'active_support/core_ext/string/access' class HashExtTest < Test::Unit::TestCase def setup diff --git a/activesupport/test/core_ext/module/attr_accessor_with_default_test.rb b/activesupport/test/core_ext/module/attr_accessor_with_default_test.rb index 7c59348af9..7c0d0bb242 100644 --- a/activesupport/test/core_ext/module/attr_accessor_with_default_test.rb +++ b/activesupport/test/core_ext/module/attr_accessor_with_default_test.rb @@ -1,4 +1,5 @@ require 'abstract_unit' +require 'active_support/core_ext/module/attr_accessor_with_default' class AttrAccessorWithDefaultTest < Test::Unit::TestCase def setup diff --git a/activesupport/test/core_ext/module/attr_internal_test.rb b/activesupport/test/core_ext/module/attr_internal_test.rb index 52833019e7..93578c9610 100644 --- a/activesupport/test/core_ext/module/attr_internal_test.rb +++ b/activesupport/test/core_ext/module/attr_internal_test.rb @@ -1,4 +1,5 @@ require 'abstract_unit' +require 'active_support/core_ext/module/attr_internal' class AttrInternalTest < Test::Unit::TestCase def setup @@ -37,8 +38,8 @@ class AttrInternalTest < Test::Unit::TestCase end def test_naming_format - assert_equal '@_%s', @target.attr_internal_naming_format - assert_nothing_raised { @target.attr_internal_naming_format = '@abc%sdef' } + assert_equal '@_%s', Module.attr_internal_naming_format + assert_nothing_raised { Module.attr_internal_naming_format = '@abc%sdef' } @target.attr_internal :foo assert !@instance.instance_variable_defined?('@_foo') @@ -47,6 +48,6 @@ class AttrInternalTest < Test::Unit::TestCase assert !@instance.instance_variable_defined?('@_foo') assert @instance.instance_variable_defined?('@abcfoodef') ensure - @target.attr_internal_naming_format = '@_%s' + Module.attr_internal_naming_format = '@_%s' end end diff --git a/activesupport/test/core_ext/module/attribute_accessor_test.rb b/activesupport/test/core_ext/module/attribute_accessor_test.rb index 96975085cf..bd9461e62c 100644 --- a/activesupport/test/core_ext/module/attribute_accessor_test.rb +++ b/activesupport/test/core_ext/module/attribute_accessor_test.rb @@ -1,4 +1,5 @@ require 'abstract_unit' +require 'active_support/core_ext/module/attribute_accessors' class ModuleAttributeAccessorTest < Test::Unit::TestCase def setup diff --git a/activesupport/test/core_ext/module/model_naming_test.rb b/activesupport/test/core_ext/module/model_naming_test.rb index d08349dd97..da3b6c4932 100644 --- a/activesupport/test/core_ext/module/model_naming_test.rb +++ b/activesupport/test/core_ext/module/model_naming_test.rb @@ -1,4 +1,5 @@ require 'abstract_unit' +require 'active_support/core_ext/module/model_naming' class ModelNamingTest < Test::Unit::TestCase def setup diff --git a/activesupport/test/core_ext/name_error_test.rb b/activesupport/test/core_ext/name_error_test.rb index bae004809f..10913e2ade 100644 --- a/activesupport/test/core_ext/name_error_test.rb +++ b/activesupport/test/core_ext/name_error_test.rb @@ -1,4 +1,5 @@ require 'abstract_unit' +require 'active_support/core_ext/name_error' class NameErrorTest < Test::Unit::TestCase def test_name_error_should_set_missing_name diff --git a/activesupport/test/core_ext/numeric_ext_test.rb b/activesupport/test/core_ext/numeric_ext_test.rb index 9cca4d3aaf..74b086fa9c 100644 --- a/activesupport/test/core_ext/numeric_ext_test.rb +++ b/activesupport/test/core_ext/numeric_ext_test.rb @@ -1,6 +1,7 @@ require 'abstract_unit' - -require 'active_support/core_ext/numeric/bytes' +require 'active_support/core_ext/numeric' +require 'active_support/core_ext/integer' +require 'active_support/core/time' class NumericExtTimeAndDateTimeTest < Test::Unit::TestCase def setup diff --git a/activesupport/test/core_ext/object_and_class_ext_test.rb b/activesupport/test/core_ext/object_and_class_ext_test.rb index c919698c0f..8869b053e6 100644 --- a/activesupport/test/core_ext/object_and_class_ext_test.rb +++ b/activesupport/test/core_ext/object_and_class_ext_test.rb @@ -1,5 +1,7 @@ require 'abstract_unit' require 'active_support/core_ext/object' +require 'active_support/core_ext/class/removal' +require 'active_support/core/time' class ClassA; end class ClassB < ClassA; end diff --git a/activesupport/test/core_ext/proc_test.rb b/activesupport/test/core_ext/proc_test.rb index 29f85371de..dc7b2c957d 100644 --- a/activesupport/test/core_ext/proc_test.rb +++ b/activesupport/test/core_ext/proc_test.rb @@ -1,4 +1,5 @@ require 'abstract_unit' +require 'active_support/core_ext/proc' class ProcTests < Test::Unit::TestCase def test_bind_returns_method_with_changed_self diff --git a/activesupport/test/core_ext/range_ext_test.rb b/activesupport/test/core_ext/range_ext_test.rb index 76e05e9954..2565c56b8a 100644 --- a/activesupport/test/core_ext/range_ext_test.rb +++ b/activesupport/test/core_ext/range_ext_test.rb @@ -1,5 +1,6 @@ require 'abstract_unit' require 'active_support/core_ext/range' +require 'active_support/core_ext/date/conversions' class RangeTest < Test::Unit::TestCase def test_to_s_from_dates diff --git a/activesupport/test/core_ext/string_ext_test.rb b/activesupport/test/core_ext/string_ext_test.rb index a357ba5852..237a843f9a 100644 --- a/activesupport/test/core_ext/string_ext_test.rb +++ b/activesupport/test/core_ext/string_ext_test.rb @@ -4,6 +4,7 @@ require 'abstract_unit' require 'inflector_test_cases' require 'active_support/core_ext/string' +require 'active_support/core_ext/time' class StringInflectionsTest < Test::Unit::TestCase include InflectorTestCases diff --git a/activesupport/test/core_ext/time_ext_test.rb b/activesupport/test/core_ext/time_ext_test.rb index 8ee4904036..3bf7b789ce 100644 --- a/activesupport/test/core_ext/time_ext_test.rb +++ b/activesupport/test/core_ext/time_ext_test.rb @@ -1,4 +1,5 @@ require 'abstract_unit' +require 'active_support/core/time' class TimeExtCalculationsTest < Test::Unit::TestCase def test_seconds_since_midnight diff --git a/activesupport/test/core_ext/time_with_zone_test.rb b/activesupport/test/core_ext/time_with_zone_test.rb index 3dec4c95f4..0380c28c17 100644 --- a/activesupport/test/core_ext/time_with_zone_test.rb +++ b/activesupport/test/core_ext/time_with_zone_test.rb @@ -1,5 +1,6 @@ require 'abstract_unit' require 'active_support/time_with_zone' +require 'active_support/json' class TimeWithZoneTest < Test::Unit::TestCase @@ -56,12 +57,12 @@ class TimeWithZoneTest < Test::Unit::TestCase end def test_to_json - assert_equal "\"1999/12/31 19:00:00 -0500\"", @twz.to_json + assert_equal "\"1999/12/31 19:00:00 -0500\"", ActiveSupport::JSON.encode(@twz) end def test_to_json_with_use_standard_json_time_format_config_set_to_true old, ActiveSupport.use_standard_json_time_format = ActiveSupport.use_standard_json_time_format, true - assert_equal "\"1999-12-31T19:00:00-05:00\"", @twz.to_json + assert_equal "\"1999-12-31T19:00:00-05:00\"", ActiveSupport::JSON.encode(@twz) ensure ActiveSupport.use_standard_json_time_format = old end diff --git a/activesupport/test/dependencies_test.rb b/activesupport/test/dependencies_test.rb index 01c1d67f4c..99c53924c2 100644 --- a/activesupport/test/dependencies_test.rb +++ b/activesupport/test/dependencies_test.rb @@ -1,6 +1,8 @@ require 'abstract_unit' require 'pp' require 'active_support/dependencies' +require 'active_support/core_ext/module/loading' +require 'active_support/core_ext/kernel/reporting' module ModuleWithMissing mattr_accessor :missing_count diff --git a/activesupport/test/i18n_test.rb b/activesupport/test/i18n_test.rb index 7535f4ad7a..2a08abfb3e 100644 --- a/activesupport/test/i18n_test.rb +++ b/activesupport/test/i18n_test.rb @@ -1,4 +1,6 @@ require 'abstract_unit' +require 'active_support/core/time' +require 'active_support/core_ext/array/conversions' class I18nTest < Test::Unit::TestCase def setup diff --git a/activesupport/test/inflector_test.rb b/activesupport/test/inflector_test.rb index 6b9fbd3156..8c4d831a39 100644 --- a/activesupport/test/inflector_test.rb +++ b/activesupport/test/inflector_test.rb @@ -1,4 +1,6 @@ require 'abstract_unit' +require 'active_support/inflector' + require 'inflector_test_cases' module Ace diff --git a/activesupport/test/json/decoding_test.rb b/activesupport/test/json/decoding_test.rb index 9b4b207c88..7e1bfcca84 100644 --- a/activesupport/test/json/decoding_test.rb +++ b/activesupport/test/json/decoding_test.rb @@ -1,49 +1,75 @@ # encoding: UTF-8 require 'abstract_unit' require 'active_support/json' +require 'active_support/core_ext/kernel/reporting' class TestJSONDecoding < ActiveSupport::TestCase TESTS = { %q({"returnTo":{"\/categories":"\/"}}) => {"returnTo" => {"/categories" => "/"}}, - %q({returnTo:{"\/categories":"\/"}}) => {"returnTo" => {"/categories" => "/"}}, %q({"return\\"To\\":":{"\/categories":"\/"}}) => {"return\"To\":" => {"/categories" => "/"}}, %q({"returnTo":{"\/categories":1}}) => {"returnTo" => {"/categories" => 1}}, %({"returnTo":[1,"a"]}) => {"returnTo" => [1, "a"]}, %({"returnTo":[1,"\\"a\\",", "b"]}) => {"returnTo" => [1, "\"a\",", "b"]}, - %({a: "'", "b": "5,000"}) => {"a" => "'", "b" => "5,000"}, - %({a: "a's, b's and c's", "b": "5,000"}) => {"a" => "a's, b's and c's", "b" => "5,000"}, + %({"a": "'", "b": "5,000"}) => {"a" => "'", "b" => "5,000"}, + %({"a": "a's, b's and c's", "b": "5,000"}) => {"a" => "a's, b's and c's", "b" => "5,000"}, # multibyte %({"matzue": "松江", "asakusa": "浅草"}) => {"matzue" => "松江", "asakusa" => "浅草"}, - %({a: "2007-01-01"}) => {'a' => Date.new(2007, 1, 1)}, - %({a: "2007-01-01 01:12:34 Z"}) => {'a' => Time.utc(2007, 1, 1, 1, 12, 34)}, + %({"a": "2007-01-01"}) => {'a' => Date.new(2007, 1, 1)}, + %({"a": "2007-01-01 01:12:34 Z"}) => {'a' => Time.utc(2007, 1, 1, 1, 12, 34)}, # no time zone - %({a: "2007-01-01 01:12:34"}) => {'a' => "2007-01-01 01:12:34"}, + %({"a": "2007-01-01 01:12:34"}) => {'a' => "2007-01-01 01:12:34"}, # needs to be *exact* - %({a: " 2007-01-01 01:12:34 Z "}) => {'a' => " 2007-01-01 01:12:34 Z "}, - %({a: "2007-01-01 : it's your birthday"}) => {'a' => "2007-01-01 : it's your birthday"}, + %({"a": " 2007-01-01 01:12:34 Z "}) => {'a' => " 2007-01-01 01:12:34 Z "}, + %({"a": "2007-01-01 : it's your birthday"}) => {'a' => "2007-01-01 : it's your birthday"}, %([]) => [], %({}) => {}, - %(1) => 1, - %("") => "", - %("\\"") => "\"", - %(null) => nil, - %(true) => true, - %(false) => false, - %q("http:\/\/test.host\/posts\/1") => "http://test.host/posts/1", - %q("\u003cunicode\u0020escape\u003e") => "<unicode escape>", - %q("\\\\u0020skip double backslashes") => "\\u0020skip double backslashes", - %q({a: "\u003cbr /\u003e"}) => {'a' => "<br />"}, - %q({b:["\u003ci\u003e","\u003cb\u003e","\u003cu\u003e"]}) => {'b' => ["<i>","<b>","<u>"]} + %({"a":1}) => {"a" => 1}, + %({"a": ""}) => {"a" => ""}, + %({"a":"\\""}) => {"a" => "\""}, + %({"a": null}) => {"a" => nil}, + %({"a": true}) => {"a" => true}, + %({"a": false}) => {"a" => false}, + %q({"a": "http:\/\/test.host\/posts\/1"}) => {"a" => "http://test.host/posts/1"}, + %q({"a": "\u003cunicode\u0020escape\u003e"}) => {"a" => "<unicode escape>"}, + %q({"a": "\\\\u0020skip double backslashes"}) => {"a" => "\\u0020skip double backslashes"}, + %q({"a": "\u003cbr /\u003e"}) => {'a' => "<br />"}, + %q({"b":["\u003ci\u003e","\u003cb\u003e","\u003cu\u003e"]}) => {'b' => ["<i>","<b>","<u>"]} } - - TESTS.each do |json, expected| - test "json decodes #{json}" do - assert_nothing_raised do - assert_equal expected, ActiveSupport::JSON.decode(json) + + backends = %w(Yaml) + begin + gem 'json', '>= 1.1' + require 'json' + backends << "JSONGem" + rescue Gem::LoadError + # Skip JSON gem tests + end + + backends.each do |backend| + TESTS.each do |json, expected| + test "json decodes #{json} with the #{backend} backend" do + ActiveSupport.parse_json_times = true + silence_warnings do + ActiveSupport::JSON.with_backend backend do + assert_nothing_raised do + assert_equal expected, ActiveSupport::JSON.decode(json) + end + end + end + end + end + end + + if backends.include?("JSONGem") + test "json decodes time json with time parsing disabled" do + ActiveSupport.parse_json_times = false + expected = {"a" => "2007-01-01 01:12:34 Z"} + ActiveSupport::JSON.with_backend "JSONGem" do + assert_equal expected, ActiveSupport::JSON.decode(%({"a": "2007-01-01 01:12:34 Z"})) end end end - + def test_failed_json_decoding assert_raise(ActiveSupport::JSON::ParseError) { ActiveSupport::JSON.decode(%({: 1})) } end diff --git a/activesupport/test/json/encoding_test.rb b/activesupport/test/json/encoding_test.rb index 9e6b4fa501..db24b3d96a 100644 --- a/activesupport/test/json/encoding_test.rb +++ b/activesupport/test/json/encoding_test.rb @@ -19,14 +19,14 @@ class TestJSONEncoding < Test::Unit::TestCase [ 'a "string" with quotes & an ampersand', %("a \\"string\\" with quotes \\u0026 an ampersand") ], [ 'http://test.host/posts/1', %("http://test.host/posts/1")]] - ArrayTests = [[ ['a', 'b', 'c'], %([\"a\", \"b\", \"c\"]) ], - [ [1, 'a', :b, nil, false], %([1, \"a\", \"b\", null, false]) ]] + 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 = [[ Foo.new(1, 2), %({\"a\": 1, \"b\": 2}) ]] + ObjectTests = [[ Foo.new(1, 2), %({\"a\":1,\"b\":2}) ]] VariableTests = [[ ActiveSupport::JSON::Variable.new('foo'), 'foo'], [ ActiveSupport::JSON::Variable.new('alert("foo")'), 'alert("foo")']] @@ -47,7 +47,7 @@ class TestJSONEncoding < Test::Unit::TestCase 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, pair.first.to_json + assert_equal pair.last, ActiveSupport::JSON.encode(pair.first) end ensure ActiveSupport.escape_html_entities_in_json = false @@ -57,45 +57,45 @@ class TestJSONEncoding < Test::Unit::TestCase 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 - assert_equal %({"1": 2}), { 1 => 2 }.to_json + assert_equal %({\"a\":\"b\"}), ActiveSupport::JSON.encode(:a => :b) + assert_equal %({\"a\":1}), ActiveSupport::JSON.encode('a' => 1) + assert_equal %({\"a\":[1,2]}), ActiveSupport::JSON.encode('a' => [1,2]) + assert_equal %({"1":2}), ActiveSupport::JSON.encode(1 => 2) - sorted_json = '{' + {:a => :b, :c => :d}.to_json[1..-2].split(', ').sort.join(', ') + '}' - assert_equal %({\"a\": \"b\", \"c\": \"d\"}), sorted_json + sorted_json = '{' + ActiveSupport::JSON.encode(:a => :b, :c => :d)[1..-2].split(',').sort.join(',') + '}' + assert_equal %({\"a\":\"b\",\"c\":\"d\"}), sorted_json end def test_utf8_string_encoded_properly_when_kcode_is_utf8 with_kcode 'UTF8' do - assert_equal '"\\u20ac2.99"', '€2.99'.to_json - assert_equal '"\\u270e\\u263a"', '✎☺'.to_json + assert_equal '"\\u20ac2.99"', ActiveSupport::JSON.encode('€2.99') + assert_equal '"\\u270e\\u263a"', ActiveSupport::JSON.encode('✎☺') end end def test_exception_raised_when_encoding_circular_reference a = [1] a << a - assert_raise(ActiveSupport::JSON::CircularReferenceError) { a.to_json } + assert_raise(ActiveSupport::JSON::CircularReferenceError) { ActiveSupport::JSON.encode(a) } end def test_hash_key_identifiers_are_always_quoted values = {0 => 0, 1 => 1, :_ => :_, "$" => "$", "a" => "a", :A => :A, :A0 => :A0, "A0B" => "A0B"} - assert_equal %w( "$" "A" "A0" "A0B" "_" "a" "0" "1" ).sort, object_keys(values.to_json) + assert_equal %w( "$" "A" "A0" "A0B" "_" "a" "0" "1" ).sort, object_keys(ActiveSupport::JSON.encode(values)) end def test_hash_should_allow_key_filtering_with_only - assert_equal %({"a": 1}), { 'a' => 1, :b => 2, :c => 3 }.to_json(:only => 'a') + assert_equal %({"a":1}), ActiveSupport::JSON.encode({'a' => 1, :b => 2, :c => 3}, :only => 'a') end def test_hash_should_allow_key_filtering_with_except - assert_equal %({"b": 2}), { 'foo' => 'bar', :b => 2, :c => 3 }.to_json(:except => ['foo', :c]) + assert_equal %({"b":2}), ActiveSupport::JSON.encode({'foo' => 'bar', :b => 2, :c => 3}, :except => ['foo', :c]) end def test_time_to_json_includes_local_offset ActiveSupport.use_standard_json_time_format = true with_env_tz 'US/Eastern' do - assert_equal %("2005-02-01T15:15:10-05:00"), Time.local(2005,2,1,15,15,10).to_json + assert_equal %("2005-02-01T15:15:10-05:00"), ActiveSupport::JSON.encode(Time.local(2005,2,1,15,15,10)) end ensure ActiveSupport.use_standard_json_time_format = false @@ -109,7 +109,7 @@ class TestJSONEncoding < Test::Unit::TestCase :latitude => 123.234 } } - result = hash.to_json + result = ActiveSupport::JSON.encode(hash) end end @@ -134,6 +134,6 @@ class JsonOptionsTests < Test::Unit::TestCase ActiveSupport::JSON.expects(:encode).with(2, json_options) ActiveSupport::JSON.expects(:encode).with('foo', json_options) - [1, 2, 'foo'].to_json(json_options) + [1, 2, 'foo'].rails_to_json(json_options) end end diff --git a/activesupport/test/new_callbacks_test.rb b/activesupport/test/new_callbacks_test.rb index 5cde078b65..abe7790ebf 100644 --- a/activesupport/test/new_callbacks_test.rb +++ b/activesupport/test/new_callbacks_test.rb @@ -19,11 +19,11 @@ module NewCallbacksTest class << self def callback_symbol(callback_method) - returning(:"#{callback_method}_method") do |method_name| - define_method(method_name) do - history << [callback_method, :symbol] - end + method_name = :"#{callback_method}_method" + define_method(method_name) do + history << [callback_method, :symbol] end + method_name end def callback_string(callback_method) @@ -381,4 +381,4 @@ module NewCallbacksTest assert_equal ["first", "second", "third", "second", "first"], terminator.history end end -end
\ No newline at end of file +end diff --git a/activesupport/test/test_test.rb b/activesupport/test/test_test.rb index d250b10822..40d3d612e7 100644 --- a/activesupport/test/test_test.rb +++ b/activesupport/test/test_test.rb @@ -1,4 +1,5 @@ require 'abstract_unit' +require 'active_support/core_ext/kernel/reporting' class AssertDifferenceTest < ActiveSupport::TestCase def setup diff --git a/activesupport/test/time_zone_test.rb b/activesupport/test/time_zone_test.rb index 7e8047566e..87d6ccc30d 100644 --- a/activesupport/test/time_zone_test.rb +++ b/activesupport/test/time_zone_test.rb @@ -1,4 +1,5 @@ require 'abstract_unit' +require 'active_support/core/time' class TimeZoneTest < Test::Unit::TestCase def test_utc_to_local diff --git a/activesupport/test/xml_mini/nokogiri_engine_test.rb b/activesupport/test/xml_mini/nokogiri_engine_test.rb index e5174a0b57..886a9d1aba 100644 --- a/activesupport/test/xml_mini/nokogiri_engine_test.rb +++ b/activesupport/test/xml_mini/nokogiri_engine_test.rb @@ -1,5 +1,6 @@ require 'abstract_unit' require 'active_support/xml_mini' +require 'active_support/core_ext/hash/conversions' begin gem 'nokogiri', '>= 1.1.1' |