aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/test')
-rw-r--r--activesupport/test/core_ext/hash_ext_test.rb38
-rw-r--r--activesupport/test/core_ext/time_with_zone_test.rb7
-rw-r--r--activesupport/test/dependencies_test.rb26
-rw-r--r--activesupport/test/json/encoding_test.rb16
-rw-r--r--activesupport/test/time_zone_test.rb2
5 files changed, 82 insertions, 7 deletions
diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb
index 706e218abc..69028a123f 100644
--- a/activesupport/test/core_ext/hash_ext_test.rb
+++ b/activesupport/test/core_ext/hash_ext_test.rb
@@ -733,6 +733,44 @@ class HashToXmlTest < Test::Unit::TestCase
assert_equal hash, Hash.from_xml(hash.to_xml(@xml_options))['person']
end
+
+ def test_datetime_xml_type_with_utc_time
+ alert_xml = <<-XML
+ <alert>
+ <alert_at type="datetime">2008-02-10T15:30:45Z</alert_at>
+ </alert>
+ XML
+ alert_at = Hash.from_xml(alert_xml)['alert']['alert_at']
+ assert alert_at.utc?
+ assert_equal Time.utc(2008, 2, 10, 15, 30, 45), alert_at
+ end
+
+ def test_datetime_xml_type_with_non_utc_time
+ alert_xml = <<-XML
+ <alert>
+ <alert_at type="datetime">2008-02-10T10:30:45-05:00</alert_at>
+ </alert>
+ XML
+ alert_at = Hash.from_xml(alert_xml)['alert']['alert_at']
+ assert alert_at.utc?
+ assert_equal Time.utc(2008, 2, 10, 15, 30, 45), alert_at
+ end
+
+ def test_datetime_xml_type_with_far_future_date
+ alert_xml = <<-XML
+ <alert>
+ <alert_at type="datetime">2050-02-10T15:30:45Z</alert_at>
+ </alert>
+ XML
+ alert_at = Hash.from_xml(alert_xml)['alert']['alert_at']
+ assert alert_at.utc?
+ assert_equal 2050, alert_at.year
+ assert_equal 2, alert_at.month
+ assert_equal 10, alert_at.day
+ assert_equal 15, alert_at.hour
+ assert_equal 30, alert_at.min
+ assert_equal 45, alert_at.sec
+ end
end
class QueryTest < Test::Unit::TestCase
diff --git a/activesupport/test/core_ext/time_with_zone_test.rb b/activesupport/test/core_ext/time_with_zone_test.rb
index 70c393dd46..c373bca88d 100644
--- a/activesupport/test/core_ext/time_with_zone_test.rb
+++ b/activesupport/test/core_ext/time_with_zone_test.rb
@@ -170,6 +170,13 @@ 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
diff --git a/activesupport/test/dependencies_test.rb b/activesupport/test/dependencies_test.rb
index 9e98e764fd..0309ab6858 100644
--- a/activesupport/test/dependencies_test.rb
+++ b/activesupport/test/dependencies_test.rb
@@ -584,6 +584,12 @@ class DependenciesTest < Test::Unit::TestCase
assert_equal [], m
end
+ def test_new_constants_in_with_illegal_module_name_raises_correct_error
+ assert_raises(NameError) do
+ Dependencies.new_constants_in("Illegal-Name") {}
+ end
+ end
+
def test_file_with_multiple_constants_and_require_dependency
with_loading 'autoloading_fixtures' do
assert ! defined?(MultipleConstantFile)
@@ -667,7 +673,7 @@ class DependenciesTest < Test::Unit::TestCase
assert !defined?(::RaisesNoMethodError), "::RaisesNoMethodError is defined but it should have failed!"
end
end
-
+
ensure
Object.class_eval { remove_const :RaisesNoMethodError if const_defined?(:RaisesNoMethodError) }
end
@@ -680,11 +686,20 @@ class DependenciesTest < Test::Unit::TestCase
assert !defined?(::RaisesNoMethodError), "::RaisesNoMethodError is defined but it should have failed!"
end
end
-
+
ensure
Object.class_eval { remove_const :RaisesNoMethodError if const_defined?(:RaisesNoMethodError) }
end
+ def test_autoload_doesnt_shadow_error_when_mechanism_not_set_to_load
+ with_loading 'autoloading_fixtures' do
+ Dependencies.mechanism = :require
+ 2.times do
+ assert_raise(NameError) {"RaisesNameError".constantize}
+ end
+ end
+ end
+
def test_autoload_doesnt_shadow_name_error
with_loading 'autoloading_fixtures' do
assert !defined?(::RaisesNameError), "::RaisesNameError is defined but it hasn't been referenced yet!"
@@ -708,7 +723,7 @@ class DependenciesTest < Test::Unit::TestCase
ensure
Object.class_eval { remove_const :RaisesNoMethodError if const_defined?(:RaisesNoMethodError) }
end
-
+
def test_remove_constant_handles_double_colon_at_start
Object.const_set 'DeleteMe', Module.new
DeleteMe.const_set 'OrMe', Module.new
@@ -718,7 +733,7 @@ class DependenciesTest < Test::Unit::TestCase
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
@@ -731,7 +746,7 @@ class DependenciesTest < Test::Unit::TestCase
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]
@@ -747,5 +762,4 @@ class DependenciesTest < Test::Unit::TestCase
ensure
Dependencies.load_once_paths = []
end
-
end
diff --git a/activesupport/test/json/encoding_test.rb b/activesupport/test/json/encoding_test.rb
index 7bc8eaf06c..38bb8f3e79 100644
--- a/activesupport/test/json/encoding_test.rb
+++ b/activesupport/test/json/encoding_test.rb
@@ -90,6 +90,15 @@ class TestJSONEncoding < Test::Unit::TestCase
def test_hash_should_allow_key_filtering_with_except
assert_equal %({"b": 2}), { 'foo' => 'bar', :b => 2, :c => 3 }.to_json(:except => ['foo', :c])
end
+
+ def test_time_to_json_includes_local_offset
+ ActiveSupport.use_standard_json_time_format = true
+ with_env_tz 'US/Eastern' do
+ assert_equal %("2005-02-01T15:15:10-05:00"), Time.local(2005,2,1,15,15,10).to_json
+ end
+ ensure
+ ActiveSupport.use_standard_json_time_format = false
+ end
protected
def with_kcode(code)
@@ -108,6 +117,13 @@ class TestJSONEncoding < Test::Unit::TestCase
def object_keys(json_object)
json_object[1..-2].scan(/([^{}:,\s]+):/).flatten.sort
end
+
+ 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
uses_mocha 'JsonOptionsTests' do
diff --git a/activesupport/test/time_zone_test.rb b/activesupport/test/time_zone_test.rb
index 3757ddcedb..f3069b589b 100644
--- a/activesupport/test/time_zone_test.rb
+++ b/activesupport/test/time_zone_test.rb
@@ -252,7 +252,7 @@ class TimeZoneTest < Test::Unit::TestCase
end
def test_to_s
- assert_equal "(UTC+03:00) Moscow", TimeZone['Moscow'].to_s
+ assert_equal "(GMT+03:00) Moscow", TimeZone['Moscow'].to_s
end
def test_all_sorted