Currently, when checking that the collection has been loaded, only the first
record is checked. In specific scenarios, if a record is fetched via an `after_initialize`
hook, there is a chance that the first record has been loaded, but other records in the
collection have not.
In order to successfully short circuit the fetching of data, we need to verify that
all of the records in the collection have been loaded.
* Create test for edge case
* Move `reset_callbacks` method to `cases/helper`, since it has been defined in multiple
locations.
Closes#37730
When a test method name includes a slash (e.g. `test "signup on the
/signup page"`) the screenshot is generated in the nested directory on
systems that use slash as a directory separator (e.g. a screenshot
called `signup_page.png` is generated within `failures_signup_on_the_`).
Nesting screenshots causes an issue with `tmp:clear` rake task:
```
== Removing old logs and tempfiles ==
rails aborted!
Errno::EISDIR: Is a directory @ apply2files - tmp/screenshots/failures_signup_on_the_
/var/lib/gems/2.5.0/gems/railties-5.2.3/lib/rails/tasks/tmp.rake:41:in `block (3 levels) in <top (required)>'
/var/lib/gems/2.5.0/gems/railties-5.2.3/lib/rails/commands/rake/rake_command.rb:23:in `block in perform'
...
Tasks: TOP => tmp:clear => tmp:screenshots:clear
```
While the error could be prevented by changing `tmp:clear` task, there's
no reason to generate deep directory structures for tests using slashes.
To prevent a similar problem on Windows, we'll also "sanitize"
backslashes.
Replacing the problamatic characters with dashes seems to be a safe
workaround, although dash is very arbitrary choice in this case.
Co-Authored-By: Louis-Michel Couture <louim_1@hotmail.com>
The concept of treating Accept header lists including "*/*" as
identifying the request as coming from a browser, and allowing the mime
negotiation to fall back to a HTML response, was introduced in commits
1310231c15 and dc5300adb6.
I am adding the comment (based on the commit messages of the two commits
mentioned) because it is far from obvious why this regex exists and what
it does.
Co-authored-by: Matthew Riddle <mriddle89@gmail.com>
Adapters don't necessarily have the ability to execute a batch of
statements.
Previously execute_batch took a single string of statements separated by
';', this meant that the adapter had to have the ability to execute
batch statements.
Instead, this commit changes the method to take an array of statements.
Adapters which support batched queries can do the join there. For
adapters which don't we provide a fallback implementation: executing
each statement one at a time.
This also improves the implementation for the mysql2 adapter, which
understands that there is a maximium query length. Previously the caller
needed to split the statements before passing them to execute_batch, now
execute_batch itself is responsible for splitting the queries.
Keep the example complex enough to showcase involving Action Mailers
to either: bounce and halt processing or finish the email processing
by asking for more information.
Closes https://github.com/rails/rails/pull/37736
[ Paul McMahon, Kasper Timm Hansen ]
Thor will show a deprecation if a command fails and this method is not
define. We should investigate which command we want to return a non-zero
status when it fails but for now I'm just disabling the warning and
keeping the old behavior.
In a forking process web server like Unicorn, connections are
reconnected after fork. This test ensures that when connects are
reconnected after fork when using multiple databases, the query cache
will be on and work correctly.
This test fails on Rails 6.0 for now.
Follow up of #35280.
If a model has default scopes, vanilla `klass.all` is not the same with
`klass.unscoped`.
In that case, we should use `klass.default_scoped` instead.
The errors below heppens in executing `bundle exec rake
guides:validate`.
```
$ bundle exec rake guides:generate:html
(snip)
$ bundle exec rake guides:validate
(snip)
./output/active_record_querying.html has 57 validation error(s):
ERROR; line 55: Element “dt” not allowed as child of element
“div” in this context. (Suppressing further errors from this
subtree.)
(snip)
```