- No changes.
- No changes.
- No changes.
- No changes.
- No changes.
- No changes.
-
Improve compatibility for
ActiveSupport::BroadcastLogger.Máximo Mussini
-
Pass options along to write_entry in handle_expired_entry method.
Graham Cooper
-
Fix Active Support configurations deprecations.
fatkodima
-
Fix teardown callbacks.
Tristan Starck
-
BacktraceCleanersilence core internal methods by default.Jean Boussier
-
Fix
delegate_missing_to allow_nil: truewhen called with implict selfclass Person delegate_missing_to :address, allow_nil: true def address nil end def berliner? city == "Berlin" end end Person.new.city # => nil Person.new.berliner? # undefined local variable or method `city' for an instance of Person (NameError)
Jean Boussier
-
Work around a Ruby bug that can cause a VM crash.
This would happen if using
TaggerLoggerwith a Proc formatter on which you calledobject_id.[BUG] Object ID seen, but not in mapping table: procJean Boussier
-
Fix
ActiveSupport::Notifications.publish_eventto preserve units.This solves the incorrect reporting of time spent running Active Record asynchronous queries (by a factor
1000).Jean Boussier
-
Revert "Fix
ActiveSupport::JSON.encodeto prevent duplicate keys." introduced in 7.1.3If the same key exist in both String and Symbol form, json encoder again emits the same key twice. Reaseon
ActiveSupport 7.1.3
{a: 1, "a" => 2}.to_json # gives: "{\"a\":2}"
ActiveSupport 7.1.4
{a: 1, "a" => 2}.to_json # gives: "{\"a\":1,\"a\":2}"
Rafael Mendonça França
- No changes.
- No changes.
- No changes.
- No changes.
-
Handle nil
backtrace_locationsinActiveSupport::SyntaxErrorProxy.Eugene Kenny
-
Fix
ActiveSupport::JSON.encodeto prevent duplicate keys.If the same key exist in both String and Symbol form it could lead to the same key being emitted twice.
ActiveSupport 7.1.2
{a: 1, "a" => 2}.to_json # gives: "{\"a\":1,\"a\":2}"
ActiveSupport 7.1.3
{a: 1, "a" => 2}.to_json # gives: "{\"a\":2}"
Manish Sharma
-
Fix
ActiveSupport::Cache::Store#read_multiwhen using a cache namespace and local cache strategy.Mark Oleson
-
Fix
Time.now/DateTime.now/Date.todayto return results in a system timezone after#travel_to.There is a bug in the current implementation of #travel_to: it remembers a timezone of its argument, and all stubbed methods start returning results in that remembered timezone. However, the expected behaviour is to return results in a system timezone.
Aleksei Chernenkov
-
Fix
:unless_existoption forMemoryStore#write(et al) when using a cache namespace.S. Brent Faulkner
-
Fix ActiveSupport::Deprecation to handle blaming generated code.
Jean Boussier, fatkodima
-
Fix
:expires_inoption forRedisCacheStore#write_multi.fatkodima
-
Fix deserialization of non-string "purpose" field in Message serializer
Jacopo Beschi
-
Prevent global cache options being overwritten when setting dynamic options inside a
ActiveSupport::Cache::Store#fetchblock.Yasha Krasnou
-
Fix missing
requireresulting inNoMethodErrorwhen runningbin/rails secrets:showorbin/rails secrets:edit.Stephen Ierodiaconou
-
Ensure
{down,up}case_firstreturns non-frozen string.Jonathan Hefner
-
Fix
#to_fs(:human_size)to correctly work with negative numbers.Earlopain
-
Fix
BroadcastLogger#dupso that it duplicates the logger'sbroadcasts.Andrew Novoselac
-
Fix issue where
bootstrap.rboverwrites thelevelof aBroadcastLogger'sbroadcasts.Andrew Novoselac
-
Fix
ActiveSupport::Cacheto handle outdated Marshal payload from Rails 6.1 format.Active Support's Cache is supposed to treat a Marshal payload that can no longer be deserialized as a cache miss. It fail to do so for compressed payload in the Rails 6.1 legacy format.
Jean Boussier
-
Fix
OrderedOptions#digfor array indexes.fatkodima
-
Fix time travel helpers to work when nested using with separate classes.
fatkodima
-
Fix
delete_matchedfor file cache store to work with keys longer than the max filename size.fatkodima and Jonathan Hefner
-
Fix compatibility with the
semantic_loggergem.The
semantic_loggergem doesn't behave exactly like stdlib logger in thatSemanticLogger#levelreturns a Symbol while stdlibLogger#levelreturns an Integer.This caused the various
LogSubscriberclasses in Rails to break when assigned aSemanticLoggerinstance.Jean Boussier, ojab
-
Add support for keyword arguments when delegating calls to custom loggers from
ActiveSupport::BroadcastLogger.Edouard Chin
-
NumberHelper: handle objects respondingto_d.fatkodima
-
Fix RedisCacheStore to properly set the TTL when incrementing or decrementing.
This bug was only impacting Redis server older than 7.0.
Thomas Countz
-
Fix MemoryStore to prevent race conditions when incrementing or decrementing.
Pierre Jambet
- No changes.
-
Fix
AS::MessagePackwithENV["RAILS_MAX_THREADS"].Jonathan Hefner
-
Add a new public API for broadcasting logs
This feature existed for a while but was until now a private API. Broadcasting log allows to send log message to difference sinks (STDOUT, a file ...) and is used by default in the development environment to write logs both on STDOUT and in the "development.log" file.
Basic usage:
stdout_logger = Logger.new(STDOUT) file_logger = Logger.new("development.log") broadcast = ActiveSupport::BroadcastLogger.new(stdout_logger, file_logger) broadcast.info("Hello!") # The "Hello!" message is written on STDOUT and in the log file.
Adding other sink(s) to the broadcast:
broadcast = ActiveSupport::BroadcastLogger.new broadcast.broadcast_to(Logger.new(STDERR))
Remove a sink from the broadcast:
stdout_logger = Logger.new(STDOUT) broadcast = ActiveSupport::BroadcastLogger.new(stdout_logger) broadcast.stop_broadcasting_to(stdout_logger)
Edouard Chin
-
Fix Range#overlap? not taking empty ranges into account on Ruby < 3.3
Nobuyoshi Nakada, Shouichi Kamiya, Hartley McGuire
-
Use Ruby 3.3 Range#overlap? if available
Yasuo Honda
-
Add
bigdecimalas Active Support dependency that is a bundled gem candidate for Ruby 3.4.bigdecimal3.1.4 or higher version will be installed. Ruby 2.7 and 3.0 users who wantbigdecimalversion 2.0.0 or 3.0.0 behavior as a default gem, pin thebigdecimalversion in your application Gemfile.Koichi ITO
-
Add
drb,mutex_mandbase64that are bundled gem candidates for Ruby 3.4Yasuo Honda
-
When using cache format version >= 7.1 or a custom serializer, expired and version-mismatched cache entries can now be detected without deserializing their values.
Jonathan Hefner
-
Make all cache stores return a boolean for
#deletePreviously the
RedisCacheStore#deletewould return1if the entry exists and0otherwise. Now it returns true if the entry exists and false otherwise, just like the other stores.The
FileStorewould returnnilif the entry doesn't exists and returnsfalsenow as well.Petrik de Heus
-
Active Support cache stores now support replacing the default compressor via a
:compressoroption. The specified compressor must respond todeflateandinflate. For example:module MyCompressor def self.deflate(string) # compression logic... end def self.inflate(compressed) # decompression logic... end end config.cache_store = :redis_cache_store, { compressor: MyCompressor }
Jonathan Hefner
-
Active Support cache stores now support a
:serializeroption. Similar to the:coderoption, serializers must respond todumpandload. However, serializers are only responsible for serializing a cached value, whereas coders are responsible for serializing the entireActiveSupport::Cache::Entryinstance. Additionally, the output from serializers can be automatically compressed, whereas coders are responsible for their own compression.Specifying a serializer instead of a coder also enables performance optimizations, including the bare string optimization introduced by cache format version 7.1.
The
:serializerand:coderoptions are mutually exclusive. Specifying both will raise anArgumentError.Jonathan Hefner
-
Fix
ActiveSupport::Inflector.humanize(nil)raisingNoMethodError: undefined method `end_with?' for nil:NilClass.James Robinson
-
Don't show secrets for
ActiveSupport::KeyGenerator#inspect.Before:
ActiveSupport::KeyGenerator.new(secret).inspect "#<ActiveSupport::KeyGenerator:0x0000000104888038 ... @secret=\"\\xAF\\bFh]LV}q\\nl\\xB2U\\xB3 ... >"
After:
ActiveSupport::KeyGenerator::Aes256Gcm(secret).inspect "#<ActiveSupport::KeyGenerator:0x0000000104888038>"
Petrik de Heus
-
Improve error message when EventedFileUpdateChecker is used without a compatible version of the Listen gem
Hartley McGuire
-
Add
:reportbehavior for DeprecationSetting
config.active_support.deprecation = :reportuses the error reporter to report deprecation warnings toActiveSupport::ErrorReporter.Deprecations are reported as handled errors, with a severity of
:warning.Useful to report deprecations happening in production to your bug tracker.
Étienne Barrié
-
Rename
Range#overlaps?to#overlap?and add alias for backwards compatibilityChristian Schmidt
-
Fix
EncryptedConfigurationreturning incorrect values for someHashmethodsHartley McGuire
-
Don't show secrets for
MessageEncryptor#inspect.Before:
ActiveSupport::MessageEncryptor.new(secret, cipher: "aes-256-gcm").inspect "#<ActiveSupport::MessageEncryptor:0x0000000104888038 ... @secret=\"\\xAF\\bFh]LV}q\\nl\\xB2U\\xB3 ... >"
After:
ActiveSupport::MessageEncryptor.new(secret, cipher: "aes-256-gcm").inspect "#<ActiveSupport::MessageEncryptor:0x0000000104888038>"
Petrik de Heus
-
Don't show contents for
EncryptedConfiguration#inspect.Before:
Rails.application.credentials.inspect "#<ActiveSupport::EncryptedConfiguration:0x000000010d2b38e8 ... @config={:secret=>\"something secret\"} ... @key_file_contents=\"915e4ea054e011022398dc242\" ...>"
After:
Rails.application.credentials.inspect "#<ActiveSupport::EncryptedConfiguration:0x000000010d2b38e8>"
Petrik de Heus
-
ERB::Util.html_escape_oncealways returns anhtml_safestring.This method previously maintained the
html_safe?property of a string on the return value. Because this string has been escaped, however, not marking it ashtml_safecauses entities to be double-escaped.As an example, take this view snippet:
<p><%= html_escape_once("this & that & the other") %></p>
Before this change, that would be double-escaped and render as:
<p>this &amp; that &amp; the other</p>
After this change, it renders correctly as:
<p>this & that & the other</p>
Fixes #48256
Mike Dalessio
-
Deprecate
SafeBuffer#clone_empty.This method has not been used internally since Rails 4.2.0.
Mike Dalessio
-
MessageEncryptor,MessageVerifier, andconfig.active_support.message_serializernow accept:message_packand:message_pack_allow_marshalas serializers. These serializers require themsgpackgem (>= 1.7.0).The Message Pack format can provide improved performance and smaller payload sizes. It also supports round-tripping some Ruby types that are not supported by JSON. For example:
verifier = ActiveSupport::MessageVerifier.new("secret") data = [{ a: 1 }, { b: 2 }.with_indifferent_access, 1.to_d, Time.at(0, 123)] message = verifier.generate(data) # BEFORE with config.active_support.message_serializer = :json verifier.verified(message) # => [{"a"=>1}, {"b"=>2}, "1.0", "1969-12-31T18:00:00.000-06:00"] verifier.verified(message).map(&:class) # => [Hash, Hash, String, String] # AFTER with config.active_support.message_serializer = :message_pack verifier.verified(message) # => [{:a=>1}, {"b"=>2}, 0.1e1, 1969-12-31 18:00:00.000123 -0600] verifier.verified(message).map(&:class) # => [Hash, ActiveSupport::HashWithIndifferentAccess, BigDecimal, Time]
The
:message_packserializer can fall back to deserializing withActiveSupport::JSONwhen necessary, and the:message_pack_allow_marshalserializer can fall back to deserializing withMarshalas well asActiveSupport::JSON. Additionally, the:marshal,:json, and:json_allow_marshalserializers can now fall back to deserializing withActiveSupport::MessagePackwhen necessary. These behaviors ensure old messages can still be read so that migration is easier.Jonathan Hefner
-
A new
7.1cache format is available which includes an optimization for bare string values such as view fragments.The
7.1cache format is used by default for new apps, and existing apps can enable the format by settingconfig.load_defaults 7.1or by settingconfig.active_support.cache_format_version = 7.1inconfig/application.rbor aconfig/environments/*.rbfile.Cache entries written using the
6.1or7.0cache formats can be read when using the7.1format. To perform a rolling deploy of a Rails 7.1 upgrade, wherein servers that have not yet been upgraded must be able to read caches from upgraded servers, leave the cache format unchanged on the first deploy, then enable the7.1cache format on a subsequent deploy.Jonathan Hefner
-
Active Support cache stores can now use a preconfigured serializer based on
ActiveSupport::MessagePackvia the:serializeroption:config.cache_store = :redis_cache_store, { serializer: :message_pack }
The
:message_packserializer can reduce cache entry sizes and improve performance, but requires themsgpackgem (>= 1.7.0).The
:message_packserializer can read cache entries written by the default serializer, and the default serializer can now read entries written by the:message_packserializer. These behaviors make it easy to migrate between serializer without invalidating the entire cache.Jonathan Hefner
-
Object#deep_dupno longer duplicate named classes and modules.Before:
hash = { class: Object, module: Kernel } hash.deep_dup # => {:class=>#<Class:0x00000001063ffc80>, :module=>#<Module:0x00000001063ffa00>}
After:
hash = { class: Object, module: Kernel } hash.deep_dup # => {:class=>Object, :module=>Kernel}
Jean Boussier
-
Consistently raise an
ArgumentErrorif theActiveSupport::Cachekey is blank.Joshua Young
-
Deprecate usage of the singleton
ActiveSupport::Deprecation.All usage of
ActiveSupport::Deprecationas a singleton is deprecated, the most common one beingActiveSupport::Deprecation.warn. Gem authors should now create their own deprecator (ActiveSupport::Deprecationobject), and use it to emit deprecation warnings.Calling any of the following without specifying a deprecator argument is also deprecated:
- Module.deprecate
- deprecate_constant
- DeprecatedObjectProxy
- DeprecatedInstanceVariableProxy
- DeprecatedConstantProxy
- deprecation-related test assertions
Use of
ActiveSupport::Deprecation.silenceand configuration methods likebehavior=,disallowed_behavior=,disallowed_warnings=should now be aimed at the application's deprecators.Rails.application.deprecators.silence do # code that emits deprecation warnings end
If your gem has a Railtie or Engine, it's encouraged to add your deprecator to the application's deprecators, that way the deprecation related configuration options will apply to it as well, e.g.
config.active_support.report_deprecationsset tofalsein the production environment will also disable your deprecator.initializer "my_gem.deprecator" do |app| app.deprecators[:my_gem] = MyGem.deprecator end
Étienne Barrié
-
Add
Object#withto set and restore public attributes around a blockclient.timeout # => 5 client.with(timeout: 1) do client.timeout # => 1 end client.timeout # => 5
Jean Boussier
-
Remove deprecated support to generate incorrect RFC 4122 UUIDs when providing a namespace ID that is not one of the constants defined on
Digest::UUID.Rafael Mendonça França
-
Deprecate
config.active_support.use_rfc4122_namespaced_uuids.Rafael Mendonça França
-
Remove implicit conversion of objects into
StringbyActiveSupport::SafeBuffer.Rafael Mendonça França
-
Remove deprecated
active_support/core_ext/range/include_time_with_zonefile.Rafael Mendonça França
-
Deprecate
config.active_support.remove_deprecated_time_with_zone_name.Rafael Mendonça França
-
Remove deprecated override of
ActiveSupport::TimeWithZone.name.Rafael Mendonça França
-
Deprecate
config.active_support.disable_to_s_conversion.Rafael Mendonça França
-
Remove deprecated option to passing a format to
#to_sinArray,Range,Date,DateTime,Time,BigDecimal,Floatand,Integer.Rafael Mendonça França
-
Remove deprecated
ActiveSupport::PerThreadRegistry.Rafael Mendonça França
-
Remove deprecated override of
Enumerable#sum.Rafael Mendonça França
-
Deprecated initializing a
ActiveSupport::Cache::MemCacheStorewith an instance ofDalli::Client.Deprecate the undocumented option of providing an already-initialized instance of
Dalli::ClienttoActiveSupport::Cache::MemCacheStore. Such clients could be configured with unrecognized options, which could lead to unexpected behavior. Instead, provide addresses as documented.aledustet
-
Stub
Time.new()inTimeHelpers#travel_totravel_to Time.new(2004, 11, 24) do # Inside the `travel_to` block `Time.new` is stubbed assert_equal 2004, Time.new.year end
fatkodima
-
Raise
ActiveSupport::MessageEncryptor::InvalidMessagefromActiveSupport::MessageEncryptor#decrypt_and_verifyregardless of cipher. Previously, when aMessageEncryptorwas using a non-AEAD cipher such as AES-256-CBC, a corrupt or tampered message would raiseActiveSupport::MessageVerifier::InvalidSignature. Now, all ciphers raise the same error:encryptor = ActiveSupport::MessageEncryptor.new("x" * 32, cipher: "aes-256-gcm") message = encryptor.encrypt_and_sign("message") encryptor.decrypt_and_verify(message.next) # => raises ActiveSupport::MessageEncryptor::InvalidMessage encryptor = ActiveSupport::MessageEncryptor.new("x" * 32, cipher: "aes-256-cbc") message = encryptor.encrypt_and_sign("message") encryptor.decrypt_and_verify(message.next) # BEFORE: # => raises ActiveSupport::MessageVerifier::InvalidSignature # AFTER: # => raises ActiveSupport::MessageEncryptor::InvalidMessage
Jonathan Hefner
-
Support
niloriginal values when usingActiveSupport::MessageVerifier#verify. Previously,MessageVerifier#verifydid not work withniloriginal values, though bothMessageVerifier#verifiedandMessageEncryptor#decrypt_and_verifydo:encryptor = ActiveSupport::MessageEncryptor.new(secret) message = encryptor.encrypt_and_sign(nil) encryptor.decrypt_and_verify(message) # => nil verifier = ActiveSupport::MessageVerifier.new(secret) message = verifier.generate(nil) verifier.verified(message) # => nil verifier.verify(message) # BEFORE: # => raises ActiveSupport::MessageVerifier::InvalidSignature # AFTER: # => nil
Jonathan Hefner
-
Maintain
html_safe?on html_safe strings when sliced withslice,slice!, orchrmethod.Previously,
html_safe?was only maintained when the html_safe strings were sliced with[]method. Now,slice,slice!, andchrmethods will maintainhtml_safe?like[]method.string = "<div>test</div>".html_safe string.slice(0, 1).html_safe? # => true string.slice!(0, 1).html_safe? # => true # maintain html_safe? after the slice! string.html_safe? # => true string.chr.html_safe? # => true
Michael Go
-
Add
Object#in?support for open ranges.assert Date.today.in?(..Date.tomorrow) assert_not Date.today.in?(Date.tomorrow..)
Ignacio Galindo
-
config.i18n.raise_on_missing_translations = truenow raises on any missing translation.Previously it would only raise when called in a view or controller. Now it will raise anytime
I18n.tis provided an unrecognised key.If you do not want this behaviour, you can customise the i18n exception handler. See the upgrading guide or i18n guide for more information.
Alex Ghiculescu
-
ActiveSupport::CurrentAttributesnow raises if a restricted attribute name is used.Attributes such as
setandresetcannot be used as they clash with theCurrentAttributespublic API.Alex Ghiculescu
-
HashWithIndifferentAccess#transform_keysnow takes a Hash argument, just as Ruby'sHash#transform_keysdoes.Akira Matsuda
-
delegatenow defines method with proper arity when delegating to a Class. With this change, it defines faster method (3.5x faster with no argument). However, in order to gain this benefit, the delegation target method has to be defined before declaring the delegation.# This defines 3.5 times faster method than before class C def self.x() end delegate :x, to: :class end class C # This works but silently falls back to old behavior because # `delegate` cannot find the definition of `x` delegate :x, to: :class def self.x() end end
Akira Matsuda
-
assert_differencemessage now includes what changed.This makes it easier to debug non-obvious failures.
Before:
"User.count" didn't change by 32. Expected: 1611 Actual: 1579After:
"User.count" didn't change by 32, but by 0. Expected: 1611 Actual: 1579Alex Ghiculescu
-
Add ability to match exception messages to
assert_raisesassertionInstead of this
error = assert_raises(ArgumentError) do perform_service(param: 'exception') end assert_match(/incorrect param/i, error.message)
you can now write this
assert_raises(ArgumentError, match: /incorrect param/i) do perform_service(param: 'exception') end
fatkodima
-
Add
Rails.env.local?shorthand forRails.env.development? || Rails.env.test?.DHH
-
ActiveSupport::Testing::TimeHelpersnow accepts namedwith_usecargument tofreeze_time,travel, andtravel_tomethods. Passing true prevents truncating the destination time withchange(usec: 0).KevSlashNull, and serprex
-
ActiveSupport::CurrentAttributes.resetsnow accepts a method nameThe block API is still the recommended approach, but now both APIs are supported:
class Current < ActiveSupport::CurrentAttributes resets { Time.zone = nil } resets :clear_time_zone end
Alex Ghiculescu
-
Ensure
ActiveSupport::Testing::Isolation::Forkingcloses pipesPreviously,
Forking.run_in_isolationopened two ends of a pipe. The fork process closed the read end, wrote to it, and then terminated (which presumably closed the file descriptors on its end). The parent process closed the write end, read from it, and returned, never closing the read end.This resulted in an accumulation of open file descriptors, which could cause errors if the limit is reached.
Sam Bostock
-
Fix
Time#changeandTime#advancefor times around the end of Daylight Saving Time.Previously, when
Time#changeorTime#advanceconstructed a time inside the final stretch of Daylight Saving Time (DST), the non-DST offset would always be chosen for local times:# DST ended just before 2021-11-07 2:00:00 AM in US/Eastern. ENV["TZ"] = "US/Eastern" time = Time.local(2021, 11, 07, 00, 59, 59) + 1 # => 2021-11-07 01:00:00 -0400 time.change(day: 07) # => 2021-11-07 01:00:00 -0500 time.advance(seconds: 0) # => 2021-11-07 01:00:00 -0500 time = Time.local(2021, 11, 06, 01, 00, 00) # => 2021-11-06 01:00:00 -0400 time.change(day: 07) # => 2021-11-07 01:00:00 -0500 time.advance(days: 1) # => 2021-11-07 01:00:00 -0500
And the DST offset would always be chosen for times with a
TimeZoneobject:Time.zone = "US/Eastern" time = Time.new(2021, 11, 07, 02, 00, 00, Time.zone) - 3600 # => 2021-11-07 01:00:00 -0500 time.change(day: 07) # => 2021-11-07 01:00:00 -0400 time.advance(seconds: 0) # => 2021-11-07 01:00:00 -0400 time = Time.new(2021, 11, 8, 01, 00, 00, Time.zone) # => 2021-11-08 01:00:00 -0500 time.change(day: 07) # => 2021-11-07 01:00:00 -0400 time.advance(days: -1) # => 2021-11-07 01:00:00 -0400
Now,
Time#changeandTime#advancewill choose the offset that matches the original time's offset when possible:ENV["TZ"] = "US/Eastern" time = Time.local(2021, 11, 07, 00, 59, 59) + 1 # => 2021-11-07 01:00:00 -0400 time.change(day: 07) # => 2021-11-07 01:00:00 -0400 time.advance(seconds: 0) # => 2021-11-07 01:00:00 -0400 time = Time.local(2021, 11, 06, 01, 00, 00) # => 2021-11-06 01:00:00 -0400 time.change(day: 07) # => 2021-11-07 01:00:00 -0400 time.advance(days: 1) # => 2021-11-07 01:00:00 -0400 Time.zone = "US/Eastern" time = Time.new(2021, 11, 07, 02, 00, 00, Time.zone) - 3600 # => 2021-11-07 01:00:00 -0500 time.change(day: 07) # => 2021-11-07 01:00:00 -0500 time.advance(seconds: 0) # => 2021-11-07 01:00:00 -0500 time = Time.new(2021, 11, 8, 01, 00, 00, Time.zone) # => 2021-11-08 01:00:00 -0500 time.change(day: 07) # => 2021-11-07 01:00:00 -0500 time.advance(days: -1) # => 2021-11-07 01:00:00 -0500
Kevin Hall, Takayoshi Nishida, and Jonathan Hefner
-
Fix MemoryStore to preserve entries TTL when incrementing or decrementing
This is to be more consistent with how MemCachedStore and RedisCacheStore behaves.
Jean Boussier
-
Rails.error.handleandRails.error.recordfilter now by multiple error classes.Rails.error.handle(IOError, ArgumentError) do 1 + '1' # raises TypeError end 1 + 1 # TypeErrors are not IOErrors or ArgumentError, so this will *not* be handled
Martin Spickermann
-
Class#subclassesandClass#descendantsnow automatically filter reloaded classes.Previously they could return old implementations of reloadable classes that have been dereferenced but not yet garbage collected.
They now automatically filter such classes like
DescendantTracker#subclassesandDescendantTracker#descendants.Jean Boussier
-
Rails.error.reportnow marks errors as reported to avoid reporting them twice.In some cases, users might want to report errors explicitly with some extra context before letting it bubble up.
This also allows to safely catch and report errors outside of the execution context.
Jean Boussier
-
Add
assert_error_reportedandassert_no_error_reportedAllows to easily asserts an error happened but was handled
report = assert_error_reported(IOError) do # ... end assert_equal "Oops", report.error.message assert_equal "admin", report.context[:section] assert_equal :warning, report.severity assert_predicate report, :handled?
Jean Boussier
-
ActiveSupport::Deprecationbehavior callbacks can now receive the deprecator instance as an argument. This makes it easier for such callbacks to change their behavior based on the deprecator's state. For example, based on the deprecator'sdebugflag.3-arity and splat-args callbacks such as the following will now be passed the deprecator instance as their third argument:
->(message, callstack, deprecator) { ... }->(*args) { ... }->(message, *other_args) { ... }
2-arity and 4-arity callbacks such as the following will continue to behave the same as before:
->(message, callstack) { ... }->(message, callstack, deprecation_horizon, gem_name) { ... }->(message, callstack, *deprecation_details) { ... }
Jonathan Hefner
-
ActiveSupport::Deprecation#disallowed_warningsnow affects the instance on which it is configured.This means that individual
ActiveSupport::Deprecationinstances can be configured with their own disallowed warnings, and the globalActiveSupport::Deprecation.disallowed_warningsnow only affects the globalActiveSupport::Deprecation.warn.Before
ActiveSupport::Deprecation.disallowed_warnings = ["foo"] deprecator = ActiveSupport::Deprecation.new("2.0", "MyCoolGem") deprecator.disallowed_warnings = ["bar"] ActiveSupport::Deprecation.warn("foo") # => raise ActiveSupport::DeprecationException ActiveSupport::Deprecation.warn("bar") # => print "DEPRECATION WARNING: bar" deprecator.warn("foo") # => raise ActiveSupport::DeprecationException deprecator.warn("bar") # => print "DEPRECATION WARNING: bar"
After
ActiveSupport::Deprecation.disallowed_warnings = ["foo"] deprecator = ActiveSupport::Deprecation.new("2.0", "MyCoolGem") deprecator.disallowed_warnings = ["bar"] ActiveSupport::Deprecation.warn("foo") # => raise ActiveSupport::DeprecationException ActiveSupport::Deprecation.warn("bar") # => print "DEPRECATION WARNING: bar" deprecator.warn("foo") # => print "DEPRECATION WARNING: foo" deprecator.warn("bar") # => raise ActiveSupport::DeprecationException
Note that global
ActiveSupport::Deprecationmethods such asActiveSupport::Deprecation.warnandActiveSupport::Deprecation.disallowed_warningshave been deprecated.Jonathan Hefner
-
Add italic and underline support to
ActiveSupport::LogSubscriber#colorPreviously, only bold text was supported via a positional argument. This allows for bold, italic, and underline options to be specified for colored logs.
info color("Hello world!", :red, bold: true, underline: true)
Gannon McGibbon
-
Add
String#downcase_firstmethod.This method is the corollary of
String#upcase_first.Mark Schneider
-
thread_mattr_accessorwill call.dup.freezeon non-frozen default values.This provides a basic level of protection against different threads trying to mutate a shared default object.
Jonathan Hefner
-
Add
raise_on_invalid_cache_expiration_timeconfig toActiveSupport::Cache::StoreSpecifies if an
ArgumentErrorshould be raised ifRails.cachefetchorwriteare given an invalidexpires_atorexpires_intime.Options are
true, andfalse. Iffalse, the exception will be reported ashandledand logged instead. Defaults totrueifconfig.load_defaults >= 7.1.Trevor Turk
-
ActiveSupport::Cache::Store#fetchnow passes an options accessor to the block.It makes possible to override cache options:
Rails.cache.fetch("3rd-party-token") do |name, options| token = fetch_token_from_remote # set cache's TTL to match token's TTL options.expires_in = token.expires_in token endAndrii Gladkyi, Jean Boussier
-
defaultoption ofthread_mattr_accessornow applies through inheritance and also across new threads.Previously, the
defaultvalue provided was set only at the moment of defining the attribute writer, which would cause the attribute to be uninitialized in descendants and in other threads.Fixes #43312.
Thierry Deo
-
Redis cache store is now compatible with redis-rb 5.0.
Jean Boussier
-
Add
skip_nil:support toActiveSupport::Cache::Store#fetch_multi.Daniel Alfaro
-
Add
quartermethod to date/timeMatt Swanson
-
Fix
NoMethodErroron customActiveSupport::Deprecationbehavior.ActiveSupport::Deprecation.behavior=was supposed to accept any object that responds tocall, but in fact its internal implementation assumed that this object could respond toarity, so it was restricted to onlyProcobjects.This change removes this
arityrestriction of custom behaviors.Ryo Nakamura
-
Support
:url_safeoption forMessageEncryptor.The
MessageEncryptorconstructor now accepts a:url_safeoption, similar to theMessageVerifierconstructor. When enabled, this option ensures that messages use a URL-safe encoding.Jonathan Hefner
-
Add
url_safeoption toActiveSupport::MessageVerifierinitializerActiveSupport::MessageVerifier.newnow takes optionalurl_safeargument. It can generate URL-safe strings by passingurl_safe: true.verifier = ActiveSupport::MessageVerifier.new(url_safe: true) message = verifier.generate(data) # => URL-safe string
This option is
falseby default to be backwards compatible.Shouichi Kamiya
-
Enable connection pooling by default for
MemCacheStoreandRedisCacheStore.If you want to disable connection pooling, set
:pooloption tofalsewhen configuring the cache store:config.cache_store = :mem_cache_store, "cache.example.com", pool: false
fatkodima
-
Add
force:support toActiveSupport::Cache::Store#fetch_multi.fatkodima
-
Deprecated
:pool_sizeand:pool_timeoutoptions for configuring connection pooling in cache stores.Use
pool: trueto enable pooling with default settings:config.cache_store = :redis_cache_store, pool: true
Or pass individual options via
:pooloption:config.cache_store = :redis_cache_store, pool: { size: 10, timeout: 2 }
fatkodima
-
Allow #increment and #decrement methods of
ActiveSupport::Cache::Storesubclasses to set new values.Previously incrementing or decrementing an unset key would fail and return nil. A default will now be assumed and the key will be created.
Andrej Blagojević, Eugene Kenny
-
Add
skip_nil:support toRedisCacheStoreJoey Paris
-
ActiveSupport::Cache::MemoryStore#write(name, val, unless_exist:true)now correctly writes expired keys.Alan Savage
-
ActiveSupport::ErrorReporternow accepts and forward asource:parameter.This allow libraries to signal the origin of the errors, and reporters to easily ignore some sources.
Jean Boussier
-
Fix and add protections for XSS in
ActionView::HelpersandERB::Util.Add the method
ERB::Util.xml_name_escapeto escape dangerous characters in names of tags and names of attributes, following the specification of XML.Álvaro Martín Fraguas
-
Respect
ActiveSupport::Logger.new's:formatterkeyword argumentThe stdlib
Logger::newallows passing a:formatterkeyword argument to set the logger's formatter. PreviouslyActiveSupport::Logger.newignored that argument by always setting the formatter to an instance ofActiveSupport::Logger::SimpleFormatter.Steven Harman
-
Deprecate preserving the pre-Ruby 2.4 behavior of
to_timeWith Ruby 2.4+ the default for +to_time+ changed from converting to the local system time to preserving the offset of the receiver. At the time Rails supported older versions of Ruby so a compatibility layer was added to assist in the migration process. From Rails 5.0 new applications have defaulted to the Ruby 2.4+ behavior and since Rails 7.0 now only supports Ruby 2.7+ this compatibility layer can be safely removed.
To minimize any noise generated the deprecation warning only appears when the setting is configured to
falseas that is the only scenario where the removal of the compatibility layer has any effect.Andrew White
-
Pathname.blank?only returns true forPathname.new("")Previously it would end up calling
Pathname#empty?which returned true if the path existed and was an empty directory or file.That behavior was unlikely to be expected.
Jean Boussier
-
Deprecate
Notification::Event's#childrenand#parent_of?John Hawthorn
-
Change the default serializer of
ActiveSupport::MessageVerifierfromMarshaltoActiveSupport::JSONwhen usingconfig.load_defaults 7.1.Messages serialized with
Marshalcan still be read, but new messages will be serialized withActiveSupport::JSON. For more information, see https://guides.rubyonrails.org/v7.1/configuring.html#config-active-support-message-serializer.Saba Kiaei, David Buckley, and Jonathan Hefner
-
Change the default serializer of
ActiveSupport::MessageEncryptorfromMarshaltoActiveSupport::JSONwhen usingconfig.load_defaults 7.1.Messages serialized with
Marshalcan still be read, but new messages will be serialized withActiveSupport::JSON. For more information, see https://guides.rubyonrails.org/v7.1/configuring.html#config-active-support-message-serializer.Zack Deveau, Martin Gingras, and Jonathan Hefner
-
Add
ActiveSupport::TestCase#stub_constto stub a constant for the duration of a yield.DHH
-
Fix
ActiveSupport::EncryptedConfigurationto be compatible with Psych 4Stephen Sugden
-
Improve
File.atomic_writeerror handlingDaniel Pepper
-
Fix
Class#descendantsandDescendantsTracker#descendantscompatibility with Ruby 3.1.The native
Class#descendantswas reverted prior to Ruby 3.1 release, butClass#subclasseswas kept, breaking the feature detection.Jean Boussier
Please check 7-0-stable for previous changes.