- The `halted_callback_hook` method is called whenever the
`terminator` halt the callback execution.
Usually, this translate to when a `before` callback throw
an `:abort`.
<details>
<summary> Example </summary>
```ruby
class Foo
include ActiveSupport::Callbacks
define_callbacks :save
set_callback(:save, :before) { throw(:abort) }
def run
run_callbacks(:save) do
'hello'
end
end
def halted_callback_hook(filter)
# filter is the proc passed to `set_callback` above
end
end
```
</details>
### Problem
When a class has multiple callbacks, (i.e. `save`, `validate` ...),
it's impossible to tell in the halted_callback_hook which type of
callback halted the execution.
This is useful to take different action based on the callback.
<details>
<summary> Use Case </summary>
```ruby
class Foo
include ActiveSupport::Callbacks
define_callbacks :save
define_callbacks :validate
set_callback(:save, :before) { throw(:abort) }
set_callback(:validate, :before) { throw(:abort) }
def run
run_callbacks(:validate) do
...
end
run_callbacks(:save) do
...
end
end
def halted_callback_hook(filter)
Rails.logger.warn("Couldn't save the record, the ??? callback halted the execution")
end
end
```
</details>
### Solution
Allow `halted_callback_hook` to receive a second argument which is
the name of the callback being run.
This provides better more specific diffs when comparing complex objects.
Reverts bbe437faecca5fd6bdc2327a4bc7a31ba21afe2e.
Closes#37507. Closes#38220.
Co-authored-by: michdsouza <michd2005@gmail.com>
Co-authored-by: Rahul Purohit <rahulpuroht@gmail.com>
Co-authored-by: Nicholas Koh <nkohwl@gmail.com>
This reverts commit 7aa047b57237f691540afc3e22b91f73df7e5bc4, reversing
changes made to c9b36dd67a1c8fe40ad76301e3929e47b0b23e1d.
This is a right example for singular names.
- If an error occurs when rendering ERB (other than a Psych's
SyntaxError), it's impossible to know in which file the error
occured.
This commit fixes that
Using a class variable here makes the tests susceptible to phantom
greens because (depending on the order of the tests), the class variable
could have been set by a prior test. (Test polution)
Better to have the variable be tied to the instance.
In rare instances, a module needs to be prepended into the ancestor
hierarchy, not simply included. In cases where this is necessary, and it
is desirable to use an inline concern, it would be beneficial to be able
to instruct `concerning` that the concern should be prepended.
This is now possible, by providing `prepend: true` kwarg to
`concerning`. (It is false by default.)
It's been 6 years since [the original](https://github.com/rails/rails/pull/13584), so we're overdue for a sequel.
The correct word is "cannot", one word, not "can not", two words.
This initializes our caches with a random namespace which should ensure
that we can run the tests in parallel without interfering with each
other.
One compromise is that we can never actually call cache.clear on the
memcache client, since that would clear the cache for all namespaces. We
can work around this for the one test that needs to do a clear to
stub flush_all on the client and replace it with a delete.
This allows deprecation messages to be matched by substring, symbol (treated as
substring), or regular expression. If a warning is matched, the behaviors
configured for disallowed deprecations will be used. The default behavior for
disallowed deprecation warnings is `:raise`.
Also adds `ActiveSupport::Deprecation.allow` for thread-local, block level ignoring of deprecation warnings which would otherwise be disallowed by ActiveSupport::Deprecation.disallowed_warnings.
Support handling a `round_mode` in `ActiveSupport::NumberHelper::RoundingHelper`
Add default value to locale file
Update inline documentation with new parameter option
Update CHANGELOG
Add round_mode examples to all the tests
Add I18n test
Simplify logic
Further simpification
It converts the week part into days and removes it from the final result.
```
duration = ActiveSupport::Duration.build(1000000) # 1 week, 4 days, 13 hours, 46 minutes, and 40.0 seconds
duration_iso = duration.iso8601 # P11DT13H46M40S
ActiveSupport::Duration.parse(duration_iso) # 11 days, 13 hours, 46 minutes, and 40 seconds
```
Related #37839.
Sometimes divisions of `ActiveSupport::Duration` makes the instance's
parts attribute empty, but it has a value actually (e.g. `(1.minute /
60) # => @value=1 (second), but empty parts`).
In that case we should respect `value` as the source of seconds.
```ruby
(1.day / 24).inspect #=> "0 seconds"
(1.day / 24).to_i #=> 3600
(1.day / 24) == 1.hour #=> true
(1.hour).inspect #=> "1 hour"
(1.hour).parts #=> {:hours=>1}
(1.day / 24).parts #=> {}
```
Sometimes divisions of `ActiveSupport::Duration` make the instance's `parts` attribute empty. But these instances are not always 0 seconds.
Related to #31310 and #31302
9845cd6 broke configuring a cache store like so:
config.cache_store = :redis_cache_store, config_for("redis/cache")
Rails::Application#config_for returns an ActiveSupport::OrderedOptions. By default, the Array#extract_options! core extension won't extract instances of Hash subclasses. Add ActiveSupport::OrderedOptions#extractable_options? and have it return true to fix.