From 42a06d2d6253eed3b9f4fb4edfa251c9508a2e20 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 22 Apr 2009 09:10:14 -0700 Subject: stdlib autoloads were hanging on 1.9.1 --- activesupport/test/json/decoding_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'activesupport/test') diff --git a/activesupport/test/json/decoding_test.rb b/activesupport/test/json/decoding_test.rb index 8fe40557d6..7d8a07654d 100644 --- a/activesupport/test/json/decoding_test.rb +++ b/activesupport/test/json/decoding_test.rb @@ -1,7 +1,7 @@ # encoding: UTF-8 require 'abstract_unit' -class TestJSONDecoding < Test::Unit::TestCase +class TestJSONDecoding < ActiveSupport::TestCase TESTS = { %q({"returnTo":{"\/categories":"\/"}}) => {"returnTo" => {"/categories" => "/"}}, %q({returnTo:{"\/categories":"\/"}}) => {"returnTo" => {"/categories" => "/"}}, @@ -36,7 +36,7 @@ class TestJSONDecoding < Test::Unit::TestCase } TESTS.each do |json, expected| - define_method :"test_json_decoding_#{json}" do + test "json decodes #{json}" do assert_nothing_raised do assert_equal expected, ActiveSupport::JSON.decode(json) end -- cgit v1.2.3 From f5d720fb96f2e085acc4ed17f63272c4d38e567e Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 22 Apr 2009 16:41:06 -0700 Subject: Opt in to Dependencies --- activesupport/test/core_ext/module/attribute_aliasing_test.rb | 1 + activesupport/test/dependencies_test.rb | 1 + 2 files changed, 2 insertions(+) (limited to 'activesupport/test') diff --git a/activesupport/test/core_ext/module/attribute_aliasing_test.rb b/activesupport/test/core_ext/module/attribute_aliasing_test.rb index 570ac3b8d5..f17d031662 100644 --- a/activesupport/test/core_ext/module/attribute_aliasing_test.rb +++ b/activesupport/test/core_ext/module/attribute_aliasing_test.rb @@ -1,4 +1,5 @@ require 'abstract_unit' +require 'active_support/core_ext/module/aliasing' module AttributeAliasing class Content diff --git a/activesupport/test/dependencies_test.rb b/activesupport/test/dependencies_test.rb index a21f09403f..01c1d67f4c 100644 --- a/activesupport/test/dependencies_test.rb +++ b/activesupport/test/dependencies_test.rb @@ -1,5 +1,6 @@ require 'abstract_unit' require 'pp' +require 'active_support/dependencies' module ModuleWithMissing mattr_accessor :missing_count -- cgit v1.2.3 From 6fee981fa4ea2654f825c58b58327fc15fddf3a6 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 22 Apr 2009 16:48:58 -0700 Subject: Opt in to JSON --- activesupport/test/json/decoding_test.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'activesupport/test') diff --git a/activesupport/test/json/decoding_test.rb b/activesupport/test/json/decoding_test.rb index 7d8a07654d..9b4b207c88 100644 --- a/activesupport/test/json/decoding_test.rb +++ b/activesupport/test/json/decoding_test.rb @@ -1,5 +1,6 @@ # encoding: UTF-8 require 'abstract_unit' +require 'active_support/json' class TestJSONDecoding < ActiveSupport::TestCase TESTS = { -- cgit v1.2.3 From 5c4ba6e3fc66a779c28a70b8d7bde14b49e7c36c Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 22 Apr 2009 17:17:31 -0700 Subject: new_callbacks core extensions --- activesupport/test/new_callbacks_test.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'activesupport/test') 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 -- cgit v1.2.3 From f28bd9557c669cd63c31704202a46dd83f0a4102 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 22 Apr 2009 17:41:28 -0700 Subject: Fix dependencies revealed by testing in isolation --- activesupport/test/buffered_logger_test.rb | 14 ++++++++------ activesupport/test/core_ext/array_ext_test.rb | 3 +++ activesupport/test/core_ext/blank_test.rb | 1 + .../test/core_ext/class/attribute_accessor_test.rb | 1 + .../core_ext/class/class_inheritable_attributes_test.rb | 1 + activesupport/test/core_ext/date_time_ext_test.rb | 1 + activesupport/test/core_ext/duplicable_test.rb | 2 ++ activesupport/test/core_ext/duration_test.rb | 1 + activesupport/test/core_ext/exception_test.rb | 1 + activesupport/test/core_ext/hash_ext_test.rb | 2 ++ .../core_ext/module/attr_accessor_with_default_test.rb | 1 + activesupport/test/core_ext/module/attr_internal_test.rb | 7 ++++--- .../test/core_ext/module/attribute_accessor_test.rb | 1 + activesupport/test/core_ext/module/model_naming_test.rb | 1 + activesupport/test/core_ext/name_error_test.rb | 1 + activesupport/test/core_ext/numeric_ext_test.rb | 5 +++-- activesupport/test/core_ext/object_and_class_ext_test.rb | 2 ++ activesupport/test/core_ext/proc_test.rb | 1 + activesupport/test/core_ext/range_ext_test.rb | 1 + activesupport/test/core_ext/string_ext_test.rb | 1 + activesupport/test/core_ext/time_ext_test.rb | 1 + activesupport/test/core_ext/time_with_zone_test.rb | 1 + activesupport/test/dependencies_test.rb | 2 ++ activesupport/test/i18n_test.rb | 2 ++ activesupport/test/inflector_test.rb | 2 ++ activesupport/test/test_test.rb | 1 + activesupport/test/time_zone_test.rb | 1 + activesupport/test/xml_mini/nokogiri_engine_test.rb | 1 + 28 files changed, 48 insertions(+), 11 deletions(-) (limited to 'activesupport/test') 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..612a50c225 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 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/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' -- cgit v1.2.3 From 3c4c6bd0df598f865f49a983b4c65c415af4bcfc Mon Sep 17 00:00:00 2001 From: rick Date: Thu, 23 Apr 2009 00:08:40 -0700 Subject: * Add pluggable JSON backends with support for the JSON gem. [rick] Example: ActiveSupport::JSON.backend = "JSONGem" All internal Rails JSON encoding is now handled by ActiveSupport::JSON.encode(). Use of #to_json is not recommended, as it may clash with other libraries that overwrite it. However, you can recover Rails specific functionality if you really want to use #to_json. gem 'json' ActiveSupport::JSON.backend = "JSONGem" class ActiveRecord::Base alias to_json rails_to_json end --- activesupport/test/core_ext/time_with_zone_test.rb | 4 +- activesupport/test/json/decoding_test.rb | 76 +++++++++++++++------- activesupport/test/json/encoding_test.rb | 38 +++++------ 3 files changed, 72 insertions(+), 46 deletions(-) (limited to 'activesupport/test') diff --git a/activesupport/test/core_ext/time_with_zone_test.rb b/activesupport/test/core_ext/time_with_zone_test.rb index 612a50c225..0380c28c17 100644 --- a/activesupport/test/core_ext/time_with_zone_test.rb +++ b/activesupport/test/core_ext/time_with_zone_test.rb @@ -57,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/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") => "", - %q("\\\\u0020skip double backslashes") => "\\u0020skip double backslashes", - %q({a: "\u003cbr /\u003e"}) => {'a' => "
"}, - %q({b:["\u003ci\u003e","\u003cb\u003e","\u003cu\u003e"]}) => {'b' => ["","",""]} + %({"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" => ""}, + %q({"a": "\\\\u0020skip double backslashes"}) => {"a" => "\\u0020skip double backslashes"}, + %q({"a": "\u003cbr /\u003e"}) => {'a' => "
"}, + %q({"b":["\u003ci\u003e","\u003cb\u003e","\u003cu\u003e"]}) => {'b' => ["","",""]} } - - 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 -- cgit v1.2.3 From 3bd32754e24c4894abd2316eb0be3aeed08cf906 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sun, 26 Apr 2009 15:54:28 -0700 Subject: Privatize rails_to_json --- activesupport/test/json/encoding_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport/test') diff --git a/activesupport/test/json/encoding_test.rb b/activesupport/test/json/encoding_test.rb index db24b3d96a..1a0e6d543c 100644 --- a/activesupport/test/json/encoding_test.rb +++ b/activesupport/test/json/encoding_test.rb @@ -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'].rails_to_json(json_options) + [1, 2, 'foo'].send(:rails_to_json, json_options) end end -- cgit v1.2.3 From 1d71a34afa206e611d2dc5368c55cc4aed25ba01 Mon Sep 17 00:00:00 2001 From: Stephen Bannasch Date: Sun, 15 Mar 2009 06:32:29 -0400 Subject: add JRuby-JDOM backend for XmlMini Signed-off-by: Jeremy Kemper --- activesupport/test/xml_mini/jdom_engine_test.rb | 153 ++++++++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 activesupport/test/xml_mini/jdom_engine_test.rb (limited to 'activesupport/test') diff --git a/activesupport/test/xml_mini/jdom_engine_test.rb b/activesupport/test/xml_mini/jdom_engine_test.rb new file mode 100644 index 0000000000..b745228994 --- /dev/null +++ b/activesupport/test/xml_mini/jdom_engine_test.rb @@ -0,0 +1,153 @@ +require 'abstract_unit' +require 'active_support/xml_mini' + +if RUBY_PLATFORM =~ /java/ + +class JDOMEngineTest < Test::Unit::TestCase + include ActiveSupport + + def setup + @default_backend = XmlMini.backend + XmlMini.backend = 'JDOM' + end + + def teardown + XmlMini.backend = @default_backend + end + + # def test_file_from_xml + # hash = Hash.from_xml(<<-eoxml) + # + # + # + # + # eoxml + # assert hash.has_key?('blog') + # assert hash['blog'].has_key?('logo') + # + # file = hash['blog']['logo'] + # assert_equal 'logo.png', file.original_filename + # assert_equal 'image/png', file.content_type + # end + + def test_exception_thrown_on_expansion_attack + assert_raise NativeException do + attack_xml = <<-EOT + + + + + + + + + ]> + + &a; + + EOT + Hash.from_xml(attack_xml) + end + end + + def test_setting_JDOM_as_backend + XmlMini.backend = 'JDOM' + assert_equal XmlMini_JDOM, XmlMini.backend + end + + def test_blank_returns_empty_hash + assert_equal({}, XmlMini.parse(nil)) + assert_equal({}, XmlMini.parse('')) + end + + def test_array_type_makes_an_array + assert_equal_rexml(<<-eoxml) + + + a post + another post + + + eoxml + end + + def test_one_node_document_as_hash + assert_equal_rexml(<<-eoxml) + + eoxml + end + + def test_one_node_with_attributes_document_as_hash + assert_equal_rexml(<<-eoxml) + + eoxml + end + + def test_products_node_with_book_node_as_hash + assert_equal_rexml(<<-eoxml) + + + + eoxml + end + + def test_products_node_with_two_book_nodes_as_hash + assert_equal_rexml(<<-eoxml) + + + + + eoxml + end + + def test_single_node_with_content_as_hash + assert_equal_rexml(<<-eoxml) + + hello world + + eoxml + end + + def test_children_with_children + assert_equal_rexml(<<-eoxml) + + + + + + eoxml + end + + def test_children_with_text + assert_equal_rexml(<<-eoxml) + + + hello everyone + + + eoxml + end + + def test_children_with_non_adjacent_text + assert_equal_rexml(<<-eoxml) + + good + + hello everyone + + morning + + eoxml + end + + private + def assert_equal_rexml(xml) + hash = XmlMini.with_backend('REXML') { XmlMini.parse(xml) } + assert_equal(hash, XmlMini.parse(xml)) + end +end + +else + # don't run these test because we aren't running in JRuby +end -- cgit v1.2.3 From 79420e71e0e75d6f81e5284184bac4e7d0b02c30 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Thu, 30 Apr 2009 01:33:07 -0700 Subject: Work around Float faux precision --- activesupport/test/core_ext/duration_test.rb | 20 ++++++++++---------- activesupport/test/core_ext/time_ext_test.rb | 8 ++++---- activesupport/test/core_ext/time_with_zone_test.rb | 2 +- 3 files changed, 15 insertions(+), 15 deletions(-) (limited to 'activesupport/test') diff --git a/activesupport/test/core_ext/duration_test.rb b/activesupport/test/core_ext/duration_test.rb index ea6979bc6b..30d4152729 100644 --- a/activesupport/test/core_ext/duration_test.rb +++ b/activesupport/test/core_ext/duration_test.rb @@ -42,23 +42,23 @@ class DurationTest < ActiveSupport::TestCase end def test_since_and_ago_with_fractional_days - Time.stubs(:now).returns Time.local(2000) + t = Time.local(2000) # since - assert_equal 36.hours.since, 1.5.days.since - assert_equal((24 * 1.7).hours.since, 1.7.days.since) + assert_equal 36.hours.since(t), 1.5.days.since(t) + assert_in_delta((24 * 1.7).hours.since(t), 1.7.days.since(t), 1) # ago - assert_equal 36.hours.ago, 1.5.days.ago - assert_equal((24 * 1.7).hours.ago, 1.7.days.ago) + assert_equal 36.hours.ago(t), 1.5.days.ago(t) + assert_in_delta((24 * 1.7).hours.ago(t), 1.7.days.ago(t), 1) end def test_since_and_ago_with_fractional_weeks - Time.stubs(:now).returns Time.local(2000) + t = Time.local(2000) # since - assert_equal((7 * 36).hours.since, 1.5.weeks.since) - assert_equal((7 * 24 * 1.7).hours.since, 1.7.weeks.since) + assert_equal((7 * 36).hours.since(t), 1.5.weeks.since(t)) + assert_in_delta((7 * 24 * 1.7).hours.since(t), 1.7.weeks.since(t), 1) # ago - assert_equal((7 * 36).hours.ago, 1.5.weeks.ago) - assert_equal((7 * 24 * 1.7).hours.ago, 1.7.weeks.ago) + assert_equal((7 * 36).hours.ago(t), 1.5.weeks.ago(t)) + assert_in_delta((7 * 24 * 1.7).hours.ago(t), 1.7.weeks.ago(t), 1) end def test_since_and_ago_anchored_to_time_now_when_time_zone_default_not_set diff --git a/activesupport/test/core_ext/time_ext_test.rb b/activesupport/test/core_ext/time_ext_test.rb index 3bf7b789ce..e265423f06 100644 --- a/activesupport/test/core_ext/time_ext_test.rb +++ b/activesupport/test/core_ext/time_ext_test.rb @@ -424,10 +424,10 @@ class TimeExtCalculationsTest < Test::Unit::TestCase assert_equal Time.local(2005,6,28,15,15,10), Time.local(2005,2,28,15,15,10).advance(:months => 4) assert_equal Time.local(2005,3,21,15,15,10), Time.local(2005,2,28,15,15,10).advance(:weeks => 3) assert_equal Time.local(2005,3,25,3,15,10), Time.local(2005,2,28,15,15,10).advance(:weeks => 3.5) - assert_equal Time.local(2005,3,26,12,51,10), Time.local(2005,2,28,15,15,10).advance(:weeks => 3.7) + assert_in_delta Time.local(2005,3,26,12,51,10), Time.local(2005,2,28,15,15,10).advance(:weeks => 3.7), 1 assert_equal Time.local(2005,3,5,15,15,10), Time.local(2005,2,28,15,15,10).advance(:days => 5) assert_equal Time.local(2005,3,6,3,15,10), Time.local(2005,2,28,15,15,10).advance(:days => 5.5) - assert_equal Time.local(2005,3,6,8,3,10), Time.local(2005,2,28,15,15,10).advance(:days => 5.7) + assert_in_delta Time.local(2005,3,6,8,3,10), Time.local(2005,2,28,15,15,10).advance(:days => 5.7), 1 assert_equal Time.local(2012,9,28,15,15,10), Time.local(2005,2,28,15,15,10).advance(:years => 7, :months => 7) assert_equal Time.local(2013,10,3,15,15,10), Time.local(2005,2,28,15,15,10).advance(:years => 7, :months => 19, :days => 5) assert_equal Time.local(2013,10,17,15,15,10), Time.local(2005,2,28,15,15,10).advance(:years => 7, :months => 19, :weeks => 2, :days => 5) @@ -446,10 +446,10 @@ class TimeExtCalculationsTest < Test::Unit::TestCase assert_equal Time.utc(2005,6,22,15,15,10), Time.utc(2005,2,22,15,15,10).advance(:months => 4) assert_equal Time.utc(2005,3,21,15,15,10), Time.utc(2005,2,28,15,15,10).advance(:weeks => 3) assert_equal Time.utc(2005,3,25,3,15,10), Time.utc(2005,2,28,15,15,10).advance(:weeks => 3.5) - assert_equal Time.utc(2005,3,26,12,51,10), Time.utc(2005,2,28,15,15,10).advance(:weeks => 3.7) + assert_in_delta Time.utc(2005,3,26,12,51,10), Time.utc(2005,2,28,15,15,10).advance(:weeks => 3.7), 1 assert_equal Time.utc(2005,3,5,15,15,10), Time.utc(2005,2,28,15,15,10).advance(:days => 5) assert_equal Time.utc(2005,3,6,3,15,10), Time.utc(2005,2,28,15,15,10).advance(:days => 5.5) - assert_equal Time.utc(2005,3,6,8,3,10), Time.utc(2005,2,28,15,15,10).advance(:days => 5.7) + assert_in_delta Time.utc(2005,3,6,8,3,10), Time.utc(2005,2,28,15,15,10).advance(:days => 5.7), 1 assert_equal Time.utc(2012,9,22,15,15,10), Time.utc(2005,2,22,15,15,10).advance(:years => 7, :months => 7) assert_equal Time.utc(2013,10,3,15,15,10), Time.utc(2005,2,22,15,15,10).advance(:years => 7, :months => 19, :days => 11) assert_equal Time.utc(2013,10,17,15,15,10), Time.utc(2005,2,28,15,15,10).advance(:years => 7, :months => 19, :weeks => 2, :days => 5) diff --git a/activesupport/test/core_ext/time_with_zone_test.rb b/activesupport/test/core_ext/time_with_zone_test.rb index 0380c28c17..03ae70d420 100644 --- a/activesupport/test/core_ext/time_with_zone_test.rb +++ b/activesupport/test/core_ext/time_with_zone_test.rb @@ -92,7 +92,7 @@ class TimeWithZoneTest < Test::Unit::TestCase end def test_xmlschema_with_fractional_seconds - @twz += 0.123456 # advance the time by a fraction of a second + @twz += 0.1234560001 # advance the time by a fraction of a second assert_equal "1999-12-31T19:00:00.123-05:00", @twz.xmlschema(3) assert_equal "1999-12-31T19:00:00.123456-05:00", @twz.xmlschema(6) assert_equal "1999-12-31T19:00:00.123456-05:00", @twz.xmlschema(12) -- cgit v1.2.3 From 34509777fd375e5bc529f21ca66cf63263c2cf64 Mon Sep 17 00:00:00 2001 From: Yehuda Katz + Carl Lerche Date: Mon, 27 Apr 2009 18:16:55 -0700 Subject: Makes new callbacks support keys with special characters --- activesupport/test/new_callbacks_test.rb | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'activesupport/test') diff --git a/activesupport/test/new_callbacks_test.rb b/activesupport/test/new_callbacks_test.rb index abe7790ebf..8c887e1bf1 100644 --- a/activesupport/test/new_callbacks_test.rb +++ b/activesupport/test/new_callbacks_test.rb @@ -255,6 +255,26 @@ module NewCallbacksTest end end + class HyphenatedCallbacks + include ActiveSupport::NewCallbacks + define_callbacks :save + attr_reader :stuff + + save_callback :before, :omg, :per_key => {:if => :yes} + + def yes() true end + + def omg + @stuff = "OMG" + end + + def save + _run_save_callbacks("hyphen-ated") do + @stuff + end + end + end + class AroundCallbacksTest < Test::Unit::TestCase def test_save_around around = AroundPerson.new @@ -381,4 +401,12 @@ module NewCallbacksTest assert_equal ["first", "second", "third", "second", "first"], terminator.history end end + + class HyphenatedKeyTest < Test::Unit::TestCase + def test_save + obj = HyphenatedCallbacks.new + obj.save + assert_equal obj.stuff, "OMG" + end + end end -- cgit v1.2.3 From eb201e64c0b68aee6d0715d44cf48178204c4133 Mon Sep 17 00:00:00 2001 From: codebrulee Date: Mon, 4 May 2009 12:36:22 -0400 Subject: Fixed Hash#from_xml with keys that are all caps. Signed-off-by: Michael Koziarski --- activesupport/test/core_ext/hash_ext_test.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'activesupport/test') diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb index d65a5323bf..ece5466abb 100644 --- a/activesupport/test/core_ext/hash_ext_test.rb +++ b/activesupport/test/core_ext/hash_ext_test.rb @@ -646,6 +646,22 @@ class HashToXmlTest < Test::Unit::TestCase assert_equal expected_topic_hash, Hash.from_xml(topic_xml)["rsp"]["photos"]["photo"] end + def test_all_caps_key_from_xml + test_xml = <<-EOT + + Lorem Ipsum + + EOT + + expected_hash = { + "ABC3XYZ" => { + "TEST" => "Lorem Ipsum" + } + } + + assert_equal expected_hash, Hash.from_xml(test_xml) + end + def test_empty_array_from_xml blog_xml = <<-XML -- cgit v1.2.3 From 783deae99a4850f597135146b19e7ee4622da94e Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Thu, 7 May 2009 10:03:39 -0500 Subject: Add test coverage to module setup extensions --- activesupport/test/core_ext/module/setup_test.rb | 74 ++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 activesupport/test/core_ext/module/setup_test.rb (limited to 'activesupport/test') diff --git a/activesupport/test/core_ext/module/setup_test.rb b/activesupport/test/core_ext/module/setup_test.rb new file mode 100644 index 0000000000..132790f2ff --- /dev/null +++ b/activesupport/test/core_ext/module/setup_test.rb @@ -0,0 +1,74 @@ +require 'abstract_unit' +require 'active_support/core/time' +require 'active_support/core_ext/module/setup' + +class SetupTest < Test::Unit::TestCase + module Baz + module ClassMethods + def baz + "baz" + end + + def setup=(value) + @@setup = value + end + + def setup + @@setup + end + end + + setup do + self.setup = true + end + + def baz + "baz" + end + end + + module Bar + depends_on Baz + + def bar + "bar" + end + + def baz + "bar+" + super + end + end + + def setup + @klass = Class.new + end + + def test_module_is_included_normally + @klass.use(Baz) + assert_equal "baz", @klass.new.baz + assert_equal SetupTest::Baz, @klass.included_modules[0] + + @klass.use(Baz) + assert_equal "baz", @klass.new.baz + assert_equal SetupTest::Baz, @klass.included_modules[0] + end + + def test_class_methods_are_extended + @klass.use(Baz) + assert_equal "baz", @klass.baz + assert_equal SetupTest::Baz::ClassMethods, (class << @klass; self.included_modules; end)[0] + end + + def test_setup_block_is_ran + @klass.use(Baz) + assert_equal true, @klass.setup + end + + def test_modules_dependencies_are_met + @klass.use(Bar) + assert_equal "bar", @klass.new.bar + assert_equal "bar+baz", @klass.new.baz + assert_equal "baz", @klass.baz + assert_equal [SetupTest::Bar, SetupTest::Baz], @klass.included_modules[0..1] + end +end -- cgit v1.2.3 From 2854535b02bcee3668bda02c76c3105fc24730d3 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Thu, 7 May 2009 10:29:22 -0500 Subject: Make module dependency DSL opt in --- activesupport/test/core_ext/module/setup_test.rb | 74 ----------------------- activesupport/test/dependency_module_test.rb | 77 ++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 74 deletions(-) delete mode 100644 activesupport/test/core_ext/module/setup_test.rb create mode 100644 activesupport/test/dependency_module_test.rb (limited to 'activesupport/test') diff --git a/activesupport/test/core_ext/module/setup_test.rb b/activesupport/test/core_ext/module/setup_test.rb deleted file mode 100644 index 132790f2ff..0000000000 --- a/activesupport/test/core_ext/module/setup_test.rb +++ /dev/null @@ -1,74 +0,0 @@ -require 'abstract_unit' -require 'active_support/core/time' -require 'active_support/core_ext/module/setup' - -class SetupTest < Test::Unit::TestCase - module Baz - module ClassMethods - def baz - "baz" - end - - def setup=(value) - @@setup = value - end - - def setup - @@setup - end - end - - setup do - self.setup = true - end - - def baz - "baz" - end - end - - module Bar - depends_on Baz - - def bar - "bar" - end - - def baz - "bar+" + super - end - end - - def setup - @klass = Class.new - end - - def test_module_is_included_normally - @klass.use(Baz) - assert_equal "baz", @klass.new.baz - assert_equal SetupTest::Baz, @klass.included_modules[0] - - @klass.use(Baz) - assert_equal "baz", @klass.new.baz - assert_equal SetupTest::Baz, @klass.included_modules[0] - end - - def test_class_methods_are_extended - @klass.use(Baz) - assert_equal "baz", @klass.baz - assert_equal SetupTest::Baz::ClassMethods, (class << @klass; self.included_modules; end)[0] - end - - def test_setup_block_is_ran - @klass.use(Baz) - assert_equal true, @klass.setup - end - - def test_modules_dependencies_are_met - @klass.use(Bar) - assert_equal "bar", @klass.new.bar - assert_equal "bar+baz", @klass.new.baz - assert_equal "baz", @klass.baz - assert_equal [SetupTest::Bar, SetupTest::Baz], @klass.included_modules[0..1] - end -end diff --git a/activesupport/test/dependency_module_test.rb b/activesupport/test/dependency_module_test.rb new file mode 100644 index 0000000000..d611b4056c --- /dev/null +++ b/activesupport/test/dependency_module_test.rb @@ -0,0 +1,77 @@ +require 'abstract_unit' +require 'active_support/dependency_module' + +class DependencyModuleTest < Test::Unit::TestCase + module Baz + extend ActiveSupport::DependencyModule + + module ClassMethods + def baz + "baz" + end + + def setup=(value) + @@setup = value + end + + def setup + @@setup + end + end + + setup do + self.setup = true + end + + def baz + "baz" + end + end + + module Bar + extend ActiveSupport::DependencyModule + + depends_on Baz + + def bar + "bar" + end + + def baz + "bar+" + super + end + end + + def setup + @klass = Class.new + end + + def test_module_is_included_normally + @klass.send(:include, Baz) + assert_equal "baz", @klass.new.baz + assert_equal DependencyModuleTest::Baz, @klass.included_modules[0] + + @klass.send(:include, Baz) + assert_equal "baz", @klass.new.baz + assert_equal DependencyModuleTest::Baz, @klass.included_modules[0] + end + + def test_class_methods_are_extended + @klass.send(:include, Baz) + assert_equal "baz", @klass.baz + assert_equal DependencyModuleTest::Baz::ClassMethods, (class << @klass; self.included_modules; end)[0] + end + + def test_setup_block_is_ran + @klass.send(:include, Baz) + assert_equal true, @klass.setup + end + + def test_modules_dependencies_are_met + @klass.send(:include, Bar) + assert_equal "bar", @klass.new.bar + assert_equal "bar+baz", @klass.new.baz + assert_equal "baz", @klass.baz + assert_equal [DependencyModuleTest::Bar, DependencyModuleTest::Baz], @klass.included_modules[0..1] + end +end -- cgit v1.2.3 From af40fa6d036d86895e7be4ef46a615d44eb41ede Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Thu, 7 May 2009 10:38:57 -0500 Subject: Prefer "included" language over "setup" --- activesupport/test/dependency_module_test.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'activesupport/test') diff --git a/activesupport/test/dependency_module_test.rb b/activesupport/test/dependency_module_test.rb index d611b4056c..07090d15a1 100644 --- a/activesupport/test/dependency_module_test.rb +++ b/activesupport/test/dependency_module_test.rb @@ -10,17 +10,17 @@ class DependencyModuleTest < Test::Unit::TestCase "baz" end - def setup=(value) - @@setup = value + def included_ran=(value) + @@included_ran = value end - def setup - @@setup + def included_ran + @@included_ran end end - setup do - self.setup = true + included do + self.included_ran = true end def baz @@ -62,9 +62,9 @@ class DependencyModuleTest < Test::Unit::TestCase assert_equal DependencyModuleTest::Baz::ClassMethods, (class << @klass; self.included_modules; end)[0] end - def test_setup_block_is_ran + def test_included_block_is_ran @klass.send(:include, Baz) - assert_equal true, @klass.setup + assert_equal true, @klass.included_ran end def test_modules_dependencies_are_met -- cgit v1.2.3 From 9e0cfdb7f951c0446cdfd3b2cc26443712fe657a Mon Sep 17 00:00:00 2001 From: Ken Collins Date: Sat, 9 May 2009 18:35:31 -0400 Subject: ActiveSupport::OrderedHash#to_a method returns an ordered set of arrays. Matches ruby1.9's Hash#to_a. Signed-off-by: Michael Koziarski [#2629 state:committed] --- activesupport/test/ordered_hash_test.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'activesupport/test') diff --git a/activesupport/test/ordered_hash_test.rb b/activesupport/test/ordered_hash_test.rb index 7cd8c8a8f4..6fccbbdc41 100644 --- a/activesupport/test/ordered_hash_test.rb +++ b/activesupport/test/ordered_hash_test.rb @@ -51,6 +51,10 @@ class OrderedHashTest < Test::Unit::TestCase assert_same @ordered_hash, @ordered_hash.to_hash end + def test_to_a + assert_equal @keys.zip(@values), @ordered_hash.to_a + end + def test_has_key assert_equal true, @ordered_hash.has_key?('blue') assert_equal true, @ordered_hash.key?('blue') -- cgit v1.2.3 From e1854e0b199fba352ddcaa58a3af168e8cc70e3a Mon Sep 17 00:00:00 2001 From: Douglas F Shearer Date: Thu, 7 May 2009 23:58:07 +0100 Subject: ActiveSupport::OrderedHash[1,2,3,4] creates an OrderedHash instead of a Hash. [#2615 state:committed] Signed-off-by: Jeremy Kemper --- activesupport/test/ordered_hash_test.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'activesupport/test') diff --git a/activesupport/test/ordered_hash_test.rb b/activesupport/test/ordered_hash_test.rb index 6fccbbdc41..647938dd87 100644 --- a/activesupport/test/ordered_hash_test.rb +++ b/activesupport/test/ordered_hash_test.rb @@ -162,4 +162,10 @@ class OrderedHashTest < Test::Unit::TestCase def test_inspect assert @ordered_hash.inspect.include?(@hash.inspect) end + + def test_alternate_initialization + alternate = ActiveSupport::OrderedHash[1,2,3,4] + assert_kind_of ActiveSupport::OrderedHash, alternate + assert_equal [1, 3], alternate.keys + end end -- cgit v1.2.3 From c1d120a71e74aa3ccab6dc28a5406b87a51a69c1 Mon Sep 17 00:00:00 2001 From: Yehuda Katz + Carl Lerche Date: Mon, 11 May 2009 11:48:38 -0700 Subject: Don't run the action if callbacks are halted. In AbstractController, this means that response_body is not empty --- activesupport/test/new_callbacks_test.rb | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'activesupport/test') diff --git a/activesupport/test/new_callbacks_test.rb b/activesupport/test/new_callbacks_test.rb index 8c887e1bf1..dec6106ac1 100644 --- a/activesupport/test/new_callbacks_test.rb +++ b/activesupport/test/new_callbacks_test.rb @@ -365,7 +365,7 @@ module NewCallbacksTest save_callback :after, :third - attr_reader :history + attr_reader :history, :saved def initialize @history = [] end @@ -390,7 +390,9 @@ module NewCallbacksTest end def save - _run_save_callbacks + _run_save_callbacks do + @saved = true + end end end @@ -400,6 +402,12 @@ module NewCallbacksTest terminator.save assert_equal ["first", "second", "third", "second", "first"], terminator.history end + + def test_block_never_called_if_terminated + obj = CallbackTerminator.new + obj.save + assert !obj.saved + end end class HyphenatedKeyTest < Test::Unit::TestCase @@ -407,6 +415,6 @@ module NewCallbacksTest obj = HyphenatedCallbacks.new obj.save assert_equal obj.stuff, "OMG" - end + end end end -- cgit v1.2.3 From 53dda29f8b34073a4b135ee224c1d09c1f10de02 Mon Sep 17 00:00:00 2001 From: Brian Lopez Date: Sun, 17 May 2009 10:37:30 -0500 Subject: Add support for parsing XML and JSON from an IO as well as a string [#2659 state:resolved] Signed-off-by: Joshua Peek --- activesupport/test/xml_mini/nokogiri_engine_test.rb | 13 +++++++++++++ activesupport/test/xml_mini/rexml_engine_test.rb | 14 ++++++++++++++ 2 files changed, 27 insertions(+) (limited to 'activesupport/test') diff --git a/activesupport/test/xml_mini/nokogiri_engine_test.rb b/activesupport/test/xml_mini/nokogiri_engine_test.rb index 886a9d1aba..7c3a591e63 100644 --- a/activesupport/test/xml_mini/nokogiri_engine_test.rb +++ b/activesupport/test/xml_mini/nokogiri_engine_test.rb @@ -148,6 +148,19 @@ class NokogiriEngineTest < Test::Unit::TestCase eoxml end + def test_parse_from_io + io = StringIO.new(<<-eoxml) + + good + + hello everyone + + morning + + eoxml + XmlMini.parse(io) + end + private def assert_equal_rexml(xml) hash = XmlMini.with_backend('REXML') { XmlMini.parse(xml) } diff --git a/activesupport/test/xml_mini/rexml_engine_test.rb b/activesupport/test/xml_mini/rexml_engine_test.rb index a412d8ca05..57bb35254a 100644 --- a/activesupport/test/xml_mini/rexml_engine_test.rb +++ b/activesupport/test/xml_mini/rexml_engine_test.rb @@ -12,4 +12,18 @@ class REXMLEngineTest < Test::Unit::TestCase XmlMini.backend = 'REXML' assert_equal XmlMini_REXML, XmlMini.backend end + + def test_parse_from_io + XmlMini.backend = 'REXML' + io = StringIO.new(<<-eoxml) + + good + + hello everyone + + morning + + eoxml + XmlMini.parse(io) + end end -- cgit v1.2.3 From e89241c92fbcf68b59d9efb50c21c5040e9f3156 Mon Sep 17 00:00:00 2001 From: rick Date: Sun, 17 May 2009 19:16:11 -0700 Subject: load the JSON Backend lazily. If the JSON gem is already loaded, use the JSONGem backend by default. --- activesupport/test/json/decoding_test.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'activesupport/test') diff --git a/activesupport/test/json/decoding_test.rb b/activesupport/test/json/decoding_test.rb index 7e1bfcca84..09fd0d09ba 100644 --- a/activesupport/test/json/decoding_test.rb +++ b/activesupport/test/json/decoding_test.rb @@ -36,6 +36,9 @@ class TestJSONDecoding < ActiveSupport::TestCase %q({"b":["\u003ci\u003e","\u003cb\u003e","\u003cu\u003e"]}) => {'b' => ["","",""]} } + # load the default JSON backend + ActiveSupport::JSON.backend + backends = %w(Yaml) begin gem 'json', '>= 1.1' -- cgit v1.2.3 From 29550cc91f8dcbfe3e4020986d719c77ddd2f14d Mon Sep 17 00:00:00 2001 From: Joe Van Dyk Date: Mon, 2 Feb 2009 16:43:14 -0800 Subject: Add ability to get multiple memcached keys at the same time (via MemCacheStore#read_multi). Signed-off-by: Jeremy Kemper --- activesupport/test/caching_test.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'activesupport/test') diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb index 8bb0c155cf..b845796fe5 100644 --- a/activesupport/test/caching_test.rb +++ b/activesupport/test/caching_test.rb @@ -251,6 +251,15 @@ uses_memcached 'memcached backed store' do end end + def test_multi_get + @cache.with_local_cache do + @cache.write('foo', 1) + @cache.write('goo', 2) + result = @cache.read_multi('foo', 'goo') + assert_equal({'foo' => 1, 'goo' => 2}, result) + end + end + def test_middleware app = lambda { |env| result = @cache.write('foo', 'bar') -- cgit v1.2.3 From e2ed1a1ca4f2dbfb9eb2c31fd1ddd45562afef25 Mon Sep 17 00:00:00 2001 From: Bryan Helmkamp Date: Tue, 19 May 2009 10:24:26 -0400 Subject: Allow MemCacheStore to be initialized with a MemCache object instead of addresses and options --- activesupport/test/caching_test.rb | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'activesupport/test') diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb index b845796fe5..ad19dcfd09 100644 --- a/activesupport/test/caching_test.rb +++ b/activesupport/test/caching_test.rb @@ -15,22 +15,28 @@ class CacheStoreSettingTest < ActiveSupport::TestCase end def test_mem_cache_fragment_cache_store + MemCache.expects(:new).with(%w[localhost], {}) store = ActiveSupport::Cache.lookup_store :mem_cache_store, "localhost" assert_kind_of(ActiveSupport::Cache::MemCacheStore, store) - assert_equal %w(localhost), store.addresses + end + + def test_mem_cache_fragment_cache_store_with_given_mem_cache + mem_cache = MemCache.new + MemCache.expects(:new).never + store = ActiveSupport::Cache.lookup_store :mem_cache_store, mem_cache + assert_kind_of(ActiveSupport::Cache::MemCacheStore, store) end def test_mem_cache_fragment_cache_store_with_multiple_servers + MemCache.expects(:new).with(%w[localhost 192.168.1.1], {}) store = ActiveSupport::Cache.lookup_store :mem_cache_store, "localhost", '192.168.1.1' assert_kind_of(ActiveSupport::Cache::MemCacheStore, store) - assert_equal %w(localhost 192.168.1.1), store.addresses end def test_mem_cache_fragment_cache_store_with_options + MemCache.expects(:new).with(%w[localhost 192.168.1.1], { :namespace => "foo" }) store = ActiveSupport::Cache.lookup_store :mem_cache_store, "localhost", '192.168.1.1', :namespace => 'foo' assert_kind_of(ActiveSupport::Cache::MemCacheStore, store) - assert_equal %w(localhost 192.168.1.1), store.addresses - assert_equal 'foo', store.instance_variable_get('@data').instance_variable_get('@namespace') end def test_object_assigned_fragment_cache_store -- cgit v1.2.3 From 36058f45040b5559fd8f6a44a17ead27a6b3d2f7 Mon Sep 17 00:00:00 2001 From: Bryan Helmkamp Date: Tue, 19 May 2009 19:51:38 -0400 Subject: Use duck typing to also allow MemCache-like object when initializing a MemCacheStore Signed-off-by: Jeremy Kemper --- activesupport/test/caching_test.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'activesupport/test') diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb index ad19dcfd09..bd237a5c8e 100644 --- a/activesupport/test/caching_test.rb +++ b/activesupport/test/caching_test.rb @@ -27,6 +27,12 @@ class CacheStoreSettingTest < ActiveSupport::TestCase assert_kind_of(ActiveSupport::Cache::MemCacheStore, store) end + def test_mem_cache_fragment_cache_store_with_given_mem_cache_like_object + MemCache.expects(:new).never + store = ActiveSupport::Cache.lookup_store :mem_cache_store, stub("memcache", :get => true) + assert_kind_of(ActiveSupport::Cache::MemCacheStore, store) + end + def test_mem_cache_fragment_cache_store_with_multiple_servers MemCache.expects(:new).with(%w[localhost 192.168.1.1], {}) store = ActiveSupport::Cache.lookup_store :mem_cache_store, "localhost", '192.168.1.1' -- cgit v1.2.3 From 67247ca8ee850223193a5fe77f5460aefc0336c0 Mon Sep 17 00:00:00 2001 From: Yehuda Katz + Carl Lerche Date: Tue, 19 May 2009 17:41:17 -0700 Subject: Corrected new callbacks semantics with regards to using objects for around filters. --- activesupport/test/new_callbacks_test.rb | 62 ++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) (limited to 'activesupport/test') diff --git a/activesupport/test/new_callbacks_test.rb b/activesupport/test/new_callbacks_test.rb index dec6106ac1..7bec47224d 100644 --- a/activesupport/test/new_callbacks_test.rb +++ b/activesupport/test/new_callbacks_test.rb @@ -396,6 +396,68 @@ module NewCallbacksTest end end + class CallbackObject + def before_save(caller) + caller.record << "before" + end + + def around_save(caller) + caller.record << "around before" + yield + caller.record << "around after" + end + end + + class UsingObjectBefore + include ActiveSupport::NewCallbacks + + define_callbacks :save + save_callback :before, CallbackObject.new + + attr_accessor :record + def initialize + @record = [] + end + + def save + _run_save_callbacks do + @record << "yielded" + end + end + end + + class UsingObjectAround + include ActiveSupport::NewCallbacks + + define_callbacks :save + save_callback :around, CallbackObject.new + + attr_accessor :record + def initialize + @record = [] + end + + def save + _run_save_callbacks do + @record << "yielded" + end + end + end + + class UsingObjectTest < Test::Unit::TestCase + def test_before_object + u = UsingObjectBefore.new + u.save + assert_equal ["before", "yielded"], u.record + end + + def test_around_object + u = UsingObjectAround.new + u.save + assert_equal ["around before", "yielded", "around after"], u.record + end + end + class CallbackTerminatorTest < Test::Unit::TestCase def test_termination terminator = CallbackTerminator.new -- cgit v1.2.3 From 5a036457620b7fb22027dc4f0c399871db6ed0c3 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Thu, 21 May 2009 03:04:17 +0200 Subject: Allow Module#depends_on to accept multiple modules --- activesupport/test/dependency_module_test.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'activesupport/test') diff --git a/activesupport/test/dependency_module_test.rb b/activesupport/test/dependency_module_test.rb index 07090d15a1..be7db0fa7b 100644 --- a/activesupport/test/dependency_module_test.rb +++ b/activesupport/test/dependency_module_test.rb @@ -42,6 +42,12 @@ class DependencyModuleTest < Test::Unit::TestCase end end + module Foo + extend ActiveSupport::DependencyModule + + depends_on Bar, Baz + end + def setup @klass = Class.new end @@ -74,4 +80,9 @@ class DependencyModuleTest < Test::Unit::TestCase assert_equal "baz", @klass.baz assert_equal [DependencyModuleTest::Bar, DependencyModuleTest::Baz], @klass.included_modules[0..1] end + + def test_depends_on_with_multiple_modules + @klass.send(:include, Foo) + assert_equal [DependencyModuleTest::Foo, DependencyModuleTest::Bar, DependencyModuleTest::Baz], @klass.included_modules[0..2] + end end -- cgit v1.2.3 From 5f222c524ed00b2ac805e267f70a916cf8f9bc77 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 20 May 2009 17:11:41 -0700 Subject: Remove 'core' fluff. Hookable ActiveSupport.load_all! --- activesupport/test/core_ext/duration_test.rb | 2 +- activesupport/test/core_ext/numeric_ext_test.rb | 2 +- activesupport/test/core_ext/object_and_class_ext_test.rb | 2 +- activesupport/test/core_ext/time_ext_test.rb | 2 +- activesupport/test/i18n_test.rb | 2 +- activesupport/test/time_zone_test.rb | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) (limited to 'activesupport/test') diff --git a/activesupport/test/core_ext/duration_test.rb b/activesupport/test/core_ext/duration_test.rb index 30d4152729..6f16621ae5 100644 --- a/activesupport/test/core_ext/duration_test.rb +++ b/activesupport/test/core_ext/duration_test.rb @@ -1,5 +1,5 @@ require 'abstract_unit' -require 'active_support/core/time' +require 'active_support/time' class DurationTest < ActiveSupport::TestCase def test_inspect diff --git a/activesupport/test/core_ext/numeric_ext_test.rb b/activesupport/test/core_ext/numeric_ext_test.rb index 74b086fa9c..992ec60302 100644 --- a/activesupport/test/core_ext/numeric_ext_test.rb +++ b/activesupport/test/core_ext/numeric_ext_test.rb @@ -1,7 +1,7 @@ require 'abstract_unit' +require 'active_support/time' 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 8869b053e6..f0121b862d 100644 --- a/activesupport/test/core_ext/object_and_class_ext_test.rb +++ b/activesupport/test/core_ext/object_and_class_ext_test.rb @@ -1,7 +1,7 @@ require 'abstract_unit' +require 'active_support/time' 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/time_ext_test.rb b/activesupport/test/core_ext/time_ext_test.rb index e265423f06..1c2d0fbce4 100644 --- a/activesupport/test/core_ext/time_ext_test.rb +++ b/activesupport/test/core_ext/time_ext_test.rb @@ -1,5 +1,5 @@ require 'abstract_unit' -require 'active_support/core/time' +require 'active_support/time' class TimeExtCalculationsTest < Test::Unit::TestCase def test_seconds_since_midnight diff --git a/activesupport/test/i18n_test.rb b/activesupport/test/i18n_test.rb index 2a08abfb3e..9868f1e87d 100644 --- a/activesupport/test/i18n_test.rb +++ b/activesupport/test/i18n_test.rb @@ -1,5 +1,5 @@ require 'abstract_unit' -require 'active_support/core/time' +require 'active_support/time' require 'active_support/core_ext/array/conversions' class I18nTest < Test::Unit::TestCase diff --git a/activesupport/test/time_zone_test.rb b/activesupport/test/time_zone_test.rb index 87d6ccc30d..99c4310854 100644 --- a/activesupport/test/time_zone_test.rb +++ b/activesupport/test/time_zone_test.rb @@ -1,5 +1,5 @@ require 'abstract_unit' -require 'active_support/core/time' +require 'active_support/time' class TimeZoneTest < Test::Unit::TestCase def test_utc_to_local -- cgit v1.2.3 From 6ef329d3250cfc3a21184cc2a8248aa18a1f6815 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Wed, 27 May 2009 14:54:58 -0500 Subject: Ensure Memcache local cache returns duplicated values [#2302 state:resolved] --- activesupport/test/caching_test.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'activesupport/test') diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb index bd237a5c8e..51d04d9388 100644 --- a/activesupport/test/caching_test.rb +++ b/activesupport/test/caching_test.rb @@ -180,6 +180,15 @@ uses_memcached 'memcached backed store' do end end + def test_stored_objects_should_not_be_frozen + @cache.with_local_cache do + @cache.write('foo', 'bar') + end + @cache.with_local_cache do + assert !@cache.read('foo').frozen? + end + end + def test_write_should_return_true_on_success @cache.with_local_cache do result = @cache.write('foo', 'bar') -- cgit v1.2.3 From 4e50a35fa243f6cf7ad567774a9f7c1cb87a1653 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Thu, 28 May 2009 11:35:36 -0500 Subject: Break up DependencyModule's dual function of providing a "depend_on" DSL and "included" block DSL into separate modules. But, unify both approaches under AS::Concern. --- activesupport/test/concern_test.rb | 88 ++++++++++++++++++++++++++++ activesupport/test/dependency_module_test.rb | 88 ---------------------------- 2 files changed, 88 insertions(+), 88 deletions(-) create mode 100644 activesupport/test/concern_test.rb delete mode 100644 activesupport/test/dependency_module_test.rb (limited to 'activesupport/test') diff --git a/activesupport/test/concern_test.rb b/activesupport/test/concern_test.rb new file mode 100644 index 0000000000..22f7ec2064 --- /dev/null +++ b/activesupport/test/concern_test.rb @@ -0,0 +1,88 @@ +require 'abstract_unit' +require 'active_support/concern' + +class ConcernTest < Test::Unit::TestCase + module Baz + extend ActiveSupport::Concern + + module ClassMethods + def baz + "baz" + end + + def included_ran=(value) + @@included_ran = value + end + + def included_ran + @@included_ran + end + end + + included do + self.included_ran = true + end + + def baz + "baz" + end + end + + module Bar + extend ActiveSupport::Concern + + depends_on Baz + + def bar + "bar" + end + + def baz + "bar+" + super + end + end + + module Foo + extend ActiveSupport::Concern + + depends_on Bar, Baz + end + + def setup + @klass = Class.new + end + + def test_module_is_included_normally + @klass.send(:include, Baz) + assert_equal "baz", @klass.new.baz + assert_equal ConcernTest::Baz, @klass.included_modules[0] + + @klass.send(:include, Baz) + assert_equal "baz", @klass.new.baz + assert_equal ConcernTest::Baz, @klass.included_modules[0] + end + + def test_class_methods_are_extended + @klass.send(:include, Baz) + assert_equal "baz", @klass.baz + assert_equal ConcernTest::Baz::ClassMethods, (class << @klass; self.included_modules; end)[0] + end + + def test_included_block_is_ran + @klass.send(:include, Baz) + assert_equal true, @klass.included_ran + end + + def test_modules_dependencies_are_met + @klass.send(:include, Bar) + assert_equal "bar", @klass.new.bar + assert_equal "bar+baz", @klass.new.baz + assert_equal "baz", @klass.baz + assert_equal [ConcernTest::Bar, ConcernTest::Baz], @klass.included_modules[0..1] + end + + def test_depends_on_with_multiple_modules + @klass.send(:include, Foo) + assert_equal [ConcernTest::Foo, ConcernTest::Bar, ConcernTest::Baz], @klass.included_modules[0..2] + end +end diff --git a/activesupport/test/dependency_module_test.rb b/activesupport/test/dependency_module_test.rb deleted file mode 100644 index be7db0fa7b..0000000000 --- a/activesupport/test/dependency_module_test.rb +++ /dev/null @@ -1,88 +0,0 @@ -require 'abstract_unit' -require 'active_support/dependency_module' - -class DependencyModuleTest < Test::Unit::TestCase - module Baz - extend ActiveSupport::DependencyModule - - module ClassMethods - def baz - "baz" - end - - def included_ran=(value) - @@included_ran = value - end - - def included_ran - @@included_ran - end - end - - included do - self.included_ran = true - end - - def baz - "baz" - end - end - - module Bar - extend ActiveSupport::DependencyModule - - depends_on Baz - - def bar - "bar" - end - - def baz - "bar+" + super - end - end - - module Foo - extend ActiveSupport::DependencyModule - - depends_on Bar, Baz - end - - def setup - @klass = Class.new - end - - def test_module_is_included_normally - @klass.send(:include, Baz) - assert_equal "baz", @klass.new.baz - assert_equal DependencyModuleTest::Baz, @klass.included_modules[0] - - @klass.send(:include, Baz) - assert_equal "baz", @klass.new.baz - assert_equal DependencyModuleTest::Baz, @klass.included_modules[0] - end - - def test_class_methods_are_extended - @klass.send(:include, Baz) - assert_equal "baz", @klass.baz - assert_equal DependencyModuleTest::Baz::ClassMethods, (class << @klass; self.included_modules; end)[0] - end - - def test_included_block_is_ran - @klass.send(:include, Baz) - assert_equal true, @klass.included_ran - end - - def test_modules_dependencies_are_met - @klass.send(:include, Bar) - assert_equal "bar", @klass.new.bar - assert_equal "bar+baz", @klass.new.baz - assert_equal "baz", @klass.baz - assert_equal [DependencyModuleTest::Bar, DependencyModuleTest::Baz], @klass.included_modules[0..1] - end - - def test_depends_on_with_multiple_modules - @klass.send(:include, Foo) - assert_equal [DependencyModuleTest::Foo, DependencyModuleTest::Bar, DependencyModuleTest::Baz], @klass.included_modules[0..2] - end -end -- cgit v1.2.3