aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/finder_test.rb
Commit message (Collapse)AuthorAgeFilesLines
...
| * 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
|
* Add test for deprecation warning for passing an AR object to `find`.Lauro Caetano2014-03-131-0/+6
|
* Test deprecation warning for passing an ActiveRecord object toLauro Caetano2014-03-131-0/+6
| | | | `exists?`
* passing an ActiveRecord object to `exists?` is deprecated.Aaron Patterson2014-03-131-1/+1
| | | | | Pass the id of the object to the method by calling `.id` on the AR object.
* mysql adapter also fails with a number bigger than intRafael Mendonça França2014-03-101-2/+5
|
* Change the assertions depending in the database adapterRafael Mendonça França2014-03-101-14/+9
| | | | This will avoid the confusing flunk logic
* Do proper adapter checkRafael Mendonça França2014-03-101-2/+2
|
* Make exists? use bound values.Martin Schürrer2014-03-041-2/+14
| | | | | | | | | | | When we build a query with an inline value that is a numeric (e.g. because it's out of range for an int4) PostgreSQL doesn't use an index on the column, since it's now comparing numerics and not int4s. This leads to a _very_ slow query. When we use bound parameters instead of inline values PostgreSQL raises numeric_value_out_of_range since no automatic coercion happens.
* Fix `ActiveRecord::RecordNotFound` error message with custom primary keyKuldeep Aggarwal2014-01-251-7/+24
|
* Ensure AR #second, #third, etc. finders work through associationsJason Meller2014-01-211-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit fixes two regressions introduced in cafe31a078 where newly created finder methods #second, #third, #forth, and #fifth caused a NoMethodError error on reload associations and where we were pulling the wrong element out of cached associations. Examples: some_book.authors.reload.second # Before # => NoMethodError: undefined method 'first' for nil:NilClass # After # => #<Author id: 2, name: "Sally Second", ...> some_book.first.authors.first some_book.first.authors.second # Before # => #<Author id: 1, name: "Freddy First", ...> # => #<Author id: 1, name: "Freddy First", ...> # After # => #<Author id: 1, name: "Freddy First", ...> # => #<Author id: 2, name: "Sally Second", ...> Fixes #13783.
* Ensure #second acts like #first AR finderJason Meller2014-01-201-1/+89
| | | | | | | | | | | | This commit bring the famous ordinal Array instance methods defined in ActiveSupport into ActiveRecord as fully-fledged finders. These finders ensure a default ascending order of the table's primary key, and utilize the OFFSET SQL verb to locate the user's desired record. If an offset is defined in the query, calling #second adds to the offset to get the actual desired record. Fixes #13743.
* we have `with_env_tz` as global test helper. Remove duplicate.Yves Senn2014-01-161-7/+0
|
* Fix mysql to support duplicated column namesKassio Borges2013-12-131-1/+1
| | | | | | | | | | This will fix the [broken test](https://github.com/rails/rails/commit/4a2650836680f51490e999c3c8441a2f9adff96e) `test_with_limiting_with_custom_select`. The query's result was built in a hash with column name as key, if the result have a duplicated column name the last value was overriding the first one.
* Prevent invalid code when using dynamic finders with Ruby's reserved words.Lauro Caetano2013-12-111-0/+8
| | | | | | | | | | | | | | | | | | | | | The dynamic finder was creating the method signature with the parameters name, which may have reserved words and this way creating invalid Ruby code. Closes: #13261 Example: # Before Dog.find_by_alias('dog name') # Was creating this method def self.find_by_alias(alias, options = {}) # After Dog.find_by_alias('dog name') # Will create this method def self.find_by_alias(_alias, options = {})
* Remove deprecated call to Relation#allCarlos Antonio da Silva2013-12-051-1/+1
|
* Fix offset with last.Lauro Caetano2013-12-031-0/+9
| | | | Closes #7441
* Make the tests break againRafael Mendonça França2013-12-021-2/+0
| | | | We need to fix this test
* use complete Relation API and not only `Model.all.merge!`.Yves Senn2013-11-091-88/+83
|
* Mark broken test as pendingRafael Mendonça França2013-11-081-0/+2
| | | | This will avoid the broken window effect in our test suite
* prevent global timezone state from leaking out of test cases.Yves Senn2013-10-251-4/+4
|