Commit Graph

90684 Commits

Author SHA1 Message Date
Jean Boussier bffe05f246 Module#delegate stop accepting the private `as:` parameter
The feature remains usable internally, but via `ActiveSupport::Delegation`,
this way we don't allow third party use.
2024-01-25 11:51:00 +01:00
Jean Boussier 6ee0041ed2 Refactor `Module#delegate` inside ActiveSupport::Delegation
This allow to support some extra private features without exposing
them in `Module#delegate`.
2024-01-25 11:51:00 +01:00
Jean Boussier ddc32f5a47 Use an anonymous block parameter in Module#delegate
`...` generates an anonymous block, it's basically a shortcut
for `*, **, &`. So to look more similar to tools that introspect
method signatures, it's best to continue to use an anonymous block.
2024-01-25 09:16:21 +01:00
Hartley McGuire 0041af4c94
Ensure all RubyTracker RenderParsers are tested
Previously, only the PrismRenderParser or RipperRenderParser would be
tested depending on if the Prism gem is available. This meant that
PrismRenderParser was being tested on Ruby 3.3 and RipperRenderParser
was tested on Ruby < 3.3. Additionally, if someone were to add prism to
the rails/rails Gemfile because they wrote a tool that uses it then the
RipperRenderParser would end up completely untested.

This commit is a small refactor to enable testing both RenderParsers in
all Ruby versions so that the prism gem can be added to the Gemfile.
2024-01-24 19:16:59 -05:00
Hartley McGuire 1ecac5b8d3
./tools/rdoc-to-md --only=actiontext -a 2024-01-24 19:08:44 -05:00
Hartley McGuire 195d80199f
Add tools/rdoc-to-md script
Generally the idea is:
- use Prism to parse the file into AST + Comments
- transform each comment block into plain RDoc (instead of RDoc in a
  comment)
- use RDoc's ToMarkdown class to get a Markdown representation of the
  comment
- transform the Markdown representation back into a comment
- write a new file, skipping the lines that were previously RDoc
  comments and instead inserting the new Markdown comments

A little extra work has to be down for metaprogrammed documentation
because ToMarkdown turns RDoc directives into H1s. So for these cases,
the directive is first split off the top before doing the ToMarkdown
transformation and then added back afterwards.
2024-01-24 19:00:32 -05:00
Nikita Vasilevsky 605d910194
Fix eager loading of composite primary key associations
Co-Authored-By: Christine Belan <christine.belan@shopify.com>
2024-01-24 17:25:03 +00:00
Petrik de Heus c7551d08fc
Merge pull request #50836 from p8/activerecord/fix-query-logs-rdoc
Specify RDoc method name for accessors defined on singleton_class [ci-skip]
2024-01-24 13:03:43 +01:00
Jean Boussier 2af2b222d4
Merge pull request #50855 from Shopify/update-console-prompt-color
Display dev & test env in console prompt in blue instead of green
2024-01-24 12:55:21 +01:00
Joshua Young 9691cf675f Add section on Queue Priority to `ActiveJob` docs 2024-01-24 21:28:23 +10:00
Stan Lo 7cbf06c1e8
Display dev/test env in console prompt in blue instead of green
The combination of red and blue is more color-blind friendly than red
and green.

Discussion: https://github.com/rails/rails/pull/50796#discussion_r1463670198
2024-01-24 11:07:40 +00:00
Stan Lo 0ea9748ba6
Fix prompt colorization test's setup 2024-01-24 11:07:40 +00:00
Aaron Patterson 80bce4aad3
Merge pull request #50859 from rails/no-row-mutation
Don't mutate row arrays that come back from the database adapter
2024-01-23 16:49:08 -08:00
Aaron Patterson 84130af8b5
Don't mutate row arrays that come back from the database adapter
In SQLite3-Ruby version 2.0, I would like to make row arrays frozen. I
tested the change, and it only breaks this test, so I'm changing the
test. I don't think we should be mutating the objects that the database
adapter returns
2024-01-23 16:33:04 -08:00
John Hawthorn bb0e59b42d
Merge pull request #50202 from composerinteralia/trilogy-syscallerror-translate
Translate Trilogy syscall errors as conn failed
2024-01-23 15:25:09 -08:00
Daniel Colson 6616770ec9
Translate Trilogy syscall errors as conn failed
At GitHub we get a fair number of Trilogy `ETIMEDOUT` errors (for known
reasons that we might be able to improve somewhat, but I doubt we'll
make them go away entirely). These are very much retryable network
errors, so it'd be handy if these `ETIMEDOUT` errors were translated to
`ConnectionFailed` instead of `StatementInvalid`, making them
`retryable_connection_error`s.

ed2bc92b82/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb (L1077)

We're already translating `ECONNRESET` (via matching on the error
message) and `EPIPE` to `ConnectionFailed`. Rather than adding another
case, this commit treats all of the Trilogy `SystemCallError` subclasses
as `ConnectionFailed`.

This requires bumping trilogy 2.7 so we can get
https://github.com/trilogy-libraries/trilogy/pull/143
2024-01-23 16:20:02 -05:00
Anup Narkhede 776626ff98
Fix rotation detection for HDR videos (#50854)
Fixes https://github.com/rails/rails/issues/50853

The video analyzer was relying on the positional reference of the Display
Matrix side_data to fetch the rotation value. However, the side_data is
not guaranteed to be in the same position. For instance, HDR videos shot
on iOS have "DOVI configuration record" side_data in the first position,
followed by the "Display Matrix" side data containing the rotation value.

This fix removes the positional reference and explicitely searches for
the "Display Matrix" side_data to retrieve the rotation angle.
2024-01-23 11:28:11 -08:00
notapatch addf281ddc Update Guides: AR querying english text to match code behavior
The code: Book.joins(:author, :reviews)

This code will return books that have an author and at least 1
review.

English text implies it returns the book and the author:

"return all books with their author .."

Changing the text to imply it returns books with an author.
2024-01-23 13:01:18 +00:00
Rafael Mendonça França ee88f4133f
Merge pull request #50843 from p8/upgrade/sdoc-e9bb86
Upgrade to latest SDoc for performance
2024-01-22 17:08:01 -05:00
Petrik 0797273427 Upgrade to latest SDoc for performance
The latest version of SDoc fixes a performance regression.
This version is at least twice as fast.
https://github.com/rails/sdoc/pull/363
2024-01-22 19:43:03 +01:00
Petrik db6eb7b72c Specify singleton method name for accessors defined on singleton_class [ci-skip]
RDoc can't extract the name of accessors defined with
`singleton_class.attr_accessor`, resulting in methods called `unknown`
in RDoc.
2024-01-22 12:34:07 +01:00
Petrik de Heus fe81d667a7
Merge pull request #50789 from p8/docs/relative-includes
Use relative includes of README's in documentation [ci-skip]
2024-01-21 18:30:07 +01:00
Jean Boussier 1faf89f559
Merge pull request #50284 from seanpdoyle/close-49574
Infer `:inverse_of` for `has_many ..., through:`
2024-01-21 17:21:49 +01:00
Sean Doyle 68013b30d2 Infer `:inverse_of` for `has_many ..., through:`
Closes [#49574][]

Issue #49574 outlines how an Active Record join model accessed through a
`has_many ..., through:` association is unable to infer an appropriate
`:inverse_of` association by pluralizing a predictably pluralizable
class name.

This commit resolves that issue by also checking a model's reflections
for a pluralized inverse name in addition to whatever's provided through
the `:as` option or inferred in the singular.

The issue shares a code sample:

```ruby
ActiveRecord::Schema.define do
  create_table "listings", force: :cascade do |t|
    t.bigint "list_id", null: false
    t.bigint "pin_id", null: false
  end

  create_table "lists", force: :cascade do |t|
  end

  create_table "pins", force: :cascade do |t|
  end
end

class Pin < ActiveRecord::Base
  has_many :listings
end

class List < ActiveRecord::Base
  has_many :listings
  has_many :pins, through: :listings
end

class Listing < ActiveRecord::Base
  belongs_to :list
  belongs_to :pin
end

class BugTest < Minitest::Test
  def test_association_stuff
    list = List.create!
    pin = list.pins.new

    pin.save!

    assert_equal [pin], list.reload.pins
    assert_equal 1, list.reload.pins.count
  end
end
```

Unfortunately, there isn't a one-to-one mapping in the test suite's
`test/model` directory for this type of structure. The most similar
associations were between the `Book`, `Subscription`, and `Subscriber`.
For the sake of ease, this commit wraps the test block in a new
`skipping_validations_for` helper method to ignore validations declared
on the `Subscription` join table model.

[#49574]: https://github.com/rails/rails/issues/49574
2024-01-21 10:25:46 -05:00
Jean Boussier 310bb2abdb
Merge pull request #50800 from Edouard-chin/ec-inverseof-blob
Fix ActiveStorage::Blob inverse association:
2024-01-21 09:17:05 +01:00
Jean Boussier 9f52c45b18
Merge pull request #50308 from fatkodima/refactor-loaded-batches
Small refactoring of batching over loaded relation
2024-01-21 09:13:43 +01:00
Jean Boussier 3064d4f53a
Merge pull request #50825 from Shopify/update-rails-console-prompt
Update rails console prompt
2024-01-21 00:36:25 +01:00
Stan Lo 09b2aecec5
Change Rails console prompt's format
Following the discussion in #50770, the new format will be:
`[dasherized-app-name]([colorized-env])>`

For example, if the app's module name is `MyApp`, the prompt will be:
`my-app(dev)>`, where the `dev` part will be colored.

Update railties/lib/rails/commands/console/console_command.rb

Co-authored-by: Jean Boussier <jean.boussier@gmail.com>

Update changelog
2024-01-20 23:34:33 +00:00
Petrik de Heus f84b428efb
Merge pull request #50822 from kylevoyto/patch-1
Fix the CreateProducts migration file name in the docs [ci-skip]
2024-01-20 18:15:59 +01:00
Kyle Voytovich 458f2c1c45
Fix the CreateProducts migration file name in the docs 2024-01-20 10:12:23 -05:00
Jean Boussier fcab061839
Merge pull request #50814 from Shopify/improve-rails-console
Improve Rails console's IRB autocompletion control
2024-01-20 15:01:14 +01:00
Stan Lo 4d6714fcd3
Remove unnecessary nocolorize flag
Setting `TERM=dumb` is enough to disable colorization in those tests.

Mocked app should also load console helpers

Move console method extension to IRBConsole's constructor

Test IRB autocompletion control without mutating ENV

Control IRB autocompletion without mutating ENV

Correct local variable name
2024-01-20 11:45:52 +00:00
Petrik de Heus 93b83f9b96
Merge pull request #50819 from tanaken0515/patch-1
[ci skip] docs: fix `Entry#entryable_types` to `Entry.entryable_types`
2024-01-20 10:25:14 +01:00
tanaken0515 024d0abdec
fix: `Entry#entryable_types` to `Entry.entryable_types` 2024-01-20 16:26:01 +09:00
Jean Boussier 30cb7a6221
Merge pull request #50796 from Shopify/implement-#50770
Add customized prompt for Rails console
2024-01-19 20:11:51 +01:00
Stan Lo 0c2898a768
Create IRBConsole to encapsulate IRB-specific setup
Add Rails-specific IRB prompt

Update changelog
2024-01-19 19:01:26 +00:00
Edouard Chin 21eceb7db2
Merge pull request #50808 from m-nakamura145/actionpack/modules_for_helpers-example
Add example to modules_for_helpers documentation [ci-skip]
2024-01-19 16:59:37 +01:00
m-nakamura145 930649598f
Add example to modules_for_helpers documentation [ci-skip] 2024-01-20 00:48:59 +09:00
Jean Boussier 2ddbca3e6a
Merge pull request #50809 from Shopify/freeze-cached-strings
Freeze and dedup `quote_column_name` and `quote_table_name` caches
2024-01-19 15:23:55 +01:00
Petrik de Heus 25d03be267
Merge pull request #50810 from m-nakamura145/activesupport/duration-parts-example
Add example to parts documentation [ci-skip]
2024-01-19 15:10:24 +01:00
m-nakamura145 a5af0a9118
Add example to parts documentation [ci-skip] 2024-01-19 22:05:59 +09:00
Jean Boussier 44ef49c2d0
Merge pull request #50804 from joshuay03/consistently-raise-an-error-for-nested-attributes-args
[Fix #50803] Consistently raise an `ArgumentError` when passing an invalid argument to a nested attributes association writer
2024-01-19 13:29:01 +01:00
Jean Boussier 9d4a44d049 Freeze and dedup `quote_column_name` and `quote_table_name` caches
Avoid corrupting the cache by mutating the return value, and also
sligthly reduce memory usage when the quoting format often return
an unmodified string.
2024-01-19 12:42:02 +01:00
Joshua Young 1eab83a0a8 [Fix #50803] Consistently raise an `ArgumentError` when passing an invalid argument to a nested attributes association writer 2024-01-19 20:34:33 +10:00
Arn van der Pluijm f3de8b698d
Update guides/source/command_line.md
Co-authored-by: Petrik de Heus <petrik@deheus.net>
2024-01-19 11:18:04 +01:00
Edouard CHIN 82d4ad5da3 Fix ActiveStorage::Blob inverse association:
- This is a fix needed to unblock
  https://github.com/rails/rails/pull/50284,
  because Active Storage relies on a Active Record bug.

  The problem is best understood with a small snippet:

  ```
    blob = ActiveStorage::Blob.new

    ActiveStorage::Attachment.new(blob: blob)
    ActiveStorage::Attachment.new(blob: blob)

    # Currently:
    p blob.attachments #=> #<ActiveRecord::Associations::CollectionProxy []>

    # Once the Active Record bug is fixed:
    p blob.attachments #=> #<ActiveRecord::Associations::CollectionProxy [#<ActiveStorage::Attachment id: nil, name: nil, record_type: nil, record_id: nil, blob_id: nil, created_at: nil>, #<ActiveStorage::Attachment id: nil, name: nil, record_type: nil, record_id: nil, blob_id: nil, created_at: nil>]>

    # Trying to save the blob would result in trying to create 2 attachments which
    # fails because of unique constrainsts.
  ```

  ### Code path

  The real code path that does what the snippet above does is located here:

  9c3ffab47c/activestorage/lib/active_storage/attached/many.rb (L52)

  It's basically doing this:

  ```
    user.images.attach "photo1.png"
    # Initialize a Blob record and an Attachment

    user.images.attach "photo2.png"
    # Get the Blob from above, create another Attachment
    # Initialize a new Blob record and an new Attachment

    # rinse and repeat every time `attach` is called
  ```

  Basically each time we call `attach`, we grab the previous blobs that were attached
  (and that already have an Attachment record), and

  ### Solution

  - Explicitly set the `inverse_of`, so that it behaves as if #50284 is shipped
  - Don't build a new attachment for blob already having one.

  ### Tests

  I didn't add tests, the test suite is already well covered, adding the `inverse_of`
  without any changes breaks the test suite already. You can try by running
  for instance the `activestorage/test/models/attached/many_test.rb`.
2024-01-19 04:18:15 +01:00
Jonathan Hefner 9c3ffab47c Fix RateLimitingTest assertion for :by option
Follow-up to #50788.

This test wasn't actually asserting that the `:by` option worked.
2024-01-18 18:43:43 -06:00
Jonathan Hefner c8bfd6870d
Merge pull request #50799 from jonathanhefner/command-fix-task-list-when-no-default-task
Fix `bin/rails -T` when no default task is defined
2024-01-18 18:43:18 -06:00
Eugene Kenny 36cc7c560b Remove unsupported values for config.action_dispatch.show_exceptions [ci skip]
Support for `true` and `false` was removed in
ec2c2666c2.
2024-01-19 00:21:26 +00:00
Jonathan Hefner f21e4299d6 Fix `bin/rails -T` when no default task is defined
When Rake parses an argument string with no tasks, it sets the top-level
task as "default".  Prior to this commit, if no default task was defined
(for example, if an app was generated with `--skip-test` and didn't
define its own default task), `Rails::Command::RakeCommand` would raise
`UnrecognizedCommandError`, preventing Rake from displaying the task
list.

This commit changes `Rails::Command::RakeCommand` to let Rake handle the
"default" task.

Fixes #50700.
2024-01-18 18:10:44 -06:00