aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
Commit message (Collapse)AuthorAgeFilesLines
* Replaced usage of where.delete/destroy_all with delete/destroy_byAbhay Nikam2019-02-201-1/+1
|
* Introduce delete_by and destroy_by methods to ActiveRecord::RelationAbhay Nikam2019-02-191-0/+18
|
* Don't allow `where` with invalid value matches to nil valuesRyuta Kamizono2019-02-182-2/+12
| | | | | | | | | That is considered as silently leaking information. If type casting doesn't return any actual value, it should not be matched to any record. Fixes #33624. Closes #33946.
* Extract duplicated `serialize` methods into helpersRyuta Kamizono2019-02-181-0/+3
| | | | | | | | Since `serialize` is passed user input args (from `where`, schema default, etc), a helper should provide `serialize` if the helper also provide `cast`. Related #32624, 34cc301, a741208.
* Remove duplicated `test_update_all_with_order_and_limit`Ryuta Kamizono2019-02-181-6/+0
| | | | | This is covered by `test_update_all_with_order_and_limit_updates_subset_only` and `test_update_all_with_order_and_limit_and_offset_updates_subset_only`.
* Fix eager loading polymorphic association with mixed table conditionsRyuta Kamizono2019-02-182-1/+14
| | | | | | This fixes a bug that the `foreign_key` and the `foreign_type` are separated as different table conditions if a polymorphic association has a scope that joins another tables.
* Merge pull request #35274 from AlexBrodianoi/fix_does_not_support_reverseRyuta Kamizono2019-02-171-0/+9
|\ | | | | Raise ActiveRecord::IrreversibleOrderError if nulls first/last is not a single ordering argument.
| * Raise ActiveRecord::IrreversibleOrderError if nulls first/last is not a ↵Finn Young2019-02-171-0/+9
| | | | | | | | single ordering argument.
* | Fix `order` with custom attributesRyuta Kamizono2019-02-173-2/+13
| | | | | | | | This follows up 0ee96d13de29680e148ccb8e5b68025f29fd091c.
* | Merge pull request #35299 from kamipo/fix_mismatched_foreign_keyRyuta Kamizono2019-02-171-3/+80
|\ \ | | | | | | | | | Fix the regex that extract mismatched foreign key information
| * | Fix the regex that extract mismatched foreign key informationRyuta Kamizono2019-02-171-3/+80
|/ / | | | | | | | | | | | | | | | | | | | | | | | | The CI failure for `test_errors_for_bigint_fks_on_integer_pk_table` is due to the poor regex that extract all ``` `(\w+)` ``` like parts from the message (`:foreign_key` should be `"old_car_id"`, but `"engines"`): https://travis-ci.org/rails/rails/jobs/494123455#L1703 I've improved the regex more strictly and have more exercised mismatched foreign key tests. Fixes #35294
* | Remove `NoForeignKeySupportTest` which is no longer reachedRyuta Kamizono2019-02-162-46/+0
| | | | | | | | Since #35212, foreign key feature is supported by all adapters.
* | Merge pull request #35286 from matthewdunbar/masterRyuta Kamizono2019-02-161-0/+12
|\ \ | | | | | | | | | Properly handle cached queries with too many bind parameters
| * | Properly handle cached queries with too many bind parametersMatthew Dunbar2019-02-141-0/+10
| | |
* | | Deprecate using class level querying methods if the receiver scope regarded ↵Ryuta Kamizono2019-02-152-14/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | as leaked This deprecates using class level querying methods if the receiver scope regarded as leaked, since #32380 and #35186 may cause that silently leaking information when people upgrade the app. We need deprecation first before making those.
* | | Revert "Merge pull request #35186 from ↵Ryuta Kamizono2019-02-153-12/+36
|/ / | | | | | | | | | | | | | | | | | | | | | | kamipo/fix_leaking_scope_on_relation_create" This reverts commit b67d5c6dedbf033515a96a95d24d085bf99a0d07, reversing changes made to 2e018361c7c51e36d1d98bf770b7456d78dee68b. Reason: #35186 may cause that silently leaking information when people upgrade the app. We need deprecation first before making this.
* | Merge pull request #35242 from ↵Eileen M. Uchitelle2019-02-142-43/+117
|\ \ | |/ |/| | | | | eileencodes/add-setter-and-deprecation-for-configurations-hashes Add setter and deprecation for configurations hashes
| * Improve errors and handling of hashes for database configurationseileencodes2019-02-142-43/+117
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In chat Sam Saffron asked how to use the setter now that configurations is no longer a hash and you need to do AR::Base.configurations["test"]=. Technically you can do `ActiveRecord::Base.configurations = { the hash }` but I realized the old way throws an error and is unintuitive. To aid in the transition from hashes to objects this PR makes a few changes: 1) Re-adds a deprecated hash setter `[]=` that will add a new hash to the configurations list OR replace an existing hash if that environment is already present. This won't be supported in future Rails versions but a good error is important. 2) Changed to throw deprecation warnings on the methods we decided to support for hash conversion and raise on the methods we don't support. 3) Refactored the setter/getter hash deprecation warnings messages and rewrote them. Getters message: ``` DEPRECATION WARNING: `ActiveRecord::Base.configurations` no longer returns a hash. Methods that act on the hash like `values` are deprecated and will be removed in Rails 6.1. Use the `configs_for` method to collect and iterate over the database configurations. ``` Setter message: ``` DEPRECATION WARNING: Setting `ActiveRecord::Base.configurations` with `[]=` is deprecated. Use `ActiveRecord::Base.configurations=` directly to set the configurations instead. ``` 4) Rewrote the legacy configurations test file to test all the public methods in the DatabaseConfigurations class.
* | Revert "Chaining named scope is no longer leaking to class level querying ↵Ryuta Kamizono2019-02-143-6/+4
| | | | | | | | | | | | | | | | | | methods" This reverts #32380, since this may cause that silently leaking information when people upgrade the app. We need deprecation first before making this.
* | Merge pull request #35244 from palkan/fix/activerecord-database-uri-resolveEileen M. Uchitelle2019-02-131-0/+10
|\ \ | | | | | | Fix database configurations building when DATABASE_URL present
| * | Fix database configurations building when DATABASE_URL presentVladimir Dementyev2019-02-121-0/+10
| | |
* | | Revert "Merge pull request #35127 from bogdan/counter-cache-loading"Ryuta Kamizono2019-02-131-36/+14
|/ / | | | | | | | | | | | | | | | | | | | | | | | | This reverts commit eec3e28a1abf75676dcee58308ee5721bb53c325, reversing changes made to 5588fb4802328a2183f4a55c36d6703ee435f85c. Reason: Marking as loaded without actual loading is too greedy optimization. See more context #35239. Closes #35239. [Edouard CHIN & Ryuta Kamizono]
* | Merge pull request #35237 from eileencodes/fix-teardown-in-db-selector-testEileen M. Uchitelle2019-02-121-0/+4
|\ \ | | | | | | Fix DatabaseSelector test that fails sometimes
| * | Fix DatabaseSelector test that fails sometimeseileencodes2019-02-121-0/+4
| |/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | On CI we've seen a few test failures when the DatabaseSelectorTest runs before the ConnectionHandlersMultiDbTest. This is because it's creating 2 handlers but not properly tearing them down. Example failure: ``` Failure: ActiveRecord::ConnectionAdapters::ConnectionHandlersMultiDbTest#test_connects_to_with_single_configuration [/rails/activerecord/test/cases/connection_adapters/connection_handlers_multi_db_test.rb:241]: Expected: 1 Actual: 2 ```
* / Fix `pluck` and `select` with custom attributesRyuta Kamizono2019-02-138-7/+31
|/ | | | | | | | | Currently custom attributes are always qualified by the table name in the generated SQL wrongly even if the table doesn't have the named column, it would cause an invalid SQL error. Custom attributes should only be qualified if the table has the same named column.
* Add `remove_foreign_key` for `change_table`Ryuta Kamizono2019-02-111-0/+11
|
* SQLite3: Implement `add_foreign_key` and `remove_foreign_key`Ryuta Kamizono2019-02-114-15/+47
| | | | | | | | | | | | I implemented Foreign key create in `create_table` for SQLite3 at #24743. This follows #24743 to implement `add_foreign_key` and `remove_foreign_key`. Unfortunately SQLite3 has one limitation that `PRAGMA foreign_key_list(table-name)` doesn't have constraint name. So we couldn't implement find/remove foreign key by name for now. Fixes #35207. Closes #31343.
* More exercise table name prefix and suffix testsRyuta Kamizono2019-02-111-25/+81
|
* Fix random CI failure due to non-deterministic sorting orderRyuta Kamizono2019-02-101-3/+3
| | | | https://travis-ci.org/rails/rails/jobs/491045821#L1528-L1531
* Merge pull request #35203 from chiastolite/add_column_without_column_namesRyuta Kamizono2019-02-101-0/+11
|\ | | | | | | Do not allow to add column without column name
| * Do not allow to add column without column nameHiroyuki Morita2019-02-101-0/+9
|/
* Merge pull request #35193 from kamipo/fix_exists_with_distinct_and_offsetRyuta Kamizono2019-02-081-0/+10
|\ | | | | Fix `relation.exists?` with giving both `distinct` and `offset`
| * Fix `relation.exists?` with giving both `distinct` and `offset`Ryuta Kamizono2019-02-081-0/+10
| | | | | | | | | | | | | | | | | | | | | | The `distinct` affects (reduces) rows of the result, so it is important part when both `distinct` and `offset` are given. Replacing SELECT clause to `1 AS one` and removing `distinct` and `order` is just optimization for the `exists?`, we should not apply the optimization for that case. Fixes #35191.
* | Merge pull request #35178 from bogdan/has-many-sizeRyuta Kamizono2019-02-081-0/+15
|\ \ | |/ |/| Bugfix has_many association #size when ids reader is cached and assoc…
| * Bugfix has_many association #size when ids reader is cached and association ↵Bogdan Gusiev2019-02-081-0/+15
| | | | | | | | is changed
* | Address `test_belongs_to_does_not_use_order_by` failure due to checking ↵Yasuo Honda2019-02-082-3/+4
| | | | | | | | | | | | | | | | order by for metadata queries Also, `test_has_one_does_not_use_order_by` should not check metadata queries. Fixes #35098
* | Fix `relation.create` to avoid leaking scope to initialization block and ↵Ryuta Kamizono2019-02-073-4/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | callbacks `relation.create` populates scope attributes to new record by `scoping`, it is necessary to assign the scope attributes to the record and to find STI subclass from the scope attributes. But the effect of `scoping` is class global, it was caused undesired behavior that pollute all class level querying methods in initialization block and callbacks (`after_initialize`, `before_validation`, `before_save`, etc), which are user provided code. To avoid the leaking scope issue, restore the original current scope before initialization block and callbacks are invoked. Fixes #9894. Fixes #17577. Closes #31526.
* | Fix `CollectionProxy#concat` to return self by alias it to `#<<`Yuya Tanaka2019-02-062-2/+4
| | | | | | | | Formerly it was returning arguments (`records` array).
* | Relation no longer respond to Arel methodsRyuta Kamizono2019-02-062-18/+7
| | | | | | | | This follows up d97980a16d76ad190042b4d8578109714e9c53d0.
* | Merge pull request #32380 from kamipo/fix_leaking_scopeRyuta Kamizono2019-02-062-0/+17
|\ \ | | | | | | Chaining named scope is no longer leaking to class level querying methods
| * | Chaining named scope is no longer leaking to class level querying methodsRyuta Kamizono2019-02-062-0/+17
| |/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Active Record uses `scoping` to delegate to named scopes from relations for propagating the chaining source scope. It was needed to restore the source scope in named scopes, but it was caused undesired behavior that pollute all class level querying methods. Example: ```ruby class Topic < ActiveRecord::Base scope :toplevel, -> { where(parent_id: nil) } scope :children, -> { where.not(parent_id: nil) } scope :has_children, -> { where(id: Topic.children.select(:parent_id)) } end # Works as expected. Topic.toplevel.where(id: Topic.children.select(:parent_id)) # Doesn't work due to leaking `toplevel` to `Topic.children`. Topic.toplevel.has_children ``` Since #29301, the receiver in named scopes has changed from the model class to the chaining source scope, so the polluting class level querying methods is no longer required for that purpose. Fixes #14003.
* / Respect ENV variables when finding DBs etc for the test suiteMatthew Draper2019-02-061-0/+6
|/ | | | | If they're not set we'll still fall back to localhost, but this makes it possible to run the tests against a remote Postgres / Redis / whatever.
* Merge pull request #35127 from bogdan/counter-cache-loadingRyuta Kamizono2019-02-051-5/+35
|\ | | | | Bugfix association loading behavior when counter cache is zero
| * Bugfix association loading behavior when counter cache is zeroBogdan Gusiev2019-02-051-5/+35
| |
* | Merge pull request #35089 from ↵Eileen M. Uchitelle2019-02-041-0/+38
|\ \ | | | | | | | | | | | | eileencodes/fix-query-cache-for-database-switching Invalidate all query caches for current thread
| * | Invalidate query cache for all connections in the current threadEileen Uchitelle2019-02-011-0/+38
| | | | | | | | | | | | | | | | | | This change ensures that all query cahces are cleared across all connections per handler for the current thread so if you write on one connection the read will have the query cache cleared.
* | | Merge pull request #35132 from ↵Eileen M. Uchitelle2019-02-043-0/+48
|\ \ \ | | | | | | | | | | | | | | | | eileencodes/allow-application-to-change-handler-names Add ability to change the names of the default handlers
| * | | Add ability to change the names of the default handlersEileen Uchitelle2019-02-013-0/+48
| |/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When I wrote the `connected_to` and `connects_to` API's I wrote them with the idea in mind that it didn't really matter what the handlers/roles were called as long as those connecting to the roles knew which one wrote and which one read. With the introduction of the middleware Rails begins to assume it's `writing` and `reading` and there's no room for other roles. At GitHub we've been using this method for a long time so we have a ton of legacy code that uses different handler names `default` and `readonly`. We could rename all our code but I think this is better for a few reasons: - Legacy apps that have been using multiple databases for a long time can have an eaiser time switching. - If we later find this to cause more issues than it's worth we can easily deprecate. - We won't force old apps to rewrite the resolver middleware just to use a different handler. Adding the writing_role/reading_role required that I move the code that creates the first handler for writing to the railtie. If I didn't move this the core class would assign the handler before I was able to assign a new one in my configuration and I'd end up with 3 handlers instead of 2.
* | | Merge pull request #35130 from rails/move-delay-to-options-argumentEileen M. Uchitelle2019-02-011-0/+48
|\ \ \ | | | | | | | | Refactor options for database selector middleware
| * | | Refactor options for middlewareEileen Uchitelle2019-02-011-0/+48
| |/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | Right now we only have one option that's supported, the delay. However I can see us supporting other options in the future. This PR refactors the options to get passed into the resolver so whether you're using middleware or using the config options you can pass options to the resolver. This will also make it easy to add new options in the future.