diff options
-rw-r--r-- | actionview/CHANGELOG.md | 7 | ||||
-rw-r--r-- | actionview/lib/action_view/helpers/debug_helper.rb | 2 | ||||
-rw-r--r-- | actionview/test/activerecord/debug_helper_test.rb | 6 | ||||
-rw-r--r-- | actionview/test/template/number_helper_test.rb | 4 | ||||
-rw-r--r-- | activerecord/Rakefile | 2 | ||||
-rw-r--r-- | activerecord/test/cases/associations/callbacks_test.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/mixin_test.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/query_cache_test.rb | 2 | ||||
-rw-r--r-- | activesupport/CHANGELOG.md | 7 | ||||
-rw-r--r-- | activesupport/lib/active_support/callbacks.rb | 14 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/time/calculations.rb | 6 | ||||
-rw-r--r-- | activesupport/lib/active_support/number_helper/number_to_rounded_converter.rb | 2 | ||||
-rw-r--r-- | activesupport/test/number_helper_test.rb | 4 |
13 files changed, 45 insertions, 15 deletions
diff --git a/actionview/CHANGELOG.md b/actionview/CHANGELOG.md index 101f1263d9..82a636315a 100644 --- a/actionview/CHANGELOG.md +++ b/actionview/CHANGELOG.md @@ -1,3 +1,10 @@ +* `number_to_percentage` does not crash with `Float::NAN` or `Float::INFINITY` + as input when `precision: 0` is used. + + Fixes #19227. + + *Yves Senn* + * Fixed the translation helper method to accept different default values types besides String. diff --git a/actionview/lib/action_view/helpers/debug_helper.rb b/actionview/lib/action_view/helpers/debug_helper.rb index ba47eee9ba..e9dccbad1c 100644 --- a/actionview/lib/action_view/helpers/debug_helper.rb +++ b/actionview/lib/action_view/helpers/debug_helper.rb @@ -26,7 +26,7 @@ module ActionView Marshal::dump(object) object = ERB::Util.html_escape(object.to_yaml) content_tag(:pre, object, :class => "debug_dump") - rescue Exception # errors from Marshal or YAML + rescue # errors from Marshal or YAML # Object couldn't be dumped, perhaps because of singleton methods -- this is the fallback content_tag(:code, object.inspect, :class => "debug_dump") end diff --git a/actionview/test/activerecord/debug_helper_test.rb b/actionview/test/activerecord/debug_helper_test.rb index 5609694cd5..03cb1d5a91 100644 --- a/actionview/test/activerecord/debug_helper_test.rb +++ b/actionview/test/activerecord/debug_helper_test.rb @@ -1,8 +1,14 @@ require 'active_record_unit' +require 'nokogiri' class DebugHelperTest < ActionView::TestCase def test_debug company = Company.new(name: "firebase") assert_match "name: firebase", debug(company) end + + def test_debug_with_marshal_error + obj = -> { } + assert_match obj.inspect, Nokogiri.XML(debug(obj)).content + end end diff --git a/actionview/test/template/number_helper_test.rb b/actionview/test/template/number_helper_test.rb index b59883b760..b70b750869 100644 --- a/actionview/test/template/number_helper_test.rb +++ b/actionview/test/template/number_helper_test.rb @@ -35,6 +35,10 @@ class NumberHelperTest < ActionView::TestCase assert_equal "98a%", number_to_percentage("98a") assert_equal "NaN%", number_to_percentage(Float::NAN) assert_equal "Inf%", number_to_percentage(Float::INFINITY) + assert_equal "NaN%", number_to_percentage(Float::NAN, precision: 0) + assert_equal "Inf%", number_to_percentage(Float::INFINITY, precision: 0) + assert_equal "NaN%", number_to_percentage(Float::NAN, precision: 1) + assert_equal "Inf%", number_to_percentage(Float::INFINITY, precision: 1) end def test_number_with_delimiter diff --git a/activerecord/Rakefile b/activerecord/Rakefile index 976b559da9..ec6a902c00 100644 --- a/activerecord/Rakefile +++ b/activerecord/Rakefile @@ -10,7 +10,7 @@ def run_without_aborting(*tasks) tasks.each do |task| begin Rake::Task[task].invoke - rescue Exception + rescue errors << task end end diff --git a/activerecord/test/cases/associations/callbacks_test.rb b/activerecord/test/cases/associations/callbacks_test.rb index a531e0e02c..a341cb706d 100644 --- a/activerecord/test/cases/associations/callbacks_test.rb +++ b/activerecord/test/cases/associations/callbacks_test.rb @@ -180,7 +180,7 @@ class AssociationCallbacksTest < ActiveRecord::TestCase assert !@david.unchangable_posts.include?(@authorless) begin @david.unchangable_posts << @authorless - rescue Exception + rescue end assert @david.post_log.empty? assert !@david.unchangable_posts.include?(@authorless) diff --git a/activerecord/test/cases/mixin_test.rb b/activerecord/test/cases/mixin_test.rb index 7ddb2bfee1..7ebdcac711 100644 --- a/activerecord/test/cases/mixin_test.rb +++ b/activerecord/test/cases/mixin_test.rb @@ -61,8 +61,6 @@ class TouchTest < ActiveRecord::TestCase # Make sure Mixin.record_timestamps gets reset, even if this test fails, # so that other tests do not fail because Mixin.record_timestamps == false - rescue Exception => e - raise e ensure Mixin.record_timestamps = true end diff --git a/activerecord/test/cases/query_cache_test.rb b/activerecord/test/cases/query_cache_test.rb index 744f9edc47..a5f8776f77 100644 --- a/activerecord/test/cases/query_cache_test.rb +++ b/activerecord/test/cases/query_cache_test.rb @@ -235,7 +235,7 @@ class QueryCacheTest < ActiveRecord::TestCase assert_equal 1, Post.where(title: 'rollback').to_a.count raise 'broken' end - rescue Exception + rescue end assert_equal 0, Post.where(title: 'rollback').to_a.count diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md index f5fa70494a..1d21a18c16 100644 --- a/activesupport/CHANGELOG.md +++ b/activesupport/CHANGELOG.md @@ -1,3 +1,10 @@ +* `number_to_percentage` does not crash with `Float::NAN` or `Float::INFINITY` + as input when `precision: 0` is used. + + Fixes #19227. + + *Yves Senn* + * Take DST into account when locating TimeZone from Numeric. When given a specific offset, use the first result found where the diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb index f32bb8a0cc..37f9494272 100644 --- a/activesupport/lib/active_support/callbacks.rb +++ b/activesupport/lib/active_support/callbacks.rb @@ -490,17 +490,17 @@ module ActiveSupport end def around(&around) - CallbackSequence.new do |*args| - around.call(*args) { - self.call(*args) + CallbackSequence.new do |arg| + around.call(arg) { + self.call(arg) } end end - def call(*args) - @before.each { |b| b.call(*args) } - value = @call.call(*args) - @after.each { |a| a.call(*args) } + def call(arg) + @before.each { |b| b.call(arg) } + value = @call.call(arg) + @after.each { |a| a.call(arg) } value end end diff --git a/activesupport/lib/active_support/core_ext/time/calculations.rb b/activesupport/lib/active_support/core_ext/time/calculations.rb index 13610ba19f..6f1b653639 100644 --- a/activesupport/lib/active_support/core_ext/time/calculations.rb +++ b/activesupport/lib/active_support/core_ext/time/calculations.rb @@ -48,7 +48,11 @@ class Time alias_method :at, :at_with_coercion end - # Seconds since midnight: Time.now.seconds_since_midnight + # Returns the number of seconds since 00:00:00. + # + # Time.new(2012, 8, 29, 0, 0, 0).seconds_since_midnight # => 0 + # Time.new(2012, 8, 29, 12, 34, 56).seconds_since_midnight # => 45296 + # Time.new(2012, 8, 29, 23, 59, 59).seconds_since_midnight # => 86399 def seconds_since_midnight to_i - change(:hour => 0).to_i + (usec / 1.0e+6) end diff --git a/activesupport/lib/active_support/number_helper/number_to_rounded_converter.rb b/activesupport/lib/active_support/number_helper/number_to_rounded_converter.rb index df316a08e6..981c562551 100644 --- a/activesupport/lib/active_support/number_helper/number_to_rounded_converter.rb +++ b/activesupport/lib/active_support/number_helper/number_to_rounded_converter.rb @@ -23,7 +23,7 @@ module ActiveSupport precision = 0 if precision < 0 # don't let it be negative else rounded_number = number.round(precision) - rounded_number = rounded_number.to_i if precision == 0 + rounded_number = rounded_number.to_i if precision == 0 && rounded_number.finite? rounded_number = rounded_number.abs if rounded_number.zero? # prevent showing negative zeros end diff --git a/activesupport/test/number_helper_test.rb b/activesupport/test/number_helper_test.rb index 23996ef381..83efbffdfb 100644 --- a/activesupport/test/number_helper_test.rb +++ b/activesupport/test/number_helper_test.rb @@ -83,6 +83,10 @@ module ActiveSupport assert_equal("98a%", number_helper.number_to_percentage("98a")) assert_equal("NaN%", number_helper.number_to_percentage(Float::NAN)) assert_equal("Inf%", number_helper.number_to_percentage(Float::INFINITY)) + assert_equal("NaN%", number_helper.number_to_percentage(Float::NAN, precision: 0)) + assert_equal("Inf%", number_helper.number_to_percentage(Float::INFINITY, precision: 0)) + assert_equal("NaN%", number_helper.number_to_percentage(Float::NAN, precision: 1)) + assert_equal("Inf%", number_helper.number_to_percentage(Float::INFINITY, precision: 1)) assert_equal("1000%", number_helper.number_to_percentage(1000, precision: nil)) assert_equal("1000%", number_helper.number_to_percentage(1000, precision: nil)) assert_equal("1000.1%", number_helper.number_to_percentage(1000.1, precision: nil)) |