aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/finder_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* activerecord: Fix where nil condition on composed_of attributeDylan Thacker-Smith2019-01-181-0/+18
|
* All of queries should return correct result even if including large numberRyuta Kamizono2019-01-181-0/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently several queries cannot return correct result due to incorrect `RangeError` handling. First example: ```ruby assert_equal true, Topic.where(id: [1, 9223372036854775808]).exists? assert_equal true, Topic.where.not(id: 9223372036854775808).exists? ``` The first example is obviously to be true, but currently it returns false. Second example: ```ruby assert_equal topics(:first), Topic.where(id: 1..9223372036854775808).find(1) ``` The second example also should return the object, but currently it raises `RecordNotFound`. It can be seen from the examples, the queries including large number assuming empty result is not always correct. Therefore, This change handles `RangeError` to generate executable SQL instead of raising `RangeError` to users to always return correct result. By this change, it is no longer raised `RangeError` to users.
* Merge pull request #34963 from ↵Rafael França2019-01-171-0/+1
|\ | | | | | | | | dylanahsmith/better-composed-of-single-field-query activerecord: Use a simpler query condition for aggregates with one mapping
| * activerecord: Use a simpler query condition for aggregates with one mappingDylan Thacker-Smith2019-01-171-0/+1
| |
* | Ensure that AR::Relation#exists? allows only permitted paramsbogdanvlviv2019-01-171-2/+6
|/ | | | | Clarify changelog entry Related to #34891
* Allow strong params in ActiveRecord::Base#exists?Gannon McGibbon2019-01-071-0/+9
| | | | | Allow `ActionController::Params` as argument of `ActiveRecord::Base#exists?`
* Module#{define_method,alias_method,undef_method,remove_method} become public ↵Ryuta Kamizono2018-12-211-1/+1
| | | | | | since Ruby 2.5 https://bugs.ruby-lang.org/issues/14133
* Make implicit order column configurableTekin Suleyman2018-11-261-0/+10
| | | | | | | | | | | | | | When calling ordered finder methods such as +first+ or +last+ without an explicit order clause, ActiveRecord sorts records by primary key. This can result in unpredictable and surprising behaviour when the primary key is not an auto-incrementing integer, for example when it's a UUID. This change makes it possible to override the column used for implicit ordering such that +first+ and +last+ will return more predictable results. For Example: class Project < ActiveRecord::Base self.implicit_order_column = "created_at" end
* `exists?` with string argument is not invalid typeRyuta Kamizono2018-10-271-5/+13
| | | | | | Any type can be a primary key, so blank string is also valid value. Closes #26356.
* Ignore empty condition on #construct_relation_for_existsr7kamura2018-10-271-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | At https://github.com/rails/rails/commit/fc0e3354af7e7878bdd905a95ce4c1491113af9a, ```rb relation = relation.where(conditions) ``` was rewritten to: ```rb relation.where!(condition) ``` This change accidentally changed the result of `Topic.exists?({})` from true to false. To fix this regression, first I moved the blank check logic (`opts.blank?`) from `#where` to `#where!`, because I thought `#where!` should be identical to `#where`, except that instead of returning a new relation, it adds the condition to the existing relation. But on second thought after some discussion on https://github.com/rails/rails/pull/34329, I started to think that just fixing `#construct_relation_for_exists` is more preferable than changing `#where` and `#where!`.
* Don't return the same object when using find with an empty arrayRafael Mendonça França2018-09-191-1/+4
| | | | | | When you pass an empty array to find we know we shoudl return an empty array but it is surprising that we are returning the original empty array instead of a new one.
* Revert "Merge pull request #24131 from brchristian/limit_and_primary_key"Ryuta Kamizono2018-08-011-15/+0
| | | | | | | | | | This reverts commit d162188dd662a7d9f62ba8431474f50bc35e3e93, reversing changes made to 3576782888c307e3e192c44e332b957cd1174128. Reason: #24131 conflicts the #5153's default order contract, it means that existing apps would be broken by that change. We don't want to break existing apps without a deprecation cycle.
* Add test case for the #5153's default order contractRyuta Kamizono2018-08-011-0/+13
|
* tests for use of primary_key with limitBrian Christian2018-07-191-0/+15
|
* Add missing test case for `find` with a large numberRyuta Kamizono2018-06-221-0/+6
|
* Address CI failure due to non-deterministic query resultRyuta Kamizono2018-05-061-1/+1
| | | | https://travis-ci.org/rails/rails/jobs/375326992#L1160-L1166
* Replace `assert !` with `assert_not`Daniel Colson2018-04-191-2/+2
| | | | | This autocorrects the violations after adding a custom cop in 3305c78dcd.
* Fix `#columsn_for_distinct` of MySQL and PostgreSQLkg8m2018-02-271-0/+5
| | | | | | | Prevent `ActiveRecord::FinderMethods#limited_ids_for` from using correct primary key values even if `ORDER BY` columns include other table's primary key. Fixes #28364.
* More exercise range predicate builderRyuta Kamizono2018-02-231-0/+9
| | | | | * Add test case for open-ended range. * Add test case for numeric range for string column.
* Fix expanding an array of `composed_of` objects which have multiple mappingsRyuta Kamizono2018-01-291-4/+5
| | | | | | | | | Follow up of #31724. If `composed_of` objects have multiple mappings, array predicate handler can not correctly handle the expanded condition. We need to handle it like polymorphic association objects.
* Merge pull request #31724 from orekyuu/fix-expand-composed-object-arrayRyuta Kamizono2018-01-291-0/+18
|\ | | | | | | Fix not expanded problem when passing an Array object as argument to the where method using composed_of column.
| * Allow expanding an array of `composed_of` objectsRyuta Kamizono2018-01-291-3/+2
| |
| * Fix not expanded problem when passing an Array object as argument to the ↵orekyuu2018-01-261-0/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | where method using composed_of column. Fixes #31723 ``` david_balance = customers(:david).balance Customer.where(balance: [david_balance]).to_sql # Before: WHERE `customers`.`balance` = NULL # After : WHERE `customers`.`balance` = 50 ```
* | Use assert_predicate and assert_not_predicateDaniel Colson2018-01-251-2/+2
|/
* Make `relation.exists?` more performant when using eager loadingRyuta Kamizono2018-01-111-10/+12
| | | | | | `relation.exists?` just wants to know if there is a result or not, does not need the exact records matched. Therefore, an intermediate SELECT query for eager loading is not necessary.
* resolve inconsistencies between first and to_a.first with limitBrian Christian2018-01-091-0/+18
|
* Fix `last` with `offset` to behave consistently with loaded relationRyuta Kamizono2018-01-071-8/+4
| | | | | | Currently `last` with `offset` behaves incorrectly because `offset` can not be reversed like `limit`. Therefore, `offset` should also be handled like `limit`.
* assert_nothing_raised not required here, we can assert directly for the ↵Prathamesh Sonpatki2017-12-191-4/+2
| | | | actual result
* Enable `Layout/LeadingCommentSpace` to not allow cosmetic changes in the futureRyuta Kamizono2017-12-141-1/+1
| | | | Follow up of #31432.
* Enable `Layout/SpaceBeforeComma` rubocop rule, and fixed moreRyuta Kamizono2017-12-121-1/+1
| | | | Follow up of #31390.
* Revert "Merge pull request #31006 from ↵eileencodes2017-11-261-16/+0
| | | | | | | | | | | rails/kamipo/ordinal_methods_should_respect_loaded_records" This reverts commit 0f79ab91150b4cdb6c018530978a3395962c7a02, reversing changes made to d575f7f2e737739302a0e8210d01c10f5d4e2c35. This PR philosophically conflicts with #30800 and Matthew thinks we should hold off merging this until we find concensus. Reverting since we're about to cut a release for 5.2.
* Merge pull request #31184 from TheSmartnik/fix_record_not_found_on_reloadRafael França2017-11-251-0/+15
|\ | | | | Provide arguments to RecordNotFound
| * Provide arguments to RecordNotFoundNikita Misharin2017-11-251-0/+15
| |
* | Merge pull request #31006 from ↵Eileen M. Uchitelle2017-11-251-0/+16
|\ \ | |/ |/| | | | | rails/kamipo/ordinal_methods_should_respect_loaded_records Ordinal methods should respect loaded records
| * Ordinal methods should respect loaded recordsRyuta Kamizono2017-10-281-0/+16
| | | | | | | | | | | | We should reset partially loaded `@offsets` cache when latest records has loaded because the cache has been staled and it may not be consistent with latest records.
* | try using regexesBen Toews2017-11-091-7/+7
| |
* | allow table name and direction in string order argBen Toews2017-11-091-11/+11
| |
* | work around deprecation warnings in a bunch of testsBen Toews2017-11-091-20/+20
|/
* All test cases for `exists?` places in `finder_test.rb` to ease to find the ↵Ryuta Kamizono2017-10-091-0/+26
| | | | test cases
* Fix `relation.exists?` with has_many through associationsRyuta Kamizono2017-10-091-0/+8
| | | | | `relation.exists?` should reference correct aliases while joining tables of has_many through associations.
* Merge pull request #29720 from gaurish/ar_find_error_message_improvementRafael França2017-08-111-1/+1
|\ | | | | Return Not found Ids in ActiveRecord::NotFound
| * Return Not found Ids in ActiveRecord::NotFoundGaurish Sharma2017-07-291-1/+1
| | | | | | | | | | This builds on top of 15e2da656f41af0124f7577858536f3b65462ad5. now it also returns exact Ids which were not found which will be debugging simple.
* | Merge pull request #29842 from kamipo/fix_find_by_with_rangeMatthew Draper2017-08-021-0/+4
|\ \ | |/ |/| Fix `find_by` with range conditions
| * Fix `find_by` with range conditionsRyuta Kamizono2017-07-201-0/+4
| | | | | | | | | | `StatementCache` doesn't support range conditions. So we need to through the args to `FinderMethods#find_by` if range value is passed.
* | Use frozen-string-literal in ActiveRecordKir Shatrov2017-07-191-0/+2
|/
* Skip query cache for in_batches and friendsEugene Kenny2017-07-061-0/+28
| | | | | | | | | | | 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
|
* Remove the redundant `test_find_all_with_join` in ARKoichi ITO2017-06-021-10/+0
|
* Remove a redundant test assertionKoichi ITO2017-05-271-1/+0
|