diff options
Diffstat (limited to 'activesupport/CHANGELOG.md')
-rw-r--r-- | activesupport/CHANGELOG.md | 449 |
1 files changed, 288 insertions, 161 deletions
diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md index 3e68ca84d8..7c0f3eae80 100644 --- a/activesupport/CHANGELOG.md +++ b/activesupport/CHANGELOG.md @@ -4,280 +4,407 @@ *Gordon Chan* -* `Object#with_options` executes block in merging option context when - explicit receiver in not passed. +* Change Integer#year to return a Fixnum instead of a Float to improve + consistency. - *Pavel Pravosud* + Integer#years returned a Float while the rest of the accompanying methods + (days, weeks, months, etc.) return a Fixnum. -* Fixed a compatibility issue with the `Oj` gem when cherry-picking the file - `active_support/core_ext/object/json` without requiring `active_support/json`. + Before: - Fixes #16131. + 1.year # => 31557600.0 - *Godfrey Chan* + After: -* Make `Hash#with_indifferent_access` copy the default proc too. + 1.year # => 31557600 - *arthurnn*, *Xanders* + *Konstantinos Rousis* -* Add `String#truncate_words` to truncate a string by a number of words. +* Handle invalid UTF-8 strings when HTML escaping - *Mohamed Osama* + Use `ActiveSupport::Multibyte::Unicode.tidy_bytes` to handle invalid UTF-8 + strings in `ERB::Util.unwrapped_html_escape` and `ERB::Util.html_escape_once`. + Prevents user-entered input passed from a querystring into a form field from + causing invalid byte sequence errors. -* Deprecate `capture` and `quietly`. + *Grey Baker* - These methods are not thread safe and may cause issues when used in threaded environments. - To avoid problems we are deprecating them. +* Update `ActiveSupport::Multibyte::Chars#slice!` to return `nil` if the + arguments are out of bounds, to mirror the behavior of `String#slice!` - *Tom Meier* + *Gourav Tiwari* -* `DateTime#to_f` now preserves the fractional seconds instead of always - rounding to `.0`. +* Fix `number_to_human` so that 999999999 rounds to "1 Billion" instead of + "1000 Million". - Fixes #15994. + *Max Jacobson* - *John Paul Ashenfelter* +* Fix `ActiveSupport::Deprecation#deprecate_methods` to report using the + current deprecator instance, where applicable. -* Add `Hash#transform_values` to simplify a common pattern where the values of a - hash must change, but the keys are left the same. + *Brandon Dunne* - *Sean Griffin* +* `Cache#fetch` instrumentation marks whether it was a `:hit`. -* Always instrument `ActiveSupport::Cache`. + *Robin Clowers* - Since `ActiveSupport::Notifications` only instrument items when there - are subscriber we don't need to disable instrumentation. +* `assert_difference` and `assert_no_difference` now returns the result of the + yielded block. - *Peter Wagenet* + Example: -* Make the `apply_inflections` method case-insensitive when checking - whether a word is uncountable or not. + post = assert_difference -> { Post.count }, 1 do + Post.create + end - *Robin Dupret* + *Lucas Mazza* -* Make Dependencies pass a name to NameError error. +* Short-circuit `blank?` on date and time values since they are never blank. - *arthurnn* + Fixes #21657 -* Fixed `ActiveSupport::Cache::FileStore` exploding with long paths. + *Andrew White* - *Adam Panzer / Michael Grosser* +* Replaced deprecated `ThreadSafe::Cache` with its successor `Concurrent::Map` now that + the thread_safe gem has been merged into concurrent-ruby. -* Fixed `ActiveSupport::TimeWithZone#-` so precision is not unnecessarily lost - when working with objects with a nanosecond component. + *Jerry D'Antonio* - `ActiveSupport::TimeWithZone#-` should return the same result as if we were - using `Time#-`: +* Updated Unicode version to 8.0.0 - Time.now.end_of_day - Time.now.beginning_of_day #=> 86399.999999999 + *Anshul Sharma* - Before: +* `number_to_currency` and `number_with_delimiter` now accept custom `delimiter_pattern` option + to handle placement of delimiter, to support currency formats like INR - Time.zone.now.end_of_day.nsec #=> 999999999 - Time.zone.now.end_of_day - Time.zone.now.beginning_of_day #=> 86400.0 + Example: - After: + number_to_currency(1230000, delimiter_pattern: /(\d+?)(?=(\d\d)+(\d)(?!\d))/, unit: '₹', format: "%u %n") + # => '₹ 12,30,000.00' - Time.zone.now.end_of_day - Time.zone.now.beginning_of_day - #=> 86399.999999999 + *Vipul A M* - *Gordon Chan* +* Deprecate `:prefix` option of `number_to_human_size` with no replacement. -* Fixed precision error in NumberHelper when using Rationals. + *Jean Boussier* - Before: +* Fix `TimeWithZone#eql?` to properly handle `TimeWithZone` created from `DateTime`: + twz = DateTime.now.in_time_zone + twz.eql?(twz.dup) => true - ActiveSupport::NumberHelper.number_to_rounded Rational(1000, 3), precision: 2 - #=> "330.00" + Fixes #14178. - After: + *Roque Pinel* - ActiveSupport::NumberHelper.number_to_rounded Rational(1000, 3), precision: 2 - #=> "333.33" +* ActiveSupport::HashWithIndifferentAccess `select` and `reject` will now return + enumerator if called without block. - See #15379. + Fixes #20095 - *Juanjo Bazán* + *Bernard Potocki* -* Removed deprecated `Numeric#ago` and friends +* Removed `ActiveSupport::Concurrency::Latch`, superseded by `Concurrent::CountDownLatch` + from the concurrent-ruby gem. - Replacements: + *Jerry D'Antonio* - 5.ago => 5.seconds.ago - 5.until => 5.seconds.until - 5.since => 5.seconds.since - 5.from_now => 5.seconds.from_now +* Fix not calling `#default` on `HashWithIndifferentAccess#to_hash` when only + `default_proc` is set, which could raise. - See #12389 for the history and rationale behind this. + *Simon Eskildsen* - *Godfrey Chan* +* Fix setting `default_proc` on `HashWithIndifferentAccess#dup` + + *Simon Eskildsen* + +* Fix a range of values for parameters of the Time#change + + *Nikolay Kondratyev* -* DateTime `advance` now supports partial days. +* Add `Enumerable#pluck` to get the same values from arrays as from ActiveRecord + associations. + + Fixes #20339. + + *Kevin Deisz* + +* Add a bang version to `ActiveSupport::OrderedOptions` get methods which will raise + an `KeyError` if the value is `.blank?` Before: - DateTime.now.advance(days: 1, hours: 12) + if (slack_url = Rails.application.secrets.slack_url).present? + # Do something worthwhile + else + # Raise as important secret password is not specified + end After: - DateTime.now.advance(days: 1.5) + slack_url = Rails.application.secrets.slack_url! - Fixes #12005. + *Aditya Sanghi*, *Gaurish Sharma* - *Shay Davidson* +* Remove deprecated `Class#superclass_delegating_accessor`. + Use `Class#class_attribute` instead. -* `Hash#deep_transform_keys` and `Hash#deep_transform_keys!` now transform hashes - in nested arrays. This change also applies to `Hash#deep_stringify_keys`, - `Hash#deep_stringify_keys!`, `Hash#deep_symbolize_keys` and - `Hash#deep_symbolize_keys!`. + *Akshay Vishnoi* + +* Patch `Delegator` to work with `#try`. + + Fixes #5790. + + *Nate Smith* + +* Add `Integer#positive?` and `Integer#negative?` query methods + in the vein of `Fixnum#zero?`. + + This makes it nicer to do things like `bunch_of_numbers.select(&:positive?)`. + + *DHH* + +* Encoding `ActiveSupport::TimeWithZone` to YAML now preserves the timezone information. - *OZAWA Sakuro* + Fixes #9183. -* Fixed confusing `DelegationError` in `Module#delegate`. + *Andrew White* - See #15186. +* Added `ActiveSupport::TimeZone#strptime` to allow parsing times as if + from a given timezone. - *Vladimir Yarotsky* + *Paul A Jungwirth* -* Fixed `ActiveSupport::Subscriber` so that no duplicate subscriber is created - when a subscriber method is redefined. +* `ActiveSupport::Callbacks#skip_callback` now raises an `ArgumentError` if + an unrecognized callback is removed. - *Dennis Schön* + *Iain Beeston* -* Remove deprecated string based terminators for `ActiveSupport::Callbacks`. +* Added `ActiveSupport::ArrayInquirer` and `Array#inquiry`. - *Eileen M. Uchitelle* + Wrapping an array in an `ArrayInquirer` gives a friendlier way to check its + contents: -* Fixed an issue when using - `ActiveSupport::NumberHelper::NumberToDelimitedConverter` to - convert a value that is an `ActiveSupport::SafeBuffer` introduced - in 2da9d67. + variants = ActiveSupport::ArrayInquirer.new([:phone, :tablet]) - See #15064. + variants.phone? # => true + variants.tablet? # => true + variants.desktop? # => false - *Mark J. Titorenko* + variants.any?(:phone, :tablet) # => true + variants.any?(:phone, :desktop) # => true + variants.any?(:desktop, :watch) # => false -* `TimeZone#parse` defaults the day of the month to '1' if any other date - components are specified. This is more consistent with the behavior of - `Time#parse`. + `Array#inquiry` is a shortcut for wrapping the receiving array in an + `ArrayInquirer`. - *Ulysse Carion* + *George Claghorn* -* `humanize` strips leading underscores, if any. +* Deprecate `alias_method_chain` in favour of `Module#prepend` introduced in + Ruby 2.0. + + *Kir Shatrov* + +* Added `#without` on `Enumerable` and `Array` to return a copy of an + enumerable without the specified elements. + + *Todd Bealmear* + +* Fixed a problem where `String#truncate_words` would get stuck with a complex + string. + + *Henrik Nygren* + +* Fixed a roundtrip problem with `AS::SafeBuffer` where primitive-like strings + will be dumped as primitives: Before: - '_id'.humanize # => "" + YAML.load ActiveSupport::SafeBuffer.new("Hello").to_yaml # => "Hello" + YAML.load ActiveSupport::SafeBuffer.new("true").to_yaml # => true + YAML.load ActiveSupport::SafeBuffer.new("false").to_yaml # => false + YAML.load ActiveSupport::SafeBuffer.new("1").to_yaml # => 1 + YAML.load ActiveSupport::SafeBuffer.new("1.1").to_yaml # => 1.1 After: - '_id'.humanize # => "Id" + YAML.load ActiveSupport::SafeBuffer.new("Hello").to_yaml # => "Hello" + YAML.load ActiveSupport::SafeBuffer.new("true").to_yaml # => "true" + YAML.load ActiveSupport::SafeBuffer.new("false").to_yaml # => "false" + YAML.load ActiveSupport::SafeBuffer.new("1").to_yaml # => "1" + YAML.load ActiveSupport::SafeBuffer.new("1.1").to_yaml # => "1.1" - *Xavier Noria* + *Godfrey Chan* -* Fixed backward compatibility isues introduced in 326e652. +* Enable `number_to_percentage` to keep the number's precision by allowing + `:precision` to be `nil`. - Empty Hash or Array should not present in serialization result. + *Jack Xu* - {a: []}.to_query # => "" - {a: {}}.to_query # => "" +* `config_accessor` became a private method, as with Ruby's `attr_accessor`. - For more info see #14948. + *Akira Matsuda* - *Bogdan Gusiev* +* `AS::Testing::TimeHelpers#travel_to` now changes `DateTime.now` as well as + `Time.now` and `Date.today`. -* Add `Digest::UUID::uuid_v3` and `Digest::UUID::uuid_v5` to support stable - UUID fixtures on PostgreSQL. + *Yuki Nishijima* - *Roderick van Domburg* +* Add `file_fixture` to `ActiveSupport::TestCase`. + It provides a simple mechanism to access sample files in your test cases. -* Fixed `ActiveSupport::Duration#eql?` so that `1.second.eql?(1.second)` is - true. + By default file fixtures are stored in `test/fixtures/files`. This can be + configured per test-case using the `file_fixture_path` class attribute. - This fixes the current situation of: + *Yves Senn* - 1.second.eql?(1.second) #=> false +* Return value of yielded block in `File.atomic_write`. - `eql?` also requires that the other object is an `ActiveSupport::Duration`. - This requirement makes `ActiveSupport::Duration`'s behavior consistent with - the behavior of Ruby's numeric types: + *Ian Ker-Seymer* - 1.eql?(1.0) #=> false - 1.0.eql?(1) #=> false +* Duplicate frozen array when assigning it to a `HashWithIndifferentAccess` so + that it doesn't raise a `RuntimeError` when calling `map!` on it in `convert_value`. - 1.second.eql?(1) #=> false (was true) - 1.eql?(1.second) #=> false + Fixes #18550. - { 1 => "foo", 1.0 => "bar" } - #=> { 1 => "foo", 1.0 => "bar" } + *Aditya Kapoor* - { 1 => "foo", 1.second => "bar" } - # now => { 1 => "foo", 1.second => "bar" } - # was => { 1 => "bar" } +* Add missing time zone definitions for Russian Federation and sync them + with `zone.tab` file from tzdata version 2014j (latest). - And though the behavior of these hasn't changed, for reference: + *Andrey Novikov* - 1 == 1.0 #=> true - 1.0 == 1 #=> true +* Add `SecureRandom.base58` for generation of random base58 strings. - 1 == 1.second #=> true - 1.second == 1 #=> true + *Matthew Draper*, *Guillermo Iguaran* - *Emily Dobervich* +* Add `#prev_day` and `#next_day` counterparts to `#yesterday` and + `#tomorrow` for `Date`, `Time`, and `DateTime`. -* `ActiveSupport::SafeBuffer#prepend` acts like `String#prepend` and modifies - instance in-place, returning self. `ActiveSupport::SafeBuffer#prepend!` is - deprecated. + *George Claghorn* - *Pavel Pravosud* +* Add `same_time` option to `#next_week` and `#prev_week` for `Date`, `Time`, + and `DateTime`. -* `HashWithIndifferentAccess` better respects `#to_hash` on objects it's - given. In particular, `.new`, `#update`, `#merge`, `#replace` all accept - objects which respond to `#to_hash`, even if those objects are not Hashes - directly. + *George Claghorn* - *Peter Jaros* +* Add `#on_weekend?`, `#next_weekday`, `#prev_weekday` methods to `Date`, + `Time`, and `DateTime`. -* Deprecate `Class#superclass_delegating_accessor`, use `Class#class_attribute` instead. + `#on_weekend?` returns `true` if the receiving date/time falls on a Saturday + or Sunday. - *Akshay Vishnoi* + `#next_weekday` returns a new date/time representing the next day that does + not fall on a Saturday or Sunday. -* Ensure classes which `include Enumerable` get `#to_json` in addition to - `#as_json`. + `#prev_weekday` returns a new date/time representing the previous day that + does not fall on a Saturday or Sunday. - *Sammy Larbi* + *George Claghorn* -* Change the signature of `fetch_multi` to return a hash rather than an - array. This makes it consistent with the output of `read_multi`. +* Change the default test order from `:sorted` to `:random`. - *Parker Selbert* + *Rafael Mendonça França* -* Introduce `Concern#class_methods` as a sleek alternative to clunky - `module ClassMethods`. Add `Kernel#concern` to define at the toplevel - without chunky `module Foo; extend ActiveSupport::Concern` boilerplate. +* Remove deprecated `ActiveSupport::JSON::Encoding::CircularReferenceError`. - # app/models/concerns/authentication.rb - concern :Authentication do - included do - after_create :generate_private_key - end + *Rafael Mendonça França* + +* Remove deprecated methods `ActiveSupport::JSON::Encoding.encode_big_decimal_as_string=` + and `ActiveSupport::JSON::Encoding.encode_big_decimal_as_string`. + + *Rafael Mendonça França* + +* Remove deprecated `ActiveSupport::SafeBuffer#prepend`. + + *Rafael Mendonça França* + +* Remove deprecated methods at `Kernel`. + + `silence_stderr`, `silence_stream`, `capture` and `quietly`. + + *Rafael Mendonça França* + +* Remove deprecated `active_support/core_ext/big_decimal/yaml_conversions` + file. + + *Rafael Mendonça França* + +* Remove deprecated methods `ActiveSupport::Cache::Store.instrument` and + `ActiveSupport::Cache::Store.instrument=`. + + *Rafael Mendonça França* + +* Change the way in which callback chains can be halted. + + The preferred method to halt a callback chain from now on is to explicitly + `throw(:abort)`. + In the past, callbacks could only be halted by explicitly providing a + terminator and by having a callback match the conditions of the terminator. + +* Add `ActiveSupport.halt_callback_chains_on_return_false` + + Setting `ActiveSupport.halt_callback_chains_on_return_false` + to `true` will let an app support the deprecated way of halting Active Record, + and Active Model callback chains by returning `false`. - class_methods do - def authenticate(credentials) - # ... + Setting the value to `false` will tell the app to ignore any `false` value + returned by those callbacks, and only halt the chain upon `throw(:abort)`. + + When the configuration option is missing, its value is `true`, so older apps + ported to Rails 5.0 will not break (but display a deprecation warning). + For new Rails 5.0 apps, its value is set to `false` in an initializer, so + these apps will support the new behavior by default. + + *claudiob*, *Roque Pinel* + +* Changes arguments and default value of CallbackChain's `:terminator` option + + Chains of callbacks defined without an explicit `:terminator` option will + now be halted as soon as a `before_` callback throws `:abort`. + + Chains of callbacks defined with a `:terminator` option will maintain their + existing behavior of halting as soon as a `before_` callback matches the + terminator's expectation. + + *claudiob* + +* Deprecate `MissingSourceFile` in favor of `LoadError`. + + `MissingSourceFile` was just an alias to `LoadError` and was not being + raised inside the framework. + + *Rafael Mendonça França* + +* Add support for error dispatcher classes in `ActiveSupport::Rescuable`. + Now it acts closer to Ruby's rescue. + + Example: + + class BaseController < ApplicationController + module ErrorDispatcher + def self.===(other) + Exception === other && other.respond_to?(:status) end end - def generate_private_key - # ... + rescue_from ErrorDispatcher do |error| + render status: error.status, json: { error: error.to_s } end end - # app/models/user.rb - class User < ActiveRecord::Base - include Authentication - end + *Genadi Samokovarov* + +* Add `#verified` and `#valid_message?` methods to `ActiveSupport::MessageVerifier` + + Previously, the only way to decode a message with `ActiveSupport::MessageVerifier` + was to use `#verify`, which would raise an exception on invalid messages. Now + `#verified` can also be used, which returns `nil` on messages that cannot be + decoded. + + Previously, there was no way to check if a message's format was valid without + attempting to decode it. `#valid_message?` is a boolean convenience method that + checks whether the message is valid without actually decoding it. - *Jeremy Kemper* + *Logan Leger* -Please check [4-1-stable](https://github.com/rails/rails/blob/4-1-stable/activesupport/CHANGELOG.md) for previous changes. +Please check [4-2-stable](https://github.com/rails/rails/blob/4-2-stable/activesupport/CHANGELOG.md) for previous changes. |