Commit Graph

84346 Commits

Author SHA1 Message Date
eileencodes
1623892582
Fix rubocop warning re unused argument 2022-08-04 14:50:11 -04:00
John Hawthorn
668d866b4b
Merge pull request #45756 from jhawthorn/avoid_to_s_in_erb
Avoid calling to_s at end of ERB
2022-08-04 11:16:36 -07:00
eileencodes
8d0da3d568
Refactor changes in #44931 and add a test
The PR #44931 fell off my radar a few months ago so I decided to add a
test myself to ensure this behavior change is tested. While doing that I
decided to refactor the changes from that PR to make the code a little
cleaner and easier to read.
2022-08-04 12:58:39 -04:00
Matt Larraz
8af4165a18
Improve #configured_migrate_path logic (#44931)
* Improve #configured_migrate_path logic

This solves two issues:

* `migrations_paths` is an Array, which here gets coerced to a string.
  This is fine if it's a single path, but otherwise the generated path
  is a concatenation of all the paths. Instead, pick the first one.

* If the `--database` flag is not passed in, fall back to the primary
  database's `migrations_paths` entry if available before falling back
  to the global default migrate path.

* migrations_paths can be a String, Array, or nil
2022-08-04 12:58:20 -04:00
Jonathan Hefner
246eed4d1b
Merge pull request #45737 from jonathanhefner/generalize-command-editor-helper-module
Remove remnants from `Editor` command helper module
2022-08-04 11:45:22 -05:00
Jonathan Hefner
239d6fa67d Use tap in conditionally-required password example [ci-skip] 2022-08-04 11:39:29 -05:00
Eileen M. Uchitelle
0c9e4069f7
Merge pull request #45751 from adrianna-chang-shopify/ac-build-change-column-default-definition
Define #build_change_column_definition for MySQL and PG
2022-08-04 08:37:11 -04:00
Yasuo Honda
a0c1d33d2f
Merge pull request #45735 from ghiculescu/drop-enum
Add `drop_enum` command for Postgres
2022-08-04 09:26:46 +09:00
Alex Ghiculescu
bd0fdc8094 Add drop_enum command for Postgres 2022-08-03 18:50:43 -05:00
Yasuo Honda
c558d98b9d
Merge pull request #45674 from skipkayhil/add-changelog-linter
Add linter for CHANGELOG formatting [ci skip]
2022-08-04 08:45:28 +09:00
John Hawthorn
ee68644c28 Avoid calling to_s at end of ERB
With the recent changes to OutputBuffer, calling `to_s` is extremely
expensive if the buffer later is concatenated to (if the buffer never
changes it should be relatively inexpensive, as Ruby will share memory).
2022-08-03 16:24:12 -07:00
Jonathan Hefner
3f814695d7
Merge pull request #45754 from jonathanhefner/has_secure_password-conditional-password-example
Add example of conditionally requiring a password [ci-skip]
2022-08-03 16:17:45 -05:00
Jonathan Hefner
f53e3ad938 Add example of conditionally requiring a password [ci-skip]
This example addresses the use case brought up by #45487, which has been
reverted by #45753.
2022-08-03 16:14:08 -05:00
Jonathan Hefner
396776644d
Merge pull request #45753 from jonathanhefner/revert-45487
Revert "Allow passing hash on secure password validations"
2022-08-03 16:13:46 -05:00
Eileen M. Uchitelle
cf0873010a
Merge pull request #45743 from deepakmahakale/fix-test-case
Fix test case to check has_many_attached
2022-08-03 16:33:02 -04:00
Adrianna Chang
7455336638 Define #build_change_column_definition for MySQL and PG
Define APIs on the MySQL and PostgreSQL connection adapters for building
ChangeColumnDefaultDefinition objects. These provide information on what a
column default change would look like, when called with the same arguments as
would be passed to #change_column_default.
2022-08-03 16:27:25 -04:00
eileencodes
58e6f11878
Fix indentation
I messed up copying and pasting this. Rubocop failures caught
this in https://github.com/rails/rails/runs/7658743379?check_suite_focus=true
2022-08-03 14:46:11 -04:00
eileencodes
25f97a66bd
Add support for if_exists option when removing a check constraint
The `remove_check_constraint` method now accepts an `if_exists` option. If set
to true an error won't be raised if the check constraint doesn't exist.

This commit is a combination of PR #45726 and #45718 with some
additional changes to improve wording, testing, and implementation.

Usage:

```ruby
remove_check_constraint :products, name: "price_check", if_exists: true
```

Fixes #45634

Co-authored-by: Margaret Parsa <mparsa@actbluetech.com>
Co-authored-by: Aditya Bhutani <adi_bhutani16@yahoo.in>
2022-08-03 14:39:54 -04:00
Jean Boussier
1288289ed0
Merge pull request #45697 from adrianna-chang-shopify/ac-change-column-default-mysql
Use SET DEFAULT when changing a column default in MySQL
2022-08-03 20:23:08 +02:00
Jean Boussier
e1f566a6f4
Merge pull request #45734 from fatkodima/fix-columnless-enums
Raise when defining an enum not backed by a database column
2022-08-03 20:20:39 +02:00
Jonathan Hefner
6020f5331d Revert "Allow passing hash on secure password validations"
This reverts #45487 (8804128ad4cfea228ce97005072b029d0379d80f) until a
better API can be decided upon.
2022-08-03 11:52:30 -05:00
Adrianna Chang
b9b8852adc Use SET DEFAULT when changing a column default in MySQL
Aligns the SQL produced for changing a column default between MySQL and PostgreSQL.
MySQL is currently producing an <ALTER TABLE x CHANGE COLUMN y> query just to
change the default for a column, which is less efficient than using the SET DEFAULT syntax.

Additionally, extracts ChangeColumnDefaultDefinition and moves the SQL generation to the visitor class.
2022-08-03 11:16:06 -04:00
Jean Boussier
d0e26bf891
Merge pull request #45748 from Shopify/action-view-refactor-output-buffer-test-2
Refactor Action View tests to stop re-assigning @output_buffer
2022-08-03 15:18:13 +02:00
Petrik de Heus
df55109cbe
Merge pull request #45747 from Nittarab/main [ci-skip]
Add missing Versioning header in maintenance policy guide
2022-08-03 15:05:23 +02:00
Jean Boussier
4b67dffc8d Refactor Action View tests to stop re-assigning @output_buffer
Followup on https://github.com/rails/rails/pull/45745

`@rendered` is a much better variable for this kind of intermediate
result as that's what is used by DOM assertions.
2022-08-03 15:00:58 +02:00
Jean Boussier
206b2b8319
Merge pull request #45731 from Shopify/action-view-buffer-slice
Add OutputBuffer#raw and #capture to reduce the need to swap the buffer
2022-08-03 14:57:34 +02:00
Jean Boussier
a5862af315
Merge pull request #45744 from fatkodima/mysql-change-column-collation
Preserve collation when changing column in MySQL
2022-08-03 14:53:48 +02:00
Jean Boussier
9ac8e0c9ae
Merge pull request #45677 from Shopify/action-view-erb-freeze
Avoid explictly freezing literals strings when possible
2022-08-03 13:47:09 +02:00
Patrick Barattin
8821574186 Add missing Versioning header in maintenance policy guide 2022-08-03 13:32:59 +02:00
Jean Boussier
fc0db35fb1 Add OutputBuffer#raw and #capture to reduce the need to swap the buffer
Right now many helpers have to deal with two modes of operation to
capture view output.

The main one is to swap the `@output_buffer` variable with a new buffer.
But since some view implementations such as `builder` keep a reference
on the buffer they were initialized with, this doesn't always work.

So additionally, the various capturing helpers also record the buffer
length prior to executing the block, and then `slice!` the buffer back
to its original size.

This is wasteful and make the code rather unclear.

Now that `OutputBuffer` is a delegator, I'd like to refactor all this
so that:

  - @output_buffer is no longer re-assigned
  - A single OutputBuffer instance is used for the entire response rendering
  - Instead capturing is done through `OutputBuffer#capture`

Once the above is achieved, it should allow us to enabled Erubi's
`:chain_appends` option and get some reduced template size and some
performance.

Not re-assigning `@output_buffer` will also allow template to access
the local variable instead of an instance variable, which is cheaper.

But more importantly, that should make the code easier to understand
and easier to be compatible with `StreamingBuffer`.
2022-08-03 12:56:34 +02:00
Jean Boussier
ee754bac2a
Merge pull request #45745 from Shopify/refactor-form-helper-test
Refactor form_for tests to stop re-assigning @output_buffer
2022-08-03 12:56:05 +02:00
Jean Boussier
577bb114b5 Refactor form_for tests to stop re-assigning @output_buffer
It's really not what it's meant for. `@renderer` is a better use
for this as it's the variable used by the DOM testing helpers.

Ref: https://github.com/rails/rails/pull/45731
2022-08-03 12:33:08 +02:00
fatkodima
3a0d0f4bd8 Preserve collaction when changing column in MySQL 2022-08-03 13:09:25 +03:00
Deepak Mahakale
380cd17ae4 Fix attachment to has_many_attached 2022-08-03 15:09:49 +05:30
Jean Boussier
476aeda794 Avoid explictly freezing literals strings when possible
Ref: https://github.com/jeremyevans/erubi/pull/33

If the template is compiled with `frozen_string_literals: true`,
then explicitly freezing string is slightly wasteful as it will be
compiled as `opt_str_freeze` instead of a simple `putobject`.

The former has to check wether `String#freeze` was redefined every
time, which while fast is useless extra work.
2022-08-03 11:15:36 +02:00
fatkodima
6c5fab0668 Raise when defining an enum not backed by a database column 2022-08-03 11:14:45 +03:00
Jonathan Hefner
943fca0de8 Remove remnants from Editor command helper module
The `Editor` command helper module was originally extracted from
`CredentialsCommand`, and still includes a help message mentioning
"credentials" and a `rescue` that is specific to encrypted files.

This commit removes those remnants, fully generalizing the `Editor`
module.  Additionally, this commit changes `SecretsCommand` to make use
of the `Editor` module.
2022-08-02 15:47:28 -05:00
Jonathan Hefner
887dc9af6c
Merge pull request #45716 from jonathanhefner/command-executable-helper
Consistently format commands in help messages
2022-08-02 15:42:38 -05:00
Jonathan Hefner
3661d0d8a4
Merge pull request #45675 from hirotaka/fix_date_select_with_locale
Fixes Date Helper with locale
2022-08-02 11:14:25 -05:00
Jean Boussier
408d061a80
Merge pull request #45720 from Shopify/find-or-create-or-find-by
find_or_create_by: handle race condition by finding again
2022-08-02 15:11:20 +02:00
Jean Boussier
562a038eae
Merge pull request #45732 from fatkodima/redis-cache-store-flaky-tests
Fix flaky tests for RedisCacheStore
2022-08-02 15:09:12 +02:00
fatkodima
813b58d8f9 Fix flaky tests for RedisCacheStore 2022-08-02 15:39:06 +03:00
Jean Boussier
090f78e6ed
Merge pull request #45729 from fatkodima/insert_all-empty-attributes
Accept empty list of attributes for `insert_all`, `insert_all!` and `upsert_all`
2022-08-02 13:02:56 +02:00
fatkodima
cd3508607d Accept empty list of attributes for insert_all, insert_all! and upsert_all 2022-08-02 13:21:31 +03:00
Hirotaka Mizutani
60ca482cf0 Fixes Date Helper with locale
The i18n gem (https://github.com/ruby-i18n/i18n) has been modified to `freeze`
locale setting values. This could cause the Date helper to not work correctly
under certain conditions. `dup` the configuration values fixes that problem.
2022-08-02 18:32:13 +09:00
Jean Boussier
023a3eb3c0 find_or_create_by: handle race condition by finding again
Using `create_or_find_by` in codepaths where most of the time
the record already exist is wasteful on several accounts.

`create_or_find_by` should be the method to use when most of the
time the record doesn't already exist, not a race condition safe
version of `find_or_create_by`.

To make `find_or_create_by` race-condition free, we can search
the record again if the creation failed because of an unicity
constraint.

Co-Authored-By: Alex Kitchens <alexcameron98@gmail.com>
2022-08-02 09:58:26 +02:00
Jean Boussier
195f20dca8
Merge pull request #45728 from fatkodima/null_store-repeated-reads
Fix `Cache::NullStore` with local caching for repeated reads
2022-08-02 09:37:13 +02:00
Jean Boussier
91b51e31cd
Merge pull request #45727 from joelhawksley/rename-strict-locals
Rename 'Explicit Locals` to `Strict Locals`
2022-08-02 08:35:24 +02:00
fatkodima
6dad6e7604 Fix Cache::NullStore with local caching for repeated reads 2022-08-02 03:18:35 +03:00
Joel Hawksley
b7908a62f9 Rename 'Explicit Locals to Strict Locals`
Per https://github.com/rails/rails/pull/45602#discussion_r934981516
2022-08-01 17:23:47 -06:00