aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
Commit message (Collapse)AuthorAgeFilesLines
...
* | | | | | Add test case for `unscope` with unknown columnRyuta Kamizono2019-02-241-0/+11
| | | | | |
* | | | | | More exercise tests for distinct count with group byRyuta Kamizono2019-02-241-2/+16
| | | | | |
* | | | | | Make `test_select_with_subquery_in_from_uses_original_table_name` work with ↵yuuji.yaginuma2019-02-231-7/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | old SQLite3 It seems that the reason why the `test_select_with_subquery_in_from_uses_original_table_name` does not pass is that the return value of `sqlite3_column_name()` is wrong due to subquery flattening. This seems to have been fixed with SQLite 3.20.0(https://sqlite.org/changes.html#version_3_20_0). But CI uses the old version(maybe 3.11.0), I added `DISTINCT` to avoid optimization by subquery flattening. Ref: https://sqlite.org/optoverview.html#flattening
* | | | | | Skip `test_select_with_subquery_in_from_uses_original_table_name` on CIRyuta Kamizono2019-02-231-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | Somehow `ENV["BUILDKITE"]` didn't work as expected.
* | | | | | Skip `test_select_with_subquery_in_from_uses_original_table_name` on ↵Ryuta Kamizono2019-02-221-2/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Buildkite as well https://buildkite.com/rails/rails/builds/58981#2423c707-7c56-4639-a76e-8db4fd1e5cf3/102-111
* | | | | | Just skip `test_select_with_subquery_in_from_uses_original_table_name` on TravisRyuta Kamizono2019-02-221-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I'm not sure why the test is failed on Travis, it passed on locally. I suspect that failure is a bug on SQLite3, so just skip the test for now, since it was not covered by before. https://travis-ci.org/rails/rails/jobs/496726410#L1198-L1208
* | | | | | Fix `pluck` and `select` with `from` if `from` has original table nameRyuta Kamizono2019-02-221-0/+36
|/ / / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is caused by 0ee96d1. Since #18744, `select` columns doesn't be qualified by table name if using `from`. 0ee96d1 follows that for `pluck` as well. But people depends that `pluck` columns are qualified even if using `from`. So I've fixed that to be qualified if `from` has the original table name to keep the behavior as much as before. Fixes #35359.
* | | | | Merge pull request #35336 from ↵Ryuta Kamizono2019-02-211-1/+2
|\ \ \ \ \ | | | | | | | | | | | | | | | | | | | | | | | | kamipo/dont_allow_non_numeric_string_matches_to_zero Don't allow `where` with non numeric string matches to 0 values
| * | | | | Don't allow `where` with non numeric string matches to 0 valuesRyuta Kamizono2019-02-201-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a follow-up of #35310. Currently `Topic.find_by(id: "not-a-number")` matches to a `id = 0` record. That is considered as silently leaking information. If non numeric string is given to find by an integer column, it should not be matched to any record. Related #12793.
* | | | | | Address "warning: in `column': the last argument was passed as a single Hash"Ryuta Kamizono2019-02-211-7/+8
| | | | | |
* | | | | | More exercise test cases for order by table name qualified column nameRyuta Kamizono2019-02-211-8/+8
| | | | | | | | | | | | | | | | | | | | | | | | This covers what #34626 fixes.
* | | | | | Merge pull request #35263 from hatch-carl/reduce-postgres-uuid-allocationsRyuta Kamizono2019-02-211-1/+13
|\ \ \ \ \ \ | | | | | | | | | | | | | | Reduce unused allocations when casting UUIDs for Postgres
| * | | | | | Reduce unused allocations when casting UUIDs for PostgresCarl Thuringer2019-02-201-1/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Using the subscript method `#[]` on a string has several overloads and rather complex implementation. One of the overloads is the capability to accept a regular expression and then run a match, then return the receiver (if it matched) or one of the groups from the MatchData. The function of the `UUID#cast` method is to cast a UUID to a type and format acceptable by postgres. Naturally UUIDs are supposed to be string and of a certain format, but it had been determined that it was not ideal for the framework to send just any old string to Postgres and allow the engine to complain when "foobar" or "" was sent, being obviously of the wrong format for a valid UUID. Therefore this code was written to facilitate the checking, and if it were not of the correct format, a `nil` would be returned as is conventional in Rails. Now, the subscript method will allocate one or more strings on a match and return one of them, based on the index parameter. However, there is no need for a new string, as a UUID of the correct format is already such, and so long as the format was verified then the string supplied is adequate for consumption by the database. The subscript method also creates a MatchData object which will never be used, and so must eventually be garbage collected. Garbage collection indeed. This innocuous method tends to be called quite a lot, for example if the primary key of a table is a uuid, then this method will be called. If the foreign key of a relation is a UUID, once again this method is called. If that foreign key is belonging to a has_many relationship with dozens of objects, then again dozens of UUIDs shall be cast to a dup of themselves, and spawn dozens of MatchData objects, and so on. So, for users that: * Use UUIDs as primary keys * Use Postgres * Operate on collections of objects This accomplishes a significant savings in total allocations, and may save many garbage collections.
* | | | | | | Merge pull request #35327 from abhaynikam/use-delete-by-and-destroy-by-methodRyuta Kamizono2019-02-201-1/+1
|\ \ \ \ \ \ \ | |_|/ / / / / |/| | | | | | Replaced usage of where.delete/destroy_all with delete/destroy_by
| * | | | | | Replaced usage of where.delete/destroy_all with delete/destroy_byAbhay Nikam2019-02-201-1/+1
| | | | | | |
* | | | | | | Merge pull request #35247 from bogdan/fix-source-reflection-reset-codeRyuta Kamizono2019-02-203-3/+12
|\ \ \ \ \ \ \ | | | | | | | | | | | | | | | | Fix reset of the source association when through association is loaded
| * | | | | | | Fix reset of the source association when through association is loadedBogdan Gusiev2019-02-203-3/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The special case happens when through association has a custom scope that is applied to the source association when loading. In this case, the soucre association would need to be reset after main association is loaded. See tests. The special case exists when a through association has
* | | | | | | | PostgreSQL: Support endless range values for range typesRyuta Kamizono2019-02-201-0/+16
| | | | | | | |
* | | | | | | | Add delegation tests for delete_by and destroy_by methodsAbhay Nikam2019-02-201-1/+1
| |_|/ / / / / |/| | | | | |
* | | | | | | Merge pull request #35271 from gmcgibbon/fix_time_attribute_test_failuresGannon McGibbon2019-02-191-0/+4
|\ \ \ \ \ \ \ | |_|/ / / / / |/| | | | | | Reset column info after making Topic tz-aware
| * | | | | | Reset column info after making Topic tz-awareGannon McGibbon2019-02-181-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In AttributeMethodsTest, we make the global Topic class time zone-aware which changes instance date time attribute casting behaviour. We need to reset column info after the test because future tests don't expect Topic date time columns to be time zone-aware.
* | | | | | | 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