Commit Graph

90999 Commits

Author SHA1 Message Date
Carlos Antonio da Silva
d514a31eed Remove WIP from Action Mailbox & Action Text guides [ci skip]
These have been reviewed recently by the Rails Foundation team working
on the guides:

Action Mailbox: https://github.com/rails/rails/pull/50973
Action Text: https://github.com/rails/rails/pull/50977
2024-03-05 11:48:06 -03:00
Yasuo Honda
917b6b2908
Merge pull request #51252 from yahonda/diag_247
Add missing :author_addresses in `OrderTest`
2024-03-05 14:58:52 +09:00
Yasuo Honda
3a7d96c485 Add missing :author_addresses in OrderTest
This commit addresses this CI failure https://buildkite.com/rails/rails-nightly/builds/247#018e0bea-7a88-45eb-94fa-be4155aeeeca/1164-1173

- Error without this commit
```ruby
$ bin/test test/cases/relation/order_test.rb test/cases/fixtures_test.rb -n "/^(?:OrderTest#(?:test_order_desc)|FixturesWithForeignKeyViolationsTest#(?:test_does_not_raise_if_no_fk_violations))$/" --seed 31115
Using sqlite3
Run options: -n "/^(?:OrderTest#(?:test_order_desc)|FixturesWithForeignKeyViolationsTest#(?:test_does_not_raise_if_no_fk_violations))$/" --seed 31115

.E

Error:
FixturesWithForeignKeyViolationsTest#test_does_not_raise_if_no_fk_violations:
RuntimeError: Foreign key violations found in your fixture data. Ensure you aren't referring to labels that don't exist on associations. Error from database:

Foreign key violations found: authors, authors, authors
    lib/active_record/fixtures.rb:704:in `rescue in check_all_foreign_keys_valid!'
    lib/active_record/fixtures.rb:701:in `check_all_foreign_keys_valid!'
    lib/active_record/fixtures.rb:688:in `block (2 levels) in insert'
    lib/active_record/connection_adapters/abstract/connection_pool.rb:384:in `with_connection'
    lib/active_record/fixtures.rb:685:in `block in insert'
    lib/active_record/fixtures.rb:676:in `each'
    lib/active_record/fixtures.rb:676:in `insert'
    lib/active_record/fixtures.rb:662:in `read_and_insert'
    lib/active_record/fixtures.rb:607:in `create_fixtures'
    test/cases/fixtures_test.rb:893:in `block (2 levels) in test_does_not_raise_if_no_fk_violations'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/testing/assertions.rb:49:in `assert_nothing_raised'
    test/cases/fixtures_test.rb:892:in `block in test_does_not_raise_if_no_fk_violations'
    test/cases/fixtures_test.rb:906:in `with_verify_foreign_keys_for_fixtures'
    test/cases/fixtures_test.rb:891:in `test_does_not_raise_if_no_fk_violations'

bin/test test/cases/fixtures_test.rb:884

Finished in 0.084771s, 23.5930 runs/s, 94.3720 assertions/s.
2 runs, 8 assertions, 0 failures, 1 errors, 0 skips
$
```

Refer to #43873 that has the same reason why it gets error.
2024-03-05 14:23:20 +09:00
Yasuo Honda
db30dd6fe7
Merge pull request #51240 from yahonda/follow_up_51204
Use `ActiveRecord::Base.lease_connection` for uncached dirties tests
2024-03-04 08:39:52 +09:00
Yasuo Honda
a556be5ddc Use ActiveRecord::Base.lease_connection for uncached dirties tests
This commit addresses these errors since #51192 renames `.connection` into `.lease_connection`

Follow up #51204

```ruby
$ cd activerecord
$ bin/test test/cases/query_cache_test.rb -n /uncached_dirties/
Using sqlite3
Run options: -n /uncached_dirties/ --seed 57207

E

Error:
QueryCacheTest#test_query_cache_uncached_dirties:
NoMethodError: undefined method `connection' for class ActiveRecord::Base
    lib/active_record/dynamic_matchers.rb:22:in `method_missing'
    test/cases/query_cache_test.rb:712:in `block (2 levels) in test_query_cache_uncached_dirties'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/testing/assertions.rb:241:in `assert_no_changes'
    test/cases/query_cache_test.rb:712:in `block in test_query_cache_uncached_dirties'
    test/cases/query_cache_test.rb:771:in `block (2 levels) in middleware'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/execution_wrapper.rb:91:in `wrap'
    test/cases/query_cache_test.rb:771:in `block in middleware'
    test/cases/query_cache_test.rb:720:in `test_query_cache_uncached_dirties'

bin/test test/cases/query_cache_test.rb:709

E

Error:
QueryCacheTest#test_query_cache_connection_uncached_dirties:
NoMethodError: undefined method `connection' for class ActiveRecord::Base
    lib/active_record/dynamic_matchers.rb:22:in `method_missing'
    test/cases/query_cache_test.rb:726:in `block (2 levels) in test_query_cache_connection_uncached_dirties'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/testing/assertions.rb:241:in `assert_no_changes'
    test/cases/query_cache_test.rb:726:in `block in test_query_cache_connection_uncached_dirties'
    test/cases/query_cache_test.rb:771:in `block (2 levels) in middleware'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/execution_wrapper.rb:91:in `wrap'
    test/cases/query_cache_test.rb:771:in `block in middleware'
    test/cases/query_cache_test.rb:734:in `test_query_cache_connection_uncached_dirties'

bin/test test/cases/query_cache_test.rb:723

E

Error:
QueryCacheTest#test_query_cache_uncached_dirties_disabled_with_nested_cache:
NoMethodError: undefined method `connection' for class ActiveRecord::Base
    lib/active_record/dynamic_matchers.rb:22:in `method_missing'
    test/cases/query_cache_test.rb:740:in `block (2 levels) in test_query_cache_uncached_dirties_disabled_with_nested_cache'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/testing/assertions.rb:194:in `assert_changes'
    test/cases/query_cache_test.rb:740:in `block in test_query_cache_uncached_dirties_disabled_with_nested_cache'
    test/cases/query_cache_test.rb:771:in `block (2 levels) in middleware'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/execution_wrapper.rb:91:in `wrap'
    test/cases/query_cache_test.rb:771:in `block in middleware'
    test/cases/query_cache_test.rb:757:in `test_query_cache_uncached_dirties_disabled_with_nested_cache'

bin/test test/cases/query_cache_test.rb:737

Finished in 0.134429s, 22.3166 runs/s, 0.0000 assertions/s.
3 runs, 0 assertions, 0 failures, 3 errors, 0 skips
$
```
2024-03-03 23:37:54 +09:00
Donal McBreen
5d528ba0c8
Add dirties option to uncached (#51204)
This adds a `dirties` option to `ActiveRecord::Base.uncached` and
`ActiveRecord::ConnectionAdapters::ConnectionPool#uncached`.

Setting `dirties` to `false`, means database writes to the connection
pool will not mark any query caches as dirty.

The option defaults to `true` which retains the existing behaviour and
clears query caches on all connection pools used by the current thread.

Co-authored-by: Jeremy Daer <jeremy@rubyonrails.org>
2024-03-02 19:01:24 -08:00
Jeremy Daer
5cedb8745c Illustrator files are previewable with Poppler as well
Extends #51235's MuPDF support to Poppler.

Add test coverage for Blob previews and representation.
2024-03-01 13:04:27 -08:00
Jeremy Daer
bf8e0f5f61 Illustrator .ai files are previewable as PDFs
This happened to work with Marcel 1.0.2 and earlier since magic byte
sniffing sees that Illustrator files are PDFs internally, causing these
files to be treated as `application/pdf` despite having a declared
content type of `application/illustrator` and an `.ai` file extension.

Marcel 1.0.3 corrected this to the more specific `application/illustrator`
subtype of `application/pdf`, but the MuPDF previewer only accepts the
parent `application/pdf` type.

Changing it to accept PDF and any child types allows the previewer to
explicitly work with Illustrator files again, which was only a happy
accident previously.
2024-03-01 10:55:48 -08:00
Jeremy Daer
4f0f3448cd Marcel 1.0.4
Update tests to clarify content type detection heuristic after exposing
a regression in Marcel 1.0.3 that wasn't caught by its test suite:

1. magic bytes
2. declared content type, unless it's binary
3. filename extension
4. binary: application/octet-stream
2024-03-01 09:29:24 -08:00
Jean Boussier
1c0982d88a
Merge pull request #51232 from Shopify/refactor-insert-all
Refactor InsertAll not to permanently lease a connection
2024-03-01 17:30:03 +01:00
Hartley McGuire
7d008fee70
Merge pull request #51229 from Earlopain/update-bin-rails-test-help-output
Update output of `bin/rails test -h` in testing guide [ci-skip]
2024-03-01 15:37:14 +00:00
Jean Boussier
ec7deca7ee Refactor InsertAll not to permanently lease a connection
Extracted from: https://github.com/rails/rails/pull/50793
2024-03-01 15:33:45 +01:00
Jean Boussier
2bf0d68de6 Fix a typo in ConnectionPoool#connection deprecation (again) 2024-03-01 15:32:58 +01:00
Jean Boussier
f657842090 Fix a typo in ConnectionPoool#connection deprecation 2024-03-01 15:28:00 +01:00
Jean Boussier
e27a0df338
Merge pull request #51230 from Shopify/deprecate-connection
Deprecate `ConnectionPool#connection`
2024-03-01 14:53:09 +01:00
Jean Boussier
7263da542b Deprecate ConnectionPool#connection
Replaced by `#lease_connection` to better reflect what it does.

`ActiveRecord::Base#connection` is deprecated in the same way
but without a removal timeline nor a deprecation warning.

Inside the Active Record test suite, we do remove `Base.connection`
to ensure it's not used internally.

Some callsites have been converted to use `with_connection`,
some other have been more simply migrated to `lease_connection`
and will serve as a list of callsites to convert for
https://github.com/rails/rails/pull/50793
2024-03-01 14:32:55 +01:00
Earlopain
1aa2b9306c
Update output of bin/rails test -h in testing guide 2024-03-01 13:32:16 +01:00
Jean Boussier
75e3407917
Merge pull request #51192 from Shopify/connection-leasing-2
Make `.connection` always return a permanently leased connection
2024-03-01 11:50:17 +01:00
Jean Boussier
38e8609ded Make .connection always return a permanently leased connection
Ref: https://github.com/rails/rails/pull/51083

The introduction of `ActiveRecord::Base.with_connection` somewhat broke
some expectations, namely that calling `.connection` would cause the
connection to be permenently leased, hence that future calls to it
would return the same connection, with all it's possible environmental
changes.

So any call to `.connection`, even inside `.with_connection` should
cause the lease to be sticky, and persist beyond the `with_connection`
block.

Also rename `.connection` into `.lease_connection`, as to make it
more explicit.
2024-03-01 11:37:06 +01:00
Jean Boussier
1f6cef4ca5
Merge pull request #51222 from Shopify/ar-clear-pinned-connection-cache
Clear all threads query cache when a connection is pinned
2024-02-29 09:50:48 +01:00
Jean Boussier
1d0b396f40 Clear all threads query cache when a connection is pinned
Ref: https://github.com/Shopify/maintenance_tasks/pull/983#issuecomment-1969407080
Ref: https://github.com/rails/rails/pull/51151

Now that query caches are owned by the pool, and assigned on connections
during checkout, when running multithreaded code inside transactional
tests (typically system tests), the two threads uses the same connection
but not the same cache.

So it's important that we do clear the caches for all threads when
a connection is pinned.
2024-02-29 09:21:18 +01:00
Jean Boussier
3ecc269814
Merge pull request #51213 from Shopify/generic-fixture-accessor
Expose a generic fixture accessor for fixture names that may conflict with Minitest
2024-02-28 16:09:34 +01:00
Jean Boussier
ef947f9932 Expose a generic fixture accessor for fixture names that may conflict with Minitest
```ruby
assert_equal "Ruby on Rails", web_sites(:rubyonrails).name
assert_equal "Ruby on Rails", fixture(:web_sites, :rubyonrails).name
```

This was brought to me by someone with a `Metadata` model. The fixtures
accessor being `metadata` which conflicts with the `metadata` method
recently added in `Minitest`.
2024-02-28 16:09:23 +01:00
Eileen M. Uchitelle
8bb5620c87
Merge pull request #51165 from joshuay03/query-constraints-confusing-error-with-single-non-primary-key-column
[Fix #51164] `Model.query_constraints` with single non-primary-key column raises incorrect error
2024-02-28 08:12:52 -05:00
Collin Jilbert
f14a6298f8
Add Solid Queue to the list of backends in Active Job guide (#51212)
This PR adds Solid Queue to the list of backends for ActiveJob and links to the README for Solid Queue.

[ci skip]
2024-02-28 09:55:47 -03:00
Joshua Young
f42d9cbc32 [Fix #51164] Model.query_constraints with single non-primary-key column raises incorrect error 2024-02-28 14:19:10 +10:00
Rafael Mendonça França
649e99bf92
Merge pull request #51206 from fatkodima/fix-indexes-for-nonexisting-table
Fix `indexes` method for non-existing MySQL tables
2024-02-27 16:29:49 -05:00
Steve Polito
59a3dd4729
Set action_mailer.default_url_options values in development and test (#51191)
* Set `action_mailer.default_url_options` values in `development` and `test`.

Prior to this commit, new Rails applications would raise
`ActionView::Template::Error` if a mailer included a url built with a
`*_path` helper.

Since we already know [new apps will be served on `localhost:3000`][new
apps], we set this as the value in `development`.

In an effort to remain consistent with existing patters, we set the
`host` to `www.example.com` in `test.

[new apps]: 47300002db/README.md (L81)

* Update railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt

Co-authored-by: Rafael Mendonça França <rafael@franca.dev>

---------

Co-authored-by: Rafael Mendonça França <rafael@franca.dev>
2024-02-27 16:19:23 -05:00
Rafael Mendonça França
2772e8ad18
Merge pull request #51207 from Earlopain/fix-tools-profile
Remove `tools/profile`
2024-02-27 15:59:43 -05:00
Earlopain
626e014d34
Remove tools/profile 2024-02-27 20:43:30 +01:00
fatkodima
8510efa841 Fix indexes method for non-existing MySQL tables 2024-02-27 13:39:01 +02:00
Jean Boussier
af85f74418
Merge pull request #51174 from Shopify/connection-less-quoting
Don't require an active connection for table and column quoting
2024-02-27 11:34:32 +01:00
Jean Boussier
0016280f4f Don't require an active connection for table and column quoting
Extracted from: https://github.com/rails/rails/pull/50793

Right now quoting table or column names requires a leased Adapter
instance, even though none of the implementations actually requires
an active connection.

The idea here is to move these methods to the class so that the quoting
can be done without leasing a connection or even needing the connection
to ever have been established.

I also checked `activerecord-sqlserver-adapter` and `oracle-enhanced`
gems, and neither need an active connection.
2024-02-27 11:19:00 +01:00
Rafael Mendonça França
0a9ca0107c
✂️ 2024-02-27 02:16:02 +00:00
Rafael Mendonça França
88afcce1dd
Merge pull request #51198 from willnet/fix-wrong-documentation-for-logger_outputs_to
Fix documentation and sample code for `ActiveSupport::Logger.logger_outputs_to?`
2024-02-26 21:08:52 -05:00
Shinichi Maeshima
fc62f03ae3
[ci skip]Fix documentation and sample code for ActiveSupport::Logger.logger_outputs_to?
Fixed incorrect documentation for `ActiveSupport::Logger.logger_outputs_to?`. The method expects the first argument to be a Logger object and subsequent variadic arguments to be either IO objects or strings representing file paths.

Also corrected the sample code in CHANGELOG.md, which previously only passed a single argument, not reflecting the correct usage.

related PR: https://github.com/rails/rails/pull/51125
2024-02-27 10:56:53 +09:00
Rafael Mendonça França
a3f884f7a7
Merge pull request #50128 from thiagopradi/main
Removing not used fixtures from ActionPack test suite
2024-02-26 20:52:10 -05:00
Rafael Mendonça França
ada3d775bd
Use Kernel#Array to wrap the default value 2024-02-27 01:37:54 +00:00
Rafael Mendonça França
d216d1ede7
Do not always mark the default translation as html safe
If the `_html` suffis isn't provided we should not mark the default
translation as html safe and escape it.
2024-02-27 01:36:40 +00:00
Carlos Antonio da Silva
c402ec7872 Add punctuation on some newly added API docs [ci skip] 2024-02-26 13:32:39 -03:00
Jean Boussier
f0864e34d6
Merge pull request #51193 from Shopify/fix-migrator-current-version
Fix `Migrator.current_version` to instantiate `SchemaMigration` correctly
2024-02-26 12:54:26 +01:00
Jean Boussier
6e74098b8c Fix Migrator.current_version to instantiate SchemaMigration correctly
This was missed in https://github.com/rails/rails/pull/51162
2024-02-26 12:49:31 +01:00
Vipul A M
2abee307fe
Merge pull request #51184 from ConfusedVorlon/document_after_commit_deduplication
[ci skip] Add warning about deduplication of after_xxx_commit shortcuts
2024-02-25 16:30:11 -05:00
Vipul A M
e34a0eec38
Merge pull request #51186 from Earlopain/encourage-html-safe-methods-for-safe-join
Docs: Encourage html safe methods for safe join [ci skip]
2024-02-25 11:58:07 -05:00
Vipul A M
4a95c64685
Merge pull request #51187 from lexcao/fix/typo
Fix typo [ci-skip]
2024-02-25 10:21:44 -05:00
Lex Cao
48036fee0d Fix typo 2024-02-25 23:11:40 +08:00
Thiago Pradi
4a91897831
Merge branch 'rails:main' into main 2024-02-25 11:37:47 -03:00
Earlopain
295e7079aa
Docs: Encourage html safe methods for safe join 2024-02-25 12:27:56 +01:00
Rob Jonson
79fa0e3b2d Add warning about deduplication of after_xxx_commit shortcuts 2024-02-24 19:40:13 +00:00
Edouard CHIN
23af6f37a3
Merge pull request #51180 from cjilbert504/patch-1
Update layouts_and_rendering.md
2024-02-24 15:19:07 +01:00