aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/finder_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* 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
|
* Raise an exception when model without primary key calls .find_with_idsShimpei Makimoto2013-10-211-0/+7
|
* Add a test case for exists? with multiple valuesRafael Mendonça França + Kassio Borges2013-09-041-0/+1
|
* let AR::FinderMethods#exists? return singletons in all cases [closes #11592]Xavier Noria2013-08-191-27/+29
| | | | | | | | | | | | | | | | | | | | | This fixes a regression. The documentation said in its introduction paragraph that the method returns truthy/falsy, but then below it was said that if there were no arguments you'd get `true` or `false`. Also when the argument is exactly `false` a singleton is documented to be returned. The method was not returning the singletons so it didn't conform to those special cases. The best solution here seems to be to just return singletons in all cases. This solution is backwards compatible. Also, the contract has been revised because it has no sense that the predicate varies that way depending on the input. I bet the previous contract was just an accident, not something mixed on purpose. Conflicts: activerecord/lib/active_record/relation/finder_methods.rb activerecord/test/cases/finder_test.rb
* remove duplicate methodNeeraj Singh2013-07-291-7/+0
| | | | This method is already present in helper.rb
* Don't allow `quote_value` to be called without a columnBen Woosley2013-07-221-1/+1
| | | | | | | Some adapters require column information to do their job properly. By enforcing the provision of the column for this internal method we ensure that those using adapters that require column information will always get the proper behavior.
* Fix that #exists? can produce invalid SQL: "SELECT DISTINCT DISTINCT"Ben Woosley2013-05-101-0/+12
| | | | | | | | | | | | The combination of a :uniq => true association and the #distinct call in #construct_limited_ids_condition combine to create invalid SQL, because we're explicitly selecting DISTINCT, and also sending #distinct on to AREL, via the relation#distinct_value. Rather than build a select distinct clause in #construct_limited_ids_condition, I set #distinct! and pass just the columns into the select statement. This requires introducing a #columns_for_distinct method to return the select columns but not the statement itself.
* Handle aliased attributes in ActiveRecord::Relation.Godfrey Chan2013-05-011-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | When using symbol keys, ActiveRecord will now translate aliased attribute names to the actual column name used in the database: With the model class Topic alias_attribute :heading, :title end The call Topic.where(heading: 'The First Topic') should yield the same result as Topic.where(title: 'The First Topic') This also applies to ActiveRecord::Relation::Calculations calls such as `Model.sum(:aliased)` and `Model.pluck(:aliased)`. This will not work with SQL fragment strings like `Model.sum('DISTINCT aliased')`. Github #7839 *Godfrey Chan*
* adding test for the symbol refsAaron Patterson2013-04-261-0/+7
|
* Reset the primary key for other testsAndrew White2013-04-241-0/+2
|
* rename `Relation#uniq` to `Relation#distinct`. `#uniq` still works.Yves Senn2013-03-151-1/+1
| | | | | | | | The similarity of `Relation#uniq` to `Array#uniq` is confusing. Since our Relation API is close to SQL terms I renamed `#uniq` to `#distinct`. There is no deprecation. `#uniq` and `#uniq!` are aliases and will continue to work. I also updated the documentation to promote the use of `#distinct`.
* Reverting 16f6f25 (Change behaviour with empty array in where clause)Guillermo Iguaran2013-02-081-0/+9
|
* Change behaviour with empty array in where clauserobertomiranda2013-02-081-9/+0
|
* CVE-2012-5664 options hashes should only be extracted if there are extra ↵Aaron Patterson2013-01-021-0/+12
| | | | | | | parameters Conflicts: activerecord/lib/active_record/dynamic_matchers.rb
* Assert the query result instead of checking for nothing raisedCarlos Antonio da Silva2012-11-131-4/+2
| | | | | | | Nothing should be raised anyway :smile: Thanks @spastorino :heart: https://github.com/rails/rails/pull/8202/files#r2112067
* Regression test for #7238Nikita Afanasenko2012-11-131-0/+7
|
* Raise MissingAttributeError on query methodsErnie Miller2012-09-081-0/+1
| | | | | | | | | | | | | When calling a query method on an attribute that was not selected by an ActiveRecord query, an ActiveModel::MissingAttributeError is not raised. Instead, a nil value is returned, which will return false once cast to boolean. This is undesirable, as we should not give the impression that we know the attribute's boolean value when we haven't loaded the attribute's (possibly) non-boolean value from the database. This issue is present on versions going back as far as 2.3, at least.
* Remove ActiveRecord::Base.to_aJon Leighton2012-08-031-1/+1
| | | | | On reflection, it seems like a bit of a weird method to have on ActiveRecord::Base, and it shouldn't be needed most of the time anyway.
* Revert "Removing composed_of from ActiveRecord."Rafael Mendonça França2012-07-271-0/+99
| | | | | | | | | | | This reverts commit 14fc8b34521f8354a17e50cd11fa3f809e423592. Reason: we need to discuss a better path from this removal. Conflicts: activerecord/lib/active_record/reflection.rb activerecord/test/cases/base_test.rb activerecord/test/models/developer.rb
* Deprecate ActiveRecord::Base.scoped.Jon Leighton2012-07-271-69/+69
| | | | | | | It doesn't serve much purpose now that ActiveRecord::Base.all returns a Relation. The code is moved to active_record_deprecated_finders.
* ActiveRecord::Base.all returns a Relation.Jon Leighton2012-07-271-17/+17
| | | | | | | | | | | Previously it returned an Array. If you want an array, call e.g. `Post.to_a` rather than `Post.all`. This is more explicit. In most cases this should not break existing code, since Relations use method_missing to delegate unknown methods to #to_a anyway.
* exists?(false) returns falseEgor Lynko2012-06-251-0/+4
| | | | `FinderMethods#exists?` finder method now returns *false* with the *false* argument
* made dynamic finders alias_attribute awareMaximilian Schneider2012-06-221-0/+5
| | | | | previously dynamic finders only worked in combination with the actual column name and not its alias defined with #alias_attribute
* Removing composed_of from ActiveRecord.Steve Klabnik2012-06-181-99/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | This feature adds a lot of complication to ActiveRecord for dubious value. Let's talk about what it does currently: class Customer < ActiveRecord::Base composed_of :balance, :class_name => "Money", :mapping => %w(balance amount) end Instead, you can do something like this: def balance @balance ||= Money.new(value, currency) end def balance=(balance) self[:value] = balance.value self[:currency] = balance.currency @balance = balance end Since that's fairly easy code to write, and doesn't need anything extra from the framework, if you use composed_of today, you'll have to add accessors/mutators like that. Closes #1436 Closes #2084 Closes #3807
* Address ORA-00911 errors because of the heading underscore.Yasuo Honda2012-06-111-1/+1
|
* Fix that #exists? raises ThrowResult when called with an empty limitedBen Woosley2012-06-101-1/+6
| | | | | | | | | reflection. ActiveRecord::FinderMethods#construct_limited_ids_condition will raise ThrowResult if the limited reflection comes back empty. The other callers of #construct_limited_ids_condition handle this exception (more specifically, the callers of construct_relation_for*), but #exists? didn't until now.
* Add test to column alias in `exists?` SQL.Rafael Mendonça França2012-06-101-0/+6
| | | | | | | | This behavior was added in be4ecdcc87984e9421ff5d5c90d33f475e0fbc01. Closes #1139. Fixes #2553, #1141, #1623 and #2062.
* stop `to_s`ing method namesAkira Matsuda2012-06-061-1/+1
| | | | Module#methods are Symbols in Ruby >= 1.9
* quarantine more deprecated stuffJon Leighton2012-05-181-9/+0
|