Commit Graph

86911 Commits

Author SHA1 Message Date
Petrik
977bc53932 Use indentation for dividing sections in USAGE files
Thor, the generator USAGE files and some command USAGE files use
identation to divide the USAGE files into separate sections.
Indentation is also used to describe the options that can be passed
to the commands.

For consistency we should use the same formatting for all commands.
As Thor and most USAGE files already use identation it's a smaller
change to use identation for all commands.

For the examples extra identation is used. This makes them stand out
more allows removing the backticks which make it easier to copy the code
examples.

__Before (example for runner)__

```console
bin/rails runner --help
Commands:
  bin/rails runner [<'Some.ruby(code)'> | <filename.rb> | -]  # Run Ruby code in the context of your application
  bin/rails runner:help [COMMAND]                             # Describe available commands or one specific command

Options:
  -e, [--environment=ENVIRONMENT]  # The environment to run `runner` in (e.g. test / development / production).

Examples:

Run `puts Rails.env` after loading the app:

  bin/rails runner 'puts Rails.env'

Run the Ruby file located at `path/to/filename.rb` after loading the app:

  bin/rails runner path/to/filename.rb

Run the Ruby script read from stdin after loading the app:

  bin/rails runner -

You can also use the runner command as a shebang line for your executables:

  #!/usr/bin/env /path/to/weblog/bin/rails runner

  Product.all.each { |p| p.price *= 2 ; p.save! }
```

__After__

```console
bin/rails runner --help
Usage:
  bin/rails runner [<'Some.ruby(code)'> | <filename.rb> | -]

Options:
  -e, [--environment=ENVIRONMENT]  # The environment to run `runner` in (e.g. test / development / production).

Run Ruby code in the context of your application

Description:
    The Rails `runner` allows running Ruby code in the context of your application.

Examples:
    Run `puts Rails.env` after loading the app:

        bin/rails runner 'puts Rails.env'

    Run the Ruby file located at `path/to/filename.rb` after loading the app:

        bin/rails runner path/to/filename.rb

    Run the Ruby script read from stdin after loading the app:

        bin/rails runner -

    You can also use the runner command as a shebang line for your executables:

        #!/usr/bin/env /path/to/weblog/bin/rails runner
        Product.all.each { |p| p.price *= 2 ; p.save! }
```
2023-03-22 21:56:44 +01:00
Jean Boussier
210932662b Also undefine with on Symbol 2023-03-16 11:04:19 +00:00
Jean Boussier
a4d7ed1018
Merge pull request #47688 from Shopify/object-with-immediates
Undefine `with` on NilClass and other common immediate types
2023-03-16 10:43:45 +00:00
Jean Boussier
dc6bfecdef Undefine with on NilClass and other common immediate types
with isn't usable on immediates, so we might as well undefine the
method in common immediate classes to avoid potential confusion.
2023-03-16 10:29:54 +00:00
Jonathan Hefner
13ea2d76d0
Merge pull request #47682 from tiramizoo/non-default-env-example
Add example of simple environment config extending [ci-skip]

Co-authored-by: Hartley McGuire <skipkayhil@gmail.com>
2023-03-15 15:42:58 -05:00
Wojciech Wnętrzak
e0e7030f99
Add example of simple environment config extending
Follow up to https://github.com/rails/rails/issues/47570

[ci skip]

Update guides/source/configuring.md

Co-authored-by: Hartley McGuire <skipkayhil@gmail.com>

Update guides/source/configuring.md

Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
2023-03-15 21:23:56 +01:00
Jonathan Hefner
13dc6e76fb
Merge pull request #47685 from jonathanhefner/rely-autoload-active_model-forbidden_attributes_protection
Rely on `AM::ForbiddenAttributesProtection` autoload
2023-03-15 14:11:46 -05:00
Jonathan Hefner
9f399a6b6b Rely on AM::ForbiddenAttributesProtection autoload
`ActiveModel::ForbiddenAttributesProtection` is autoloaded, so this
`require` is not necessary.
2023-03-15 13:23:00 -05:00
Jonathan Hefner
8986050c41
Merge pull request #47683 from yskkin/patch-3
Remove redundant require: follow #10776
2023-03-15 13:16:20 -05:00
Jonathan Hefner
a51364dcf1
Merge pull request #47619 from p8/railties/thor-restart-task
Use Thor for built-in restart task
2023-03-15 11:38:07 -05:00
Matthew Draper
0dc919b544
Merge pull request #47684 from rails/revert-47493-quote_binary_strings
Revert "Quote binary strings in Arel"
2023-03-16 01:40:13 +10:30
Eileen M. Uchitelle
3b7e4134e5
Merge pull request #47664 from Shopify/support-composite-identifier-in-find
Extend `ActiveRecord::FinderMethods#find` with support for composite pk values
2023-03-15 10:57:34 -04:00
Nikita Vasilevsky
7375ff2494 Introduce ActiveRecord::PrimaryKey#composite_primary_key? abstraction
Initial implementation falls back to `primary_key.is_a?(Array)` so
it can be immediately used in place of direct `is_a?` checks.
Though implementation may be changed to rely on a pre-initialized
`@composite_primary_key` ivar in the future.
2023-03-15 13:45:23 +00:00
Nikita Vasilevsky
b05321d31a Extend ActiveRecord::FinderMethods#find with support for composite pk values
`ActiveRecord::FinderMethods#find` now supports passing sets of
composite primary key values like:

```ruby
Cpk::Book.find([1, 1])
Cpk::Book.find([[1, 1]])
Cpk::Book.find([1, 1], [1, 2])
Cpk::Book.find([[1, 1], [1, 2]])
```

and treats values as values of the composite primary key columns but
only for models with the `primary_key` being an `Array`.
2023-03-15 13:44:54 +00:00
Eileen M. Uchitelle
9527e5e307
Merge pull request #47668 from Shopify/pm/destroy-async-composite-keys
Destroying associations asynchronously respect query constraints
2023-03-15 09:18:42 -04:00
Rafael Mendonça França
74554cde8b
Merge PR #47675 2023-03-15 13:05:44 +00:00
Petrik
51c965c431 Use Thor for built-in restart task
Currently we use both Thor and Rake for `bin/rails` commands.
We eventually want to get all the built-ins task promoted to Thor Commands.
This migrates the `restart` task to Thor.

With this change it also possible to restart outside the application
directory:

```bash
blog/bin/rails restart
```

Co-authored-by: Hartley McGuire <skipkayhil@gmail.com>
Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
2023-03-15 13:09:48 +01:00
Matthew Draper
bb7f3be138
Revert "Quote binary strings in Arel" 2023-03-15 19:50:50 +10:30
Yoshiyuki Kinjo
db944ce3b2
Remove redundant require: follow #10776
active_model/forbidden_attributes_protection is not used since #10776
2023-03-15 18:16:51 +09:00
Jean Boussier
335733b858
Merge pull request #47649 from fatkodima/retry-flaky-secure_password-test 2023-03-15 08:56:39 +00:00
Yasuo Honda
7d88419227
Merge pull request #47681 from skipkayhil/fix-changelog-rubygems-version
Fix rubygems version mentioned in CHANGELOG
2023-03-15 13:36:28 +09:00
Hartley McGuire
b40c5f2512
Fix rubygems version mentioned in CHANGELOG
The version check [added][1] is for 3.3.13, but the CHANGELOG specifies
3.3.16

[1]: 7da3353b60749426aac27c6b43d589448f3a3cd0
2023-03-14 23:56:23 -04:00
Yasuo Honda
126d2169d0
Merge pull request #47655 from alpaca-tc/deferrable_exclusion_constraint
Adds support for deferrable exclude constraints in PostgreSQL.
2023-03-15 08:27:01 +09:00
Paarth Madan
a270108bf6 Destroy associations async respect query constraints
The codepaths related to destroying associations asynchronously now
consider when query constraints are present. In most cases, this means
interpreting the primary key as an array of columns, and identifying
associated records by a tuple of these columns, where previously this
would've been a single ID. In each of the callsites, we use branching.
This is done to maintain backwards compatibility and ensure the
signature of the destroy job remains stable: it has consumers outside of
Rails.
2023-03-14 19:09:09 -04:00
Andrew Novoselac
6902cbce1b Introducs TestFixtures#fixture_paths.
Multiple fixture paths can now be specified using the `#fixture_paths` accessor.
2023-03-14 19:02:56 -04:00
Jonathan Hefner
96fa75e321
Merge pull request #47663 from p8/railties/remove-unused-command-requires-in-tests
Remove unused requires in command test cases
2023-03-14 16:40:39 -05:00
Jonathan Hefner
bed48e6d8f
Merge pull request #47676 from jonathanhefner/rake_command-fix-task-arguments
Fix Rake-style task arguments for `bin/rails`
2023-03-14 16:32:33 -05:00
Jonathan Hefner
72b7a8924a Fix Rake-style task arguments for bin/rails
Follow-up to #47208.

When using Rake-style CLI arguments, `Rake::Application#top_level_tasks`
will return the full task invocation rather than the parsed task name.
For example, when running `rake foo[bar] baz[qux]`, `top_level_tasks`
will return `["foo[bar]", "baz[qux]"]` rather than `["foo", "baz"]`.
Therefore, we must extract the task name before checking existence.
2023-03-14 16:06:28 -05:00
Eileen M. Uchitelle
fdceee8d78
Merge pull request #47674 from Shopify/nodoc-valid-options
Add `nodoc` to `valid_*_options` methods
2023-03-14 15:38:42 -04:00
Hormoz Kheradmand
34d8a65969
add nodoc to valid_*_options methods 2023-03-14 12:32:58 -07:00
Rafael Mendonça França
ef4841eac8
Update link to the security announcements list 2023-03-14 17:46:06 +00:00
Eileen M. Uchitelle
c5530fd989
Merge pull request #47673 from eileencodes/pass-self-directly-for-establish-connection
Pass `self` directly to `connection_class`
2023-03-14 11:46:05 -04:00
eileencodes
0603d512dc
Pass self directly to connection_class
Returning `self` and `db_config` from `resolve_config_for_connection` is
hold over from legacy behavior when we returned `self.name` or
`Base.name` rather than just `self`. We can simplify this by passing
`self` directly` to the handlers `establish_connection`.
2023-03-14 11:26:11 -04:00
alpaca-tc
cbc7b59749 Adds support for deferrable exclude constraints in PostgreSQL.
By default, exclude constraints in PostgreSQL are checked after each statement.
This works for most use cases, but becomes a major limitation when replacing
records with overlapping ranges by using multiple statements.

```ruby
exclusion_constraint :users, "daterange(valid_from, valid_to) WITH &&", deferrable: :immediate
```

Passing `deferrable: :immediate` checks constraint after each statement,
but allows manually deferring the check using `SET CONSTRAINTS ALL DEFERRED`
within a transaction. This will cause the excludes to be checked after the transaction.

It's also possible to change the default behavior from an immediate check
(after the statement), to a deferred check (after the transaction):

```ruby
exclusion_constraint :users, "daterange(valid_from, valid_to) WITH &&", deferrable: :deferred
```

*Hiroyuki Ishii*
2023-03-14 23:29:35 +09:00
Eileen M. Uchitelle
95fe1f3a99
Merge pull request #45041 from jasonkarns/delegated-type-column
Delegated Type supports customizeable foreign_type column
2023-03-14 09:58:32 -04:00
Jason Karns
1f61fd65ae
Delegated Type supports customizeable foreign_type column 2023-03-14 09:19:30 -04:00
Petrik
4f559f7265 Remove unused requires in command test cases
If the command class isn't invoked directly we don't need to require the
class.
2023-03-14 08:53:28 +01:00
Yasuo Honda
2e81ed6d10
Merge pull request #47669 from zzak/rails-generators-gem_ruby_version
Extract gem_ruby_version from app generator
2023-03-14 14:17:24 +09:00
zzak
af4a07b4fc
Extract gem_ruby_version from app generator
Co-authored-by: Yasuo Honda <yasuo.honda@gmail.com>
Co-authored-by: David Rodríguez <deivid.rodriguez@riseup.net>
2023-03-14 13:42:57 +09:00
Yasuo Honda
ed337e637a
Merge pull request #47584 from yahonda/diag_47542
Support prerelease rubies in Gemfile template if possible
2023-03-14 12:10:14 +09:00
Jonathan Hefner
6a5f5af74f
Merge pull request #47631 from p8/railties/thor-middleware-task
Use Thor for built-in middleware task
2023-03-13 16:25:41 -05:00
Petrik
0b99cd6aaf Use Thor for built-in middleware task
Currently we use both Thor and Rake for `bin/rails` commands.
We eventually want to get all the built-in tasks promoted to Thor Commands.
This migrates the `middleware` task to Thor.
2023-03-13 22:03:16 +01:00
Jonathan Hefner
4fda95a6bb
Merge pull request #47662 from alvir/patch-1
Typo fix on create_table description [ci-skip]
2023-03-13 15:34:47 -05:00
Alexander Ryazantsev
8381a503c1
Typo fix on create_table description 2023-03-13 23:22:28 +03:00
Zack Deveau
8e3449908c Ignore certain data-* attributes in rails-ujs when element is contenteditable
There is a potential DOM based cross-site scripting issue in rails-ujs
which leverages the Clipboard API to target HTML elements that are
assigned the contenteditable attribute. This has the potential to occur
when pasting malicious HTML content from the clipboard that includes
a data-method, data-disable-with or data-remote attribute.

[CVE-2023-23913]
2023-03-13 12:13:42 -07:00
Akira Matsuda
217411564e Implement SafeBuffer#bytesplice
[CVE-2023-28120]
2023-03-13 12:13:31 -07:00
Rafael Mendonça França
a3d15ade68
Merge pull request #47644 from zzak/action-discord
Notify discord when workflows fail on main
2023-03-13 14:00:38 -04:00
Rafael Mendonça França
e64cbf75e9
Merge pull request #47597 from higher-pixels/fix-47535
Fixes 47535 - flag multiple cookies as secure
2023-03-13 13:54:08 -04:00
Eileen M. Uchitelle
deeb50f3dd
Merge pull request #47616 from szymonlipka/fix-drop-table-invert
Fix 47614 issue with inverting create_table/drop_table migration
2023-03-13 10:46:41 -04:00
Eileen M. Uchitelle
3c0569ec17
Merge pull request #47635 from Shopify/generate-composite-pk-in-fixtures
Fix fixtures id generation for composite primary keys
2023-03-13 10:26:06 -04:00