| Commit message (Collapse) | Author | Age | Files | Lines |
... | |
|\ \ \
| | | |
| | | | |
Align Time.zone.at method signature with that of Time::at
|
| | | |
| | | |
| | | |
| | | | |
For parity with Ruby's Time::at
|
|/ / /
| | |
| | |
| | | |
This is unnecessary since #22269.
|
| | | |
|
|\ \ \
| | | |
| | | | |
Clearer error message in assert_changes
|
| | | |
| | | |
| | | |
| | | | |
When `to:` is passed to `assert_changes`, it now prints the well-known `"Expected: x\n Actual: y"` message.
Before, the message only contained the actual value.
|
|\ \ \ \
| | | | |
| | | | | |
Document require_dependency [ci skip]
|
| |/ / / |
|
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | | |
ruby/ruby@989e07c features switching `Range#===` to use internal `r_cover_p`
instead of rubyland `include?`. This breaks expected behavior of
`ActiveSupport::CoreExt::Range` documented since at least 8b67a02.
This patch adds overrides on `Range#cover?` and `Range#===` and places all
three in a single module, `CompareWithRange`.
*Requiring core_ext/range/include_range now causes a deprecation warnning*
|
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | | |
In the app I'm working on I've wished that index_by had a buddy that would
assign the hash value instead of the key multiple times.
Enter index_with. Useful when building a hash from a static list of
symbols. Before you'd do:
```ruby
POST_ATTRIBUTES.map { |attr_name| [ attr_name, public_send(attr_name) ] }.to_h
```
But now that's a little clearer and faster with:
````ruby
POST_ATTRIBUTES.index_with { |attr_name| public_send(attr_name) }
```
It's also useful when you have an enumerable that should be converted to a hash,
but you don't want to muddle the code up with the overhead that it takes to create
that hash. So before, that's:
```ruby
WEEKDAYS.each_with_object(Hash.new) do |day, intervals|
intervals[day] = [ Interval.all_day ]
end
```
And now it's just:
```ruby
WEEKDAYS.index_with([ Interval.all_day ])
```
It's also nice to quickly get a hash with either nil, [], or {} as the value.
|
|/ / /
| | |
| | |
| | | |
Fixes #32928.
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | | |
See #29632 for details. In short, it's possible to enter `LoadError#is_missing?` when `LoadError#path` returns `nil`, leading to `path.sub` throwing an none-to-helpful `NoMethodError`.
This tiniest of patch inserts `#to_s` before the `sub` call to make sure it succeeds. Affected surface area should be just as tiny since something has already gone wrong to get us into `#is_missing?` and the current behavior when `#path` returns `nil` seems clearly not intended.
[Gannon McGibbon + Neil Souza]
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | | |
This improves the performance for the most ordinalized numbers (1st,
2nd, 3rd, etc).
```
require "benchmark/ips"
def o1(number)
abs_number = number.to_i.abs
if (11..13).include?(abs_number % 100)
"th"
else
case abs_number % 10
when 1; "st"
when 2; "nd"
when 3; "rd"
else "th"
end
end
end
def o3(number)
case number
when 1; "st"
when 2; "nd"
when 3; "rd"
when 4, 5, 6, 7, 8, 9, 10, 11, 12, 13; "th"
else
num_modulo = number.to_i.abs % 100
if 11 <= num_modulo && num_modulo <= 13
"th"
else
case num_modulo % 10
when 1; "st"
when 2; "nd"
when 3; "rd"
else "th"
end
end
end
end
def o4(number)
case number
when 1; "st"
when 2; "nd"
when 3; "rd"
when 4, 5, 6, 7, 8, 9, 10, 11, 12, 13; "th"
else
num_modulo = number.to_i.abs % 100
num_modulo %= 10 if num_modulo > 13
case num_modulo
when 1; "st"
when 2; "nd"
when 3; "rd"
else "th"
end
end
end
puts RUBY_DESCRIPTION
Benchmark.ips do |x|
x.report("orig") { o1(1); o1(2); o1(3); o1(4); o1(11); o1(111); o1(1523) }
x.report("ord3") { o3(1); o3(2); o3(3); o3(4); o3(11); o3(111); o3(1523) }
x.report("ord4") { o4(1); o4(2); o4(3); o4(4); o4(11); o4(111); o4(1523) }
x.compare!
end
```
```
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin15]
Warming up --------------------------------------
orig 25.305k i/100ms
ord3 121.146k i/100ms
ord4 124.944k i/100ms
Calculating -------------------------------------
orig 275.496k (± 2.4%) i/s - 1.392M in 5.054720s
ord3 1.649M (± 5.0%) i/s - 8.238M in 5.009801s
ord4 1.700M (± 7.0%) i/s - 8.496M in 5.031646s
Comparison:
ord4: 1700059.6 i/s
ord3: 1649154.9 i/s - same-ish: difference falls within error
orig: 275496.3 i/s - 6.17x slower
```
Closes #25020.
[lvl0nax, Jeremy Daer, Ryuta Kamizono]
|
|\ \ \
| | | |
| | | | |
`SetupAndTeardown` has few caveats that breaks libraries
|
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | | |
- In #32472 I introduced a fix in order for all `after_teardown` method provided by libraries and Rails to run, even if the application's `teardown` method raised an error (That's the default minitest behavior). However this change wasn't enough and doesn't take in consideration the ancestors chain.
If a library's module containing an `after_teardown` method get included after the `SetupAndTeardown` module (one example is the [ActiveRecord::TestFixtures module](https://github.com/rails/rails/blob/7d2400ab61c8e3ed95e14d03ba3844e8ba2e36e4/activerecord/lib/active_record/fixtures.rb#L855-L856), then the ancestors of the test class would look something like
```ruby
class MyTest < ActiveSupport::TestCase
end
puts MyTest.ancestors # [MyTest, ActiveSupport::TestCase, ActiveRecord::TestFixtures, ActiveSupport::Testing::SetupAndTeardown]
```
Any class/module in the ancestors chain that are **before** the `ActiveSupport::Testing::SetupAndTeardown` will behave incorrectly:
- Their `before_setup` method will get called **after** all regular setup method
- Their `after_teardown` method won't even get called in case an exception is raised inside a regular's test `teardown`
A simple reproduction script of the problem here https://gist.github.com/Edouard-chin/70705542a59a8593f619b02e1c0a188c
- One solution to this problem is to have the `AS::SetupAndTeardown` module be the very first in the ancestors chain. By doing that we ensure that no `before_setup` / `after_teardown` get executed prior to running the teardown callbacks
|
|/ / /
| | |
| | |
| | | |
This method would be called so many times and would create so many temporary garbage Strings
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | | |
tags_text method creates 3 Ruby objects per each logger call when no custom tags are given
(which is the default setting, and so presumably the majority use case).
This patch reduces two temporary object creations in this case.
require 'allocation_tracer'
ObjectSpace::AllocationTracer.setup(%i{type})
tags = ['a']
pp before: ObjectSpace::AllocationTracer.trace {
tags.collect { |tag| "[#{tag}] " }.join
}
pp after: ObjectSpace::AllocationTracer.trace {
"[#{tags[0]}] "
}
{:before=>{[:T_ARRAY]=>[1, 0, 0, 0, 0, 0], [:T_STRING]=>[2, 0, 0, 0, 0, 0]}}
{:after=>{[:T_STRING]=>[1, 0, 0, 0, 0, 0]}}
|
| | | |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | | |
- The "/" was removed in 40bdbce191ad90dfea43dad51fac5c4726b89392 during
refactoring. It may cause regression since looks like was added
intentionaly because it is possible that a name of any another gem
can start with /rails/, so slash was added to ensure that it is "rails"
gem.
I would like to backport this to `5-2-stable` too.
- Use `__dir__` instead of `__FILE__`. Follow up #29176.
|
|\ \ \
| | | |
| | | | |
`#ordinal` and `#ordinalize` now support I18n
|
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | | |
now support translations through I18n.
{
fr: {
number: {
nth: {
ordinals: lambda do |_key, number:, **_options|
if number.to_i.abs == 1
'er'
else
'e'
end
end,
ordinalized: lambda do |_key, number:, **_options|
"#{number}#{ActiveSupport::Inflector.ordinal(number)}"
end
}
}
}
}
|
|\ \ \ \ |
|
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | | |
Fixes #32610. Closes #32614.
Lua scripts in redis are *blocking*, meaning that no other client can
execute any commands while the script is running. See
https://redis.io/commands/eval#atomicity-of-scripts.
This results in the following exceptions once the number of keys is
sufficiently large:
BUSY Redis is busy running a script.
You can only call SCRIPT KILL or SHUTDOWN NOSAVE.
This commit replaces the lua-based implementation with one that uses
`SCAN` and `DEL` in batches. This doesn't block the server.
The primary limitation of `SCAN`, i.e. potential duplicate keys, is of
no consequence here, because `DEL` ignores keys that do not exist.
|
|/ / / /
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | | |
Before this change missing timezone data for any of the time zones
defined in `ActiveSupport::Timezone::MAPPING` caused a `comparison of
NilClass with ActiveSupport::TimeZone failed` exception.
Attempting to get a timezone by passing a number/duration to `[]` or
calling `all` directly will try to sort sort the values of `zones_map`.
Those values are initialized by the return value of `create(zonename)`
which returns `nil` if `TZInfo` is unable to find the timezone
information.
In our case the exception was triggered by an outdated tzdata package
which did not include information for the "recently" added time zones.
Before 078421bacba178eac6a8e607b16f3f4511c5d72f `zones_map` only
returned the information that have been loaded into `@lazy_zone_map`
which ignored time zones for which the data could not be loaded, this
change restores the previous behaviour.
|
| | | | |
|
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | | |
Namespace not working in RedisCacheStore#clear method. Bacause
namespace = merged_options(options)[namespace]
is always nil, Correct is
namespace = merged_options(options)[:namespace]
|
|\ \ \ \
| | | | |
| | | | | |
Don't doc _original_sum_with_required_identity
|
| | | | |
| | | | |
| | | | |
| | | | | |
It's not public API so don't document it.
|
|\ \ \ \ \
| |/ / / /
|/| | | | |
Fix ActiveSupport::Cache compression
|
| | | | |
| | | | |
| | | | |
| | | | | |
(See previous commit for a description of the issue)
|
|\ \ \ \ \
| | | | | |
| | | | | |
| | | | | |
| | | | | | |
teddywing/active-support-cache-store--fix-end-tag-in-read-method-documentation
Cache::Store#read: Fix fixed-width end tag in docs
|
| |/ / / /
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | | |
* Fix the ending `</tt>` tag for `:expires_in`. Otherwise, the "or" is
set in fixed-width also.
* Re-wrap paragraph to 80 columns.
[ci skip]
|
|\ \ \ \ \
| |/ / / /
|/| | | | |
Define callbacks on descendants.
|
| | | | |
| | | | |
| | | | |
| | | | | |
Addresses feedback from https://github.com/rails/rails/pull/31913#issuecomment-365983580
|
| | | | |
| | | | |
| | | | |
| | | | | |
We set callbacks on all descendants, so we need to make sure that they are also defined on all descendants as well.
|
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | | |
If you have a regular test that have a teardown block, and for any reason an exception get raised, ActiveSupport will not run subsequent after_teardown method provided by other module or gems.
One of them being the ActiveRecord::TestFixtures which won't rollback the transation when the test ends making all subsequent test to be in a weird state.
The default implementation of minitest is to run all teardown methods from the user's test, rescue all exceptions, run all after_teardown methods provided by libraries and finally re-raise the exception that happened in the user's teardown method.
Rails should do the same.
|
| | | | | |
|
| | | | |
| | | | |
| | | | |
| | | | | |
[ci skip]
|
|\ \ \ \ \
| | | | | |
| | | | | | |
Change temporary file name extension while editing encrypted file.
|
| | | | | |
| | | | | |
| | | | | |
| | | | | | |
To have syntax highlighting in an editor try to preserve original extension of edited file.
|
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | | |
This prevents duplication of code.
Prevent duplication of tests by moving them to `DateAndTimeBehavior`.
Related to #32185.
|
| | | | | | |
|
|\ \ \ \ \ \
| | | | | | |
| | | | | | | |
Add `before?` and `after?` methods to date and time classes
|
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | | |
Equality comparisons between dates and times can take some extra time to
comprehend. I tend to think of a date or time as "before" or "after"
another date or time, but I naturally read `<` and `>` as "less than"
and "greater than." This change seeks to make date/time comparisons more
human readable.
|
| | | | | | | |
|
|\ \ \ \ \ \ \
| | | | | | | |
| | | | | | | | |
Fix Cache `read_multi` with local_cache bug, should returns raw value, not `ActiveSupport::Cache::Entry` instance.
|
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | | |
It should returns raw value, not instance of `ActiveSupport::Cache::Entry`.
|
| | | | | | | | |
|
|/ / / / / / /
| | | | | | |
| | | | | | |
| | | | | | | |
since revision 62897 https://github.com/ruby/ruby/commit/234a30459cdae6aa7da6e28a1082d9c11f315696
|
| |/ / / / /
|/| | | | | |
|