From 8dd4aca4850c678f96d0a72098b3a080b51dea44 Mon Sep 17 00:00:00 2001 From: "Birkir A. Barkarson" Date: Wed, 13 Nov 2013 12:31:02 +0900 Subject: Fix breakage in XmlMini - Boolean parsing breaks on non strings (i.e. integer 1|0) - Symbol parsing breaks on non strings. - BigDecimal parsing breaks due to missing require. - Update changelog. --- activesupport/test/xml_mini_test.rb | 125 ++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) (limited to 'activesupport/test') diff --git a/activesupport/test/xml_mini_test.rb b/activesupport/test/xml_mini_test.rb index d992028323..262e5e35c6 100644 --- a/activesupport/test/xml_mini_test.rb +++ b/activesupport/test/xml_mini_test.rb @@ -169,4 +169,129 @@ module XmlMiniTest end end end + + class ParsingTest < ActiveSupport::TestCase + def setup + @parsing = ActiveSupport::XmlMini::PARSING + end + + def test_symbol + parser = @parsing['symbol'] + assert_equal :symbol, parser.call('symbol') + assert_equal :symbol, parser.call(:symbol) + assert_equal :'123', parser.call(123) + assert_raises(ArgumentError) { parser.call(Date.new(2013,11,12,02,11)) } + end + + def test_date + parser = @parsing['date'] + assert_equal Date.new(2013,11,12), parser.call("2013-11-12T0211Z") + assert_raises(TypeError) { parser.call(1384190018) } + assert_raises(ArgumentError) { parser.call("not really a date") } + end + + def test_datetime + parser = @parsing['datetime'] + assert_equal Time.new(2013,11,12,02,11,00,0), parser.call("2013-11-12T02:11:00Z") + assert_equal DateTime.new(2013,11,12), parser.call("2013-11-12T0211Z") + assert_equal DateTime.new(2013,11,12,02,11), parser.call("2013-11-12T02:11Z") + assert_equal DateTime.new(2013,11,12,02,11), parser.call("2013-11-12T11:11+9") + assert_raises(ArgumentError) { parser.call("1384190018") } + end + + def test_integer + parser = @parsing['integer'] + assert_equal 123, parser.call(123) + assert_equal 123, parser.call(123.003) + assert_equal 123, parser.call("123") + assert_equal 0, parser.call("") + assert_raises(ArgumentError) { parser.call(Date.new(2013,11,12,02,11)) } + end + + def test_float + parser = @parsing['float'] + assert_equal 123, parser.call("123") + assert_equal 123.003, parser.call("123.003") + assert_equal 123.0, parser.call("123,003") + assert_equal 0.0, parser.call("") + assert_equal 123, parser.call(123) + assert_equal 123.05, parser.call(123.05) + assert_raises(ArgumentError) { parser.call(Date.new(2013,11,12,02,11)) } + end + + def test_decimal + parser = @parsing['decimal'] + assert_equal 123, parser.call("123") + assert_equal 123.003, parser.call("123.003") + assert_equal 123.0, parser.call("123,003") + assert_equal 0.0, parser.call("") + assert_equal 123, parser.call(123) + assert_raises(ArgumentError) { parser.call(123.04) } + assert_raises(ArgumentError) { parser.call(Date.new(2013,11,12,02,11)) } + end + + def test_boolean + parser = @parsing['boolean'] + [1, true, "1"].each do |value| + assert parser.call(value) + end + + [0, false, "0"].each do |value| + assert_not parser.call(value) + end + end + + def test_string + parser = @parsing['string'] + assert_equal "123", parser.call(123) + assert_equal "123", parser.call("123") + assert_equal "[]", parser.call("[]") + assert_equal "[]", parser.call([]) + assert_equal "{}", parser.call({}) + assert_raises(ArgumentError) { parser.call(Date.new(2013,11,12,02,11)) } + end + + def test_yaml + yaml = < [ + {"sku"=>"BL394D", "quantity"=>4, "description"=>"Basketball"} + ] + } + parser = @parsing['yaml'] + assert_equal(expected, parser.call(yaml)) + assert_equal({1 => 'test'}, parser.call({1 => 'test'})) + assert_equal({"1 => 'test'"=>nil}, parser.call("{1 => 'test'}")) + end + + def test_base64Binary_and_binary + base64 = < 'base64') + assert_equal "IGNORED INPUT", parser.call("IGNORED INPUT", {}) + end + + end end -- cgit v1.2.3 From b5944928700cfc13ed8f615acb54116a3039f345 Mon Sep 17 00:00:00 2001 From: Andrew White Date: Sun, 26 Jan 2014 16:56:33 +0000 Subject: Maintain current timezone when changing time during DST overlap Currently if a time is changed during DST overlap in the autumn then the method `period_for_local` will return the DST period. However if the original time is not DST then this can be surprising and is not what is generally wanted. This commit changes that behavior to maintain the current period if it's in the list of periods returned by `periods_for_local`. It is possible to alter the behavior of `period_for_local` by specifying a second argument but since we may be change from another time that could be either DST or not then this would give inconsistent results. Fixes #12163. --- activesupport/test/core_ext/time_with_zone_test.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'activesupport/test') diff --git a/activesupport/test/core_ext/time_with_zone_test.rb b/activesupport/test/core_ext/time_with_zone_test.rb index 5494824a40..43fe572bfc 100644 --- a/activesupport/test/core_ext/time_with_zone_test.rb +++ b/activesupport/test/core_ext/time_with_zone_test.rb @@ -511,6 +511,11 @@ class TimeWithZoneTest < ActiveSupport::TestCase assert_equal "Fri, 31 Dec 1999 19:00:30 EST -05:00", @twz.change(:sec => 30).inspect end + def test_change_at_dst_boundary + twz = ActiveSupport::TimeWithZone.new(Time.at(1319936400).getutc, ActiveSupport::TimeZone['Madrid']) + assert_equal twz, twz.change(:min => 0) + 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 -- cgit v1.2.3 From 4cfc467594da86090efa63f1852fb82df9458c2b Mon Sep 17 00:00:00 2001 From: Parker Selbert Date: Tue, 16 Jul 2013 16:16:33 -0400 Subject: Customize subsecond digits when encoding DateWithTime The subsecond fraction digits had been hardcoded to 3. This forced all timestamps to include the subsecond digits with no way to customize the value. While the subsecond format is part of the ISO8601 spec, it is not adhered to by all parsers (notably mobile clients). This adds the ability to customize the number of digits used, optionally setting them to 0 in order to eliminate the subsecond fraction entirely: ActiveSupport::JSON::Encoding.subsecond_fraction_digits = 0 --- activesupport/test/core_ext/time_with_zone_test.rb | 29 ++++++++++++++++------ 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'activesupport/test') diff --git a/activesupport/test/core_ext/time_with_zone_test.rb b/activesupport/test/core_ext/time_with_zone_test.rb index 43fe572bfc..4ea8d2bed6 100644 --- a/activesupport/test/core_ext/time_with_zone_test.rb +++ b/activesupport/test/core_ext/time_with_zone_test.rb @@ -67,17 +67,25 @@ class TimeWithZoneTest < ActiveSupport::TestCase end def test_to_json_with_use_standard_json_time_format_config_set_to_false - old, ActiveSupport.use_standard_json_time_format = ActiveSupport.use_standard_json_time_format, false - assert_equal "\"1999/12/31 19:00:00 -0500\"", ActiveSupport::JSON.encode(@twz) - ensure - ActiveSupport.use_standard_json_time_format = old + with_standard_json_time_format(false) do + assert_equal "\"1999/12/31 19:00:00 -0500\"", ActiveSupport::JSON.encode(@twz) + 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.000-05:00\"", ActiveSupport::JSON.encode(@twz) + with_standard_json_time_format(true) do + assert_equal "\"1999-12-31T19:00:00.000-05:00\"", ActiveSupport::JSON.encode(@twz) + end + end + + def test_to_json_with_custom_subsecond_resolution + with_standard_json_time_format(true) do + ActiveSupport::JSON::Encoding.subsecond_fraction_digits = 0 + + assert_equal "\"1999-12-31T19:00:00-05:00\"", ActiveSupport::JSON.encode(@twz) + end ensure - ActiveSupport.use_standard_json_time_format = old + ActiveSupport::JSON::Encoding.subsecond_fraction_digits = nil end def test_to_json_when_wrapping_a_date_time @@ -814,6 +822,13 @@ class TimeWithZoneTest < ActiveSupport::TestCase ensure old_tz ? ENV['TZ'] = old_tz : ENV.delete('TZ') end + + def with_standard_json_time_format(boolean = true) + old, ActiveSupport.use_standard_json_time_format = ActiveSupport.use_standard_json_time_format, boolean + yield + ensure + ActiveSupport.use_standard_json_time_format = old + end end class TimeWithZoneMethodsForTimeAndDateTimeTest < ActiveSupport::TestCase -- cgit v1.2.3 From ef17225173131541f0f5495ea31fc51ea46cb236 Mon Sep 17 00:00:00 2001 From: Andrew White Date: Sun, 26 Jan 2014 20:32:34 +0000 Subject: Consolidate JSON encoding tests in one file --- activesupport/test/core_ext/time_with_zone_test.rb | 35 ------------- activesupport/test/json/encoding_test.rb | 59 ++++++++++++++++++---- 2 files changed, 48 insertions(+), 46 deletions(-) (limited to 'activesupport/test') diff --git a/activesupport/test/core_ext/time_with_zone_test.rb b/activesupport/test/core_ext/time_with_zone_test.rb index 4ea8d2bed6..e9bf43667a 100644 --- a/activesupport/test/core_ext/time_with_zone_test.rb +++ b/activesupport/test/core_ext/time_with_zone_test.rb @@ -1,6 +1,5 @@ require 'abstract_unit' require 'active_support/time' -require 'active_support/json' class TimeWithZoneTest < ActiveSupport::TestCase @@ -66,33 +65,6 @@ class TimeWithZoneTest < ActiveSupport::TestCase assert_equal 'EDT', ActiveSupport::TimeWithZone.new(Time.utc(2000, 6), @time_zone).zone #dst end - def test_to_json_with_use_standard_json_time_format_config_set_to_false - with_standard_json_time_format(false) do - assert_equal "\"1999/12/31 19:00:00 -0500\"", ActiveSupport::JSON.encode(@twz) - end - end - - def test_to_json_with_use_standard_json_time_format_config_set_to_true - with_standard_json_time_format(true) do - assert_equal "\"1999-12-31T19:00:00.000-05:00\"", ActiveSupport::JSON.encode(@twz) - end - end - - def test_to_json_with_custom_subsecond_resolution - with_standard_json_time_format(true) do - ActiveSupport::JSON::Encoding.subsecond_fraction_digits = 0 - - assert_equal "\"1999-12-31T19:00:00-05:00\"", ActiveSupport::JSON.encode(@twz) - end - ensure - ActiveSupport::JSON::Encoding.subsecond_fraction_digits = nil - end - - def test_to_json_when_wrapping_a_date_time - twz = ActiveSupport::TimeWithZone.new(DateTime.civil(2000), @time_zone) - assert_equal '"1999-12-31T19:00:00.000-05:00"', ActiveSupport::JSON.encode(twz) - end - def test_nsec local = Time.local(2011,6,7,23,59,59,Rational(999999999, 1000)) with_zone = ActiveSupport::TimeWithZone.new(nil, ActiveSupport::TimeZone["Hawaii"], local) @@ -822,13 +794,6 @@ class TimeWithZoneTest < ActiveSupport::TestCase ensure old_tz ? ENV['TZ'] = old_tz : ENV.delete('TZ') end - - def with_standard_json_time_format(boolean = true) - old, ActiveSupport.use_standard_json_time_format = ActiveSupport.use_standard_json_time_format, boolean - yield - ensure - ActiveSupport.use_standard_json_time_format = old - end end class TimeWithZoneMethodsForTimeAndDateTimeTest < ActiveSupport::TestCase diff --git a/activesupport/test/json/encoding_test.rb b/activesupport/test/json/encoding_test.rb index 78cf4819f9..ef76d63f29 100644 --- a/activesupport/test/json/encoding_test.rb +++ b/activesupport/test/json/encoding_test.rb @@ -3,6 +3,7 @@ require 'securerandom' require 'abstract_unit' require 'active_support/core_ext/string/inflections' require 'active_support/json' +require 'active_support/time' class TestJSONEncoding < ActiveSupport::TestCase class Foo @@ -226,21 +227,17 @@ class TestJSONEncoding < ActiveSupport::TestCase end def test_time_to_json_includes_local_offset - prev = ActiveSupport.use_standard_json_time_format - ActiveSupport.use_standard_json_time_format = true - with_env_tz 'US/Eastern' do - assert_equal %("2005-02-01T15:15:10.000-05:00"), ActiveSupport::JSON.encode(Time.local(2005,2,1,15,15,10)) + with_standard_json_time_format(true) do + with_env_tz 'US/Eastern' do + assert_equal %("2005-02-01T15:15:10.000-05:00"), ActiveSupport::JSON.encode(Time.local(2005,2,1,15,15,10)) + end end - ensure - ActiveSupport.use_standard_json_time_format = prev end def test_hash_with_time_to_json - prev = ActiveSupport.use_standard_json_time_format - ActiveSupport.use_standard_json_time_format = false - assert_equal '{"time":"2009/01/01 00:00:00 +0000"}', { :time => Time.utc(2009) }.to_json - ensure - ActiveSupport.use_standard_json_time_format = prev + with_standard_json_time_format(false) do + assert_equal '{"time":"2009/01/01 00:00:00 +0000"}', { :time => Time.utc(2009) }.to_json + end end def test_nested_hash_with_float @@ -453,6 +450,39 @@ EXPECTED assert_nil h.as_json_called end + def test_twz_to_json_with_use_standard_json_time_format_config_set_to_false + with_standard_json_time_format(false) do + zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] + time = ActiveSupport::TimeWithZone.new(Time.utc(2000), zone) + assert_equal "\"1999/12/31 19:00:00 -0500\"", ActiveSupport::JSON.encode(time) + end + end + + def test_twz_to_json_with_use_standard_json_time_format_config_set_to_true + with_standard_json_time_format(true) do + zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] + time = ActiveSupport::TimeWithZone.new(Time.utc(2000), zone) + assert_equal "\"1999-12-31T19:00:00.000-05:00\"", ActiveSupport::JSON.encode(time) + end + end + + def test_twz_to_json_with_custom_subsecond_resolution + with_standard_json_time_format(true) do + ActiveSupport::JSON::Encoding.subsecond_fraction_digits = 0 + zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] + time = ActiveSupport::TimeWithZone.new(Time.utc(2000), zone) + assert_equal "\"1999-12-31T19:00:00-05:00\"", ActiveSupport::JSON.encode(time) + end + ensure + ActiveSupport::JSON::Encoding.subsecond_fraction_digits = nil + end + + def test_twz_to_json_when_wrapping_a_date_time + zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] + time = ActiveSupport::TimeWithZone.new(DateTime.new(2000), zone) + assert_equal '"1999-12-31T19:00:00.000-05:00"', ActiveSupport::JSON.encode(time) + end + protected def object_keys(json_object) @@ -465,4 +495,11 @@ EXPECTED ensure old_tz ? ENV['TZ'] = old_tz : ENV.delete('TZ') end + + def with_standard_json_time_format(boolean = true) + old, ActiveSupport.use_standard_json_time_format = ActiveSupport.use_standard_json_time_format, boolean + yield + ensure + ActiveSupport.use_standard_json_time_format = old + end end -- cgit v1.2.3 From e3c382e3d69e7f25593cf45a4acc1b74bb93d057 Mon Sep 17 00:00:00 2001 From: Andrew White Date: Sun, 26 Jan 2014 20:39:16 +0000 Subject: Rename subsecond_fraction_digits option to time_precision --- activesupport/test/json/encoding_test.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'activesupport/test') diff --git a/activesupport/test/json/encoding_test.rb b/activesupport/test/json/encoding_test.rb index ef76d63f29..52d2708d1e 100644 --- a/activesupport/test/json/encoding_test.rb +++ b/activesupport/test/json/encoding_test.rb @@ -466,15 +466,15 @@ EXPECTED end end - def test_twz_to_json_with_custom_subsecond_resolution + def test_twz_to_json_with_custom_time_precision with_standard_json_time_format(true) do - ActiveSupport::JSON::Encoding.subsecond_fraction_digits = 0 + ActiveSupport::JSON::Encoding.time_precision = 0 zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] time = ActiveSupport::TimeWithZone.new(Time.utc(2000), zone) assert_equal "\"1999-12-31T19:00:00-05:00\"", ActiveSupport::JSON.encode(time) end ensure - ActiveSupport::JSON::Encoding.subsecond_fraction_digits = nil + ActiveSupport::JSON::Encoding.time_precision = nil end def test_twz_to_json_when_wrapping_a_date_time -- cgit v1.2.3 From c0965004486f2ea5a9656ba718a3377c9614f97d Mon Sep 17 00:00:00 2001 From: Andrew White Date: Sun, 26 Jan 2014 21:09:06 +0000 Subject: Add support for JSON time_precision to Time and DateTime --- activesupport/test/json/encoding_test.rb | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'activesupport/test') diff --git a/activesupport/test/json/encoding_test.rb b/activesupport/test/json/encoding_test.rb index 52d2708d1e..c4283ee79a 100644 --- a/activesupport/test/json/encoding_test.rb +++ b/activesupport/test/json/encoding_test.rb @@ -474,7 +474,25 @@ EXPECTED assert_equal "\"1999-12-31T19:00:00-05:00\"", ActiveSupport::JSON.encode(time) end ensure - ActiveSupport::JSON::Encoding.time_precision = nil + ActiveSupport::JSON::Encoding.time_precision = 3 + end + + def test_time_to_json_with_custom_time_precision + with_standard_json_time_format(true) do + ActiveSupport::JSON::Encoding.time_precision = 0 + assert_equal "\"2000-01-01T00:00:00Z\"", ActiveSupport::JSON.encode(Time.utc(2000)) + end + ensure + ActiveSupport::JSON::Encoding.time_precision = 3 + end + + def test_datetime_to_json_with_custom_time_precision + with_standard_json_time_format(true) do + ActiveSupport::JSON::Encoding.time_precision = 0 + assert_equal "\"2000-01-01T00:00:00+00:00\"", ActiveSupport::JSON.encode(DateTime.new(2000)) + end + ensure + ActiveSupport::JSON::Encoding.time_precision = 3 end def test_twz_to_json_when_wrapping_a_date_time -- cgit v1.2.3 From dd339bb0adc3bb1f0c376c4352f769ae2ab02b62 Mon Sep 17 00:00:00 2001 From: Andrew White Date: Sun, 26 Jan 2014 21:22:23 +0000 Subject: Make ActiveSupport::TimeWithZone#xmlschema consistent Both Time#xmlschema and DateTime#xmlschema can accept nil values for the fraction_digits parameter. This commit makes this so for TimeWithZone values as well. --- activesupport/test/core_ext/time_with_zone_test.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'activesupport/test') diff --git a/activesupport/test/core_ext/time_with_zone_test.rb b/activesupport/test/core_ext/time_with_zone_test.rb index e9bf43667a..8e25f1e2f2 100644 --- a/activesupport/test/core_ext/time_with_zone_test.rb +++ b/activesupport/test/core_ext/time_with_zone_test.rb @@ -111,6 +111,10 @@ class TimeWithZoneTest < ActiveSupport::TestCase assert_equal "1999-12-31T19:00:00.001234-05:00", @twz.xmlschema(12) end + def test_xmlschema_with_nil_fractional_seconds + assert_equal "1999-12-31T19:00:00-05:00", @twz.xmlschema(nil) + end + def test_to_yaml assert_match(/^--- 2000-01-01 00:00:00(\.0+)?\s*Z\n/, @twz.to_yaml) end -- cgit v1.2.3 From 6b16c2788186d45c70bd1d9fc476407e3e265439 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Wed, 29 Jan 2014 22:24:48 -0200 Subject: Add `travel_back` to remove stubs from `travel` and `travel_to` --- activesupport/test/test_test.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'activesupport/test') diff --git a/activesupport/test/test_test.rb b/activesupport/test/test_test.rb index 8a71ef4324..1e539d8d06 100644 --- a/activesupport/test/test_test.rb +++ b/activesupport/test/test_test.rb @@ -201,4 +201,16 @@ class TimeHelperTest < ActiveSupport::TestCase assert_not_equal expected_time, Time.now assert_not_equal Date.new(2004, 11, 24), Date.today end + + def test_time_helper_travel_back + expected_time = Time.new(2004, 11, 24, 01, 04, 44) + + travel_to expected_time + assert_equal expected_time, Time.now + assert_equal Date.new(2004, 11, 24), Date.today + travel_back + + assert_not_equal expected_time, Time.now + assert_not_equal Date.new(2004, 11, 24), Date.today + end end -- cgit v1.2.3 From 7abb6e00c0f1d6cc98b10b0e7620dfb9786449a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Wed, 29 Jan 2014 22:41:30 -0200 Subject: Remove automatic removal of Date/Time stubs after each test case This behavior is only work out-of-box with minitest and also add a downside to run after each test case, even if we don't used the travel or travel_to methods --- activesupport/test/test_test.rb | 4 ++++ activesupport/test/time_zone_test.rb | 3 +++ 2 files changed, 7 insertions(+) (limited to 'activesupport/test') diff --git a/activesupport/test/test_test.rb b/activesupport/test/test_test.rb index 1e539d8d06..0fa08c0e3a 100644 --- a/activesupport/test/test_test.rb +++ b/activesupport/test/test_test.rb @@ -162,6 +162,10 @@ class TimeHelperTest < ActiveSupport::TestCase Time.stubs now: Time.now end + teardown do + travel_back + end + def test_time_helper_travel expected_time = Time.now + 1.day travel 1.day diff --git a/activesupport/test/time_zone_test.rb b/activesupport/test/time_zone_test.rb index 1107b48460..cd79efbe8c 100644 --- a/activesupport/test/time_zone_test.rb +++ b/activesupport/test/time_zone_test.rb @@ -97,6 +97,7 @@ class TimeZoneTest < ActiveSupport::TestCase assert_equal Date.new(2000, 1, 1), ActiveSupport::TimeZone['Eastern Time (US & Canada)'].today travel_to(Time.utc(2000, 1, 2, 5)) # midnight Jan 2 EST assert_equal Date.new(2000, 1, 2), ActiveSupport::TimeZone['Eastern Time (US & Canada)'].today + travel_back end def test_tomorrow @@ -108,6 +109,7 @@ class TimeZoneTest < ActiveSupport::TestCase assert_equal Date.new(2000, 1, 2), ActiveSupport::TimeZone['Eastern Time (US & Canada)'].tomorrow travel_to(Time.utc(2000, 1, 2, 5)) # midnight Jan 2 EST assert_equal Date.new(2000, 1, 3), ActiveSupport::TimeZone['Eastern Time (US & Canada)'].tomorrow + travel_back end def test_yesterday @@ -119,6 +121,7 @@ class TimeZoneTest < ActiveSupport::TestCase assert_equal Date.new(1999, 12, 31), ActiveSupport::TimeZone['Eastern Time (US & Canada)'].yesterday travel_to(Time.utc(2000, 1, 2, 5)) # midnight Jan 2 EST assert_equal Date.new(2000, 1, 1), ActiveSupport::TimeZone['Eastern Time (US & Canada)'].yesterday + travel_back end def test_local -- cgit v1.2.3 From 63f8fabe4939ad59d597dfea441002ef5b16d2f4 Mon Sep 17 00:00:00 2001 From: Andrew White Date: Fri, 31 Jan 2014 17:13:12 +0000 Subject: Maintain the current timezone in wrap_with_time_zone Extend the solution from the fix for #12163 to the general case where `Time` methods are wrapped with a time zone. Fixes #12596. --- activesupport/test/core_ext/time_with_zone_test.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'activesupport/test') diff --git a/activesupport/test/core_ext/time_with_zone_test.rb b/activesupport/test/core_ext/time_with_zone_test.rb index 8e25f1e2f2..7fe4d4a6b2 100644 --- a/activesupport/test/core_ext/time_with_zone_test.rb +++ b/activesupport/test/core_ext/time_with_zone_test.rb @@ -500,6 +500,11 @@ class TimeWithZoneTest < ActiveSupport::TestCase assert_equal twz, twz.change(:min => 0) end + def test_round_at_dst_boundary + twz = ActiveSupport::TimeWithZone.new(Time.at(1319936400).getutc, ActiveSupport::TimeZone['Madrid']) + assert_equal twz, twz.round + 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 -- cgit v1.2.3 From 85d820b1693a52faddf1f838512e132906272e41 Mon Sep 17 00:00:00 2001 From: David Celis Date: Fri, 31 Jan 2014 17:42:21 -0800 Subject: Don't require BigDecimal serialization extension Rails currently provides an extension to BigDecimal that redefines how it is serialized to YAML. However, as noted in #12467, this does not work as expected. When ActiveSupport is required, BigDecimal YAML serialization does not maintain the object type. It instead ends up serializing the number represented by the BigDecimal itself which, when loaded by YAML later, becomes a Float: ```ruby require 'yaml' require 'bigdecimal' yaml = BigDecimal('13.37').to_yaml YAML.load(yaml).class require 'active_support/all' yaml = BigDecimal('13.37').to_yaml YAML.load(yaml).class ``` @tenderlove posits that we should deprecate the custom BigDecimal serialization and let Ruby handle it. For the time being, users who require this serialization for backwards compatibility can manually `require 'active_support/core_ext/big_decimal/yaml_conversions'`. This will close #12467 and deprecate the custom BigDecimal#to_yaml. Signed-off-by: David Celis --- .../test/core_ext/big_decimal/yaml_conversions_test.rb | 11 +++++++++++ activesupport/test/core_ext/bigdecimal_test.rb | 9 +-------- 2 files changed, 12 insertions(+), 8 deletions(-) create mode 100644 activesupport/test/core_ext/big_decimal/yaml_conversions_test.rb (limited to 'activesupport/test') diff --git a/activesupport/test/core_ext/big_decimal/yaml_conversions_test.rb b/activesupport/test/core_ext/big_decimal/yaml_conversions_test.rb new file mode 100644 index 0000000000..49020e0567 --- /dev/null +++ b/activesupport/test/core_ext/big_decimal/yaml_conversions_test.rb @@ -0,0 +1,11 @@ +require 'abstract_unit' +require 'active_support/core_ext/big_decimal/yaml_conversions' + +class BigDecimalYamlConversionsTest < ActiveSupport::TestCase + def test_to_yaml + assert_match("--- 100000.30020320320000000000000000000000000000001\n", BigDecimal.new('100000.30020320320000000000000000000000000000001').to_yaml) + assert_match("--- .Inf\n", BigDecimal.new('Infinity').to_yaml) + assert_match("--- .NaN\n", BigDecimal.new('NaN').to_yaml) + assert_match("--- -.Inf\n", BigDecimal.new('-Infinity').to_yaml) + end +end diff --git a/activesupport/test/core_ext/bigdecimal_test.rb b/activesupport/test/core_ext/bigdecimal_test.rb index b386e55d6c..61bf3f81e6 100644 --- a/activesupport/test/core_ext/bigdecimal_test.rb +++ b/activesupport/test/core_ext/bigdecimal_test.rb @@ -2,18 +2,11 @@ require 'abstract_unit' require 'active_support/core_ext/big_decimal' class BigDecimalTest < ActiveSupport::TestCase - def test_to_yaml - assert_match("--- 100000.30020320320000000000000000000000000000001\n", BigDecimal.new('100000.30020320320000000000000000000000000000001').to_yaml) - assert_match("--- .Inf\n", BigDecimal.new('Infinity').to_yaml) - assert_match("--- .NaN\n", BigDecimal.new('NaN').to_yaml) - assert_match("--- -.Inf\n", BigDecimal.new('-Infinity').to_yaml) - end - def test_to_d bd = BigDecimal.new '10' assert_equal bd, bd.to_d end - + def test_to_s bd = BigDecimal.new '0.01' assert_equal '0.01', bd.to_s -- cgit v1.2.3 From c87b27ebde4c5a0bc172ffce59faaadb20301dec Mon Sep 17 00:00:00 2001 From: David Celis Date: Sat, 1 Feb 2014 10:26:50 -0800 Subject: Remove BigDecimal#to_d This was backported for Ruby 1.8 support and is no longer needed. Signed-off-by: David Celis --- activesupport/test/core_ext/bigdecimal_test.rb | 5 ----- 1 file changed, 5 deletions(-) (limited to 'activesupport/test') diff --git a/activesupport/test/core_ext/bigdecimal_test.rb b/activesupport/test/core_ext/bigdecimal_test.rb index 61bf3f81e6..423a3f2e9d 100644 --- a/activesupport/test/core_ext/bigdecimal_test.rb +++ b/activesupport/test/core_ext/bigdecimal_test.rb @@ -2,11 +2,6 @@ require 'abstract_unit' require 'active_support/core_ext/big_decimal' class BigDecimalTest < ActiveSupport::TestCase - def test_to_d - bd = BigDecimal.new '10' - assert_equal bd, bd.to_d - end - def test_to_s bd = BigDecimal.new '0.01' assert_equal '0.01', bd.to_s -- cgit v1.2.3 From 4ac114471cc14de44b77ced3dd4a0676c13b818b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Sat, 1 Feb 2014 18:29:53 -0200 Subject: Assert the file is deprecated --- activesupport/test/core_ext/big_decimal/yaml_conversions_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport/test') diff --git a/activesupport/test/core_ext/big_decimal/yaml_conversions_test.rb b/activesupport/test/core_ext/big_decimal/yaml_conversions_test.rb index 49020e0567..e634679d20 100644 --- a/activesupport/test/core_ext/big_decimal/yaml_conversions_test.rb +++ b/activesupport/test/core_ext/big_decimal/yaml_conversions_test.rb @@ -1,8 +1,8 @@ require 'abstract_unit' -require 'active_support/core_ext/big_decimal/yaml_conversions' class BigDecimalYamlConversionsTest < ActiveSupport::TestCase def test_to_yaml + assert_deprecated { require 'active_support/core_ext/big_decimal/yaml_conversions' } assert_match("--- 100000.30020320320000000000000000000000000000001\n", BigDecimal.new('100000.30020320320000000000000000000000000000001').to_yaml) assert_match("--- .Inf\n", BigDecimal.new('Infinity').to_yaml) assert_match("--- .NaN\n", BigDecimal.new('NaN').to_yaml) -- cgit v1.2.3 From 4c3e11d30a9295404c54646a5d0c8a47991c35d4 Mon Sep 17 00:00:00 2001 From: Marc-Andre Lafortune Date: Tue, 4 Feb 2014 01:51:21 -0500 Subject: Remove obsolete line (was needed for Ruby 1.8.7 support) --- activesupport/test/core_ext/enumerable_test.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'activesupport/test') diff --git a/activesupport/test/core_ext/enumerable_test.rb b/activesupport/test/core_ext/enumerable_test.rb index 6781e3c20e..6c32622e71 100644 --- a/activesupport/test/core_ext/enumerable_test.rb +++ b/activesupport/test/core_ext/enumerable_test.rb @@ -8,7 +8,6 @@ class SummablePayment < Payment end class EnumerableTests < ActiveSupport::TestCase - Enumerator = [].each.class class GenericEnumerable include Enumerable -- cgit v1.2.3 From 39b2cc1900b0cb10057d46d7e2ed54f8e0b1e26f Mon Sep 17 00:00:00 2001 From: Marc-Andre Lafortune Date: Tue, 4 Feb 2014 01:57:27 -0500 Subject: Remove obsolete test (builtin group_by is now used) --- activesupport/test/core_ext/enumerable_test.rb | 20 -------------------- 1 file changed, 20 deletions(-) (limited to 'activesupport/test') diff --git a/activesupport/test/core_ext/enumerable_test.rb b/activesupport/test/core_ext/enumerable_test.rb index 6c32622e71..6b3e8364c5 100644 --- a/activesupport/test/core_ext/enumerable_test.rb +++ b/activesupport/test/core_ext/enumerable_test.rb @@ -20,26 +20,6 @@ class EnumerableTests < ActiveSupport::TestCase end end - def test_group_by - names = %w(marcel sam david jeremy) - klass = Struct.new(:name) - objects = (1..50).map do - klass.new names.sample - end - - enum = GenericEnumerable.new(objects) - grouped = enum.group_by { |object| object.name } - - grouped.each do |name, group| - assert group.all? { |person| person.name == name } - end - - assert_equal objects.uniq.map(&:name), grouped.keys - assert({}.merge(grouped), "Could not convert ActiveSupport::OrderedHash into Hash") - assert_equal Enumerator, enum.group_by.class - assert_equal grouped, enum.group_by.each(&:name) - end - def test_sums enum = GenericEnumerable.new([5, 15, 10]) assert_equal 30, enum.sum -- cgit v1.2.3 From a476020567a47f5fbec3629707d5bf31b400a284 Mon Sep 17 00:00:00 2001 From: Marc-Andre Lafortune Date: Tue, 4 Feb 2014 02:18:03 -0500 Subject: Return sized enumerator from Enumerable#index_by --- activesupport/test/core_ext/enumerable_test.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'activesupport/test') diff --git a/activesupport/test/core_ext/enumerable_test.rb b/activesupport/test/core_ext/enumerable_test.rb index 6b3e8364c5..6fcf6e8743 100644 --- a/activesupport/test/core_ext/enumerable_test.rb +++ b/activesupport/test/core_ext/enumerable_test.rb @@ -73,6 +73,10 @@ class EnumerableTests < ActiveSupport::TestCase assert_equal({ 5 => Payment.new(5), 15 => Payment.new(15), 10 => Payment.new(10) }, payments.index_by { |p| p.price }) assert_equal Enumerator, payments.index_by.class + if Enumerator.method_defined? :size + assert_equal nil, payments.index_by.size + assert_equal 42, (1..42).index_by.size + end assert_equal({ 5 => Payment.new(5), 15 => Payment.new(15), 10 => Payment.new(10) }, payments.index_by.each { |p| p.price }) end -- cgit v1.2.3 From 26698fb91d88dca0f860adcb80528d8d3f0f6285 Mon Sep 17 00:00:00 2001 From: Sean Walbran Date: Wed, 5 Feb 2014 17:19:51 -0600 Subject: fix interplay of humanize and html_escape --- activesupport/test/core_ext/string_ext_test.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'activesupport/test') diff --git a/activesupport/test/core_ext/string_ext_test.rb b/activesupport/test/core_ext/string_ext_test.rb index d4f8ba8cdd..072b970a2d 100644 --- a/activesupport/test/core_ext/string_ext_test.rb +++ b/activesupport/test/core_ext/string_ext_test.rb @@ -161,6 +161,10 @@ class StringInflectionsTest < ActiveSupport::TestCase end end + def test_humanize_with_html_escape + assert_equal 'Hello', ERB::Util.html_escape("hello").humanize + end + def test_ord assert_equal 97, 'a'.ord assert_equal 97, 'abc'.ord -- cgit v1.2.3 From 326e6527497126b2ea3627e377b6a4b5c9191bef Mon Sep 17 00:00:00 2001 From: Hincu Petru Date: Mon, 3 Feb 2014 09:51:05 +0000 Subject: Fixed "Hash#to_param confused by empty hash values #13892" --- activesupport/test/core_ext/object/to_param_test.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'activesupport/test') diff --git a/activesupport/test/core_ext/object/to_param_test.rb b/activesupport/test/core_ext/object/to_param_test.rb index bd7c6c422a..eae68ed184 100644 --- a/activesupport/test/core_ext/object/to_param_test.rb +++ b/activesupport/test/core_ext/object/to_param_test.rb @@ -1,5 +1,6 @@ require 'abstract_unit' require 'active_support/core_ext/object/to_param' +require 'active_support/core_ext/object/to_query' class ToParamTest < ActiveSupport::TestCase def test_object @@ -16,4 +17,14 @@ class ToParamTest < ActiveSupport::TestCase assert_equal true, true.to_param assert_equal false, false.to_param end + + def test_nested_empty_hash + hash1 = {a: 1, b: {c: 3, d: {}}}.to_param + hash2 = {p: 12, b: {c: 3, e: nil, f: ''}}.to_param + hash3 = {b: {c: 3, k: {}, f: '' }}.to_param + + assert_equal 'a=1&b[c]=3&b[d]=', CGI::unescape(hash1) + assert_equal 'b[c]=3&b[e]=&b[f]=&p=12', CGI::unescape(hash2) + assert_equal 'b[c]=3&b[f]=&b[k]=', CGI::unescape(hash3) + end end -- cgit v1.2.3 From 88b064dfae924f28ec4750ea5a3a91b855481546 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Wed, 5 Feb 2014 23:42:43 -0200 Subject: Move test to the right file --- activesupport/test/core_ext/object/to_param_test.rb | 11 ----------- activesupport/test/core_ext/object/to_query_test.rb | 9 +++++++++ 2 files changed, 9 insertions(+), 11 deletions(-) (limited to 'activesupport/test') diff --git a/activesupport/test/core_ext/object/to_param_test.rb b/activesupport/test/core_ext/object/to_param_test.rb index eae68ed184..bd7c6c422a 100644 --- a/activesupport/test/core_ext/object/to_param_test.rb +++ b/activesupport/test/core_ext/object/to_param_test.rb @@ -1,6 +1,5 @@ require 'abstract_unit' require 'active_support/core_ext/object/to_param' -require 'active_support/core_ext/object/to_query' class ToParamTest < ActiveSupport::TestCase def test_object @@ -17,14 +16,4 @@ class ToParamTest < ActiveSupport::TestCase assert_equal true, true.to_param assert_equal false, false.to_param end - - def test_nested_empty_hash - hash1 = {a: 1, b: {c: 3, d: {}}}.to_param - hash2 = {p: 12, b: {c: 3, e: nil, f: ''}}.to_param - hash3 = {b: {c: 3, k: {}, f: '' }}.to_param - - assert_equal 'a=1&b[c]=3&b[d]=', CGI::unescape(hash1) - assert_equal 'b[c]=3&b[e]=&b[f]=&p=12', CGI::unescape(hash2) - assert_equal 'b[c]=3&b[f]=&b[k]=', CGI::unescape(hash3) - end end diff --git a/activesupport/test/core_ext/object/to_query_test.rb b/activesupport/test/core_ext/object/to_query_test.rb index 92f996f9a4..a53d7781f9 100644 --- a/activesupport/test/core_ext/object/to_query_test.rb +++ b/activesupport/test/core_ext/object/to_query_test.rb @@ -46,6 +46,15 @@ class ToQueryTest < ActiveSupport::TestCase :person => {:id => [20, 10]} end + def test_nested_empty_hash + assert_query_equal 'a=1&b%5Bc%5D=3&b%5Bd%5D=', + { a: 1, b: { c: 3, d: {} } } + assert_query_equal 'b%5Bc%5D=3&b%5Be%5D=&b%5Bf%5D=&p=12', + { p: 12, b: { c: 3, e: nil, f: '' } } + assert_query_equal 'b%5Bc%5D=3&b%5Bf%5D=&b%5Bk%5D=', + { b: { c: 3, k: {}, f: '' } } + end + private def assert_query_equal(expected, actual) assert_equal expected.split('&'), actual.to_query.split('&') -- cgit v1.2.3 From d6e3fd775b8a0277b07b06c22c29f66dbafe6559 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Wed, 5 Feb 2014 23:47:16 -0200 Subject: Test with a blank value --- activesupport/test/core_ext/object/to_query_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'activesupport/test') diff --git a/activesupport/test/core_ext/object/to_query_test.rb b/activesupport/test/core_ext/object/to_query_test.rb index a53d7781f9..51275e36bf 100644 --- a/activesupport/test/core_ext/object/to_query_test.rb +++ b/activesupport/test/core_ext/object/to_query_test.rb @@ -49,8 +49,8 @@ class ToQueryTest < ActiveSupport::TestCase def test_nested_empty_hash assert_query_equal 'a=1&b%5Bc%5D=3&b%5Bd%5D=', { a: 1, b: { c: 3, d: {} } } - assert_query_equal 'b%5Bc%5D=3&b%5Be%5D=&b%5Bf%5D=&p=12', - { p: 12, b: { c: 3, e: nil, f: '' } } + assert_query_equal 'b%5Bc%5D=false&b%5Be%5D=&b%5Bf%5D=&p=12', + { p: 12, b: { c: false, e: nil, f: '' } } assert_query_equal 'b%5Bc%5D=3&b%5Bf%5D=&b%5Bk%5D=', { b: { c: 3, k: {}, f: '' } } end -- cgit v1.2.3 From ab51b285e2cccdc0cbdcd2daa04a7fd2fbb661ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Wed, 5 Feb 2014 23:55:17 -0200 Subject: Refatoring the method to avoid shot-circuit return --- activesupport/test/core_ext/object/to_query_test.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'activesupport/test') diff --git a/activesupport/test/core_ext/object/to_query_test.rb b/activesupport/test/core_ext/object/to_query_test.rb index 51275e36bf..a892471e0f 100644 --- a/activesupport/test/core_ext/object/to_query_test.rb +++ b/activesupport/test/core_ext/object/to_query_test.rb @@ -47,6 +47,8 @@ class ToQueryTest < ActiveSupport::TestCase end def test_nested_empty_hash + assert_equal '', + {}.to_query assert_query_equal 'a=1&b%5Bc%5D=3&b%5Bd%5D=', { a: 1, b: { c: 3, d: {} } } assert_query_equal 'b%5Bc%5D=false&b%5Be%5D=&b%5Bf%5D=&p=12', -- cgit v1.2.3 From c82dbc6a1c1a269fb21de8fd2722fc680ab7ea54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Thu, 6 Feb 2014 01:03:41 -0200 Subject: Fix to_query with empty arrays too --- activesupport/test/core_ext/object/to_query_test.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'activesupport/test') diff --git a/activesupport/test/core_ext/object/to_query_test.rb b/activesupport/test/core_ext/object/to_query_test.rb index a892471e0f..f887a9e613 100644 --- a/activesupport/test/core_ext/object/to_query_test.rb +++ b/activesupport/test/core_ext/object/to_query_test.rb @@ -55,6 +55,8 @@ class ToQueryTest < ActiveSupport::TestCase { p: 12, b: { c: false, e: nil, f: '' } } assert_query_equal 'b%5Bc%5D=3&b%5Bf%5D=&b%5Bk%5D=', { b: { c: 3, k: {}, f: '' } } + assert_query_equal 'a%5B%5D=&b=3', + {a: [], b: 3} end private -- cgit v1.2.3 From 4fa8c8b52f2ee7155b18cee2f3fc978075c68db1 Mon Sep 17 00:00:00 2001 From: Noah Lindner Date: Sat, 8 Feb 2014 15:35:12 -0800 Subject: Fixed an issue where reloading of removed dependencies would cause an unexpected circular dependency error --- activesupport/test/dependencies_test.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'activesupport/test') diff --git a/activesupport/test/dependencies_test.rb b/activesupport/test/dependencies_test.rb index 00bec5bd9d..4ca63b3417 100644 --- a/activesupport/test/dependencies_test.rb +++ b/activesupport/test/dependencies_test.rb @@ -948,6 +948,18 @@ class DependenciesTest < ActiveSupport::TestCase Object.class_eval { remove_const :A if const_defined?(:A) } end + def test_access_unloaded_constants_for_reload + with_autoloading_fixtures do + assert_kind_of Module, A + assert_kind_of Class, A::B # Necessary to load A::B for the test + ActiveSupport::Dependencies.mark_for_unload(A::B) + ActiveSupport::Dependencies.remove_unloadable_constants! + + A::B # Make sure no circular dependency error + end + end + + def test_autoload_once_paths_should_behave_when_recursively_loading with_loading 'dependencies', 'autoloading_fixtures' do ActiveSupport::Dependencies.autoload_once_paths = [ActiveSupport::Dependencies.autoload_paths.last] -- cgit v1.2.3