Commit Graph

88922 Commits

Author SHA1 Message Date
Jean Boussier
9e4d9c48f1
Merge pull request #49281 from Shopify/fix-error-reporter-assertions
Make ErrorReporterAssertions methods public
2023-09-15 11:23:23 +02:00
Jean Boussier
c15996c1bc Make ErrorReporterAssertions methods public
Since the methods are private they weren't documented.
2023-09-15 10:57:14 +02:00
Gannon McGibbon
ed9248d4e0
Merge pull request #49265 from gmcgibbon/cpk_tuple_or_querying
Clean up old composite key code
2023-09-14 22:58:44 -05:00
Gannon McGibbon
1111ec052f Clean up old composite key code
Because where now supports tuple querying, we don't need to manually
build queries with where and or statements.
2023-09-14 22:36:18 -05:00
dhh
83f36d5390 Remove duplication from #49278 2023-09-14 15:15:08 -07:00
Rafael Mendonça França
9e34e3bdf8
Merge pull request #49262 from ipc103/transaction-instrumentation-payload-outcome
Add outcome to transaction tracking payload
2023-09-14 18:14:20 -04:00
Rafael Mendonça França
4d4f105e25
Merge pull request #49279 from ghiculescu/documents-formattin
Shorten some of the guide names in the Guides index
2023-09-14 18:13:58 -04:00
David Heinemeier Hansson
757861889d
Ignore env files (except templates) (#49278)
Help prevent security issues out of the box.
2023-09-14 14:53:27 -07:00
Alex Ghiculescu
ccde530867 Shorten some of the guide names in the Guides index 2023-09-15 07:52:59 +10:00
Eileen M. Uchitelle
ff6bf8dd7e
Merge pull request #49277 from akhilgkrishnan/add-missing-dollar-s-gn
Add missing dollar sign for bash script [skip ci]
2023-09-14 14:13:06 -04:00
Akhil G Krishnan
0d3a4ca7e9
Add missing dollar sign for bash script [skip ci] 2023-09-14 17:48:20 +00:00
Hartley McGuire
6ba2bf4fbd
Merge pull request #49275 from akhilgkrishnan/add-missing-dollar
Add missing dollar sign to bash scripts [skip ci]
2023-09-14 13:02:21 -04:00
Akhil G Krishnan
96ff4767bf
Add missing dollar sign to bash scripts 2023-09-14 16:55:46 +00:00
Eileen M. Uchitelle
910eb470c5
Merge pull request #49264 from Shopify/explicitly-configured-primary-key-option-must-take-priority-in-association-primary-key
Explicit `primary_key:` option should always take priority in associations
2023-09-14 11:48:10 -04:00
Eileen M. Uchitelle
ff309346d3
Merge pull request #49268 from ghiculescu/cpk-guide
Add Composite Primary Keys guide to guides index
2023-09-14 11:39:14 -04:00
Ryuta Kamizono
da2af18834
Merge pull request #49269 from aidanharan/batches-test-regex-escape
Regex escape table and column names
2023-09-14 23:23:50 +09:00
Ryuta Kamizono
6d4abdca5d
Merge pull request #47752 from p8/activerecord/keyword-attributes
Raise error when generating attribute with dangerous name
2023-09-14 21:33:06 +09:00
Petrik
99b1316fd9 Raise error when generating attribute with dangerous name
Generating a model with attributes named `hash` or `save` should raise
an error, instead of generating a migration with an invalid attribute.
2023-09-14 12:58:36 +02:00
Aidan Haran
d777f7322e Regex escape table and column names 2023-09-14 10:55:22 +01:00
Ryuta Kamizono
7b670848e1
Merge pull request #49237 from shouichi/active-job-instrumentation-tests
Add tests for AJ events
2023-09-14 16:20:53 +09:00
Shouichi Kamiya
7ff936570b Add tests for AJ events
Because events are documented but not tested.
2023-09-14 16:05:26 +09:00
Ryuta Kamizono
bd3a0d4984
Merge pull request #49258 from p8/activerecord/enum-test-remove-unused-code
Remove unused delete_all from test
2023-09-14 14:48:48 +09:00
Alex
25524826aa Add Composite Primary Keys guide to guides index 2023-09-14 12:32:33 +10:00
Rafael Mendonça França
13b3e7d839
Merge pull request #49193 from seanpdoyle/action-view-test-case-documentation
Add "Testing View Partials" section to the Testing Guides
2023-09-13 19:06:33 -04:00
Nikita Vasilevsky
dcfddc1f90
Explicit primary_key: option should always take priority in associations
This commit fixes the issue where the `primary_key:` option was ignored
if the associated model had a `query_constraints` configured.
Now `primary_key:` option always takes priority and only if there is no
`primary_key:` option, the `query_constraints` are used to determine
the `association_primary_key` value.
2023-09-13 21:12:04 +00:00
Daniel Colson
cf8ab2f4b8
Add outcome to transaction tracking payload
Following up on https://github.com/rails/rails/pull/49192, this commit
adds the transaction `outcome` to the payload, helpful for collecting
stats on how many transactions commit, rollback, restart, or (perhaps
most interestingly) are incomplete because of an error.

The one quirk here is that we have to modify the payload on finish. It's
not the only place this sort of thing happens (instrument mutates the
payload with exceptions, for example), but it does mean we need to dup
the payload we initialize with to avoid mutating it for other tracking.

Co-authored-by: Ian Candy <ipc103@github.com>
2023-09-13 15:30:50 -04:00
Petrik
39f3f96ddb Remove unused delete_all from test
Deleting all books should not effect the inclusion validation.
2023-09-13 21:28:05 +02:00
Eileen M. Uchitelle
bb2fedbf01
Merge pull request #49257 from fatkodima/changelog-entry-49082
Add changelog entry for profiling slow tests
2023-09-13 15:10:06 -04:00
fatkodima
e4206c64d9 Add changelog entry for profiling slow tests
The change was added in #49082.
[skip ci]
2023-09-13 21:41:50 +03:00
Eileen M. Uchitelle
edd43af862
Merge pull request #49255 from eileencodes/minor-refactoring-on-derived-fk
Don't pass active_record to `derive_fk_query_constraints`
2023-09-13 13:32:22 -04:00
eileencodes
86a5f33bbe
Don't pass active_record to derive_fk_query_constraints
We already have access to the `active_record` on the reflection here so
there's no point in passing it to `derive_fk_query_constraints`.

In addition the id, fk check wasn't actually doing anything here, it was
holdover from debugging I was doing when implementing this
functionality.
2023-09-13 10:35:19 -04:00
Sean Doyle
a92bc713ee
Update guides/source/testing.md
Co-authored-by: Adrianna Chang <adrianna.chang@shopify.com>
2023-09-13 10:18:52 -04:00
Sean Doyle
a9148b45f3 Add "Testing View Partials" section to the Testing Guides
Motivation / Background
---

While the `ActionView::TestCase` class isn't marked with a `:nodoc:`
comment to indicate that it's internal to Rails, there isn't much
content in the guides that explains how to test view partials.

Libraries like
[view_component](https://github.com/ViewComponent/view_component/) have
[built-in support for
testing](https://viewcomponent.org/guide/testing.html), including
Capybara integration.

While `ActionView::TestCase` already integrates with
`rails-dom-testing`, that integration could be better documented.
Additionally, it wouldn't take much for consuming applications to mimic
the ViewComponent testing experience for their Action View Partials.

Details
---

First, link to the "Testing Rails Applications" page from the
`ActionView::TestCase` class documentation.

Next, add a "Testing View Partials" section to the guides that expands
upon the variety of tooling available to tests that inherit from
`ActionView::TestCase`. In that section, cover topics like:

* the `render` helper method
* the `rendered` helper attribute reader
* calls to `assert_select` with attribute placeholders
* the `document_root_element` helper method
* integration with Ruby's Pattern Matching
* opportunities to integrate with Capybara

Additional Information
---

Additionally, add test coverage that exercise the examples shared in the
new section, including:

* Calls to `assert_select` that utilize attribute placeholders
* Ruby 3.0's Pattern Matching
* Integration with Capybara
2023-09-13 09:44:44 -04:00
Ryuta Kamizono
bd4996bdfd
Merge pull request #49247 from koic/remove_redundant_blank_line_from_gemfile_of_new_app
Remove a redundant blank line from Gemfile of new app
2023-09-13 15:09:48 +09:00
Koichi ITO
f47d082bea Remove a redundant blank line from Gemfile of new app
## Motivation / Background

Continuous Integrating rubocop-rails_config after upgrading from Rails 7.0.7.2 to Rails 7.0.8 now fails:

```console
(snip)
rubocop --except=Style/StringLiterals,Style/FrozenStringLiteralComment .
cp ./test/fixture/.rubocop.yml rails_test/.rubocop.yml
cd rails_test
Inspecting 28 files
C...........................

Offenses:

Gemfile:71:1: C: [Correctable] Layout/EmptyLinesAroundBlockBody: Extra empty line detected at block body end.

28 files inspected, 1 offense detected, 1 offense autocorrectable
rake aborted!
```

https://github.com/toshimaru/rubocop-rails_config/actions/runs/6167995304/job/16739825926

Upon checking, redundant blank was added from version 7.0.8. This was `gem "webdrivers"` before 7.0.7.2.

### Rails 7.0.7.2

```console
$ ruby -v
ruby 3.3.0dev (2023-09-08T16:09:30Z master af5df9ee5e) [x86_64-darwin22]

$ cat Gemfile
# frozen_string_literal: true

source "https://rubygems.org"

gem "rails", "7.0.7.2"

$ bundle install
(snip)

$ bundle exec rails new example && cd $_
(snip)

% tail -n5 Gemfile
  # Use system testing [https://guides.rubyonrails.org/testing.html#system-testing]
  gem "capybara"
  gem "selenium-webdriver"
  gem "webdrivers"
end
```

### Rails 7.0.8

```console
$ cat Gemfile
# frozen_string_literal: true

source "https://rubygems.org"

gem "rails", "7.0.8"

$ bundle install
(snip)

$ bundle exec rails new example && cd $_
(snip)

% tail -n5 Gemfile
  # Use system testing [https://guides.rubyonrails.org/testing.html#system-testing]
  gem "capybara"
  gem "selenium-webdriver"

end
```

This is reproduced with Rails 7.0.8, Rails 7.1.0.beta1 and the main branch.

I understand this might not be of utmost importance, but I would appreciate
it if it could be backported to the Rails 7.0 branch, if possible.

## Detail

The blank line is filled in by https://github.com/rails/rails/pull/48847.
This PR removes the redundant blank line from Gemfile of new app.
2023-09-13 14:47:45 +09:00
Rafael Mendonça França
9150a98deb
Merge pull request #48216 from zzak/import-rails-bin-linter
Import rails-bin linter to rails internal tools lib
2023-09-12 22:01:59 -04:00
Rafael Mendonça França
32b8e66d22
Autocorrect violations 2023-09-13 01:58:14 +00:00
Rafael Mendonça França
296156033a
Support CHANGELOG with release headers in the linter 2023-09-13 01:57:17 +00:00
zzak
5c2a112d37
Import rails-bin to internal tools/
Co-authored-by: zzak <zzakscott@gmail.com>
2023-09-13 01:57:16 +00:00
Jonathan Hefner
11aa3fdd08
Merge pull request #49236 from shouichi/enable-literal-as-actual-argument
Enable Minitest/LiteralAsActualArgument
2023-09-12 20:24:07 -05:00
Shouichi Kamiya
51ac8b9f6f Enable Minitest/LiteralAsActualArgument
There are assertions that expected/actual arguments are passed in the
reversed order by mistake. Enabling the LiteralAsActualArgument rule
prevents this mistake from happening.

The existing tests were auto-corrected by rubocop with a bit of
indentation adjustment.

Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
2023-09-13 10:09:32 +09:00
Rafael Mendonça França
699dfdb426
Preparing for 7.1.0.beta1 release 2023-09-13 00:36:01 +00:00
Rafael Mendonça França
aa268ba931
Merge pull request #49072 from ghiculescu/extend-queries-per-attribute
Encryption: support `support_unencrypted_data` at a per-attribute level
2023-09-12 20:23:46 -04:00
Rafael Mendonça França
9eb16e77da
Revert "Merge pull request #49242 from eileencodes/fix-inferred-query-constraints"
This reverts commit 213e8ff95e71cd35b9ae51fcbc26e97ed8eda658, reversing
changes made to b5d63b9b16c6f251eaa08f61086f21ff3ef3292f.

It broke a lot of test.

It also changed how lazy loading of model code works.

With this change a simple `belongs_to :owner` is now loading `owner.rb`
when that line is executed, where before it wasn't doing that.
This can have serious impact on boot time in development.

We should make this as lazy as possible.
2023-09-12 22:36:33 +00:00
Jason Meller
274bc97d63
Add Bun support (#49241)
* Add Bun support to `rails new -j` generator

* Add additional generation consideration for Bun

* Use development gems to test the whole workflow

* Remove custom gems from local testing

* Revert lock

* Revert errant custom gem declaration

* Fix linting errors

* Fix remnants of bad merge

* Always use latest bun

* Update actioncable/lib/rails/generators/channel/channel_generator.rb

Co-authored-by: Cadu Ribeiro <mail@cadu.dev>

* Update guides/source/working_with_javascript_in_rails.md

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

* Only use the latest bun if nothing is specified

* Hardcode known good version

---------

Co-authored-by: Cadu Ribeiro <mail@cadu.dev>
Co-authored-by: Rafael Mendonça França <rafael@franca.dev>
2023-09-12 16:55:27 -04:00
Eileen M. Uchitelle
15bbd9bc9b
Merge pull request #49243 from flavorjones/flavorjones-bump-sqlite-version
dep: bump sqlite3 dependency to v1.6.6 or higher
2023-09-12 15:13:14 -04:00
Mike Dalessio
64169655c7
dep: bump sqlite3 dependency
sqlite3-ruby v1.6.6 has sqlite 3.43.1 which fixes the AVG() bug
described in https://github.com/sparklemotion/sqlite3-ruby/issues/396

See related https://github.com/rails/rails/pull/49048
2023-09-12 14:18:13 -04:00
Eileen M. Uchitelle
213e8ff95e
Merge pull request #49242 from eileencodes/fix-inferred-query-constraints
Fix inferred query constraints
2023-09-12 12:24:29 -04:00
eileencodes
a8ea8bb4bd
Fix inferred query constraints
While working on implementing query constraints in our vitess gem, I
noticed that we were applying query constraints even when we didn't have
them on both sides of the association. We only want to infer query
constraints if both the `klass` and `active_record` have them set.

* If both the `klass` and `active_record` on the association don't have
query constraints set, use the `foreign_key` and don't infer query
constraints.
* Adds an error if the `active_record` and `klass` query constraints
don't match.
* Calling `klass` in `derive_fk_query_constraints` revealed that a bunch
of our tests are missing requires, without these we'll see test failures
that an association can't compute the klass name. Adding the requires
fixes those.
2023-09-12 11:57:51 -04:00
Jean Boussier
b5d63b9b16
Merge pull request #49234 from ghiculescu/regression-test-for-45722
Add regression test for #45722
2023-09-12 09:00:52 +02:00