aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/finder_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* Prevent `RangeError` for `FinderMethods#exists?`Ryuta Kamizono2016-06-161-4/+2
| | | | | | | | | | | | | `FinderMethods#exists?` should return a boolean rather than raising an exception. `UniquenessValidator#build_relation` catches a `RangeError` because it includes type casting due to a string value truncation. But a string value truncation was removed at #23523 then type casting in `build_relation` is no longer necessary. aa06231 removes type casting in `build_relation` then a `RangeError` moves to `relation.exists?`. This change will remove the catching a `RangeError`.
* Followup of #24835Vipul A M2016-05-031-1/+1
| | | | Fix failing tests
* Allow symbols using "dot notation" to be passed to whereSean Griffin2016-04-121-1/+6
| | | | | | | | | | | | | | | | | In 04ac5655be91f49cd4dfe2838df96213502fb274 I assumed that we would never want to pass the "table_name.column_name" form to where with a symbol. However, in Ruby 2.2 and later, you can quote symbols using the new hash syntax, so it's a semi-reasonable thing to do if we want to support the dot notation (which I'd rather deprecate, but that would be too painful of a migration). Instead we've changed the definition of "this is a table name with a dot" to when the value associated is a hash. It would make very little sense to write `where("table_name.column_name": { foo: :bar })` in any scenario (other than equality for a JSON column which we don't support through `where` in this way). Close #24514.
* comment out failing .second and .third testsBrian Christian2016-02-271-3/+3
|
* adding additional tests for offset and limit behaviorBrian Christian2016-02-271-0/+8
|
* additional test assertions (limit and offset)Brian Christian2016-02-271-0/+16
|
* AR #second_to_last tests and finder methodsBrian Christian2016-02-271-0/+36
|
* remove args from assert_nothing_raised in testsTara Scherner de la Fuente2016-02-221-3/+3
|
* Merge pull request #23377 from bogdan/last-with-sqlEileen M. Uchitelle2016-02-131-8/+36
|\ | | | | Fix AR::Relation#last bugs instroduced in 7705fc
| * Make ActiveRecord::Relation#last to reverse SQL orderBogdan Gusiev2016-02-131-8/+36
| | | | | | | | instead of loading the relation into memory
* | Fix grammar `a` to `an` [ci skip]Ryuta Kamizono2016-02-131-1/+1
|/
* Revert "Merge pull request #16400 from bogdan/last-with-sql"Sean Griffin2016-02-011-23/+9
| | | | | | | | | | This reverts commit 9f3730a516f30beb0050caea9539f8d6b808e58a, reversing changes made to 2637fb75d82e1c69333855abd58c2470994995d3. There are additional issues with this commit that need to be addressed before this change is ready (see #23377). This is a temporary revert in order for us to have more time to address the issues with that PR, without blocking the release of beta2.
* Reworked ActiveRecord::Relation#last to always use SQLBogdan Gusiev2016-01-281-9/+23
| | | | instead of loading relation
* Fix ↵Ryuta Kamizono2015-12-191-3/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `test_find_with_order_on_included_associations_with_construct_finder_sql_for_association_limiting_and_is_distinct` to NULL-agnostic way The sort order of NULL depends on the RDBS implementation. This commit is to fix the test to NULL-agnostic way. Example: ``` activerecord_unittest=# SELECT DISTINCT "posts"."id", author_addresses_authors.id AS alias_0 FROM "posts" LEFT OUTER JOIN "authors" ON "authors"."id" = "posts"."author_id" LEFT OUTER JOIN "author_addresses" ON "author_addresses"."id" = "authors"."author_address_id" LEFT OUTER JOIN "categorizations" ON "categorizations"."category_id" = "posts"."id" LEFT OUTER JOIN "authors" "authors_posts" ON "authors_posts"."id" = "categorizations"."author_id" LEFT OUTER JOIN "author_addresses" "author_addresses_authors" ON "author_addresses_authors"."id" = "authors_posts"."author_address_id" ORDER BY author_addresses_authors.id DESC; id | alias_0 ----+--------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 1 | 1 (12 rows) ``` ``` root@localhost [activerecord_unittest] > SELECT DISTINCT `posts`.`id`, author_addresses_authors.id AS alias_0 FROM `posts` LEFT OUTER JOIN `authors` ON `authors`.`id` = `posts`.`author_id` LEFT OUTER JOIN `author_addresses` ON `author_addresses`.`id` = `authors`.`author_address_id` LEFT OUTER JOIN `categorizations` ON `categorizations`.`category_id` = `posts`.`id` LEFT OUTER JOIN `authors` `authors_posts` ON `authors_posts`.`id` = `categorizations`.`author_id` LEFT OUTER JOIN `author_addresses` `author_addresses_authors` ON `author_addresses_authors`.`id` = `authors_posts`.`author_address_id` ORDER BY author_addresses_authors.id DESC; +----+---------+ | id | alias_0 | +----+---------+ | 1 | 1 | | 3 | NULL | | 1 | NULL | | 2 | NULL | | 4 | NULL | | 5 | NULL | | 6 | NULL | | 7 | NULL | | 8 | NULL | | 9 | NULL | | 10 | NULL | | 11 | NULL | +----+---------+ 12 rows in set (0.00 sec) ```
* Merge pull request #22653 from matthewd/find_array_orderedMatthew Draper2015-12-181-1/+74
|\ | | | | | | ActiveRecord::Base#find(array) returning result in the same order as the array passed
| * Implement limit & offset for ourselvesMatthew Draper2015-12-181-2/+2
| | | | | | | | | | | | | | | | | | | | We know the query will return exactly one row for each entry in the `ids` array, so we can do all the limit/offset calculations on that array, in advance. I also split our new ordered-ids behaviour out of the existing `find_some` method: especially with this change, the conditionals were overwhelming the actual logic.
| * Adding a new test using chained where, limit and find([pks])Miguel Grazziotin2015-08-071-2/+12
| |
| * WIP: fixing the limit bug and introducing new tests (failing for now) on ↵Miguel Grazziotin2015-06-191-4/+25
| | | | | | | | .find(array) with offset
| * do not change the order of the result if the object was already ordered by ↵Miguel Grazziotin2015-06-051-0/+5
| | | | | | | | the user via :order clause
| * adding a test to ensure the find is obbeying the limitMiguel Grazziotin2015-06-031-0/+7
| |
| * [#20338] adding tests to ensure the order clause takes precedenceMiguel Grazziotin2015-06-031-0/+18
| |
| * [#20338] WIP: first basic implementation and specsMiguel Grazziotin2015-05-291-0/+12
| |
* | Use a bind param for `LIMIT` and `OFFSET`Sean Griffin2015-12-141-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We currently generate an unbounded number of prepared statements when `limit` or `offset` are called with a dynamic argument. This changes `LIMIT` and `OFFSET` to use bind params, eliminating the problem. `Type::Value#hash` needed to be implemented, as it turns out we busted the query cache if the type object used wasn't exactly the same object. This drops support for passing an `Arel::Nodes::SqlLiteral` to `limit`. Doing this relied on AR internals, and was never officially supported usage. Fixes #22250.
* | Remove some bind related test cases from finder_test.rb to sanitize_test.rbyui-knk2015-11-211-91/+0
| | | | | | | | | | | | `replace_named_bind_variables` and `replace_bind_variables` are definded in `sanitization.rb`, so it is reasonable these tests are on `sanitize_test.rb`.
* | Don't cache arguments in #find_by if they are an ActiveRecord::Relationakihiro172015-10-061-0/+6
| | | | | | | | | | | | | | In this commit, find_by doesn't cache arguments so that find_by with association subquery works correctly. Fixes #20817
* | Add tests for sanitize named bind arityyui-knk2015-09-231-3/+9
| |
* | Removed mocha from Active Record Part 2Ronak Jangir2015-09-161-2/+3
| |
* | Revert "Merge pull request #20080 from ↵Rafael Mendonça França2015-09-091-13/+0
| | | | | | | | | | | | | | | | | | robertjlooby/fix_overwriting_by_dynamic_finders" This reverts commit d5ba9a42a6e93b163a49f99d739aa56820e044d0, reversing changes made to 30c503395bf6bf7db1ec0295bd661ce644628db5. Reason: This generate the dynalic finders more than one time
* | put dynamic matchers on the GeneratedAssociationMethods instead of modelRob Looby2015-05-081-0/+13
|/
* remove old unavailable link with relevant fixGaurav Sharma2015-03-231-1/+0
|
* Remove version conditional for calling GC.disableRafael Mendonça França2015-01-041-1/+1
|
* Don't perform statement caching for `find` when called from a scopeSean Griffin2014-12-221-1/+23
| | | | | | | | If there is a method defined such as `find_and_do_stuff(id)`, which then gets called on an association, we will perform statement caching and the parent ID will not change on subsequent calls. Fixes #18117
* Remove deprecated behavior allowing nested arrays as query valuesMelanie Gilman2014-12-041-24/+0
|
* Prevent Symbol GCRyuta Kamizono2014-12-041-0/+3
|
* Refactor `build_from_hash` to convert dot notation to hash firstMelanie Gilman2014-12-021-0/+6
| | | | | | | | | | This ensures that we're handling all forms of nested tables the same way. We're aware that the `convert_dot_notation_to_hash` method will cause a performance hit, and we intend to come back to it once we've refactored some of the surrounding code. [Melissa Xie & Melanie Gilman]
* Pass symbol as an argument instead of a blockErik Michaels-Ober2014-11-291-4/+4
|
* Build fix when running in isolationArun Agrawal2014-11-141-0/+1
| | | | | `Computer` class needs to be require See #17217 for more details
* Handle `RangeError` from casting in `find_by` and `find_by!` on RelationSean Griffin2014-11-021-0/+10
| | | | | We should not behave differently just because a class has a default scope.
* Treat strings greater than int max value as out of rangeSean Griffin2014-10-311-13/+14
| | | | | | | | | | | Sufficiently large integers cause `find` and `find_by` to raise `StatementInvalid` instead of `RecordNotFound` or just returning `nil`. Given that we can't cast to `nil` for `Integer` like we would with junk data for other types, we raise a `RangeError` instead, and rescue in places where it would be highly unexpected to get an exception from casting. Fixes #17380
* Fix find_by with associations not working with adequate recordGodfrey Chan2014-09-201-0/+5
| | | | | | | | | For now, we will just skip the cache when a non-column key is used in the hash. If the future, we can probably move some of the logic in PredicateBuilder.expand up the chain to make caching possible for association queries. Closes #16903 Fixes #16884
* Merge pull request #15791 from zev/add_model_to_recordnotfound_messageAaron Patterson2014-09-191-10/+18
|\ | | | | Update RecordNotFound exception cases to include a message with the
| * Update RecordNotFound exception cases to include a message with theZev Blut2014-06-181-10/+18
| | | | | | | | Model that the Record was not found in.
* | Fix query with nested array in Active RecordCristian Bica2014-09-061-0/+28
| | | | | | | | | | | | | | | | `User.where(id: [[1,2],3])` was equal to `User.where(id:[1, 2, 3])` in Rails 4.1.x but because of some refactoring in Arel this stopped working in 4.2.0. This fixes it in Rails. [Dan Olson & Cristian Bica]
* | Override #find_by! in core to enable AST cachingGodfrey Chan2014-08-251-0/+22
| |
* | Fixed find_by("sql fragment without bindings") on masterGodfrey Chan2014-08-251-0/+20
| | | | | | | | | | | | | | | | | | | | | | * Also duplicated find_by tests from relations_test.rb to finder_test.rb now that we have a completely different implementation on the class (in core.rb with AST caching stuff). * Also removed a (failing) test that used mocks. Now that we have tests for the behavior, there's no point having another test that tests the implementation (that it delegates). Further, what the test was implying is nolonger true with the current implementation, because Class.find_by is a real method now.
* | Fixes the `Relation#exists?` to work with polymorphic associations.Kassio Borges2014-08-181-0/+14
| | | | | | | | Fixes #15821.
* | Warm up Symbols with where methodAkira Matsuda2014-08-151-1/+1
| | | | | | | | Looks like #first wasn't warm enough...
* | Deprecate automatic counter caches on has_many :throughSean Griffin2014-06-261-2/+2
| | | | | | | | | | | | | | | | | | | | | | Reliant on https://github.com/rails/rails/pull/15747 but pulled to a separate PR to reduce noise. `has_many :through` associations have the undocumented behavior of automatically detecting counter caches. However, the way in which it does so is inconsistent with counter caches everywhere else, and doesn't actually work consistently. As with normal `has_many` associations, the user should specify the counter cache on the `belongs_to`, if they'd like it updated.
* | Silence warnings in tests.Sean Griffin2014-06-101-2/+2
|/ | | | | | | | ``` activerecord/test/cases/adapters/postgresql/range_test.rb:159: warning: (...) interpreted as grouped expression activerecord/test/cases/finder_test.rb:38: warning: shadowing outer local variable - e activerecord/test/cases/finder_test.rb:43: warning: shadowing outer local variable - e ```
* ActiveRecord::FinderMethods.find passes proc parameter #15382James Yang2014-06-101-0/+11
|