From 35598db01a2d754df96b23c20050c1a96c999c76 Mon Sep 17 00:00:00 2001 From: Marius Nuennerich Date: Sat, 1 May 2010 14:40:02 +0200 Subject: repair the activesupport message encryptor tests for me, do so in the same way as jeremy did with message verifier [#4517 state:committed] Signed-off-by: Jeremy Kemper --- activesupport/test/message_encryptor_test.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'activesupport/test') diff --git a/activesupport/test/message_encryptor_test.rb b/activesupport/test/message_encryptor_test.rb index 2fba62bdd6..684b931176 100644 --- a/activesupport/test/message_encryptor_test.rb +++ b/activesupport/test/message_encryptor_test.rb @@ -1,4 +1,12 @@ require 'abstract_unit' + +begin + require 'openssl' + OpenSSL::Digest::SHA1 +rescue LoadError, NameError + $stderr.puts "Skipping MessageEncryptor test: broken OpenSSL install" +else + require 'active_support/time' class MessageEncryptorTest < Test::Unit::TestCase @@ -45,3 +53,5 @@ class MessageEncryptorTest < Test::Unit::TestCase ActiveSupport::Base64.encode64s(bits) end end + +end -- cgit v1.2.3 From 1b33a151b2da4f8d24a981e0fbaa008352c41aa0 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sun, 2 May 2010 01:36:10 +0200 Subject: revises tests for Date.yesterday and Date.tomorrow --- activesupport/test/core_ext/date_ext_test.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'activesupport/test') diff --git a/activesupport/test/core_ext/date_ext_test.rb b/activesupport/test/core_ext/date_ext_test.rb index 23c9bc7fb1..4ff714cabc 100644 --- a/activesupport/test/core_ext/date_ext_test.rb +++ b/activesupport/test/core_ext/date_ext_test.rb @@ -176,13 +176,13 @@ class DateExtCalculationsTest < Test::Unit::TestCase end def test_yesterday_constructor - assert_equal Date.today - 1, Date.yesterday + assert_equal Date.current - 1, Date.yesterday end def test_tomorrow_constructor - assert_equal Date.today + 1, Date.tomorrow + assert_equal Date.current + 1, Date.tomorrow end - + def test_since assert_equal Time.local(2005,2,21,0,0,45), Date.new(2005,2,21).since(45) end -- cgit v1.2.3 From 109d3ee38d1c39f0e27bc827065427635d6396b2 Mon Sep 17 00:00:00 2001 From: Justin George Date: Tue, 27 Apr 2010 14:13:47 -0700 Subject: Make notifications go off even when an error is raised, so that we capture the underlying performance data [#4505 state:resolved] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is important when trying to keep track of many layers of interrelated calls i.e.: ActiveRecord::Base.transaction do MyModel.find(1) #ActiveRecord::NotFound end # should capture the full time until the error propagation Signed-off-by: José Valim --- activesupport/test/notifications_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'activesupport/test') diff --git a/activesupport/test/notifications_test.rb b/activesupport/test/notifications_test.rb index c2e1c588f0..251380a0d5 100644 --- a/activesupport/test/notifications_test.rb +++ b/activesupport/test/notifications_test.rb @@ -168,7 +168,7 @@ module Notifications assert_equal Hash[:payload => "notifications"], @events.last.payload end - def test_instrument_does_not_publish_when_exception_is_raised + def test_instrument_publishes_when_exception_is_raised begin instrument(:awesome, :payload => "notifications") do raise "FAIL" @@ -178,7 +178,7 @@ module Notifications end drain - assert_equal 0, @events.size + assert_equal 1, @events.size end def test_event_is_pushed_even_without_block -- cgit v1.2.3 From a76c7e68d5e39f5962d9cb85c98e6a8e96f8b3af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 2 May 2010 22:40:20 +0200 Subject: Event should be aware if yielded block failed or not. --- activesupport/test/notifications_test.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'activesupport/test') diff --git a/activesupport/test/notifications_test.rb b/activesupport/test/notifications_test.rb index 251380a0d5..e11de5f67a 100644 --- a/activesupport/test/notifications_test.rb +++ b/activesupport/test/notifications_test.rb @@ -179,6 +179,8 @@ module Notifications drain assert_equal 1, @events.size + assert_equal Hash[:payload => "notifications", + :exception => ["RuntimeError", "FAIL"]], @events.last.payload end def test_event_is_pushed_even_without_block -- cgit v1.2.3 From 0e00f428a816cd24ca645794385fd7b71dbfed73 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Mon, 3 May 2010 00:02:14 +0200 Subject: adds test coverage for Date.current vs Date.today in Date.(yesterday|tomorrow) implementation --- activesupport/test/core_ext/date_ext_test.rb | 46 +++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) (limited to 'activesupport/test') diff --git a/activesupport/test/core_ext/date_ext_test.rb b/activesupport/test/core_ext/date_ext_test.rb index 4ff714cabc..c403d7fb11 100644 --- a/activesupport/test/core_ext/date_ext_test.rb +++ b/activesupport/test/core_ext/date_ext_test.rb @@ -178,11 +178,47 @@ class DateExtCalculationsTest < Test::Unit::TestCase def test_yesterday_constructor assert_equal Date.current - 1, Date.yesterday end + + def test_yesterday_constructor_when_zone_default_is_not_set + with_env_tz 'UTC' do + with_tz_default do + Time.stubs(:now).returns Time.local(2000, 1, 1) + assert_equal Date.new(1999, 12, 31), Date.yesterday + end + end + end + + def test_yesterday_constructor_when_zone_default_is_set + with_env_tz 'UTC' do + with_tz_default ActiveSupport::TimeZone['Eastern Time (US & Canada)'] do # UTC -5 + Time.stubs(:now).returns Time.local(2000, 1, 1) + assert_equal Date.new(1999, 12, 30), Date.yesterday + end + end + end def test_tomorrow_constructor assert_equal Date.current + 1, Date.tomorrow end - + + def test_tomorrow_constructor_when_zone_default_is_not_set + with_env_tz 'UTC' do + with_tz_default do + Time.stubs(:now).returns Time.local(1999, 12, 31) + assert_equal Date.new(2000, 1, 1), Date.tomorrow + end + end + end + + def test_tomorrow_constructor_when_zone_default_is_set + with_env_tz 'UTC' do + with_tz_default ActiveSupport::TimeZone['Europe/Paris'] do # UTC +1 + Time.stubs(:now).returns Time.local(1999, 12, 31, 23) + assert_equal Date.new(2000, 1, 2), Date.tomorrow + end + end + end + def test_since assert_equal Time.local(2005,2,21,0,0,45), Date.new(2005,2,21).since(45) end @@ -264,6 +300,14 @@ class DateExtCalculationsTest < Test::Unit::TestCase ensure old_tz ? ENV['TZ'] = old_tz : ENV.delete('TZ') end + + def with_tz_default(tz = nil) + old_tz = Time.zone_default + Time.zone_default = tz + yield + ensure + Time.zone_default = old_tz + end end class DateExtBehaviorTest < Test::Unit::TestCase -- cgit v1.2.3 From 5d7d0c2fa31d72bc70fdd1b1e34144da9055995d Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Mon, 3 May 2010 22:10:36 +0200 Subject: BigDecimal#as_json does not really specify the F format, it delegates that to whatever BigDecimal#to_s default format is, do the same in its test --- activesupport/test/json/encoding_test.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'activesupport/test') diff --git a/activesupport/test/json/encoding_test.rb b/activesupport/test/json/encoding_test.rb index ac7ca96c4d..a8ecf4e4cf 100644 --- a/activesupport/test/json/encoding_test.rb +++ b/activesupport/test/json/encoding_test.rb @@ -1,5 +1,7 @@ # encoding: utf-8 require 'abstract_unit' +require 'bigdecimal' +require 'active_support/core_ext/big_decimal/conversions' require 'active_support/json' class TestJSONEncoding < Test::Unit::TestCase @@ -26,7 +28,7 @@ class TestJSONEncoding < Test::Unit::TestCase NilTests = [[ nil, %(null) ]] NumericTests = [[ 1, %(1) ], [ 2.5, %(2.5) ], - [ BigDecimal('2.5'), %("#{BigDecimal('2.5').to_s('F')}") ]] + [ BigDecimal('2.5'), %("#{BigDecimal('2.5').to_s}") ]] StringTests = [[ 'this is the ', %("this is the \\u003Cstring\\u003E")], [ 'a "string" with quotes & an ampersand', %("a \\"string\\" with quotes \\u0026 an ampersand") ], -- cgit v1.2.3