Commit Graph

22191 Commits

Author SHA1 Message Date
fatkodima
cac061e87e Clear metadata tables in tests instead of droping 2023-01-11 02:56:49 +02:00
fatkodima
dc4e05c8d5 Do not drop schema migrations and internal metadata tables in test/cases/tasks/database_tasks_test.rb 2023-01-10 15:28:05 +02:00
Yasuo Honda
dcdd671629
Merge pull request #46894 from avispatech/enable-extensions-schema
Adds schema parameter into enable_extension
2023-01-10 14:28:49 +09:00
fatkodima
83845c4d06 Fix schema cache dumping of virtual columns 2023-01-09 23:04:43 +02:00
Jonathan Hefner
e0d384aeb4 Clarify caveats of parameterized association scope [ci-skip]
When joining or eager loading an association with a parameterized scope,
the scope block will not be called with a `nil` argument.  Rather,
`ActiveRecord::Reflection::AssociationReflection#check_eager_loadable!`
will raise an `ArgumentError`.

Closes #43539.

Co-authored-by: jcoleman <james.coleman@getbraintree.com>
2023-01-08 15:47:20 -06:00
Jonathan Hefner
3eadf057db Fix typos in API docs [ci-skip] 2023-01-08 15:47:20 -06:00
Jonathan Hefner
33557c5dca Indent private methods in code examples [ci-skip]
This matches the indentation used in generated code, such as code from
`railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb.tt`.
2023-01-08 15:47:20 -06:00
fatkodima
cf940daa76 Fix ActiveRecord grouped calculations on joined tables on column present in both tables 2023-01-07 21:56:13 +02:00
Jean Boussier
15a032517f
Merge pull request #46831 from nick4tech/issue-46741
[issue-46741] remove `require pathname` from `drop` method
2023-01-07 19:05:33 +01:00
Jean Boussier
f2e0844042
Merge pull request #46659 from fatkodima/indexes-nulls-not-distinct
Handle `NULLS [NOT] DISTINCT` when getting indexes in PostgreSQL
2023-01-06 16:43:17 +01:00
Jean Boussier
ffa644e40e
Merge pull request #46836 from fatkodima/sqlite-alter_table-preserve-bigints
Preserve bigint column types when altering a table in sqlite3
2023-01-06 16:30:04 +01:00
Eileen M. Uchitelle
43b1c3371a
Merge pull request #46879 from fatkodima/db_prepare-fix-test-environment
Store correct environment in `internal_metadata` when run `rails db:prepare`
2023-01-05 09:33:50 -05:00
Leonardo Luarte González
7e95d3e653 Adds schema parameter into enable_extension
This patch tries to solve Heroku's new [PostgreSQL extension policy](https://devcenter.heroku.com/changelog-items/2446)
while keeping the migration and schema code idiomatic.

PostgreSQL adapter method `enable_extension` now allows to add an schema in its name.
The extension must be installed on another schema.

Usage:

`enable_extension('other_schema.hstore')`

The `enable_extension` can work with `schema` only if the given schema
already exists in the database.
2023-01-05 06:58:48 +00:00
eileencodes
25dc484e3d
Only establish temporary pool in prepare_all
If we access the pool we can ensure that the ActiveRecord::Base pool is
set back at the end. This will set us up to avoid calling
`establish_connection` from any task / database task. Without this we'll
need to set the connection back when we move to a class specifically for
migration connections.
2023-01-04 17:04:11 -05:00
fatkodima
2e7f287627 Store correct environment in internal_metadata when run rails db:prepare 2023-01-05 00:00:11 +02:00
Jean Boussier
75fa74325a Fix a typo in ActiveRecord::Sanitization documentation 2023-01-04 14:20:05 +01:00
Eileen M. Uchitelle
6f3c966119
Merge pull request #46759 from ghiculescu/readonly-assoc
Don't re-assign unchanged belongs_to associations during saves
2023-01-03 13:03:34 -05:00
Akira Matsuda
d1461cdb61
Sort autoloads in alphabetical order 2023-01-04 00:57:53 +09:00
Akira Matsuda
b378293c0d
Move load_schema from Object to AR::TestCase
as its instance and class mathod
2023-01-01 21:43:24 +09:00
Akira Matsuda
946bc94e82
Connect to the DB at the bottom of AR::TestCase class definition 2023-01-01 21:43:24 +09:00
Akira Matsuda
4ba87aae1f
Use included hook to properly call adapter helpers from a module 2023-01-01 21:43:24 +09:00
Akira Matsuda
2ead5132ea
Adapter helpers are available as AR::TestCase class methods
in case we need to call them outside of test case
2023-01-01 21:43:24 +09:00
Akira Matsuda
bcfdfefc08
Call AR::Connection's method via connection instance 2023-01-01 21:43:24 +09:00
Akira Matsuda
d15acd7ba6
AR adapter helpers are now available only within AR::TestCase class 2023-01-01 21:43:24 +09:00
Akira Matsuda
ee94a5c34b
Move AR adapter related helper methods under AR::TestCase
These helpers are called from both test class definition and test execution,
so we're defining them as both class and instance methods on AR::TestCase.
2023-01-01 18:17:01 +09:00
Akira Matsuda
a18d90e7cd
Don't pollute Object with test helper methods
Defining methods on toplevel changes the behavior of all Ruby Objects which of
course includes the test target, and thus that will spoil the meaning of the
whole testing. This is something that testing libraries or helpers should never
do.

These methods are just called from testing methods, so we can just move them
under AR::TestCase as its instance methods.
2023-01-01 18:09:06 +09:00
Akira Matsuda
dce7c1cd7c
Respect the timezone, or these would fail on a particular day of the year
like, on New Year's Day in Japan or New Year's Eve in US
2023-01-01 04:45:50 +09:00
zzak
9de0d59bb7
Fix rdoc syntax for Kernel.Float (#46860) 2022-12-31 10:33:16 +09:00
Jon Dufresne
c17c13ac74 Fix typo: "an storage" -> "a storage" 2022-12-30 06:31:41 -07:00
Jonathan Hefner
a731e5e757
Merge pull request #46813 from ezekg/fix-unencrypted-joins-for-deterministic-active-record-encryption-follow-up
Fix #46789
2022-12-29 11:42:37 -06:00
Zeke Gabrielse
9c33fa15e3 Fix issue where set attribute was symbol instead of string 2022-12-28 14:05:51 -06:00
fatkodima
b9ac0ff869 Preserve bigint column types when altering a table in sqlite3 2022-12-27 21:42:57 +02:00
Nicolas Iragorri Dominguez
e708599c85 [issue-46741] remove require pathname from drop method 2022-12-27 01:24:19 +01:00
Petrik
702421e5c2 Fix Active Record README formatting [ci-skip]
This fixes the indentation of the example code of the first bullet
point. The "Learn more" link was moved to the bottom of the bullet point,
similar to the other bullet points.
2022-12-26 21:57:50 +01:00
Akshay Birajdar
c312bb7e04 Prefer using new shorthand helper Rails.env.local? 2022-12-23 19:04:33 +05:30
Jean Boussier
28386bdc0f
Merge pull request #46789 from ezekg/fix-string-keys-for-deterministic-active-record-encryption
Support string keys for queries on deterministic attributes
2022-12-22 16:27:19 +01:00
Zeke Gabrielse
5b8625928d Support string keys for queries on deterministic attributes 2022-12-22 08:56:07 -06:00
Jean Boussier
68664aee48
Merge pull request #46790 from lazaronixon/singular-association-refactor
Small refactor on build singular association
2022-12-22 09:17:48 +01:00
Jean Boussier
50d59e9c3e Document MySQL numeric quoting behavior in ActiveRecord::Sanitization
Ref: https://github.com/rails/rails/issues/44312
Ref: https://github.com/rails/rails/pull/42440
Fix: https://github.com/rails/rails/pull/46776
2022-12-22 08:58:23 +01:00
George Claghorn
827ae3c449
ActiveRecord::Relation#none?/#any?/#one?: support pattern arg (#46728) 2022-12-22 08:21:54 +01:00
Nixon
4279b47c91 Small refactor on build singular association 2022-12-22 00:16:48 -03:00
Jonathan Hefner
d4c31bd849 Add ActiveRecord::Base::normalizes
`ActiveRecord::Base::normalizes` declares a normalization for one or
more attributes.  The normalization is applied when the attribute is
assigned or updated, and the normalized value will be persisted to the
database.  The normalization is also applied to the corresponding
keyword argument of finder methods.  This allows a record to be created
and later queried using unnormalized values.  For example:

  ```ruby
  class User < ActiveRecord::Base
    normalizes :email, with: -> email { email.strip.downcase }
  end

  user = User.create(email: " CRUISE-CONTROL@EXAMPLE.COM\n")
  user.email                  # => "cruise-control@example.com"

  user = User.find_by(email: "\tCRUISE-CONTROL@EXAMPLE.COM ")
  user.email                  # => "cruise-control@example.com"
  user.email_before_type_cast # => "cruise-control@example.com"

  User.exists?(email: "\tCRUISE-CONTROL@EXAMPLE.COM ")         # => true
  User.exists?(["email = ?", "\tCRUISE-CONTROL@EXAMPLE.COM "]) # => false
  ```
2022-12-21 12:08:36 -06:00
Petrik de Heus
0854202493
Merge pull request #46719 from p8/activerecord/improve-association-classmethods-docs
Replace created methods list documentation with code examples [ci-skip]
2022-12-19 14:02:46 +01:00
Alex Ghiculescu
2bdee49def Don't re-assign unchanged belongs_to associations during saves 2022-12-16 22:07:56 -06:00
Eileen M. Uchitelle
d2391f30f9
Merge pull request #46742 from ghiculescu/default-scope-reload
AR default scopes: only include `all_queries` default scopes on `reload`
2022-12-16 09:02:19 -05:00
Alex Ghiculescu
f43544d9a2 AR default scopes: only include all_queries default scopes on reload
Fixes https://github.com/rails/rails/issues/46731
2022-12-15 13:00:05 -06:00
Adrianna Chang
0b5a705e1b Hide changes to before_committed! behaviour behind config
As of https://github.com/rails/rails/pull/46525, the behaviour around
before_committed! callbacks has changed: callbacks are run on every
enrolled record in a transaction, even multiple copies of the same record.
This is a significant change that apps should be able to opt into in order
to avoid unexpected issues.
2022-12-15 11:43:51 -05:00
Petrik
bb1d506439 Replace added methods list with code examples [ci-skip]
The methods added when declaring association macros can be more clearly
explained with an actual code example instead of a list of definitions.
2022-12-13 21:43:42 +01:00
Petrik
660533fde6 Add missing end to code example [ci-skip]
The missing `end` seems to mess-up code highlighting on https://rubydoc.info
2022-12-13 20:29:03 +01:00
Eileen M. Uchitelle
b94b9bd984
Merge pull request #46641 from ghiculescu/query-log-namespace
Query Logs: `namespaced_controller` tag should match `controller` format
2022-12-13 13:13:34 -05:00