Commit Graph

21047 Commits

Author SHA1 Message Date
Jean Boussier
2d79790247 Make signed_id_verifier_secret a class attribute
Followup: https://github.com/rails/rails/pull/42442
2021-06-11 09:14:28 +02:00
Jean Boussier
c8932d6ec5 Make primary_key_prefix_type a class attribute
Followup: https://github.com/rails/rails/pull/42442
2021-06-11 09:12:36 +02:00
Jean Boussier
67268f1b68 Make time_zone_aware_attributes a class attribute
Followup: https://github.com/rails/rails/pull/42442
2021-06-11 09:09:57 +02:00
Jean Boussier
19c9a2046e Make index_nested_attribute_errors a module instance variable
Followup: https://github.com/rails/rails/pull/42442
2021-06-11 09:04:30 +02:00
Ryuta Kamizono
3cac9d8193 ✂️ [ci skip] 2021-06-11 14:24:06 +09:00
Ryuta Kamizono
2527682e3f Fix deprecation message s/Rails 7.0/Rails 7.1/ 2021-06-11 14:09:46 +09:00
eileencodes
566c4033f7
Fix disable_joins when foreign key is not ID
If you have a `has_one through` assocation where the `through` has a
`belongs_to` the foreign key won't be `id` for the joins. This change
ensures we use the correct foreign key when querying with disable joins
turned off. Prior to this change the call to `project.lead_developer`
would return `nil` if `disable_joins` was set.

Project has one lead developer through firm. Project also belongs to
firm. So when we call `project.lead_developer` it needs to find the
lead developer through the firm. In these cases we don't want to read
the owners id, we want to read the attribute that will give us the
value of the first chain item's `join_foreign_key`.
2021-06-10 16:29:34 -04:00
Jean Boussier
ba877bd088 Copy config.active_record.* again when ActiveRecord::Base is loaded
Otherwise initializer files with `Rails.application.active_record.*`
might break.
2021-06-10 19:12:57 +02:00
Jean Boussier
85622b949c Move async_query confurations on the ActiveRecord module
Followup: https://github.com/rails/rails/pull/42442
2021-06-10 18:31:33 +02:00
Jean Boussier
f4a3bf06a1 Make maintain_test_schema a module instance variable
Followup: https://github.com/rails/rails/pull/42442
2021-06-10 18:31:33 +02:00
Jean Boussier
957921443a Make queues a module instance variable
Followup: https://github.com/rails/rails/pull/42442
2021-06-10 18:31:33 +02:00
Jean Boussier
03e569bcfd Make verbose_query_logs a module instance variable
Followup: https://github.com/rails/rails/pull/42442
2021-06-10 18:31:33 +02:00
Jean Boussier
bcd6c0f3d0 Convert many ActiveRecord::Base class variable into instance variables
Followup: https://github.com/rails/rails/pull/42442
2021-06-10 18:31:33 +02:00
Jean Boussier
e65042707e Make action_on_strict_loading_violation a module instance variable
Followup: https://github.com/rails/rails/pull/42442
2021-06-10 18:31:33 +02:00
Jean Boussier
a50ff734cb Get rid of the unused ActiveRecord::Base.sqlite3_production_warning 2021-06-10 18:31:33 +02:00
Jean Boussier
40f6bd0eb9 Make application_record_class a module instance variable
Followup: https://github.com/rails/rails/pull/42442
2021-06-10 18:24:38 +02:00
Jean Boussier
d0e2b00570 Make warn_on_records_fetched_greater_than a module instance variable
Followup: https://github.com/rails/rails/pull/42442
2021-06-10 18:24:38 +02:00
Jean Boussier
8ae1339ae0 Make reading_role and writing_role module instance variables
Followup: https://github.com/rails/rails/pull/42442
2021-06-10 18:24:37 +02:00
Jean Boussier
c6e4dbeebb Make default_timezone a module instance variable
Followup: https://github.com/rails/rails/pull/42442
2021-06-10 17:25:38 +02:00
Jean Boussier
8459c1c22f Make legacy_connection_handling a module instance variable
Ref: https://github.com/rails/rails/pull/42237
Ref: https://bugs.ruby-lang.org/issues/17763

Ruby class variables are slow, and get slower the more ancestors the class has.
And it doesn't seem likely to get faster any time soon. Overall I'm under the
impression that ruby-core consider them more or less deprecated.

But in many cases where `cattr_accessor` is used, a class instance variable
could work just fine, and would be much faster.

For Active Record this means most of the `cattr_accessor` on `ActiveRecord::Base`
could actually be `attr_accessor` on `ActiveRecord`.

I started with `legacy_connection_handling` as a proof of concept.
2021-06-10 15:00:20 +02:00
Zachary Scott
4a85239c3e
Merge pull request #42443 from daven97/daven97update_active_record_relation_wording
Revise documentation example wording - ActiveRecord::Relation#find_or_create_by [ci skip]
2021-06-10 21:37:47 +09:00
Zachary Scott
50dce5dea4 Correct changelog for #42423 to be class method instead of instance
Also added an example [ci skip]
2021-06-10 21:06:59 +09:00
Zachary Scott
1987cbd17c Expand on AR::Base for method definition from #42423 [ci skip] 2021-06-10 20:06:45 +09:00
Zachary Scott
d3e9ca92c7 Add CHANGELOG for #42423 2021-06-10 19:40:28 +09:00
Jean Boussier
8b36cca481 Fix the Active Record test suite following fcc83e47384b69 2021-06-10 12:30:35 +02:00
Eugene Kenny
fcc83e4738 Fix method name in update! error message [ci skip]
Followup to 562ec582f78a39f91ae97c4be8a56a50689916c8.
2021-06-10 08:30:16 +01:00
Rafael França
05fe94c5b5
Merge pull request #42423 from dorianmarie/Model.update!
add Model.update! that is similar to Model.update but raises exceptions
2021-06-09 22:26:46 -04:00
Dave Nuttall
e648bf1877
Use consistent and more clear wording 2021-06-09 17:15:33 -06:00
Rafael Mendonça França
600ff9abfc
Fix all rubocop violations 2021-06-08 23:35:59 +00:00
Jean Boussier
5adb6a9a98
Merge pull request #42409 from shioyama/attributes_for_database
Add `attributes_for_database` method to return attributes as they would be in the database
2021-06-08 18:33:33 +02:00
Dorian Marié
ecda489c93
Update activerecord/lib/active_record/persistence.rb
Co-authored-by: Sunny Ripert <sunny@sunfox.org>
2021-06-08 15:32:16 +02:00
eileencodes
69dfa29135
Fix documentation
The docs for disable joins had intermingled with the docs for through. I
think that this happened in a merge conflict/rebase.
2021-06-08 09:21:03 -04:00
Dorian Marié
562ec582f7
add Model.update! that is similar to Model.update but raises exceptions 2021-06-08 14:40:56 +02:00
Chris Salzberg
caced27393 Add ActiveModel::AttributeSet#values_for_database 2021-06-08 16:39:23 +09:00
Heinrich Lee Yu
8325d07976
Use an empty query instead of SELECT 1
Using an empty query skips the PG query planner so it is more efficient
2021-06-07 17:12:04 +08:00
Eileen M. Uchitelle
db4a014aef
Merge pull request #42389 from intrip/introduce-previously-persisted
Add `ActiveRecord::Base#previously_persisted?`
2021-06-04 08:01:26 -04:00
Jacopo
851898114b Add ActiveRecord::Base#previously_persisted?
Returns `true` if the object has been previously persisted but now it has been deleted.

This is a follow up of https://github.com/rails/rails/pull/42256/files#r641914920
2021-06-04 13:06:51 +02:00
Jean Boussier
f5abd30f0d
Merge pull request #42376 from Shopify/activerecord-has-many-inversing-class-attr
Make `ActiveRecord::Base.has_many_inversing` a `class_attribute`
2021-06-04 09:34:24 +02:00
Zachary Scott
ac48eed08f
Merge pull request #41626 from angdraug/find_by_sql_injection_warning
Reiterate the SQL injection warning in find_by_sql API doc
2021-06-04 09:46:39 +09:00
Jean Boussier
24de1ab4f5 Make ActiveRecord::Base.has_many_inversing a class_attribute
This allows to enable or disable thew new behavior on a per
mode basis, which is helpful for large applications where
fixing all the problems at once is too much.
2021-06-03 17:59:00 +02:00
Eileen M. Uchitelle
2257a237d8
Merge pull request #42352 from nvasilevski/nikita-vasilevsky-any-all-queries
Faster check for any default scope with all_queries
2021-06-03 07:57:12 -04:00
Jean Boussier
d3f4db9e95
Merge pull request #42355 from Shopify/split-partial-writes
Deprecate `partial_writes` in favor of `partial_inserts` and `partial_updates`
2021-06-03 09:46:03 +02:00
Alex Ghiculescu
1cc8be30ba
Update compatibility.rb 2021-06-02 12:36:01 -05:00
Alex Ghiculescu
2ccbd38d69
Add developer docs on how ActiveRecord::Migration::Compatibility works
In https://github.com/rails/rails/pull/41084#discussion_r626739953, @pixeltrix helped me work through adding a new feature to the migration compatibility system. We both founded it a bit head scratching understanding the inheritance chain. In this PR I'm adding comments for future developers working on this to hopefully save some head scratching.

These comments aren't intended to be public - I think the `# :nodoc: all` on line 5 should prevent that.
2021-06-02 12:33:35 -05:00
Jean Boussier
125987e35d Deprecate partial_writes in favor of partial_inserts and partial_updates
This allows to have a different behavior on update and create.

For instance it might be desirable to disable partial inserts
to protect against a concurrent migration removing the default
value of a column, which would cause processes with an outdated
schema cache to fail on insert.
2021-06-02 15:04:08 +02:00
Nikita Vasilevsky
fde6da2164 Faster check for any default scope with all_queries 2021-06-01 22:11:43 -04:00
fatkodima
d836faf41c Fix retrieving default value for text column for MariaDB 2021-05-31 14:01:29 +03:00
Martin Jaime
e3849a6c27 Add tests for and method 2021-05-30 10:26:44 -03:00
Martin Jaime
1f4efef5ca Added test for or query error message 2021-05-29 11:52:24 -03:00
Étienne Barrié
a031a43d96 Expose BatchEnumerator attributes
BatchEnumerator is a simple object storing a few parameters coming from
ActiveRecord::Batches#in_batches when it's called without a block.

Sometimes, it's useful to access those values, in our case, a library
receiving a BatchEnumerator from application code.

Co-authored-by: Adrianna Chang <adrianna.chang@shopify.com>
2021-05-28 13:32:48 -04:00
Santiago Bartesaghi
9f7ee7e4e7 Minor test fix 2021-05-27 13:09:35 -03:00
Eugene Kenny
df76f078bc
Merge pull request #42290 from brunvez/top_level_update_error_message
Fix error message on top level update when sending an array of records
2021-05-27 16:48:42 +01:00
Ryuta Kamizono
56cfefe0cd
Merge pull request #42291 from martinjaimem/enhancement/add-tests-for-error-messages
Add tests for argument error messages in ActiveRecord methods
2021-05-26 18:25:59 +09:00
Martin Jaime
eec0ff0b39 Add tests for argument error messages in ActiveRecord methods 2021-05-25 20:34:04 -03:00
Bruno Vezoli
9912e9c594 Fix error message on top level update when sending an array of records 2021-05-25 18:54:36 -03:00
Ryuta Kamizono
a8461b7217
Merge pull request #42287 from martinjaimem/enhancement/add-tests-for-argument-error-on-finder-methods
Add tests for ArgumentError errors in finder methods
2021-05-25 16:01:16 +09:00
Martin Jaime
93c15c353a Add tests for ArgumentError errors in finder methods 2021-05-24 22:35:58 -03:00
Eugene Kenny
7612243b88 Remove redundant tests for Relation#select
These were superseded in 0cb3bd17e3585237eca34119543decbd992df4e6.
2021-05-24 22:49:57 +01:00
Ryuta Kamizono
168a277bc6 Test no arguments error message for both left_joins and left_outer_joins
It is a regression test for #30809.
2021-05-24 12:53:30 +09:00
Martin Jaime
0cb3bd17e3 Enhancement: refactor and add tests to the query methods argument errors 2021-05-23 15:16:09 -03:00
Martin Jaime
70dec80388 Fix ArgumentError message for without method 2021-05-22 18:06:19 -03:00
Jean Boussier
1e56b1d115 Fix ruby-master test suite (Psych 4.0.0)
Ruby master ships with Psych 4.0.0 which makes `YAML.load`
defaults to safe mode (https://github.com/ruby/psych/pull/487).

However since these YAML files are trustworthy sources
we can parse them with `unsafe_load`.
2021-05-19 14:21:21 +02:00
Jean Boussier
dcc2530af7 Make ActiveRecord::Base.logger a class_attribute
`cattr_accessor` rely on class variables which has terrible
performance on long ancestor chains. See https://bugs.ruby-lang.org/issues/17763
for a detailed description of the problem.

In comparison `class_attribute` on `ActiveRecord::Base` is almost 7x
faster:

```
Calculating -------------------------------------
              logger      1.700M (± 0.9%) i/s -      8.667M in   5.097595s
             clogger     11.556M (± 0.9%) i/s -     58.806M in   5.089282s

Comparison:
             clogger: 11555754.2 i/s
              logger:  1700280.4 i/s - 6.80x  (± 0.00) slower
```

This is because `ActiveRecord::Base.ancestors.size == 62`.
2021-05-19 10:48:23 +02:00
Keenan Brock
b775f0cbdc Support NullsFirst for all databases.
Most databases order tables with the `NULL` value first, having it before
all other data values. Postgres has `NULLS` last.

Fortunately, ANSI SQL has an option to allow the database to specify where NULLS
come out in this sort order

    ORDER BY column ASC NULLS FIRST

MS SQL, SQLite, Oracle, and Postgres all follow this syntax. Unfortunately, MySql
does not.

Before:

PostgreSQL: both `.nulls_first()` and `.nulls_last()` work as designed.
Others: both raise a runtime error.

After:

MySQL: `.nulls_first()` works as designed.
MySQL: `.nulls_last()` raises a runtime error
Others: both work as designed
2021-05-18 16:58:21 -04:00
Eugene Kenny
e44927fea9
Merge pull request #42242 from eugeneius/async_query_on_null_relation
Avoid running async queries on null relations
2021-05-18 11:47:42 +01:00
Jean Boussier
9dc032aced
Merge pull request #42231 from byroot/disabled-session
Explicitly fail on attempts to write into disabled sessions
2021-05-18 08:59:36 +02:00
Eugene Kenny
cb670c5c98 Avoid running async queries on null relations
Calling `load_async` on a null relation was executing the fallback
`WHERE 1=0` query, since it doesn't go through `exec_queries`.

Since 2a90104989b9f1653337d08871610d394b2d626d, `exec_queries` is
implemented in terms of `exec_main_query`, so we only need to override
that one method.

We can also stop assigning `@records`, as that now happens in `load`
since 847643a55acf9c82d2b70448cfa527fee63e9601.
2021-05-17 21:34:41 +01:00
Haroon Ahmed
1b8ceee4a2 Apply suggestions from code review
Co-authored-by: Zachary Scott <zzakscott@gmail.com>
2021-05-17 19:58:28 +01:00
Haroon Ahmed
b28711ffa0 Add a more detailed error messages for connection issues to pg and
mysql. Allow database to be create via a button on the UI for some
connection issues.
2021-05-17 19:58:27 +01:00
eileencodes
00bad6102c
Fix primary_abstract_class in lazy loaded envs
If you have an application that has `ApplicationRecord` and another
class like `PrimaryApplicationRecord` and the `PrimaryApplicationRecord`
is set to `primary_abstract_class`, then in a lazy loaded env like
development, it's possible for `application_record_class` to be set to
`ApplicationRecord`. This would then raise an error that you can't reset
the class if you then loaded `PrimaryApplicationRecord`.

To fix this we've removed the setter for `application_record_class` in
the fall through so that if this does happen, `ApplicationRecord` will
only be the primary class until the correct primary class is loaded.
If an application sets 2 classes to `primary_abstract_class`, the error
will still be raised.

Co-authored-by: John Crepezzi <john.crepezzi@gmail.com
2021-05-17 14:52:06 -04:00
Jean Boussier
c1c96a0140 Explicitly fail on attempts to write into disabled sessions
Until now `config.session_store :disabled` simply silently
discard the session hash at the end of the request.

By explictly failing on writes, it can help discovering bugs
earlier.

Reads are still permitted.
2021-05-17 20:02:52 +02:00
Jean Boussier
837c87e810 Fix NullRelation#to_sql to return an actual query
Fix: #42229

It is unclear why it was defined to return an empty string
in #5809.

But returning the query that will actually be generated if
the NullRelation is executed makes more sense.
2021-05-15 11:52:04 +02:00
Gonzalo Riestra
b3caf0c99a Improve performance of #one? and #many?
#one? and #many? generate a query like `SELECT COUNT(*) FROM posts` under the hood, and then compare if the result is equal (or greater) to 1. That count operation can be really slow for large tables or complex conditions, but there's no need to count all the records in these cases. It's much faster just by adding a limit, like `SELECT COUNT(*) FROM posts LIMIT 2`
2021-05-13 19:50:14 +02:00
eileencodes
da2c6eff74
Add changelog entry for #42212 2021-05-13 08:38:46 -04:00
Eileen M. Uchitelle
84266c0a95
Merge pull request #42212 from eileencodes/fix-type-column-casting-in-column_exists
Don't check `type` on `add_column` via column_exists?`
2021-05-12 17:47:07 -04:00
eileencodes
627da239be
Don't check type on add_column via column_exists?`
I originally added the `type` to the `column_exists?` check in
`add_column` because I thought it would be useful to still raise if you
tried to add a column with a different type. It seemed bad to silently
ignore.

The `type` check works fine for standard, non-type casted types like
`string`, but migrations that use types like `blob` in mysql/sqlite3 or
`char` in postgres cast these to other types. When `c.type ==
type.to_sym` is called in those cases they won't match. For example
`c.type` for a `blob` column will return `binary` so the comparison
won't match. I attempted to cast the `type` passed in but that's error
prone because for dbs like postgres we need _a lot_ more information
than just a type to determine how to cast it. I also tried going the
other way but the column doesn't store the original type, just the type
casted type (as type) and the sql type which is a string representation
of type that doesn't always match the original.

This functionality was originally extracted from GitHub and when I
looked back at our old implementation I found that we originally weren't
passing type. This came up in a migration for enterprise that wasn't
properly handling the `if_not_exists` because our `type` check was
comparing `binary` to `mediumblob`. I think it makes the most sense to
leave the public `column_exists?` method as is and remove the `type`
check from `column_exists?` in the `add_column` method.
2021-05-12 17:06:50 -04:00
Volmer Campos Soares
4e37f28881 Derive foreign key from model name in has_many associations
Currently Active Record derives the foreign key name for `has_many`
associations based on the Active Record Base `name. Sometimes when using
additional conventions for class names, such as with class name suffixes
and prefixes, it makes sense to be able to further customize the
foreign key logic to account for a different pattern.

Similar to what was done in the
[case of table names](https://github.com/rails/rails/pull/42213),
as Active Record Base extends Active Model Naming, we have already a
`model_name` at the class-level that behaves similarly to `name` while
at the same time giving more flexibility by allowing specifying a custom
name and namespacing.

This commit changes the foreign key computation in Reflections to infer
its value based on the Active Record's `model_name` object instead of
its class `name`. This allows customization of the foreing key pattern
since a distinct instance of `ActiveModel::Name` can be used instead.

For example, to use `post_id` as foreign key for a `PostRecord` class
in a `has_many` association:

```ruby
 class PostRecord < ActiveRecord::Base
   has_many :comments

   class << self
     def model_name
       ActiveModel::Name.new(self, nil, "Post")
     end
   end
 end

 PostRecord.reflect_on_association(:comments).foreign_key
 # => "post_id"
```
2021-05-12 15:21:31 -04:00
Volmer Campos Soares
d8b176855e Compute table name based on model name
Instead of using the Active Record Base's class name, the table name is
now inferred based on its model name object. This allows customization
of the table name pattern since a distinct instance of
`ActiveModel::Name` can be used instead.

For example, to map a `PostRecord` class to a `posts` table:

```ruby

 class PostRecord < ActiveRecord::Base
   class << self
     def model_name
       ActiveModel::Name.new(self, nil, 'Post')
     end
   end
 end

 PostRecord.table_name
 # => "posts"
```
2021-05-12 12:34:56 -04:00
anderslemke
1a1c455a55 Handle duplicate migration names in multi db
In a multidatabse setup, migrations live in seperate directories. The check for duplicate migration names, does not take this into
account.
So you __can__ end up having multiple migration with the same name.

When running `rails db:migrate` from the console, this other migration
might be loaded __before__ running the migrations for "this" database.

Because they have the same name, we have to ensure that the
contents of this migration is not carried over from "the other"
migrations.
2021-05-12 09:46:40 +02:00
Eileen M. Uchitelle
91f0db1353
Merge pull request #42202 from flavorjones/flavorjones-revert-selectoptions-inline
Revert "un-extract the Arel visitor for SelectOptions"
2021-05-11 10:56:59 -04:00
Mike Dalessio
685cf03f6c
Revert "un-extract the Arel visitor for SelectOptions"
This reverts commit d803b9ae9bdfb1c8643c1b463cf9af42ad6a1cb5.

See https://github.com/rsim/oracle-enhanced/issues/2186 for evidence
that this private method is being used by the Oracle12 sql visitor.
2021-05-11 09:58:12 -04:00
Jacopo
ad6a62e4e6 Log a warning when running SQLite in production
Logs a warning message when running SQlite in production.
The warning can be disabled by setting `config.active_record.sqlite3_production_warning=false`.

Closes #34715
2021-05-11 15:55:11 +02:00
Jean Boussier
e538979128
Merge pull request #42190 from Shopify/active-record-sum-init
Allow Relation#sum to take an `init` parameters
2021-05-11 00:01:01 +02:00
Scott Holden
7e791fcea8 allow ActiveRecord::ConnectionAdapters::PostgreSQL::Quoting to match schema namespaced table columns
Co-authored-by: Ryuta Kamizono <kamipo@gmail.com>
2021-05-10 09:48:39 -07:00
Jean Boussier
e672575906 Allow Relation#sum to take an init parameters
This is needed to not prevent full use of `Enumerable#sum`
on `Relation` objects.
2021-05-10 13:37:25 +02:00
Zachary Scott
be8d8edf50
Merge pull request #42179 from ricardotk002/require-as-numeric-in-ar
Update docs for `ActiveRecord::Middleware::DatabaseSelector`
2021-05-10 10:36:09 +09:00
Zachary Scott
52eec6651d
Clarify require necessity for --minimal app 2021-05-10 10:35:57 +09:00
Ricardo Díaz
3c748cc569 Update docs for ActiveRecord::Middleware::DatabaseSelector [ci skip]
The docs for this middleware indicate that you can set a delay that
can be a duration (eg. `2.seconds`).

https://api.rubyonrails.org/v6.1/classes/ActiveRecord/Middleware/DatabaseSelector.html

In normal apps, this works fine without an explicit require because
the extension is required through other libs. However, when creating a
minimal app, this results in an undefined method error.

This is something that is already being included in
test/development/production config files since c8c5497.
2021-05-09 20:05:39 -05:00
Ryuta Kamizono
8efcf9bf82 Fix isolated test failure
`Member` has `has_one :organization, through: :member_detail`, so
`@member.organization = @organization` requires `MemberDetail` class.

https://buildkite.com/rails/rails/builds/77274#c34f12f3-44c2-4ba9-ba44-dd4b2062a506/1158-1166
2021-05-08 22:04:55 +09:00
Andrew White
67feef37a7
Merge pull request #41084 from ghiculescu/default-pg-datetime-format
Active Record + PostgreSQL: native support for `timestamp with time zone`
2021-05-08 10:24:44 +01:00
Andrew White
1fd8a3f6db
Merge pull request #42080 from alberto-mota/remove_sum
Deprecates `Enumerable#sum` and `Array#sum`
2021-05-08 10:16:13 +01:00
Sarah Vessels
f7d7a22d01
Add has_one through disable_joins
This is similar to the `disable_joins` option on `has_many :through`
associations applied to `has_one :through` associations. When
`disable_joins` is set Rails will create 2 or more queries to get
associations instead of generating a join.

```ruby
class Person
  belongs_to :dog
  has_one :veterinarian, through: :dog, disable_joins: true
end
```

Then instead of generating join SQL, two queries are used for `@person.veterinarian`:

```
SELECT "dogs"."id" FROM "dogs" WHERE "dogs"."person_id" = ?  [["person_id", 1]]
SELECT "veterinarians".* FROM "veterinarians" WHERE "veterinarians"."dog_id" = ?  [["dog_id", 1]]
```

Co-authored-by: Eileen M. Uchitelle <eileencodes@gmail.com>
2021-05-07 09:00:42 -04:00
Alex Ghiculescu
867d27dd64 Active Record + PostgreSQL: native support for timestamp with time zone
In https://github.com/rails/rails/issues/21126 it was suggested to make "timestamp with time zone" the default type for datetime columns in PostgreSQL. This is in line with PostgreSQL [best practices](https://wiki.postgresql.org/wiki/Don't_Do_This#Don.27t_use_timestamp_.28without_time_zone.29). This PR lays some groundwork for that.

This PR adds a configuration option, `ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.datetime_type`. The default is `:timestamp` which preserves current Rails behavior of using "timestamp without time zone" when you do `t.datetime` in a migration. If you change it to `:timestamptz`, you'll get "timestamp with time zone" columns instead.

If you change this setting in an existing app, you should immediately call `bin/rails db:migrate` to ensure your `schema.rb` file remains correct. If you do so, then existing columns will not be impacted, so for example if you have an app with a mixture of both types of columns, and you change the config, schema dumps will continue to output the correct types.

This PR also adds two new types that can be used in migrations: `t.timestamp` and `t.timestamptz`.

```ruby
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.datetime_type = :timestamp # default value is :timestamp

create_table("foo1") do |t|
  t.datetime :default_format # "timestamp without time zone"
  t.timestamp :without_time_zone # "timestamp without time zone"
  t.timestamptz :with_time_zone # "timestamp with time zone"
end

ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.datetime_type = :timestamptz

create_table("foo2") do |t|
  t.datetime :default_format # "timestamp with time zone" <-- note how this has changed!
  t.timestamp :without_time_zone # "timestamp without time zone"
  t.timestamptz :with_time_zone # "timestamp with time zone"
end

ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::NATIVE_DATABASE_TYPES[:my_custom_type] = { name: "custom_datetime_format_i_invented" }
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.datetime_type = :my_custom_type

create_table("foo3") do |t|
  t.datetime :default_format # "custom_datetime_format_i_invented"
  t.timestamp :without_time_zone # "timestamp without time zone"
  t.timestamptz :with_time_zone # "timestamp with time zone"
end
```

**Notes**

- This PR doesn't change the default `datetime` format. The default is still "timestamp without time zone". A future PR could do that, but there was enough code here just getting the config option right.
- See also https://github.com/rails/rails/pull/41395 which set some groundwork (and added some tests) for this.
- This reverts some of https://github.com/rails/rails/pull/15184. https://github.com/rails/rails/pull/15184 alluded to issues in XML serialization, but I couldn't find any related tests that this broke.
2021-05-06 17:41:55 -05:00
John Bampton
6e85b6b86e Add spell checking with codespell as a GitHub Action
`codespell` works with a small custom dictionary and seems to find perhaps more spelling mistakes than `misspell` which really only fixes commonly misspelled English words.

Not all spell checkers can check all file types and most spell checkers can't find all the errors.

https://github.com/codespell-project/codespell
https://pypi.org/project/codespell/
2021-05-04 14:46:21 +10:00
Alberto Mota
afa83350de Deprecates Enumerable#sum and Array#sum
Ruby (2.4+) includes a native implementation of `sum` with significant
performance gains. Rails 7.1 will be removing `Enumerable#sum` and
`Array#sum` in favor of Ruby's native implementation.

This commit adds a deprecation warning to calls with non-numeric
arguments without a suitable initial argument as those will be required
once Rails removes this functionality.

Some examples that will now trigger a deprecation warning:
    >> %w[foo bar].sum
    >> [[1, 2], [3, 4, 5]].sum

To avoid the deprecation warning they should now invoked as follows:
    >> %w[foo bar].sum('')
    >> [[1, 2], [3, 4, 5]].sum([])

In order to prepare for the deprecation on Rails 7.1, it also
deprecates `[nil].sum == 0`, which in Ruby's native implementation
throws a `TypeError`.
2021-05-03 10:26:39 -07:00
Andrew White
ced1da9c8d
Merge pull request #42128 from flavorjones/flavorjones-clean-up-arel-visitor-dot
clean up Arel::Visitors::Dot
2021-05-03 17:41:26 +01:00
Mike Dalessio
d478b0f907
Arel::Visitors::Dot renders all attributes of some AST node types
These node types were missing some properties:

- SelectCore
- SelectStatement
- InsertStatement
- UpdateStatement
- DeleteStatement

Fixes #42026
2021-05-03 09:35:23 -04:00
Mike Dalessio
c4fc11a3b2
add support to Arel::Visitors::Dot for some missing AST node types
- Case
- CurrentRow
- Distinct
- InfixOperation
- NotRegexp
- Regexp
- UnaryOperation
- With

Also add test coverage for When and Else for which support was just
added in a previous commit in this changeset.

Also use assert_edge test helper for Arel::Visitors::Dot.
2021-05-03 09:31:28 -04:00
Jean Boussier
ca5542fed3 Cache and reuse generated attribute methods 2021-05-03 09:27:59 +02:00
Ryuta Kamizono
0cf198e94a
Merge pull request #42130 from ricardotk002/silence-assert-storage-performance
Modify `assert_storage_performance` to be quiet by default
2021-05-03 14:49:31 +09:00
Ricardo Díaz
8fd352749d Modify assert_storage_performance to be quiet by default
Even though encryption performance test have been ignored in 1fff866,
they're still included when using `bin/test` as the executable, and the
output could be confusing.

Following the approach used in ed8667d, this assertion is now quiet by
default.
2021-05-02 23:56:56 -05:00
Ryuta Kamizono
6951566f36 Fix add_foreign_key to prevent double prefix/suffix 2021-05-03 13:38:29 +09:00
Ryuta Kamizono
dd5886d00a Remove unused clear_association_cache
It is no longer used since #41112.
2021-05-03 12:13:19 +09:00
Ryuta Kamizono
f17386f8db Refactor schema creation to extract new_check_constraint_definition 2021-05-03 11:15:59 +09:00
Ryuta Kamizono
ecd4c846ba Refactor schema creation to extract new_foreign_key_definition 2021-05-03 10:55:09 +09:00
Ryuta Kamizono
11a3348c2d Fix isolated test failure in test/cases/adapters/mysql2/count_deleted_rows_with_lock_test.rb
`Bulb` has `belongs_to :car, touch: true`, so `Bulb.create!` requires
`Car` class.

https://buildkite.com/rails/rails/builds/77109#95e0e096-8999-4a03-8c69-ec6f02f99b6f/995-1003
2021-05-03 08:34:27 +09:00
Ryuta Kamizono
39c4e2b1e6 Fix isolated test failure
`Pet` has `belongs_to :owner, touch: true`, so `Pet.create` requires
`Owner` class.

https://buildkite.com/rails/rails/builds/77104#81b96744-ba91-40cc-a70a-982cc2a1e301/1191-1199
2021-05-03 07:59:47 +09:00
Alex Ghiculescu
db55159de1 Ensure association target classes exist
Fixes https://github.com/rails/rails/issues/42122

Currently if you call a reader on a singular association, no error is raised if the target class doesn't exist (it just returns `nil`). If you call a reader on a collection association an error is raised, but the error appears to not be intended for this case and doesn't have a very good message.

`ActiveRecord::Reflection::AssociationReflection#compute_class` appears to be set up to handle this, but it is not being called correctly. So this PR just makes a call to that (via `reflection.klass`) from `SingularAssociation#reader` and `CollectionAssociation#reader`.
2021-05-02 15:00:09 -05:00
Mike Dalessio
b3b1f5ffe1
use Arel::Visitors::Dot#visit_edge where it would simplify 2021-05-02 15:44:31 -04:00
Mike Dalessio
c2592ee251
Remove unnecessary method aliases from Arel::Visitors::Dot 2021-05-02 15:44:30 -04:00
Mike Dalessio
5640123d29
simplify Arel::Visitors::Dot
Instead of having many aliases for all the Arel::Nodes classes, rely
on generic methods for Unary, Binary, and Function (which is possible
because Arel::Visitors::Visitor#visit falls back to ancestors' visit
methods).

Note that a few new Node types are now implicitly supported that were
not previously explicitly supported, including:

- Bin
- DistinctOn
- Else
- Except
- Intersect
- Lock
- Quoted
- Union
- UnionAll
- When
2021-05-02 15:42:37 -04:00
Mike Dalessio
d803b9ae9b
un-extract the Arel visitor for SelectOptions
This does not need to be a separate method since a2040ee which removed
the Oracle12 visitor, and essentially reverses the Oracle prefactor
from 8d04c28.
2021-05-02 12:13:22 -04:00
Ryuta Kamizono
ab13f9549d Fix markup for the rdoc [ci skip] 2021-05-02 22:07:38 +09:00
Ryuta Kamizono
35bf079aed Update all Migration version references
Migration version references has been updated 2 times in less than 3
weeks (#41894, #42113).

I'd not want to receive the same tweaks in the near future.
2021-05-02 21:17:04 +09:00
Masataka Pocke Kuwabara
092bda9a2f
Describe unsafe usage of invert_where method [ci skip] 2021-05-01 23:44:15 +09:00
Ryuta Kamizono
3351347190 Fix typo mange -> manage [ci skip] 2021-05-01 16:18:02 +09:00
Jon Dufresne
bff3523242 Optimize remove_columns to use a single SQL statement when supported
Both MySQL and PostgreSQL support dropping multiple columns in a single
SQL statement.

For tables that are very large, dropping a column can be time consuming.
When multiple columns are involved, dropping them all at once can reduce
the total overhead when compared to dropping each column individually.

SQLite3 does not support this feature so its adapter overrides the
remove_columns method to workaround SQLite3's ALTER TABLE limitations.

The already written method remove_columns_for_alter creates the ALTER
TABLE SQL fragments to execute.

The remove_timestamps method also happens to drop multiple columns, so
it now uses the updated remove_columns to take advantage of the
optimization.
2021-04-30 15:00:59 -07:00
Rafael França
0b3a63fe07
Merge pull request #42064 from ashiksp/consistent-double-quotes
Used double quotes in template file for consistency.
2021-04-29 17:57:05 -04:00
Ashik Salman
68a9d6367e Used double quotes in template file for consistency. 2021-04-30 02:58:51 +05:30
Jorge Manrubia
93e4e83771 Rename "master key" -> "primary key" in Active Record encryption
There were a few spots pending after
28145c3ceefb35ae3df22f90ca7ea7c1eef0d340
2021-04-29 22:26:35 +02:00
Leo Correa
52c2fa992f
Test callback behavior when update_attribute in callback
As mentioned in https://github.com/rails/rails/pull/42002#issuecomment-822699276,
https://github.com/rails/rails/pull/41860 introduced a behavior change
in callbacks whenever `update_attribute` is called within a `before_*`
callback triggered by a `create` which caused `after_update` callbacks
to be triggered by the create.

This ensures once the revert is re-reverted we'll have properly
addressed the fix
2021-04-29 11:01:09 -04:00
Leo Correa
06e547d2ef
Test to prevent endless loop caused by changes to dirty attributes
The change introduced in https://github.com/rails/rails/pull/41860
triggered some endless loops which is now reverted by e424c41512e8779663c1bcd222b31c272af811ca

This test is just to ensure the behavior is documented once we address
both the endless loop and behavior change around update callbacks
mentioned https://github.com/rails/rails/pull/42002#issuecomment-822699276
2021-04-29 11:01:09 -04:00
Leo Correa
2d325c670c
Revert "Only update dirty attributes once for cyclic autosave callbacks"
This reverts commit ae56ecd467367e3520a5232d8c38264bfe9d173c.
2021-04-29 11:01:06 -04:00
Rafael Mendonça França
d6895fb8b4
Register autload for Deduplicable
This module is used in many classes but only required in one of them.
Depending in the load order, it could be undefined before its first use.

Instead of adding requires to every single files that use it I
registered an autoload entry for it.
2021-04-28 03:37:07 +00:00
Eugene Kenny
217f0e81d1 Add test coverage for bulk altering timestamps 2021-04-28 03:30:01 +01:00
Jean Boussier
ed8667df5c Silence assert_slower_by_at_most by default
Tests shouldn't have any output if they pass.
2021-04-27 09:34:43 +02:00
eileencodes
3328cd1d69
Ensure reload re-applies preload values for strict loading
If you have an application that has strict_loading set and then call
`reload` that would cause the preload values to get lost and
applications would start throwing a stict loading violation error.

In order to fix this we capture the association cache and re-apply that
to the reloaded records to avoid the strict loading error. Of course if
you never preloaded your records, this will still raise a strict loading
violation.

This change also removes the `reload` definition from associations.rb
because we can get the same behavior when we reassign the association
cache.

Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
2021-04-26 15:45:39 -04:00
Eileen M. Uchitelle
ba1ec19013
Merge pull request #42060 from Tonkpils/tonkpils/fix-enlist-fixture-connections
Ensure variables are set in case enlist_fixture_connections is called
2021-04-26 09:35:25 -04:00
Chris Salzberg
883292fdca
Make changes_applied public again
This was (accidentally?) made private, whereas previously it was public.
2021-04-25 22:58:46 +09:00
Ryuta Kamizono
2d040e756e Fix typo s/PostgresSQL/PostgreSQL/ [ci skip] 2021-04-25 20:09:39 +09:00
Ryuta Kamizono
90db24436a Fix typo s/limitions/limitations/ [ci skip] 2021-04-25 20:04:57 +09:00
Eugene Kenny
79744bc335 Fix fixture tests that replace connection handler
These tests have been failing intermittently since
054e19d08638e64fa9eacc9be32fb7fde4e7415c was merged.

They replace the connection handler during setup, but before that can
happen the existing handler's pool configuration has already been saved
by `setup_shared_connection_pool`. Later when the test calls
`teardown_shared_connection_pool`, it tries to restore connection pools
that do not exist in the new handler and blows up.

We can avoid this problem by calling `teardown_shared_connection_pool`
to clear the saved pools before replacing the connection handler.
2021-04-25 01:27:06 +01:00
Ryuta Kamizono
bbbc861f71 Enable Performance/MapCompact cop
Follow up to #42053.
2021-04-23 16:33:02 +09:00
Rafael França
7d88c8657d
Merge pull request #42053 from MatheusRich/replace-map-compact-with-filter-map
Replace `map + compact` with `filter_map`
2021-04-22 22:06:16 -04:00
Matheus Richard
63e7ef6fe1 Replace gsub with tr 2021-04-22 22:31:49 -03:00
Matheus Richard
c3d7794f16 Replace map + compact with filter_map 2021-04-22 22:08:34 -03:00
Leo Correa
e088454bca
Ensure variables are not nil in case enlist_fixture_connections is
called

enlist_fixture_connections is currently called within the code when the
context is `run_in_transasction?`. However if
`enlist_fixture_connections` is called outside of that context the code
fails since these variables are not defined. This ensures the code can
still be executed without side effects
2021-04-22 13:45:15 -04:00
Jorge Manrubia
6107209361 Add test to validate that ciphertext is returned when all previous schemes fail 2021-04-22 08:03:48 -04:00
Jorge Manrubia
9b7aafac98 Extract helper method for common logic across tests 2021-04-22 08:03:48 -04:00
Jorge Manrubia
30b96c7cf3 Add missing text for encryption exception raising 2021-04-22 08:03:48 -04:00
Jorge Manrubia
e249fb8817 We want to check previous_types ignoring clean text type here
This wasn't causing any issue because the behavior was virtually the
same (returning the ciphertext), but it was confusing to read.
2021-04-22 08:03:48 -04:00
Jorge Manrubia
9ed49b76fb Rename previous_types_including_clean_text => previous_types
It's make more sense to revert the naming approach:

- `#previous_types`, the exposed public method, always include the clean
 text type when suport for unencrypted data is enabled
- `#previous_types_without_clean_text` is a private method used
internally by the type
2021-04-22 08:03:48 -04:00
Eugene Kenny
2c79d2b260 Don't remove pool managers for test classes
These models have their own connections since
8b83793549fed994bf0231aff444aa74648b3c35.

Removing them was breaking 054e19d08638e64fa9eacc9be32fb7fde4e7415c in a
way that couldn't happen in a real app: pool managers are never removed,
except by this test helper.
2021-04-22 00:55:51 +01:00
Rafael França
9dc692bdc0
Merge pull request #42044 from basecamp/fix-are-multiple-schemes
Fix: use previous encryption schemes when support_unencrypted_data is on
2021-04-21 17:46:44 -04:00
Jorge Manrubia
b908c8876e Split method with boolean argument into two to improve clarity
We were using the same method for 2 things: fetching previous types, and
fetching previous types with the cleantext type. This was making logic
harder to follow.
2021-04-21 23:28:29 +02:00
Eugene Kenny
19a4bfda7f
Merge pull request #40384 from eugeneius/teardown_shared_connection_pool
Restore connection pools after transactional tests
2021-04-21 22:03:19 +01:00
Jorge Manrubia
26b4da371b Fix: use previous encryption schemes when support_unencrypted_data is on
This fixes a problem in Active Record Encryption where, when `config
.support_unencrypted_data` was on, it was failing to try additional
previous encryption schemes beyond the first one.

The reason is that, witwh the previous implementation, when this flag
was toggled on, it was never raising encryption errors when checking
previous types.
2021-04-21 22:40:01 +02:00
Rafael Mendonça França
6175549eaf
Setup autoload on SchemaCache
Since b71c1cddddea736ae5af70474fe9bd765596e727, the SchemaCache
is loaded during the application initialization before the connection
adapter is loaded, which means that the application could fail to boot.

To fix this issue an autoload is setup for the schema cache and the
direct require is removed.

This autoload doesn't need to be moved to `eager_autoload` block
because the constant is already referenced in an initializer.
2021-04-21 17:52:52 +00:00
Aidan Haran
0e77fa57f7 Remove requirement that SQL starts with SELECT 2021-04-21 10:11:38 +01:00
Jean Boussier
de3d1dd8f9
Merge pull request #42015 from Shopify/refactor-inheritance-column
Make ModelSchema.inheritance_column a class_attribute
2021-04-20 19:48:38 +02:00
Ryuta Kamizono
5d7b86b698
Merge pull request #42023 from caffkane/remove-unused-ar-disable-join-constant
Remove unused constant from disable_joins_association_relation
2021-04-20 17:51:45 +09:00
Ryuta Kamizono
f02a136f89 Merge pull request #41990 from p8/autosave-association-callbacks-get-called-once
Ensure has_one autosave association callbacks get called once
2021-04-20 17:50:16 +09:00
Logan Kane
6f23b69a1e Remove unused constant from disable_joins_association_relation 2021-04-19 22:26:33 -07:00
Yasuo Honda
662f7c14c6 Address non-deteristic CI failure of HasManyThroughDisableJoinsAssociationsTest
Addressed CI failure at https://buildkite.com/rails/rails/builds/76751#fa683e3c-b213-4474-8faf-dd37e6444b76
and modified two tests to avoid similar failures.

- HasManyThroughDisableJoinsAssociationsTest#test_to_a_on_disable_joins_through

```
Failure:
HasManyThroughDisableJoinsAssociationsTest#test_to_a_on_disable_joins_through [/rails/activerecord/test/cases/associations/has_many_through_disable_joins_associations_test.rb:71]:
--- expected
+++ actual
@@ -1 +1 @@
-[#<SpecialComment id: 11, post_id: 7, body: "go crazy", type: "SpecialComment", label: "default", tags_count: 0, children_count: 0, parent_id: nil, author_type: nil, author_id: nil, resource_id: nil, resource_type: nil, origin_id: nil, origin_type: nil, developer_id: nil, updated_at: "2021-04-19 22:54:11.359941000 +0000", deleted_at: nil, comments: nil, company: nil>, #<Comment id: 71, post_id: 65, body: "text", type: nil, label: "default", tags_count: 0, children_count: 0, parent_id: nil, author_type: nil, author_id: nil, resource_id: nil, resource_type: nil, origin_id: 70, origin_type: "Member", developer_id: nil, updated_at: "2021-04-19 22:54:12.138620000 +0000", deleted_at: nil, comments: nil, company: nil>, #<Comment id: 70, post_id: 64, body: "text", type: nil, label: "default", tags_count: 0, children_count: 0, parent_id: nil, author_type: nil, author_id: nil, resource_id: nil, resource_type: nil, origin_id: 69, origin_type: "Member", developer_id: nil, updated_at: "2021-04-19 22:54:12.131832000 +0000", deleted_at: nil, comments: nil, company: nil>]
+[#<SpecialComment id: 11, post_id: 7, body: "go crazy", type: "SpecialComment", label: "default", tags_count: 0, children_count: 0, parent_id: nil, author_type: nil, author_id: nil, resource_id: nil, resource_type: nil, origin_id: nil, origin_type: nil, developer_id: nil, updated_at: "2021-04-19 22:54:11.359941000 +0000", deleted_at: nil, comments: nil, company: nil>, #<Comment id: 70, post_id: 64, body: "text", type: nil, label: "default", tags_count: 0, children_count: 0, parent_id: nil, author_type: nil, author_id: nil, resource_id: nil, resource_type: nil, origin_id: 69, origin_type: "Member", developer_id: nil, updated_at: "2021-04-19 22:54:12.131832000 +0000", deleted_at: nil, comments: nil, company: nil>, #<Comment id: 71, post_id: 65, body: "text", type: nil, label: "default", tags_count: 0, children_count: 0, parent_id: nil, author_type: nil, author_id: nil, resource_id: nil, resource_type: nil, origin_id: 70, origin_type: "Member", developer_id: nil, updated_at: "2021-04-19 22:54:12.138620000 +0000", deleted_at: nil, comments: nil, company: nil>]
```

- HasManyThroughDisableJoinsAssociationsTest#test_pluck_on_disable_joins_through
Reproduced one time at local environment.

```ruby
...........F

Failure:
HasManyThroughDisableJoinsAssociationsTest#test_pluck_on_disable_joins_through [/home/yahonda/src/github.com/rails/rails/activerecord/test/cases/associations/has_many_through_disable_joins_associations_test.rb:47]:
Expected: [31, 11, 32]
  Actual: [11, 31, 32]

bin/test test/cases/associations/has_many_through_disable_joins_associations_test.rb:46

```

-  HasManyThroughDisableJoinsAssociationsTest#test_pluck_on_disable_joins_through_using_custom_foreign_key

Were not reproduced locally but it could also fail due to
non-determistic order.
2021-04-20 11:56:34 +09:00
eileencodes
de6b4efa3e
Add option to skip joins for associations.
In a multiple database application, associations can't join across
databases. When set, this option tells Rails to make 2 or more queries
rather than using joins for associations.

Set the option on a has many through association:

```ruby
class Dog
  has_many :treats, through: :humans, disable_joins: true
  has_many :humans
end
```

Then instead of generating join SQL, two queries are used for `@dog.treats`:

```
SELECT "humans"."id" FROM "humans" WHERE "humans"."dog_id" = ?  [["dog_id", 1]]
SELECT "treats".* FROM "treats" WHERE "treats"."human_id" IN (?, ?, ?)  [["human_id", 1], ["human_id", 2], ["human_id", 3]]
```

This code is extracted from a gem we use internally at GitHub which
means the implementation here is used in production daily and isn't
experimental.

I often get the question "why can't Rails do this automatically" so I
figured I'd include the answer in the commit. Rails can't do this
automatically because associations are lazily loaded. `dog.treats` needs
to load `Dog`, then `Human` and then `Treats`. When `dog.treats` is
called Rails pre-generates the SQL that will be run and puts that
information into a reflection object. Because the SQL parts are pre-generated,
as soon as `dog.treats` is loaded it's too late to skip a join. The join
is already available on the object and that join is what's run to load
`treats` from `dog` through `humans`. I think the only way to avoid setting
an option on the association is to rewrite how and when the SQL is
generated for associations which is a large undertaking. Basically the
way that Active Record associations are designed, it is currently
impossible to have Rails figure out to not join (loading the association
will cause the join to occur, and that join will raise an error if the
models don't live in the same db).

The original implementation was written by me and Aaron. Lee helped port
over tests, and I refactored the extraction to better match Rails style.

Co-authored-by: Lee Quarella <leequarella@gmail.com>
Co-authored-by: Aaron Patterson <aaron@rubyonrails.org>
2021-04-19 11:17:31 -04:00
Jean Boussier
5877562f56 Make ModelSchema.inheritance_column a class_attribute
Ultimately it's exactly the same semantic that was implemented
using `superclass`, except it avoid recursion and benefit from
method cache, so much faster the longer the inheritance chain.

The use of an alias_method chain is unfortunate, but I don't
see any alternative to cast the provided value to string.
2021-04-19 11:17:39 +02:00
Ryuta Kamizono
9a263e9a0f
Merge pull request #42001 from ricardotk002/fix-encrypted-fixtures-test
Fix test `EncryptableFixtureTest` that fails intermittently
2021-04-17 13:10:01 +09:00
Ricardo Díaz
edc481a66d Fix test EncryptableFixtureTest that fails intermittently
Reference:

https://buildkite.com/rails/rails/builds/76506#f42a5ab3-1923-4a9f-b843-56c4098b6bef
https://buildkite.com/rails/rails/builds/76590#04721d73-9505-4c29-82bf-0a1be1f41649
https://buildkite.com/rails/rails/builds/76556#aa284ad0-0eab-48e9-a50b-60e3b5c7ccac

Apparently when loading different fixtures that reference the same
table, the files that are loaded last run a `DELETE FROM` statement
that removes previous data.

Reproduction command using `minitest_bisect`:

```
activerecord $ bin/test -a mysql2 --seed 22031 -n "/^(?:ActiveRecord::Encryption::EncryptableRecordTest#(?:test_when_downcase:_true_it_creates_content_downcased)|ActiveRecord::Encryption::EncryptableFixtureTest#(?:test_fixtures_get_encrypted_automatically))$/"
```
2021-04-16 13:06:05 -05:00
Ashik Salman
8e1b191b37 Updated abbreviation for single table inheritance. 2021-04-16 11:53:05 +05:30
Rafael Mendonça França
6d624c648c
Make sure the config values is set back to the original value
If the test fails the config should be reset as well.
2021-04-15 23:36:26 +00:00
Rafael Mendonça França
7b198e6024
Copy edit #41718 2021-04-15 23:34:30 +00:00
Rafael França
7ce853ecb0
Merge pull request #41718 from dzunk/enumerate_columns
Add setting for enumerating column names in SELECT statements
2021-04-15 19:28:41 -04:00
Rafael Mendonça França
8f07a124ef
Eager load ActiveRecord::StatementCache 2021-04-15 22:09:21 +00:00
Petrik
2a786431e2 Ensure has_one autosave association callbacks get called once
When saving a record, autosave adds callbacks to save its' associations.
Since the associations can have similar callbacks for the inverse,
endless loops could occur.

To prevent these endless loops, the callbacks for `has_many` and
`belongs_to` are defined as methods that only execute once.
This is implemented in the `define_non_cyclic_method` method.
However, this wasn't used for the `has_one` callbacks.

While `has_one` association callbacks didn't result in endless loops,
they could execute multiple times.
For example for a bidirectional `has_one` with autosave enabled,
the `save_has_one_association` gets called twice:

    class Pirate < ActiveRecord::Base
      has_one :ship, autosave: true

      def save_has_one_association(reflection)
        @count ||= 0
        @count += 1 if reflection.name == :ship
        super
      end
    end

    class Ship < ActiveRecord::Base
      belongs_to :pirate, autosave: true
    end

    pirate = Pirate.new(catchphrase: "Aye")
    pirate.build_ship(name: "Nights Dirty Lightning")
    pirate.save!
    # this returns 2 instead of 1.
    assert_equal 1, pirate.instance_variable_get(:@count)

This commit changes `has_one` autosave callbacks to be non-cyclic as
well. By doing this the autosave callback are made more consistent for
all 3 cases: `has_many`, `has_one` and `belongs_to`.
2021-04-15 22:30:59 +02:00
Eileen M. Uchitelle
80a23227ea
Merge pull request #41839 from abhaynikam/fix-return-type-for-strict-loading
ActiveRecord#strict_loading! should return boolean instead of current mode set.
2021-04-15 08:49:33 -04:00
Abhay Nikam
b841b2a84e Adds documentation for strict_loading_n_plus_one_only? [ci skip] 2021-04-15 10:35:11 +05:30
Abhay Nikam
2629f48ced ActiveRecord#strict_loading! should return boolean instead of mode set.
The return type was changed in the PR #41704 after addition of mode
option. The current documentation is misleading since
documentation puropose strict_loading! would return boolean whereas
it returns the current mode set.

I can across this issue while debugging issue: #41827 and thought
this should be brought to the attention.

PR fixes the issue and would always return boolean based on
strict_loading is enabled or disabled.

```
user.strict_loading! # => true
user.strict_loading!(false) # => false
user.strict_loading!(mode: :n_plus_one_only) # => true
```
2021-04-15 10:22:18 +05:30
John Bampton
cf05afc990 chore: fix spelling 2021-04-15 14:14:59 +10:00
John Bampton
5afc11f897 chore: fix spelling 2021-04-15 12:32:57 +10:00
Matt Duszynski
726abeaab4 Add setting for enumerating column names in SELECT statements 2021-04-14 15:48:17 -07:00
Rafael França
16c0f388be
Merge pull request #41860 from p8/fix-previously-saved-for-autosaved-record
Only update dirty attributes once for cyclic autosave callbacks
2021-04-14 16:05:28 -04:00
Bastian Bartmann
0daf81f69a upsert_all fails cleanly for MySQL 2021-04-14 19:33:42 +02:00
Zachary Scott
43e29f0f5d
Merge pull request #41945 from jbampton/fix-grammar
chore: fix grammar, spelling and minor whitespace fix
2021-04-14 09:19:15 +09:00
Petrik
ae56ecd467 Only update dirty attributes once for cyclic autosave callbacks
Calling save on a record with cyclic autosave callbacks, can call other
callbacks and hooks multiple times. This can lead to unexpected
behaviour.

For example `save` gets called twice on Post in the following example.
This results in `changes_applied` getting called twice.

    class Post < ApplicationRecord
      belongs_to :postable, polymorphic: true, inverse_of: :post
    end

    class Message < ApplicationRecord
      has_one :post, as: :postable
    end

    post = Post.create!(postable: Message.new(subject: "Hello, world!"))
    # the following would return false when true is expected
    post.id_previously_changed?

`save` gets called twice because Post autosaves Message, which
autosaves Post again.

Instead of calling `changes_applied` everytime `save` is called,
we can skip it if it has already been called once in the current saving
cycle. This requires us to track the `@_saving` state of a record.
if `@_saving` is true we know we the record is being saved.

To track if a method has already been called we reuse the
@_already_called hash that is already used for this purpose.
2021-04-13 21:39:29 +02:00
Petrik
406374de09 Add regression test for #41714
Commit a1a5d37749964b1e1a23914ef13da327403e34cb tried to fix doubles
saves in autosaved associations. However, it didn't work properly for
non-nullable foreign_keys and had to be reverted.

To prevent this in the future, add a regression test.
2021-04-13 20:45:13 +02:00
Rafael Mendonça França
94b954576a
Autocorrect Rubocop roles 2021-04-13 18:32:25 +00:00
Ryuta Kamizono
e68cd6fe96 Remove unused HstorePair constant
It is no longer used since 98bf64bcb9648f88bff4cb59a7ae4db2b6410241.
2021-04-14 00:51:36 +09:00
John Bampton
a0b8ac3eb2
Fix spelling in HasOneAssociationsTest 2021-04-13 10:46:55 -04:00
Jean Boussier
67c0f9aa25
Merge pull request #41930 from Shopify/optimize-hstore-parser
Optimize the HStore parser
2021-04-13 15:46:26 +02:00
Andrew White
98bf64bcb9 Use StringScanner to parse Hstore payloads 2021-04-13 15:32:09 +02:00
John Bampton
c5fe7b8d9a
Fix spelling in AsynchronousQueryInsideTransactionError docs [ci skip] 2021-04-13 09:17:47 -04:00
John Bampton
33baf0dabd
Fix spelling of EnvelopeEncryptionPerformanceTest 2021-04-13 09:17:11 -04:00
Jorge Manrubia
170bc08eae Remove fixed "id" in encrypted book fixtures
Hopefully this will help with flaky encrypted_fixture_test failing from
time to time due to not finding book with id=1.
2021-04-13 08:55:44 -04:00
Jorge Manrubia
ae7f693647 Fix: assign previous encryption schemes via previous: config option.
The previous: config option was being skipped because it was checking
the existence of a reader method instead of the accessor itself.

This also adds a test for the .configure option that was missing.
2021-04-13 08:55:44 -04:00
John Bampton
bf79740600
Fix spelling in Encryptor.encrypt docs [ci skip] 2021-04-13 08:39:38 -04:00
John Bampton
97cf9c21fb
Fix spelling in EncryptionSchemesTest 2021-04-13 08:39:01 -04:00
John Bampton
54e526e473 chore: fix grammar, spelling and minor whitespace fix 2021-04-13 21:35:50 +10:00
John Bampton
285d7d4eaf docs: change user name to the more used username
Remove an unneeded comma
2021-04-13 15:54:49 +10:00
Rafael Mendonça França
14bca25975
Make sure establish_connection with symbol work properly
Before when calling `preventing_writes?` in the connection the code
would raise a `NoMethodError` when calling `current_preventing_writes`
in a String.

This problem only happen when `establish_connection` is called on the
`ConnectionHandler` and not in the model itself.

This also removes the conditional from the `PoolConfig`.
2021-04-12 22:27:16 +00:00
Jean Boussier
6a5fb7dbd4
Merge pull request #41911 from Shopify/simplify-proxy-call
Allow to pass the method signature when defining attribute methods
2021-04-12 22:36:32 +02:00
Rafael França
a18f8a9a17
Merge pull request #41899 from sebastian-palma/add-for-docs
Add QueryMethods#for docs [ci skip]
2021-04-12 16:23:36 -04:00
Rafael França
32db8149ed
Merge pull request #41926 from jbampton/fix-favorite
chore: fix spelling change `favourite` to the more used `favorite`
2021-04-12 16:14:56 -04:00
Rafael França
b171b842da
Merge pull request #41933 from palkan/feat/upsert-all-returning-update-sql
Add ability to provide raw SQL as returning and update to #upsert_all
2021-04-12 15:29:52 -04:00
Rafael Mendonça França
4354e3ae49
Don't define methods using the method modifier in the same line as the method
Our style guide use block method modifiers, not inline method modifiers.
2021-04-12 18:49:54 +00:00
Vladimir Dementyev
4bef82217c Force Arel.sql for returning and on_duplicate 2021-04-12 20:23:46 +03:00
Vladimir Dementyev
8f3c12f880 Add update_sql option to #upsert_all 2021-04-12 19:09:17 +03:00
Vladimir Dementyev
c7613dde53 Support string returning clause for AR#insert_all
(cherry picked from commit 15b3310a4d6b2044da4ff79737e2b19fef9b6267)
2021-04-12 18:08:04 +03:00
Ryuta Kamizono
9aed3dcdfe Remove unused Category.has_and_belongs_to_many :popular_grouped_posts definition
This was added at 97403ad but it was never used.
2021-04-12 15:05:42 +09:00
John Bampton
11557e6cec chore: fix spelling change favourite to the more used favorite 2021-04-12 12:35:12 +10:00
Ryuta Kamizono
b8c67807b4
Merge pull request #41898 from kamipo/delete_all_payload_name
Improve the payload name for `delete_all` to more appropriate
2021-04-12 07:34:11 +09:00
Ryuta Kamizono
54979ffa25
Merge pull request #41916 from jbampton/fix-spelling
chore: fix grammar and spelling
2021-04-12 07:26:23 +09:00
Ryuta Kamizono
f06c94190c
Merge pull request #41913 from jbampton/remove-trailing-whitespace
chore: remove unneeded trailing whitespace
2021-04-12 07:18:19 +09:00
John Bampton
13b1d9dc35 chore: fix grammar and spelling 2021-04-12 05:30:44 +10:00
Jean Boussier
9ef7f406e6 Optimize the HStore parser
Test string from taken from the the test suite: `"\"a\\\\b\"=>\"b\\\\ar\", \"1\\\"foo\"=>\"2\""`

Bench:

```
Warming up --------------------------------------
            original     6.896k i/100ms
             patched    15.787k i/100ms
Calculating -------------------------------------
            original     68.176k (± 1.2%) i/s -    344.800k in   5.058270s
             patched    157.786k (± 1.0%) i/s -    789.350k in   5.003144s

Comparison:
             patched:   157786.0 i/s
            original:    68176.1 i/s - 2.31x  (± 0.00) slower

```

Memory before: allocated 4376 bytes (55 objects)
Memory after: allocated: 1880 bytes (23 objects)
2021-04-11 21:11:21 +02:00
John Bampton
6cf394c236 chore: fix i.e. typos in Markdown and Ruby
i.e. is the customary abbreviation for "that is." It is derived from the Latin term "id est."
2021-04-12 03:30:55 +10:00
John Bampton
c757ab2efe chore: remove unneeded trailing whitespace 2021-04-12 01:44:46 +10:00
Jean Boussier
eece095765 Allow to pass the method signature when defining attribute methods
This saves some array allocations from avoiding `*args`, as well
as makes the Method object `arity` and `parameters` correct.

e.g. before this patch, ArgumentError would be confusing:

```ruby
>> model.name_was(1)
ArgumentError: wrong number of arguments (given 2, expected 1)
```
2021-04-11 17:03:25 +02:00
Jean Boussier
3f59640016 Stop checking if ruby2_keywords is defined 2021-04-11 13:42:02 +02:00
Jean Boussier
8c580d716f Reset base_class when the model class is duped or cloned 2021-04-11 11:06:16 +02:00
Jean Boussier
7abd9b5f66 Precompute Inheritance.base_class
This saves checking the inehritance chain on
each access.
2021-04-11 08:40:51 +02:00
Sebastián Palma
3db607096d Add QueryMethods#for docs [ci skip] 2021-04-10 19:17:23 +02:00
Ryuta Kamizono
99049262d3 Clear @cache_keys cache even when eager loading
Follow up to #41789.
2021-04-10 21:28:28 +09:00
Ryuta Kamizono
899ecd4186 Improve the payload name for delete_all to more appropriate
The payload name for `delete_all` was named "Destroy" in #30619 since
`delete_all` was used in `record.destroy` at that time.

Since ea45d56, `record.destroy` no longer relies on `delete_all`, so now
we can improve the payload name for `delete_all` to more appropriate.
2021-04-10 20:19:53 +09:00
Ryuta Kamizono
b576dd02af Fix user-defined self.default_scope to respect table alias
If a model which has a user-defined `self.default_scope` is joined with
table alias, a user-defined `self.default_scope` ignores table alias.

This problem has potentially existed for a long time, but it has not
become apparent because it is difficult to meet this condition.

Since #40106, table alias is easily used if association names are used
in `where`.

So user-defined `self.default_scope` should be evaluated in the current
aliased relation.

Fixes #41857.
2021-04-09 19:43:56 +09:00
John Hawthorn
82b958a222 Add more methods to NullPool
This commit adds more empty methods to a connection pool.

In normal usage, a connection is always be associated with a pool, but
for testing (we do this a few places in the AR test suite) it can be
convenient to build a connection and use it without associating a pool.

In most cases, this worked fine, but there were a few corner cases which
would hit NoMethodError on the NullPool. In particular in some cases
raising in a transaction would error in connection.throw_away!.

To make these "standalone" or "pool-less" connections work consistently,
this commit adds the methods which a connection could call on it's pool
(but not any other of ConnectionPool's public interface).
2021-04-08 10:58:07 -07:00
Aaron Patterson
f95c0b7e96
Merge pull request #41825 from rails/refactor-scope-registry
Refactor scope registry
2021-04-08 08:53:36 -07:00
Jean Boussier
57cbf4136f
Merge pull request #41866 from etiennebarrie/simplify-active-model-record-registry
Simplify ActiveModel & ActiveRecord Type::Registry
2021-04-07 21:31:37 +02:00
Étienne Barrié
81d0653f84 Simplify ActiveModel & ActiveRecord Type::Registry
ActiveRecord::Type::Registry doesn't need to inherit from
ActiveModel::Type::Registry, and it makes both classes more simple.

Co-authored-by: Adrianna Chang <adrianna.chang@shopify.com>
2021-04-07 09:59:55 -04:00
eileencodes
b8b1c9eba9
Fix missing link in deprecation 2021-04-07 08:15:48 -04:00
Ryuta Kamizono
7fd8079ef2
Merge pull request #41789 from kamipo/update_cache_key_after_mutation
Clear `@cache_keys` cache after `update_all`, `delete_all`, `destroy_all`
2021-04-07 16:47:17 +09:00
Ryuta Kamizono
bc488431ae
Merge pull request #41788 from pbstriker38/check_table_name_constraint_mariadb
Add support for check_constraints with the same name on different tables
2021-04-07 09:16:59 +09:00
eileencodes
634bf89df3
Deprecate legacy_connection_handling
This deprecates `legacy_connection_handling` via the
`connection_handlers` setter. This is called from the ActiveRecord
Railtie on boot and since most applications don't set this themselves
this will prevent the deprecation from being raised multiple times for a
test run or in development.

I've also updated the guides to include a migration path for
applications using the deprecated methods. The majority of applications
won't need to make any changes.
2021-04-06 18:57:22 -04:00
John Hawthorn
23996030ba Fix build 2021-04-06 11:13:33 -07:00
John Hawthorn
0ff395e1b1
Merge pull request #41790 from jhawthorn/preloader_smart_batching
"Smart" ActiveRecord Preloader batching
2021-04-05 10:14:07 -07:00
Jorge Manrubia
1fff866dd1 Exclude encryption performance tests from isolated runs
Encryption performance tests were meant to be excluded from the builds,
however they were still being executed when running `isolated:` tests
for active record adapters.

See https://buildkite.com/rails/rails/builds/76249#e7605d50-87be-445e-a9ae-a5761c996597/1512-1531
2021-04-03 23:11:30 +02:00
George Claghorn
432bc68a2c Fix more Book references.
Follow-up to 434fb39.
2021-04-03 08:31:59 -04:00
George Claghorn
b4120d0a30 Fix lingering references to Book
Follow-up to 434fb39.
2021-04-03 08:20:42 -04:00
Ricardo Díaz
434fb39d47
Add new "encrypted_books" table to the schema
Reusing the "books" one could cause interferences when fixtures are
loaded in a very specific order such as:

https://buildkite.com/rails/rails/builds/76217#ee4ce591-e6c1-4a0d-a7db-1f83647d141e

Reproduction script:

```
activerecord $ bin/test -v --seed 23607 -n "/^(?:EagerAssociationTest#(?:test_preloading_a_regular_association_with_a_typo_through_a_polymorphic_association_still_raises)|ActiveRecord::Encryption::EncryptableFixtureTest#(?:test_fixtures_get_encrypted_automatically)|ViewWithoutPrimaryKeyTest#(?:test_attributes|test_reading))$/"
```
2021-04-03 08:00:01 -04:00
Aaron Patterson
8af85e161d
Reduce the number of times we look up the ScopeRegistry
I noticed in profiles of simple queries (like `Post.where(id: 1).first`)
we're spending lots of time looking up the current thread.  I couldn't
find any way to speed this up in Ruby, so I thought maybe we could call
`Thread.current` fewer times per query.

This patch should eliminate 4 calls to `Thread.current` per query.

For this benchmark:

```ruby
  StackProf.run(mode: :wall, out: 'out.dump') do
    8000.times { Post.where(id: id).first }
  end
```

`Thread.current` goes from 7% to 4.7% of time:

```
==================================
  Mode: wall(1000)
  Samples: 1633 (0.00% miss rate)
  GC: 51 (3.12%)
==================================
     TOTAL    (pct)     SAMPLES    (pct)     FRAME
       140   (8.6%)         140   (8.6%)     String#sub!
       114   (7.0%)         114   (7.0%)     Thread.current
```

```
==================================
  Mode: wall(1000)
  Samples: 1719 (0.00% miss rate)
  GC: 51 (2.97%)
==================================
     TOTAL    (pct)     SAMPLES    (pct)     FRAME
       134   (7.8%)         134   (7.8%)     String#sub!
        99   (5.8%)          99   (5.8%)     Module#===
        81   (4.7%)          81   (4.7%)     Thread.current
```

This isn't huge, but I think we need to find more sources of
Thread.current.  It's surprising to me that we spend so much time
looking up the current thread when doing a query that is so "easy"
2021-04-02 12:31:05 -07:00
Aaron Patterson
73c18888ad
Use methods to get ScopeRegistry values rather than symbols
We're spending time validating symbol parameters of the ScopeRegistry.
It's an internal class, and we can stop validating symbols by converting
to methods (you'll automatically get an error if you try to call a
method that doesn't exist).  Second, since we only have 3 things to keep
track of, rather than keep those things in a hash, just break it out in
to 3 instance variables.  (This is absolutely not a memory bottleneck,
but technically this patch will save some memory as the 3 ivars will be
embedded in the object rather than require a full st_table for the
original wrapper hash)
2021-04-02 12:14:57 -07:00
Jorge Manrubia
224c9b34cb
Add Active Record encryption to CHANGELOG 2021-04-02 07:40:00 -04:00
Ryuta Kamizono
7e1820d71b
Merge pull request #41818 from ricardotk002/fix-missing-require
Fix seemingly wrong require "lib"
2021-04-02 19:56:11 +09:00
Ricardo Díaz
27b0180232 Remove print statement / uncomment relevant assertion 2021-04-02 01:03:43 -05:00
Ricardo Díaz
b11645eb2b Fix wrong require
This library is used here

https://github.com/rails/rails/blob/1251703/activerecord/lib/active_record/encryption/encryptor.rb#L121

and here

https://github.com/rails/rails/blob/1251703/activerecord/lib/active_record/encryption/encryptor.rb#L135

Reference https://buildkite.com/rails/rails/builds/76198#de7db4af-b8ca-46de-986f-0db34b1d4ddc
2021-04-02 01:00:37 -05:00
Sampat Badhe
2032daa415
Fix typos encryption doc (#41817)
* fix typo

[ci skip]
2021-04-02 14:24:43 +09:00
Jorge Manrubia
5a6352c072 Fix deterministic queries that were broken after #41068
This is adding yet another patch to make them work. This system needs to
be reworked as it's currently very brittle.
2021-04-01 22:10:59 +02:00
John Hawthorn
20b9bb1de0 Intelligent batch preloading
This examines all the association branches we are being asked to preload
and will delay loading an association if it's likely that we find a
similar association later and can batch them together.

For example, when loading

    Author.preload(:posts, favorite_authors: :posts).first

The preloader now knows to delay loading the top level posts so that it
can load both the top level :posts and the :posts from the favourite
authors associations together.

Co-authored-by: Dinah Shi <dinahshi@github.com>
2021-04-01 12:52:43 -07:00
Jorge Manrubia
e24fb5524a Validate that proper keys are configured when declaring attributes
This enables to disable deterministic encryption by just not setting
deterministic_key.
2021-04-01 18:20:54 +02:00
Jorge Manrubia
2035138115 Use proper hook for loading fixtures extension 2021-04-01 15:02:15 +02:00
Jorge Manrubia
a61692cf41 Add support for uniqueness validations 2021-04-01 15:02:15 +02:00
Jorge Manrubia
f78a480818 Encourage deterministic encryption to remain unchanged
This implements several changes to encourage deterministic encryption to
remain unchanged. The main motivation is letting you define unique
indexes on deterministically-encrypted columns:

- By default, deterministic encryption will always use the oldest
encryption scheme to encrypt new data, when there are many.
- You can skip this default behavior and make it always use the current
encryption scheme with:

```ruby
deterministic: { fixed: false } # using this should be a rare need
```

- Deterministic encryption still supports previous encryption schemes
normally. So they will be used to add additional values to queries, for
example.
- You can't rotate deterministic encryption keys anymore. We can add
support for that in the future.

This makes for reasonable defaults:

- People using "deterministic: true" will get unique indexes working out
of the box.
- The system will encourage keeping deterministic encryption stable:
  - By always using oldest encryption schemes
  - By forbidding configuring multiple keys

But you can still opt-out of the default if you need to.
2021-04-01 15:02:15 +02:00
Jorge Manrubia
7a1fb99302 Add support to declare previous encryption schemes globally 2021-04-01 15:02:15 +02:00
Jorge Manrubia
d35905ccae Add Scheme, a container for encrypted attribute configs
This adds a new class `Scheme` that encapsulates the encryption
properties for a given attribute. This adds a proper code representation
for a domain concept we keep referring to: encryption schemes.

It's in charge of processing the user-passed config properties when
declaring the attribute, as well as of validating those.

This removes the concern of processing properties from
`EncryptableRecord` and `EncryptableAttributeType`. It's also nice to
have a place to group attribute encryption options, versus passing
lists of hashes around.

This is in preparation to upcoming changes that will add new config
options and support for previous encryption schemes.
2021-04-01 15:02:15 +02:00
Jorge Manrubia
28145c3cee Rename master_key => primary_key 2021-04-01 15:02:15 +02:00
Jorge Manrubia
c275b10a0e Show performance tests results now that they are excluded from the build 2021-04-01 15:02:15 +02:00
Jorge Manrubia
bcf6a5fafb Fix test
The .encrypts declaration in `ActionText::Encryption` was making this test
fail. It was failing to load a MySQL error that was being raised when trying
to determine the column limit.
2021-04-01 15:02:15 +02:00
Jorge Manrubia
e4dae63013 Remove before_initialize, I think it's not needed 2021-04-01 15:02:15 +02:00
Jorge Manrubia
a786e34ab2 Move to on_load hook to see if it helps with railty test failing 2021-04-01 15:02:15 +02:00
Jorge Manrubia
bf75702b1c Inline prepend 2021-04-01 15:02:15 +02:00
Jorge Manrubia
9556720527 Wait for active record to be loaded to extend it 2021-04-01 15:02:15 +02:00