diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2008-06-03 22:38:27 -0700 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2008-06-03 22:38:27 -0700 |
commit | 53bcbfbdc1eed45cc6615e59d36baf018ab43d96 (patch) | |
tree | 691441d50ef7e49b5317ce279329bcaa1d135744 /activesupport/test | |
parent | f55ad960d22337d0d92a93724f1cc3ad45200836 (diff) | |
parent | 82e96eb294ae21528c3e05e91c05c7ee5222afbd (diff) | |
download | rails-53bcbfbdc1eed45cc6615e59d36baf018ab43d96.tar.gz rails-53bcbfbdc1eed45cc6615e59d36baf018ab43d96.tar.bz2 rails-53bcbfbdc1eed45cc6615e59d36baf018ab43d96.zip |
Merge branch 'master' into erbout
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/core_ext/array_ext_test.rb | 26 | ||||
-rw-r--r-- | activesupport/test/core_ext/date_ext_test.rb | 14 | ||||
-rw-r--r-- | activesupport/test/core_ext/date_time_ext_test.rb | 24 | ||||
-rw-r--r-- | activesupport/test/core_ext/duration_test.rb | 8 | ||||
-rw-r--r-- | activesupport/test/core_ext/time_ext_test.rb | 28 | ||||
-rw-r--r-- | activesupport/test/core_ext/time_with_zone_test.rb | 240 | ||||
-rw-r--r-- | activesupport/test/dependencies_test.rb | 240 | ||||
-rw-r--r-- | activesupport/test/deprecation_test.rb | 10 | ||||
-rw-r--r-- | activesupport/test/inflector_test.rb | 126 | ||||
-rw-r--r-- | activesupport/test/ordered_hash_test.rb | 19 | ||||
-rw-r--r-- | activesupport/test/ordered_options_test.rb | 6 | ||||
-rw-r--r-- | activesupport/test/string_questioneer_test.rb | 15 | ||||
-rw-r--r-- | activesupport/test/time_zone_test.rb | 135 |
13 files changed, 466 insertions, 425 deletions
diff --git a/activesupport/test/core_ext/array_ext_test.rb b/activesupport/test/core_ext/array_ext_test.rb index 20bc5dfcb7..73fbeb8b6b 100644 --- a/activesupport/test/core_ext/array_ext_test.rb +++ b/activesupport/test/core_ext/array_ext_test.rb @@ -21,7 +21,7 @@ class ArrayExtToParamTests < Test::Unit::TestCase "#{self}1" end end - + def test_string_array assert_equal '', %w().to_param assert_equal 'hello/world', %w(hello world).to_param @@ -31,7 +31,7 @@ class ArrayExtToParamTests < Test::Unit::TestCase def test_number_array assert_equal '10/20', [10, 20].to_param end - + def test_to_param_array assert_equal 'custom1/param1', [ToParam.new('custom'), ToParam.new('param')].to_param end @@ -222,10 +222,10 @@ class ArrayToXmlTests < Test::Unit::TestCase assert xml.include?(%(<count>2</count>)), xml end - + def test_to_xml_with_empty xml = [].to_xml - assert_match /type="array"\/>/, xml + assert_match(/type="array"\/>/, xml) end end @@ -239,17 +239,15 @@ class ArrayExtractOptionsTests < Test::Unit::TestCase end uses_mocha "ArrayExtRandomTests" do + class ArrayExtRandomTests < Test::Unit::TestCase + def test_random_element_from_array + assert_nil [].rand -class ArrayExtRandomTests < Test::Unit::TestCase - def test_random_element_from_array - assert_nil [].rand - - Kernel.expects(:rand).with(1).returns(0) - assert_equal 'x', ['x'].rand + Kernel.expects(:rand).with(1).returns(0) + assert_equal 'x', ['x'].rand - Kernel.expects(:rand).with(3).returns(1) - assert_equal 2, [1, 2, 3].rand + Kernel.expects(:rand).with(3).returns(1) + assert_equal 2, [1, 2, 3].rand + end end end - -end diff --git a/activesupport/test/core_ext/date_ext_test.rb b/activesupport/test/core_ext/date_ext_test.rb index 11b6056047..ddfe1f904f 100644 --- a/activesupport/test/core_ext/date_ext_test.rb +++ b/activesupport/test/core_ext/date_ext_test.rb @@ -172,7 +172,7 @@ class DateExtCalculationsTest < Test::Unit::TestCase def test_last_month_on_31st assert_equal Date.new(2004, 2, 29), Date.new(2004, 3, 31).last_month - end + end def test_yesterday_constructor assert_equal Date.today - 1, Date.yesterday @@ -197,11 +197,11 @@ class DateExtCalculationsTest < Test::Unit::TestCase def test_end_of_day assert_equal Time.local(2005,2,21,23,59,59), Date.new(2005,2,21).end_of_day end - + def test_date_acts_like_date assert Date.new.acts_like_date? end - + def test_xmlschema with_env_tz 'US/Eastern' do assert_match(/^1980-02-28T00:00:00-05:?00$/, Date.new(1980, 2, 28).xmlschema) @@ -213,7 +213,7 @@ class DateExtCalculationsTest < Test::Unit::TestCase end end end - + uses_mocha 'TestDateCurrent' do def test_current_returns_date_today_when_zone_default_not_set with_env_tz 'US/Central' do @@ -222,10 +222,10 @@ class DateExtCalculationsTest < Test::Unit::TestCase assert_equal Date.new(1999, 12, 31), Date.current end end - + def test_current_returns_time_zone_today_when_zone_default_set silence_warnings do # silence warnings raised by tzinfo gem - Time.zone_default = TimeZone['Eastern Time (US & Canada)'] + Time.zone_default = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] with_env_tz 'US/Central' do Time.stubs(:now).returns Time.local(1999, 12, 31, 23) assert_equal Date.new(1999, 12, 31), Date.today @@ -243,5 +243,5 @@ class DateExtCalculationsTest < Test::Unit::TestCase yield ensure old_tz ? ENV['TZ'] = old_tz : ENV.delete('TZ') - end + end end diff --git a/activesupport/test/core_ext/date_time_ext_test.rb b/activesupport/test/core_ext/date_time_ext_test.rb index ed45daf403..854a3a05e1 100644 --- a/activesupport/test/core_ext/date_time_ext_test.rb +++ b/activesupport/test/core_ext/date_time_ext_test.rb @@ -219,14 +219,14 @@ class DateTimeExtCalculationsTest < Test::Unit::TestCase assert_equal Rational(-6, 24), DateTime.local_offset end end - + def test_utc? assert_equal true, DateTime.civil(2005, 2, 21, 10, 11, 12).utc? assert_equal true, DateTime.civil(2005, 2, 21, 10, 11, 12, 0).utc? assert_equal false, DateTime.civil(2005, 2, 21, 10, 11, 12, 0.25).utc? assert_equal false, DateTime.civil(2005, 2, 21, 10, 11, 12, -0.25).utc? end - + def test_utc_offset assert_equal 0, DateTime.civil(2005, 2, 21, 10, 11, 12).utc_offset assert_equal 0, DateTime.civil(2005, 2, 21, 10, 11, 12, 0).utc_offset @@ -234,7 +234,7 @@ class DateTimeExtCalculationsTest < Test::Unit::TestCase assert_equal( -21600, DateTime.civil(2005, 2, 21, 10, 11, 12, -0.25).utc_offset ) assert_equal( -18000, DateTime.civil(2005, 2, 21, 10, 11, 12, Rational(-5, 24)).utc_offset ) end - + def test_utc assert_equal DateTime.civil(2005, 2, 21, 16, 11, 12, 0), DateTime.civil(2005, 2, 21, 10, 11, 12, Rational(-6, 24)).utc assert_equal DateTime.civil(2005, 2, 21, 15, 11, 12, 0), DateTime.civil(2005, 2, 21, 10, 11, 12, Rational(-5, 24)).utc @@ -242,37 +242,37 @@ class DateTimeExtCalculationsTest < Test::Unit::TestCase assert_equal DateTime.civil(2005, 2, 21, 9, 11, 12, 0), DateTime.civil(2005, 2, 21, 10, 11, 12, Rational(1, 24)).utc assert_equal DateTime.civil(2005, 2, 21, 9, 11, 12, 0), DateTime.civil(2005, 2, 21, 10, 11, 12, Rational(1, 24)).getutc end - + def test_formatted_offset_with_utc assert_equal '+00:00', DateTime.civil(2000).formatted_offset assert_equal '+0000', DateTime.civil(2000).formatted_offset(false) assert_equal 'UTC', DateTime.civil(2000).formatted_offset(true, 'UTC') end - + def test_formatted_offset_with_local dt = DateTime.civil(2005, 2, 21, 10, 11, 12, Rational(-5, 24)) assert_equal '-05:00', dt.formatted_offset assert_equal '-0500', dt.formatted_offset(false) end - + def test_compare_with_time assert_equal 1, DateTime.civil(2000) <=> Time.utc(1999, 12, 31, 23, 59, 59) assert_equal 0, DateTime.civil(2000) <=> Time.utc(2000, 1, 1, 0, 0, 0) assert_equal(-1, DateTime.civil(2000) <=> Time.utc(2000, 1, 1, 0, 0, 1)) end - + def test_compare_with_datetime assert_equal 1, DateTime.civil(2000) <=> DateTime.civil(1999, 12, 31, 23, 59, 59) assert_equal 0, DateTime.civil(2000) <=> DateTime.civil(2000, 1, 1, 0, 0, 0) assert_equal(-1, DateTime.civil(2000) <=> DateTime.civil(2000, 1, 1, 0, 0, 1)) end - + def test_compare_with_time_with_zone - assert_equal 1, DateTime.civil(2000) <=> ActiveSupport::TimeWithZone.new( Time.utc(1999, 12, 31, 23, 59, 59), TimeZone['UTC'] ) - assert_equal 0, DateTime.civil(2000) <=> ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 0, 0, 0), TimeZone['UTC'] ) - assert_equal(-1, DateTime.civil(2000) <=> ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 0, 0, 1), TimeZone['UTC'] )) + assert_equal 1, DateTime.civil(2000) <=> ActiveSupport::TimeWithZone.new( Time.utc(1999, 12, 31, 23, 59, 59), ActiveSupport::TimeZone['UTC'] ) + assert_equal 0, DateTime.civil(2000) <=> ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 0, 0, 0), ActiveSupport::TimeZone['UTC'] ) + assert_equal(-1, DateTime.civil(2000) <=> ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 0, 0, 1), ActiveSupport::TimeZone['UTC'] )) end - + def test_to_f assert_equal 946684800.0, DateTime.civil(2000).to_f assert_equal 946684800.0, DateTime.civil(1999,12,31,19,0,0,Rational(-5,24)).to_f diff --git a/activesupport/test/core_ext/duration_test.rb b/activesupport/test/core_ext/duration_test.rb index 7b17fe71db..f802ed8760 100644 --- a/activesupport/test/core_ext/duration_test.rb +++ b/activesupport/test/core_ext/duration_test.rb @@ -29,7 +29,7 @@ class DurationTest < Test::Unit::TestCase flunk("ArgumentError should be raised, but we got #{$!.class} instead") end end - + uses_mocha 'TestDurationSinceAndAgoWithCurrentTime' do def test_since_and_ago_anchored_to_time_now_when_time_zone_default_not_set Time.zone_default = nil @@ -43,10 +43,10 @@ class DurationTest < Test::Unit::TestCase assert_equal Time.local(1999,12,31,23,59,55), 5.seconds.ago end end - + def test_since_and_ago_anchored_to_time_zone_now_when_time_zone_default_set silence_warnings do # silence warnings raised by tzinfo gem - Time.zone_default = TimeZone['Eastern Time (US & Canada)'] + Time.zone_default = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] with_env_tz 'US/Eastern' do Time.stubs(:now).returns Time.local(2000) # since @@ -63,7 +63,7 @@ class DurationTest < Test::Unit::TestCase Time.zone_default = nil end end - + protected def with_env_tz(new_tz = 'US/Eastern') old_tz, ENV['TZ'] = ENV['TZ'], new_tz diff --git a/activesupport/test/core_ext/time_ext_test.rb b/activesupport/test/core_ext/time_ext_test.rb index e53b7193ea..17a0968c0e 100644 --- a/activesupport/test/core_ext/time_ext_test.rb +++ b/activesupport/test/core_ext/time_ext_test.rb @@ -449,7 +449,7 @@ class TimeExtCalculationsTest < Test::Unit::TestCase assert_equal "17:44", time.to_s(:time) assert_equal "February 21, 2005 17:44", time.to_s(:long) assert_equal "February 21st, 2005 17:44", time.to_s(:long_ordinal) - with_env_tz "UTC" do + with_env_tz "UTC" do assert_equal "Mon, 21 Feb 2005 17:44:30 +0000", time.to_s(:rfc822) end end @@ -505,13 +505,13 @@ class TimeExtCalculationsTest < Test::Unit::TestCase assert_equal 30, Time.days_in_month(11, 2005) assert_equal 31, Time.days_in_month(12, 2005) end - + uses_mocha 'TestTimeDaysInMonthWithoutYearArg' do def test_days_in_month_feb_in_common_year_without_year_arg Time.stubs(:now).returns(Time.utc(2007)) assert_equal 28, Time.days_in_month(2) end - + def test_days_in_month_feb_in_leap_year_without_year_arg Time.stubs(:now).returns(Time.utc(2008)) assert_equal 29, Time.days_in_month(2) @@ -559,13 +559,13 @@ class TimeExtCalculationsTest < Test::Unit::TestCase def test_acts_like_time assert Time.new.acts_like_time? end - + def test_formatted_offset_with_utc assert_equal '+00:00', Time.utc(2000).formatted_offset assert_equal '+0000', Time.utc(2000).formatted_offset(false) assert_equal 'UTC', Time.utc(2000).formatted_offset(true, 'UTC') end - + def test_formatted_offset_with_local with_env_tz 'US/Eastern' do assert_equal '-05:00', Time.local(2000).formatted_offset @@ -574,27 +574,27 @@ class TimeExtCalculationsTest < Test::Unit::TestCase assert_equal '-0400', Time.local(2000, 7).formatted_offset(false) end end - + def test_compare_with_time assert_equal 1, Time.utc(2000) <=> Time.utc(1999, 12, 31, 23, 59, 59, 999) assert_equal 0, Time.utc(2000) <=> Time.utc(2000, 1, 1, 0, 0, 0) assert_equal(-1, Time.utc(2000) <=> Time.utc(2000, 1, 1, 0, 0, 0, 001)) end - + def test_compare_with_datetime assert_equal 1, Time.utc(2000) <=> DateTime.civil(1999, 12, 31, 23, 59, 59) assert_equal 0, Time.utc(2000) <=> DateTime.civil(2000, 1, 1, 0, 0, 0) assert_equal(-1, Time.utc(2000) <=> DateTime.civil(2000, 1, 1, 0, 0, 1)) end - + def test_compare_with_time_with_zone - assert_equal 1, Time.utc(2000) <=> ActiveSupport::TimeWithZone.new( Time.utc(1999, 12, 31, 23, 59, 59), TimeZone['UTC'] ) - assert_equal 0, Time.utc(2000) <=> ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 0, 0, 0), TimeZone['UTC'] ) - assert_equal(-1, Time.utc(2000) <=> ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 0, 0, 1), TimeZone['UTC'] )) + assert_equal 1, Time.utc(2000) <=> ActiveSupport::TimeWithZone.new( Time.utc(1999, 12, 31, 23, 59, 59), ActiveSupport::TimeZone['UTC'] ) + assert_equal 0, Time.utc(2000) <=> ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 0, 0, 0), ActiveSupport::TimeZone['UTC'] ) + assert_equal(-1, Time.utc(2000) <=> ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 0, 0, 1), ActiveSupport::TimeZone['UTC'] )) end - + def test_minus_with_time_with_zone - assert_equal 86_400.0, Time.utc(2000, 1, 2) - ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1), TimeZone['UTC'] ) + assert_equal 86_400.0, Time.utc(2000, 1, 2) - ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1), ActiveSupport::TimeZone['UTC'] ) end def test_time_created_with_local_constructor_cannot_represent_times_during_hour_skipped_by_dst @@ -608,7 +608,7 @@ class TimeExtCalculationsTest < Test::Unit::TestCase def test_case_equality assert Time === Time.utc(2000) - assert Time === ActiveSupport::TimeWithZone.new(Time.utc(2000), TimeZone['UTC']) + assert Time === ActiveSupport::TimeWithZone.new(Time.utc(2000), ActiveSupport::TimeZone['UTC']) assert_equal false, Time === DateTime.civil(2000) end diff --git a/activesupport/test/core_ext/time_with_zone_test.rb b/activesupport/test/core_ext/time_with_zone_test.rb index c373bca88d..012ec373c9 100644 --- a/activesupport/test/core_ext/time_with_zone_test.rb +++ b/activesupport/test/core_ext/time_with_zone_test.rb @@ -1,10 +1,10 @@ require 'abstract_unit' - + class TimeWithZoneTest < Test::Unit::TestCase def setup @utc = Time.utc(2000, 1, 1, 0) - @time_zone = TimeZone['Eastern Time (US & Canada)'] + @time_zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] @twz = ActiveSupport::TimeWithZone.new(@utc, @time_zone) end @@ -21,114 +21,114 @@ class TimeWithZoneTest < Test::Unit::TestCase def test_time_zone assert_equal @time_zone, @twz.time_zone end - + def test_in_time_zone Time.use_zone 'Alaska' do - assert_equal ActiveSupport::TimeWithZone.new(@utc, TimeZone['Alaska']), @twz.in_time_zone + assert_equal ActiveSupport::TimeWithZone.new(@utc, ActiveSupport::TimeZone['Alaska']), @twz.in_time_zone end end def test_in_time_zone_with_argument - assert_equal ActiveSupport::TimeWithZone.new(@utc, TimeZone['Alaska']), @twz.in_time_zone('Alaska') + assert_equal ActiveSupport::TimeWithZone.new(@utc, ActiveSupport::TimeZone['Alaska']), @twz.in_time_zone('Alaska') end - + def test_in_time_zone_with_new_zone_equal_to_old_zone_does_not_create_new_object - assert_equal @twz.object_id, @twz.in_time_zone(TimeZone['Eastern Time (US & Canada)']).object_id + assert_equal @twz.object_id, @twz.in_time_zone(ActiveSupport::TimeZone['Eastern Time (US & Canada)']).object_id end def test_utc? assert_equal false, @twz.utc? - assert_equal true, ActiveSupport::TimeWithZone.new(Time.utc(2000), TimeZone['UTC']).utc? + assert_equal true, ActiveSupport::TimeWithZone.new(Time.utc(2000), ActiveSupport::TimeZone['UTC']).utc? end - + def test_formatted_offset silence_warnings do # silence warnings raised by tzinfo gem assert_equal '-05:00', @twz.formatted_offset assert_equal '-04:00', ActiveSupport::TimeWithZone.new(Time.utc(2000, 6), @time_zone).formatted_offset #dst end end - + def test_dst? silence_warnings do # silence warnings raised by tzinfo gem assert_equal false, @twz.dst? assert_equal true, ActiveSupport::TimeWithZone.new(Time.utc(2000, 6), @time_zone).dst? end end - + def test_zone silence_warnings do # silence warnings raised by tzinfo gem assert_equal 'EST', @twz.zone assert_equal 'EDT', ActiveSupport::TimeWithZone.new(Time.utc(2000, 6), @time_zone).zone #dst end end - + def test_to_json silence_warnings do # silence warnings raised by tzinfo gem assert_equal "\"1999/12/31 19:00:00 -0500\"", @twz.to_json end 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 ensure ActiveSupport.use_standard_json_time_format = old end - + def test_strftime silence_warnings do # silence warnings raised by tzinfo gem assert_equal '1999-12-31 19:00:00 EST -0500', @twz.strftime('%Y-%m-%d %H:%M:%S %Z %z') end end - + def test_inspect silence_warnings do # silence warnings raised by tzinfo gem assert_equal 'Fri, 31 Dec 1999 19:00:00 EST -05:00', @twz.inspect end end - + def test_to_s silence_warnings do # silence warnings raised by tzinfo gem assert_equal '1999-12-31 19:00:00 -0500', @twz.to_s end end - + def test_to_s_db silence_warnings do # silence warnings raised by tzinfo gem assert_equal '2000-01-01 00:00:00', @twz.to_s(:db) end end - + def test_xmlschema silence_warnings do # silence warnings raised by tzinfo gem assert_equal "1999-12-31T19:00:00-05:00", @twz.xmlschema end end - + def test_to_yaml silence_warnings do # silence warnings raised by tzinfo gem assert_equal "--- 1999-12-31 19:00:00 -05:00\n", @twz.to_yaml end end - + def test_ruby_to_yaml silence_warnings do assert_equal "--- \n:twz: 2000-01-01 00:00:00 Z\n", {:twz => @twz}.to_yaml end end - + def test_httpdate silence_warnings do # silence warnings raised by tzinfo gem assert_equal 'Sat, 01 Jan 2000 00:00:00 GMT', @twz.httpdate end end - + def test_rfc2822 silence_warnings do # silence warnings raised by tzinfo gem assert_equal "Fri, 31 Dec 1999 19:00:00 -0500", @twz.rfc2822 end end - + def test_compare_with_time assert_equal 1, @twz <=> Time.utc(1999, 12, 31, 23, 59, 59) assert_equal 0, @twz <=> Time.utc(2000, 1, 1, 0, 0, 0) @@ -142,27 +142,27 @@ class TimeWithZoneTest < Test::Unit::TestCase end def test_compare_with_time_with_zone - assert_equal 1, @twz <=> ActiveSupport::TimeWithZone.new( Time.utc(1999, 12, 31, 23, 59, 59), TimeZone['UTC'] ) - assert_equal 0, @twz <=> ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 0, 0, 0), TimeZone['UTC'] ) - assert_equal(-1, @twz <=> ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 0, 0, 1), TimeZone['UTC'] )) + assert_equal 1, @twz <=> ActiveSupport::TimeWithZone.new( Time.utc(1999, 12, 31, 23, 59, 59), ActiveSupport::TimeZone['UTC'] ) + assert_equal 0, @twz <=> ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 0, 0, 0), ActiveSupport::TimeZone['UTC'] ) + assert_equal(-1, @twz <=> ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 0, 0, 1), ActiveSupport::TimeZone['UTC'] )) end - + def test_between? assert @twz.between?(Time.utc(1999,12,31,23,59,59), Time.utc(2000,1,1,0,0,1)) assert_equal false, @twz.between?(Time.utc(2000,1,1,0,0,1), Time.utc(2000,1,1,0,0,2)) end - + def test_eql? assert @twz.eql?(Time.utc(2000)) - assert @twz.eql?( ActiveSupport::TimeWithZone.new(Time.utc(2000), TimeZone["Hawaii"]) ) + assert @twz.eql?( ActiveSupport::TimeWithZone.new(Time.utc(2000), ActiveSupport::TimeZone["Hawaii"]) ) end - + def test_plus_with_integer silence_warnings do # silence warnings raised by tzinfo gem assert_equal Time.utc(1999, 12, 31, 19, 0 ,5), (@twz + 5).time end end - + def test_plus_with_integer_when_self_wraps_datetime silence_warnings do # silence warnings raised by tzinfo gem datetime = DateTime.civil(2000, 1, 1, 0) @@ -170,26 +170,26 @@ class TimeWithZoneTest < Test::Unit::TestCase assert_equal DateTime.civil(1999, 12, 31, 19, 0 ,5), (twz + 5).time end end - + def test_plus_when_crossing_time_class_limit silence_warnings do # silence warnings raised by tzinfo gem twz = ActiveSupport::TimeWithZone.new(Time.utc(2038, 1, 19), @time_zone) assert_equal [0, 0, 19, 19, 1, 2038], (twz + 86_400).to_a[0,6] end end - + def test_plus_with_duration silence_warnings do # silence warnings raised by tzinfo gem assert_equal Time.utc(2000, 1, 5, 19, 0 ,0), (@twz + 5.days).time end end - + def test_minus_with_integer silence_warnings do # silence warnings raised by tzinfo gem assert_equal Time.utc(1999, 12, 31, 18, 59 ,55), (@twz - 5).time end end - + def test_minus_with_integer_when_self_wraps_datetime silence_warnings do # silence warnings raised by tzinfo gem datetime = DateTime.civil(2000, 1, 1, 0) @@ -197,24 +197,24 @@ class TimeWithZoneTest < Test::Unit::TestCase assert_equal DateTime.civil(1999, 12, 31, 18, 59 ,55), (twz - 5).time end end - + def test_minus_with_duration silence_warnings do # silence warnings raised by tzinfo gem assert_equal Time.utc(1999, 12, 26, 19, 0 ,0), (@twz - 5.days).time end end - + def test_minus_with_time - assert_equal 86_400.0, ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 2), TimeZone['UTC'] ) - Time.utc(2000, 1, 1) - assert_equal 86_400.0, ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 2), TimeZone['Hawaii'] ) - Time.utc(2000, 1, 1) + assert_equal 86_400.0, ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 2), ActiveSupport::TimeZone['UTC'] ) - Time.utc(2000, 1, 1) + assert_equal 86_400.0, ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 2), ActiveSupport::TimeZone['Hawaii'] ) - Time.utc(2000, 1, 1) end - + def test_minus_with_time_with_zone - twz1 = ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1), TimeZone['UTC'] ) - twz2 = ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 2), TimeZone['UTC'] ) + twz1 = ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1), ActiveSupport::TimeZone['UTC'] ) + twz2 = ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 2), ActiveSupport::TimeZone['UTC'] ) assert_equal 86_400.0, twz2 - twz1 end - + def test_plus_and_minus_enforce_spring_dst_rules silence_warnings do # silence warnings raised by tzinfo gem utc = Time.utc(2006,4,2,6,59,59) # == Apr 2 2006 01:59:59 EST; i.e., 1 second before daylight savings start @@ -232,7 +232,7 @@ class TimeWithZoneTest < Test::Unit::TestCase assert_equal 'EST', twz.zone end end - + def test_plus_and_minus_enforce_fall_dst_rules silence_warnings do # silence warnings raised by tzinfo gem utc = Time.utc(2006,10,29,5,59,59) # == Oct 29 2006 01:59:59 EST; i.e., 1 second before daylight savings end @@ -250,25 +250,25 @@ class TimeWithZoneTest < Test::Unit::TestCase assert_equal 'EDT', twz.zone end end - + def test_to_a silence_warnings do # silence warnings raised by tzinfo gem - assert_equal [45, 30, 5, 1, 2, 2000, 2, 32, false, "HST"], ActiveSupport::TimeWithZone.new( Time.utc(2000, 2, 1, 15, 30, 45), TimeZone['Hawaii'] ).to_a + assert_equal [45, 30, 5, 1, 2, 2000, 2, 32, false, "HST"], ActiveSupport::TimeWithZone.new( Time.utc(2000, 2, 1, 15, 30, 45), ActiveSupport::TimeZone['Hawaii'] ).to_a end end - + def test_to_f - result = ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1), TimeZone['Hawaii'] ).to_f + result = ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1), ActiveSupport::TimeZone['Hawaii'] ).to_f assert_equal 946684800.0, result assert result.is_a?(Float) end - + def test_to_i - result = ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1), TimeZone['Hawaii'] ).to_i + result = ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1), ActiveSupport::TimeZone['Hawaii'] ).to_i assert_equal 946684800, result assert result.is_a?(Integer) end - + def test_to_time assert_equal @twz, @twz.to_time end @@ -276,55 +276,55 @@ class TimeWithZoneTest < Test::Unit::TestCase def test_to_date silence_warnings do # silence warnings raised by tzinfo gem # 1 sec before midnight Jan 1 EST - assert_equal Date.new(1999, 12, 31), ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 4, 59, 59), TimeZone['Eastern Time (US & Canada)'] ).to_date + assert_equal Date.new(1999, 12, 31), ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 4, 59, 59), ActiveSupport::TimeZone['Eastern Time (US & Canada)'] ).to_date # midnight Jan 1 EST - assert_equal Date.new(2000, 1, 1), ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 5, 0, 0), TimeZone['Eastern Time (US & Canada)'] ).to_date + assert_equal Date.new(2000, 1, 1), ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 5, 0, 0), ActiveSupport::TimeZone['Eastern Time (US & Canada)'] ).to_date # 1 sec before midnight Jan 2 EST - assert_equal Date.new(2000, 1, 1), ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 2, 4, 59, 59), TimeZone['Eastern Time (US & Canada)'] ).to_date + assert_equal Date.new(2000, 1, 1), ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 2, 4, 59, 59), ActiveSupport::TimeZone['Eastern Time (US & Canada)'] ).to_date # midnight Jan 2 EST - assert_equal Date.new(2000, 1, 2), ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 2, 5, 0, 0), TimeZone['Eastern Time (US & Canada)'] ).to_date + assert_equal Date.new(2000, 1, 2), ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 2, 5, 0, 0), ActiveSupport::TimeZone['Eastern Time (US & Canada)'] ).to_date end end - + def test_to_datetime silence_warnings do # silence warnings raised by tzinfo gem assert_equal DateTime.civil(1999, 12, 31, 19, 0, 0, Rational(-18_000, 86_400)), @twz.to_datetime end end - + def test_acts_like_time assert @twz.acts_like?(:time) assert ActiveSupport::TimeWithZone.new(DateTime.civil(2000), @time_zone).acts_like?(:time) end - + def test_acts_like_date assert_equal false, @twz.acts_like?(:date) assert_equal false, ActiveSupport::TimeWithZone.new(DateTime.civil(2000), @time_zone).acts_like?(:date) end - + def test_is_a assert @twz.is_a?(Time) assert @twz.kind_of?(Time) assert @twz.is_a?(ActiveSupport::TimeWithZone) end - + def test_method_missing_with_time_return_value silence_warnings do # silence warnings raised by tzinfo gem assert_instance_of ActiveSupport::TimeWithZone, @twz.months_since(1) assert_equal Time.utc(2000, 1, 31, 19, 0 ,0), @twz.months_since(1).time end end - + def test_marshal_dump_and_load silence_warnings do # silence warnings raised by tzinfo gem marshal_str = Marshal.dump(@twz) mtime = Marshal.load(marshal_str) assert_equal Time.utc(2000, 1, 1, 0), mtime.utc - assert_equal TimeZone['Eastern Time (US & Canada)'], mtime.time_zone + assert_equal ActiveSupport::TimeZone['Eastern Time (US & Canada)'], mtime.time_zone assert_equal Time.utc(1999, 12, 31, 19), mtime.time end end - + def test_marshal_dump_and_load_with_tzinfo_identifier silence_warnings do # silence warnings raised by tzinfo gem twz = ActiveSupport::TimeWithZone.new(@utc, TZInfo::Timezone.get('America/New_York')) @@ -335,14 +335,14 @@ class TimeWithZoneTest < Test::Unit::TestCase assert_equal Time.utc(1999, 12, 31, 19), mtime.time end end - + def test_method_missing_with_non_time_return_value silence_warnings do # silence warnings raised by tzinfo gem @twz.time.expects(:foo).returns('bar') assert_equal 'bar', @twz.foo end end - + def test_date_part_value_methods silence_warnings do # silence warnings raised by tzinfo gem twz = ActiveSupport::TimeWithZone.new(Time.utc(1999,12,31,19,18,17,500), @time_zone) @@ -356,14 +356,14 @@ class TimeWithZoneTest < Test::Unit::TestCase assert_equal 500, twz.usec end end - + def test_usec_returns_0_when_datetime_is_wrapped silence_warnings do # silence warnings raised by tzinfo gem twz = ActiveSupport::TimeWithZone.new(DateTime.civil(2000), @time_zone) assert_equal 0, twz.usec end end - + def test_utc_to_local_conversion_saves_period_in_instance_variable silence_warnings do # silence warnings raised by tzinfo gem assert_nil @twz.instance_variable_get('@period') @@ -371,14 +371,14 @@ class TimeWithZoneTest < Test::Unit::TestCase assert_kind_of TZInfo::TimezonePeriod, @twz.instance_variable_get('@period') end end - + def test_instance_created_with_local_time_returns_correct_utc_time silence_warnings do # silence warnings raised by tzinfo gem twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(1999, 12, 31, 19)) assert_equal Time.utc(2000), twz.utc end end - + def test_instance_created_with_local_time_enforces_spring_dst_rules silence_warnings do # silence warnings raised by tzinfo gem twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(2006,4,2,2)) # first second of DST @@ -387,7 +387,7 @@ class TimeWithZoneTest < Test::Unit::TestCase assert_equal 'EDT', twz.zone end end - + def test_instance_created_with_local_time_enforces_fall_dst_rules silence_warnings do # silence warnings raised by tzinfo gem twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(2006,10,29,1)) # 1AM can be either DST or non-DST; we'll pick DST @@ -396,14 +396,14 @@ class TimeWithZoneTest < Test::Unit::TestCase assert_equal 'EDT', twz.zone end end - + def test_ruby_19_weekday_name_query_methods ruby_19_or_greater = RUBY_VERSION >= '1.9' %w(sunday? monday? tuesday? wednesday? thursday? friday? saturday?).each do |name| assert_equal ruby_19_or_greater, @twz.respond_to?(name) end end - + def test_utc_to_local_conversion_with_far_future_datetime silence_warnings do # silence warnings raised by tzinfo gem assert_equal [0,0,19,31,12,2049], ActiveSupport::TimeWithZone.new(DateTime.civil(2050), @time_zone).to_a[0,6] @@ -415,7 +415,7 @@ class TimeWithZoneTest < Test::Unit::TestCase assert_equal DateTime.civil(2050).to_f, ActiveSupport::TimeWithZone.new(nil, @time_zone, DateTime.civil(2049,12,31,19)).to_f end end - + def test_change assert_equal "Fri, 31 Dec 1999 19:00:00 EST -05:00", @twz.inspect assert_equal "Mon, 31 Dec 2001 19:00:00 EST -05:00", @twz.change(:year => 2001).inspect @@ -426,7 +426,7 @@ class TimeWithZoneTest < Test::Unit::TestCase assert_equal "Fri, 31 Dec 1999 19:15:00 EST -05:00", @twz.change(:min => 15).inspect assert_equal "Fri, 31 Dec 1999 19:00:30 EST -05:00", @twz.change(:sec => 30).inspect end - + def test_advance assert_equal "Fri, 31 Dec 1999 19:00:00 EST -05:00", @twz.inspect assert_equal "Mon, 31 Dec 2001 19:00:00 EST -05:00", @twz.advance(:years => 2).inspect @@ -436,77 +436,77 @@ class TimeWithZoneTest < Test::Unit::TestCase assert_equal "Fri, 31 Dec 1999 19:15:00 EST -05:00", @twz.advance(:minutes => 15).inspect assert_equal "Fri, 31 Dec 1999 19:00:30 EST -05:00", @twz.advance(:seconds => 30).inspect end - + def beginning_of_year assert_equal "Fri, 31 Dec 1999 19:00:00 EST -05:00", @twz.inspect assert_equal "Fri, 01 Jan 1999 00:00:00 EST -05:00", @twz.beginning_of_year.inspect end - + def end_of_year assert_equal "Fri, 31 Dec 1999 19:00:00 EST -05:00", @twz.inspect assert_equal "Fri, 31 Dec 1999 23:59:59 EST -05:00", @twz.end_of_year.inspect end - + def beginning_of_month assert_equal "Fri, 31 Dec 1999 19:00:00 EST -05:00", @twz.inspect assert_equal "Fri, 01 Dec 1999 00:00:00 EST -05:00", @twz.beginning_of_month.inspect end - + def end_of_month assert_equal "Fri, 31 Dec 1999 19:00:00 EST -05:00", @twz.inspect assert_equal "Fri, 31 Dec 1999 23:59:59 EST -05:00", @twz.end_of_month.inspect end - + def beginning_of_day assert_equal "Fri, 31 Dec 1999 19:00:00 EST -05:00", @twz.inspect assert_equal "Fri, 31 Dec 1999 00:00:00 EST -05:00", @twz.beginning_of_day.inspect end - + def end_of_day assert_equal "Fri, 31 Dec 1999 19:00:00 EST -05:00", @twz.inspect assert_equal "Fri, 31 Dec 1999 23:59:59 EST -05:00", @twz.end_of_day.inspect end - + def test_since assert_equal "Fri, 31 Dec 1999 19:00:01 EST -05:00", @twz.since(1).inspect end - + def test_ago assert_equal "Fri, 31 Dec 1999 18:59:59 EST -05:00", @twz.ago(1).inspect end - + def test_seconds_since_midnight assert_equal 19 * 60 * 60, @twz.seconds_since_midnight end - + def test_advance_1_year_from_leap_day twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(2004,2,29)) assert_equal "Mon, 28 Feb 2005 00:00:00 EST -05:00", twz.advance(:years => 1).inspect assert_equal "Mon, 28 Feb 2005 00:00:00 EST -05:00", twz.years_since(1).inspect assert_equal "Mon, 28 Feb 2005 00:00:00 EST -05:00", (twz + 1.year).inspect end - + def test_advance_1_month_from_last_day_of_january twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(2005,1,31)) assert_equal "Mon, 28 Feb 2005 00:00:00 EST -05:00", twz.advance(:months => 1).inspect assert_equal "Mon, 28 Feb 2005 00:00:00 EST -05:00", twz.months_since(1).inspect assert_equal "Mon, 28 Feb 2005 00:00:00 EST -05:00", (twz + 1.month).inspect end - + def test_advance_1_month_from_last_day_of_january_during_leap_year twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(2000,1,31)) assert_equal "Tue, 29 Feb 2000 00:00:00 EST -05:00", twz.advance(:months => 1).inspect assert_equal "Tue, 29 Feb 2000 00:00:00 EST -05:00", twz.months_since(1).inspect assert_equal "Tue, 29 Feb 2000 00:00:00 EST -05:00", (twz + 1.month).inspect end - + def test_advance_1_month_into_spring_dst_gap twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(2006,3,2,2)) assert_equal "Sun, 02 Apr 2006 03:00:00 EDT -04:00", twz.advance(:months => 1).inspect assert_equal "Sun, 02 Apr 2006 03:00:00 EDT -04:00", twz.months_since(1).inspect assert_equal "Sun, 02 Apr 2006 03:00:00 EDT -04:00", (twz + 1.month).inspect end - + def test_advance_1_second_into_spring_dst_gap twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(2006,4,2,1,59,59)) assert_equal "Sun, 02 Apr 2006 03:00:00 EDT -04:00", twz.advance(:seconds => 1).inspect @@ -519,11 +519,11 @@ class TimeWithZoneMethodsForTimeAndDateTimeTest < Test::Unit::TestCase def setup @t, @dt = Time.utc(2000), DateTime.civil(2000) end - + def teardown Time.zone = nil end - + def test_in_time_zone silence_warnings do # silence warnings raised by tzinfo gem Time.use_zone 'Alaska' do @@ -554,7 +554,7 @@ class TimeWithZoneMethodsForTimeAndDateTimeTest < Test::Unit::TestCase end end end - + def test_in_time_zone_with_time_local_instance silence_warnings do # silence warnings raised by tzinfo gem with_env_tz 'US/Eastern' do @@ -563,85 +563,85 @@ class TimeWithZoneMethodsForTimeAndDateTimeTest < Test::Unit::TestCase end end end - + def test_use_zone Time.zone = 'Alaska' Time.use_zone 'Hawaii' do - assert_equal TimeZone['Hawaii'], Time.zone + assert_equal ActiveSupport::TimeZone['Hawaii'], Time.zone end - assert_equal TimeZone['Alaska'], Time.zone + assert_equal ActiveSupport::TimeZone['Alaska'], Time.zone end - + def test_use_zone_with_exception_raised Time.zone = 'Alaska' assert_raises RuntimeError do Time.use_zone('Hawaii') { raise RuntimeError } end - assert_equal TimeZone['Alaska'], Time.zone + assert_equal ActiveSupport::TimeZone['Alaska'], Time.zone end - + def test_time_zone_getter_and_setter - Time.zone = TimeZone['Alaska'] - assert_equal TimeZone['Alaska'], Time.zone + Time.zone = ActiveSupport::TimeZone['Alaska'] + assert_equal ActiveSupport::TimeZone['Alaska'], Time.zone Time.zone = 'Alaska' - assert_equal TimeZone['Alaska'], Time.zone + assert_equal ActiveSupport::TimeZone['Alaska'], Time.zone Time.zone = -9.hours - assert_equal TimeZone['Alaska'], Time.zone + assert_equal ActiveSupport::TimeZone['Alaska'], Time.zone Time.zone = nil assert_equal nil, Time.zone end - + def test_time_zone_getter_and_setter_with_zone_default - Time.zone_default = TimeZone['Alaska'] - assert_equal TimeZone['Alaska'], Time.zone - Time.zone = TimeZone['Hawaii'] - assert_equal TimeZone['Hawaii'], Time.zone + Time.zone_default = ActiveSupport::TimeZone['Alaska'] + assert_equal ActiveSupport::TimeZone['Alaska'], Time.zone + Time.zone = ActiveSupport::TimeZone['Hawaii'] + assert_equal ActiveSupport::TimeZone['Hawaii'], Time.zone Time.zone = nil - assert_equal TimeZone['Alaska'], Time.zone + assert_equal ActiveSupport::TimeZone['Alaska'], Time.zone ensure Time.zone_default = nil end - + def test_time_zone_setter_is_thread_safe Time.use_zone 'Paris' do t1 = Thread.new { Time.zone = 'Alaska' }.join t2 = Thread.new { Time.zone = 'Hawaii' }.join assert t1.stop?, "Thread 1 did not finish running" assert t2.stop?, "Thread 2 did not finish running" - assert_equal TimeZone['Paris'], Time.zone - assert_equal TimeZone['Alaska'], t1[:time_zone] - assert_equal TimeZone['Hawaii'], t2[:time_zone] + assert_equal ActiveSupport::TimeZone['Paris'], Time.zone + assert_equal ActiveSupport::TimeZone['Alaska'], t1[:time_zone] + assert_equal ActiveSupport::TimeZone['Hawaii'], t2[:time_zone] end end - + def test_time_zone_setter_with_tzinfo_timezone_object_wraps_in_rails_time_zone silence_warnings do # silence warnings raised by tzinfo gem tzinfo = TZInfo::Timezone.get('America/New_York') Time.zone = tzinfo - assert_kind_of TimeZone, Time.zone + assert_kind_of ActiveSupport::TimeZone, Time.zone assert_equal tzinfo, Time.zone.tzinfo assert_equal 'America/New_York', Time.zone.name assert_equal(-18_000, Time.zone.utc_offset) end end - + def test_time_zone_setter_with_tzinfo_timezone_identifier_does_lookup_and_wraps_in_rails_time_zone silence_warnings do # silence warnings raised by tzinfo gem Time.zone = 'America/New_York' - assert_kind_of TimeZone, Time.zone + assert_kind_of ActiveSupport::TimeZone, Time.zone assert_equal 'America/New_York', Time.zone.tzinfo.name assert_equal 'America/New_York', Time.zone.name assert_equal(-18_000, Time.zone.utc_offset) end end - + def test_time_zone_setter_with_non_identifying_argument_returns_nil Time.zone = 'foo' assert_equal nil, Time.zone Time.zone = -15.hours assert_equal nil, Time.zone end - + uses_mocha 'TestTimeCurrent' do def test_current_returns_time_now_when_zone_default_not_set with_env_tz 'US/Eastern' do @@ -650,10 +650,10 @@ class TimeWithZoneMethodsForTimeAndDateTimeTest < Test::Unit::TestCase assert_equal Time.local(2000), Time.current end end - + def test_current_returns_time_zone_now_when_zone_default_set silence_warnings do # silence warnings raised by tzinfo gem - Time.zone_default = TimeZone['Eastern Time (US & Canada)'] + Time.zone_default = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] with_env_tz 'US/Eastern' do Time.stubs(:now).returns Time.local(2000) assert_equal true, Time.current.is_a?(ActiveSupport::TimeWithZone) @@ -665,7 +665,7 @@ class TimeWithZoneMethodsForTimeAndDateTimeTest < Test::Unit::TestCase Time.zone_default = nil end end - + protected def with_env_tz(new_tz = 'US/Eastern') old_tz, ENV['TZ'] = ENV['TZ'], new_tz diff --git a/activesupport/test/dependencies_test.rb b/activesupport/test/dependencies_test.rb index 0309ab6858..038547a862 100644 --- a/activesupport/test/dependencies_test.rb +++ b/activesupport/test/dependencies_test.rb @@ -15,31 +15,31 @@ end class DependenciesTest < Test::Unit::TestCase def teardown - Dependencies.clear + ActiveSupport::Dependencies.clear end def with_loading(*from) - old_mechanism, Dependencies.mechanism = Dependencies.mechanism, :load + old_mechanism, ActiveSupport::Dependencies.mechanism = ActiveSupport::Dependencies.mechanism, :load dir = File.dirname(__FILE__) - prior_load_paths = Dependencies.load_paths - Dependencies.load_paths = from.collect { |f| "#{dir}/#{f}" } + prior_load_paths = ActiveSupport::Dependencies.load_paths + ActiveSupport::Dependencies.load_paths = from.collect { |f| "#{dir}/#{f}" } yield ensure - Dependencies.load_paths = prior_load_paths - Dependencies.mechanism = old_mechanism - Dependencies.explicitly_unloadable_constants = [] + ActiveSupport::Dependencies.load_paths = prior_load_paths + ActiveSupport::Dependencies.mechanism = old_mechanism + ActiveSupport::Dependencies.explicitly_unloadable_constants = [] end def test_tracking_loaded_files require_dependency 'dependencies/service_one' require_dependency 'dependencies/service_two' - assert_equal 2, Dependencies.loaded.size + assert_equal 2, ActiveSupport::Dependencies.loaded.size end def test_tracking_identical_loaded_files require_dependency 'dependencies/service_one' require_dependency 'dependencies/service_one' - assert_equal 1, Dependencies.loaded.size + assert_equal 1, ActiveSupport::Dependencies.loaded.size end def test_missing_dependency_raises_missing_source_file @@ -64,46 +64,46 @@ class DependenciesTest < Test::Unit::TestCase end assert_equal count + 1, $raises_exception_load_count - assert !Dependencies.loaded.include?(filename) - assert !Dependencies.history.include?(filename) + assert !ActiveSupport::Dependencies.loaded.include?(filename) + assert !ActiveSupport::Dependencies.history.include?(filename) end end end def test_warnings_should_be_enabled_on_first_load with_loading 'dependencies' do - old_warnings, Dependencies.warnings_on_first_load = Dependencies.warnings_on_first_load, true + old_warnings, ActiveSupport::Dependencies.warnings_on_first_load = ActiveSupport::Dependencies.warnings_on_first_load, true filename = "check_warnings" expanded = File.expand_path("test/dependencies/#{filename}") $check_warnings_load_count = 0 - assert !Dependencies.loaded.include?(expanded) - assert !Dependencies.history.include?(expanded) + assert !ActiveSupport::Dependencies.loaded.include?(expanded) + assert !ActiveSupport::Dependencies.history.include?(expanded) silence_warnings { require_dependency filename } assert_equal 1, $check_warnings_load_count assert_equal true, $checked_verbose, 'On first load warnings should be enabled.' - assert Dependencies.loaded.include?(expanded) - Dependencies.clear - assert !Dependencies.loaded.include?(expanded) - assert Dependencies.history.include?(expanded) + assert ActiveSupport::Dependencies.loaded.include?(expanded) + ActiveSupport::Dependencies.clear + assert !ActiveSupport::Dependencies.loaded.include?(expanded) + assert ActiveSupport::Dependencies.history.include?(expanded) silence_warnings { require_dependency filename } assert_equal 2, $check_warnings_load_count assert_equal nil, $checked_verbose, 'After first load warnings should be left alone.' - assert Dependencies.loaded.include?(expanded) - Dependencies.clear - assert !Dependencies.loaded.include?(expanded) - assert Dependencies.history.include?(expanded) + assert ActiveSupport::Dependencies.loaded.include?(expanded) + ActiveSupport::Dependencies.clear + assert !ActiveSupport::Dependencies.loaded.include?(expanded) + assert ActiveSupport::Dependencies.history.include?(expanded) enable_warnings { require_dependency filename } assert_equal 3, $check_warnings_load_count assert_equal true, $checked_verbose, 'After first load warnings should be left alone.' - assert Dependencies.loaded.include?(expanded) + assert ActiveSupport::Dependencies.loaded.include?(expanded) end end @@ -113,7 +113,7 @@ class DependenciesTest < Test::Unit::TestCase assert_nothing_raised { require_dependency 'mutual_one' } assert_equal 2, $mutual_dependencies_count - Dependencies.clear + ActiveSupport::Dependencies.clear $mutual_dependencies_count = 0 assert_nothing_raised { require_dependency 'mutual_two' } @@ -239,7 +239,7 @@ class DependenciesTest < Test::Unit::TestCase end def test_loadable_constants_for_path_should_handle_empty_autoloads - assert_equal [], Dependencies.loadable_constants_for_path('hello') + assert_equal [], ActiveSupport::Dependencies.loadable_constants_for_path('hello') end def test_loadable_constants_for_path_should_handle_relative_paths @@ -247,7 +247,7 @@ class DependenciesTest < Test::Unit::TestCase relative_root = File.dirname(__FILE__) + '/dependencies' ['', '/'].each do |suffix| with_loading fake_root + suffix do - assert_equal ["A::B"], Dependencies.loadable_constants_for_path(relative_root + '/a/b') + assert_equal ["A::B"], ActiveSupport::Dependencies.loadable_constants_for_path(relative_root + '/a/b') end end end @@ -255,106 +255,106 @@ class DependenciesTest < Test::Unit::TestCase def test_loadable_constants_for_path_should_provide_all_results fake_root = '/usr/apps/backpack' with_loading fake_root, fake_root + '/lib' do - root = Dependencies.load_paths.first - assert_equal ["Lib::A::B", "A::B"], Dependencies.loadable_constants_for_path(root + '/lib/a/b') + root = ActiveSupport::Dependencies.load_paths.first + assert_equal ["Lib::A::B", "A::B"], ActiveSupport::Dependencies.loadable_constants_for_path(root + '/lib/a/b') end end def test_loadable_constants_for_path_should_uniq_results fake_root = '/usr/apps/backpack/lib' with_loading fake_root, fake_root + '/' do - root = Dependencies.load_paths.first - assert_equal ["A::B"], Dependencies.loadable_constants_for_path(root + '/a/b') + root = ActiveSupport::Dependencies.load_paths.first + assert_equal ["A::B"], ActiveSupport::Dependencies.loadable_constants_for_path(root + '/a/b') end end def test_loadable_constants_with_load_path_without_trailing_slash path = File.dirname(__FILE__) + '/autoloading_fixtures/class_folder/inline_class.rb' with_loading 'autoloading_fixtures/class/' do - assert_equal [], Dependencies.loadable_constants_for_path(path) + assert_equal [], ActiveSupport::Dependencies.loadable_constants_for_path(path) end end def test_qualified_const_defined - assert Dependencies.qualified_const_defined?("Object") - assert Dependencies.qualified_const_defined?("::Object") - assert Dependencies.qualified_const_defined?("::Object::Kernel") - assert Dependencies.qualified_const_defined?("::Object::Dependencies") - assert Dependencies.qualified_const_defined?("::Test::Unit::TestCase") + assert ActiveSupport::Dependencies.qualified_const_defined?("Object") + assert ActiveSupport::Dependencies.qualified_const_defined?("::Object") + assert ActiveSupport::Dependencies.qualified_const_defined?("::Object::Kernel") + assert ActiveSupport::Dependencies.qualified_const_defined?("::Object::Dependencies") + assert ActiveSupport::Dependencies.qualified_const_defined?("::Test::Unit::TestCase") end def test_qualified_const_defined_should_not_call_method_missing ModuleWithMissing.missing_count = 0 - assert ! Dependencies.qualified_const_defined?("ModuleWithMissing::A") + assert ! ActiveSupport::Dependencies.qualified_const_defined?("ModuleWithMissing::A") assert_equal 0, ModuleWithMissing.missing_count - assert ! Dependencies.qualified_const_defined?("ModuleWithMissing::A::B") + assert ! ActiveSupport::Dependencies.qualified_const_defined?("ModuleWithMissing::A::B") assert_equal 0, ModuleWithMissing.missing_count end def test_autoloaded? with_loading 'autoloading_fixtures' do - assert ! Dependencies.autoloaded?("ModuleFolder") - assert ! Dependencies.autoloaded?("ModuleFolder::NestedClass") + assert ! ActiveSupport::Dependencies.autoloaded?("ModuleFolder") + assert ! ActiveSupport::Dependencies.autoloaded?("ModuleFolder::NestedClass") - assert Dependencies.autoloaded?(ModuleFolder) + assert ActiveSupport::Dependencies.autoloaded?(ModuleFolder) - assert Dependencies.autoloaded?("ModuleFolder") - assert ! Dependencies.autoloaded?("ModuleFolder::NestedClass") + assert ActiveSupport::Dependencies.autoloaded?("ModuleFolder") + assert ! ActiveSupport::Dependencies.autoloaded?("ModuleFolder::NestedClass") - assert Dependencies.autoloaded?(ModuleFolder::NestedClass) + assert ActiveSupport::Dependencies.autoloaded?(ModuleFolder::NestedClass) - assert Dependencies.autoloaded?("ModuleFolder") - assert Dependencies.autoloaded?("ModuleFolder::NestedClass") + assert ActiveSupport::Dependencies.autoloaded?("ModuleFolder") + assert ActiveSupport::Dependencies.autoloaded?("ModuleFolder::NestedClass") - assert Dependencies.autoloaded?("::ModuleFolder") - assert Dependencies.autoloaded?(:ModuleFolder) + assert ActiveSupport::Dependencies.autoloaded?("::ModuleFolder") + assert ActiveSupport::Dependencies.autoloaded?(:ModuleFolder) # Anonymous modules aren't autoloaded. - assert !Dependencies.autoloaded?(Module.new) + assert !ActiveSupport::Dependencies.autoloaded?(Module.new) nil_name = Module.new def nil_name.name() nil end - assert !Dependencies.autoloaded?(nil_name) + assert !ActiveSupport::Dependencies.autoloaded?(nil_name) Object.class_eval { remove_const :ModuleFolder } end end def test_qualified_name_for - assert_equal "A", Dependencies.qualified_name_for(Object, :A) - assert_equal "A", Dependencies.qualified_name_for(:Object, :A) - assert_equal "A", Dependencies.qualified_name_for("Object", :A) - assert_equal "A", Dependencies.qualified_name_for("::Object", :A) - assert_equal "A", Dependencies.qualified_name_for("::Kernel", :A) + assert_equal "A", ActiveSupport::Dependencies.qualified_name_for(Object, :A) + assert_equal "A", ActiveSupport::Dependencies.qualified_name_for(:Object, :A) + assert_equal "A", ActiveSupport::Dependencies.qualified_name_for("Object", :A) + assert_equal "A", ActiveSupport::Dependencies.qualified_name_for("::Object", :A) + assert_equal "A", ActiveSupport::Dependencies.qualified_name_for("::Kernel", :A) - assert_equal "Dependencies::A", Dependencies.qualified_name_for(:Dependencies, :A) - assert_equal "Dependencies::A", Dependencies.qualified_name_for(Dependencies, :A) + assert_equal "ActiveSupport::Dependencies::A", ActiveSupport::Dependencies.qualified_name_for(:'ActiveSupport::Dependencies', :A) + assert_equal "ActiveSupport::Dependencies::A", ActiveSupport::Dependencies.qualified_name_for(ActiveSupport::Dependencies, :A) end def test_file_search with_loading 'dependencies' do - root = Dependencies.load_paths.first - assert_equal nil, Dependencies.search_for_file('service_three') - assert_equal nil, Dependencies.search_for_file('service_three.rb') - assert_equal root + '/service_one.rb', Dependencies.search_for_file('service_one') - assert_equal root + '/service_one.rb', Dependencies.search_for_file('service_one.rb') + root = ActiveSupport::Dependencies.load_paths.first + assert_equal nil, ActiveSupport::Dependencies.search_for_file('service_three') + assert_equal nil, ActiveSupport::Dependencies.search_for_file('service_three.rb') + assert_equal root + '/service_one.rb', ActiveSupport::Dependencies.search_for_file('service_one') + assert_equal root + '/service_one.rb', ActiveSupport::Dependencies.search_for_file('service_one.rb') end end def test_file_search_uses_first_in_load_path with_loading 'dependencies', 'autoloading_fixtures' do - deps, autoload = Dependencies.load_paths + deps, autoload = ActiveSupport::Dependencies.load_paths assert_match %r/dependencies/, deps assert_match %r/autoloading_fixtures/, autoload - assert_equal deps + '/conflict.rb', Dependencies.search_for_file('conflict') + assert_equal deps + '/conflict.rb', ActiveSupport::Dependencies.search_for_file('conflict') end with_loading 'autoloading_fixtures', 'dependencies' do - autoload, deps = Dependencies.load_paths + autoload, deps = ActiveSupport::Dependencies.load_paths assert_match %r/dependencies/, deps assert_match %r/autoloading_fixtures/, autoload - assert_equal autoload + '/conflict.rb', Dependencies.search_for_file('conflict') + assert_equal autoload + '/conflict.rb', ActiveSupport::Dependencies.search_for_file('conflict') end end @@ -383,7 +383,7 @@ class DependenciesTest < Test::Unit::TestCase with_loading 'autoloading_fixtures' do require_dependency '././counting_loader' assert_equal 1, $counting_loaded_times - assert_raises(ArgumentError) { Dependencies.load_missing_constant Object, :CountingLoader } + assert_raises(ArgumentError) { ActiveSupport::Dependencies.load_missing_constant Object, :CountingLoader } assert_equal 1, $counting_loaded_times end end @@ -407,12 +407,12 @@ class DependenciesTest < Test::Unit::TestCase def test_removal_from_tree_should_be_detected with_loading 'dependencies' do - root = Dependencies.load_paths.first + root = ActiveSupport::Dependencies.load_paths.first c = ServiceOne - Dependencies.clear + ActiveSupport::Dependencies.clear assert ! defined?(ServiceOne) begin - Dependencies.load_missing_constant(c, :FakeMissing) + ActiveSupport::Dependencies.load_missing_constant(c, :FakeMissing) flunk "Expected exception" rescue ArgumentError => e assert_match %r{ServiceOne has been removed from the module tree}i, e.message @@ -430,25 +430,25 @@ class DependenciesTest < Test::Unit::TestCase def test_load_once_paths_do_not_add_to_autoloaded_constants with_loading 'autoloading_fixtures' do - Dependencies.load_once_paths = Dependencies.load_paths.dup + ActiveSupport::Dependencies.load_once_paths = ActiveSupport::Dependencies.load_paths.dup - assert ! Dependencies.autoloaded?("ModuleFolder") - assert ! Dependencies.autoloaded?("ModuleFolder::NestedClass") - assert ! Dependencies.autoloaded?(ModuleFolder) + assert ! ActiveSupport::Dependencies.autoloaded?("ModuleFolder") + assert ! ActiveSupport::Dependencies.autoloaded?("ModuleFolder::NestedClass") + assert ! ActiveSupport::Dependencies.autoloaded?(ModuleFolder) 1 if ModuleFolder::NestedClass # 1 if to avoid warning - assert ! Dependencies.autoloaded?(ModuleFolder::NestedClass) + assert ! ActiveSupport::Dependencies.autoloaded?(ModuleFolder::NestedClass) end ensure Object.class_eval { remove_const :ModuleFolder } - Dependencies.load_once_paths = [] + ActiveSupport::Dependencies.load_once_paths = [] end def test_application_should_special_case_application_controller with_loading 'autoloading_fixtures' do require_dependency 'application' assert_equal 10, ApplicationController - assert Dependencies.autoloaded?(:ApplicationController) + assert ActiveSupport::Dependencies.autoloaded?(:ApplicationController) end end @@ -463,15 +463,15 @@ class DependenciesTest < Test::Unit::TestCase def test_preexisting_constants_are_not_marked_as_autoloaded with_loading 'autoloading_fixtures' do require_dependency 'e' - assert Dependencies.autoloaded?(:E) - Dependencies.clear + assert ActiveSupport::Dependencies.autoloaded?(:E) + ActiveSupport::Dependencies.clear end Object.const_set :E, Class.new with_loading 'autoloading_fixtures' do require_dependency 'e' - assert ! Dependencies.autoloaded?(:E), "E shouldn't be marked autoloaded!" - Dependencies.clear + assert ! ActiveSupport::Dependencies.autoloaded?(:E), "E shouldn't be marked autoloaded!" + ActiveSupport::Dependencies.clear end ensure @@ -483,11 +483,11 @@ class DependenciesTest < Test::Unit::TestCase Object.const_set :M, Module.new M.unloadable - Dependencies.clear + ActiveSupport::Dependencies.clear assert ! defined?(M) Object.const_set :M, Module.new - Dependencies.clear + ActiveSupport::Dependencies.clear assert ! defined?(M), "Dependencies should unload unloadable constants each time" end end @@ -508,24 +508,24 @@ class DependenciesTest < Test::Unit::TestCase end def test_new_contants_in_without_constants - assert_equal [], (Dependencies.new_constants_in(Object) { }) - assert Dependencies.constant_watch_stack.empty? + assert_equal [], (ActiveSupport::Dependencies.new_constants_in(Object) { }) + assert ActiveSupport::Dependencies.constant_watch_stack.empty? end def test_new_constants_in_with_a_single_constant - assert_equal ["Hello"], Dependencies.new_constants_in(Object) { + assert_equal ["Hello"], ActiveSupport::Dependencies.new_constants_in(Object) { Object.const_set :Hello, 10 }.map(&:to_s) - assert Dependencies.constant_watch_stack.empty? + assert ActiveSupport::Dependencies.constant_watch_stack.empty? ensure Object.class_eval { remove_const :Hello } end def test_new_constants_in_with_nesting - outer = Dependencies.new_constants_in(Object) do + outer = ActiveSupport::Dependencies.new_constants_in(Object) do Object.const_set :OuterBefore, 10 - assert_equal ["Inner"], Dependencies.new_constants_in(Object) { + assert_equal ["Inner"], ActiveSupport::Dependencies.new_constants_in(Object) { Object.const_set :Inner, 20 }.map(&:to_s) @@ -533,7 +533,7 @@ class DependenciesTest < Test::Unit::TestCase end assert_equal ["OuterAfter", "OuterBefore"], outer.sort.map(&:to_s) - assert Dependencies.constant_watch_stack.empty? + assert ActiveSupport::Dependencies.constant_watch_stack.empty? ensure %w(OuterBefore Inner OuterAfter).each do |name| Object.class_eval { remove_const name if const_defined?(name) } @@ -543,10 +543,10 @@ class DependenciesTest < Test::Unit::TestCase def test_new_constants_in_module Object.const_set :M, Module.new - outer = Dependencies.new_constants_in(M) do + outer = ActiveSupport::Dependencies.new_constants_in(M) do M.const_set :OuterBefore, 10 - inner = Dependencies.new_constants_in(M) do + inner = ActiveSupport::Dependencies.new_constants_in(M) do M.const_set :Inner, 20 end assert_equal ["M::Inner"], inner @@ -554,17 +554,17 @@ class DependenciesTest < Test::Unit::TestCase M.const_set :OuterAfter, 30 end assert_equal ["M::OuterAfter", "M::OuterBefore"], outer.sort - assert Dependencies.constant_watch_stack.empty? + assert ActiveSupport::Dependencies.constant_watch_stack.empty? ensure Object.class_eval { remove_const :M } end def test_new_constants_in_module_using_name - outer = Dependencies.new_constants_in(:M) do + outer = ActiveSupport::Dependencies.new_constants_in(:M) do Object.const_set :M, Module.new M.const_set :OuterBefore, 10 - inner = Dependencies.new_constants_in(:M) do + inner = ActiveSupport::Dependencies.new_constants_in(:M) do M.const_set :Inner, 20 end assert_equal ["M::Inner"], inner @@ -572,13 +572,13 @@ class DependenciesTest < Test::Unit::TestCase M.const_set :OuterAfter, 30 end assert_equal ["M::OuterAfter", "M::OuterBefore"], outer.sort - assert Dependencies.constant_watch_stack.empty? + assert ActiveSupport::Dependencies.constant_watch_stack.empty? ensure Object.class_eval { remove_const :M } end def test_new_constants_in_with_inherited_constants - m = Dependencies.new_constants_in(:Object) do + m = ActiveSupport::Dependencies.new_constants_in(:Object) do Object.class_eval { include ModuleWithConstant } end assert_equal [], m @@ -586,7 +586,7 @@ class DependenciesTest < Test::Unit::TestCase def test_new_constants_in_with_illegal_module_name_raises_correct_error assert_raises(NameError) do - Dependencies.new_constants_in("Illegal-Name") {} + ActiveSupport::Dependencies.new_constants_in("Illegal-Name") {} end end @@ -598,10 +598,10 @@ class DependenciesTest < Test::Unit::TestCase require_dependency 'multiple_constant_file' assert defined?(MultipleConstantFile) assert defined?(SiblingConstant) - assert Dependencies.autoloaded?(:MultipleConstantFile) - assert Dependencies.autoloaded?(:SiblingConstant) + assert ActiveSupport::Dependencies.autoloaded?(:MultipleConstantFile) + assert ActiveSupport::Dependencies.autoloaded?(:SiblingConstant) - Dependencies.clear + ActiveSupport::Dependencies.clear assert ! defined?(MultipleConstantFile) assert ! defined?(SiblingConstant) @@ -617,10 +617,10 @@ class DependenciesTest < Test::Unit::TestCase assert defined?(MultipleConstantFile) assert defined?(SiblingConstant) - assert Dependencies.autoloaded?(:MultipleConstantFile) - assert Dependencies.autoloaded?(:SiblingConstant) + assert ActiveSupport::Dependencies.autoloaded?(:MultipleConstantFile) + assert ActiveSupport::Dependencies.autoloaded?(:SiblingConstant) - Dependencies.clear + ActiveSupport::Dependencies.clear assert ! defined?(MultipleConstantFile) assert ! defined?(SiblingConstant) @@ -636,10 +636,10 @@ class DependenciesTest < Test::Unit::TestCase assert defined?(ClassFolder::NestedClass) assert defined?(ClassFolder::SiblingClass) - assert Dependencies.autoloaded?("ClassFolder::NestedClass") - assert Dependencies.autoloaded?("ClassFolder::SiblingClass") + assert ActiveSupport::Dependencies.autoloaded?("ClassFolder::NestedClass") + assert ActiveSupport::Dependencies.autoloaded?("ClassFolder::SiblingClass") - Dependencies.clear + ActiveSupport::Dependencies.clear assert ! defined?(ClassFolder::NestedClass) assert ! defined?(ClassFolder::SiblingClass) @@ -655,10 +655,10 @@ class DependenciesTest < Test::Unit::TestCase assert defined?(ClassFolder::NestedClass) assert defined?(ClassFolder::SiblingClass) - assert Dependencies.autoloaded?("ClassFolder::NestedClass") - assert Dependencies.autoloaded?("ClassFolder::SiblingClass") + assert ActiveSupport::Dependencies.autoloaded?("ClassFolder::NestedClass") + assert ActiveSupport::Dependencies.autoloaded?("ClassFolder::SiblingClass") - Dependencies.clear + ActiveSupport::Dependencies.clear assert ! defined?(ClassFolder::NestedClass) assert ! defined?(ClassFolder::SiblingClass) @@ -693,7 +693,7 @@ class DependenciesTest < Test::Unit::TestCase def test_autoload_doesnt_shadow_error_when_mechanism_not_set_to_load with_loading 'autoloading_fixtures' do - Dependencies.mechanism = :require + ActiveSupport::Dependencies.mechanism = :require 2.times do assert_raise(NameError) {"RaisesNameError".constantize} end @@ -727,39 +727,39 @@ class DependenciesTest < Test::Unit::TestCase def test_remove_constant_handles_double_colon_at_start Object.const_set 'DeleteMe', Module.new DeleteMe.const_set 'OrMe', Module.new - Dependencies.remove_constant "::DeleteMe::OrMe" + ActiveSupport::Dependencies.remove_constant "::DeleteMe::OrMe" assert ! defined?(DeleteMe::OrMe) assert defined?(DeleteMe) - Dependencies.remove_constant "::DeleteMe" + ActiveSupport::Dependencies.remove_constant "::DeleteMe" assert ! defined?(DeleteMe) end def test_load_once_constants_should_not_be_unloaded with_loading 'autoloading_fixtures' do - Dependencies.load_once_paths = Dependencies.load_paths + ActiveSupport::Dependencies.load_once_paths = ActiveSupport::Dependencies.load_paths ::A.to_s assert defined?(A) - Dependencies.clear + ActiveSupport::Dependencies.clear assert defined?(A) end ensure - Dependencies.load_once_paths = [] + ActiveSupport::Dependencies.load_once_paths = [] Object.class_eval { remove_const :A if const_defined?(:A) } end def test_load_once_paths_should_behave_when_recursively_loading with_loading 'dependencies', 'autoloading_fixtures' do - Dependencies.load_once_paths = [Dependencies.load_paths.last] + ActiveSupport::Dependencies.load_once_paths = [ActiveSupport::Dependencies.load_paths.last] assert !defined?(CrossSiteDependency) assert_nothing_raised { CrossSiteDepender.nil? } assert defined?(CrossSiteDependency) - assert !Dependencies.autoloaded?(CrossSiteDependency), + assert !ActiveSupport::Dependencies.autoloaded?(CrossSiteDependency), "CrossSiteDependency shouldn't be marked as autoloaded!" - Dependencies.clear + ActiveSupport::Dependencies.clear assert defined?(CrossSiteDependency), "CrossSiteDependency shouldn't have been unloaded!" end ensure - Dependencies.load_once_paths = [] + ActiveSupport::Dependencies.load_once_paths = [] end end diff --git a/activesupport/test/deprecation_test.rb b/activesupport/test/deprecation_test.rb index ebfa405947..27e9573ce2 100644 --- a/activesupport/test/deprecation_test.rb +++ b/activesupport/test/deprecation_test.rb @@ -24,6 +24,11 @@ class Deprecatee def d; end def e; end deprecate :a, :b, :c => :e, :d => "you now need to do something extra for this one" + + module B + C = 1 + end + A = ActiveSupport::Deprecation::DeprecatedConstantProxy.new('Deprecatee::A', 'Deprecatee::B::C') end @@ -83,6 +88,11 @@ class DeprecationTest < Test::Unit::TestCase assert_not_deprecated { assert_equal @dtc.request.inspect, @dtc.old_request.inspect } end + def test_deprecated_constant_proxy + assert_not_deprecated { Deprecatee::B::C } + assert_deprecated('Deprecatee::A') { assert_equal Deprecatee::B::C, Deprecatee::A } + end + def test_assert_deprecation_without_match assert_deprecated do @dtc.partially diff --git a/activesupport/test/inflector_test.rb b/activesupport/test/inflector_test.rb index 26af245ff7..4ce9cbb705 100644 --- a/activesupport/test/inflector_test.rb +++ b/activesupport/test/inflector_test.rb @@ -12,188 +12,188 @@ class InflectorTest < Test::Unit::TestCase include InflectorTestCases def test_pluralize_plurals - assert_equal "plurals", Inflector.pluralize("plurals") - assert_equal "Plurals", Inflector.pluralize("Plurals") + assert_equal "plurals", ActiveSupport::Inflector.pluralize("plurals") + assert_equal "Plurals", ActiveSupport::Inflector.pluralize("Plurals") end def test_pluralize_empty_string - assert_equal "", Inflector.pluralize("") + assert_equal "", ActiveSupport::Inflector.pluralize("") end SingularToPlural.each do |singular, plural| define_method "test_pluralize_#{singular}" do - assert_equal(plural, Inflector.pluralize(singular)) - assert_equal(plural.capitalize, Inflector.pluralize(singular.capitalize)) + assert_equal(plural, ActiveSupport::Inflector.pluralize(singular)) + assert_equal(plural.capitalize, ActiveSupport::Inflector.pluralize(singular.capitalize)) end end SingularToPlural.each do |singular, plural| define_method "test_singularize_#{plural}" do - assert_equal(singular, Inflector.singularize(plural)) - assert_equal(singular.capitalize, Inflector.singularize(plural.capitalize)) + assert_equal(singular, ActiveSupport::Inflector.singularize(plural)) + assert_equal(singular.capitalize, ActiveSupport::Inflector.singularize(plural.capitalize)) end end MixtureToTitleCase.each do |before, titleized| define_method "test_titleize_#{before}" do - assert_equal(titleized, Inflector.titleize(before)) + assert_equal(titleized, ActiveSupport::Inflector.titleize(before)) end end def test_camelize CamelToUnderscore.each do |camel, underscore| - assert_equal(camel, Inflector.camelize(underscore)) + assert_equal(camel, ActiveSupport::Inflector.camelize(underscore)) end end def test_underscore CamelToUnderscore.each do |camel, underscore| - assert_equal(underscore, Inflector.underscore(camel)) + assert_equal(underscore, ActiveSupport::Inflector.underscore(camel)) end CamelToUnderscoreWithoutReverse.each do |camel, underscore| - assert_equal(underscore, Inflector.underscore(camel)) + assert_equal(underscore, ActiveSupport::Inflector.underscore(camel)) end end def test_camelize_with_module CamelWithModuleToUnderscoreWithSlash.each do |camel, underscore| - assert_equal(camel, Inflector.camelize(underscore)) + assert_equal(camel, ActiveSupport::Inflector.camelize(underscore)) end end def test_underscore_with_slashes CamelWithModuleToUnderscoreWithSlash.each do |camel, underscore| - assert_equal(underscore, Inflector.underscore(camel)) + assert_equal(underscore, ActiveSupport::Inflector.underscore(camel)) end end def test_demodulize - assert_equal "Account", Inflector.demodulize("MyApplication::Billing::Account") + assert_equal "Account", ActiveSupport::Inflector.demodulize("MyApplication::Billing::Account") end def test_foreign_key ClassNameToForeignKeyWithUnderscore.each do |klass, foreign_key| - assert_equal(foreign_key, Inflector.foreign_key(klass)) + assert_equal(foreign_key, ActiveSupport::Inflector.foreign_key(klass)) end ClassNameToForeignKeyWithoutUnderscore.each do |klass, foreign_key| - assert_equal(foreign_key, Inflector.foreign_key(klass, false)) + assert_equal(foreign_key, ActiveSupport::Inflector.foreign_key(klass, false)) end end def test_tableize ClassNameToTableName.each do |class_name, table_name| - assert_equal(table_name, Inflector.tableize(class_name)) + assert_equal(table_name, ActiveSupport::Inflector.tableize(class_name)) end end def test_classify ClassNameToTableName.each do |class_name, table_name| - assert_equal(class_name, Inflector.classify(table_name)) - assert_equal(class_name, Inflector.classify("table_prefix." + table_name)) + assert_equal(class_name, ActiveSupport::Inflector.classify(table_name)) + assert_equal(class_name, ActiveSupport::Inflector.classify("table_prefix." + table_name)) end end def test_classify_with_symbol assert_nothing_raised do - assert_equal 'FooBar', Inflector.classify(:foo_bars) + assert_equal 'FooBar', ActiveSupport::Inflector.classify(:foo_bars) end end def test_classify_with_leading_schema_name - assert_equal 'FooBar', Inflector.classify('schema.foo_bar') + assert_equal 'FooBar', ActiveSupport::Inflector.classify('schema.foo_bar') end def test_humanize UnderscoreToHuman.each do |underscore, human| - assert_equal(human, Inflector.humanize(underscore)) + assert_equal(human, ActiveSupport::Inflector.humanize(underscore)) end end def test_constantize - assert_nothing_raised { assert_equal Ace::Base::Case, Inflector.constantize("Ace::Base::Case") } - assert_nothing_raised { assert_equal Ace::Base::Case, Inflector.constantize("::Ace::Base::Case") } - assert_nothing_raised { assert_equal InflectorTest, Inflector.constantize("InflectorTest") } - assert_nothing_raised { assert_equal InflectorTest, Inflector.constantize("::InflectorTest") } - assert_raises(NameError) { Inflector.constantize("UnknownClass") } - assert_raises(NameError) { Inflector.constantize("An invalid string") } - assert_raises(NameError) { Inflector.constantize("InvalidClass\n") } + assert_nothing_raised { assert_equal Ace::Base::Case, ActiveSupport::Inflector.constantize("Ace::Base::Case") } + assert_nothing_raised { assert_equal Ace::Base::Case, ActiveSupport::Inflector.constantize("::Ace::Base::Case") } + assert_nothing_raised { assert_equal InflectorTest, ActiveSupport::Inflector.constantize("InflectorTest") } + assert_nothing_raised { assert_equal InflectorTest, ActiveSupport::Inflector.constantize("::InflectorTest") } + assert_raises(NameError) { ActiveSupport::Inflector.constantize("UnknownClass") } + assert_raises(NameError) { ActiveSupport::Inflector.constantize("An invalid string") } + assert_raises(NameError) { ActiveSupport::Inflector.constantize("InvalidClass\n") } end def test_constantize_does_lexical_lookup - assert_raises(NameError) { Inflector.constantize("Ace::Base::InflectorTest") } + assert_raises(NameError) { ActiveSupport::Inflector.constantize("Ace::Base::InflectorTest") } end def test_ordinal OrdinalNumbers.each do |number, ordinalized| - assert_equal(ordinalized, Inflector.ordinalize(number)) + assert_equal(ordinalized, ActiveSupport::Inflector.ordinalize(number)) end end def test_dasherize UnderscoresToDashes.each do |underscored, dasherized| - assert_equal(dasherized, Inflector.dasherize(underscored)) + assert_equal(dasherized, ActiveSupport::Inflector.dasherize(underscored)) end end def test_underscore_as_reverse_of_dasherize UnderscoresToDashes.each do |underscored, dasherized| - assert_equal(underscored, Inflector.underscore(Inflector.dasherize(underscored))) + assert_equal(underscored, ActiveSupport::Inflector.underscore(ActiveSupport::Inflector.dasherize(underscored))) end end def test_underscore_to_lower_camel UnderscoreToLowerCamel.each do |underscored, lower_camel| - assert_equal(lower_camel, Inflector.camelize(underscored, false)) + assert_equal(lower_camel, ActiveSupport::Inflector.camelize(underscored, false)) end end - + %w{plurals singulars uncountables}.each do |inflection_type| class_eval " def test_clear_#{inflection_type} - cached_values = Inflector.inflections.#{inflection_type} - Inflector.inflections.clear :#{inflection_type} - assert Inflector.inflections.#{inflection_type}.empty?, \"#{inflection_type} inflections should be empty after clear :#{inflection_type}\" - Inflector.inflections.instance_variable_set :@#{inflection_type}, cached_values + cached_values = ActiveSupport::Inflector.inflections.#{inflection_type} + ActiveSupport::Inflector.inflections.clear :#{inflection_type} + assert ActiveSupport::Inflector.inflections.#{inflection_type}.empty?, \"#{inflection_type} inflections should be empty after clear :#{inflection_type}\" + ActiveSupport::Inflector.inflections.instance_variable_set :@#{inflection_type}, cached_values end " end - + def test_clear_all - cached_values = Inflector.inflections.plurals, Inflector.inflections.singulars, Inflector.inflections.uncountables - Inflector.inflections.clear :all - assert Inflector.inflections.plurals.empty? - assert Inflector.inflections.singulars.empty? - assert Inflector.inflections.uncountables.empty? - Inflector.inflections.instance_variable_set :@plurals, cached_values[0] - Inflector.inflections.instance_variable_set :@singulars, cached_values[1] - Inflector.inflections.instance_variable_set :@uncountables, cached_values[2] - end - + cached_values = ActiveSupport::Inflector.inflections.plurals, ActiveSupport::Inflector.inflections.singulars, ActiveSupport::Inflector.inflections.uncountables + ActiveSupport::Inflector.inflections.clear :all + assert ActiveSupport::Inflector.inflections.plurals.empty? + assert ActiveSupport::Inflector.inflections.singulars.empty? + assert ActiveSupport::Inflector.inflections.uncountables.empty? + ActiveSupport::Inflector.inflections.instance_variable_set :@plurals, cached_values[0] + ActiveSupport::Inflector.inflections.instance_variable_set :@singulars, cached_values[1] + ActiveSupport::Inflector.inflections.instance_variable_set :@uncountables, cached_values[2] + end + def test_clear_with_default - cached_values = Inflector.inflections.plurals, Inflector.inflections.singulars, Inflector.inflections.uncountables - Inflector.inflections.clear - assert Inflector.inflections.plurals.empty? - assert Inflector.inflections.singulars.empty? - assert Inflector.inflections.uncountables.empty? - Inflector.inflections.instance_variable_set :@plurals, cached_values[0] - Inflector.inflections.instance_variable_set :@singulars, cached_values[1] - Inflector.inflections.instance_variable_set :@uncountables, cached_values[2] + cached_values = ActiveSupport::Inflector.inflections.plurals, ActiveSupport::Inflector.inflections.singulars, ActiveSupport::Inflector.inflections.uncountables + ActiveSupport::Inflector.inflections.clear + assert ActiveSupport::Inflector.inflections.plurals.empty? + assert ActiveSupport::Inflector.inflections.singulars.empty? + assert ActiveSupport::Inflector.inflections.uncountables.empty? + ActiveSupport::Inflector.inflections.instance_variable_set :@plurals, cached_values[0] + ActiveSupport::Inflector.inflections.instance_variable_set :@singulars, cached_values[1] + ActiveSupport::Inflector.inflections.instance_variable_set :@uncountables, cached_values[2] end Irregularities.each do |irregularity| singular, plural = *irregularity - Inflector.inflections do |inflect| + ActiveSupport::Inflector.inflections do |inflect| define_method("test_irregularity_between_#{singular}_and_#{plural}") do inflect.irregular(singular, plural) - assert_equal singular, Inflector.singularize(plural) - assert_equal plural, Inflector.pluralize(singular) + assert_equal singular, ActiveSupport::Inflector.singularize(plural) + assert_equal plural, ActiveSupport::Inflector.pluralize(singular) end end end [ :all, [] ].each do |scope| - Inflector.inflections do |inflect| + ActiveSupport::Inflector.inflections do |inflect| define_method("test_clear_inflections_with_#{scope.kind_of?(Array) ? "no_arguments" : scope}") do # save all the inflections singulars, plurals, uncountables = inflect.singulars, inflect.plurals, inflect.uncountables @@ -218,7 +218,7 @@ class InflectorTest < Test::Unit::TestCase end { :singulars => :singular, :plurals => :plural, :uncountables => :uncountable }.each do |scope, method| - Inflector.inflections do |inflect| + ActiveSupport::Inflector.inflections do |inflect| define_method("test_clear_inflections_with_#{scope}") do # save the inflections values = inflect.send(scope) diff --git a/activesupport/test/ordered_hash_test.rb b/activesupport/test/ordered_hash_test.rb index 14be48724e..98a6ad6b26 100644 --- a/activesupport/test/ordered_hash_test.rb +++ b/activesupport/test/ordered_hash_test.rb @@ -42,4 +42,23 @@ class OrderedHashTest < Test::Unit::TestCase assert_nil @ordered_hash.delete(bad_key) end + + def test_has_key + assert_equal true, @ordered_hash.has_key?('blue') + assert_equal true, @ordered_hash.key?('blue') + assert_equal true, @ordered_hash.include?('blue') + assert_equal true, @ordered_hash.member?('blue') + + assert_equal false, @ordered_hash.has_key?('indigo') + assert_equal false, @ordered_hash.key?('indigo') + assert_equal false, @ordered_hash.include?('indigo') + assert_equal false, @ordered_hash.member?('indigo') + end + + def test_has_value + assert_equal true, @ordered_hash.has_value?('000099') + assert_equal true, @ordered_hash.value?('000099') + assert_equal false, @ordered_hash.has_value?('ABCABC') + assert_equal false, @ordered_hash.value?('ABCABC') + end end diff --git a/activesupport/test/ordered_options_test.rb b/activesupport/test/ordered_options_test.rb index fb7a58d0b0..e48425ca25 100644 --- a/activesupport/test/ordered_options_test.rb +++ b/activesupport/test/ordered_options_test.rb @@ -2,7 +2,7 @@ require 'abstract_unit' class OrderedOptionsTest < Test::Unit::TestCase def test_usage - a = OrderedOptions.new + a = ActiveSupport::OrderedOptions.new assert_nil a[:not_set] @@ -20,7 +20,7 @@ class OrderedOptionsTest < Test::Unit::TestCase end def test_looping - a = OrderedOptions.new + a = ActiveSupport::OrderedOptions.new a[:allow_concurreny] = true a["else_where"] = 56 @@ -34,7 +34,7 @@ class OrderedOptionsTest < Test::Unit::TestCase end def test_method_access - a = OrderedOptions.new + a = ActiveSupport::OrderedOptions.new assert_nil a.not_set diff --git a/activesupport/test/string_questioneer_test.rb b/activesupport/test/string_questioneer_test.rb new file mode 100644 index 0000000000..ff9d2c17f9 --- /dev/null +++ b/activesupport/test/string_questioneer_test.rb @@ -0,0 +1,15 @@ +require 'abstract_unit' + +class StringQuestioneerTest < Test::Unit::TestCase + def test_match + assert StringQuestioneer.new("production").production? + end + + def test_miss + assert !StringQuestioneer.new("production").development? + end + + def test_missing_question_mark + assert_raises(NoMethodError) { StringQuestioneer.new("production").production } + end +end
\ No newline at end of file diff --git a/activesupport/test/time_zone_test.rb b/activesupport/test/time_zone_test.rb index f3069b589b..b42dcd17f8 100644 --- a/activesupport/test/time_zone_test.rb +++ b/activesupport/test/time_zone_test.rb @@ -1,10 +1,9 @@ require 'abstract_unit' class TimeZoneTest < Test::Unit::TestCase - def test_utc_to_local silence_warnings do # silence warnings raised by tzinfo gem - zone = TimeZone['Eastern Time (US & Canada)'] + zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] assert_equal Time.utc(1999, 12, 31, 19), zone.utc_to_local(Time.utc(2000, 1)) # standard offset -0500 assert_equal Time.utc(2000, 6, 30, 20), zone.utc_to_local(Time.utc(2000, 7)) # dst offset -0400 end @@ -12,41 +11,41 @@ class TimeZoneTest < Test::Unit::TestCase def test_local_to_utc silence_warnings do # silence warnings raised by tzinfo gem - zone = TimeZone['Eastern Time (US & Canada)'] + zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] assert_equal Time.utc(2000, 1, 1, 5), zone.local_to_utc(Time.utc(2000, 1)) # standard offset -0500 assert_equal Time.utc(2000, 7, 1, 4), zone.local_to_utc(Time.utc(2000, 7)) # dst offset -0400 end end - + def test_period_for_local silence_warnings do # silence warnings raised by tzinfo gem - zone = TimeZone['Eastern Time (US & Canada)'] + zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] assert_instance_of TZInfo::TimezonePeriod, zone.period_for_local(Time.utc(2000)) end end - - TimeZone::MAPPING.keys.each do |name| + + ActiveSupport::TimeZone::MAPPING.keys.each do |name| define_method("test_map_#{name.downcase.gsub(/[^a-z]/, '_')}_to_tzinfo") do silence_warnings do # silence warnings raised by tzinfo gem - zone = TimeZone[name] + zone = ActiveSupport::TimeZone[name] assert zone.tzinfo.respond_to?(:period_for_local) end end end def test_from_integer_to_map - assert_instance_of TimeZone, TimeZone[-28800] # PST + assert_instance_of ActiveSupport::TimeZone, ActiveSupport::TimeZone[-28800] # PST end def test_from_duration_to_map - assert_instance_of TimeZone, TimeZone[-480.minutes] # PST + assert_instance_of ActiveSupport::TimeZone, ActiveSupport::TimeZone[-480.minutes] # PST end - TimeZone.all.each do |zone| + ActiveSupport::TimeZone.all.each do |zone| name = zone.name.downcase.gsub(/[^a-z]/, '_') define_method("test_from_#{name}_to_map") do silence_warnings do # silence warnings raised by tzinfo gem - assert_instance_of TimeZone, TimeZone[zone.name] + assert_instance_of ActiveSupport::TimeZone, ActiveSupport::TimeZone[zone.name] end end @@ -62,62 +61,62 @@ class TimeZoneTest < Test::Unit::TestCase def test_now with_env_tz 'US/Eastern' do Time.stubs(:now).returns(Time.local(2000)) - zone = TimeZone['Eastern Time (US & Canada)'] + zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] assert_instance_of ActiveSupport::TimeWithZone, zone.now assert_equal Time.utc(2000,1,1,5), zone.now.utc assert_equal Time.utc(2000), zone.now.time assert_equal zone, zone.now.time_zone end end - + def test_now_enforces_spring_dst_rules with_env_tz 'US/Eastern' do Time.stubs(:now).returns(Time.local(2006,4,2,2)) # 2AM springs forward to 3AM - zone = TimeZone['Eastern Time (US & Canada)'] + zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] assert_equal Time.utc(2006,4,2,3), zone.now.time assert_equal true, zone.now.dst? end end - + def test_now_enforces_fall_dst_rules with_env_tz 'US/Eastern' do Time.stubs(:now).returns(Time.at(1162098000)) # equivalent to 1AM DST - zone = TimeZone['Eastern Time (US & Canada)'] + zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] assert_equal Time.utc(2006,10,29,1), zone.now.time assert_equal true, zone.now.dst? end end - + def test_today Time.stubs(:now).returns(Time.utc(2000, 1, 1, 4, 59, 59)) # 1 sec before midnight Jan 1 EST - assert_equal Date.new(1999, 12, 31), TimeZone['Eastern Time (US & Canada)'].today + assert_equal Date.new(1999, 12, 31), ActiveSupport::TimeZone['Eastern Time (US & Canada)'].today Time.stubs(:now).returns(Time.utc(2000, 1, 1, 5)) # midnight Jan 1 EST - assert_equal Date.new(2000, 1, 1), TimeZone['Eastern Time (US & Canada)'].today + assert_equal Date.new(2000, 1, 1), ActiveSupport::TimeZone['Eastern Time (US & Canada)'].today Time.stubs(:now).returns(Time.utc(2000, 1, 2, 4, 59, 59)) # 1 sec before midnight Jan 2 EST - assert_equal Date.new(2000, 1, 1), TimeZone['Eastern Time (US & Canada)'].today + assert_equal Date.new(2000, 1, 1), ActiveSupport::TimeZone['Eastern Time (US & Canada)'].today Time.stubs(:now).returns(Time.utc(2000, 1, 2, 5)) # midnight Jan 2 EST - assert_equal Date.new(2000, 1, 2), TimeZone['Eastern Time (US & Canada)'].today + assert_equal Date.new(2000, 1, 2), ActiveSupport::TimeZone['Eastern Time (US & Canada)'].today end end - + def test_local silence_warnings do # silence warnings raised by tzinfo gem - time = TimeZone["Hawaii"].local(2007, 2, 5, 15, 30, 45) + time = ActiveSupport::TimeZone["Hawaii"].local(2007, 2, 5, 15, 30, 45) assert_equal Time.utc(2007, 2, 5, 15, 30, 45), time.time - assert_equal TimeZone["Hawaii"], time.time_zone + assert_equal ActiveSupport::TimeZone["Hawaii"], time.time_zone end end def test_local_with_old_date silence_warnings do # silence warnings raised by tzinfo gem - time = TimeZone["Hawaii"].local(1850, 2, 5, 15, 30, 45) + time = ActiveSupport::TimeZone["Hawaii"].local(1850, 2, 5, 15, 30, 45) assert_equal [45,30,15,5,2,1850], time.to_a[0,6] - assert_equal TimeZone["Hawaii"], time.time_zone + assert_equal ActiveSupport::TimeZone["Hawaii"], time.time_zone end end def test_local_enforces_spring_dst_rules - zone = TimeZone['Eastern Time (US & Canada)'] + zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] twz = zone.local(2006,4,2,1,59,59) # 1 second before DST start assert_equal Time.utc(2006,4,2,1,59,59), twz.time assert_equal Time.utc(2006,4,2,6,59,59), twz.utc @@ -138,16 +137,16 @@ class TimeZoneTest < Test::Unit::TestCase def test_local_enforces_fall_dst_rules # 1AM during fall DST transition is ambiguous, it could be either DST or non-DST 1AM # Mirroring Time.local behavior, this method selects the DST time - zone = TimeZone['Eastern Time (US & Canada)'] + zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] twz = zone.local(2006,10,29,1) assert_equal Time.utc(2006,10,29,1), twz.time assert_equal Time.utc(2006,10,29,5), twz.utc - assert_equal true, twz.dst? + assert_equal true, twz.dst? assert_equal 'EDT', twz.zone end def test_at - zone = TimeZone['Eastern Time (US & Canada)'] + zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] secs = 946684800.0 twz = zone.at(secs) assert_equal Time.utc(1999,12,31,19), twz.time @@ -157,7 +156,7 @@ class TimeZoneTest < Test::Unit::TestCase end def test_at_with_old_date - zone = TimeZone['Eastern Time (US & Canada)'] + zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] secs = DateTime.civil(1850).to_f twz = zone.at(secs) assert_equal [1850, 1, 1, 0], [twz.utc.year, twz.utc.mon, twz.utc.day, twz.utc.hour] @@ -166,7 +165,7 @@ class TimeZoneTest < Test::Unit::TestCase end def test_parse - zone = TimeZone['Eastern Time (US & Canada)'] + zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] twz = zone.parse('1999-12-31 19:00:00') assert_equal Time.utc(1999,12,31,19), twz.time assert_equal Time.utc(2000), twz.utc @@ -175,7 +174,7 @@ class TimeZoneTest < Test::Unit::TestCase def test_parse_string_with_timezone (-11..13).each do |timezone_offset| - zone = TimeZone[timezone_offset] + zone = ActiveSupport::TimeZone[timezone_offset] twz = zone.parse('1999-12-31 19:00:00') assert_equal twz, zone.parse(twz.to_s) end @@ -183,25 +182,25 @@ class TimeZoneTest < Test::Unit::TestCase def test_parse_with_old_date silence_warnings do # silence warnings raised by tzinfo gem - zone = TimeZone['Eastern Time (US & Canada)'] + zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] twz = zone.parse('1850-12-31 19:00:00') assert_equal [0,0,19,31,12,1850], twz.to_a[0,6] assert_equal zone, twz.time_zone end end - + def test_parse_far_future_date_with_time_zone_offset_in_string silence_warnings do # silence warnings raised by tzinfo gem - zone = TimeZone['Eastern Time (US & Canada)'] + zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] twz = zone.parse('2050-12-31 19:00:00 -10:00') # i.e., 2050-01-01 05:00:00 UTC assert_equal [0,0,0,1,1,2051], twz.to_a[0,6] assert_equal zone, twz.time_zone end end - + def test_parse_returns_nil_when_string_without_date_information_is_passed_in silence_warnings do # silence warnings raised by tzinfo gem - zone = TimeZone['Eastern Time (US & Canada)'] + zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] assert_nil zone.parse('foobar') assert_nil zone.parse(' ') end @@ -209,80 +208,80 @@ class TimeZoneTest < Test::Unit::TestCase uses_mocha 'TestParseWithIncompleteDate' do def test_parse_with_incomplete_date - zone = TimeZone['Eastern Time (US & Canada)'] + zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] zone.stubs(:now).returns zone.local(1999,12,31) twz = zone.parse('19:00:00') assert_equal Time.utc(1999,12,31,19), twz.time end end - + def test_utc_offset_lazy_loaded_from_tzinfo_when_not_passed_in_to_initialize silence_warnings do # silence warnings raised by tzinfo gem tzinfo = TZInfo::Timezone.get('America/New_York') - zone = TimeZone.create(tzinfo.name, nil, tzinfo) + zone = ActiveSupport::TimeZone.create(tzinfo.name, nil, tzinfo) assert_equal nil, zone.instance_variable_get('@utc_offset') assert_equal(-18_000, zone.utc_offset) end end - + def test_formatted_offset_positive - zone = TimeZone['Moscow'] + zone = ActiveSupport::TimeZone['Moscow'] assert_equal "+03:00", zone.formatted_offset assert_equal "+0300", zone.formatted_offset(false) end - + def test_formatted_offset_negative - zone = TimeZone['Eastern Time (US & Canada)'] + zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] assert_equal "-05:00", zone.formatted_offset assert_equal "-0500", zone.formatted_offset(false) end - + def test_formatted_offset_zero - zone = TimeZone['London'] + zone = ActiveSupport::TimeZone['London'] assert_equal "+00:00", zone.formatted_offset assert_equal "UTC", zone.formatted_offset(true, 'UTC') end - + def test_zone_compare - zone1 = TimeZone['Central Time (US & Canada)'] # offset -0600 - zone2 = TimeZone['Eastern Time (US & Canada)'] # offset -0500 + zone1 = ActiveSupport::TimeZone['Central Time (US & Canada)'] # offset -0600 + zone2 = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] # offset -0500 assert zone1 < zone2 assert zone2 > zone1 assert zone1 == zone1 end - + def test_to_s - assert_equal "(GMT+03:00) Moscow", TimeZone['Moscow'].to_s + assert_equal "(GMT+03:00) Moscow", ActiveSupport::TimeZone['Moscow'].to_s end - + def test_all_sorted - all = TimeZone.all + all = ActiveSupport::TimeZone.all 1.upto( all.length-1 ) do |i| assert all[i-1] < all[i] end end - + def test_index - assert_nil TimeZone["bogus"] - assert_instance_of TimeZone, TimeZone["Central Time (US & Canada)"] - assert_instance_of TimeZone, TimeZone[8] - assert_raises(ArgumentError) { TimeZone[false] } + assert_nil ActiveSupport::TimeZone["bogus"] + assert_instance_of ActiveSupport::TimeZone, ActiveSupport::TimeZone["Central Time (US & Canada)"] + assert_instance_of ActiveSupport::TimeZone, ActiveSupport::TimeZone[8] + assert_raises(ArgumentError) { ActiveSupport::TimeZone[false] } end - + def test_new - assert_equal TimeZone["Central Time (US & Canada)"], TimeZone.new("Central Time (US & Canada)") + assert_equal ActiveSupport::TimeZone["Central Time (US & Canada)"], ActiveSupport::TimeZone.new("Central Time (US & Canada)") end - + def test_us_zones - assert TimeZone.us_zones.include?(TimeZone["Hawaii"]) - assert !TimeZone.us_zones.include?(TimeZone["Kuala Lumpur"]) - end - + assert ActiveSupport::TimeZone.us_zones.include?(ActiveSupport::TimeZone["Hawaii"]) + assert !ActiveSupport::TimeZone.us_zones.include?(ActiveSupport::TimeZone["Kuala Lumpur"]) + end + protected def with_env_tz(new_tz = 'US/Eastern') old_tz, ENV['TZ'] = ENV['TZ'], new_tz yield ensure old_tz ? ENV['TZ'] = old_tz : ENV.delete('TZ') - end + end end |