Eileen M. Uchitelle
ce77d671ae
Merge pull request #40241 from eileencodes/make-role-required
...
Make `role` required when using `shard` in `connected_to`
2020-09-17 08:23:38 -04:00
eileencodes
d4df616cc2
Make role
required when using shard
in connected_to
...
While working on some more indepth changes to Rails internal connection
management we noticed that it's confusing in some cases that the `role`
is implcit when using a `shard`. For example, if you passed a `shard`
and not a `role` in an un-nested block the default `role` would be
`writing`.
```
ActiveRecord::Base.connected_to(shard: :one) do
# connected to writing
end
```
However in cases where nesting is used it could be confusing to
application authors that the role is inherited:
```
ActiveRecord::Base.connected_to(role: :reading) do
ActiveRecord::Base.connected_to(shard: :one) do
# will read from shard one replica, not write to primary
end
end
```
Since this could be potentially confusing, and extremely hard to track
in complex applications, the best approach is to require `role` when
using `shard` which is what this PR does.
Note: the code for this method is...getting unweildy. Once the
`database` argument is fully deprecated we can remove most of the guards
and make `role` required by removing `nil` from the keyword argument.
Until then we need to support required arguments in this round about way.
2020-09-17 08:07:03 -04:00
Aaron Patterson
e5b07258c2
Merge pull request #40209 from latinadeveloper/guides-spanish-link
...
Update translation efforts Spanish link.
2020-09-16 12:10:10 -07:00
Eugene Kenny
0b244ff44c
Merge pull request #39989 from jonathanhefner/translate-refactor
...
Improve Action View `translate` helper
2020-09-16 17:01:45 +01:00
Jonathan Hefner
d81926fdac
Improve Action View translate
helper
...
This disentangles the control flow between Action View's `translate` and
I18n's `translate`. In doing so, it fixes a handful of corner cases,
for which tests have now been added. It also reduces memory
allocations, and improves speed when using a default:
**Memory**
```ruby
require "benchmark/memory"
Benchmark.memory do |x|
x.report("warmup") { translate(:"translations.foo"); translate(:"translations.html") }
x.report("text") { translate(:"translations.foo") }
x.report("html") { translate(:"translations.html") }
x.report("text 1 default") { translate(:"translations.missing", default: :"translations.foo") }
x.report("html 1 default") { translate(:"translations.missing", default: :"translations.html") }
x.report("text 2 defaults") { translate(:"translations.missing", default: [:"translations.missing", :"translations.foo"]) }
x.report("html 2 defaults") { translate(:"translations.missing", default: [:"translations.missing", :"translations.html"]) }
end
```
Before:
```
text 1.240k memsize ( 0.000 retained)
13.000 objects ( 0.000 retained)
2.000 strings ( 0.000 retained)
html 1.600k memsize ( 0.000 retained)
19.000 objects ( 0.000 retained)
2.000 strings ( 0.000 retained)
text 1 default 4.728k memsize ( 1.200k retained)
39.000 objects ( 4.000 retained)
5.000 strings ( 0.000 retained)
html 1 default 5.056k memsize ( 1.160k retained)
41.000 objects ( 3.000 retained)
4.000 strings ( 0.000 retained)
text 2 defaults 7.464k memsize ( 2.392k retained)
54.000 objects ( 6.000 retained)
4.000 strings ( 0.000 retained)
html 2 defaults 7.944k memsize ( 2.384k retained)
60.000 objects ( 6.000 retained)
4.000 strings ( 0.000 retained)
```
After:
```
text 952.000 memsize ( 0.000 retained)
9.000 objects ( 0.000 retained)
1.000 strings ( 0.000 retained)
html 1.008k memsize ( 0.000 retained)
10.000 objects ( 0.000 retained)
1.000 strings ( 0.000 retained)
text 1 default 2.400k memsize ( 40.000 retained)
24.000 objects ( 1.000 retained)
4.000 strings ( 0.000 retained)
html 1 default 2.464k memsize ( 0.000 retained)
22.000 objects ( 0.000 retained)
2.000 strings ( 0.000 retained)
text 2 defaults 3.232k memsize ( 0.000 retained)
30.000 objects ( 0.000 retained)
2.000 strings ( 0.000 retained)
html 2 defaults 3.456k memsize ( 0.000 retained)
32.000 objects ( 0.000 retained)
2.000 strings ( 0.000 retained)
```
**Speed**
```ruby
require "benchmark/ips"
Benchmark.ips do |x|
x.report("text") { translate(:"translations.foo") }
x.report("html") { translate(:"translations.html") }
x.report("text 1 default") { translate(:"translations.missing", default: :"translations.foo") }
x.report("html 1 default") { translate(:"translations.missing", default: :"translations.html") }
x.report("text 2 defaults") { translate(:"translations.missing", default: [:"translations.missing", :"translations.foo"]) }
x.report("html 2 defaults") { translate(:"translations.missing", default: [:"translations.missing", :"translations.html"]) }
end
```
Before:
```
text 35.685k (± 0.7%) i/s - 179.050k in 5.017773s
html 28.569k (± 3.1%) i/s - 143.871k in 5.040128s
text 1 default 13.953k (± 2.0%) i/s - 70.737k in 5.071651s
html 1 default 12.507k (± 0.4%) i/s - 63.546k in 5.080908s
text 2 defaults 9.103k (± 0.3%) i/s - 46.308k in 5.087323s
html 2 defaults 8.570k (± 4.3%) i/s - 43.071k in 5.034322s
```
After:
```
text 36.694k (± 2.0%) i/s - 186.864k in 5.094367s
html 30.415k (± 0.5%) i/s - 152.900k in 5.027226s
text 1 default 18.095k (± 2.7%) i/s - 91.086k in 5.036857s
html 1 default 15.934k (± 1.7%) i/s - 80.223k in 5.036085s
text 2 defaults 12.179k (± 0.6%) i/s - 61.659k in 5.062910s
html 2 defaults 11.193k (± 2.1%) i/s - 56.406k in 5.041433s
```
2020-09-16 10:18:54 -05:00
Akira Matsuda
46ea76980f
URL helper methods on controllers are public methods
2020-09-16 12:15:24 +09:00
Akira Matsuda
666897a025
AC::Base#url_for is a public method
2020-09-16 12:15:24 +09:00
Akira Matsuda
d41939a678
*Store implements delete_session as a public method
2020-09-16 12:15:24 +09:00
Akira Matsuda
badcaf6763
AR::Base#read_attribute_for_validation is a public_method
2020-09-16 12:15:23 +09:00
Akira Matsuda
9bed2269c9
AR::Base#write_attribute is a public method
2020-09-16 12:15:23 +09:00
Akira Matsuda
2d74f6c152
AC::Base#flash is a public method
2020-09-16 12:15:23 +09:00
Ryuta Kamizono
c848baffd2
✂️ [ci skip]
...
895134bcff (diff-7789e18ec0a61c6845755a257e6eb34fR3)
ee9e308f68 (diff-5e9551294914b338d923032fa904c6beR103)
5f63c771f7 (diff-600d5368b55e46ed961abb4295977ac3R506)
48b6bacbc5 (diff-279ac5c088a3ee7e9f954bbc10d1b773R246)
49adb7f4c6 (diff-0cbe7171fdd7821fd5836896849141c0R111)
9bfe89e68e (diff-9c1c95b001e3680ba8a473cf23508b68R8)
a0f18e6090 (diff-bef0ae2c16dacf77bfd2ba099af8a330R47)
8b4d344815 (diff-09660f59aee7ec893ad609315e8843c5R18)
49d1b5a98d (diff-531e71a9d5fdc8181f38ce4416553694R107)
b674f04756 (diff-7521c0bb452244663b689e77658e63e3R98)
a9012af688 (diff-60bdcf1e1954ec56d41fc4c7bd8d3e39R512)
6380aee182 (diff-5158c234d5e19bb1cffadcbc088400f1R262)
c7820d8124 (diff-f4614e7ba8081c0c9e20fe64b6374228R60)
8df7ed3b88 (diff-0495ed68f82d1bbde593ab5491eab24aR169)
6f94260ac6 (diff-7ecb6672f3fd37dfb79c4539395d3857R28)
03e44f9300 (diff-e9234c4c6668852448059c0a35840bcaR185)
2020-09-16 09:52:10 +09:00
Aaron Patterson
10d95e6848
Merge pull request #40231 from Shopify/gtg-builder
...
Use indentity hashes in Journey::GTG::Builder
2020-09-15 13:46:43 -07:00
Jean Boussier
895134bcff
Use indentity hashes in Journey::GTG::Builder
2020-09-15 22:02:05 +02:00
Ryuta Kamizono
77fc1c2b8e
Fix typo s/InvalidStatement/StatementInvalid/ [ci skip]
2020-09-15 18:57:25 +09:00
Akira Matsuda
47f5459138
Module#const_set is a public method
2020-09-15 17:19:37 +09:00
Eileen M. Uchitelle
31197f2079
Merge pull request #40219 from eileencodes/ensure-connects_to-is-always-called-on-base-or-abstract-classes
...
Ensure `connects_to` can only be called on base or abstract classes
2020-09-14 09:59:51 -04:00
eileencodes
5d36b04986
Ensure connects_to
can only be called on base or abstract classes
...
`connectes_to` should only be called on `ActiveRecord::Base` or abstract
classes. This is recommended in the documentation but until now was not
enforced by the code. It's unsafe to open too many connections to mysql
(and probably other databases), so it's safest to have 1 class for the
connection and subclass from that.
Co-authored-by: John Crepezzi <john.crepezzi@gmail.com>
2020-09-14 09:05:57 -04:00
Ryuta Kamizono
d097ee9706
Revert "Merge pull request #19881 from sikachu/silence-mysql-errno-warning"
...
This reverts commit 55d9e494e896e7b041dc7c18df197d53690642b5, reversing
changes made to 03e987cd8fa0951d80c70cbadb7daf890df38271.
Legacy mysql adapter is already removed in #22642 .
2020-09-14 14:02:45 +09:00
Ryuta Kamizono
e7a9f9de41
Merge pull request #40212 from Shopify/active-record-exceptions-wrapping
...
Translate Mysql2 errors in Mysql2Adapter#quote_string (take 2)
2020-09-14 14:00:47 +09:00
Eugene Kenny
1b2879404f
Remove MemCacheStore#write_entry options nil check
...
It will always be a hash since ee51b51b60f9e6cce9babed2c8a65a14d87790c8.
2020-09-13 22:50:27 +01:00
Kasper Timm Hansen
f04819972b
Merge pull request #40225 from p8/remove-unused-cache-hit-ivar
...
Remove unused @cache_hit Hash assignment
2020-09-13 12:35:18 +02:00
Petrik
ebb83e46ba
Remove unused @cache_hit Hash assignment
...
In 2abf6ca0c8304a3cfcdae6e14060b561780be43c @cache_hit got introduced.
This was renamed to @cache_hits and revised in the subsequent commit
8240636beda7b2b487217be1d945eb0d36145c4d but it seems one assignment was
overlooked.
2020-09-13 10:40:28 +02:00
Santiago Bartesaghi
4a78dcb326
Clarify ActiveStorage::Service#url docs [ci skip]
...
* Public services don’t respect `:disposition`, `:filename`, or `:content_type`.
* `:expires_in` is optional.
2020-09-12 12:47:33 -04:00
Jonathan Hefner
98a76a50ed
Refactor Action View translate
helper
...
This refactor incidentally fixes a corner case when `translate` is
called with a block, the translation is missing, and
`debug_missing_translation` is false.
This commit adds a test for the above corner case, and additional tests
for existing behavior.
2020-09-11 11:56:17 -05:00
Eileen M. Uchitelle
99a0254eff
Merge pull request #40186 from lulalala/alias-detail-to-details
...
Rename Error#detail method as details
2020-09-11 08:57:19 -04:00
lulalala
1fee2cbc50
Rename Error#detail method as details
...
Plural is more expected.
2020-09-11 17:03:59 +08:00
Jean Boussier
1269ab776d
Add a changelog entry for the exception changes in adapters
2020-09-10 13:39:24 +02:00
Jean Boussier
740cdc8414
Revert "Revert "Raise ConnectionNotEstablished rather than StatementInvalid in Mysql2Adapter#quote_string""
...
This reverts commit 6f92c40d3b5bf6ef65f4cc36645d28018450c878.
2020-09-10 12:09:53 +02:00
Ryuta Kamizono
e3b8ba396b
Merge pull request #40210 from utilum/update_minitest_to_ruby3_compatible
...
Update Minitest to allow installation with Ruby 3.
2020-09-10 18:47:01 +09:00
utilum
cac50764b8
Update Minitest to allow installation with Ruby 3.
...
9713c55362
2020-09-10 11:18:57 +02:00
Jonathan Hefner
1b58c536ab
Merge pull request from GHSA-cfjv-5498-mph5
...
Prior to this commit, when a translation key indicated that the
translation text was HTML, the value returned by `I18n.translate` would
always be marked as `html_safe`. However, the value returned by
`I18n.translate` could be an untrusted value directly from
`options[:default]`.
This commit ensures values directly from `options[:default]` are not
marked as `html_safe`.
2020-09-09 14:44:14 -04:00
Jonathan Hefner
18ded3a741
Merge pull request from GHSA-cfjv-5498-mph5
...
Prior to this commit, when a translation key indicated that the
translation text was HTML, the value returned by `I18n.translate` would
always be marked as `html_safe`. However, the value returned by
`I18n.translate` could be an untrusted value directly from
`options[:default]`.
This commit ensures values directly from `options[:default]` are not
marked as `html_safe`.
2020-09-09 14:42:25 -04:00
Jonathan Hefner
e663f08446
Merge pull request from GHSA-cfjv-5498-mph5
...
Prior to this commit, when a translation key indicated that the
translation text was HTML, the value returned by `I18n.translate` would
always be marked as `html_safe`. However, the value returned by
`I18n.translate` could be an untrusted value directly from
`options[:default]`.
This commit ensures values directly from `options[:default]` are not
marked as `html_safe`.
2020-09-09 14:41:31 -04:00
Ryuta Kamizono
5259062868
Test calculation with from
for all adapters
2020-09-09 19:37:58 +09:00
Ryuta Kamizono
f7b1582435
Add regression test for https://github.com/rails/rails/pull/40178#issuecomment-688222844
...
It is a common use case especially for MySQL users.
2020-09-09 19:26:57 +09:00
Ryuta Kamizono
d04acc0bc5
Merge pull request #40202 from KapilSachdev/fix/revert_40178
...
Revert #40178
2020-09-09 18:52:06 +09:00
John Hawthorn
10df6931de
Merge pull request #40125 from jhawthorn/actionview_test_case_isolation
...
Use a unique controller class per ActionView::TestCase
2020-09-08 14:08:13 -07:00
Isis Harris
a26b304d2f
Update translation efforts Spanish link.
2020-09-08 15:32:10 -05:00
KapilSachdev
a14f06692d
Revert "Merge pull request #40178 from tgxworld/raise_error_from_delete_all"
...
This reverts commit b8ab1f89fc3a26c83066b052b6262e8df12d1217, reversing
changes made to 73ae5655a098ef84bba77b59cde716265aa5fd0b.
2020-09-09 00:14:55 +05:30
Eugene Kenny
015c393285
Merge pull request #40194 from kddeisz/nulls-firstlast-reverse
...
Properly support `reverse_order` on relations with `nulls_first` or `nulls_last` calls
2020-09-08 16:53:18 +01:00
Kevin Deisz
4a13f8ad4f
Properly support reverse_order
on relations with nulls_first
or nulls_last
calls
...
If you're using the `nulls_first` or `nulls_last` functionality with an explicit ordering, then previously it wasn't properly handling calls to `#reverse` (called through `reverse_order`). This commit changes the behavior to match what would be expected.
2020-09-08 11:20:46 -04:00
Eugene Kenny
7af59e16a2
Use transform_values in a few more places
...
It's faster on Ruby 2.7+ since it avoids rehashing the keys.
2020-09-08 01:34:41 +01:00
Eugene Kenny
6c7d85edae
Remove checks for validate constraints support
...
These methods are PostgreSQL-specific, and all supported versions of
PostgreSQL support validating constraints.
2020-09-08 01:26:56 +01:00
Eugene Kenny
78a8188007
Merge pull request #40192 from agrobbin/postgresql-not-valid-check-constraint
...
Add support for `NOT VALID` check constraints in PostgreSQL
2020-09-08 01:08:05 +01:00
Alex Robbin
368da3ef29
add support for NOT VALID
check constraints in PostgreSQL
...
Active Record already supports adding `NOT VALID` foreign key constraints in PostgreSQL, but back in #31323 when check constraint support was initially added, the ability to add a check constraint and validate it separately was not included. This adds that functionality!
2020-09-07 19:47:22 -04:00
Eugene Kenny
b154862904
Merge pull request #40198 from jonathanhefner/anchor-backtrace-gem-filter-regexp
...
Anchor BacktraceCleaner gem filter regexp
2020-09-08 00:06:58 +01:00
Jonathan Hefner
5611f4b430
Anchor BacktraceCleaner gem filter regexp
...
This ensures the default gem filter does not affect backtrace lines that
have a subpath incidentally matching a gem path.
Fixes #40196 .
2020-09-07 16:44:57 -05:00
Muhammad Usman
580eefe1bc
Fix AR signed IDs for STI models
...
Closes #40187 .
2020-09-06 20:00:02 -04:00
Eugene Kenny
812a2c1d6c
Merge pull request #40191 from jonathanhefner/gemfile-lock-rubocop-packaging
...
Update Gemfile.lock with rubocop-packaging
2020-09-06 21:13:08 +01:00