aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/relations_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* Remove extra whitespaceDaniel Colson2018-01-251-14/+14
|
* Use assert_empty and assert_not_emptyDaniel Colson2018-01-251-4/+4
|
* Use assert_predicate and assert_not_predicateDaniel Colson2018-01-251-62/+62
|
* Use respond_to test helpersDaniel Colson2018-01-251-5/+5
|
* Fix `count(:all)` with eager loading and having an order other than the ↵Ryuta Kamizono2018-01-251-0/+6
| | | | | | | | | | | | | | | | | | | driving table This is a regression caused by 6beb4de. In PostgreSQL, ORDER BY expressions must appear in SELECT list when using DISTINCT. When using `count(:all)` with eager loading, Active Record enforces DISTINCT to count the driving table records only. 6beb4de was caused the regression because `count(:all)` with DISTINCT path no longer removes ORDER BY. We need to ignore ORDER BY when DISTINCT is enforced, otherwise not always generated valid SQL for PostgreSQL. Fixes #31783.
* Avoid passing unnecessary arguments to relationDaniel Colson2018-01-241-1/+5
| | | | | | | | | | | | Most of the time the table and predicate_builder passed to Relation.new are exactly the arel_table and predicate builder of the given klass. This uses klass.arel_table and klass.predicate_builder as the defaults, so we don't have to pass them in most cases. This does change the signaure of both Relation and AssocationRelation. Are we ok with that?
* Fix `count(:all)` to correctly work `distinct` with custom SELECT listRyuta Kamizono2017-12-201-0/+6
| | | | | | | | | | | | | | Currently `count(:all)` with `distinct` doesn't work correctly because SELECT list is always replaced to `*` or primary key in that case even if having custom SELECT list. And also, PostgreSQL has a limitation that ORDER BY expressions must appear in select list for SELECT DISTINCT. Therefore, we should not replace custom SELECT list when using `count(:all)` with `distinct`. Closes #31277.
* Remove outdated comments [ci skip]Ryuta Kamizono2017-12-191-4/+0
|
* Using subselect for `delete_all` with `limit` or `offset`Ryuta Kamizono2017-12-191-2/+0
| | | | | | Arel doesn't support subselect generation for DELETE unlike UPDATE yet, but we already have that generation in connection adapters. We can simply use the subselect generated by that one.
* Fix `scope_for_create` to do not lose polymorphic associationsRyuta Kamizono2017-12-081-0/+9
| | | | | | | | | | | | This regression was caused at 213796fb due to polymorphic predicates are combined by `Arel::Nodes::And`. But I'd like to keep that combined because it would help inverting polymorphic predicates correctly (e9ba12f7), and we can collect equality nodes regardless of combined by `Arel::Nodes::And` (`a AND (b AND c) AND d` == `a AND b AND c AND d`). This change fixes the regression to collect equality nodes in `Arel::Nodes::And` as well. Fixes #31338.
* Merge pull request #27947 from mastahyeti/unsafe_raw_sqlMatthew Draper2017-11-141-19/+19
|\ | | | | | | Disallow raw SQL in dangerous AR methods
| * deal with Array arguments to #orderBen Toews2017-11-091-3/+3
| |
| * convert order arg to string before checking if we can reverse itBen Toews2017-11-091-2/+2
| |
| * use << instead of #concat in #reverse_sql_order because we might be working ↵Ben Toews2017-11-091-1/+1
| | | | | | | | with Arel SQL literator which overrides #concat
| * try using regexesBen Toews2017-11-091-26/+23
| |
| * allow table name and direction in string order argBen Toews2017-11-091-33/+33
| |
| * work around deprecation warnings in a bunch of testsBen Toews2017-11-091-61/+64
| |
* | Fix random CI failure due to non-deterministic sorting orderRyuta Kamizono2017-11-101-1/+1
| | | | | | | | https://travis-ci.org/rails/rails/jobs/300163487#L1974
* | Ensure `apply_join_dependency` for subqueries in `from` and `where`Ryuta Kamizono2017-11-101-0/+12
| | | | | | | | Fixes #21577.
* | Set counter caches to correct values in fixturesBogdan Gusiev2017-11-081-9/+9
|/
* All test cases for `exists?` places in `finder_test.rb` to ease to find the ↵Ryuta Kamizono2017-10-091-26/+0
| | | | test cases
* Ensure `AliasTracker` respects a custom table nameRyuta Kamizono2017-09-301-4/+8
|
* Add test case for `arel_attribute` with a custom tableRyuta Kamizono2017-09-271-0/+4
| | | | Since #29301, `arel_attribute` respects a custom table name.
* Treat `Set` as an `Array` in `Relation#where`Sean Griffin2017-09-261-0/+13
| | | | | | | | I do not want to set the expectation that any enumerable object should behave this way, but this case in particular comes up frequently enough that I'm caving on this one. Fixes #30684.
* Refactor Active Record to let Arel manage bind paramsSean Griffin2017-07-241-46/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | A common source of bugs and code bloat within Active Record has been the need for us to maintain the list of bind values separately from the AST they're associated with. This makes any sort of AST manipulation incredibly difficult, as any time we want to potentially insert or remove an AST node, we need to traverse the entire tree to find where the associated bind parameters are. With this change, the bind parameters now live on the AST directly. Active Record does not need to know or care about them until the final AST traversal for SQL construction. Rather than returning just the SQL, the Arel collector will now return both the SQL and the bind parameters. At this point the connection adapter will have all the values that it had before. A bit of this code is janky and something I'd like to refactor later. In particular, I don't like how we're handling associations in the predicate builder, the special casing of `StatementCache::Substitute` in `QueryAttribute`, or generally how we're handling bind value replacement in the statement cache when prepared statements are disabled. This also mostly reverts #26378, as it moved all the code into a location that I wanted to delete. /cc @metaskills @yahonda, this change will affect the adapters Fixes #29766. Fixes #29804. Fixes #26541. Close #28539. Close #24769. Close #26468. Close #26202. There are probably other issues/PRs that can be closed because of this commit, but that's all I could find on the first few pages.
* Merge pull request #29867 from koic/fix_a_failed_ar_test_when_using_oracleKasper Timm Hansen2017-07-231-2/+10
|\ | | | | Fix a failued AR test when using OracleAdapter
| * Fix a failued AR test when using OracleAdapterKoichi ITO2017-07-201-2/+10
| |
* | Merge pull request #29732 from kirs/frozen-activerecordRafael França2017-07-211-0/+2
|\ \ | | | | | | Use frozen-string-literal in ActiveRecord
| * | Use frozen-string-literal in ActiveRecordKir Shatrov2017-07-191-0/+2
| |/
* / Revert "Extract `bind_param` and `bind_attribute` into `ActiveRecord::TestCase`"Sean Griffin2017-07-211-7/+3
|/ | | | | | | | This reverts commit b6ad4052d18e4b29b8a092526c2beef013e2bf4f. This is not something that the majority of Active Record should be testing or care about. We should look at having fewer places rely on these details, not make it easier to rely on them.
* Fix `JoinDependency` with using a custom tableRyuta Kamizono2017-07-181-5/+14
| | | | | | | | | | | | | | | Without this fix, `JoinDependency` doesn't use a custom table alias: ``` % ARCONN=sqlite3 be ruby -w -Itest test/cases/relations_test.rb -n test_using_a_custom_table_with_joins_affects_the_wheres Using sqlite3 Run options: -n test_using_a_custom_table_with_joins_affects_the_wheres --seed 14531 E Error:RelationTest#test_using_a_custom_table_with_joins_affects_the_wheres: ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column: posts.author_id: SELECT "omg_posts".* FROM "posts" "omg_posts" INNER JOIN "authors" ON "authors"."id" = "posts"."author_id" WHERE "omg_posts"."title" = ? LIMIT ? ```
* Merge pull request #29801 from kamipo/extract_null_relation_testSean Griffin2017-07-171-118/+0
|\ | | | | Extract `NullRelationTest` from `RelationTest`
| * Extract `NullRelationTest` from `RelationTest`Ryuta Kamizono2017-07-151-118/+0
| | | | | | | | | | `test/cases/relations_test.rb` file has too much lines (2000 over). So I extracted `NullRelationTest` to the dedicated file.
* | Merge pull request #29799 from ↵Sean Griffin2017-07-171-8/+0
|\ \ | | | | | | | | | | | | kamipo/remove_outdated_test_scoped_responds_to_delegated_methods Remove outdated `test_scoped_responds_to_delegated_methods`
| * | Remove outdated `test_scoped_responds_to_delegated_methods`Ryuta Kamizono2017-07-151-8/+0
| |/ | | | | | | | | | | | | | | This test was added at 74ed123 to ensure `respond_to?` delegate methods to `Array` and `arel_table`. But array method delegation was removed at 9d79334 in favor of including `Enumerable`. And now `Relation` has `insert`, `update`, and `delete` methods (63480d2, 8d31c9f, d5f9173). So this delegation test is already outdated.
* | Fix `where` with a custom tableRyuta Kamizono2017-07-181-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Without this fix, SELECT clause doesn't use a custom table alias name: ``` % ARCONN=sqlite3 be ruby -w -Itest test/cases/relations_test.rb -n test_using_a_custom_table_affects_the_wheres Using sqlite3 Run options: -n test_using_a_custom_table_affects_the_wheres --seed 31818 E Error: RelationTest#test_using_a_custom_table_affects_the_wheres: ActiveRecord::StatementInvalid: SQLite3::SQLException: no such table: posts: SELECT "posts".* FROM "posts" "omg_posts" WHERE "omg_posts"."title" = ? LIMIT ? ```
* | Fix `create_with` using both string and symbolRyuta Kamizono2017-07-161-1/+1
|/ | | | | | | This is related with #27680. Since `where_values_hash` keys constructed by `where` are string, so we need `stringify_keys` to `create_with_value` before merging it.
* Skip query cache for in_batches and friendsEugene Kenny2017-07-061-0/+42
| | | | | | | | | | | The `find_each`, `find_in_batches` and `in_batches` APIs usually operate on large numbers of records, where it's preferable not to load them all into memory at once. If the query cache is enabled, it will hold onto the query results until the end of the execution context (request/job), which means the memory used is still proportional to the total number of records. These queries are typically not repeated, so the query cache isn't desirable here.
* Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"Matthew Draper2017-07-021-1/+0
| | | | | This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
* Enforce frozen string in RubocopKir Shatrov2017-07-011-0/+1
|
* Merge pull request #29405 from kamipo/locked_should_not_build_arelRafael França2017-06-281-0/+6
|\ | | | | `Relation#locked?` should not build arel
| * Remove delegating to arel in a relationRyuta Kamizono2017-06-291-1/+1
| | | | | | | | | | The delegation was needed since passing `relation` with `relation.bound_attributes`. It should use `relation.arel` in that case.
| * `Relation#locked?` should not build arelRyuta Kamizono2017-06-201-0/+6
| |
* | Fix extracting `references` via `order_values` to respect quotingRyuta Kamizono2017-06-261-0/+6
|/
* Remove a redundant default_scope testsKoichi ITO2017-06-031-10/+0
|
* Should test against `Relation#bound_attributes`Ryuta Kamizono2017-05-041-8/+12
| | | | Since legacy `Relation#bind_values` was removed in b06f64c.
* Remove duplicated `test_merging_reorders_bind_params`Ryuta Kamizono2017-05-041-9/+0
| | | | | | The same test exists in `test/cases/relation/merging_test.rb`. https://github.com/rails/rails/blob/v5.1.0/activerecord/test/cases/relation/merging_test.rb#L94-L101
* Restore `fixtures :author_addresses`Ryuta Kamizono2017-04-271-1/+1
| | | | | This change reverted in eac6f369 but it is needed for data integrity. See #25328.
* Revert "Merge pull request #27636 from ↵Rafael Mendonça França2017-04-261-1/+1
| | | | | | | | | mtsmfm/disable-referential-integrity-without-superuser-privilege-take-2" This reverts commit c1faca6333abe4b938b98fedc8d1f47b88209ecf, reversing changes made to 8c658a0ecc7f2b5fc015d424baf9edf6f3eb2b0b. See https://github.com/rails/rails/pull/27636#issuecomment-297534129
* `respond_to_missing?` should be privateRyuta Kamizono2017-04-221-5/+1
| | | | | | | Follow up of 03d3f036. Some of `respond_to?` were replaced to `respond_to_missing?` in 03d3f036. But the visibility is still public. It should be private.