Commit Graph

84199 Commits

Author SHA1 Message Date
Yasuo Honda 1755c5ac28
Merge pull request #45474 from fatkodima/disable_extension-cascade
Avoid removing a PostgreSQL extension when there are dependent objects
2022-07-25 20:55:48 +09:00
Yasuo Honda 6dd46e180e
Merge pull request #45655 from yahonda/strscan_304
Bump strscan to 3.0.4
2022-07-25 18:01:09 +09:00
Yasuo Honda 2e8381c8b2 Bump strscan to 3.0.4
This commit addresses bug_report_templates/action_controller_gem.rb failures.

```
% ruby -v
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [arm64-darwin22]
% cd guides/bug_report_templates
% ruby action_controller_gem.rb
Fetching gem metadata from https://rubygems.org/...........
... snip ...
Using rails 7.0.3.1
/Users/yahonda/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.14/lib/bundler/runtime.rb:309:in `check_for_activated_spec!': You have already activated strscan 3.0.2, but your Gemfile requires strscan 3.0.4. Prepending `bundle exec` to your command may solve this. (Gem::LoadError)
	from /Users/yahonda/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.14/lib/bundler/runtime.rb:25:in `block in setup'
	from /Users/yahonda/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.14/lib/bundler/spec_set.rb:138:in `each'
	from /Users/yahonda/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.14/lib/bundler/spec_set.rb:138:in `each'
	from /Users/yahonda/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.14/lib/bundler/runtime.rb:24:in `map'
	from /Users/yahonda/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.14/lib/bundler/runtime.rb:24:in `setup'
	from /Users/yahonda/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.14/lib/bundler/inline.rb:71:in `block in gemfile'
	from /Users/yahonda/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.14/lib/bundler/settings.rb:131:in `temporary'
	from /Users/yahonda/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.14/lib/bundler/inline.rb:55:in `gemfile'
	from action_controller_gem.rb:5:in `<main>'
%
```

strscan 3.0.4 has been released on July 23, 2022.
https://rubygems.org/gems/strscan/versions/3.0.4

Refer to https://github.com/rails/rails/pull/45052 for the similar change.
https://github.com/rubygems/rubygems/pull/5529
https://github.com/rubygems/rubygems/pull/5535
2022-07-25 17:41:00 +09:00
Jonathan Hefner 3d0686a9f6 Document ActiveSupport::EncryptedFile#key [ci-skip] 2022-07-24 18:43:19 -05:00
Jonathan Hefner bbcf4bd3c6
Merge pull request #45652 from skipkayhil/test-for-system-test-update
Test skip_system_test being preserved after update
2022-07-24 16:51:44 -05:00
Hartley McGuire 3b667adcdf
Test skip_system_test being preserved after update
Followup to 37d0516

Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
2022-07-24 17:34:40 -04:00
Jonathan Hefner 76b0ef8d00
Merge pull request #45647 from skipkayhil/rm-redundant-updating-option
Remove duplicate 'updating' option from generator
2022-07-24 11:04:37 -05:00
Jonathan Hefner 7548d76bdc
Merge pull request #45648 from skipkayhil/fix-skip-system-test-update
Fix skip_system_test not being preserved in update
2022-07-23 21:13:44 -05:00
Jonathan Hefner 88921001ef
Merge pull request #45649 from skipkayhil/fix-extra-setup-newline
Fix extra line added to bin/setup in app:update
2022-07-23 21:00:50 -05:00
Hartley McGuire f99f04a0c1
Fix extra line added to bin/setup in app:update
155b757 added some yarn commands to bin/setup for apps that are using
Node. However, the blank line between the added block and the
skip_active_record block results in an extraneous blank line added to
apps when running app:update.
2022-07-23 16:44:44 -04:00
Hartley McGuire 37d051612d
Fix skip_system_test not being preserved in update
Previously running app:update always would template an application.rb
file without the `config.generators.system_tests = nil` set, even for
applications that previously had it set.
2022-07-23 16:23:07 -04:00
Hartley McGuire 7fe640b8ca
Remove duplicate 'updating' option from generator
:update has been defined since a7adec9, and both options serve the same
purpose
2022-07-23 16:08:11 -04:00
Gannon McGibbon 97f13c2b82
Merge pull request #45627 from gmcgibbon/controller_generator_improvements
Controller generator improvements
2022-07-22 14:23:00 -05:00
fatkodima 515a9215d1 Avoid removing a PostgreSQL extension when there are dependent objects 2022-07-22 15:17:18 +03:00
Jonathan Hefner 789a3648f3
Merge pull request #45619 from pbstriker38/add_skip_nil_to_fetch_multi
Add `skip_nil:` support to `ActiveSupport::Cache::Store#fetch_multi`
2022-07-21 10:33:34 -05:00
Jonathan Hefner aced3bb07b
Merge pull request #45569 from whyinzoo/whyinzoo-update-docs-ActiveSupport--Notification-monotonic-subscribe-for-pr
Add docs for ActiveSupport::Notifications.monotonic_subscribe [ci-skip]
2022-07-21 10:24:06 -05:00
Jean Boussier 17fd2edafb
Merge pull request #45618 from sambostock/active-job-big-decimal-serialization
Fix `BigDecimal `(de)serialization for `JSON` adapters
2022-07-21 15:58:28 +02:00
Ryan Zhou e3de7872b1 better docs for ActiveSupport::Notifications.monotonic_subscribe 2022-07-21 03:20:33 +00:00
Gannon McGibbon aaeffb2a56 Add --parent option to controller generator to specify parent class of controller.
Example:

`bin/rails g controller admin/users --parent=admin_controller` generates:

```ruby
class Admin::UsersController < AdminController
  # ...
end
```
2022-07-20 19:20:00 -05:00
Daniel Alfaro 1344031d7e Add `skip_nil:` support to `ActiveSupport::Cache::Store#fetch_multi` 2022-07-20 17:02:25 -05:00
Eileen M. Uchitelle 69078b0820
Merge pull request #45625 from adrianna-chang-shopify/ac-extract-build-create-table-definition
Extract `#build_create_table_definition` method
2022-07-20 09:25:05 -04:00
John Hawthorn b5a758db1b
Avoid checking defined?(@html_safe) (#45620)
We should not need to check defined? here because we are only interested
in whether @html_safe is truthy or falsy.

We can  use an aliased attr_reader to make this even faster by skipping
both method dispatch.

Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
2022-07-19 15:16:21 -07:00
Gannon McGibbon bf4858722c Add more detailed description to controller generator
- Arguments are actions, not views
- URLs are routes
- Adds example for --skip-routes option
2022-07-19 16:13:42 -05:00
Sam Bostock bc1f323338
Add ActiveJob::Serializers::BigDecimalSerializer
Previously, BigDecimal was listed as not needing a serializer.  However,
when used with an adapter storing the job arguments as JSON, it would get
serialized as a simple String, resulting in deserialization also producing
a String (instead of a BigDecimal).

By using a serializer, we ensure the round trip is safe.

During upgrade deployments of applications with multiple replicas making use of
BigDecimal job arguments with a queue adapter serializing to JSON, there exists
a possible race condition, whereby a "new" replica enqueues a job with an
argument serialized using `BigDecimalSerializer`, and an "old" replica fails to
deserialize it (as it does not have `BigDecimalSerializer`).

Therefore, to ensure safe upgrades, serialization will not use
`BigDecimalSerializer` until `config.active_job.use_big_decimal_serializer` is
enabled, which can be done safely after successful deployment of Rails 7.1.

This option will be removed in Rails 7.2, when it will become the default.
2022-07-19 15:31:41 -04:00
Jean Boussier 06e9fbd954
Merge pull request #45614 from Shopify/faster-output-buffer
Speedup ActionView::OutputBuffer
2022-07-19 21:08:49 +02:00
Jean Boussier 71c59c69f4
Merge pull request #44010 from siegfault/dangerous_query_method_allow_nested_functions
Accept nested functions in Dangerous Query Methods
2022-07-19 21:04:15 +02:00
Sam Bostock b48b196910
Consolidate active_record 7.1 default loading
There appears to be no reason for these configs to be separate, and it makes
sense to group by framework.
2022-07-19 14:43:29 -04:00
Adrianna Chang d747b0f132 Define #build_create_table_definition on connection adapter
Define API on connection adapter for building a TableDefinition.
The provided TableDefinition object offers insight into what a table
created using the migration method #create_table would look like, including
information on primary keys, column types, etc.

As a part of this PR, we extract TableDefinition#set_primary_key to handle
some of the primary key setting logic currently being performed in #create_table.
2022-07-19 14:22:54 -04:00
Eileen M. Uchitelle fa7f977e2d
Merge pull request #45626 from eileencodes/remove-duplicate-code-in-rake-tasks
Remove duplicate code in dump task
2022-07-19 13:13:49 -04:00
Jonathan Hefner 166db2f2f6
Merge pull request #45574 from jonathanhefner/credentials-omit-secret_key_base-in-dev-and-test
Omit `secret_key_base` for dev and test credentials
2022-07-19 11:48:12 -05:00
eileencodes 31ab9cfe15
Remove duplicate code in dump task
The `_dump` task is private so it shouldn't be called by apps. Because
of this were establishing a connection to the db_config twice, once in
`_dump` and once in `dump`. There's no reason to do this since `_dump`
always calls `dump` and apps should not be calling `_dump`.
2022-07-19 12:42:30 -04:00
Yasuo Honda f07d080c00
Merge pull request #44760 from lxxxvi/fix_rails_issue_db_fixtures_load_raises
`db:fixtures:load` raises in Postgres if there are foreign key constraints in a non-`public` schema
2022-07-20 01:21:54 +09:00
mario e3bb10d0c3 prefix table_schema to `ALTER TABLE ... VALIDATE CONSTRAINT` for postgres
In Postgres there was an issue when calling `ActiveRecord::ConnectionAdapters::PostgreSQL::ReferentialIntegrity#all_foreign_keys_valid?` if there were multiple schemas with foreign key constraints, because the ALTER TABLE statement did not include the schema.

This commit adds the necessary schema prefix

```
ALTER TABLE [schema].[table_name] VALIDATE CONSTRAINT [constraint]
             ^^^^^^
```
2022-07-19 17:56:22 +02:00
Eileen M. Uchitelle 4ab6927b98
Merge pull request #45098 from richardboehme/active_storage-named-previews
Allow to use pre-defined variants for previews
2022-07-19 11:45:32 -04:00
Jonathan Hefner 9e0fe8e8bc
Merge pull request #45615 from jtmalinowski/fix-server-timing-overwrites
Prevent ActionDispatch::ServerTiming from overwriting existing header value
2022-07-19 10:33:43 -05:00
Richard Böhme acf767dbd6 Allow to use pre-defined variants for previews
Previously, named variants could only be used when calling the
`variant` method on an attachment. For files that are not `variable?`
but `previewable?` those pre-defined variants could not be used.

With this patch, the methods `preview` and `representation` also allow
to be passed a variation name as a symbol.

    class User < ActiveRecord::Base
      has_one_attached :file do |attachable|
        attachable.variant :thumb, resize_to_limit: [100, 100]
      end
    end

    <%= image_tag user.file.representation(:thumb) %>
2022-07-19 16:59:52 +02:00
Eileen M. Uchitelle bb68040de4
Merge pull request #45621 from eileencodes/fix-granular-swapping-for-primary_abstract_class
Fix granular swapping for primary_abstract_class
2022-07-19 09:54:43 -04:00
eileencodes 741d029606
Fix granular swapping for primary_abstract_class
In #45450 we stopped removing connections when establish_connection was
called and an identical connection existed in the pool. Unfortunately
this broke granular connection swapping for the primary_abstract_class
because the class stored in the pool was incorrect.

What was happening was connection for the writing role were getting
stored with the class ActiveRecord::Base and connections for the reading
role were getting ApplicationRecord (or whatever the app set as their
`primary_abstract_class`. If we made sure that the reading connections
also got ActiveRecord::Base that would break granular swapping for both
writing and reading because Active Record doesn't know whether you
wanted global swapping or granular swapping for prevent writes. This bug
only manifests on prevent writes because it's the only value we actually
lookup on the connection pool (because at the point we need it we don't
have access to self).

To fix this I've decided to update the class on the existing pool if it
doesn't match the owner_name passed. This is kind of gross I admit, but
it's safe because the way we find connections is on the
`connection_name`. The class is only stored so that the connection can
find it's `current_preventing_writes` value. This also required me to
move the ivar to an instance method for connection_class on the pool
because we don't want to cache the value and want to make sure we're
getting it from the pool config directly.
2022-07-19 08:22:35 -04:00
Eileen M. Uchitelle a731c929c7
Merge pull request #45624 from sambostock/clear-job-buffer-on-teardown
Clear `JobBuffer` on `ActiveJob` test teardown
2022-07-19 08:22:01 -04:00
Jean Boussier 4e8e828291 Speedup ActionView::OutputBuffer
MRI has a lot of optimizations for string concatenation that
are only available when concatenating into a `String` instance.

Using a `String` subclass disable these optimizations.

The difference is even more important with YJIT.

So ideally we want the buffer not to be a String subclass.
Luckily, the Action View buffer is for internal use only, so
we can replace inheritance by composition without much work.

Benchmark:

```
ActionView::OutputBuffer:   147644.2 i/s
    optimized buffer:   228001.4 i/s - 1.54x  (± 0.00) faster
```

Source: https://gist.github.com/casperisfine/7199579a138e268fda71d6a91366af49

NB: That 50% faster figure is to be contextualized, it can radically change
from one template to the other, but is always faster.
2022-07-19 12:13:34 +02:00
Yasuo Honda 9596ec94ea
Merge pull request #45623 from fatkodima/fix-in_order_of-mysql-strings
Fix `QueryMethods#in_order_of` for non-integer columns in MySQL
2022-07-19 16:46:19 +09:00
Sam Bostock eb4b540368
Clear JobBuffer on teardown
ActiveJob tests should be able to rely on a clean JobBuffer in each test.
2022-07-18 23:33:07 -04:00
fatkodima c5ef2f4fb9 Fix `QueryMethods#in_order_of` for non-integer columns in MySQL 2022-07-19 02:24:58 +03:00
Jakub Malinowski f075e0cf06
Prevent ActionDispatch::ServerTiming from overwriting existing header 2022-07-18 20:51:10 +02:00
Jonathan Hefner 4e9fee9629
Merge pull request #45570 from whyinzoo/whyinzoo-update-docs-ActiveSupport--EncryptedFile-read-for-pr
Add docs for ActiveSupport::EncryptedFile#read [ci-skip]
2022-07-18 11:16:44 -05:00
Jonathan Hefner bc0f07b93c
Merge pull request #45617 from ajporterfield/add-beginless-range-example-to-ar-querying-guide
Add endless range example to the Active Record Querying guide [ci-skip]
2022-07-18 11:11:44 -05:00
Andrew Porterfield 504887cff5 Add endless range example to the Active Record Querying guide 2022-07-18 10:43:03 -04:00
Yuta Uchida a16c7c722e
Added default values to raise_delivery_errors guide (#45616) 2022-07-18 19:42:46 +05:30
Ryan Zhou d64367e765 better docs for ActiveSupport::EncryptedFile#read 2022-07-16 04:04:42 +00:00
Jonathan Hefner 9994d38bc6
Merge pull request #45572 from fatkodima/fix-cached-missing-translations
Fix caching of missed translations
2022-07-15 15:06:29 -05:00