diff options
Diffstat (limited to 'activesupport/test')
33 files changed, 77 insertions, 73 deletions
diff --git a/activesupport/test/abstract_unit.rb b/activesupport/test/abstract_unit.rb index a0c0c59e47..428a06b0bf 100644 --- a/activesupport/test/abstract_unit.rb +++ b/activesupport/test/abstract_unit.rb @@ -4,16 +4,19 @@ require 'test/unit' gem 'mocha', '>= 0.9.5' require 'mocha' +ENV['NO_RELOAD'] = '1' $:.unshift "#{File.dirname(__FILE__)}/../lib" require 'active_support' require 'active_support/test_case' def uses_memcached(test_name) require 'memcache' - MemCache.new('localhost').stats - yield -rescue MemCache::MemCacheError - $stderr.puts "Skipping #{test_name} tests. Start memcached and try again." + begin + MemCache.new('localhost').stats + yield + rescue MemCache::MemCacheError + $stderr.puts "Skipping #{test_name} tests. Start memcached and try again." + end end def with_kcode(code) diff --git a/activesupport/test/buffered_logger_test.rb b/activesupport/test/buffered_logger_test.rb index e178ced06d..d48c7fcc54 100644 --- a/activesupport/test/buffered_logger_test.rb +++ b/activesupport/test/buffered_logger_test.rb @@ -1,6 +1,7 @@ require 'abstract_unit' require 'stringio' require 'fileutils' +require 'active_support/buffered_logger' class BufferedLoggerTest < Test::Unit::TestCase def setup diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb index 4e212f1661..8bb0c155cf 100644 --- a/activesupport/test/caching_test.rb +++ b/activesupport/test/caching_test.rb @@ -1,4 +1,5 @@ require 'abstract_unit' +require 'active_support/cache' class CacheKeyTest < ActiveSupport::TestCase def test_expand_cache_key @@ -13,12 +14,6 @@ class CacheStoreSettingTest < ActiveSupport::TestCase assert_equal "/path/to/cache/directory", store.cache_path end - def test_drb_fragment_cache_store - store = ActiveSupport::Cache.lookup_store :drb_store, "druby://localhost:9192" - assert_kind_of(ActiveSupport::Cache::DRbStore, store) - assert_equal "druby://localhost:9192", store.address - end - def test_mem_cache_fragment_cache_store store = ActiveSupport::Cache.lookup_store :mem_cache_store, "localhost" assert_kind_of(ActiveSupport::Cache::MemCacheStore, store) diff --git a/activesupport/test/callbacks_test.rb b/activesupport/test/callbacks_test.rb index 2bc2e1eaf0..2f747e2238 100644 --- a/activesupport/test/callbacks_test.rb +++ b/activesupport/test/callbacks_test.rb @@ -7,11 +7,11 @@ class Record 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) diff --git a/activesupport/test/clean_logger_test.rb b/activesupport/test/clean_logger_test.rb index 269dd2a620..6c4ec5ac46 100644 --- a/activesupport/test/clean_logger_test.rb +++ b/activesupport/test/clean_logger_test.rb @@ -1,5 +1,6 @@ require 'abstract_unit' require 'stringio' +require 'active_support/core_ext/logger' class CleanLoggerTest < Test::Unit::TestCase def setup diff --git a/activesupport/test/core_ext/array_ext_test.rb b/activesupport/test/core_ext/array_ext_test.rb index b70ec475ad..112cb998b1 100644 --- a/activesupport/test/core_ext/array_ext_test.rb +++ b/activesupport/test/core_ext/array_ext_test.rb @@ -1,5 +1,6 @@ require 'abstract_unit' -require 'bigdecimal' +require 'active_support/core_ext/array' +require 'active_support/core_ext/big_decimal' class ArrayExtAccessTests < Test::Unit::TestCase def test_from diff --git a/activesupport/test/core_ext/cgi_ext_test.rb b/activesupport/test/core_ext/cgi_ext_test.rb index 320efd405f..c80362e382 100644 --- a/activesupport/test/core_ext/cgi_ext_test.rb +++ b/activesupport/test/core_ext/cgi_ext_test.rb @@ -1,4 +1,5 @@ require 'abstract_unit' +require 'active_support/core_ext/cgi' class EscapeSkippingSlashesTest < Test::Unit::TestCase def test_array diff --git a/activesupport/test/core_ext/class/delegating_attributes_test.rb b/activesupport/test/core_ext/class/delegating_attributes_test.rb index 8fc08a0250..b51d68551d 100644 --- a/activesupport/test/core_ext/class/delegating_attributes_test.rb +++ b/activesupport/test/core_ext/class/delegating_attributes_test.rb @@ -1,4 +1,5 @@ require 'abstract_unit' +require 'active_support/core_ext/class/delegating_attributes' module DelegatingFixtures class Parent diff --git a/activesupport/test/core_ext/class_test.rb b/activesupport/test/core_ext/class_test.rb index 48d8a78acf..bb4eb3c7d5 100644 --- a/activesupport/test/core_ext/class_test.rb +++ b/activesupport/test/core_ext/class_test.rb @@ -1,4 +1,5 @@ require 'abstract_unit' +require 'active_support/core_ext/class' class A end diff --git a/activesupport/test/core_ext/date_ext_test.rb b/activesupport/test/core_ext/date_ext_test.rb index 1001868c77..7fd551eaf3 100644 --- a/activesupport/test/core_ext/date_ext_test.rb +++ b/activesupport/test/core_ext/date_ext_test.rb @@ -1,4 +1,5 @@ require 'abstract_unit' +require 'active_support/core_ext/date' class DateExtCalculationsTest < Test::Unit::TestCase def test_to_s diff --git a/activesupport/test/core_ext/duration_test.rb b/activesupport/test/core_ext/duration_test.rb index 8954295d10..d4a4627e3e 100644 --- a/activesupport/test/core_ext/duration_test.rb +++ b/activesupport/test/core_ext/duration_test.rb @@ -60,26 +60,6 @@ class DurationTest < ActiveSupport::TestCase assert_equal((7 * 24 * 1.7).hours.ago, 1.7.weeks.ago) end - def test_deprecated_fractional_years - years_re = /Fractional years are not respected\. Convert value to integer before calling #years\./ - assert_deprecated(years_re){1.0.years} - assert_deprecated(years_re){1.5.years} - assert_not_deprecated{1.years} - assert_deprecated(years_re){1.0.year} - assert_deprecated(years_re){1.5.year} - assert_not_deprecated{1.year} - end - - def test_deprecated_fractional_months - months_re = /Fractional months are not respected\. Convert value to integer before calling #months\./ - assert_deprecated(months_re){1.5.months} - assert_deprecated(months_re){1.0.months} - assert_not_deprecated{1.months} - assert_deprecated(months_re){1.5.month} - assert_deprecated(months_re){1.0.month} - assert_not_deprecated{1.month} - end - def test_since_and_ago_anchored_to_time_now_when_time_zone_default_not_set Time.zone_default = nil with_env_tz 'US/Eastern' do diff --git a/activesupport/test/core_ext/enumerable_test.rb b/activesupport/test/core_ext/enumerable_test.rb index 92db977a77..885393815b 100644 --- a/activesupport/test/core_ext/enumerable_test.rb +++ b/activesupport/test/core_ext/enumerable_test.rb @@ -1,4 +1,6 @@ require 'abstract_unit' +require 'active_support/core_ext/array' +require 'active_support/core_ext/enumerable' Payment = Struct.new(:price) class SummablePayment < Payment diff --git a/activesupport/test/core_ext/file_test.rb b/activesupport/test/core_ext/file_test.rb index eedc6b592b..26be694176 100644 --- a/activesupport/test/core_ext/file_test.rb +++ b/activesupport/test/core_ext/file_test.rb @@ -1,4 +1,5 @@ require 'abstract_unit' +require 'active_support/core_ext/file' class AtomicWriteTest < Test::Unit::TestCase def test_atomic_write_without_errors diff --git a/activesupport/test/core_ext/float_ext_test.rb b/activesupport/test/core_ext/float_ext_test.rb index d19b5ecf47..ac7e7a8ed6 100644 --- a/activesupport/test/core_ext/float_ext_test.rb +++ b/activesupport/test/core_ext/float_ext_test.rb @@ -1,4 +1,5 @@ require 'abstract_unit' +require 'active_support/core_ext/float/rounding' class FloatExtRoundingTests < Test::Unit::TestCase def test_round_for_positive_number diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb index 0edac72fe7..bbb1c631f9 100644 --- a/activesupport/test/core_ext/hash_ext_test.rb +++ b/activesupport/test/core_ext/hash_ext_test.rb @@ -1,5 +1,5 @@ require 'abstract_unit' -require 'builder' +require 'active_support/core_ext/hash' class HashExtTest < Test::Unit::TestCase def setup diff --git a/activesupport/test/core_ext/integer_ext_test.rb b/activesupport/test/core_ext/integer_ext_test.rb index b7006a5c86..956ae5189d 100644 --- a/activesupport/test/core_ext/integer_ext_test.rb +++ b/activesupport/test/core_ext/integer_ext_test.rb @@ -1,4 +1,5 @@ require 'abstract_unit' +require 'active_support/core_ext/integer' class IntegerExtTest < Test::Unit::TestCase def test_even diff --git a/activesupport/test/core_ext/kernel_test.rb b/activesupport/test/core_ext/kernel_test.rb index e826ec161d..1dfc283268 100644 --- a/activesupport/test/core_ext/kernel_test.rb +++ b/activesupport/test/core_ext/kernel_test.rb @@ -1,4 +1,5 @@ require 'abstract_unit' +require 'active_support/core_ext/kernel' class KernelTest < Test::Unit::TestCase def test_silence_warnings @@ -41,3 +42,18 @@ class KernelTest < Test::Unit::TestCase assert_equal 1, silence_stderr { 1 } end end + +class KernelSupressTest < Test::Unit::TestCase + def test_reraise + assert_raise(LoadError) do + suppress(ArgumentError) { raise LoadError } + end + end + + def test_supression + suppress(ArgumentError) { raise ArgumentError } + suppress(LoadError) { raise LoadError } + suppress(LoadError, ArgumentError) { raise LoadError } + suppress(LoadError, ArgumentError) { raise ArgumentError } + end +end diff --git a/activesupport/test/core_ext/load_error_test.rb b/activesupport/test/core_ext/load_error_test.rb index cfa8f978af..b775b65f9f 100644 --- a/activesupport/test/core_ext/load_error_test.rb +++ b/activesupport/test/core_ext/load_error_test.rb @@ -1,4 +1,5 @@ require 'abstract_unit' +require 'active_support/core_ext/load_error' class TestMissingSourceFile < Test::Unit::TestCase def test_with_require 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/core_ext/module/synchronization_test.rb b/activesupport/test/core_ext/module/synchronization_test.rb index c28bc9b073..43d65ab249 100644 --- a/activesupport/test/core_ext/module/synchronization_test.rb +++ b/activesupport/test/core_ext/module/synchronization_test.rb @@ -1,5 +1,8 @@ require 'abstract_unit' +require 'active_support/core_ext/class/attribute_accessors' +require 'active_support/core_ext/module/synchronization' + class SynchronizationTest < Test::Unit::TestCase def setup @target = Class.new @@ -82,4 +85,4 @@ class SynchronizationTest < Test::Unit::TestCase assert_nothing_raised { @target.to_s; @target.to_s } assert_equal 2, @target.mutex.sync_count end -end
\ No newline at end of file +end diff --git a/activesupport/test/core_ext/module_test.rb b/activesupport/test/core_ext/module_test.rb index 0d3d10f333..c3c696f93a 100644 --- a/activesupport/test/core_ext/module_test.rb +++ b/activesupport/test/core_ext/module_test.rb @@ -1,4 +1,5 @@ require 'abstract_unit' +require 'active_support/core_ext/module' module One Constant1 = "Hello World" diff --git a/activesupport/test/core_ext/numeric_ext_test.rb b/activesupport/test/core_ext/numeric_ext_test.rb index 5401ed7c7e..9cca4d3aaf 100644 --- a/activesupport/test/core_ext/numeric_ext_test.rb +++ b/activesupport/test/core_ext/numeric_ext_test.rb @@ -1,5 +1,7 @@ require 'abstract_unit' +require 'active_support/core_ext/numeric/bytes' + class NumericExtTimeAndDateTimeTest < Test::Unit::TestCase def setup @now = Time.local(2005,2,10,15,30,45) @@ -145,18 +147,3 @@ class NumericExtSizeTest < Test::Unit::TestCase assert_equal 3458764513820540928, 3.exabyte end end - -class NumericExtConversionsTest < Test::Unit::TestCase - - def test_to_utc_offset_s_with_colon - assert_equal "-06:00", -21_600.to_utc_offset_s - assert_equal "+00:00", 0.to_utc_offset_s - assert_equal "+05:00", 18_000.to_utc_offset_s - end - - def test_to_utc_offset_s_without_colon - assert_equal "-0600", -21_600.to_utc_offset_s(false) - assert_equal "+0000", 0.to_utc_offset_s(false) - assert_equal "+0500", 18_000.to_utc_offset_s(false) - end -end 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 b6515e05a0..c919698c0f 100644 --- a/activesupport/test/core_ext/object_and_class_ext_test.rb +++ b/activesupport/test/core_ext/object_and_class_ext_test.rb @@ -1,4 +1,5 @@ require 'abstract_unit' +require 'active_support/core_ext/object' class ClassA; end class ClassB < ClassA; end @@ -108,16 +109,6 @@ class ClassExtTest < Test::Unit::TestCase end class ObjectTests < Test::Unit::TestCase - def test_suppress_re_raises - assert_raise(LoadError) { suppress(ArgumentError) {raise LoadError} } - end - def test_suppress_supresses - suppress(ArgumentError) { raise ArgumentError } - suppress(LoadError) { raise LoadError } - suppress(LoadError, ArgumentError) { raise LoadError } - suppress(LoadError, ArgumentError) { raise ArgumentError } - end - def test_extended_by foo = Foo.new assert foo.extended_by.include?(Bar) diff --git a/activesupport/test/core_ext/pathname_test.rb b/activesupport/test/core_ext/pathname_test.rb deleted file mode 100644 index d17e8bb255..0000000000 --- a/activesupport/test/core_ext/pathname_test.rb +++ /dev/null @@ -1,9 +0,0 @@ -require 'abstract_unit' - -class TestPathname < Test::Unit::TestCase - def test_clean_within - assert_equal "Hi", Pathname.clean_within("Hi") - assert_equal "Hi", Pathname.clean_within("Hi/a/b/../..") - assert_equal "Hello\nWorld", Pathname.clean_within("Hello/a/b/../..\na/b/../../World/c/..") - end -end diff --git a/activesupport/test/core_ext/range_ext_test.rb b/activesupport/test/core_ext/range_ext_test.rb index 38253d4d25..76e05e9954 100644 --- a/activesupport/test/core_ext/range_ext_test.rb +++ b/activesupport/test/core_ext/range_ext_test.rb @@ -1,4 +1,5 @@ require 'abstract_unit' +require 'active_support/core_ext/range' 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 6c9b7e7236..a357ba5852 100644 --- a/activesupport/test/core_ext/string_ext_test.rb +++ b/activesupport/test/core_ext/string_ext_test.rb @@ -3,6 +3,8 @@ require 'date' require 'abstract_unit' require 'inflector_test_cases' +require 'active_support/core_ext/string' + class StringInflectionsTest < Test::Unit::TestCase include InflectorTestCases @@ -132,10 +134,12 @@ class StringInflectionsTest < Test::Unit::TestCase assert_equal "h", s.first assert_equal "he", s.first(2) + assert_equal "", s.first(0) assert_equal "o", s.last assert_equal "llo", s.last(3) assert_equal "hello", s.last(10) + assert_equal "", s.last(0) assert_equal 'x', 'x'.first assert_equal 'x', 'x'.first(4) diff --git a/activesupport/test/core_ext/time_with_zone_test.rb b/activesupport/test/core_ext/time_with_zone_test.rb index 7be19e7900..3dec4c95f4 100644 --- a/activesupport/test/core_ext/time_with_zone_test.rb +++ b/activesupport/test/core_ext/time_with_zone_test.rb @@ -1,4 +1,5 @@ require 'abstract_unit' +require 'active_support/time_with_zone' class TimeWithZoneTest < Test::Unit::TestCase diff --git a/activesupport/test/core_ext/uri_ext_test.rb b/activesupport/test/core_ext/uri_ext_test.rb index 0837d3cb2d..2d4f38d095 100644 --- a/activesupport/test/core_ext/uri_ext_test.rb +++ b/activesupport/test/core_ext/uri_ext_test.rb @@ -1,5 +1,6 @@ require 'abstract_unit' require 'uri' +require 'active_support/core_ext/uri' class URIExtTest < Test::Unit::TestCase def test_uri_decode_handle_multibyte 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 diff --git a/activesupport/test/json/decoding_test.rb b/activesupport/test/json/decoding_test.rb index 8fe40557d6..9b4b207c88 100644 --- a/activesupport/test/json/decoding_test.rb +++ b/activesupport/test/json/decoding_test.rb @@ -1,7 +1,8 @@ # encoding: UTF-8 require 'abstract_unit' +require 'active_support/json' -class TestJSONDecoding < Test::Unit::TestCase +class TestJSONDecoding < ActiveSupport::TestCase TESTS = { %q({"returnTo":{"\/categories":"\/"}}) => {"returnTo" => {"/categories" => "/"}}, %q({returnTo:{"\/categories":"\/"}}) => {"returnTo" => {"/categories" => "/"}}, @@ -36,7 +37,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 diff --git a/activesupport/test/json/encoding_test.rb b/activesupport/test/json/encoding_test.rb index 7d2eedad61..9e6b4fa501 100644 --- a/activesupport/test/json/encoding_test.rb +++ b/activesupport/test/json/encoding_test.rb @@ -1,5 +1,6 @@ # encoding: utf-8 require 'abstract_unit' +require 'active_support/json' class TestJSONEncoding < Test::Unit::TestCase class Foo diff --git a/activesupport/test/option_merger_test.rb b/activesupport/test/option_merger_test.rb index f26d61617d..b898292c9c 100644 --- a/activesupport/test/option_merger_test.rb +++ b/activesupport/test/option_merger_test.rb @@ -1,4 +1,5 @@ require 'abstract_unit' +require 'active_support/core_ext/object/misc' class OptionMergerTest < Test::Unit::TestCase def setup diff --git a/activesupport/test/time_zone_test.rb b/activesupport/test/time_zone_test.rb index b01f62460a..7e8047566e 100644 --- a/activesupport/test/time_zone_test.rb +++ b/activesupport/test/time_zone_test.rb @@ -196,6 +196,18 @@ class TimeZoneTest < Test::Unit::TestCase assert_equal(-18_000, zone.utc_offset) end + def test_seconds_to_utc_offset_with_colon + assert_equal "-06:00", ActiveSupport::TimeZone.seconds_to_utc_offset(-21_600) + assert_equal "+00:00", ActiveSupport::TimeZone.seconds_to_utc_offset(0) + assert_equal "+05:00", ActiveSupport::TimeZone.seconds_to_utc_offset(18_000) + end + + def test_seconds_to_utc_offset_without_colon + assert_equal "-0600", ActiveSupport::TimeZone.seconds_to_utc_offset(-21_600, false) + assert_equal "+0000", ActiveSupport::TimeZone.seconds_to_utc_offset(0, false) + assert_equal "+0500", ActiveSupport::TimeZone.seconds_to_utc_offset(18_000, false) + end + def test_formatted_offset_positive zone = ActiveSupport::TimeZone['Moscow'] assert_equal "+03:00", zone.formatted_offset |