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') 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 a61a6d206b1d37747c3f907487db4bc0952c7b5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 1 May 2010 22:38:57 +0200 Subject: Speed up I18n helpers in views and add entry to CHANGELOG. --- activesupport/CHANGELOG | 2 ++ 1 file changed, 2 insertions(+) (limited to 'activesupport') diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index f24a1b1c6c..0652a20035 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -1,5 +1,7 @@ *Rails 3.0.0 [beta 4/release candidate] (unreleased)* +* Deprecate {{}} as interpolation syntax for I18n in favor of %{} [José Valim] + * Array#to_xml is more powerful and able to handle the same types as Hash#to_xml #4490 [Neeraj Singh] * Harmonize the caching API and refactor the backends. #4452 [Brian Durand] -- cgit v1.2.3 From 7aaabea5175be4b01697684e7573b422629206e6 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sun, 2 May 2010 01:12:31 +0200 Subject: let Date.yesterday and Date.tomorrow be based on Date.current rather than Date.today --- activesupport/lib/active_support/core_ext/date/calculations.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/core_ext/date/calculations.rb b/activesupport/lib/active_support/core_ext/date/calculations.rb index 9d2ad2bbcf..fef49e1003 100644 --- a/activesupport/lib/active_support/core_ext/date/calculations.rb +++ b/activesupport/lib/active_support/core_ext/date/calculations.rb @@ -7,12 +7,12 @@ class Date class << self # Returns a new Date representing the date 1 day ago (i.e. yesterday's date). def yesterday - ::Date.today.yesterday + ::Date.current.yesterday end # Returns a new Date representing the date 1 day after today (i.e. tomorrow's date). def tomorrow - ::Date.today.tomorrow + ::Date.current.tomorrow end # Returns Time.zone.today when config.time_zone is set, otherwise just returns Date.today. -- 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') 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 02028e529c97488b6c70cdbf66dc08c7fb2d36aa Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Sun, 2 May 2010 14:59:51 -0300 Subject: Missing require added make pass activesupport/test/json/encoding_test.rb in isolation Signed-off-by: Xavier Noria --- activesupport/lib/active_support/json/encoding.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/json/encoding.rb b/activesupport/lib/active_support/json/encoding.rb index e692f6d142..3d7be8da1f 100644 --- a/activesupport/lib/active_support/json/encoding.rb +++ b/activesupport/lib/active_support/json/encoding.rb @@ -1,6 +1,7 @@ # encoding: utf-8 require 'bigdecimal' require 'active_support/core_ext/array/wrap' +require 'active_support/core_ext/big_decimal/conversions' require 'active_support/core_ext/hash/except' require 'active_support/core_ext/hash/slice' require 'active_support/core_ext/module/delegation' -- 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/lib/active_support/notifications/instrumenter.rb | 10 +++++++--- activesupport/test/notifications_test.rb | 4 ++-- 2 files changed, 9 insertions(+), 5 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/notifications/instrumenter.rb b/activesupport/lib/active_support/notifications/instrumenter.rb index f3d877efe7..ef3fdd1843 100644 --- a/activesupport/lib/active_support/notifications/instrumenter.rb +++ b/activesupport/lib/active_support/notifications/instrumenter.rb @@ -15,9 +15,13 @@ module ActiveSupport # and publish it. def instrument(name, payload={}) time = Time.now - result = yield(payload) if block_given? - @notifier.publish(name, time, Time.now, @id, payload) - result + begin + yield(payload) if block_given? + ensure + # Notify in an ensure block so that we can be certain end + # events get sent even if an error occurs in the passed-in block + @notifier.publish(name, time, Time.now, @id, payload) + end end private 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 731d4392e478ff5526b595074d9caa999da8bd0c Mon Sep 17 00:00:00 2001 From: Justin George Date: Tue, 27 Apr 2010 21:16:06 -0700 Subject: Change event namespace ordering to most-significant first [#4504 state:resolved] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit More work still needs to be done on some of these names (render_template.action_view and render_template!.action_view particularly) but this allows (for example) /^sql/ to subscribe to all the various ORMs without further modification Signed-off-by: José Valim --- activesupport/lib/active_support/cache.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/cache.rb b/activesupport/lib/active_support/cache.rb index ec5007c284..2605a3f2b8 100644 --- a/activesupport/lib/active_support/cache.rb +++ b/activesupport/lib/active_support/cache.rb @@ -502,7 +502,7 @@ module ActiveSupport if self.class.instrument payload = { :key => key } payload.merge!(options) if options.is_a?(Hash) - ActiveSupport::Notifications.instrument("active_support.cache_#{operation}", payload){ yield } + ActiveSupport::Notifications.instrument("cache_#{operation}.active_support", payload){ yield } else yield end -- 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/lib/active_support/notifications/instrumenter.rb | 8 +++++--- activesupport/test/notifications_test.rb | 2 ++ 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/notifications/instrumenter.rb b/activesupport/lib/active_support/notifications/instrumenter.rb index ef3fdd1843..7e89402822 100644 --- a/activesupport/lib/active_support/notifications/instrumenter.rb +++ b/activesupport/lib/active_support/notifications/instrumenter.rb @@ -12,14 +12,16 @@ module ActiveSupport end # Instrument the given block by measuring the time taken to execute it - # and publish it. + # and publish it. Notice that events get sent even if an error occurs + # in the passed-in block def instrument(name, payload={}) time = Time.now begin yield(payload) if block_given? + rescue Exception => e + payload[:exception] = [e.class.name, e.message] + raise e ensure - # Notify in an ensure block so that we can be certain end - # events get sent even if an error occurs in the passed-in block @notifier.publish(name, time, Time.now, @id, payload) end end 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') 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 36fc489aa3086e384db9f13390f01246d006e47e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Mon, 3 May 2010 13:44:11 +0200 Subject: Update I18n gem to 0.4.0.beta1 [#4525 state:resolved]. --- activesupport/activesupport.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport') diff --git a/activesupport/activesupport.gemspec b/activesupport/activesupport.gemspec index 0fea84a6ef..cfd85f61c9 100644 --- a/activesupport/activesupport.gemspec +++ b/activesupport/activesupport.gemspec @@ -19,7 +19,7 @@ Gem::Specification.new do |s| s.has_rdoc = true - s.add_dependency('i18n', '~> 0.4.0.beta') + s.add_dependency('i18n', '~> 0.4.0.beta1') s.add_dependency('tzinfo', '~> 0.3.16') s.add_dependency('builder', '~> 2.1.2') s.add_dependency('memcache-client', '>= 1.7.5') -- cgit v1.2.3 From 756f762cdb1ee5ad0046e40e3620399d1707fee7 Mon Sep 17 00:00:00 2001 From: Norman Clarke Date: Mon, 3 May 2010 10:16:38 -0300 Subject: Fix transliteration rule example in docs. [#4526 state:resolved] Signed-off-by: Xavier Noria --- activesupport/lib/active_support/inflector/transliterate.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/inflector/transliterate.rb b/activesupport/lib/active_support/inflector/transliterate.rb index 5ec87372d0..2c9115c427 100644 --- a/activesupport/lib/active_support/inflector/transliterate.rb +++ b/activesupport/lib/active_support/inflector/transliterate.rb @@ -24,8 +24,9 @@ module ActiveSupport # # Store the transliterations in locales/de.yml # i18n: # transliterate: - # ü: "ue" - # ö: "oe" + # :rule + # ü: "ue" + # ö: "oe" # # # Or set them using Ruby # I18n.backend.store_translations(:de, :i18n => { -- cgit v1.2.3 From 34d57251672d31e70d3ce53e1df3ea9dd4aae9c8 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Mon, 3 May 2010 15:25:28 +0200 Subject: fixes colon in previous YAML example --- activesupport/lib/active_support/inflector/transliterate.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/inflector/transliterate.rb b/activesupport/lib/active_support/inflector/transliterate.rb index 2c9115c427..2344bb1bb3 100644 --- a/activesupport/lib/active_support/inflector/transliterate.rb +++ b/activesupport/lib/active_support/inflector/transliterate.rb @@ -24,7 +24,7 @@ module ActiveSupport # # Store the transliterations in locales/de.yml # i18n: # transliterate: - # :rule + # rule: # ü: "ue" # ö: "oe" # -- cgit v1.2.3 From 9e085a9f3365e316e2026addedef30f08ead46f2 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Mon, 3 May 2010 22:04:47 +0200 Subject: adds a comment explaining why BigDecimal#as_json returns a JSON string --- activesupport/lib/active_support/json/encoding.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/json/encoding.rb b/activesupport/lib/active_support/json/encoding.rb index 3d7be8da1f..02c233595d 100644 --- a/activesupport/lib/active_support/json/encoding.rb +++ b/activesupport/lib/active_support/json/encoding.rb @@ -1,7 +1,7 @@ # encoding: utf-8 require 'bigdecimal' require 'active_support/core_ext/array/wrap' -require 'active_support/core_ext/big_decimal/conversions' +require 'active_support/core_ext/big_decimal/conversions' # for #to_s require 'active_support/core_ext/hash/except' require 'active_support/core_ext/hash/slice' require 'active_support/core_ext/module/delegation' @@ -179,6 +179,14 @@ class Numeric end class BigDecimal + # A BigDecimal would be naturally represented as a JSON number. Most libraries, + # however, parse non-integer JSON numbers directly as floats. Clients using + # those libraries would get in general a wrong number and no way to recover + # other than manually inspecting the string with the JSON code itself. + # + # That's why a JSON string is returned. The JSON literal is not numeric, but if + # the other end knows by contract that the data is supposed to be a BigDecimal, + # it still has the chance to post-process the string and get the real value. def as_json(options = nil) to_s end #:nodoc: end -- 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') 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 From 6704d8c994d9d20d0cc9d71b72521e141c7dc05d Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Mon, 3 May 2010 23:11:09 +0200 Subject: date/conversions needs time/calculations for (utc|local)_time --- activesupport/lib/active_support/core_ext/date/conversions.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/core_ext/date/conversions.rb b/activesupport/lib/active_support/core_ext/date/conversions.rb index 90ab1eb281..13ef703f49 100644 --- a/activesupport/lib/active_support/core_ext/date/conversions.rb +++ b/activesupport/lib/active_support/core_ext/date/conversions.rb @@ -1,5 +1,6 @@ require 'date' require 'active_support/inflector' +require 'active_support/core_ext/time/calculations' class Date DATE_FORMATS = { -- cgit v1.2.3