aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/relations_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* 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.
* | Remove deprecation of using ActiveRecord::Base instance in .updateRafael Mendonça França2017-01-031-2/+2
| |
* | Remove deprecated `#uniq`, `#uniq!`, and `#uniq_value`Ryuta Kamizono2016-12-301-6/+0
| |
* | Remove deprecated conditions parameter from #delete_allRafael Mendonça França2016-12-291-6/+0
| |
* | Remove deprecated conditions parameter from `#destroy_all`Rafael Mendonça França2016-12-291-6/+0
| |
* | Remove deprecated support to passing a class as a value in a queryRafael Mendonça França2016-12-291-9/+0
| |
* | "Use assert_nil if expecting nil. This will fail in minitest 6."Akira Matsuda2016-12-251-8/+8
|/
* Respect new records for `CollectionProxy#uniq`Ryuta Kamizono2016-11-131-1/+0
| | | | | | | | | | | | | Currently if `CollectionProxy` has more than one new record, `CollectionProxy#uniq` result is incorrect. And `CollectionProxy#uniq` was aliased to `distinct` in a1bb6c8b06db. But the `uniq` method and the `SELECT DISTINCT` method are different methods. The doc in `CollectionProxy` is for the `SELECT DISTINCT` method, not for the `uniq` method. Therefore, reverting the alias in `CollectionProxy` to fix the inconsistency and to have the both methods.
* Add more rubocop rules about whitespacesRafael Mendonça França2016-10-291-21/+21
|
* Tweak a test so the queries matchMatthew Draper2016-10-081-1/+1
|
* improve error message when include assertions failMichael Grosser2016-09-161-4/+4
| | | | | | assert [1, 3].includes?(2) fails with unhelpful "Asserting failed" message assert_includes [1, 3], 2 fails with "Expected [1, 3] to include 2" which makes it easier to debug and more obvious what went wrong
* Merge pull request #25987 from aquajach/masterRafael Mendonça França2016-08-171-0/+9
|\ | | | | | | Fix does_not_support_reverse? to find sql functions with commas in nested brackets
| * have does_not_support_reverse? support sql functions with commas in nested ↵Jack2016-07-291-0/+9
| | | | | | | | brackets
* | Add three new rubocop rulesRafael Mendonça França2016-08-161-17/+17
| | | | | | | | | | | | | | | | Style/SpaceBeforeBlockBraces Style/SpaceInsideBlockBraces Style/SpaceInsideHashLiteralBraces Fix all violations in the repository.
* | Add `Style/EmptyLines` in `.rubocop.yml` and remove extra empty linesRyuta Kamizono2016-08-071-1/+0
| |
* | applies remaining conventions across the projectXavier Noria2016-08-061-1/+1
| |
* | remove redundant curlies from hash argumentsXavier Noria2016-08-061-2/+2
| |
* | modernizes hash syntax in activerecordXavier Noria2016-08-061-89/+89
| |
* | applies new string literal convention in activerecord/testXavier Noria2016-08-061-251/+251
|/ | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Merge pull request #24203 from sferik/count_with_blockKasper Timm Hansen2016-05-161-0/+5
|\ | | | | Forward ActiveRecord::Relation#count to Enumerable#count if block given
| * Forward ActiveRecord::Relation#count to Enumerable#count if block givenErik Michaels-Ober2016-03-191-0/+5
| |
* | Allow the connection adapters to determine the order of bind paramsSean Griffin2016-05-061-0/+18
|/ | | | | | | | | | | | In 5.0 we use bind parameters for limit and offset, while in 4.2 we used the values directly. The code as it was written assumed that limit and offset worked as `LIMIT ? OFFSET ?`. Both Oracle and SQL Server have a different syntax, where the offset is stated before the limit. We delegate this behavior to the connection adapter so that these adapters are able to determine how the bind parameters are flattened based on what order their specification has the various clauses appear. Fixes #24775
* Merge pull request #23751 from chezou/add-test-case-order-by-fieldAndrew White2016-02-221-0/+6
|\ | | | | Add test cases about MySQL ORDER BY FIELD()
| * Add assertions order by field with empty dataMichiaki Ariga2016-02-181-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Add assertions to MySQL `ORDER BY FIELD()` with empty data. These tests examine to sanitize `ORDER BY FIELD()` with empty data appropriately. ```ruby Tag.order(['field(id, ?)', []]).to_sql # => SELECT "tags".* FROM "tags" ORDER BY field(id, NULL) Tag.order(['field(id, ?)', nil]).to_sql # => SELECT "tags".* FROM "tags" ORDER BY field(id, NULL) ```
* | Mutating the result of Relation#to_a should not affect the relationMatthew Draper2016-02-211-0/+10
|/ | | | | | Clarifying this separation and enforcing relation immutability is the culmination of the previous efforts to remove the mutator method delegations.