aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/relations_test.rb
Commit message (Collapse)AuthorAgeFilesLines
...
| * 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.
* Fix an AR test of relations_test when using OracleKoichi ITO2017-04-111-1/+1
|
* Load only needed records on ActiveRecord::Relation#inspectHendy Tanata2017-03-281-0/+6
| | | | | | | Instead of loading all records and returning only a subset of those, just load the records as needed. Fixes #25537.
* Use `SET CONSTRAINTS` for `disable_referential_integrity` without superuser ↵Fumiaki MATSUSHIMA2017-03-261-1/+1
| | | | | | | | | | | | | | | privileges (take 2) Re-create https://github.com/rails/rails/pull/21233 eeac6151a5 was reverted (127509c071b4) because it breaks tests. ---------------- ref: 72c1557254 - We must use `authors` fixture with `author_addresses` because of its foreign key constraint. - Tests require PostgreSQL >= 9.4.2 because it had a bug about `ALTER CONSTRAINTS` and fixed in 9.4.2.
* Fix where_clause#except with specific where valueJohn Hawthorn2017-03-201-0/+8
| | | | | | | | | Fixes a regression introduced in 22ca710f20c3c656811df006cbf1f4dbc359f7a6 where Relation#unscope with a specific where value (vs unscoping the entire where clause) could result in the wrong binds being left on the query. This was caused by an index variable not being incremented properly.
* Use `load` rather than `collect` for force loadingRyuta Kamizono2017-03-191-7/+7
| | | | | | | Since b644964b `ActiveRecord::Relation` includes `Enumerable` so delegating `collect`, `all?`, and `include?` are also unneeded. `collect` without block returns `Enumerable` without preloading by that. We should use `load` rather than `collect` for force loading.
* Allow order to be given expressions as hash keysEugene Kenny2017-02-271-1/+24
| | | | | | | | | | | | | When `order` is given a hash, the keys are currently assumed to be attribute names and are quoted as such in the query, which makes it impossible to pass an expression instead: Post.order("LENGTH(title)" => :asc).last # SELECT `posts`.* FROM `posts` ORDER BY `posts`.`LENGTH(title)` DESC LIMIT 1 If the key is an `Arel::Nodes::SqlLiteral`, we now use it directly in the query. This provides a way to build a relation with a complex order clause that can still be reversed with `reverse_order` or `last`.
* Merge pull request #27122 from kamipo/fix_unscope_with_subqueryRafael França2017-02-131-0/+12
|\ | | | | Fix unscope with subquery
| * Fix unscope with subqueryRyuta Kamizono2016-12-051-0/+12
| | | | | | | | | | | | | | Currently cannot unscope subquery properly. This commit fixes the issue. Fixes #26323.
* | Revert "Merge pull request #21233 from ↵Rafael Mendonça França2017-01-031-1/+1
| | | | | | | | | | | | | | | | | | | | mtsmfm/disable-referential-integrity-without-superuser-privileges" This reverts commit eeac6151a55cb7d5f799e1ae33aa64a839cbc3aa, reversing changes made to 5c40239d3104543e70508360d27584a3e4dc5baf. Reason: Broke the isolated tests. https://travis-ci.org/rails/rails/builds/188721346
* | Merge pull request #27563 from kamipo/fix_typoRafael França2017-01-031-1/+1
|\ \ | | | | | | Fix typo s/permited/permitted/
| * | Fix typo s/permited/permitted/Ryuta Kamizono2017-01-041-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | ``` % git grep -n permited actionview/test/template/url_helper_test.rb:238: def test_button_to_with_permited_strong_params actionview/test/template/url_helper_test.rb:245: def test_button_to_with_unpermited_strong_params activerecord/test/cases/relations_test.rb:1620: def test_update_on_relation_passing_active_record_object_is_not_permited ```
* | | Merge pull request #21233 from ↵Rafael França2017-01-031-1/+1
|\ \ \ | |/ / |/| | | | | | | | mtsmfm/disable-referential-integrity-without-superuser-privileges Use `SET CONSTRAINTS` for `disable_referential_integrity` without superuser privileges
| * | Use `SET CONSTRAINTS` for `disable_referential_integrity` without superuser ↵Fumiaki MATSUSHIMA2016-12-031-1/+1
| |/ | | | | | | | | | | | | | | | | privileges ref: 72c1557254 - We must use `authors` fixture with `author_addresses` because of its foreign key constraint. - Tests require PostgreSQL >= 9.4.2 because it had a bug about `ALTER CONSTRAINTS` and fixed in 9.4.2.